1
/***************************************************************************
2
* Copyright (c) 2013 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 <Mod/Part/App/FeatureCompound.h>
33
#include "ViewProviderCompound.h"
36
using namespace PartGui;
38
PROPERTY_SOURCE(PartGui::ViewProviderCompound,PartGui::ViewProviderPart)
40
ViewProviderCompound::ViewProviderCompound()
42
sPixmap = "Part_Compound.svg";
45
ViewProviderCompound::~ViewProviderCompound() = default;
47
std::vector<App::DocumentObject*> ViewProviderCompound::claimChildren() const
49
return static_cast<Part::Compound*>(getObject())->Links.getValues();
52
bool ViewProviderCompound::onDelete(const std::vector<std::string> &)
54
// get the input shapes
55
Part::Compound* pComp = static_cast<Part::Compound*>(getObject());
56
std::vector<App::DocumentObject*> pLinks = pComp->Links.getValues();
57
for (auto pLink : pLinks) {
59
Gui::Application::Instance->showViewProvider(pLink);
65
void ViewProviderCompound::updateData(const App::Property* prop)
67
PartGui::ViewProviderPart::updateData(prop);
68
if (prop->is<Part::PropertyShapeHistory>()) {
69
const std::vector<Part::ShapeHistory>& hist = static_cast<const Part::PropertyShapeHistory*>
71
Part::Compound* objComp = static_cast<Part::Compound*>(getObject());
72
std::vector<App::DocumentObject*> sources = objComp->Links.getValues();
74
if (hist.size() != sources.size()) {
75
// avoid duplicates without changing the order
76
// See also Compound::execute
77
std::set<App::DocumentObject*> tempSources;
78
std::vector<App::DocumentObject*> filter;
79
for (auto source : sources) {
80
Part::Feature* objBase = dynamic_cast<Part::Feature*>(source);
82
auto pos = tempSources.insert(objBase);
84
filter.push_back(objBase);
91
if (hist.size() != sources.size())
94
const TopoDS_Shape& compShape = objComp->Shape.getValue();
95
TopTools_IndexedMapOfShape compMap;
96
TopExp::MapShapes(compShape, TopAbs_FACE, compMap);
98
std::vector<App::Material> compCol;
99
compCol.resize(compMap.Extent(), this->ShapeAppearance[0]);
102
for (std::vector<App::DocumentObject*>::iterator it = sources.begin(); it != sources.end(); ++it, ++index) {
103
Part::Feature* objBase = dynamic_cast<Part::Feature*>(Part::Feature::getShapeOwner(*it));
107
const TopoDS_Shape& baseShape = objBase->Shape.getValue();
109
TopTools_IndexedMapOfShape baseMap;
110
TopExp::MapShapes(baseShape, TopAbs_FACE, baseMap);
112
auto vpBase = dynamic_cast<PartGui::ViewProviderPart*>(Gui::Application::Instance->getViewProvider(objBase));
114
std::vector<App::Material> baseCol = vpBase->ShapeAppearance.getValues();
115
applyTransparency(vpBase->Transparency.getValue(), baseCol);
116
if (static_cast<int>(baseCol.size()) == baseMap.Extent()) {
117
applyMaterial(hist[index], baseCol, compCol);
119
else if (!baseCol.empty() && baseCol[0] != this->ShapeAppearance[0]) {
120
baseCol.resize(baseMap.Extent(), baseCol[0]);
121
applyMaterial(hist[index], baseCol, compCol);
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(), compCol);
132
this->ShapeAppearance.setValues(compCol);
134
else if (prop->isDerivedFrom<App::PropertyLinkList>()) {
135
const std::vector<App::DocumentObject *>& pBases = static_cast<const App::PropertyLinkList*>(prop)->getValues();
136
for (auto pBase : pBases) {
137
if (pBase) Gui::Application::Instance->hideViewProvider(pBase);
142
bool ViewProviderCompound::canDragObjects() const
147
bool ViewProviderCompound::canDragObject(App::DocumentObject* obj) const
149
return obj->isDerivedFrom<Part::Feature>();
152
void ViewProviderCompound::dragObject(App::DocumentObject* obj)
154
Part::Compound* pComp = static_cast<Part::Compound*>(getObject());
155
std::vector<App::DocumentObject*> pShapes = pComp->Links.getValues();
156
for (std::vector<App::DocumentObject*>::iterator it = pShapes.begin(); it != pShapes.end(); ++it) {
159
pComp->Links.setValues(pShapes);
165
bool ViewProviderCompound::canDropObjects() const
170
bool ViewProviderCompound::canDropObject(App::DocumentObject* obj) const
172
return obj->isDerivedFrom<Part::Feature>();
175
void ViewProviderCompound::dropObject(App::DocumentObject* obj)
177
Part::Compound* pComp = static_cast<Part::Compound*>(getObject());
178
std::vector<App::DocumentObject*> pShapes = pComp->Links.getValues();
179
pShapes.push_back(obj);
180
pComp->Links.setValues(pShapes);