]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fixes for Boolean operations;
authordbv <dbv@opencascade.com>
Wed, 29 Jun 2016 15:15:36 +0000 (18:15 +0300)
committerdbv <dbv@opencascade.com>
Wed, 29 Jun 2016 15:15:36 +0000 (18:15 +0300)
High API for Boolean Smash and Boolean Fill;
Test case for Boolean Fill.

src/FeaturesAPI/FeaturesAPI_Boolean.cpp
src/FeaturesAPI/FeaturesAPI_Boolean.h
src/FeaturesPlugin/CMakeLists.txt
src/FeaturesPlugin/Test/TestBooleanFill.py [new file with mode: 0644]
src/FeaturesPlugin/boolean_widget.xml
src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp
src/PythonAPI/model/features/__init__.py

index 0774fb529c656181ca682e93be99acc83dd00506..4ee728c6c45132dee6e2606b599a74b76652dbd8 100644 (file)
@@ -110,3 +110,27 @@ BooleanPtr addCommon(const std::shared_ptr<ModelAPI_Document>& thePart,
                                             theMainObjects,
                                             theToolObjects));
 }
+
+//==================================================================================================
+BooleanPtr addSmash(const std::shared_ptr<ModelAPI_Document>& thePart,
+                    const std::list<ModelHighAPI_Selection>& theMainObjects,
+                    const std::list<ModelHighAPI_Selection>& theToolObjects)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Boolean::ID());
+  return BooleanPtr(new FeaturesAPI_Boolean(aFeature,
+                                            FeaturesPlugin_Boolean::BOOL_SMASH,
+                                            theMainObjects,
+                                            theToolObjects));
+}
+
+//==================================================================================================
+BooleanPtr addFill(const std::shared_ptr<ModelAPI_Document>& thePart,
+                   const std::list<ModelHighAPI_Selection>& theMainObjects,
+                   const std::list<ModelHighAPI_Selection>& theToolObjects)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Boolean::ID());
+  return BooleanPtr(new FeaturesAPI_Boolean(aFeature,
+                                            FeaturesPlugin_Boolean::BOOL_FILL,
+                                            theMainObjects,
+                                            theToolObjects));
+}
index 6e8833a35a864a9be2b85593759e9bb97d4447b6..9ad38f4bcf4b462cb0cb8a3c1db36a8b4f441f1e 100644 (file)
@@ -86,4 +86,18 @@ BooleanPtr addCommon(const std::shared_ptr<ModelAPI_Document>& thePart,
                      const std::list<ModelHighAPI_Selection>& theMainObjects,
                      const std::list<ModelHighAPI_Selection>& theToolObjects);
 
+/// \ingroup CPPHighAPI
+/// \brief Create Boolean Smash feature.
+FEATURESAPI_EXPORT
+BooleanPtr addSmash(const std::shared_ptr<ModelAPI_Document>& thePart,
+                    const std::list<ModelHighAPI_Selection>& theMainObjects,
+                    const std::list<ModelHighAPI_Selection>& theToolObjects);
+
+/// \ingroup CPPHighAPI
+/// \brief Create Boolean Fill feature.
+FEATURESAPI_EXPORT
+BooleanPtr addFill(const std::shared_ptr<ModelAPI_Document>& thePart,
+                   const std::list<ModelHighAPI_Selection>& theMainObjects,
+                   const std::list<ModelHighAPI_Selection>& theToolObjects);
+
 #endif // FeaturesAPI_Boolean_H_
index a14f2832bff746f5b1a01b6194b94e01e1c5669e..763e5138c491fa0465f63b90d54154b3b2be0c61 100644 (file)
@@ -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 (file)
index 0000000..26caead
--- /dev/null
@@ -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()
index 83c5cee2bea6460e2c0fde655126b0c795755c41..262c1c97a6b2dd27c1c8493856e499a475a53e79 100644 (file)
@@ -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"
   />
   <multi_selector id="main_objects"
index 3d072c2225a7b16975eebaf2c4c0d560d4149d9b..f1c9569aa27021bc8431c21a3b93ab8f643a2070 100644 (file)
@@ -225,7 +225,9 @@ std::shared_ptr<GeomAPI_Shape> 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<GeomAPI_Shape> GeomAlgoAPI_ShapeTools::groupSharedTopology(const
     aGroups.Append(aGroupedShapes);
   }
 
-  TopoDS_Compound aCompound;
-  BRep_Builder aBuilder;
-  aBuilder.MakeCompound(aCompound);
-  ListOfShape aCompSolids, aFreeSolids;
-  for(NCollection_Vector<NCollection_List<TopoDS_Shape>>::Iterator anIt(aGroups); anIt.More(); anIt.Next()) {
-    NCollection_List<TopoDS_Shape> aGroup = anIt.Value();
+  if(aGroups.Size() == 1) {
+    NCollection_List<TopoDS_Shape> 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<NCollection_List<TopoDS_Shape>>::Iterator anIt(aGroups); anIt.More(); anIt.Next()) {
+      NCollection_List<TopoDS_Shape> 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<TopoDS_Shape>());
     }
-    aBuilder.Add(aCompound, aGeomShape->impl<TopoDS_Shape>());
-  }
 
-  if(!aCompound.IsNull()) {
-    aResult->setImpl(new TopoDS_Shape(aCompound));
+    if(!aCompound.IsNull()) {
+      aResult->setImpl(new TopoDS_Shape(aCompound));
+    }
   }
 
   return aResult;
index b4266e76bef0b5a66f4a3c2bbc48a405421a8352..b0f8a075e534b2eb8aa96bb8b62108138be26beb 100644 (file)
@@ -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