From: dbv Date: Tue, 10 May 2016 12:38:30 +0000 (+0300) Subject: Test case for SubShapes X-Git-Tag: V_2.3.1~95 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ecb24ca2fcb8106ec21cd6bb01f8fc3dec55ae50;p=modules%2Fshaper.git Test case for SubShapes --- diff --git a/src/BuildPlugin/CMakeLists.txt b/src/BuildPlugin/CMakeLists.txt index 97e9633ad..ad77b74a9 100644 --- a/src/BuildPlugin/CMakeLists.txt +++ b/src/BuildPlugin/CMakeLists.txt @@ -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 index 000000000..5f6874641 --- /dev/null +++ b/src/BuildPlugin/Test/TestSubShapes.py @@ -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)