Salome HOME
5b4d4d5ae54d1371b5c20feb4830f22928bc1665
[modules/shaper.git] / src / FeaturesPlugin / Test / TestPlacement_MultiLevelCompound_v0_6.py
1 # Copyright (C) 2020-2023  CEA, EDF
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 from salome.shaper import model
21 from GeomAPI import *
22
23 model.begin()
24 partSet = model.moduleDocument()
25 Part_1 = model.addPart(partSet)
26 Part_1_doc = Part_1.document()
27 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
28 SketchPoint_1 = Sketch_1.addPoint(44.29784155360136, 17.09942588468031)
29 SketchArc_1 = Sketch_1.addArc(44.29784155360136, 17.09942588468031, 47.1668727423061, 12.27945348765633, 45.38299232715926, 22.60269052200972, False)
30 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchPoint_1.coordinates(), SketchArc_1.center())
31 SketchLine_1 = Sketch_1.addLine(42.5764228403785, 22.14892077680068, 39.70739165167375, 16.41085839939117)
32 SketchLine_2 = Sketch_1.addLine(39.70739165167375, 16.41085839939117, 43.03546783057126, 12.04993099255995)
33 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
34 SketchLine_3 = Sketch_1.addLine(28.57555063949931, 12.96802097294547, 15.72229091410204, 12.96802097294547)
35 SketchLine_4 = Sketch_1.addLine(15.72229091410204, 12.96802097294547, 15.72229091410204, 21.46035329151154)
36 SketchLine_5 = Sketch_1.addLine(15.72229091410204, 21.46035329151154, 28.57555063949931, 21.46035329151154)
37 SketchLine_6 = Sketch_1.addLine(28.57555063949931, 21.46035329151154, 28.57555063949931, 12.96802097294547)
38 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_6.endPoint(), SketchLine_3.startPoint())
39 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
40 SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint())
41 SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint())
42 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_3.result())
43 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_4.result())
44 SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_5.result())
45 SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_6.result())
46 SketchLine_7 = Sketch_1.addLine(-10.67279602198167, 14.78814178154371, -28.34602814440294, 14.78814178154371)
47 SketchLine_8 = Sketch_1.addLine(-28.34602814440294, 14.78814178154371, -28.34602814440294, 25.13271321305362)
48 SketchLine_9 = Sketch_1.addLine(-28.34602814440294, 25.13271321305362, -10.67279602198167, 25.13271321305362)
49 SketchLine_10 = Sketch_1.addLine(-10.67279602198167, 25.13271321305362, -10.67279602198167, 14.78814178154371)
50 SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchLine_10.endPoint(), SketchLine_7.startPoint())
51 SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchLine_7.endPoint(), SketchLine_8.startPoint())
52 SketchConstraintCoincidence_9 = Sketch_1.setCoincident(SketchLine_8.endPoint(), SketchLine_9.startPoint())
53 SketchConstraintCoincidence_10 = Sketch_1.setCoincident(SketchLine_9.endPoint(), SketchLine_10.startPoint())
54 SketchConstraintHorizontal_3 = Sketch_1.setHorizontal(SketchLine_7.result())
55 SketchConstraintVertical_3 = Sketch_1.setVertical(SketchLine_8.result())
56 SketchConstraintHorizontal_4 = Sketch_1.setHorizontal(SketchLine_9.result())
57 SketchConstraintVertical_4 = Sketch_1.setVertical(SketchLine_10.result())
58 SketchLine_11 = Sketch_1.addLine(-17.67323212242127, 25.13271321305362, -21.80463703415611, 14.78814178154371)
59 SketchConstraintCoincidence_11 = Sketch_1.setCoincident(SketchLine_11.startPoint(), SketchLine_9.result())
60 SketchConstraintCoincidence_12 = Sketch_1.setCoincident(SketchLine_11.endPoint(), SketchLine_7.result())
61 model.do()
62 Vertex_1 = model.addVertex(Part_1_doc, [model.selection("VERTEX", "Sketch_1/SketchArc_1")], False)
63 Edge_1 = model.addEdge(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchArc_1_2")], False)
64 Wire_1 = model.addWire(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchLine_1"), model.selection("EDGE", "Sketch_1/SketchLine_2")], False)
65 Face_1 = model.addFace(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_6r-SketchLine_5r-SketchLine_4r-SketchLine_3r")])
66 Shell_1 = model.addShell(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_10r-SketchLine_9r-SketchLine_11f-SketchLine_7r"), model.selection("FACE", "Sketch_1/Face-SketchLine_11r-SketchLine_9r-SketchLine_8r-SketchLine_7r")])
67 Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
68 Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], model.selection("EDGE", "PartSet/OX"), 50)
69 Box_2 = model.addBox(Part_1_doc, 10, 10, 10)
70 Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10)
71 Partition_1 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Box_2_1"), model.selection("SOLID", "Cylinder_1_1")])
72 Box_3 = model.addBox(Part_1_doc, 10, 10, 10)
73 Translation_2 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_3_1")], model.selection("EDGE", "PartSet/OY"), 50)
74 AngularCopy_1 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "Translation_2_1")], model.selection("EDGE", "PartSet/OZ"), 30, 3)
75 Compound_1_objects = [model.selection("VERTEX", "Vertex_1_1"), model.selection("EDGE", "Edge_1_1"), model.selection("WIRE", "Wire_1_1"), model.selection("FACE", "Face_1_1"), model.selection("SHELL", "Shell_1_1"), model.selection("SOLID", "Translation_1_1"), model.selection("COMPSOLID", "Partition_1_1"), model.selection("COMPOUND", "AngularCopy_1_1")]
76 Compound_1 = model.addCompound(Part_1_doc, Compound_1_objects)
77 model.end()
78
79 # collect reference data
80 Z_SHIFT = 10
81 REFERENCE = []
82 TOLERANCE = 1.e-7
83 for ind in range(0, Compound_1.result().numberOfSubs()):
84     p = Compound_1.result().subResult(ind).resultSubShapePair()[1].middlePoint()
85     p.setZ(p.z() + Z_SHIFT)
86     REFERENCE.append(p)
87
88 index = 0
89
90 model.begin()
91 Placement_1 = model.addPlacement(Part_1_doc, [model.selection("VERTEX", "Compound_1_1_1")], model.selection("FACE", "Compound_1_1_6/Modified_Face&Box_1_1/Bottom"), model.selection("FACE", "Compound_1_1_6/Modified_Face&Box_1_1/Top"), False, False)
92 model.testNbResults(Placement_1, 1)
93 model.testNbSubResults(Placement_1, [0])
94 model.testNbSubShapes(Placement_1, GeomAPI_Shape.SOLID, [0])
95 model.testNbSubShapes(Placement_1, GeomAPI_Shape.FACE, [0])
96 model.testNbSubShapes(Placement_1, GeomAPI_Shape.EDGE, [0])
97 model.testNbSubShapes(Placement_1, GeomAPI_Shape.VERTEX, [1])
98 model.testResultsVolumes(Placement_1, [0])
99 model.testResultsAreas(Placement_1, [0])
100 midPoint = Placement_1.defaultResult().shape().middlePoint()
101 assert(midPoint.distance(REFERENCE[index]) < TOLERANCE)
102 index += 1
103
104 Recover_1 = model.addRecover(Part_1_doc, Placement_1, [Compound_1.result()], True)
105 Placement_2 = model.addPlacement(Part_1_doc, [model.selection("EDGE", "Recover_1_1_2")], model.selection("FACE", "Recover_1_1_6/Modified_Face&Box_1_1/Bottom"), model.selection("FACE", "Recover_1_1_6/Modified_Face&Box_1_1/Top"), False, False)
106 model.testNbResults(Placement_2, 1)
107 model.testNbSubResults(Placement_2, [0])
108 model.testNbSubShapes(Placement_2, GeomAPI_Shape.SOLID, [0])
109 model.testNbSubShapes(Placement_2, GeomAPI_Shape.FACE, [0])
110 model.testNbSubShapes(Placement_2, GeomAPI_Shape.EDGE, [1])
111 model.testNbSubShapes(Placement_2, GeomAPI_Shape.VERTEX, [2])
112 model.testResultsVolumes(Placement_2, [0])
113 model.testResultsAreas(Placement_2, [0])
114 midPoint = Placement_2.defaultResult().shape().middlePoint()
115 assert(midPoint.distance(REFERENCE[index]) < TOLERANCE)
116 index += 1
117
118 Recover_2 = model.addRecover(Part_1_doc, Placement_2, [Recover_1.result()])
119 Placement_3 = model.addPlacement(Part_1_doc, [model.selection("WIRE", "Recover_2_1_3")], model.selection("FACE", "Recover_2_1_6/Modified_Face&Box_1_1/Bottom"), model.selection("FACE", "Recover_2_1_6/Modified_Face&Box_1_1/Top"), False, False)
120 model.testNbResults(Placement_3, 1)
121 model.testNbSubResults(Placement_3, [0])
122 model.testNbSubShapes(Placement_3, GeomAPI_Shape.SOLID, [0])
123 model.testNbSubShapes(Placement_3, GeomAPI_Shape.FACE, [0])
124 model.testNbSubShapes(Placement_3, GeomAPI_Shape.EDGE, [2])
125 model.testNbSubShapes(Placement_3, GeomAPI_Shape.VERTEX, [4])
126 model.testResultsVolumes(Placement_3, [0])
127 model.testResultsAreas(Placement_3, [0])
128 midPoint = Placement_3.defaultResult().shape().middlePoint()
129 assert(midPoint.distance(REFERENCE[index]) < TOLERANCE)
130 index += 1
131
132 Recover_3 = model.addRecover(Part_1_doc, Placement_3, [Recover_2.result()])
133 Placement_4 = model.addPlacement(Part_1_doc, [model.selection("FACE", "Recover_3_1_4")], model.selection("FACE", "Recover_3_1_6/Modified_Face&Box_1_1/Bottom"), model.selection("FACE", "Recover_3_1_6/Modified_Face&Box_1_1/Top"), False, False)
134 model.testNbResults(Placement_4, 1)
135 model.testNbSubResults(Placement_4, [0])
136 model.testNbSubShapes(Placement_4, GeomAPI_Shape.SOLID, [0])
137 model.testNbSubShapes(Placement_4, GeomAPI_Shape.FACE, [1])
138 model.testNbSubShapes(Placement_4, GeomAPI_Shape.EDGE, [4])
139 model.testNbSubShapes(Placement_4, GeomAPI_Shape.VERTEX, [8])
140 model.testResultsVolumes(Placement_4, [0])
141 model.testResultsAreas(Placement_4, [109.154152964914914])
142 midPoint = Placement_4.defaultResult().shape().middlePoint()
143 assert(midPoint.distance(REFERENCE[index]) < TOLERANCE)
144 index += 1
145
146 Recover_4 = model.addRecover(Part_1_doc, Placement_4, [Recover_3.result()])
147 Placement_5 = model.addPlacement(Part_1_doc, [model.selection("SHELL", "Recover_4_1_5")], model.selection("FACE", "Recover_4_1_6/Modified_Face&Box_1_1/Bottom"), model.selection("FACE", "Recover_4_1_6/Modified_Face&Box_1_1/Top"), False, False)
148 model.testNbResults(Placement_5, 1)
149 model.testNbSubResults(Placement_5, [0])
150 model.testNbSubShapes(Placement_5, GeomAPI_Shape.SOLID, [0])
151 model.testNbSubShapes(Placement_5, GeomAPI_Shape.FACE, [2])
152 model.testNbSubShapes(Placement_5, GeomAPI_Shape.EDGE, [8])
153 model.testNbSubShapes(Placement_5, GeomAPI_Shape.VERTEX, [16])
154 model.testResultsVolumes(Placement_5, [0])
155 model.testResultsAreas(Placement_5, [182.822012116])
156 midPoint = Placement_5.defaultResult().shape().middlePoint()
157 assert(midPoint.distance(REFERENCE[index]) < TOLERANCE)
158 index += 1
159
160 Recover_5 = model.addRecover(Part_1_doc, Placement_5, [Recover_4.result()])
161 Placement_6 = model.addPlacement(Part_1_doc, [model.selection("SOLID", "Recover_5_1_6")], model.selection("FACE", "Recover_5_1_6/Modified_Face&Box_1_1/Bottom"), model.selection("FACE", "Recover_5_1_6/Modified_Face&Box_1_1/Top"), False, False)
162 model.testNbResults(Placement_6, 1)
163 model.testNbSubResults(Placement_6, [0])
164 model.testNbSubShapes(Placement_6, GeomAPI_Shape.SOLID, [1])
165 model.testNbSubShapes(Placement_6, GeomAPI_Shape.FACE, [6])
166 model.testNbSubShapes(Placement_6, GeomAPI_Shape.EDGE, [24])
167 model.testNbSubShapes(Placement_6, GeomAPI_Shape.VERTEX, [48])
168 model.testResultsVolumes(Placement_6, [1000])
169 midPoint = Placement_6.defaultResult().shape().middlePoint()
170 assert(midPoint.distance(REFERENCE[index]) < TOLERANCE)
171 index += 1
172
173 Recover_6 = model.addRecover(Part_1_doc, Placement_6, [Recover_5.result()])
174 Placement_7 = model.addPlacement(Part_1_doc, [model.selection("COMPSOLID", "Recover_6_1_7")], model.selection("FACE", "Recover_6_1_6/Modified_Face&Box_1_1/Bottom"), model.selection("FACE", "Recover_6_1_6/Modified_Face&Box_1_1/Top"), False, False)
175 model.testNbResults(Placement_7, 1)
176 model.testNbSubResults(Placement_7, [3])
177 model.testNbSubShapes(Placement_7, GeomAPI_Shape.SOLID, [3])
178 model.testNbSubShapes(Placement_7, GeomAPI_Shape.FACE, [17])
179 model.testNbSubShapes(Placement_7, GeomAPI_Shape.EDGE, [66])
180 model.testNbSubShapes(Placement_7, GeomAPI_Shape.VERTEX, [132])
181 model.testResultsVolumes(Placement_7, [1589.0486226])
182 midPoint = Placement_7.defaultResult().shape().middlePoint()
183 assert(midPoint.distance(REFERENCE[index]) < TOLERANCE)
184 index += 1
185
186 Recover_7 = model.addRecover(Part_1_doc, Placement_7, [Recover_6.result()])
187 Placement_8 = model.addPlacement(Part_1_doc, [model.selection("COMPOUND", "Recover_7_1_8")], model.selection("FACE", "Recover_7_1_6/Modified_Face&Box_1_1/Bottom"), model.selection("FACE", "Recover_7_1_6/Modified_Face&Box_1_1/Top"), False, False)
188 model.testNbResults(Placement_8, 1)
189 model.testNbSubResults(Placement_8, [3])
190 model.testNbSubShapes(Placement_8, GeomAPI_Shape.SOLID, [3])
191 model.testNbSubShapes(Placement_8, GeomAPI_Shape.FACE, [18])
192 model.testNbSubShapes(Placement_8, GeomAPI_Shape.EDGE, [72])
193 model.testNbSubShapes(Placement_8, GeomAPI_Shape.VERTEX, [144])
194 model.testResultsVolumes(Placement_8, [3000])
195 midPoint = Placement_8.defaultResult().shape().middlePoint()
196 assert(midPoint.distance(REFERENCE[index]) < TOLERANCE)
197
198 model.end()
199
200 assert(model.checkPythonDump())