/
ViewProviderProjGroupItem.cpp
230 lines (198 loc) · 8.38 KB
/
ViewProviderProjGroupItem.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/***************************************************************************
* Copyright (c) 2014 Luke Parry <l.parry@warwick.ac.uk> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#include <QMessageBox>
#include <QTextStream>
#endif
/// Here the FreeCAD includes sorted by Base,App,Gui......
#include <Base/Console.h>
#include <Base/Parameter.h>
#include <Base/Exception.h>
#include <Base/Sequencer.h>
#include <App/Application.h>
#include <App/Document.h>
#include <App/DocumentObject.h>
#include <Gui/Application.h>
#include <Gui/BitmapFactory.h>
#include <Gui/Command.h>
#include <Gui/Control.h>
#include <Gui/Document.h>
#include <Gui/MainWindow.h>
#include <Mod/TechDraw/App/DrawProjGroup.h>
#include <Mod/TechDraw/App/DrawProjGroupItem.h>
#include "ViewProviderProjGroupItem.h"
using namespace TechDrawGui;
PROPERTY_SOURCE(TechDrawGui::ViewProviderProjGroupItem, TechDrawGui::ViewProviderViewPart)
//**************************************************************************
// Construction/Destruction
ViewProviderProjGroupItem::ViewProviderProjGroupItem()
{
}
ViewProviderProjGroupItem::~ViewProviderProjGroupItem()
{
}
void ViewProviderProjGroupItem::attach(App::DocumentObject *pcFeat)
{
// call parent attach method
ViewProviderViewPart::attach(pcFeat);
}
void ViewProviderProjGroupItem::setDisplayMode(const char* ModeName)
{
ViewProviderViewPart::setDisplayMode(ModeName);
}
std::vector<std::string> ViewProviderProjGroupItem::getDisplayModes(void) const
{
// get the modes of the father
std::vector<std::string> StrList = ViewProviderViewPart::getDisplayModes();
StrList.push_back("Drawing");
return StrList;
}
void ViewProviderProjGroupItem::updateData(const App::Property* prop)
{
Gui::ViewProviderDocumentObject::updateData(prop);
TechDraw::DrawProjGroupItem* proj = getObject();
if(proj) {
// Set the icon pixmap depending on the orientation
std::string projType = proj->Type.getValueAsString();
//TODO: Once we know that ProjType is valid, sPixMap = "Proj" + projType
if(strcmp(projType.c_str(), "Front") == 0) {
sPixmap = "TechDraw_ProjFront";
} else if(strcmp(projType.c_str(), "Rear") == 0) {
sPixmap = "TechDraw_ProjRear";
} else if(strcmp(projType.c_str(), "Right") == 0) {
sPixmap = "TechDraw_ProjRight";
} else if(strcmp(projType.c_str(), "Left") == 0) {
sPixmap = "TechDraw_ProjLeft";
} else if(strcmp(projType.c_str(), "Top") == 0) {
sPixmap = "TechDraw_ProjTop";
} else if(strcmp(projType.c_str(), "Bottom") == 0) {
sPixmap = "TechDraw_ProjBottom";
} else if(strcmp(projType.c_str(), "FrontTopLeft") == 0) {
sPixmap = "TechDraw_ProjFrontTopLeft";
} else if(strcmp(projType.c_str(), "FrontTopRight") == 0) {
sPixmap = "TechDraw_ProjFrontTopRight";
} else if(strcmp(projType.c_str(), "FrontBottomRight") == 0) {
sPixmap = "TechDraw_ProjFrontBottomRight";
} else if(strcmp(projType.c_str(), "FrontBottomLeft") == 0) {
sPixmap = "TechDraw_ProjFrontBottomLeft";
}
}
}
void ViewProviderProjGroupItem::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
{
Q_UNUSED(menu);
Q_UNUSED(receiver);
Q_UNUSED(member);
//QAction* act;
//act = menu->addAction(QObject::tr("Show drawing"), receiver, member);
}
bool ViewProviderProjGroupItem::setEdit(int ModNum)
{
Q_UNUSED(ModNum);
doubleClicked();
return true;
}
void ViewProviderProjGroupItem::unsetEdit(int ModNum)
{
Q_UNUSED(ModNum);
Gui::Control().closeDialog();
}
bool ViewProviderProjGroupItem::doubleClicked(void)
{
return true;
}
bool ViewProviderProjGroupItem::onDelete(const std::vector<std::string> &)
{
// we cannot delete the anchor view, thus check if the item is the front item
// we also cannot delete if the item has a section or detail view
QString bodyMessage;
QTextStream bodyMessageStream(&bodyMessage);
bool isAnchor = false;
// get the item and group
TechDraw::DrawProjGroupItem* dpgi = static_cast<TechDraw::DrawProjGroupItem*>(getViewObject());
TechDraw::DrawProjGroup* dpg = dpgi->getPGroup();
// get the projection
TechDraw::DrawProjGroupItem* proj = getObject();
// check if it is the anchor projection
if ((dpg != nullptr) && (dpg->hasProjection(proj->Type.getValueAsString()))
&& (dpg->getAnchor() == dpgi))
isAnchor = true;
// get child views
auto viewSection = getObject()->getSectionRefs();
auto viewDetail = getObject()->getDetailRefs();
auto viewLeader = getObject()->getLeaders();
if (isAnchor)
{
// generate dialog
bodyMessageStream << qApp->translate("Std_Delete",
"You cannot delete the anchor view of a projection group.");
QMessageBox::warning(Gui::getMainWindow(),
qApp->translate("Std_Delete", "Object dependencies"), bodyMessage,
QMessageBox::Ok);
// don't allow to delete
return false;
}
else if (!viewSection.empty()) {
bodyMessageStream << qApp->translate("Std_Delete",
"You cannot delete this view because it has a section view that would become broken.");
QMessageBox::warning(Gui::getMainWindow(),
qApp->translate("Std_Delete", "Object dependencies"), bodyMessage,
QMessageBox::Ok);
return false;
}
else if (!viewDetail.empty()) {
bodyMessageStream << qApp->translate("Std_Delete",
"You cannot delete this view because it has a detail view that would become broken.");
QMessageBox::warning(Gui::getMainWindow(),
qApp->translate("Std_Delete", "Object dependencies"), bodyMessage,
QMessageBox::Ok);
return false;
}
else if (!viewLeader.empty()) {
bodyMessageStream << qApp->translate("Std_Delete",
"You cannot delete this view because it has a leader line that would become broken.");
QMessageBox::warning(Gui::getMainWindow(),
qApp->translate("Std_Delete", "Object dependencies"), bodyMessage,
QMessageBox::Ok);
return false;
}
else {
return true;
}
}
bool ViewProviderProjGroupItem::canDelete(App::DocumentObject *obj) const
{
// deletions of objects from a ProjGroupItem don't necesarily destroy anything
// thus we can pass this action
// we can warn the user if necessary in the object's ViewProvider in the onDelete() function
Q_UNUSED(obj)
return true;
}
TechDraw::DrawProjGroupItem* ViewProviderProjGroupItem::getViewObject() const
{
return dynamic_cast<TechDraw::DrawProjGroupItem*>(pcObject);
}
TechDraw::DrawProjGroupItem* ViewProviderProjGroupItem::getObject() const
{
return getViewObject();
}