]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Test case for SubShapes
authordbv <dbv@opencascade.com>
Tue, 10 May 2016 12:38:30 +0000 (15:38 +0300)
committerdbv <dbv@opencascade.com>
Tue, 10 May 2016 12:38:30 +0000 (15:38 +0300)
src/BuildPlugin/CMakeLists.txt
src/BuildPlugin/Test/TestSubShapes.py [new file with mode: 0644]

index 97e9633ad3986dfaafa8dfbb82058739a4e76d28..ad77b74a95575ff65f8f78c03d32388ff1c92c9e 100644 (file)
@@ -65,4 +65,6 @@ INSTALL(DIRECTORY icons/ DESTINATION ${SHAPER_INSTALL_XML_RESOURCES}/icons/Build
 ADD_UNIT_TESTS(TestVertex.py
                TestEdge.py
                TestWire.py
-               TestFace.py)
+               TestFace.py
+               TestShell.py
+               TestSubShapes.py)
diff --git a/src/BuildPlugin/Test/TestSubShapes.py b/src/BuildPlugin/Test/TestSubShapes.py
new file mode 100644 (file)
index 0000000..5f68746
--- /dev/null
@@ -0,0 +1,128 @@
+# Initialization of the test
+from ModelAPI import *
+from GeomDataAPI import *
+from GeomAlgoAPI import *
+from GeomAPI import *
+
+import random
+
+def createPoint(theSketchFeature):
+    aSketchPointFeature = theSketchFeature.addFeature("SketchPoint")
+    aPointCoordindates = geomDataAPI_Point2D(aSketchPointFeature.attribute("PointCoordindates"))
+    aPointCoordindates.setValue(random.uniform(0, 50), random.uniform(0, 50))
+    return aSketchPointFeature
+
+def createLine(theSketchFeature):
+    aSketchLineFeature = theSketchFeature.addFeature("SketchLine")
+    aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
+    aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
+    aSketchLineStartPoint.setValue(random.uniform(0, 50), random.uniform(0, 50))
+    aSketchLineEndPoint.setValue(random.uniform(0, 50), random.uniform(0, 50))
+    return aSketchLineFeature
+
+# Get document
+aSession = ModelAPI_Session.get()
+aDocument = aSession.moduleDocument()
+
+# Create a part
+aSession.startOperation()
+aPartFeature = aDocument.addFeature("Part")
+aSession.finishOperation()
+aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
+aPart = aPartResult.partDoc()
+
+# Create a sketch
+aSession.startOperation()
+aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
+anOrigin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
+anOrigin.setValue(0, 0, 0)
+aDirX = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
+aDirX.setValue(1, 0, 0)
+aNorm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
+aNorm.setValue(0, 0, 1)
+
+# Create lines
+aSketchLineFeature = aSketchFeature.addFeature("SketchLine")
+aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
+aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
+aSketchLineStartPoint.setValue(0, 0)
+aSketchLineEndPoint.setValue(0, 50)
+aSketchLineFeature = aSketchFeature.addFeature("SketchLine")
+aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
+aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
+aSketchLineStartPoint.setValue(0, 50)
+aSketchLineEndPoint.setValue(50, 50)
+aSketchLineFeature = aSketchFeature.addFeature("SketchLine")
+aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
+aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
+aSketchLineStartPoint.setValue(50, 50)
+aSketchLineEndPoint.setValue(50, 0)
+aSketchLineFeature = aSketchFeature.addFeature("SketchLine")
+aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
+aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
+aSketchLineStartPoint.setValue(50, 0)
+aSketchLineEndPoint.setValue(0, 0)
+
+aSession.finishOperation()
+aSketchResult = aSketchFeature.firstResult()
+aSketchShape = aSketchResult.shape()
+
+# Create face
+aSession.startOperation()
+aFaceFeature = aPart.addFeature("Face")
+aBaseObjectsList = aFaceFeature.selectionList("base_objects")
+aShapeExplorer = GeomAPI_ShapeExplorer(aSketchShape, GeomAPI_Shape.EDGE)
+while aShapeExplorer.more():
+    aBaseObjectsList.append(aSketchResult, aShapeExplorer.current())
+    aShapeExplorer.next()
+aSession.finishOperation()
+aFaceResult = aFaceFeature.firstResult()
+
+# Create a sketch with points and lines
+aSession.startOperation()
+aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
+anOrigin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
+anOrigin.setValue(0, 0, 0)
+aDirX = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
+aDirX.setValue(1, 0, 0)
+aNorm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
+aNorm.setValue(0, 0, 1)
+
+# Create points
+aNumOfPoints = 10
+aPoints = []
+for i in range(aNumOfPoints):
+    aSession.startOperation()
+    aSketchPointFeature = createPoint(aSketchFeature)
+    aSession.finishOperation()
+    aPoints.append(aSketchPointFeature.firstResult().shape())
+
+# Create lines
+aNumOfLines = 10
+aLines = []
+for i in range(aNumOfLines):
+    aSession.startOperation()
+    aSketchLineFeature = createLine(aSketchFeature)
+    aSession.finishOperation()
+    aLines.append(aSketchLineFeature.firstResult().shape())
+
+aSession.finishOperation()
+aSketchResult = aSketchFeature.firstResult()
+aSketchShape = aSketchResult.shape()
+
+# Create sub-shapes
+aSession.startOperation()
+aSubShapesFeature = aPart.addFeature("SubShapes")
+aBaseShapeSelection = aSubShapesFeature.selection("base_shape")
+aBaseShapeSelection.setValue(aFaceResult, None)
+aSubShapesList = aSubShapesFeature.selectionList("sub_shapes")
+for aPoint in aPoints:
+    aSubShapesList.append(aSketchResult, aPoint)
+aShapeExplorer = GeomAPI_ShapeExplorer(aSketchShape, GeomAPI_Shape.EDGE)
+while aShapeExplorer.more():
+    aSubShapesList.append(aSketchResult, aShapeExplorer.current())
+    aShapeExplorer.next()
+aSession.finishOperation()
+
+# Test results
+assert (len(aSubShapesFeature.results()) > 0)