From aa9b5d96e307cdc469849d1240cf3be76009d26a Mon Sep 17 00:00:00 2001 From: azv Date: Wed, 1 May 2019 23:01:44 +0300 Subject: [PATCH] FUSE operation refactoring (process edges and faces while creating objects hierarchy). --- src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp | 9 +- src/FeaturesPlugin/FeaturesPlugin_Boolean.h | 3 +- .../FeaturesPlugin_BooleanCommon.cpp | 6 +- .../FeaturesPlugin_BooleanCut.cpp | 6 +- .../FeaturesPlugin_BooleanFill.cpp | 6 +- .../FeaturesPlugin_BooleanFuse.cpp | 96 ++++--------------- 6 files changed, 40 insertions(+), 86 deletions(-) diff --git a/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp b/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp index 6602ebccb..2220e4f06 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp @@ -87,7 +87,8 @@ void FeaturesPlugin_Boolean::parentForShape(const GeomShapePtr& theShape, bool FeaturesPlugin_Boolean::processAttribute(const std::string& theAttributeName, ObjectHierarchy& theObjects, - ListOfShape& thePlanesList) + ListOfShape& thePlanesList, + ListOfShape& theEdgesAndFaces) { AttributeSelectionListPtr anObjectsSelList = selectionList(theAttributeName); for (int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) { @@ -104,6 +105,12 @@ bool FeaturesPlugin_Boolean::processAttribute(const std::string& theAttributeNam return false; } + if (anObject->shapeType() == GeomAPI_Shape::EDGE || + anObject->shapeType() == GeomAPI_Shape::FACE) { + theEdgesAndFaces.push_back(anObject); + continue; + } + theObjects.AddObject(anObject); ResultPtr aContext = anObjectAttr->context(); diff --git a/src/FeaturesPlugin/FeaturesPlugin_Boolean.h b/src/FeaturesPlugin/FeaturesPlugin_Boolean.h index 63185b172..14edc73b3 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Boolean.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Boolean.h @@ -142,7 +142,8 @@ protected: /// Process SelectionList attribute and fill the objects hierarchy. bool processAttribute(const std::string& theAttributeName, ObjectHierarchy& theObjects, - ListOfShape& thePlanesList); + ListOfShape& thePlanesList, + ListOfShape& theEdgesAndFaces); /// Perform Boolean operation of the object with the tools /// \return \c false if something went wrong diff --git a/src/FeaturesPlugin/FeaturesPlugin_BooleanCommon.cpp b/src/FeaturesPlugin/FeaturesPlugin_BooleanCommon.cpp index af2d556f1..8506bc005 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_BooleanCommon.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_BooleanCommon.cpp @@ -54,7 +54,7 @@ void FeaturesPlugin_BooleanCommon::initAttributes() //================================================================================================== void FeaturesPlugin_BooleanCommon::execute() { - ListOfShape aPlanes; + ListOfShape aPlanes, anEdgesAndFaces; ObjectHierarchy anObjects, aTools; bool isSimpleMode = false; @@ -66,14 +66,14 @@ void FeaturesPlugin_BooleanCommon::execute() } // Getting objects. - if (!processAttribute(OBJECT_LIST_ID(), anObjects, aPlanes)) + if (!processAttribute(OBJECT_LIST_ID(), anObjects, aPlanes, anEdgesAndFaces)) return; // Planes are not supported as objects of COMMON operation aPlanes.clear(); // Getting tools. if (!isSimpleMode && - !processAttribute(TOOL_LIST_ID(), aTools, aPlanes)) + !processAttribute(TOOL_LIST_ID(), aTools, aPlanes, anEdgesAndFaces)) return; if (anObjects.IsEmpty() || (!isSimpleMode && aTools.IsEmpty() && aPlanes.empty())) { diff --git a/src/FeaturesPlugin/FeaturesPlugin_BooleanCut.cpp b/src/FeaturesPlugin/FeaturesPlugin_BooleanCut.cpp index be93d26ec..e6ba621a4 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_BooleanCut.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_BooleanCut.cpp @@ -45,11 +45,11 @@ FeaturesPlugin_BooleanCut::FeaturesPlugin_BooleanCut() void FeaturesPlugin_BooleanCut::execute() { ObjectHierarchy anObjects, aTools; - ListOfShape aPlanes; + ListOfShape aPlanes, anEdgesAndFaces; // Getting objects and tools - if (!processAttribute(OBJECT_LIST_ID(), anObjects, aPlanes) || - !processAttribute(TOOL_LIST_ID(), aTools, aPlanes)) + if (!processAttribute(OBJECT_LIST_ID(), anObjects, aPlanes, anEdgesAndFaces) || + !processAttribute(TOOL_LIST_ID(), aTools, aPlanes, anEdgesAndFaces)) return; int aResultIndex = 0; diff --git a/src/FeaturesPlugin/FeaturesPlugin_BooleanFill.cpp b/src/FeaturesPlugin/FeaturesPlugin_BooleanFill.cpp index a907823ad..1088fd820 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_BooleanFill.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_BooleanFill.cpp @@ -51,16 +51,16 @@ void FeaturesPlugin_BooleanFill::execute() { std::string anError; ObjectHierarchy anObjects, aTools; - ListOfShape aPlanes; + ListOfShape aPlanes, anEdgesAndFaces; // Getting objects. - if (!processAttribute(OBJECT_LIST_ID(), anObjects, aPlanes)) + if (!processAttribute(OBJECT_LIST_ID(), anObjects, aPlanes, anEdgesAndFaces)) return; // Planes are not supported as objects of FILL operation aPlanes.clear(); // Getting tools. - if (!processAttribute(TOOL_LIST_ID(), aTools, aPlanes)) + if (!processAttribute(TOOL_LIST_ID(), aTools, aPlanes, anEdgesAndFaces)) return; int aResultIndex = 0; diff --git a/src/FeaturesPlugin/FeaturesPlugin_BooleanFuse.cpp b/src/FeaturesPlugin/FeaturesPlugin_BooleanFuse.cpp index cd9fae738..53c8d66f7 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_BooleanFuse.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_BooleanFuse.cpp @@ -61,8 +61,8 @@ void FeaturesPlugin_BooleanFuse::initAttributes() void FeaturesPlugin_BooleanFuse::execute() { std::string anError; - ListOfShape anObjects, aTools, anEdgesAndFaces; - std::map aCompSolidsObjects; + ObjectHierarchy anObjectsHierarchy, aToolsHierarchy; + ListOfShape aPlanes, anEdgesAndFaces; bool isSimpleCreation = false; @@ -74,60 +74,18 @@ void FeaturesPlugin_BooleanFuse::execute() } // Getting objects. - AttributeSelectionListPtr anObjectsSelList = - selectionList(FeaturesPlugin_Boolean::OBJECT_LIST_ID()); - for (int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) { - AttributeSelectionPtr anObjectAttr = anObjectsSelList->value(anObjectsIndex); - GeomShapePtr anObject = anObjectAttr->value(); - if (!anObject.get()) { - return; - } - ResultPtr aContext = anObjectAttr->context(); - ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext); - if (!isSimpleCreation - && aResCompSolidPtr.get() - && aResCompSolidPtr->shape()->shapeType() == GeomAPI_Shape::COMPSOLID) - { - GeomShapePtr aContextShape = aResCompSolidPtr->shape(); - std::map::iterator - anIt = aCompSolidsObjects.begin(); - for (; anIt != aCompSolidsObjects.end(); anIt++) { - if (anIt->first->isEqual(aContextShape)) { - aCompSolidsObjects[anIt->first].push_back(anObject); - break; - } - } - if (anIt == aCompSolidsObjects.end()) { - aCompSolidsObjects[aContextShape].push_back(anObject); - } - } else { - if (anObject->shapeType() == GeomAPI_Shape::EDGE - || anObject->shapeType() == GeomAPI_Shape::FACE) { - anEdgesAndFaces.push_back(anObject); - } else { - anObjects.push_back(anObject); - } - } - } + if (!processAttribute(OBJECT_LIST_ID(), anObjectsHierarchy, aPlanes, anEdgesAndFaces)) + return; // Getting tools. - if (!isSimpleCreation) { - AttributeSelectionListPtr aToolsSelList = selectionList(FeaturesPlugin_Boolean::TOOL_LIST_ID()); - for (int aToolsIndex = 0; aToolsIndex < aToolsSelList->size(); aToolsIndex++) { - AttributeSelectionPtr aToolAttr = aToolsSelList->value(aToolsIndex); - GeomShapePtr aTool = aToolAttr->value(); - if (aTool->shapeType() == GeomAPI_Shape::EDGE - || aTool->shapeType() == GeomAPI_Shape::FACE) - { - anEdgesAndFaces.push_back(aTool); - } else { - aTools.push_back(aTool); - } - } - } + if (!isSimpleCreation && + !processAttribute(TOOL_LIST_ID(), aToolsHierarchy, aPlanes, anEdgesAndFaces)) + return; - if ((anObjects.size() + aTools.size() + - aCompSolidsObjects.size() + anEdgesAndFaces.size()) < 2) { + ListOfShape anObjects = anObjectsHierarchy.Objects(); + ListOfShape aTools = aToolsHierarchy.Objects(); + + if ((anObjects.size() + aTools.size() + anEdgesAndFaces.size()) < 2) { std::string aFeatureError = "Error: Not enough objects for boolean operation."; setError(aFeatureError); return; @@ -141,28 +99,16 @@ void FeaturesPlugin_BooleanFuse::execute() // Collecting solids from compsolids which will not be modified // in boolean operation and will be added to result. ListOfShape aShapesToAdd; - for (std::map::iterator anIt = aCompSolidsObjects.begin(); - anIt != aCompSolidsObjects.end(); - ++anIt) - { - GeomShapePtr aCompSolid = anIt->first; - ListOfShape& aUsedInOperationSolids = anIt->second; - aSolidsToFuse.insert(aSolidsToFuse.end(), aUsedInOperationSolids.begin(), - aUsedInOperationSolids.end()); - - // Collect solids from compsolid which will not be modified in boolean operation. - for (GeomAPI_ShapeExplorer - anExp(aCompSolid, GeomAPI_Shape::SOLID); anExp.more(); anExp.next()) { - GeomShapePtr aSolidInCompSolid = anExp.current(); - ListOfShape::iterator anIt = aUsedInOperationSolids.begin(); - for (; anIt != aUsedInOperationSolids.end(); anIt++) { - if (aSolidInCompSolid->isEqual(*anIt)) { - break; - } - } - if (anIt == aUsedInOperationSolids.end()) { - aShapesToAdd.push_back(aSolidInCompSolid); - } + for (ObjectHierarchy::Iterator anObjectsIt = anObjectsHierarchy.Begin(); + !isSimpleCreation && anObjectsIt != anObjectsHierarchy.End(); + ++anObjectsIt) { + GeomShapePtr anObject = *anObjectsIt; + GeomShapePtr aParent = anObjectsHierarchy.Parent(anObject, false); + + if (aParent && aParent->shapeType() == GeomAPI_Shape::COMPSOLID) { + ListOfShape aUsed, aNotUsed; + anObjectsHierarchy.SplitCompound(aParent, aUsed, aNotUsed); + aShapesToAdd.insert(aShapesToAdd.end(), aNotUsed.begin(), aNotUsed.end()); } } -- 2.39.2