FreeCAD

Форк
0
/
ViewProviderDimension.cpp 
307 строк · 11.7 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de>              *
3
 *   Copyright (c) 2012 Luke Parry <l.parry@warwick.ac.uk>                 *
4
 *                                                                         *
5
 *   This file is part of the FreeCAD CAx development system.              *
6
 *                                                                         *
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.      *
11
 *                                                                         *
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.                  *
16
 *                                                                         *
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                                *
21
 *                                                                         *
22
 ***************************************************************************/
23

24

25
#include "PreCompiled.h"
26

27
#ifndef _PreComp_
28
# include <QAction>
29
# include <QColor>
30
# include <QMenu>
31
#endif
32

33
#include <QMessageBox>
34

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>
41

42
#include <Mod/TechDraw/App/LineGroup.h>
43
#include <Mod/TechDraw/App/LandmarkDimension.h>
44

45
#include "PreferencesGui.h"
46
#include "ZVALUE.h"
47
#include "TaskDimension.h"
48
#include "QGIViewDimension.h"
49
#include "ViewProviderDimension.h"
50

51
using namespace TechDrawGui;
52
using namespace TechDraw;
53

54
const char *ViewProviderDimension::StandardAndStyleEnums[]=
55
    { "ISO Oriented", "ISO Referencing", "ASME Inlined", "ASME Referencing", nullptr };
56

57
const char *ViewProviderDimension::RenderingExtentEnums[]=
58
    { "None", "Minimal", "Confined", "Reduced", "Normal", "Expanded", nullptr };
59

60
PROPERTY_SOURCE(TechDrawGui::ViewProviderDimension, TechDrawGui::ViewProviderDrawingView)
61

62
//**************************************************************************
63
// Construction/Destruction
64

65
ViewProviderDimension::ViewProviderDimension()
66
{
67
    sPixmap = "TechDraw_Dimension";
68

69
    static const char *group = "Dimension Format";
70

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);
85

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");
97

98
   StackOrder.setValue(ZVALUE::DIMENSION);
99
}
100

101
ViewProviderDimension::~ViewProviderDimension()
102
{
103
}
104

105
void ViewProviderDimension::attach(App::DocumentObject *pcFeat)
106
{
107
    // call parent attach method
108
    ViewProviderDrawingView::attach(pcFeat);
109

110
//    sPixmap = "TechDraw_Dimension";
111
    setPixmapForType();
112
    if (getViewObject()->isDerivedFrom(TechDraw::LandmarkDimension::getClassTypeId())) {
113
        sPixmap = "TechDraw_LandmarkDimension";
114
    }
115
}
116

117
bool ViewProviderDimension::doubleClicked()
118
{
119
    startDefaultEditMode();
120
    return true;
121
}
122

123
void ViewProviderDimension::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
124
{
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();
130
    });
131

132
    ViewProviderDrawingView::setupContextMenu(menu, receiver, member);
133
}
134

135
bool ViewProviderDimension::setEdit(int ModNum)
136
{
137
    if (ModNum != ViewProvider::Default) {
138
        return ViewProviderDrawingView::setEdit(ModNum);
139
    }
140
    if (Gui::Control().activeDialog()) { // if TaskPanel already open
141
        return false;
142
    }
143
    // clear the selection (convenience)
144
    Gui::Selection().clearSelection();
145
    auto qgivDimension(dynamic_cast<QGIViewDimension*>(getQView()));
146
    if (qgivDimension) {
147
        Gui::Control().showDialog(new TaskDlgDimension(qgivDimension, this));
148
    }
149
    return true;
150
}
151

152
void ViewProviderDimension::updateData(const App::Property* prop)
153
{
154
    if (prop == &(getViewObject()->Type)) {
155
        setPixmapForType();
156
    }
157

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) ) {
173

174
        QGIView* qgiv = getQView();
175
        if (qgiv) {
176
            qgiv->updateView(true);
177
        }
178
        return;
179
    }
180

181
    //Skip QGIView X, Y processing - do not call ViewProviderDrawingView
182
    Gui::ViewProviderDocumentObject::updateData(prop);
183
}
184

185
void ViewProviderDimension::setPixmapForType()
186
{
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";
199
    }
200
}
201

202
void ViewProviderDimension::onChanged(const App::Property* p)
203
{
204
    if ((p == &Font)  ||
205
        (p == &Fontsize) ||
206
        (p == &Arrowsize) ||
207
        (p == &LineWidth) ||
208
        (p == &StandardAndStyle) ||
209
        (p == &RenderingExtent) ||
210
        (p == &FlipArrowheads) ||
211
        (p == &GapFactorASME) ||
212
        (p == &GapFactorISO) ||
213
        p == &LineSpacingFactorISO)  {
214
        QGIView* qgiv = getQView();
215
        if (qgiv) {
216
            qgiv->updateView(true);
217
        }
218
    }
219
    if (p == &Color) {
220
        QGIView* qgiv = getQView();
221
        if (qgiv) {
222
            QGIViewDimension* qgivd = dynamic_cast<QGIViewDimension*>(qgiv);
223
            if (qgivd) {
224
                qgivd->setNormalColorAll();
225
            }
226
        }
227
    }
228

229
    ViewProviderDrawingView::onChanged(p);
230
}
231

232
TechDraw::DrawViewDimension* ViewProviderDimension::getViewObject() const
233
{
234
    return dynamic_cast<TechDraw::DrawViewDimension*>(pcObject);
235
}
236

237
App::Color ViewProviderDimension::prefColor() const
238
{
239
   return PreferencesGui::dimColor();
240
}
241

242
std::string ViewProviderDimension::prefFont() const
243
{
244
    return Preferences::labelFont();
245
}
246

247
double ViewProviderDimension::prefFontSize() const
248
{
249
    return Preferences::dimFontSizeMM();
250
}
251

252
double ViewProviderDimension::prefArrowSize() const
253
{
254
    return Preferences::dimArrowSize();
255
}
256

257
double ViewProviderDimension::prefWeight() const
258
{
259
    return TechDraw::LineGroup::getDefaultWidth("Thin");
260
}
261

262
int ViewProviderDimension::prefStandardAndStyle() const
263
{
264
    return Preferences::getPreferenceGroup("Dimensions")->GetInt("StandardAndStyle", STD_STYLE_ISO_ORIENTED);
265
}
266

267
void ViewProviderDimension::handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property *prop)
268
// transforms properties that had been changed
269
{
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());
276
    }
277
    else {
278
        ViewProviderDrawingView::handleChangedPropertyType(reader, TypeName, prop);
279
    }
280
}
281

282
bool ViewProviderDimension::canDelete(App::DocumentObject *obj) const
283
{
284
    // deletions of dimension objects don't destroy anything
285
    // thus we can pass this action
286
    Q_UNUSED(obj)
287
    return true;
288
}
289

290
bool ViewProviderDimension::onDelete(const std::vector<std::string> & parms)
291
{
292
    Q_UNUSED(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);
296
    if (ourDlg)  {
297
        QString bodyMessage;
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,
303
            QMessageBox::Ok);
304
        return false;
305
    }
306
    return true;
307
}
308

309

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.