1
/***************************************************************************
2
* Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de> *
3
* Copyright (c) 2012 Luke Parry <l.parry@warwick.ac.uk> *
5
* This file is part of the FreeCAD CAx development system. *
7
* This library is free software; you can redistribute it and/or *
8
* modify it under the terms of the GNU Library General Public *
9
* License as published by the Free Software Foundation; either *
10
* version 2 of the License, or (at your option) any later version. *
12
* This library is distributed in the hope that it will be useful, *
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
* GNU Library General Public License for more details. *
17
* You should have received a copy of the GNU Library General Public *
18
* License along with this library; see the file COPYING.LIB. If not, *
19
* write to the Free Software Foundation, Inc., 59 Temple Place, *
20
* Suite 330, Boston, MA 02111-1307, USA *
22
***************************************************************************/
25
#include "PreCompiled.h"
35
#include <Base/Parameter.h>
36
#include <App/Application.h>
37
#include <App/DocumentObject.h>
38
#include <Gui/ActionFunction.h>
39
#include <Gui/Control.h>
40
#include <Gui/MainWindow.h>
42
#include <Mod/TechDraw/App/LineGroup.h>
43
#include <Mod/TechDraw/App/LandmarkDimension.h>
45
#include "PreferencesGui.h"
47
#include "TaskDimension.h"
48
#include "QGIViewDimension.h"
49
#include "ViewProviderDimension.h"
51
using namespace TechDrawGui;
52
using namespace TechDraw;
54
const char *ViewProviderDimension::StandardAndStyleEnums[]=
55
{ "ISO Oriented", "ISO Referencing", "ASME Inlined", "ASME Referencing", nullptr };
57
const char *ViewProviderDimension::RenderingExtentEnums[]=
58
{ "None", "Minimal", "Confined", "Reduced", "Normal", "Expanded", nullptr };
60
PROPERTY_SOURCE(TechDrawGui::ViewProviderDimension, TechDrawGui::ViewProviderDrawingView)
62
//**************************************************************************
63
// Construction/Destruction
65
ViewProviderDimension::ViewProviderDimension()
67
sPixmap = "TechDraw_Dimension";
69
static const char *group = "Dimension Format";
71
ADD_PROPERTY_TYPE(Font, (Preferences::labelFont().c_str()),
72
group, App::Prop_None, "The name of the font to use");
73
ADD_PROPERTY_TYPE(Fontsize, (Preferences::dimFontSizeMM()),
74
group, (App::PropertyType)(App::Prop_None),
75
"Dimension text size in units");
76
ADD_PROPERTY_TYPE(Arrowsize, (Preferences::dimArrowSize()),
77
group, (App::PropertyType)(App::Prop_None),
78
"Arrow size in units");
79
ADD_PROPERTY_TYPE(LineWidth, (prefWeight()), group, (App::PropertyType)(App::Prop_None),
80
"Dimension line width");
81
ADD_PROPERTY_TYPE(Color, (prefColor()), group, App::Prop_None, "Color of the dimension");
82
ADD_PROPERTY_TYPE(StandardAndStyle, (prefStandardAndStyle()), group, App::Prop_None,
83
"Standard and style according to which dimension is drawn");
84
StandardAndStyle.setEnums(StandardAndStyleEnums);
86
ADD_PROPERTY_TYPE(RenderingExtent, (REND_EXTENT_NORMAL), group, App::Prop_None,
87
"Select the rendering mode by space requirements");
88
RenderingExtent.setEnums(RenderingExtentEnums);
89
ADD_PROPERTY_TYPE(FlipArrowheads, (false), group, App::Prop_None,
90
"Reverses usual direction of dimension line terminators");
91
ADD_PROPERTY_TYPE(GapFactorISO, (Preferences::GapISO()), group, App::Prop_None,
92
"Adjusts the gap between dimension point and extension line");
93
ADD_PROPERTY_TYPE(GapFactorASME, (Preferences::GapASME()), group, App::Prop_None,
94
"Adjusts the gap between dimension point and extension line");
95
ADD_PROPERTY_TYPE(LineSpacingFactorISO, (Preferences::LineSpacingISO()), group, App::Prop_None,
96
"Adjusts the gap between dimension line and dimension text");
98
StackOrder.setValue(ZVALUE::DIMENSION);
101
ViewProviderDimension::~ViewProviderDimension()
105
void ViewProviderDimension::attach(App::DocumentObject *pcFeat)
107
// call parent attach method
108
ViewProviderDrawingView::attach(pcFeat);
110
// sPixmap = "TechDraw_Dimension";
112
if (getViewObject()->isDerivedFrom(TechDraw::LandmarkDimension::getClassTypeId())) {
113
sPixmap = "TechDraw_LandmarkDimension";
117
bool ViewProviderDimension::doubleClicked()
119
startDefaultEditMode();
123
void ViewProviderDimension::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
125
Gui::ActionFunction* func = new Gui::ActionFunction(menu);
126
QAction* act = menu->addAction(QObject::tr("Edit %1").arg(QString::fromUtf8(getObject()->Label.getValue())));
127
act->setData(QVariant((int)ViewProvider::Default));
128
func->trigger(act, [this](){
129
this->startDefaultEditMode();
132
ViewProviderDrawingView::setupContextMenu(menu, receiver, member);
135
bool ViewProviderDimension::setEdit(int ModNum)
137
if (ModNum != ViewProvider::Default) {
138
return ViewProviderDrawingView::setEdit(ModNum);
140
if (Gui::Control().activeDialog()) { // if TaskPanel already open
143
// clear the selection (convenience)
144
Gui::Selection().clearSelection();
145
auto qgivDimension(dynamic_cast<QGIViewDimension*>(getQView()));
147
Gui::Control().showDialog(new TaskDlgDimension(qgivDimension, this));
152
void ViewProviderDimension::updateData(const App::Property* prop)
154
if (prop == &(getViewObject()->Type)) {
158
//Dimension handles X, Y updates differently that other QGIView
159
//call QGIViewDimension::updateView
160
if (prop == &(getViewObject()->X) ||
161
prop == &(getViewObject()->Y) ||
162
prop == &(getViewObject()->FormatSpec) ||
163
prop == &(getViewObject()->Arbitrary) ||
164
prop == &(getViewObject()->FormatSpecOverTolerance) ||
165
prop == &(getViewObject()->FormatSpecUnderTolerance) ||
166
prop == &(getViewObject()->ArbitraryTolerances) ||
167
prop == &(getViewObject()->MeasureType) ||
168
prop == &(getViewObject()->TheoreticalExact) ||
169
prop == &(getViewObject()->EqualTolerance) ||
170
prop == &(getViewObject()->OverTolerance) ||
171
prop == &(getViewObject()->UnderTolerance) ||
172
prop == &(getViewObject()->Inverted) ) {
174
QGIView* qgiv = getQView();
176
qgiv->updateView(true);
181
//Skip QGIView X, Y processing - do not call ViewProviderDrawingView
182
Gui::ViewProviderDocumentObject::updateData(prop);
185
void ViewProviderDimension::setPixmapForType()
187
if (getViewObject()->Type.isValue("DistanceX")) {
188
sPixmap = "TechDraw_HorizontalDimension";
189
} else if (getViewObject()->Type.isValue("DistanceY")) {
190
sPixmap = "TechDraw_VerticalDimension";
191
} else if (getViewObject()->Type.isValue("Radius")) {
192
sPixmap = "TechDraw_RadiusDimension";
193
} else if (getViewObject()->Type.isValue("Diameter")) {
194
sPixmap = "TechDraw_DiameterDimension";
195
} else if (getViewObject()->Type.isValue("Angle")) {
196
sPixmap = "TechDraw_AngleDimension";
197
} else if (getViewObject()->Type.isValue("Angle3Pt")) {
198
sPixmap = "TechDraw_3PtAngleDimension";
202
void ViewProviderDimension::onChanged(const App::Property* p)
208
(p == &StandardAndStyle) ||
209
(p == &RenderingExtent) ||
210
(p == &FlipArrowheads) ||
211
(p == &GapFactorASME) ||
212
(p == &GapFactorISO) ||
213
p == &LineSpacingFactorISO) {
214
QGIView* qgiv = getQView();
216
qgiv->updateView(true);
220
QGIView* qgiv = getQView();
222
QGIViewDimension* qgivd = dynamic_cast<QGIViewDimension*>(qgiv);
224
qgivd->setNormalColorAll();
229
ViewProviderDrawingView::onChanged(p);
232
TechDraw::DrawViewDimension* ViewProviderDimension::getViewObject() const
234
return dynamic_cast<TechDraw::DrawViewDimension*>(pcObject);
237
App::Color ViewProviderDimension::prefColor() const
239
return PreferencesGui::dimColor();
242
std::string ViewProviderDimension::prefFont() const
244
return Preferences::labelFont();
247
double ViewProviderDimension::prefFontSize() const
249
return Preferences::dimFontSizeMM();
252
double ViewProviderDimension::prefArrowSize() const
254
return Preferences::dimArrowSize();
257
double ViewProviderDimension::prefWeight() const
259
return TechDraw::LineGroup::getDefaultWidth("Thin");
262
int ViewProviderDimension::prefStandardAndStyle() const
264
return Preferences::getPreferenceGroup("Dimensions")->GetInt("StandardAndStyle", STD_STYLE_ISO_ORIENTED);
267
void ViewProviderDimension::handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property *prop)
268
// transforms properties that had been changed
270
// property LineWidth had the App::PropertyFloat and was changed to App::PropertyLength
271
if (prop == &LineWidth && strcmp(TypeName, "App::PropertyFloat") == 0) {
272
App::PropertyFloat LineWidthProperty;
273
// restore the PropertyFloat to be able to set its value
274
LineWidthProperty.Restore(reader);
275
LineWidth.setValue(LineWidthProperty.getValue());
278
ViewProviderDrawingView::handleChangedPropertyType(reader, TypeName, prop);
282
bool ViewProviderDimension::canDelete(App::DocumentObject *obj) const
284
// deletions of dimension objects don't destroy anything
285
// thus we can pass this action
290
bool ViewProviderDimension::onDelete(const std::vector<std::string> & parms)
293
// Base::Console().Message("VPB::onDelete() - parms: %d\n", parms.size());
294
auto dlg = Gui::Control().activeDialog();
295
auto ourDlg = dynamic_cast<TaskDlgDimension*>(dlg);
298
QTextStream bodyMessageStream(&bodyMessage);
299
bodyMessageStream << qApp->translate("TaskDimension",
300
"You cannot delete this dimension now because\nthere is an open task dialog.");
301
QMessageBox::warning(Gui::getMainWindow(),
302
qApp->translate("TaskDimension", "Can Not Delete"), bodyMessage,