1 # Initialization of the test
3 from GeomDataAPI import *
4 from GeomAlgoAPI import *
9 def createPoint(theSketchFeature):
10 aSketchPointFeature = theSketchFeature.addFeature("SketchPoint")
11 aPointCoordindates = geomDataAPI_Point2D(aSketchPointFeature.attribute("PointCoordindates"))
12 aPointCoordindates.setValue(random.uniform(0, 50), random.uniform(0, 50))
13 return aSketchPointFeature
15 def createLine(theSketchFeature):
16 aSketchLineFeature = theSketchFeature.addFeature("SketchLine")
17 aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
18 aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
19 aSketchLineStartPoint.setValue(random.uniform(0, 50), random.uniform(0, 50))
20 aSketchLineEndPoint.setValue(random.uniform(0, 50), random.uniform(0, 50))
21 return aSketchLineFeature
24 aSession = ModelAPI_Session.get()
25 aDocument = aSession.moduleDocument()
28 aSession.startOperation()
29 aPartFeature = aDocument.addFeature("Part")
30 aSession.finishOperation()
31 aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
32 aPart = aPartResult.partDoc()
35 aSession.startOperation()
36 aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
37 anOrigin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
38 anOrigin.setValue(0, 0, 0)
39 aDirX = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
40 aDirX.setValue(1, 0, 0)
41 aNorm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
42 aNorm.setValue(0, 0, 1)
45 aSketchLineFeature = aSketchFeature.addFeature("SketchLine")
46 aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
47 aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
48 aSketchLineStartPoint.setValue(0, 0)
49 aSketchLineEndPoint.setValue(0, 50)
50 aSketchLineFeature = aSketchFeature.addFeature("SketchLine")
51 aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
52 aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
53 aSketchLineStartPoint.setValue(0, 50)
54 aSketchLineEndPoint.setValue(50, 50)
55 aSketchLineFeature = aSketchFeature.addFeature("SketchLine")
56 aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
57 aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
58 aSketchLineStartPoint.setValue(50, 50)
59 aSketchLineEndPoint.setValue(50, 0)
60 aSketchLineFeature = aSketchFeature.addFeature("SketchLine")
61 aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
62 aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
63 aSketchLineStartPoint.setValue(50, 0)
64 aSketchLineEndPoint.setValue(0, 0)
66 aSession.finishOperation()
67 aSketchResult = aSketchFeature.firstResult()
68 aSketchShape = aSketchResult.shape()
71 aSession.startOperation()
72 aFaceFeature = aPart.addFeature("Face")
73 aBaseObjectsList = aFaceFeature.selectionList("base_objects")
74 aShapeExplorer = GeomAPI_ShapeExplorer(aSketchShape, GeomAPI_Shape.EDGE)
75 while aShapeExplorer.more():
76 aBaseObjectsList.append(aSketchResult, aShapeExplorer.current())
78 aSession.finishOperation()
79 aFaceResult = aFaceFeature.firstResult()
81 # Create a sketch with points and lines
82 aSession.startOperation()
83 aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
84 anOrigin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
85 anOrigin.setValue(0, 0, 0)
86 aDirX = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
87 aDirX.setValue(1, 0, 0)
88 aNorm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
89 aNorm.setValue(0, 0, 1)
94 for i in range(aNumOfPoints):
95 aSession.startOperation()
96 aSketchPointFeature = createPoint(aSketchFeature)
97 aSession.finishOperation()
98 aPoints.append(aSketchPointFeature.firstResult().shape())
103 for i in range(aNumOfLines):
104 aSession.startOperation()
105 aSketchLineFeature = createLine(aSketchFeature)
106 aSession.finishOperation()
107 aLines.append(aSketchLineFeature.firstResult().shape())
109 aSession.finishOperation()
110 aSketchResult = aSketchFeature.firstResult()
111 aSketchShape = aSketchResult.shape()
114 aSession.startOperation()
115 aSubShapesFeature = aPart.addFeature("SubShapes")
116 aBaseShapeSelection = aSubShapesFeature.selection("base_shape")
117 aBaseShapeSelection.setValue(aFaceResult, None)
118 aSubShapesList = aSubShapesFeature.selectionList("subshapes")
119 for aPoint in aPoints:
120 aSubShapesList.append(aSketchResult, aPoint)
121 aShapeExplorer = GeomAPI_ShapeExplorer(aSketchShape, GeomAPI_Shape.EDGE)
122 while aShapeExplorer.more():
123 aSubShapesList.append(aSketchResult, aShapeExplorer.current())
124 aShapeExplorer.next()
125 aSession.finishOperation()
128 assert (len(aSubShapesFeature.results()) > 0)