/
ViewProviderDimension.cpp
282 lines (242 loc) · 10.3 KB
/
ViewProviderDimension.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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/***************************************************************************
* Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de> *
* Copyright (c) 2012 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 <QAction>
# include <QMenu>
#endif
#include <QColor>
/// 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 <App/Material.h>
#include <Gui/ActionFunction.h>
#include <Gui/Command.h>
#include <Gui/Control.h>
#include <Mod/TechDraw/App/LineGroup.h>
#include <Mod/TechDraw/App/LandmarkDimension.h>
#include "PreferencesGui.h"
#include "TaskDimension.h"
#include "QGIViewDimension.h"
#include "ViewProviderDimension.h"
using namespace TechDrawGui;
using namespace TechDraw;
const char *ViewProviderDimension::StandardAndStyleEnums[]=
{ "ISO Oriented", "ISO Referencing", "ASME Inlined", "ASME Referencing", NULL };
const char *ViewProviderDimension::RenderingExtentEnums[]=
{ "None", "Minimal", "Confined", "Reduced", "Normal", "Expanded", NULL };
PROPERTY_SOURCE(TechDrawGui::ViewProviderDimension, TechDrawGui::ViewProviderDrawingView)
//**************************************************************************
// Construction/Destruction
ViewProviderDimension::ViewProviderDimension()
{
sPixmap = "TechDraw_Dimension";
static const char *group = "Dimension Format";
ADD_PROPERTY_TYPE(Font, (Preferences::labelFont().c_str()),
group, App::Prop_None, "The name of the font to use");
ADD_PROPERTY_TYPE(Fontsize, (Preferences::dimFontSizeMM()),
group, (App::PropertyType)(App::Prop_None),
"Dimension text size in units");
ADD_PROPERTY_TYPE(LineWidth, (prefWeight()), group, (App::PropertyType)(App::Prop_None),
"Dimension line width");
ADD_PROPERTY_TYPE(Color, (prefColor()), group, App::Prop_None, "Color of the dimension");
ADD_PROPERTY_TYPE(StandardAndStyle, (prefStandardAndStyle()), group, App::Prop_None,
"Standard and style according to which dimension is drawn");
StandardAndStyle.setEnums(StandardAndStyleEnums);
ADD_PROPERTY_TYPE(RenderingExtent, (REND_EXTENT_NORMAL), group, App::Prop_None,
"Select the rendering mode by space requirements");
RenderingExtent.setEnums(RenderingExtentEnums);
ADD_PROPERTY_TYPE(FlipArrowheads, (false), group, App::Prop_None,
"Reverses usual direction of dimension line terminators");
}
ViewProviderDimension::~ViewProviderDimension()
{
}
void ViewProviderDimension::attach(App::DocumentObject *pcFeat)
{
// call parent attach method
ViewProviderDrawingView::attach(pcFeat);
sPixmap = "TechDraw_Dimension";
if (getViewObject()->isDerivedFrom(TechDraw::LandmarkDimension::getClassTypeId())) {
sPixmap = "techdraw-landmarkdistance";
}
}
void ViewProviderDimension::setDisplayMode(const char* ModeName)
{
ViewProviderDrawingView::setDisplayMode(ModeName);
}
std::vector<std::string> ViewProviderDimension::getDisplayModes(void) const
{
// get the modes of the father
std::vector<std::string> StrList = ViewProviderDrawingView::getDisplayModes();
return StrList;
}
bool ViewProviderDimension::doubleClicked(void)
{
startDefaultEditMode();
return true;
}
void ViewProviderDimension::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
{
Gui::ActionFunction* func = new Gui::ActionFunction(menu);
QAction* act = menu->addAction(QObject::tr("Edit %1").arg(QString::fromUtf8(getObject()->Label.getValue())));
act->setData(QVariant((int)ViewProvider::Default));
func->trigger(act, boost::bind(&ViewProviderDimension::startDefaultEditMode, this));
ViewProviderDrawingView::setupContextMenu(menu, receiver, member);
}
void ViewProviderDimension::startDefaultEditMode()
{
QString text = QObject::tr("Edit %1").arg(QString::fromUtf8(getObject()->Label.getValue()));
Gui::Command::openCommand(text.toUtf8());
Gui::Document* document = this->getDocument();
if (document) {
document->setEdit(this, ViewProvider::Default);
}
}
bool ViewProviderDimension::setEdit(int ModNum)
{
if (ModNum == ViewProvider::Default) {
if (Gui::Control().activeDialog()) { // if TaskPanel already open
return false;
}
// clear the selection (convenience)
Gui::Selection().clearSelection();
auto qgivDimension(dynamic_cast<QGIViewDimension*>(getQView()));
if (qgivDimension) {
Gui::Control().showDialog(new TaskDlgDimension(qgivDimension, this));
}
return true;
}
else {
return ViewProviderDrawingView::setEdit(ModNum);
}
return true;
}
void ViewProviderDimension::unsetEdit(int ModNum)
{
if (ModNum == ViewProvider::Default) {
Gui::Control().closeDialog();
}
else {
ViewProviderDrawingView::unsetEdit(ModNum);
}
}
void ViewProviderDimension::updateData(const App::Property* p)
{
if (p == &(getViewObject()->Type)) {
if (getViewObject()->Type.isValue("DistanceX")) {
sPixmap = "TechDraw_HorizontalDimension";
} else if (getViewObject()->Type.isValue("DistanceY")) {
sPixmap = "TechDraw_VerticalDimension";
} else if (getViewObject()->Type.isValue("Radius")) {
sPixmap = "TechDraw_RadiusDimension";
} else if (getViewObject()->Type.isValue("Diameter")) {
sPixmap = "TechDraw_DiameterDimension";
} else if (getViewObject()->Type.isValue("Angle")) {
sPixmap = "TechDraw_AngleDimension";
} else if (getViewObject()->Type.isValue("Angle3Pt")) {
sPixmap = "TechDraw_3PtAngleDimension";
}
}
ViewProviderDrawingView::updateData(p);
}
void ViewProviderDimension::onChanged(const App::Property* p)
{
if ((p == &Font) ||
(p == &Fontsize) ||
(p == &LineWidth) ||
(p == &StandardAndStyle) ||
(p == &RenderingExtent) ||
(p == &FlipArrowheads))
{
QGIView* qgiv = getQView();
if (qgiv) {
qgiv->updateView(true);
}
}
if (p == &Color) {
QGIView* qgiv = getQView();
if (qgiv) {
QGIViewDimension* qgivd = dynamic_cast<QGIViewDimension*>(qgiv);
if (qgivd != nullptr) {
qgivd->setNormalColorAll();
}
}
}
ViewProviderDrawingView::onChanged(p);
}
TechDraw::DrawViewDimension* ViewProviderDimension::getViewObject() const
{
return dynamic_cast<TechDraw::DrawViewDimension*>(pcObject);
}
App::Color ViewProviderDimension::prefColor() const
{
return PreferencesGui::dimColor();
}
std::string ViewProviderDimension::prefFont() const
{
return Preferences::labelFont();
}
double ViewProviderDimension::prefFontSize() const
{
return Preferences::dimFontSizeMM();
}
double ViewProviderDimension::prefWeight() const
{
int lgNumber = Preferences::lineGroup();
auto lg = TechDraw::LineGroup::lineGroupFactory(lgNumber);
double weight = lg->getWeight("Thin");
delete lg; //Coverity CID 174670
return weight;
}
int ViewProviderDimension::prefStandardAndStyle() const
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->
GetGroup("Mod/TechDraw/Dimensions");
int standardStyle = hGrp->GetInt("StandardAndStyle", STD_STYLE_ISO_ORIENTED);
return standardStyle;
}
void ViewProviderDimension::handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property *prop)
// transforms properties that had been changed
{
// property LineWidth had the App::PropertyFloat and was changed to App::PropertyLength
if (prop == &LineWidth && strcmp(TypeName, "App::PropertyFloat") == 0) {
App::PropertyFloat LineWidthProperty;
// restore the PropertyFloat to be able to set its value
LineWidthProperty.Restore(reader);
LineWidth.setValue(LineWidthProperty.getValue());
}
}
bool ViewProviderDimension::canDelete(App::DocumentObject *obj) const
{
// deletions of dimension objects don't destroy anything
// thus we can pass this action
Q_UNUSED(obj)
return true;
}