Salome HOME
added Limit Tolerance feature
[modules/shaper.git] / src / FeaturesPlugin / Test / TestSewing_Groups.py
1 import sys
2 import salome
3
4 salome.salome_init()
5
6 from SketchAPI import *
7 from GeomAPI import GeomAPI_Shape
8
9 from salome.shaper import model
10
11 aShapeTypes = {
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"}
16
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()).
22   """
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)
32
33 def testResults(theFeature,theModel,NbRes,NbSubRes,NbShell,NbFace,NbEdge,NbVertex):
34   """ Tests numbers of unique sub-shapes in the results
35   """
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)
44
45
46 model.begin()
47 partSet = model.moduleDocument()
48
49 ### Create Part
50 Part_1 = model.addPart(partSet)
51 Part_1_doc = Part_1.document()
52
53 ### Create Sketch
54 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
55
56 ### Create SketchLine
57 SketchLine_1 = Sketch_1.addLine(60, 0, 0, 0)
58
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())
63
64 ### Create SketchLine
65 SketchLine_2 = Sketch_1.addLine(0, 0, 0, 75)
66
67 ### Create SketchLine
68 SketchLine_3 = Sketch_1.addLine(0, 75, 60, 75)
69
70 ### Create SketchLine
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())
80 model.do()
81
82 ### Create Face
83 Face_1 = model.addFace(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_4r-SketchLine_3r-SketchLine_2r-SketchLine_1r")])
84
85 ### Create Sketch
86 Sketch_2 = model.addSketch(Part_1_doc, model.standardPlane("YOZ"))
87
88 ### Create SketchLine
89 SketchLine_5 = Sketch_2.addLine(75, 0.0001, 0, 0)
90
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())
95
96 ### Create SketchLine
97 SketchLine_6 = Sketch_2.addLine(0, 0, 0, 50)
98
99 ### Create SketchLine
100 SketchLine_7 = Sketch_2.addLine(0, 50, 75, 50)
101
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())
111
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)
116
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)
121 model.do()
122
123 ### Create Face
124 Face_2 = model.addFace(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchLine_8r-SketchLine_7r-SketchLine_6r-SketchLine_5r")])
125
126 ### Create Group
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)
132 model.do()
133
134 model.testNbResults(Group_1, 1)
135 model.testNbSubShapes(Group_1, GeomAPI_Shape.EDGE, [4])
136
137 ### Create Group
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)
143 model.do()
144
145 model.testNbResults(Group_2, 1)
146 model.testNbSubShapes(Group_2, GeomAPI_Shape.EDGE, [4])
147
148 ### Create Sewing
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)
150 model.do()
151
152 testResults(Sewing_1, model, 1, [0], [1], [2], [7], [6])
153
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())
157 model.end()
158
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])
163
164 # Perform same test, but moving groups after Shell feature
165 model.undo()
166 model.undo()
167 model.testNbSubShapes(Group_1, GeomAPI_Shape.EDGE, [4])
168 model.testNbSubShapes(Group_2, GeomAPI_Shape.EDGE, [4])
169
170 ### Build Shell
171 model.begin()
172 Shell_1 = model.addShell(Part_1_doc, [model.selection("FACE", "Face_1_1"), model.selection("FACE", "Face_2_1")])
173 model.do()
174
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])
177
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())
181 model.end()
182
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])