From 2924934c7f9012f6167df2d00d372f295b51dc1b Mon Sep 17 00:00:00 2001 From: dbv Date: Thu, 5 May 2016 11:53:48 +0300 Subject: [PATCH] Issue #1482: Fixed results of Extrusion, Revolution, Pipe and Partition. If it is a wire with one edge it will be stored as edge, if it is a shell with one face it will be stored as face. --- src/GeomAlgoAPI/GeomAlgoAPI_DFLoader.cpp | 27 +++++++------- src/GeomAlgoAPI/GeomAlgoAPI_Partition.cpp | 5 +++ src/GeomAlgoAPI/GeomAlgoAPI_Pipe.cpp | 41 ++++++++++++---------- src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp | 1 + src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp | 1 + 5 files changed, 45 insertions(+), 30 deletions(-) diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_DFLoader.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_DFLoader.cpp index 61e28412a..289db4f28 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_DFLoader.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_DFLoader.cpp @@ -13,20 +13,23 @@ //function : refineResult //purpose : //======================================================================= -const TopoDS_Shape GeomAlgoAPI_DFLoader::refineResult(const TopoDS_Shape& theResult) +const TopoDS_Shape GeomAlgoAPI_DFLoader::refineResult(const TopoDS_Shape& theResult) { - TopoDS_Shape aResult; - if (theResult.ShapeType() == TopAbs_COMPOUND) { - Standard_Integer nbSubResults = 0; - TopoDS_Iterator itr(theResult); - for (; itr.More(); itr.Next()) nbSubResults++; - if (nbSubResults == 1) { - itr.Initialize(theResult); - if (itr.More()) aResult = itr.Value(); - } else { - /// MPV: store compound anyway: it may be Boolean operation that produces two solids from one - aResult = theResult; + TopoDS_Shape aResult = theResult; + const TopAbs_ShapeEnum aShType = theResult.ShapeType(); + if(aShType == TopAbs_COMPOUND || aShType == TopAbs_SHELL || aShType == TopAbs_WIRE) { + Standard_Integer aSubResultsNb = 0; + TopoDS_Iterator anIt(theResult); + for(; anIt.More(); anIt.Next()) { + ++aSubResultsNb; + } + if(aSubResultsNb == 1) { + anIt.Initialize(theResult); + if(anIt.More()) { + aResult = anIt.Value(); + } } } + return aResult; } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Partition.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Partition.cpp index 63a1ddc9e..55455220c 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Partition.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Partition.cpp @@ -89,6 +89,11 @@ void GeomAlgoAPI_Partition::build(const ListOfShape& theObjects, } } + // Setting result. + if(aResult.IsNull()) { + return; + } + aResult = GeomAlgoAPI_DFLoader::refineResult(aResult); std::shared_ptr aShape(new GeomAPI_Shape()); aShape->setImpl(new TopoDS_Shape(aResult)); this->setShape(aShape); diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Pipe.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Pipe.cpp index 612df97c2..c24a9600e 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Pipe.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Pipe.cpp @@ -6,6 +6,8 @@ #include "GeomAlgoAPI_Pipe.h" +#include "GeomAlgoAPI_DFLoader.h" + #include #include #include @@ -99,10 +101,11 @@ void GeomAlgoAPI_Pipe::build(const GeomShapePtr theBaseShape, this->addToShape(aToShape); // Setting result. - TopoDS_Shape aResultShape = aPipeBuilder->Shape(); - GeomShapePtr aResultGeomShape(new GeomAPI_Shape()); - aResultGeomShape->setImpl(new TopoDS_Shape(aResultShape)); - this->setShape(aResultGeomShape); + TopoDS_Shape aResult = aPipeBuilder->Shape(); + aResult = GeomAlgoAPI_DFLoader::refineResult(aResult); + GeomShapePtr aGeomSh(new GeomAPI_Shape()); + aGeomSh->setImpl(new TopoDS_Shape(aResult)); + this->setShape(aGeomSh); this->setDone(true); } @@ -160,9 +163,7 @@ void GeomAlgoAPI_Pipe::build(const GeomShapePtr theBaseShape, return; } } - if(aPipeBuilder->Shape().IsNull()) { - return; - } + TopoDS_Shape aResult = aPipeBuilder->Shape(); // Setting naming. GeomShapePtr aFromShape(new GeomAPI_Shape), aToShape(new GeomAPI_Shape); @@ -172,10 +173,13 @@ void GeomAlgoAPI_Pipe::build(const GeomShapePtr theBaseShape, this->addToShape(aToShape); // Setting result. - TopoDS_Shape aResultShape = aPipeBuilder->Shape(); - GeomShapePtr aResultGeomShape(new GeomAPI_Shape()); - aResultGeomShape->setImpl(new TopoDS_Shape(aResultShape)); - this->setShape(aResultGeomShape); + if(aResult.IsNull()) { + return; + } + aResult = GeomAlgoAPI_DFLoader::refineResult(aResult); + GeomShapePtr aGeomSh(new GeomAPI_Shape()); + aGeomSh->setImpl(new TopoDS_Shape(aResult)); + this->setShape(aGeomSh); this->setDone(true); } @@ -251,9 +255,7 @@ void GeomAlgoAPI_Pipe::build(const ListOfShape& theBaseShapes, return; } } - if(aPipeBuilder->Shape().IsNull()) { - return; - } + TopoDS_Shape aResult = aPipeBuilder->Shape(); // Setting naming. GeomShapePtr aFromShape(new GeomAPI_Shape), aToShape(new GeomAPI_Shape); @@ -263,10 +265,13 @@ void GeomAlgoAPI_Pipe::build(const ListOfShape& theBaseShapes, this->addToShape(aToShape); // Setting result. - TopoDS_Shape aResultShape = aPipeBuilder->Shape(); - GeomShapePtr aResultGeomShape(new GeomAPI_Shape()); - aResultGeomShape->setImpl(new TopoDS_Shape(aResultShape)); - this->setShape(aResultGeomShape); + if(aResult.IsNull()) { + return; + } + aResult = GeomAlgoAPI_DFLoader::refineResult(aResult); + GeomShapePtr aGeomSh(new GeomAPI_Shape()); + aGeomSh->setImpl(new TopoDS_Shape(aResult)); + this->setShape(aGeomSh); this->setDone(true); } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp index 2829bff0a..7f2bd0b49 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp @@ -442,6 +442,7 @@ void GeomAlgoAPI_Prism::build(const GeomShapePtr& theBaseShape, if(aResult.IsNull()) { return; } + aResult = GeomAlgoAPI_DFLoader::refineResult(aResult); GeomShapePtr aGeomSh(new GeomAPI_Shape()); aGeomSh->setImpl(new TopoDS_Shape(aResult)); this->setShape(aGeomSh); diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp index 92e5924ea..889cce352 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp @@ -549,6 +549,7 @@ void GeomAlgoAPI_Revolution::build(const GeomShapePtr& theBaseSh if(aResult.IsNull()) { return; } + aResult = GeomAlgoAPI_DFLoader::refineResult(aResult); GeomShapePtr aShape(new GeomAPI_Shape()); aShape->setImpl(new TopoDS_Shape(aResult)); this->setShape(aShape); -- 2.39.2