1
/***************************************************************************
2
* Copyright (c) 2008 Werner Mayer <wmayer[at]users.sourceforge.net> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
23
#include "PreCompiled.h"
27
# include <TopTools_IndexedMapOfShape.hxx>
30
#include <Gui/Application.h>
31
#include <Gui/BitmapFactory.h>
32
#include <Mod/Part/App/FeaturePartCommon.h>
33
#include <Mod/Part/App/FeaturePartFuse.h>
35
#include "ViewProviderBoolean.h"
38
using namespace PartGui;
40
PROPERTY_SOURCE(PartGui::ViewProviderBoolean,PartGui::ViewProviderPart)
42
ViewProviderBoolean::ViewProviderBoolean() = default;
44
ViewProviderBoolean::~ViewProviderBoolean() = default;
46
std::vector<App::DocumentObject*> ViewProviderBoolean::claimChildren()const
48
std::vector<App::DocumentObject*> temp;
49
temp.push_back(static_cast<Part::Boolean*>(getObject())->Base.getValue());
50
temp.push_back(static_cast<Part::Boolean*>(getObject())->Tool.getValue());
55
QIcon ViewProviderBoolean::getIcon() const
57
App::DocumentObject* obj = getObject();
59
Base::Type type = obj->getTypeId();
60
if (type == Base::Type::fromName("Part::Common"))
61
return Gui::BitmapFactory().iconFromTheme("Part_Common");
62
else if (type == Base::Type::fromName("Part::Fuse"))
63
return Gui::BitmapFactory().iconFromTheme("Part_Fuse");
64
else if (type == Base::Type::fromName("Part::Cut"))
65
return Gui::BitmapFactory().iconFromTheme("Part_Cut");
66
else if (type == Base::Type::fromName("Part::Section"))
67
return Gui::BitmapFactory().iconFromTheme("Part_Section");
70
return ViewProviderPart::getIcon();
73
void ViewProviderBoolean::updateData(const App::Property* prop)
75
PartGui::ViewProviderPart::updateData(prop);
76
if (prop->is<Part::PropertyShapeHistory>()) {
77
const std::vector<Part::ShapeHistory>& hist = static_cast<const Part::PropertyShapeHistory*>
81
Part::Boolean* objBool = dynamic_cast<Part::Boolean*>(getObject());
84
Part::Feature* objBase = dynamic_cast<Part::Feature*>(
85
Part::Feature::getShapeOwner(objBool->Base.getValue()));
86
Part::Feature* objTool = dynamic_cast<Part::Feature*>(
87
Part::Feature::getShapeOwner(objBool->Tool.getValue()));
88
if (objBase && objTool) {
89
const TopoDS_Shape& baseShape = objBase->Shape.getValue();
90
const TopoDS_Shape& toolShape = objTool->Shape.getValue();
91
const TopoDS_Shape& boolShape = objBool->Shape.getValue();
93
TopTools_IndexedMapOfShape baseMap, toolMap, boolMap;
94
TopExp::MapShapes(baseShape, TopAbs_FACE, baseMap);
95
TopExp::MapShapes(toolShape, TopAbs_FACE, toolMap);
96
TopExp::MapShapes(boolShape, TopAbs_FACE, boolMap);
98
auto vpBase = dynamic_cast<PartGui::ViewProviderPart*>(
99
Gui::Application::Instance->getViewProvider(objBase));
100
auto vpTool = dynamic_cast<PartGui::ViewProviderPart*>(
101
Gui::Application::Instance->getViewProvider(objTool));
102
if (vpBase && vpTool) {
103
std::vector<App::Material> colBase = vpBase->ShapeAppearance.getValues();
104
std::vector<App::Material> colTool = vpTool->ShapeAppearance.getValues();
105
std::vector<App::Material> colBool;
106
colBool.resize(boolMap.Extent(), this->ShapeAppearance[0]);
107
applyTransparency(vpBase->Transparency.getValue(),colBase);
108
applyTransparency(vpTool->Transparency.getValue(),colTool);
110
if (static_cast<int>(colBase.size()) == baseMap.Extent()) {
111
applyMaterial(hist[0], colBase, colBool);
113
else if (!colBase.empty() && colBase[0] != this->ShapeAppearance[0]) {
114
colBase.resize(baseMap.Extent(), colBase[0]);
115
applyMaterial(hist[0], colBase, colBool);
118
if (static_cast<int>(colTool.size()) == toolMap.Extent()) {
119
applyMaterial(hist[1], colTool, colBool);
121
else if (!colTool.empty() && colTool[0] != this->ShapeAppearance[0]) {
122
colTool.resize(toolMap.Extent(), colTool[0]);
123
applyMaterial(hist[1], colTool, colBool);
126
// If the view provider has set a transparency then override the values
127
// of the input shapes
128
if (Transparency.getValue() > 0) {
129
applyTransparency(Transparency.getValue(), colBool);
132
this->ShapeAppearance.setValues(colBool);
136
else if (prop->isDerivedFrom<App::PropertyLink>()) {
137
App::DocumentObject *pBase = static_cast<const App::PropertyLink*>(prop)->getValue();
139
Gui::Application::Instance->hideViewProvider(pBase);
143
bool ViewProviderBoolean::onDelete(const std::vector<std::string> &)
145
// get the input shapes
146
Part::Boolean* pBool = static_cast<Part::Boolean*>(getObject());
147
App::DocumentObject *pBase = pBool->Base.getValue();
148
App::DocumentObject *pTool = pBool->Tool.getValue();
151
Gui::Application::Instance->showViewProvider(pBase);
153
Gui::Application::Instance->showViewProvider(pTool);
158
PROPERTY_SOURCE(PartGui::ViewProviderMultiFuse,PartGui::ViewProviderPart)
160
ViewProviderMultiFuse::ViewProviderMultiFuse() = default;
162
ViewProviderMultiFuse::~ViewProviderMultiFuse() = default;
164
std::vector<App::DocumentObject*> ViewProviderMultiFuse::claimChildren()const
166
return static_cast<Part::MultiFuse*>(getObject())->Shapes.getValues();
169
QIcon ViewProviderMultiFuse::getIcon() const
171
return Gui::BitmapFactory().iconFromTheme("Part_Fuse");
174
void ViewProviderMultiFuse::updateData(const App::Property* prop)
176
PartGui::ViewProviderPart::updateData(prop);
177
if (prop->is<Part::PropertyShapeHistory>()) {
178
const std::vector<Part::ShapeHistory>& hist = static_cast<const Part::PropertyShapeHistory*>
180
Part::MultiFuse* objBool = static_cast<Part::MultiFuse*>(getObject());
181
std::vector<App::DocumentObject*> sources = objBool->Shapes.getValues();
182
if (hist.size() != sources.size())
185
const TopoDS_Shape& boolShape = objBool->Shape.getValue();
186
TopTools_IndexedMapOfShape boolMap;
187
TopExp::MapShapes(boolShape, TopAbs_FACE, boolMap);
189
std::vector<App::Material> colBool;
190
colBool.resize(boolMap.Extent(), this->ShapeAppearance[0]);
193
for (std::vector<App::DocumentObject*>::iterator it = sources.begin(); it != sources.end(); ++it, ++index) {
194
Part::Feature* objBase = dynamic_cast<Part::Feature*>(Part::Feature::getShapeOwner(*it));
197
const TopoDS_Shape& baseShape = objBase->Shape.getValue();
199
TopTools_IndexedMapOfShape baseMap;
200
TopExp::MapShapes(baseShape, TopAbs_FACE, baseMap);
202
auto vpBase = dynamic_cast<PartGui::ViewProviderPart*>(Gui::Application::Instance->getViewProvider(objBase));
204
std::vector<App::Material> colBase = vpBase->ShapeAppearance.getValues();
205
applyTransparency(vpBase->Transparency.getValue(),colBase);
206
if (static_cast<int>(colBase.size()) == baseMap.Extent()) {
207
applyMaterial(hist[index], colBase, colBool);
209
else if (!colBase.empty() && colBase[0] != this->ShapeAppearance[0]) {
210
colBase.resize(baseMap.Extent(), colBase[0]);
211
applyMaterial(hist[index], colBase, colBool);
216
// If the view provider has set a transparency then override the values
217
// of the input shapes
218
if (Transparency.getValue() > 0) {
219
applyTransparency(Transparency.getValue(), colBool);
222
this->ShapeAppearance.setValues(colBool);
224
else if (prop->isDerivedFrom<App::PropertyLinkList>()) {
225
std::vector<App::DocumentObject*> pShapes = static_cast<const App::PropertyLinkList*>(prop)->getValues();
226
for (auto it : pShapes) {
228
Gui::Application::Instance->hideViewProvider(it);
234
bool ViewProviderMultiFuse::onDelete(const std::vector<std::string> &)
236
// get the input shapes
237
Part::MultiFuse* pBool = static_cast<Part::MultiFuse*>(getObject());
238
std::vector<App::DocumentObject*> pShapes = pBool->Shapes.getValues();
239
for (auto it : pShapes) {
241
Gui::Application::Instance->showViewProvider(it);
248
bool ViewProviderMultiFuse::canDragObjects() const
253
bool ViewProviderMultiFuse::canDragObject(App::DocumentObject* obj) const
256
// return Part::Feature::hasShapeOwner(obj);
260
void ViewProviderMultiFuse::dragObject(App::DocumentObject* obj)
262
Part::MultiFuse* pBool = static_cast<Part::MultiFuse*>(getObject());
263
std::vector<App::DocumentObject*> pShapes = pBool->Shapes.getValues();
264
for (std::vector<App::DocumentObject*>::iterator it = pShapes.begin(); it != pShapes.end(); ++it) {
267
pBool->Shapes.setValues(pShapes);
273
bool ViewProviderMultiFuse::canDropObjects() const
278
bool ViewProviderMultiFuse::canDropObject(App::DocumentObject* obj) const
281
// return Part::Feature::hasShapeOwner(obj);
285
void ViewProviderMultiFuse::dropObject(App::DocumentObject* obj)
287
Part::MultiFuse* pBool = static_cast<Part::MultiFuse*>(getObject());
288
std::vector<App::DocumentObject*> pShapes = pBool->Shapes.getValues();
289
pShapes.push_back(obj);
290
pBool->Shapes.setValues(pShapes);
293
PROPERTY_SOURCE(PartGui::ViewProviderMultiCommon,PartGui::ViewProviderPart)
295
ViewProviderMultiCommon::ViewProviderMultiCommon() = default;
297
ViewProviderMultiCommon::~ViewProviderMultiCommon() = default;
299
std::vector<App::DocumentObject*> ViewProviderMultiCommon::claimChildren()const
301
return static_cast<Part::MultiCommon*>(getObject())->Shapes.getValues();
304
QIcon ViewProviderMultiCommon::getIcon() const
306
return Gui::BitmapFactory().iconFromTheme("Part_Common");
309
void ViewProviderMultiCommon::updateData(const App::Property* prop)
311
PartGui::ViewProviderPart::updateData(prop);
312
if (prop->is<Part::PropertyShapeHistory>()) {
313
const std::vector<Part::ShapeHistory>& hist = static_cast<const Part::PropertyShapeHistory*>
315
Part::MultiCommon* objBool = static_cast<Part::MultiCommon*>(getObject());
316
std::vector<App::DocumentObject*> sources = objBool->Shapes.getValues();
317
if (hist.size() != sources.size())
320
const TopoDS_Shape& boolShape = objBool->Shape.getValue();
321
TopTools_IndexedMapOfShape boolMap;
322
TopExp::MapShapes(boolShape, TopAbs_FACE, boolMap);
324
std::vector<App::Material> colBool;
325
colBool.resize(boolMap.Extent(), this->ShapeAppearance[0]);
328
for (std::vector<App::DocumentObject*>::iterator it = sources.begin(); it != sources.end(); ++it, ++index) {
329
Part::Feature* objBase = dynamic_cast<Part::Feature*>(Part::Feature::getShapeOwner(*it));
332
const TopoDS_Shape& baseShape = objBase->Shape.getValue();
334
TopTools_IndexedMapOfShape baseMap;
335
TopExp::MapShapes(baseShape, TopAbs_FACE, baseMap);
337
auto vpBase = dynamic_cast<PartGui::ViewProviderPart*>(Gui::Application::Instance->getViewProvider(objBase));
339
std::vector<App::Material> colBase = vpBase->ShapeAppearance.getValues();
340
applyTransparency(vpBase->Transparency.getValue(),colBase);
341
if (static_cast<int>(colBase.size()) == baseMap.Extent()) {
342
applyMaterial(hist[index], colBase, colBool);
344
else if (!colBase.empty() && colBase[0] != this->ShapeAppearance[0]) {
345
colBase.resize(baseMap.Extent(), colBase[0]);
346
applyMaterial(hist[index], colBase, colBool);
351
// If the view provider has set a transparency then override the values
352
// of the input shapes
353
if (Transparency.getValue() > 0) {
354
applyTransparency(Transparency.getValue(), colBool);
357
this->ShapeAppearance.setValues(colBool);
359
else if (prop->isDerivedFrom<App::PropertyLinkList>()) {
360
std::vector<App::DocumentObject*> pShapes = static_cast<const App::PropertyLinkList*>(prop)->getValues();
361
for (auto it : pShapes) {
363
Gui::Application::Instance->hideViewProvider(it);
369
bool ViewProviderMultiCommon::onDelete(const std::vector<std::string> &)
371
// get the input shapes
372
Part::MultiCommon* pBool = static_cast<Part::MultiCommon*>(getObject());
373
std::vector<App::DocumentObject*> pShapes = pBool->Shapes.getValues();
374
for (auto it : pShapes) {
376
Gui::Application::Instance->showViewProvider(it);
383
bool ViewProviderMultiCommon::canDragObjects() const
388
bool ViewProviderMultiCommon::canDragObject(App::DocumentObject* obj) const
391
// return Part::Feature::hasShapeOwner(obj);
395
void ViewProviderMultiCommon::dragObject(App::DocumentObject* obj)
397
Part::MultiCommon* pBool = static_cast<Part::MultiCommon*>(getObject());
398
std::vector<App::DocumentObject*> pShapes = pBool->Shapes.getValues();
399
for (std::vector<App::DocumentObject*>::iterator it = pShapes.begin(); it != pShapes.end(); ++it) {
402
pBool->Shapes.setValues(pShapes);
408
bool ViewProviderMultiCommon::canDropObjects() const
413
bool ViewProviderMultiCommon::canDropObject(App::DocumentObject* obj) const
416
// return Part::Feature::hasShapeOwner(obj);
420
void ViewProviderMultiCommon::dropObject(App::DocumentObject* obj)
422
Part::MultiCommon* pBool = static_cast<Part::MultiCommon*>(getObject());
423
std::vector<App::DocumentObject*> pShapes = pBool->Shapes.getValues();
424
pShapes.push_back(obj);
425
pBool->Shapes.setValues(pShapes);