/
ViewProviderWeld.cpp
199 lines (168 loc) · 6.72 KB
/
ViewProviderWeld.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
/***************************************************************************
* Copyright (c) 2019 Wanderer Fan <wandererfan@gmail.com> *
* *
* 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_
#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/Control.h>
#include <Gui/Command.h>
#include <Gui/Document.h>
#include <Gui/MainWindow.h>
#include <Gui/Selection.h>
#include "TaskWeldingSymbol.h"
#include "ViewProviderWeld.h"
using namespace TechDrawGui;
PROPERTY_SOURCE(TechDrawGui::ViewProviderWeld, TechDrawGui::ViewProviderDrawingView)
//**************************************************************************
// Construction/Destruction
ViewProviderWeld::ViewProviderWeld()
{
sPixmap = "actions/techdraw-weldsymbol";
static const char *group = "Text";
ADD_PROPERTY_TYPE(Font, (prefFontName().c_str()),group,App::Prop_None, "The name of the font to use");
ADD_PROPERTY_TYPE(FontSize, (prefFontSize()), group,
(App::PropertyType)(App::Prop_None),"Tail text size");
ADD_PROPERTY_TYPE(TileFontSize, (prefFontSize() * prefTileTextAdjust()), group,
(App::PropertyType)(App::Prop_None),"Text size on individual symbol tiles");
}
ViewProviderWeld::~ViewProviderWeld()
{
}
void ViewProviderWeld::attach(App::DocumentObject *pcFeat)
{
// call parent attach method
ViewProviderDrawingView::attach(pcFeat);
}
void ViewProviderWeld::setDisplayMode(const char* ModeName)
{
ViewProviderDrawingView::setDisplayMode(ModeName);
}
std::vector<std::string> ViewProviderWeld::getDisplayModes(void) const
{
// get the modes of the father
std::vector<std::string> StrList = ViewProviderDrawingView::getDisplayModes();
return StrList;
}
void ViewProviderWeld::updateData(const App::Property* prop)
{
ViewProviderDrawingView::updateData(prop);
}
void ViewProviderWeld::onChanged(const App::Property* p)
{
QGIView* qgiv = getQView();
if (qgiv) {
qgiv->updateView(true);
}
ViewProviderDrawingView::onChanged(p);
}
std::vector<App::DocumentObject*> ViewProviderWeld::claimChildren(void) const
{
// Collect any child Document Objects and put them in the right place in the Feature tree
// valid children of a DrawWeldSymbol are:
// - DrawTiles
std::vector<App::DocumentObject*> temp;
const std::vector<App::DocumentObject *> &tiles = getFeature()->getInList();
try {
for(std::vector<App::DocumentObject *>::const_iterator it = tiles.begin(); it != tiles.end(); ++it) {
if ((*it)->getTypeId().isDerivedFrom(TechDraw::DrawTile::getClassTypeId())) {
temp.push_back((*it));
}
}
return temp;
} catch (...) {
std::vector<App::DocumentObject*> tmp;
return tmp;
}
}
bool ViewProviderWeld::setEdit(int ModNum)
{
// Base::Console().Message("VPW::setEdit(%d)\n",ModNum);
if (ModNum == ViewProvider::Default ) {
if (Gui::Control().activeDialog()) { //TaskPanel already open!
return false;
}
// clear the selection (convenience)
Gui::Selection().clearSelection();
Gui::Control().showDialog(new TaskDlgWeldingSymbol(getFeature()));
return true;
} else {
return ViewProviderDrawingView::setEdit(ModNum);
}
return true;
}
void ViewProviderWeld::unsetEdit(int ModNum)
{
Q_UNUSED(ModNum);
if (ModNum == ViewProvider::Default) {
Gui::Control().closeDialog();
}
else {
ViewProviderDrawingView::unsetEdit(ModNum);
}
}
bool ViewProviderWeld::doubleClicked(void)
{
// Base::Console().Message("VPW::doubleClicked()\n");
setEdit(ViewProvider::Default);
return true;
}
std::string ViewProviderWeld::prefFontName(void)
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->
GetGroup("Mod/TechDraw/Labels");
std::string fontName = hGrp->GetASCII("LabelFont", "osifont");
return fontName;
}
double ViewProviderWeld::prefFontSize(void)
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->
GetGroup("Mod/TechDraw/Dimensions");
double fontSize = hGrp->GetFloat("FontSize", QGIView::DefaultFontSizeInMM);
return fontSize;
}
double ViewProviderWeld::prefTileTextAdjust(void)
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->
GetGroup("Mod/TechDraw/Dimensions");
double adjust = hGrp->GetFloat("TileTextAdjust", 0.75);
return adjust;
}
TechDraw::DrawWeldSymbol* ViewProviderWeld::getViewObject() const
{
return dynamic_cast<TechDraw::DrawWeldSymbol*>(pcObject);
}
TechDraw::DrawWeldSymbol* ViewProviderWeld::getFeature() const
{
return getViewObject();
}