23
#include "PreCompiled.h"
33
#include <App/Application.h>
34
#include <App/Document.h>
35
#include <App/DocumentObject.h>
36
#include <Base/Parameter.h>
37
#include <Gui/Control.h>
38
#include <Gui/MainWindow.h>
39
#include <Gui/Selection.h>
41
#include <Mod/TechDraw/App/DrawGeomHatch.h>
42
#include <Mod/TechDraw/App/DrawHatch.h>
43
#include <Mod/TechDraw/App/DrawLeaderLine.h>
44
#include <Mod/TechDraw/App/DrawRichAnno.h>
45
#include <Mod/TechDraw/App/DrawViewBalloon.h>
46
#include <Mod/TechDraw/App/DrawViewDetail.h>
47
#include <Mod/TechDraw/App/DrawViewDimension.h>
48
#include <Mod/TechDraw/App/DrawViewMulti.h>
49
#include <Mod/TechDraw/App/LineGroup.h>
50
#include <Mod/TechDraw/App/Cosmetic.h>
51
#include <Mod/TechDraw/App/CenterLine.h>
52
#include <Mod/TechDraw/App/LineNameEnum.h>
53
#include <Mod/TechDraw/App/LineGenerator.h>
56
#include "PreferencesGui.h"
58
#include "TaskDetail.h"
59
#include "ViewProviderViewPart.h"
60
#include "ViewProviderPage.h"
61
#include "QGIViewDimension.h"
62
#include "QGIViewBalloon.h"
65
using namespace TechDrawGui;
66
using namespace TechDraw;
69
PROPERTY_SOURCE(TechDrawGui::ViewProviderViewPart, TechDrawGui::ViewProviderDrawingView)
72
const App::PropertyIntegerConstraint::Constraints intPercent = { 0, 100, 5 };
77
ViewProviderViewPart::ViewProviderViewPart()
79
sPixmap = "TechDraw_TreeView";
81
static const char *group = "Lines";
82
static const char *dgroup = "Decoration";
83
static const char *hgroup = "Highlight";
84
static const char *sgroup = "Section Line";
85
static const char *fgroup = "Faces";
89
double weight = TechDraw::LineGroup::getDefaultWidth("Thick");
90
ADD_PROPERTY_TYPE(LineWidth, (weight), group, App::Prop_None, "The thickness of visible lines (line groups xx.2");
92
weight = TechDraw::LineGroup::getDefaultWidth("Thin");
93
ADD_PROPERTY_TYPE(HiddenWidth, (weight), group, App::Prop_None, "The thickness of hidden lines, if enabled (line groups xx.1)");
95
weight = TechDraw::LineGroup::getDefaultWidth("Graphic");
96
ADD_PROPERTY_TYPE(IsoWidth, (weight), group, App::Prop_None, "The thickness of isoparameter lines, if enabled");
98
weight = TechDraw::LineGroup::getDefaultWidth("Extra");
99
ADD_PROPERTY_TYPE(ExtraWidth, (weight), group, App::Prop_None, "The thickness of LineGroup Extra lines, if enabled");
101
double defScale = Preferences::getPreferenceGroup("Decorations")->GetFloat("CenterMarkScale", 0.50);
102
bool defShowCenters = Preferences::getPreferenceGroup("Decorations")->GetBool("ShowCenterMarks", false);
105
ADD_PROPERTY_TYPE(HorizCenterLine ,(false), dgroup, App::Prop_None, "Show a horizontal centerline through view");
106
ADD_PROPERTY_TYPE(VertCenterLine ,(false), dgroup, App::Prop_None, "Show a vertical centerline through view");
107
ADD_PROPERTY_TYPE(ArcCenterMarks ,(defShowCenters), dgroup, App::Prop_None, "Center marks on/off");
108
ADD_PROPERTY_TYPE(CenterScale, (defScale), dgroup, App::Prop_None, "Center mark size adjustment, if enabled");
111
ADD_PROPERTY_TYPE(ShowSectionLine ,(true) ,sgroup, App::Prop_None, "Show/hide section line if applicable");
112
ADD_PROPERTY_TYPE(SectionLineStyle, (Preferences::SectionLineStyle()), sgroup, App::Prop_None,
113
"Set section line style if applicable");
114
ADD_PROPERTY_TYPE(SectionLineColor, (prefSectionColor()), sgroup, App::Prop_None,
115
"Set section line color if applicable");
117
bool marksDefault = Preferences::sectionLineConvention() == 1 ? true : false;
118
ADD_PROPERTY_TYPE(SectionLineMarks, (marksDefault), sgroup, App::Prop_None,
119
"Show marks at direction changes for ComplexSection");
122
ADD_PROPERTY_TYPE(HighlightLineStyle, (prefHighlightStyle()), hgroup, App::Prop_None,
123
"Set highlight line style if applicable");
124
ADD_PROPERTY_TYPE(HighlightLineColor, (prefHighlightColor()), hgroup, App::Prop_None,
125
"Set highlight line color if applicable");
126
ADD_PROPERTY_TYPE(HighlightAdjust, (0.0), hgroup, App::Prop_None, "Adjusts the rotation of the Detail highlight");
128
ADD_PROPERTY_TYPE(ShowAllEdges ,(false),dgroup, App::Prop_None, "Temporarily show invisible lines");
131
ADD_PROPERTY_TYPE(FaceColor, (Preferences::getPreferenceGroup("Colors")->GetUnsigned("FaceColor", 0xFFFFFF)),
132
fgroup, App::Prop_None, "Set color of faces");
133
ADD_PROPERTY_TYPE(FaceTransparency, (Preferences::getPreferenceGroup("Colors")->GetBool("ClearFace", false) ? 100 : 0),
134
fgroup, App::Prop_None, "Set transparency of faces");
135
FaceTransparency.setConstraints(&intPercent);
137
std::string bodyName = LineGenerator::getLineStandardsBody();
138
if (bodyName == "ISO") {
139
SectionLineStyle.setEnums(ISOLineName::ISOLineNameEnums);
140
HighlightLineStyle.setEnums(ISOLineName::ISOLineNameEnums);
141
} else if (bodyName == "ANSI") {
142
SectionLineStyle.setEnums(ANSILineName::ANSILineNameEnums);
143
HighlightLineStyle.setEnums(ANSILineName::ANSILineNameEnums);
144
} else if (bodyName == "ASME") {
145
SectionLineStyle.setEnums(ASMELineName::ASMELineNameEnums);
146
HighlightLineStyle.setEnums(ASMELineName::ASMELineNameEnums);
150
ViewProviderViewPart::~ViewProviderViewPart()
155
void ViewProviderViewPart::onChanged(const App::Property* prop)
157
if (auto part = getViewPart(); part && part->isDerivedFrom(TechDraw::DrawViewDetail::getClassTypeId()) &&
158
prop == &(HighlightAdjust)) {
159
auto detail = static_cast<DrawViewDetail*>(getViewPart());
160
auto baseDvp = dynamic_cast<DrawViewPart*>(detail->BaseView.getValue());
162
baseDvp->requestPaint();
167
if (prop == &(LineWidth) ||
168
prop == &(HiddenWidth) ||
169
prop == &(IsoWidth) ||
170
prop == &(ExtraWidth) ||
171
prop == &(HighlightAdjust) ||
172
prop == &(ArcCenterMarks) ||
173
prop == &(CenterScale) ||
174
prop == &(ShowSectionLine) ||
175
prop == &(SectionLineStyle) ||
176
prop == &(SectionLineColor) ||
177
prop == &(SectionLineMarks) ||
178
prop == &(HighlightLineStyle) ||
179
prop == &(HighlightLineColor) ||
180
prop == &(HorizCenterLine) ||
181
prop == &(VertCenterLine) ||
182
prop == &(FaceColor) ||
183
prop == &(FaceTransparency)) {
185
QGIView* qgiv = getQView();
187
qgiv->updateView(true);
191
ViewProviderDrawingView::onChanged(prop);
195
void ViewProviderViewPart::attach(App::DocumentObject *pcFeat)
198
TechDraw::DrawViewMulti* dvm = dynamic_cast<TechDraw::DrawViewMulti*>(pcFeat);
199
TechDraw::DrawViewDetail* dvd = dynamic_cast<TechDraw::DrawViewDetail*>(pcFeat);
201
sPixmap = "TechDraw_TreeMulti";
203
sPixmap = "actions/TechDraw_DetailView";
206
ViewProviderDrawingView::attach(pcFeat);
209
std::vector<App::DocumentObject*> ViewProviderViewPart::claimChildren() const
218
std::vector<App::DocumentObject*> temp;
219
const std::vector<App::DocumentObject *> &views = getViewPart()->getInList();
221
for(std::vector<App::DocumentObject *>::const_iterator it = views.begin(); it != views.end(); ++it) {
222
auto view = dynamic_cast<TechDraw::DrawView *>(*it);
223
if (view && view->claimParent() == getViewPart()) {
224
temp.push_back(view);
228
if((*it)->isDerivedFrom<TechDraw::DrawViewDimension>()) {
231
std::string dimName = (*it)->getNameInDocument();
232
for (auto& t: temp) {
233
std::string tName = t->getNameInDocument();
234
if (dimName == tName) {
242
} else if ((*it)->isDerivedFrom<TechDraw::DrawHatch>()) {
243
temp.push_back((*it));
244
} else if ((*it)->isDerivedFrom<TechDraw::DrawGeomHatch>()) {
245
temp.push_back((*it));
246
} else if ((*it)->isDerivedFrom<TechDraw::DrawViewBalloon>()) {
247
temp.push_back((*it));
248
} else if ((*it)->isDerivedFrom<TechDraw::DrawLeaderLine>()) {
249
temp.push_back((*it));
254
return std::vector<App::DocumentObject*>();
258
bool ViewProviderViewPart::setEdit(int ModNum)
260
if (ModNum != ViewProvider::Default ) {
261
return ViewProviderDrawingView::setEdit(ModNum);
264
if (Gui::Control().activeDialog()) {
267
TechDraw::DrawViewPart* dvp = getViewObject();
268
TechDraw::DrawViewDetail* dvd = dynamic_cast<TechDraw::DrawViewDetail*>(dvp);
270
if (!dvd->BaseView.getValue()) {
271
Base::Console().Error("DrawViewDetail - %s - has no BaseView!\n", dvd->getNameInDocument());
275
Gui::Selection().clearSelection();
276
Gui::Control().showDialog(new TaskDlgDetail(dvd));
277
Gui::Selection().clearSelection();
278
Gui::Selection().addSelection(dvd->getDocument()->getName(),
279
dvd->getNameInDocument());
285
bool ViewProviderViewPart::doubleClicked()
287
setEdit(ViewProvider::Default);
291
TechDraw::DrawViewPart* ViewProviderViewPart::getViewObject() const
293
return dynamic_cast<TechDraw::DrawViewPart*>(pcObject);
296
TechDraw::DrawViewPart* ViewProviderViewPart::getViewPart() const
298
return getViewObject();
301
void ViewProviderViewPart::handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property *prop)
305
if (prop == &LineWidth && strcmp(TypeName, "App::PropertyFloat") == 0) {
306
App::PropertyFloat LineWidthProperty;
308
LineWidthProperty.Restore(reader);
309
LineWidth.setValue(LineWidthProperty.getValue());
312
else if (prop == &HiddenWidth && strcmp(TypeName, "App::PropertyFloat") == 0) {
313
App::PropertyFloat HiddenWidthProperty;
314
HiddenWidthProperty.Restore(reader);
315
HiddenWidth.setValue(HiddenWidthProperty.getValue());
318
else if (prop == &IsoWidth && strcmp(TypeName, "App::PropertyFloat") == 0) {
319
App::PropertyFloat IsoWidthProperty;
320
IsoWidthProperty.Restore(reader);
321
IsoWidth.setValue(IsoWidthProperty.getValue());
324
else if (prop == &ExtraWidth && strcmp(TypeName, "App::PropertyFloat") == 0) {
325
App::PropertyFloat ExtraWidthProperty;
326
ExtraWidthProperty.Restore(reader);
327
ExtraWidth.setValue(ExtraWidthProperty.getValue());
330
ViewProviderDrawingView::handleChangedPropertyType(reader, TypeName, prop);
334
bool ViewProviderViewPart::onDelete(const std::vector<std::string> & subNames)
338
std::vector<std::string> removables = getSelectedCosmetics(subNames);
339
if (!removables.empty()) {
341
deleteCosmeticElements(removables);
342
getViewObject()->recomputeFeature();
348
QTextStream bodyMessageStream(&bodyMessage);
351
auto viewSection = getViewObject()->getSectionRefs();
352
auto viewDetail = getViewObject()->getDetailRefs();
354
if (!viewSection.empty() || !viewDetail.empty()) {
355
bodyMessageStream << qApp->translate("Std_Delete",
356
"You cannot delete this view because it has one or more dependent views that would become broken.");
357
QMessageBox::warning(Gui::getMainWindow(),
358
qApp->translate("Std_Delete", "Object dependencies"), bodyMessage,
365
bool ViewProviderViewPart::canDelete(App::DocumentObject *obj) const
374
std::vector<std::string> ViewProviderViewPart::getSelectedCosmetics(std::vector<std::string> subNames)
377
std::vector<std::string> result;
379
for (auto& sub : subNames) {
380
if (DU::getGeomTypeFromName(sub) == "Vertex") {
381
if (DU::isCosmeticVertex(getViewObject(), sub)) {
382
result.emplace_back(sub);
384
} else if (DU::getGeomTypeFromName(sub) == "Edge") {
385
if (DU::isCosmeticEdge(getViewObject(), sub) ||
386
DU::isCenterLine(getViewObject(), sub)) {
387
result.emplace_back(sub);
395
void ViewProviderViewPart::deleteCosmeticElements(std::vector<std::string> removables)
397
for (auto& name : removables) {
398
if (DU::getGeomTypeFromName(name) == "Vertex") {
399
CosmeticVertex* vert = getViewObject()->getCosmeticVertexBySelection(name);
400
getViewObject()->removeCosmeticVertex(vert->getTagAsString());
403
if (DU::getGeomTypeFromName(name) == "Edge") {
404
CosmeticEdge* edge = getViewObject()->getCosmeticEdgeBySelection(name);
407
getViewObject()->removeCosmeticEdge(edge->getTagAsString());
410
CenterLine* line = getViewObject()->getCenterLineBySelection(name);
412
getViewObject()->removeCenterLine(line->getTagAsString());
419
App::Color ViewProviderViewPart::prefSectionColor()
421
return PreferencesGui::sectionLineColor();
424
App::Color ViewProviderViewPart::prefHighlightColor()
427
fcColor.setPackedValue(Preferences::getPreferenceGroup("Decorations")->GetUnsigned("HighlightColor", 0x00000000));
431
int ViewProviderViewPart::prefHighlightStyle()
433
return Preferences::getPreferenceGroup("Decorations")->GetInt("HighlightStyle", 2);
440
void ViewProviderViewPart::fixSceneDependencies()
442
auto page = getViewProviderPage();
447
auto scene = page->getQGSPage();
448
auto partQView = getQView();
450
auto dimensions = getViewPart()->getDimensions();
451
for (auto& dim : dimensions) {
452
auto dimQView = dynamic_cast<QGIViewDimension *>(scene->findQViewForDocObj(dim));
453
if (dimQView && dimQView->parentItem() != partQView) {
455
scene->addDimToParent(dimQView, partQView);
459
auto balloons = getViewPart()->getBalloons();
460
for (auto& bal : balloons) {
461
auto balQView = dynamic_cast<QGIViewBalloon*>(scene->findQViewForDocObj(bal));
462
if (balQView && balQView->parentItem() != partQView) {
464
scene->addBalloonToParent(balQView, partQView);