Salome HOME
Copyright update 2022
[modules/shaper.git] / src / FeaturesPlugin / Test / TestSymmetry_MultiLevelCompound_v0_3.py
1 # Copyright (C) 2020-2022  CEA/DEN, EDF R&D
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
22 from GeomAPI import *
23 from SketchAPI import *
24
25 model.begin()
26 partSet = model.moduleDocument()
27 Part_1 = model.addPart(partSet)
28 Part_1_doc = Part_1.document()
29 Sketch_1 = model.addSketch(Part_1_doc, model.standardPlane("XOY"))
30 SketchEllipse_1 = Sketch_1.addEllipse(11.18033988749894, -50, 22.36067977499789, -50, 10)
31 [SketchPoint_1, SketchPoint_2, SketchPoint_3, SketchPoint_4, SketchPoint_5, SketchPoint_6, SketchPoint_7, SketchLine_1, SketchLine_2] = SketchEllipse_1.construction(center = "aux", firstFocus = "aux", secondFocus = "aux", majorAxisStart = "aux", majorAxisEnd = "aux", minorAxisStart = "aux", minorAxisEnd = "aux", majorAxis = "aux", minorAxis = "aux")
32 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
33 SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_1.result(), 30)
34 SketchConstraintLength_2 = Sketch_1.setLength(SketchLine_2.result(), 20)
35 SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OY"), False)
36 SketchLine_3 = SketchProjection_1.createdFeature()
37 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchAPI_Point(SketchPoint_3).coordinates(), SketchLine_3.result())
38 SketchConstraintDistance_1 = Sketch_1.setDistance(SketchAPI_Line(SketchLine_3).startPoint(), SketchAPI_Point(SketchPoint_3).coordinates(), 50, True)
39 SketchCircle_1 = Sketch_1.addCircle(41.18033988749897, -50, 5)
40 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchCircle_1.center(), SketchLine_1.result())
41 SketchConstraintDistance_2 = Sketch_1.setDistance(SketchEllipse_1.majorAxisPositive(), SketchCircle_1.center(), 15, True)
42 SketchConstraintRadius_1 = Sketch_1.setRadius(SketchCircle_1.results()[1], 5)
43 SketchMultiRotation_1 = Sketch_1.addRotation([SketchEllipse_1.result(), SketchCircle_1.results()[1]], SketchAPI_Point(SketchPoint_3).coordinates(), 360, 3, True)
44 [SketchEllipse_2, SketchEllipse_3, SketchCircle_2, SketchCircle_3] = SketchMultiRotation_1.rotated()
45 model.do()
46 Sketch_1.changeFacesOrder([[SketchEllipse_1.result(), SketchEllipse_1.result(), SketchEllipse_2.result(), SketchEllipse_3.result()],
47                            [SketchCircle_1.results()[1]],
48                            [SketchEllipse_2.result(), SketchEllipse_2.result(), SketchEllipse_3.result(), SketchEllipse_1.result()],
49                            [SketchEllipse_1.result(), SketchEllipse_3.result(), SketchEllipse_2.result()],
50                            [SketchEllipse_3.result(), SketchEllipse_2.result(), SketchEllipse_1.result()],
51                            [SketchEllipse_1.result(), SketchEllipse_2.result(), SketchEllipse_3.result()],
52                            [SketchEllipse_1.result(), SketchEllipse_3.result(), SketchEllipse_2.result()],
53                            [SketchEllipse_2.result(), SketchEllipse_3.result(), SketchEllipse_3.result(), SketchEllipse_1.result()],
54                            [SketchCircle_2.results()[1]],
55                            [SketchCircle_3.results()[1]]
56                           ])
57 model.do()
58 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_1")], model.selection(), 10, 0)
59 Compound_1 = model.addCompound(Part_1_doc, [model.selection("SOLID", "Extrusion_1_2"), model.selection("SOLID", "Extrusion_1_3")])
60 Compound_2_objects = [model.selection("COMPSOLID", "Extrusion_1_1"), model.selection("COMPOUND", "Compound_1_1"), model.selection("SOLID", "Extrusion_1_4")]
61 Compound_2 = model.addCompound(Part_1_doc, Compound_2_objects)
62 model.end()
63
64 TOLERANCE = 1.e-7
65
66 def symmetryXOZ(thePoint):
67     return GeomAPI_Pnt(thePoint.x(), -thePoint.y(), thePoint.z())
68
69 def centerBB(theShape):
70     res = theShape.computeSize()
71     return GeomAPI_Pnt((res[1] + res[4]) / 2, (res[2] + res[5]) / 2, (res[3] + res[6]) / 2)
72
73
74 model.begin()
75 Symmetry_1 = model.addSymmetry(Part_1_doc, [model.selection("SOLID", "Compound_2_1_1_5")], model.selection("FACE", "PartSet/XOZ"), False)
76 model.testNbResults(Symmetry_1, 1)
77 model.testNbSubResults(Symmetry_1, [0])
78 model.testNbSubShapes(Symmetry_1, GeomAPI_Shape.SOLID, [1])
79 model.testNbSubShapes(Symmetry_1, GeomAPI_Shape.FACE, [5])
80 model.testNbSubShapes(Symmetry_1, GeomAPI_Shape.EDGE, [18])
81 model.testNbSubShapes(Symmetry_1, GeomAPI_Shape.VERTEX, [36])
82 model.testResultsVolumes(Symmetry_1, [542.746463956])
83
84 refPoint = symmetryXOZ(Extrusion_1.results()[0].subResult(4).resultSubShapePair()[0].shape().middlePoint())
85 midPoint = Symmetry_1.defaultResult().shape().middlePoint()
86 assert(midPoint.distance(refPoint) < TOLERANCE)
87
88
89 Recover_1 = model.addRecover(Part_1_doc, Symmetry_1, [Compound_2.result()], True)
90 Symmetry_2 = model.addSymmetry(Part_1_doc, [model.selection("SOLID", "Recover_1_1_2_1")], model.selection("FACE", "PartSet/XOZ"), False)
91 model.testNbResults(Symmetry_2, 1)
92 model.testNbSubResults(Symmetry_2, [0])
93 model.testNbSubShapes(Symmetry_2, GeomAPI_Shape.SOLID, [1])
94 model.testNbSubShapes(Symmetry_2, GeomAPI_Shape.FACE, [3])
95 model.testNbSubShapes(Symmetry_2, GeomAPI_Shape.EDGE, [6])
96 model.testNbSubShapes(Symmetry_2, GeomAPI_Shape.VERTEX, [12])
97 model.testResultsVolumes(Symmetry_2, [785.39816339745])
98
99 refPoint = symmetryXOZ(Recover_1.result().subResult(1).subResult(0).resultSubShapePair()[0].shape().middlePoint())
100 midPoint = Symmetry_2.defaultResult().shape().middlePoint()
101 assert(midPoint.distance(refPoint) < TOLERANCE)
102
103
104 Recover_2 = model.addRecover(Part_1_doc, Symmetry_2, [Recover_1.result()], True)
105 Symmetry_3 = model.addSymmetry(Part_1_doc, [model.selection("SOLID", "Recover_2_1_3")], model.selection("FACE", "PartSet/XOZ"), False)
106 model.testNbResults(Symmetry_3, 1)
107 model.testNbSubResults(Symmetry_3, [0])
108 model.testNbSubShapes(Symmetry_3, GeomAPI_Shape.SOLID, [1])
109 model.testNbSubShapes(Symmetry_3, GeomAPI_Shape.FACE, [3])
110 model.testNbSubShapes(Symmetry_3, GeomAPI_Shape.EDGE, [6])
111 model.testNbSubShapes(Symmetry_3, GeomAPI_Shape.VERTEX, [12])
112 model.testResultsVolumes(Symmetry_3, [785.39816339745])
113
114 refPoint = symmetryXOZ(Recover_2.result().subResult(2).resultSubShapePair()[0].shape().middlePoint())
115 midPoint = Symmetry_3.defaultResult().shape().middlePoint()
116 assert(midPoint.distance(refPoint) < TOLERANCE)
117
118
119 Recover_3 = model.addRecover(Part_1_doc, Symmetry_3, [Recover_2.result()], True)
120 Symmetry_4 = model.addSymmetry(Part_1_doc, [model.selection("SOLID", "Recover_3_1_1_1"), model.selection("SOLID", "Recover_3_1_2_2"), model.selection("SOLID", "Recover_3_1_3")], model.selection("FACE", "PartSet/XOZ"), False)
121 model.testNbResults(Symmetry_4, 3)
122 model.testNbSubResults(Symmetry_4, [0, 0, 0])
123 model.testNbSubShapes(Symmetry_4, GeomAPI_Shape.SOLID, [1, 1, 1])
124 model.testNbSubShapes(Symmetry_4, GeomAPI_Shape.FACE, [6, 3, 3])
125 model.testNbSubShapes(Symmetry_4, GeomAPI_Shape.EDGE, [24, 6, 6])
126 model.testNbSubShapes(Symmetry_4, GeomAPI_Shape.VERTEX, [48, 12, 12])
127 model.testResultsVolumes(Symmetry_4, [3444.394198615, 785.39816339745, 785.39816339745])
128
129 REFERENCE = [Recover_3.result().subResult(0).subResult(0).resultSubShapePair()[0].shape().middlePoint(),
130              Recover_3.result().subResult(1).subResult(1).resultSubShapePair()[0].shape().middlePoint(),
131              Recover_3.result().subResult(2).resultSubShapePair()[0].shape().middlePoint()]
132 for res, ref in zip(Symmetry_4.results(), REFERENCE):
133     ref = symmetryXOZ(ref)
134     midPoint = res.resultSubShapePair()[0].shape().middlePoint()
135     assert(midPoint.distance(ref) < TOLERANCE)
136
137
138 Recover_4 = model.addRecover(Part_1_doc, Symmetry_4, [Recover_3.result()], True)
139 Symmetry_5 = model.addSymmetry(Part_1_doc, [model.selection("SOLID", "Recover_4_1_1_5")], model.selection("FACE", "PartSet/XOY"), True)
140 model.testNbResults(Symmetry_5, 1)
141 model.testNbSubResults(Symmetry_5, [2])
142 model.testNbSubShapes(Symmetry_5, GeomAPI_Shape.SOLID, [2])
143 model.testNbSubShapes(Symmetry_5, GeomAPI_Shape.FACE, [10])
144 model.testNbSubShapes(Symmetry_5, GeomAPI_Shape.EDGE, [36])
145 model.testNbSubShapes(Symmetry_5, GeomAPI_Shape.VERTEX, [72])
146 model.testResultsVolumes(Symmetry_5, [2 * 542.746463956])
147
148 refPoint = centerBB(Recover_4.results()[0].subResult(0).subResult(4).resultSubShapePair()[0].shape())
149 refPoint.setZ(0)
150 midPoint = Symmetry_5.defaultResult().shape().middlePoint()
151 assert(midPoint.distance(refPoint) < TOLERANCE)
152
153
154 Recover_5 = model.addRecover(Part_1_doc, Symmetry_5, [Compound_2.result()], True)
155 Symmetry_6 = model.addSymmetry(Part_1_doc, [model.selection("SOLID", "Recover_5_1_2_1")], model.selection("FACE", "PartSet/XOY"), True)
156 model.testNbResults(Symmetry_6, 1)
157 model.testNbSubResults(Symmetry_6, [2])
158 model.testNbSubShapes(Symmetry_6, GeomAPI_Shape.SOLID, [2])
159 model.testNbSubShapes(Symmetry_6, GeomAPI_Shape.FACE, [6])
160 model.testNbSubShapes(Symmetry_6, GeomAPI_Shape.EDGE, [12])
161 model.testNbSubShapes(Symmetry_6, GeomAPI_Shape.VERTEX, [24])
162 model.testResultsVolumes(Symmetry_6, [2 * 785.39816339745])
163
164 refPoint = Recover_5.result().subResult(1).subResult(0).resultSubShapePair()[0].shape().middlePoint()
165 refPoint.setZ(0)
166 midPoint = Symmetry_6.defaultResult().shape().middlePoint()
167 assert(midPoint.distance(refPoint) < TOLERANCE)
168
169
170 Recover_6 = model.addRecover(Part_1_doc, Symmetry_6, [Recover_5.result()], True)
171 Symmetry_7 = model.addSymmetry(Part_1_doc, [model.selection("SOLID", "Recover_6_1_3")], model.selection("FACE", "PartSet/XOY"), True)
172 model.testNbResults(Symmetry_7, 1)
173 model.testNbSubResults(Symmetry_7, [2])
174 model.testNbSubShapes(Symmetry_7, GeomAPI_Shape.SOLID, [2])
175 model.testNbSubShapes(Symmetry_7, GeomAPI_Shape.FACE, [6])
176 model.testNbSubShapes(Symmetry_7, GeomAPI_Shape.EDGE, [12])
177 model.testNbSubShapes(Symmetry_7, GeomAPI_Shape.VERTEX, [24])
178 model.testResultsVolumes(Symmetry_7, [2 * 785.39816339745])
179
180 refPoint = Recover_6.result().subResult(2).resultSubShapePair()[0].shape().middlePoint()
181 refPoint.setZ(0)
182 midPoint = Symmetry_7.defaultResult().shape().middlePoint()
183 assert(midPoint.distance(refPoint) < TOLERANCE)
184
185
186 Recover_7 = model.addRecover(Part_1_doc, Symmetry_7, [Recover_6.result()], True)
187 Symmetry_8 = model.addSymmetry(Part_1_doc, [model.selection("SOLID", "Recover_7_1_1_1"), model.selection("SOLID", "Recover_7_1_2_2"), model.selection("SOLID", "Recover_7_1_3")], model.selection("FACE", "PartSet/XOY"), True)
188 model.testNbResults(Symmetry_8, 3)
189 model.testNbSubResults(Symmetry_8, [2, 2, 2])
190 model.testNbSubShapes(Symmetry_8, GeomAPI_Shape.SOLID, [2, 2, 2])
191 model.testNbSubShapes(Symmetry_8, GeomAPI_Shape.FACE, [12, 6, 6])
192 model.testNbSubShapes(Symmetry_8, GeomAPI_Shape.EDGE, [48, 12, 12])
193 model.testNbSubShapes(Symmetry_8, GeomAPI_Shape.VERTEX, [96, 24, 24])
194 model.testResultsVolumes(Symmetry_8, [2 * 3444.394198615, 2 * 785.39816339745, 2 * 785.39816339745])
195
196 REFERENCE = [centerBB(Recover_7.result().subResult(0).subResult(0).resultSubShapePair()[0].shape()),
197              Recover_7.result().subResult(1).subResult(1).resultSubShapePair()[0].shape().middlePoint(),
198              Recover_7.result().subResult(2).resultSubShapePair()[0].shape().middlePoint()]
199 for res, ref in zip(Symmetry_8.results(), REFERENCE):
200     ref.setZ(0)
201     midPoint = res.resultSubShapePair()[0].shape().middlePoint()
202     assert(midPoint.distance(ref) < TOLERANCE)
203
204 model.end()
205
206 assert(model.checkPythonDump())