1
/***************************************************************************
2
* Copyright (c) 2014 Luke Parry <l.parry@warwick.ac.uk> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
23
#include "PreCompiled.h"
25
#include <QMessageBox>
26
#include <QTextStream>
29
#include <App/DocumentObject.h>
30
#include <Gui/Control.h>
31
#include <Gui/MainWindow.h>
33
#include <Mod/TechDraw/App/DrawProjGroup.h>
34
#include <Mod/TechDraw/App/DrawProjGroupItem.h>
36
#include "ViewProviderProjGroupItem.h"
38
using namespace TechDrawGui;
40
PROPERTY_SOURCE(TechDrawGui::ViewProviderProjGroupItem, TechDrawGui::ViewProviderViewPart)
42
//**************************************************************************
43
// Construction/Destruction
45
ViewProviderProjGroupItem::ViewProviderProjGroupItem()
50
ViewProviderProjGroupItem::~ViewProviderProjGroupItem()
54
void ViewProviderProjGroupItem::updateData(const App::Property* prop)
56
Gui::ViewProviderDocumentObject::updateData(prop);
57
TechDraw::DrawProjGroupItem* proj = getObject();
62
// Set the icon pixmap depending on the orientation
63
std::string projType = proj->Type.getValueAsString();
65
//TODO: Once we know that ProjType is valid, sPixMap = "Proj" + projType
67
if(strcmp(projType.c_str(), "Front") == 0) {
68
sPixmap = "TechDraw_ProjFront";
69
} else if(strcmp(projType.c_str(), "Rear") == 0) {
70
sPixmap = "TechDraw_ProjRear";
71
} else if(strcmp(projType.c_str(), "Right") == 0) {
72
sPixmap = "TechDraw_ProjRight";
73
} else if(strcmp(projType.c_str(), "Left") == 0) {
74
sPixmap = "TechDraw_ProjLeft";
75
} else if(strcmp(projType.c_str(), "Top") == 0) {
76
sPixmap = "TechDraw_ProjTop";
77
} else if(strcmp(projType.c_str(), "Bottom") == 0) {
78
sPixmap = "TechDraw_ProjBottom";
79
} else if(strcmp(projType.c_str(), "FrontTopLeft") == 0) {
80
sPixmap = "TechDraw_ProjFrontTopLeft";
81
} else if(strcmp(projType.c_str(), "FrontTopRight") == 0) {
82
sPixmap = "TechDraw_ProjFrontTopRight";
83
} else if(strcmp(projType.c_str(), "FrontBottomRight") == 0) {
84
sPixmap = "TechDraw_ProjFrontBottomRight";
85
} else if(strcmp(projType.c_str(), "FrontBottomLeft") == 0) {
86
sPixmap = "TechDraw_ProjFrontBottomLeft";
91
void ViewProviderProjGroupItem::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
97
//act = menu->addAction(QObject::tr("Show drawing"), receiver, member);
100
bool ViewProviderProjGroupItem::setEdit(int ModNum)
107
void ViewProviderProjGroupItem::unsetEdit(int ModNum)
110
Gui::Control().closeDialog();
113
bool ViewProviderProjGroupItem::doubleClicked()
118
bool ViewProviderProjGroupItem::onDelete(const std::vector<std::string> &)
120
// we cannot delete the anchor view, thus check if the item is the front item
121
// we also cannot delete if the item has a section or detail view
124
QTextStream bodyMessageStream(&bodyMessage);
125
bool isAnchor = false;
127
// get the item and group
128
TechDraw::DrawProjGroupItem* dpgi = static_cast<TechDraw::DrawProjGroupItem*>(getViewObject());
129
TechDraw::DrawProjGroup* dpg = dpgi->getPGroup();
130
// get the projection
131
TechDraw::DrawProjGroupItem* proj = getObject();
132
// check if it is the anchor projection
133
if (dpg && (dpg->hasProjection(proj->Type.getValueAsString()))
134
&& (dpg->getAnchor() == dpgi))
138
auto viewSection = getObject()->getSectionRefs();
139
auto viewDetail = getObject()->getDetailRefs();
140
auto viewLeader = getObject()->getLeaders();
145
bodyMessageStream << qApp->translate("Std_Delete",
146
"You cannot delete the anchor view of a projection group.");
147
QMessageBox::warning(Gui::getMainWindow(),
148
qApp->translate("Std_Delete", "Object dependencies"), bodyMessage,
150
// don't allow to delete
153
else if (!viewSection.empty()) {
154
bodyMessageStream << qApp->translate("Std_Delete",
155
"You cannot delete this view because it has a section view that would become broken.");
156
QMessageBox::warning(Gui::getMainWindow(),
157
qApp->translate("Std_Delete", "Object dependencies"), bodyMessage,
161
else if (!viewDetail.empty()) {
162
bodyMessageStream << qApp->translate("Std_Delete",
163
"You cannot delete this view because it has a detail view that would become broken.");
164
QMessageBox::warning(Gui::getMainWindow(),
165
qApp->translate("Std_Delete", "Object dependencies"), bodyMessage,
169
else if (!viewLeader.empty()) {
170
bodyMessageStream << qApp->translate("Std_Delete",
171
"You cannot delete this view because it has a leader line that would become broken.");
172
QMessageBox::warning(Gui::getMainWindow(),
173
qApp->translate("Std_Delete", "Object dependencies"), bodyMessage,
182
bool ViewProviderProjGroupItem::canDelete(App::DocumentObject *obj) const
184
// deletions of objects from a ProjGroupItem don't necessarily destroy anything
185
// thus we can pass this action
186
// we can warn the user if necessary in the object's ViewProvider in the onDelete() function
191
TechDraw::DrawProjGroupItem* ViewProviderProjGroupItem::getViewObject() const
193
return dynamic_cast<TechDraw::DrawProjGroupItem*>(pcObject);
196
TechDraw::DrawProjGroupItem* ViewProviderProjGroupItem::getObject() const
198
return getViewObject();