Debian Codegraph @

src/Gui/ViewProviderGeoFeatureGroupExtension.cpp

raw
1 /***************************************************************************
2 * Copyright (c) 2011 Jürgen Riegel <[email protected]> *
3 * Copyright (c) 2015 Alexander Golubev (Fat-Zer) <[email protected]> *
4 * Copyright (c) 2016 Stefan Tröger <[email protected]> *
5 * *
6 * This file is part of the FreeCAD CAx development system. *
7 * *
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Library General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2 of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Library General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Library General Public *
19 * License along with this library; see the file COPYING.LIB. If not, *
20 * write to the Free Software Foundation, Inc., 59 Temple Place, *
21 * Suite 330, Boston, MA 02111-1307, USA *
22 * *
23 ***************************************************************************/
24
25
26 #include <Inventor/nodes/SoSeparator.h>
27
28
29 #include <App/DocumentObject.h>
30 #include <App/GeoFeatureGroupExtension.h>
31
32 #include "ViewProviderGeoFeatureGroupExtension.h"
33 #include "ViewProviderDocumentObject.h"
34 #include "Application.h"
35 #include "SoFCUnifiedSelection.h"
36
37
38 using namespace Gui;
39
40 EXTENSION_PROPERTY_SOURCE(Gui::ViewProviderGeoFeatureGroupExtension, Gui::ViewProviderGroupExtension)
41
42 ViewProviderGeoFeatureGroupExtension::ViewProviderGeoFeatureGroupExtension()
43 {
44 initExtensionType(ViewProviderGeoFeatureGroupExtension::getExtensionClassTypeId());
45
46 pcGroupChildren = new SoFCSelectionRoot;
47 pcGroupChildren->ref();
48 pcGroupFront = new SoSeparator();
49 pcGroupFront->ref();
50 pcGroupBack = new SoSeparator();
51 pcGroupBack->ref();
52 }
53
54 ViewProviderGeoFeatureGroupExtension::~ViewProviderGeoFeatureGroupExtension()
55 {
56 pcGroupChildren->unref();
57 pcGroupChildren = nullptr;
58 pcGroupFront->unref();
59 pcGroupFront = nullptr;
60 pcGroupBack->unref();
61 pcGroupBack = nullptr;
62 }
63
64
65 std::vector<App::DocumentObject*> ViewProviderGeoFeatureGroupExtension::extensionClaimChildren3D() const
66 {
67
68 // all object in the group must be claimed in 3D, as we are a coordinate system for all of them
69 auto* obj = getExtendedViewProvider()->getObject();
70 auto* ext = obj ? obj->getExtensionByType<App::GeoFeatureGroupExtension>() : nullptr;
71 if (ext) {
72 auto objs = ext->Group.getValues();
73 return objs;
74 }
75 return {};
76 }
77
78 std::vector<App::DocumentObject*> ViewProviderGeoFeatureGroupExtension::extensionClaimChildren() const
79 {
80
81 auto* obj = getExtendedViewProvider()->getObject();
82 if (!obj) {
83 return {};
84 }
85
86 auto* group = obj->getExtensionByType<App::GeoFeatureGroupExtension>();
87 const std::vector<App::DocumentObject*>& model = group->Group.getValues();
88 std::set<App::DocumentObject*> outSet; //< set of objects not to claim (childrens of childrens)
89
90 // search for objects handled (claimed) by the features
91 for (auto obj : model) {
92 // stuff in another geofeaturegroup is not in the model anyway
93 if (!obj || obj->hasExtension(App::GeoFeatureGroupExtension::getExtensionClassTypeId())) {
94 continue;
95 }
96
97 Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(obj);
98 if (!vp || vp == getExtendedViewProvider()) {
99 continue;
100 }
101
102 auto children = vp->claimChildren();
103 std::remove_copy(children.begin(), children.end(), std::inserter(outSet, outSet.begin()), nullptr);
104 }
105
106 // remove the otherwise handled objects, preserving their order so the order in the TreeWidget
107 // is correct
108 std::vector<App::DocumentObject*> Result;
109 for (auto obj : model) {
110 if (!obj || !obj->isAttachedToDocument()) {
111 continue;
112 }
113 if (outSet.contains(obj)) {
114 obj->setStatus(App::ObjectStatus::GeoExcluded, true);
115 }
116 else {
117 obj->setStatus(App::ObjectStatus::GeoExcluded, false);
118 Result.push_back(obj);
119 }
120 }
121 return Result;
122 }
123
124 void ViewProviderGeoFeatureGroupExtension::extensionFinishRestoring()
125 {
126 // setup GeoExlcuded flag for children
127 extensionClaimChildren();
128 ViewProviderGroupExtension::extensionFinishRestoring();
129 }
130
131 void ViewProviderGeoFeatureGroupExtension::extensionAttach(App::DocumentObject* pcObject)
132 {
133 ViewProviderGroupExtension::extensionAttach(pcObject);
134 getExtendedViewProvider()->addDisplayMaskMode(pcGroupChildren, "Group");
135 }
136
137 void ViewProviderGeoFeatureGroupExtension::extensionSetDisplayMode(const char* ModeName)
138 {
139 if (strcmp("Group", ModeName) == 0) {
140 getExtendedViewProvider()->setDisplayMaskMode("Group");
141 }
142
143 ViewProviderGroupExtension::extensionSetDisplayMode(ModeName);
144 }
145
146 std::vector<std::string> ViewProviderGeoFeatureGroupExtension::extensionGetDisplayModes() const
147 {
148 // get the modes of the father
149 std::vector<std::string> StrList = ViewProviderGroupExtension::extensionGetDisplayModes();
150
151 // add your own modes
152 StrList.emplace_back("Group");
153
154 return StrList;
155 }
156
157 void ViewProviderGeoFeatureGroupExtension::extensionUpdateData(const App::Property* prop)
158 {
159 auto obj = getExtendedViewProvider()->getObject();
160 auto grp = obj ? obj->getExtensionByType<App::GeoFeatureGroupExtension>() : nullptr;
161 if (grp && prop == &grp->placement()) {
162 getExtendedViewProvider()->setTransformation(grp->placement().getValue().toMatrix());
163 }
164 else {
165 ViewProviderGroupExtension::extensionUpdateData(prop);
166 }
167 }
168
169 namespace Gui
170 {
171 EXTENSION_PROPERTY_SOURCE_TEMPLATE(
172 Gui::ViewProviderGeoFeatureGroupExtensionPython,
173 Gui::ViewProviderGeoFeatureGroupExtension
174 )
175
176 // explicit template instantiation
177 template class GuiExport ViewProviderExtensionPythonT<ViewProviderGeoFeatureGroupExtension>;
178 } // namespace Gui