From 93d261c062c12388f4420043776e8ee19ddceaa0 Mon Sep 17 00:00:00 2001 From: dbv Date: Thu, 22 Sep 2016 10:27:12 +0300 Subject: [PATCH] Issue #1764: The result of partition is not stored in a folder Fixed connected topology creation in partition. --- src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp | 39 ++++++++++++--- src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp | 48 +++++++------------ src/Model/Model_ResultCompSolid.cpp | 5 +- src/Model/Model_ResultCompSolid.h | 3 +- 4 files changed, 56 insertions(+), 39 deletions(-) diff --git a/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp b/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp index 075bd5f7b..c2c9cdd1f 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -140,11 +141,37 @@ void FeaturesPlugin_Boolean::execute() ListOfShape aListWithObject; aListWithObject.push_back(anObject); GeomAlgoAPI_MakeShape aBoolAlgo; + GeomShapePtr aResShape; switch(aType) { - case BOOL_CUT: aBoolAlgo = GeomAlgoAPI_Boolean(aListWithObject, aTools, GeomAlgoAPI_Boolean::BOOL_CUT); break; - case BOOL_COMMON: aBoolAlgo = GeomAlgoAPI_Boolean(aListWithObject, aTools, GeomAlgoAPI_Boolean::BOOL_COMMON); break; - case BOOL_FILL: aBoolAlgo = GeomAlgoAPI_Partition(aListWithObject, aTools); break; + case BOOL_CUT: { + aBoolAlgo = GeomAlgoAPI_Boolean(aListWithObject, aTools, GeomAlgoAPI_Boolean::BOOL_CUT); + aResShape = aBoolAlgo.shape(); + break; + } + case BOOL_COMMON: { + aBoolAlgo = GeomAlgoAPI_Boolean(aListWithObject, aTools, GeomAlgoAPI_Boolean::BOOL_COMMON); + aResShape = aBoolAlgo.shape(); + break; + } + case BOOL_FILL: { + aBoolAlgo = GeomAlgoAPI_Partition(aListWithObject, aTools); + aResShape = aBoolAlgo.shape(); + if(aResShape->shapeType() == GeomAPI_Shape::COMPOUND) { + int aSubResultsNb = 0; + GeomAPI_ShapeIterator anIt(aResShape); + for(; anIt.more(); anIt.next()) { + ++aSubResultsNb; + } + if(aSubResultsNb == 1) { + anIt.init(aResShape); + if(anIt.more()) { + aResShape = anIt.current(); + } + } + } + break; + } } // Checking that the algorithm worked properly. @@ -153,7 +180,7 @@ void FeaturesPlugin_Boolean::execute() setError(aFeatureError); return; } - if(aBoolAlgo.shape()->isNull()) { + if(aResShape->isNull()) { static const std::string aShapeError = "Error: Resulting shape is Null."; setError(aShapeError); return; @@ -164,9 +191,9 @@ void FeaturesPlugin_Boolean::execute() return; } - if(GeomAlgoAPI_ShapeTools::volume(aBoolAlgo.shape()) > 1.e-27) { + if(GeomAlgoAPI_ShapeTools::volume(aResShape) > 1.e-27) { std::shared_ptr aResultBody = document()->createBody(data(), aResultIndex); - loadNamingDS(aResultBody, anObject, aTools, aBoolAlgo.shape(), aBoolAlgo, *aBoolAlgo.mapOfSubShapes().get()); + loadNamingDS(aResultBody, anObject, aTools, aResShape, aBoolAlgo, *aBoolAlgo.mapOfSubShapes().get()); setResult(aResultBody, aResultIndex); aResultIndex++; } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp index bc64bf02e..8eb3259c3 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp @@ -324,39 +324,27 @@ std::shared_ptr GeomAlgoAPI_ShapeTools::groupSharedTopology(const aGroups.Append(aGroupedShapes); } - if(aGroups.Size() == 1) { - NCollection_List aGroup = aGroups.First(); + TopoDS_Compound aCompound; + BRep_Builder aBuilder; + aBuilder.MakeCompound(aCompound); + ListOfShape aCompSolids, aFreeSolids; + for(NCollection_Vector>::Iterator anIt(aGroups); anIt.More(); anIt.Next()) { + NCollection_List aGroup = anIt.Value(); GeomShapePtr aGeomShape(new GeomAPI_Shape()); - aGeomShape->setImpl(new TopoDS_Shape(makeCompound(aGroup))); - ListOfShape aCompSolids, aFreeSolids; - aGeomShape = GeomAlgoAPI_ShapeTools::combineShapes(aGeomShape, - GeomAPI_Shape::COMPSOLID, - aCompSolids, - aFreeSolids); - aResult = aGeomShape; - } else { - TopoDS_Compound aCompound; - BRep_Builder aBuilder; - aBuilder.MakeCompound(aCompound); - ListOfShape aCompSolids, aFreeSolids; - for(NCollection_Vector>::Iterator anIt(aGroups); anIt.More(); anIt.Next()) { - NCollection_List aGroup = anIt.Value(); - GeomShapePtr aGeomShape(new GeomAPI_Shape()); - if(aGroup.Size() == 1) { - aGeomShape->setImpl(new TopoDS_Shape(aGroup.First())); - } else { - aGeomShape->setImpl(new TopoDS_Shape(makeCompound(aGroup))); - aGeomShape = GeomAlgoAPI_ShapeTools::combineShapes(aGeomShape, - GeomAPI_Shape::COMPSOLID, - aCompSolids, - aFreeSolids); - } - aBuilder.Add(aCompound, aGeomShape->impl()); + if(aGroup.Size() == 1) { + aGeomShape->setImpl(new TopoDS_Shape(aGroup.First())); + } else { + aGeomShape->setImpl(new TopoDS_Shape(makeCompound(aGroup))); + aGeomShape = GeomAlgoAPI_ShapeTools::combineShapes(aGeomShape, + GeomAPI_Shape::COMPSOLID, + aCompSolids, + aFreeSolids); } + aBuilder.Add(aCompound, aGeomShape->impl()); + } - if(!aCompound.IsNull()) { - aResult->setImpl(new TopoDS_Shape(aCompound)); - } + if(!aCompound.IsNull()) { + aResult->setImpl(new TopoDS_Shape(aCompound)); } return aResult; diff --git a/src/Model/Model_ResultCompSolid.cpp b/src/Model/Model_ResultCompSolid.cpp index 00ca3915d..823001cd6 100755 --- a/src/Model/Model_ResultCompSolid.cpp +++ b/src/Model/Model_ResultCompSolid.cpp @@ -30,9 +30,10 @@ Model_ResultCompSolid::~Model_ResultCompSolid() updateSubs(std::shared_ptr()); // erase sub-results } -void Model_ResultCompSolid::store(const std::shared_ptr& theShape) +void Model_ResultCompSolid::store(const std::shared_ptr& theShape, + const bool theIsStoreSameShapes) { - ModelAPI_ResultCompSolid::store(theShape); + ModelAPI_ResultCompSolid::store(theShape, theIsStoreSameShapes); updateSubs(theShape); } diff --git a/src/Model/Model_ResultCompSolid.h b/src/Model/Model_ResultCompSolid.h index 60ab44b0d..b7db1b82e 100755 --- a/src/Model/Model_ResultCompSolid.h +++ b/src/Model/Model_ResultCompSolid.h @@ -32,7 +32,8 @@ public: MODEL_EXPORT virtual ~Model_ResultCompSolid(); /// Stores the shape (called by the execution method). Creates sub-results for compsolid. - MODEL_EXPORT virtual void store(const std::shared_ptr& theShape); + MODEL_EXPORT virtual void store(const std::shared_ptr& theShape, + const bool theIsStoreSameShapes = true); /// Stores the generated shape. Creates sub-results for compsolid. MODEL_EXPORT virtual void storeGenerated(const std::shared_ptr& theFromShape, -- 2.39.2