From ad65e8a81e0848a96a4124626a59a511655fb036 Mon Sep 17 00:00:00 2001 From: dbv Date: Wed, 29 Jun 2016 18:15:36 +0300 Subject: [PATCH] Fixes for Boolean operations; High API for Boolean Smash and Boolean Fill; Test case for Boolean Fill. --- src/FeaturesAPI/FeaturesAPI_Boolean.cpp | 24 ++++++++++ src/FeaturesAPI/FeaturesAPI_Boolean.h | 14 ++++++ src/FeaturesPlugin/CMakeLists.txt | 1 + src/FeaturesPlugin/Test/TestBooleanFill.py | 45 +++++++++++++++++++ src/FeaturesPlugin/boolean_widget.xml | 4 +- src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp | 52 ++++++++++++++-------- src/PythonAPI/model/features/__init__.py | 2 +- 7 files changed, 120 insertions(+), 22 deletions(-) create mode 100644 src/FeaturesPlugin/Test/TestBooleanFill.py diff --git a/src/FeaturesAPI/FeaturesAPI_Boolean.cpp b/src/FeaturesAPI/FeaturesAPI_Boolean.cpp index 0774fb529..4ee728c6c 100644 --- a/src/FeaturesAPI/FeaturesAPI_Boolean.cpp +++ b/src/FeaturesAPI/FeaturesAPI_Boolean.cpp @@ -110,3 +110,27 @@ BooleanPtr addCommon(const std::shared_ptr& thePart, theMainObjects, theToolObjects)); } + +//================================================================================================== +BooleanPtr addSmash(const std::shared_ptr& thePart, + const std::list& theMainObjects, + const std::list& theToolObjects) +{ + std::shared_ptr aFeature = thePart->addFeature(FeaturesAPI_Boolean::ID()); + return BooleanPtr(new FeaturesAPI_Boolean(aFeature, + FeaturesPlugin_Boolean::BOOL_SMASH, + theMainObjects, + theToolObjects)); +} + +//================================================================================================== +BooleanPtr addFill(const std::shared_ptr& thePart, + const std::list& theMainObjects, + const std::list& theToolObjects) +{ + std::shared_ptr aFeature = thePart->addFeature(FeaturesAPI_Boolean::ID()); + return BooleanPtr(new FeaturesAPI_Boolean(aFeature, + FeaturesPlugin_Boolean::BOOL_FILL, + theMainObjects, + theToolObjects)); +} diff --git a/src/FeaturesAPI/FeaturesAPI_Boolean.h b/src/FeaturesAPI/FeaturesAPI_Boolean.h index 6e8833a35..9ad38f4bc 100644 --- a/src/FeaturesAPI/FeaturesAPI_Boolean.h +++ b/src/FeaturesAPI/FeaturesAPI_Boolean.h @@ -86,4 +86,18 @@ BooleanPtr addCommon(const std::shared_ptr& thePart, const std::list& theMainObjects, const std::list& theToolObjects); +/// \ingroup CPPHighAPI +/// \brief Create Boolean Smash feature. +FEATURESAPI_EXPORT +BooleanPtr addSmash(const std::shared_ptr& thePart, + const std::list& theMainObjects, + const std::list& theToolObjects); + +/// \ingroup CPPHighAPI +/// \brief Create Boolean Fill feature. +FEATURESAPI_EXPORT +BooleanPtr addFill(const std::shared_ptr& thePart, + const std::list& theMainObjects, + const std::list& theToolObjects); + #endif // FeaturesAPI_Boolean_H_ diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index a14f2832b..763e5138c 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -122,6 +122,7 @@ ADD_UNIT_TESTS(TestExtrusion.py TestBoolean.py TestBooleanCompSolids.py TestBooleanSmash.py + TestBooleanFill.py TestMultiBoolean.py TestSerialBoolean.py TestGroup.py diff --git a/src/FeaturesPlugin/Test/TestBooleanFill.py b/src/FeaturesPlugin/Test/TestBooleanFill.py new file mode 100644 index 000000000..26caead92 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestBooleanFill.py @@ -0,0 +1,45 @@ +""" +Test case for Boolean Fill feature. Written on High API. +""" +from ModelAPI import * +from GeomAPI import * + +import model + +# Get session +aSession = ModelAPI_Session.get() + +# Create a part +aDocument = aSession.activeDocument() +aSession.startOperation() +model.addPart(aDocument) +aDocument = aSession.activeDocument() +aSession.finishOperation() + +# Create a sketch with circle to extrude +aSession.startOperation() +anOrigin = GeomAPI_Pnt(0, 0, 0) +aDirX = GeomAPI_Dir(1, 0, 0) +aNorm = GeomAPI_Dir(0, 0, 1) +aCircleSketch = model.addSketch(aDocument, GeomAPI_Ax3(anOrigin, aDirX, aNorm)) +aCircleSketch.addCircle(0, 0, 50) +aSession.finishOperation() + +# Create a sketch with triangle to extrude +aSession.startOperation() +aTriangleSketch = model.addSketch(aDocument, GeomAPI_Ax3(anOrigin, aDirX, aNorm)) +aTriangleSketch.addLine(25, 25, 100, 25) +aTriangleSketch.addLine(100, 25, 60, 75) +aTriangleSketch.addLine(60, 75, 25, 25) +aSession.finishOperation() + +# Make extrusion on circle (cylinder) and triangle (prism) +aSession.startOperation() +anExtrusion = model.addExtrusion(aDocument, aCircleSketch.result() + aTriangleSketch.result(), 100) +aSession.finishOperation() + +# Fill prism with cylinder +aSession.startOperation() +aBoolean = model.addFill(aDocument, [anExtrusion.result()[0]], [anExtrusion.result()[1]]) +assert (len(aBoolean.result()) > 0) +aSession.finishOperation() diff --git a/src/FeaturesPlugin/boolean_widget.xml b/src/FeaturesPlugin/boolean_widget.xml index 83c5cee2b..262c1c97a 100644 --- a/src/FeaturesPlugin/boolean_widget.xml +++ b/src/FeaturesPlugin/boolean_widget.xml @@ -6,9 +6,9 @@ buttons_dir="horizontal" label="Operation type" tooltip="Type of boolean operation" - string_list="Cut Fuse Common Smash" + string_list="Cut Fuse Common Fill Smash" use_in_title="true" - icons_list="icons/Features/bool_cut.png icons/Features/bool_fuse.png icons/Features/bool_common.png icons/Features/bool_smash.png" + icons_list="icons/Features/bool_cut.png icons/Features/bool_fuse.png icons/Features/bool_common.png icons/Features/bool_fill.png icons/Features/bool_smash.png" default="0" /> GeomAlgoAPI_ShapeTools::combineShapes(const std:: if(theCombinedShapes.size() == 1 && theFreeShapes.size() == 0) { aResult = theCombinedShapes.front(); - } else if (theCombinedShapes.size() > 1 || (theCombinedShapes.size() >= 1 && theFreeShapes.size() >= 1)) { + } else if(theCombinedShapes.size() == 0 && theFreeShapes.size() == 1) { + aResult = theFreeShapes.front(); + } else { TopoDS_Compound aResultComp; TopoDS_Builder aBuilder; aBuilder.MakeCompound(aResultComp); @@ -318,27 +320,39 @@ std::shared_ptr GeomAlgoAPI_ShapeTools::groupSharedTopology(const aGroups.Append(aGroupedShapes); } - 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(); + if(aGroups.Size() == 1) { + NCollection_List aGroup = aGroups.First(); GeomShapePtr aGeomShape(new GeomAPI_Shape()); - if(aGroup.Size() == 1) { - aGeomShape->setImpl(new TopoDS_Shape(aGroup.First())); - } else { - aGeomShape->setImpl(new TopoDS_Shape(makeCompound(anIt.Value()))); - aGeomShape = GeomAlgoAPI_ShapeTools::combineShapes(aGeomShape, - GeomAPI_Shape::COMPSOLID, - aCompSolids, - aFreeSolids); + 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()); } - 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/PythonAPI/model/features/__init__.py b/src/PythonAPI/model/features/__init__.py index b4266e76b..b0f8a075e 100644 --- a/src/PythonAPI/model/features/__init__.py +++ b/src/PythonAPI/model/features/__init__.py @@ -3,7 +3,7 @@ from FeaturesAPI import addPlacement, addRotation, addTranslation -from FeaturesAPI import addFuse, addCut, addCommon +from FeaturesAPI import addCut, addFuse, addCommon, addSmash, addFill from FeaturesAPI import addPartition -- 2.30.2