Keep faces colors on boolean operations

This commit is contained in:
wmayer
2012-05-30 15:18:37 +02:00
parent 5f54bfa899
commit 7fadf83ff5
12 changed files with 119 additions and 32 deletions

View File

@@ -24,9 +24,15 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <BRepAlgoAPI_BooleanOperation.hxx>
# include <TopExp.hxx>
# include <TopTools_IndexedMapOfShape.hxx>
# include <TopTools_ListOfShape.hxx>
# include <TopTools_ListIteratorOfListOfShape.hxx>
#endif
#include "ViewProviderBoolean.h"
#include <Gui/Application.h>
#include <Gui/BitmapFactory.h>
#include <Mod/Part/App/FeaturePartBoolean.h>
#include <Mod/Part/App/FeaturePartFuse.h>
@@ -71,6 +77,84 @@ QIcon ViewProviderBoolean::getIcon(void) const
return ViewProviderPart::getIcon();
}
void findFaces(BRepAlgoAPI_BooleanOperation* mkBool,
const TopTools_IndexedMapOfShape& M1,
const TopTools_IndexedMapOfShape& M3,
const std::vector<App::Color>& colBase,
std::vector<App::Color>& colBool)
{
for (int i=1; i<=M1.Extent(); i++) {
bool modified=false, generated=false;
TopTools_ListIteratorOfListOfShape it;
for (it.Initialize(mkBool->Modified(M1(i))); it.More(); it.Next()) {
modified = true;
for (int j=1; j<=M3.Extent(); j++) {
if (M3(j).IsPartner(it.Value())) {
colBool[j-1] = colBase[i-1];
break;
}
}
}
for (it.Initialize(mkBool->Generated(M1(i))); it.More(); it.Next()) {
generated = true;
for (int j=1; j<=M3.Extent(); j++) {
if (M3(j).IsPartner(it.Value())) {
colBool[j-1] = colBase[i-1];
break;
}
}
}
if (!modified && !generated && !mkBool->IsDeleted(M1(i))) {
for (int j=1; j<=M3.Extent(); j++) {
if (M3(j).IsPartner(M1(i))) {
colBool[j-1] = colBase[i-1];
break;
}
}
}
}
}
void ViewProviderBoolean::updateData(const App::Property* prop)
{
PartGui::ViewProviderPart::updateData(prop);
if (prop->getTypeId() == Part::PropertyPartShape::getClassTypeId()) {
Part::Boolean* objBool = dynamic_cast<Part::Boolean*>(getObject());
Part::Feature* objBase = dynamic_cast<Part::Feature*>(objBool->Base.getValue());
Part::Feature* objTool = dynamic_cast<Part::Feature*>(objBool->Tool.getValue());
BRepAlgoAPI_BooleanOperation* mkBool = objBool->getBooleanOperation();
if (mkBool && objBase && objTool) {
const TopoDS_Shape& baseShape = objBase->Shape.getValue();
const TopoDS_Shape& toolShape = objTool->Shape.getValue();
const TopoDS_Shape& boolShape = objBool->Shape.getValue();
TopTools_IndexedMapOfShape M1, M2, M3;
TopExp::MapShapes(baseShape, TopAbs_FACE, M1);
TopExp::MapShapes(toolShape, TopAbs_FACE, M2);
TopExp::MapShapes(boolShape, TopAbs_FACE, M3);
Gui::ViewProvider* vpBase = Gui::Application::Instance->getViewProvider(objBase);
Gui::ViewProvider* vpTool = Gui::Application::Instance->getViewProvider(objTool);
std::vector<App::Color> colBase = static_cast<PartGui::ViewProviderPart*>(vpBase)->DiffuseColor.getValues();
std::vector<App::Color> colTool = static_cast<PartGui::ViewProviderPart*>(vpTool)->DiffuseColor.getValues();
std::vector<App::Color> colBool;
colBool.resize(M3.Extent(), this->ShapeColor.getValue());
bool applyColor=false;
if (colBase.size() == M1.Extent()) {
findFaces(mkBool, M1, M3, colBase, colBool);
applyColor = true;
}
if (colTool.size() == M2.Extent()) {
findFaces(mkBool, M2, M3, colTool, colBool);
applyColor = true;
}
if (applyColor)
this->DiffuseColor.setValues(colBool);
}
}
}
PROPERTY_SOURCE(PartGui::ViewProviderMultiFuse,PartGui::ViewProviderPart)