X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAlgoAPI%2FGeomAlgoAPI_Partition.cpp;h=63a1ddc9e4b87a9cf3aaa7a27e72e73f30518ebe;hb=3205d0f18200948632155bbe7b640bc1e482243d;hp=05bc5d2f4749c7b4322ef68496966bb4dd22ed96;hpb=42dfdea5422ab72d81c36155b4c6f352c85c1110;p=modules%2Fshaper.git diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Partition.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Partition.cpp index 05bc5d2f4..63a1ddc9e 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Partition.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Partition.cpp @@ -7,20 +7,20 @@ #include "GeomAlgoAPI_Partition.h" #include +#include #include -#include #include -#include +#include //================================================================================================= std::shared_ptr GeomAlgoAPI_Partition::make(const ListOfShape& theObjects, const ListOfShape& theTools) { - GeomAlgoAPI_Partition aBoolAlgo(theObjects, theTools); - if(aBoolAlgo.isDone() && !aBoolAlgo.shape()->isNull() && aBoolAlgo.isValid()) { - return aBoolAlgo.shape(); + GeomAlgoAPI_Partition aPartitionAlgo(theObjects, theTools); + if(aPartitionAlgo.isDone() && !aPartitionAlgo.shape()->isNull() && aPartitionAlgo.isValid()) { + return aPartitionAlgo.shape(); } return std::shared_ptr(); } @@ -28,10 +28,6 @@ std::shared_ptr GeomAlgoAPI_Partition::make(const ListOfShape& th //================================================================================================= GeomAlgoAPI_Partition::GeomAlgoAPI_Partition(const ListOfShape& theObjects, const ListOfShape& theTools) -: myDone(false), - myShape(new GeomAPI_Shape()), - myMap(new GeomAPI_DataMapOfShapeShape()), - myMkShape(new GeomAlgoAPI_MakeShape()) { build(theObjects, theTools); } @@ -41,23 +37,22 @@ GeomAlgoAPI_Partition::GeomAlgoAPI_Partition(const ListOfShape& theObjects, void GeomAlgoAPI_Partition::build(const ListOfShape& theObjects, const ListOfShape& theTools) { - if (theObjects.empty() || theTools.empty()) { + if (theObjects.empty()) { return; } // Creating partition operation. - GEOMAlgo_Splitter * anOperation = new GEOMAlgo_Splitter; - myMkShape->setImpl(anOperation); + GEOMAlgo_Splitter* anOperation = new GEOMAlgo_Splitter; + this->setImpl(anOperation); + this->setBuilderType(OCCT_BOPAlgo_Builder); // Getting objects. - TopTools_ListOfShape anObjects; for (ListOfShape::const_iterator anObjectsIt = theObjects.begin(); anObjectsIt != theObjects.end(); anObjectsIt++) { const TopoDS_Shape& aShape = (*anObjectsIt)->impl(); anOperation->AddArgument(aShape); } // Getting tools. - TopTools_ListOfShape aTools; for (ListOfShape::const_iterator aToolsIt = theTools.begin(); aToolsIt != theTools.end(); aToolsIt++) { const TopoDS_Shape& aShape = (*aToolsIt)->impl(); anOperation->AddTool(aShape); @@ -65,53 +60,37 @@ void GeomAlgoAPI_Partition::build(const ListOfShape& theObjects, // Building and getting result. anOperation->Perform(); - TopoDS_Shape aResult = anOperation->Shape(); - myDone = !aResult.IsNull(); - if (!myDone) { + if(anOperation->ErrorStatus() != 0) { return; } + TopoDS_Shape aResult = anOperation->Shape(); if(aResult.ShapeType() == TopAbs_COMPOUND) { aResult = GeomAlgoAPI_DFLoader::refineResult(aResult); } - - // fill data map to keep correct orientation of sub-shapes - for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) { - std::shared_ptr aCurrentShape(new GeomAPI_Shape()); - aCurrentShape->setImpl(new TopoDS_Shape(Exp.Current())); - myMap->bind(aCurrentShape, aCurrentShape); + if(aResult.ShapeType() == TopAbs_COMPOUND) { + std::shared_ptr aCompound(new GeomAPI_Shape); + aCompound->setImpl(new TopoDS_Shape(aResult)); + ListOfShape aCompSolids, aFreeSolids; + GeomAlgoAPI_ShapeTools::combineShapes(aCompound, GeomAPI_Shape::COMPSOLID, aCompSolids, aFreeSolids); + if(aCompSolids.size() == 1 && aFreeSolids.size() == 0) { + aResult = aCompSolids.front()->impl(); + } else if (aCompSolids.size() > 1 || (aCompSolids.size() >= 1 && aFreeSolids.size() >= 1)) { + TopoDS_Compound aResultComp; + TopoDS_Builder aBuilder; + aBuilder.MakeCompound(aResultComp); + for(ListOfShape::const_iterator anIter = aCompSolids.cbegin(); anIter != aCompSolids.cend(); anIter++) { + aBuilder.Add(aResultComp, (*anIter)->impl()); + } + for(ListOfShape::const_iterator anIter = aFreeSolids.cbegin(); anIter != aFreeSolids.cend(); anIter++) { + aBuilder.Add(aResultComp, (*anIter)->impl()); + } + aResult = aResultComp; + } } - myShape->setImpl(new TopoDS_Shape(aResult)); - -} - -//================================================================================================= -const bool GeomAlgoAPI_Partition::isDone() const -{ - return myDone; -} - -//================================================================================================= -const bool GeomAlgoAPI_Partition::isValid() const -{ - BRepCheck_Analyzer aChecker(myShape->impl()); - return (aChecker.IsValid() == Standard_True); -} - -//================================================================================================= -const std::shared_ptr& GeomAlgoAPI_Partition::shape() const -{ - return myShape; -} -//================================================================================================= -std::shared_ptr GeomAlgoAPI_Partition::mapOfShapes() const -{ - return myMap; -} - -//================================================================================================= -std::shared_ptr GeomAlgoAPI_Partition::makeShape() const -{ - return myMkShape; + std::shared_ptr aShape(new GeomAPI_Shape()); + aShape->setImpl(new TopoDS_Shape(aResult)); + this->setShape(aShape); + this->setDone(true); }