6 from SketchAPI import *
7 from GeomAPI import GeomAPI_Shape
9 from salome.shaper import model
12 GeomAPI_Shape.SOLID: "GeomAPI_Shape.SOLID",
13 GeomAPI_Shape.FACE: "GeomAPI_Shape.FACE",
14 GeomAPI_Shape.EDGE: "GeomAPI_Shape.EDGE",
15 GeomAPI_Shape.VERTEX: "GeomAPI_Shape.VERTEX"}
17 def testNbUniqueSubShapes(theFeature, theShapeType, theExpectedNbSubShapes):
18 """ Tests number of unique feature sub-shapes of passed type for each result.
19 :param theFeature: feature to test.
20 :param theShapeType: shape type of sub-shapes to test.
21 :param theExpectedNbSubShapes: list of sub-shapes numbers. Size of list should be equal to len(theFeature.results()).
23 aResults = theFeature.feature().results()
24 aNbResults = len(aResults)
25 aListSize = len(theExpectedNbSubShapes)
26 assert (aNbResults == aListSize), "Number of results: {} not equal to list size: {}.".format(aNbResults, aListSize)
27 for anIndex in range(0, aNbResults):
28 aNbResultSubShapes = 0
29 anExpectedNbSubShapes = theExpectedNbSubShapes[anIndex]
30 aNbResultSubShapes = aResults[anIndex].shape().subShapes(theShapeType, True).size()
31 assert (aNbResultSubShapes == anExpectedNbSubShapes), "Number of sub-shapes of type {} for result[{}]: {}. Expected: {}.".format(aShapeTypes[theShapeType], anIndex, aNbResultSubShapes, anExpectedNbSubShapes)
33 def testResults(theFeature,theModel,NbRes,NbSubRes,NbShell,NbFace,NbEdge,NbVertex):
34 """ Tests numbers of unique sub-shapes in the results
36 aResults = theFeature.feature().results()
37 aNbResults = len(aResults)
38 assert (aNbResults == NbRes), "Number of results: {} not equal to {}}.".format(aNbResults, NbRes)
39 theModel.testNbSubResults(theFeature, NbSubRes)
40 testNbUniqueSubShapes(theFeature, GeomAPI_Shape.SHELL, NbShell)
41 testNbUniqueSubShapes(theFeature, GeomAPI_Shape.FACE, NbFace)
42 testNbUniqueSubShapes(theFeature, GeomAPI_Shape.EDGE, NbEdge)
43 testNbUniqueSubShapes(theFeature, GeomAPI_Shape.VERTEX, NbVertex)
47 partSet = model.moduleDocument()
50 Part_1 = model.addPart(partSet)
51 Part_1_doc = Part_1.document()
54 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
57 SketchLine_1 = Sketch_1.addLine(60, 0, 0, 0)
59 ### Create SketchProjection
60 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
61 SketchPoint_1 = SketchProjection_1.createdFeature()
62 Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchPoint_1.result())
65 SketchLine_2 = Sketch_1.addLine(0, 0, 0, 75)
68 SketchLine_3 = Sketch_1.addLine(0, 75, 60, 75)
71 SketchLine_4 = Sketch_1.addLine(60, 75, 60, 0)
72 Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint())
73 Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
74 Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
75 Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
76 Sketch_1.setHorizontal(SketchLine_1.result())
77 Sketch_1.setVertical(SketchLine_2.result())
78 Sketch_1.setHorizontal(SketchLine_3.result())
79 Sketch_1.setVertical(SketchLine_4.result())
83 Face_1 = model.addFace(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_4r-SketchLine_3r-SketchLine_2r-SketchLine_1r")])
86 Sketch_2 = model.addSketch(Part_1_doc, model.standardPlane("YOZ"))
89 SketchLine_5 = Sketch_2.addLine(75, 0.0001, 0, 0)
91 ### Create SketchProjection
92 SketchProjection_2 = Sketch_2.addProjection(model.selection("VERTEX", "Sketch_1/SketchLine_1_EndVertex"), False)
93 SketchPoint_2 = SketchProjection_2.createdFeature()
94 Sketch_2.setCoincident(SketchLine_5.endPoint(), SketchPoint_2.result())
97 SketchLine_6 = Sketch_2.addLine(0, 0, 0, 50)
100 SketchLine_7 = Sketch_2.addLine(0, 50, 75, 50)
102 ### Create SketchLine
103 SketchLine_8 = Sketch_2.addLine(75, 50, 75, 0.0001)
104 Sketch_2.setCoincident(SketchLine_8.endPoint(), SketchLine_5.startPoint())
105 Sketch_2.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint())
106 Sketch_2.setCoincident(SketchLine_6.endPoint(), SketchLine_7.startPoint())
107 Sketch_2.setCoincident(SketchLine_7.endPoint(), SketchLine_8.startPoint())
108 Sketch_2.setVertical(SketchLine_6.result())
109 Sketch_2.setHorizontal(SketchLine_7.result())
110 Sketch_2.setVertical(SketchLine_8.result())
112 ### Create SketchProjection
113 SketchProjection_3 = Sketch_2.addProjection(model.selection("EDGE", "PartSet/OY"), False)
114 SketchLine_9 = SketchProjection_3.createdFeature()
115 Sketch_2.setDistance(SketchLine_5.startPoint(), SketchLine_9.result(), 0.0001, True)
117 ### Create SketchProjection
118 SketchProjection_4 = Sketch_2.addProjection(model.selection("VERTEX", "Face_1_1/Modified_Vertex&Sketch_1/SketchLine_2_EndVertex&Sketch_1/SketchLine_3_StartVertex"), False)
119 SketchPoint_3 = SketchProjection_4.createdFeature()
120 Sketch_2.setHorizontalDistance(SketchLine_8.endPoint(), SketchAPI_Point(SketchPoint_3).coordinates(), 0)
124 Face_2 = model.addFace(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchLine_8r-SketchLine_7r-SketchLine_6r-SketchLine_5r")])
127 Group_1_objects = [model.selection("EDGE", "Face_1_1/Modified_Edge&Sketch_1/SketchLine_4"),
128 model.selection("EDGE", "Face_1_1/Modified_Edge&Sketch_1/SketchLine_1"),
129 model.selection("EDGE", "Face_1_1/Modified_Edge&Sketch_1/SketchLine_3"),
130 model.selection("EDGE", "Face_1_1/Modified_Edge&Sketch_1/SketchLine_2")]
131 Group_1 = model.addGroup(Part_1_doc, "Edges", Group_1_objects)
134 model.testNbResults(Group_1, 1)
135 model.testNbSubShapes(Group_1, GeomAPI_Shape.EDGE, [4])
138 Group_2_objects = [model.selection("EDGE", "Face_2_1/Modified_Edge&Sketch_2/SketchLine_6"),
139 model.selection("EDGE", "Face_2_1/Modified_Edge&Sketch_2/SketchLine_5"),
140 model.selection("EDGE", "Face_2_1/Modified_Edge&Sketch_2/SketchLine_7"),
141 model.selection("EDGE", "Face_2_1/Modified_Edge&Sketch_2/SketchLine_8")]
142 Group_2 = model.addGroup(Part_1_doc, "Edges", Group_2_objects)
145 model.testNbResults(Group_2, 1)
146 model.testNbSubShapes(Group_2, GeomAPI_Shape.EDGE, [4])
149 Sewing_1 = model.addSewing(Part_1_doc, [model.selection("FACE", "Face_1_1"), model.selection("FACE", "Face_2_1")], 0.0001, allowNonManifold = True, alwaysCreateResult = False)
152 testResults(Sewing_1, model, 1, [0], [1], [2], [7], [6])
154 # Move the groups after Sewing (move to the end)
155 Part_1_doc.moveFeature(Group_1.feature(), Sewing_1.feature())
156 Part_1_doc.moveFeature(Group_2.feature(), Sewing_1.feature())
159 model.testNbResults(Group_1, 1)
160 model.testNbSubShapes(Group_1, GeomAPI_Shape.EDGE, [4])
161 model.testNbResults(Group_2, 1)
162 model.testNbSubShapes(Group_2, GeomAPI_Shape.EDGE, [4])
164 # Perform same test, but moving groups after Shell feature
167 model.testNbSubShapes(Group_1, GeomAPI_Shape.EDGE, [4])
168 model.testNbSubShapes(Group_2, GeomAPI_Shape.EDGE, [4])
172 Shell_1 = model.addShell(Part_1_doc, [model.selection("FACE", "Face_1_1"), model.selection("FACE", "Face_2_1")])
175 testResults(Shell_1, model, 2, [0,0], [1,1], [1,1], [4,4], [4,4])
176 model.testNbSubShapes(Shell_1, GeomAPI_Shape.EDGE, [4,4])
178 # Move the groups after Shell (move to the end)
179 Part_1_doc.moveFeature(Group_1.feature(), Shell_1.feature())
180 Part_1_doc.moveFeature(Group_2.feature(), Shell_1.feature())
183 model.testNbResults(Group_1, 1)
184 model.testNbSubShapes(Group_1, GeomAPI_Shape.EDGE, [4])
185 model.testNbResults(Group_2, 1)
186 model.testNbSubShapes(Group_2, GeomAPI_Shape.EDGE, [4])