]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Test for boolean with compsolid
authordbv <dbv@opencascade.com>
Fri, 18 Sep 2015 08:48:46 +0000 (11:48 +0300)
committerdbv <dbv@opencascade.com>
Fri, 18 Sep 2015 08:48:57 +0000 (11:48 +0300)
src/FeaturesPlugin/CMakeLists.txt
src/FeaturesPlugin/Test/TestBooleanCompSolids.py [new file with mode: 0644]
src/ModelAPI/ModelAPI.i

index ab09c8cf301e55624aa1d34b1157d80ae2cc653c..7338ddfb864e2874d370dfea9dc039afa7d45418 100644 (file)
@@ -102,6 +102,7 @@ ADD_UNIT_TESTS(TestExtrusion.py
                TestTranslation.py
                TestRotation.py
                TestBoolean.py
+               TestBooleanCompSolids.py
                TestMultiBoolean.py
                TestSerialBoolean.py
                TestGroup.py)
diff --git a/src/FeaturesPlugin/Test/TestBooleanCompSolids.py b/src/FeaturesPlugin/Test/TestBooleanCompSolids.py
new file mode 100644 (file)
index 0000000..47e6bea
--- /dev/null
@@ -0,0 +1,113 @@
+#=========================================================================
+# Initialization of the test
+#=========================================================================
+from ModelAPI import *
+from GeomDataAPI import *
+from GeomAlgoAPI import *
+from GeomAPI import *
+
+__updated__ = "2014-12-16"
+
+aSession = ModelAPI_Session.get()
+# Create a part for extrusions & boolean
+aSession.startOperation()
+aPartFeature = aSession.moduleDocument().addFeature("Part")
+aSession.finishOperation()
+aPart = aSession.activeDocument()
+#=========================================================================
+# Create a sketch with circle to extrude
+#=========================================================================
+aSession.startOperation()
+aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
+origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
+origin.setValue(0, 0, 0)
+dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
+dirx.setValue(1, 0, 0)
+norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
+norm.setValue(0, 0, 1)
+
+aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
+aCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
+aCircleRadius = aSketchCircle.real("CircleRadius")
+aCircleCentr.setValue(0, 0)
+aCircleRadius.setValue(50)
+
+aSketchLine = aCircleSketchFeature.addFeature("SketchLine")
+aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
+aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
+aLineStartPoint.setValue(0, -50)
+aLineEndPoint.setValue(0, 50)
+aSession.finishOperation()
+#=========================================================================
+# Create a sketch with triangle to extrude
+#=========================================================================
+aSession.startOperation()
+aTriangleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
+origin = geomDataAPI_Point(aTriangleSketchFeature.attribute("Origin"))
+origin.setValue(0, 0, 0)
+dirx = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirX"))
+dirx.setValue(1, 0, 0)
+norm = geomDataAPI_Dir(aTriangleSketchFeature.attribute("Norm"))
+norm.setValue(0, 0, 1)
+aSketchLineA = aTriangleSketchFeature.addFeature("SketchLine")
+aSketchLineB = aTriangleSketchFeature.addFeature("SketchLine")
+aSketchLineC = aTriangleSketchFeature.addFeature("SketchLine")
+aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
+aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
+aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
+aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
+aLineCStartPoint = geomDataAPI_Point2D(aSketchLineC.attribute("StartPoint"))
+aLineCEndPoint = geomDataAPI_Point2D(aSketchLineC.attribute("EndPoint"))
+aLineAStartPoint.setValue(25., 25.)
+aLineAEndPoint.setValue(100., 25.)
+aLineBStartPoint.setValue(100., 25.)
+aLineBEndPoint.setValue(60., 75.)
+aLineCStartPoint.setValue(60., 75.)
+aLineCEndPoint.setValue(25., 25.)
+aSession.finishOperation()
+#=========================================================================
+# Make extrusion on circle (cylinder) and triangle (prism)
+#=========================================================================
+# Build shape from sketcher results
+aSession.startOperation()
+extrudedObjects = []
+for eachSketchFeature in [aCircleSketchFeature, aTriangleSketchFeature]:
+    # Build sketch faces
+    aSketchResult = eachSketchFeature.firstResult()
+    aSketchEdges = modelAPI_ResultConstruction(aSketchResult).shape()
+    origin = geomDataAPI_Point(eachSketchFeature.attribute("Origin")).pnt()
+    dirX = geomDataAPI_Dir(eachSketchFeature.attribute("DirX")).dir()
+    norm = geomDataAPI_Dir(eachSketchFeature.attribute("Norm")).dir()
+    aSketchFaces = ShapeList()
+    GeomAlgoAPI_SketchBuilder.createFaces(
+        origin, dirX, norm, aSketchEdges, aSketchFaces)
+    # Create extrusion on them
+    anExtrusionFt = aPart.addFeature("Extrusion")
+    anExtrusionFt.selectionList("base").append(
+        aSketchResult, None)
+    anExtrusionFt.string("CreationMethod").setValue("BySizes")
+    anExtrusionFt.real("from_size").setValue(0)
+    anExtrusionFt.real("to_size").setValue(50)
+    anExtrusionFt.real("to_offset").setValue(0) #TODO: remove
+    anExtrusionFt.real("from_offset").setValue(0) #TODO: remove
+    anExtrusionFt.execute()
+    extrudedObjects.append(modelAPI_ResultBody(anExtrusionFt.firstResult()))
+aSession.finishOperation()
+#=========================================================================
+# Create a pacman as boolean cut of the prism from the cylinder
+#=========================================================================
+aSession.startOperation()
+aBooleanFt = aPart.addFeature("Boolean")
+aBooleanFt.selectionList("main_objects").append(modelAPI_ResultCompSolid(extrudedObjects[0]).subResult(1), None)
+aBooleanFt.selectionList("tool_objects").append(extrudedObjects[1], None)
+aBooleanType = 1
+aBooleanFt.integer("bool_type").setValue(aBooleanType)
+aBooleanFt.execute()
+aSession.finishOperation()
+
+assert (len(aBooleanFt.results()) > 0)
+aBooleanResult = modelAPI_ResultBody(aBooleanFt.firstResult())
+assert (aBooleanResult is not None)
+#=========================================================================
+# End of test
+#=========================================================================
index 46efe12ab7e1b30b0c39b8cb12330a758aabceca..7da97d0c182ff97c2324541f1e984eb16cd2ca3e 100644 (file)
@@ -39,6 +39,7 @@
   #include "ModelAPI_ResultParameter.h"
   #include "ModelAPI_ResultGroup.h"
   #include "ModelAPI_Tools.h"
+  #include "ModelAPI_ResultCompSolid.h"
   
   #include <memory>
   #include <string>
@@ -98,6 +99,7 @@
 %shared_ptr(ModelAPI_ResultPart)
 %shared_ptr(ModelAPI_ResultGroup)
 %shared_ptr(ModelAPI_ResultParameter)
+%shared_ptr(ModelAPI_ResultCompSolid)
 
 // all supported interfaces
 %include "ModelAPI_Entity.h"
 %include "ModelAPI_ResultGroup.h"
 %include "ModelAPI_ResultParameter.h"
 %include "ModelAPI_Tools.h"
+%include "ModelAPI_ResultCompSolid.h"
 
 // std::list -> [] 
 %template(ObjectList) std::list<std::shared_ptr<ModelAPI_Object> >;
@@ -147,6 +150,7 @@ template<class T1, class T2> std::shared_ptr<T1> shared_ptr_cast(std::shared_ptr
 %template(modelAPI_ResultPart) shared_ptr_cast<ModelAPI_ResultPart, ModelAPI_Result>;
 %template(modelAPI_ResultParameter) shared_ptr_cast<ModelAPI_ResultParameter, ModelAPI_Result>;
 %template(modelAPI_ResultGroup) shared_ptr_cast<ModelAPI_ResultPart, ModelAPI_ResultGroup>;
+%template(modelAPI_ResultCompSolid) shared_ptr_cast<ModelAPI_ResultCompSolid, ModelAPI_ResultBody>;
 
 // Attribute casts
 %template(modelAPI_AttributeDocRef)        shared_ptr_cast<ModelAPI_AttributeDocRef, ModelAPI_Attribute>;