Salome HOME
db5bfec10296045e1edcc6a9f31577c54c6474ba
[modules/shaper.git] / src / FeaturesPlugin / Test / TestMultiRotation_MultiLevelCompound_v0_1.py
1 # Copyright (C) 2020-2023  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 GeomAlgoAPI import *
24 from SketchAPI import *
25
26 model.begin()
27 partSet = model.moduleDocument()
28 Part_1 = model.addPart(partSet)
29 Part_1_doc = Part_1.document()
30 Sketch_1 = model.addSketch(Part_1_doc, model.standardPlane("XOY"))
31 SketchEllipse_1 = Sketch_1.addEllipse(11.18033988749894, -50, 22.36067977499789, -50, 10)
32 [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")
33 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
34 SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_1.result(), 30)
35 SketchConstraintLength_2 = Sketch_1.setLength(SketchLine_2.result(), 20)
36 SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OY"), False)
37 SketchLine_3 = SketchProjection_1.createdFeature()
38 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchAPI_Point(SketchPoint_3).coordinates(), SketchLine_3.result())
39 SketchConstraintDistance_1 = Sketch_1.setDistance(SketchAPI_Line(SketchLine_3).startPoint(), SketchAPI_Point(SketchPoint_3).coordinates(), 50, True)
40 SketchCircle_1 = Sketch_1.addCircle(41.18033988749897, -50, 5)
41 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchCircle_1.center(), SketchLine_1.result())
42 SketchConstraintDistance_2 = Sketch_1.setDistance(SketchEllipse_1.majorAxisPositive(), SketchCircle_1.center(), 15, True)
43 SketchConstraintRadius_1 = Sketch_1.setRadius(SketchCircle_1.results()[1], 5)
44 SketchMultiRotation_1 = Sketch_1.addRotation([SketchEllipse_1.result(), SketchCircle_1.results()[1]], SketchAPI_Point(SketchPoint_3).coordinates(), 360, 3, True)
45 [SketchEllipse_2, SketchEllipse_3, SketchCircle_2, SketchCircle_3] = SketchMultiRotation_1.rotated()
46 model.do()
47 Sketch_1.changeFacesOrder([[SketchEllipse_1.result(), SketchEllipse_1.result(), SketchEllipse_2.result(), SketchEllipse_3.result()],
48                            [SketchCircle_1.results()[1]],
49                            [SketchEllipse_2.result(), SketchEllipse_2.result(), SketchEllipse_3.result(), SketchEllipse_1.result()],
50                            [SketchEllipse_1.result(), SketchEllipse_3.result(), SketchEllipse_2.result()],
51                            [SketchEllipse_3.result(), SketchEllipse_2.result(), SketchEllipse_1.result()],
52                            [SketchEllipse_1.result(), SketchEllipse_2.result(), SketchEllipse_3.result()],
53                            [SketchEllipse_1.result(), SketchEllipse_3.result(), SketchEllipse_2.result()],
54                            [SketchEllipse_2.result(), SketchEllipse_3.result(), SketchEllipse_3.result(), SketchEllipse_1.result()],
55                            [SketchCircle_2.results()[1]],
56                            [SketchCircle_3.results()[1]]
57                           ])
58 model.do()
59 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_1")], model.selection(), 10, 0)
60 Compound_1 = model.addCompound(Part_1_doc, [model.selection("SOLID", "Extrusion_1_2"), model.selection("SOLID", "Extrusion_1_3")])
61 Compound_2_objects = [model.selection("COMPSOLID", "Extrusion_1_1"), model.selection("COMPOUND", "Compound_1_1"), model.selection("SOLID", "Extrusion_1_4")]
62 Compound_2 = model.addCompound(Part_1_doc, Compound_2_objects)
63 model.end()
64
65 ANGLE = 60
66 COPIES = 3
67 TOLERANCE = 1.e-7
68
69
70 model.begin()
71 MultiRotation_1 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "Compound_2_1_1_5")], model.selection("EDGE", "PartSet/OZ"), ANGLE, COPIES)
72 model.testNbResults(MultiRotation_1, 1)
73 model.testNbSubResults(MultiRotation_1, [COPIES])
74 model.testNbSubShapes(MultiRotation_1, GeomAPI_Shape.SOLID, [1 * COPIES])
75 model.testNbSubShapes(MultiRotation_1, GeomAPI_Shape.FACE, [5 * COPIES])
76 model.testNbSubShapes(MultiRotation_1, GeomAPI_Shape.EDGE, [18 * COPIES])
77 model.testNbSubShapes(MultiRotation_1, GeomAPI_Shape.VERTEX, [36 * COPIES])
78 model.testResultsVolumes(MultiRotation_1, [542.746463956 * COPIES])
79
80 refPoint = GeomAPI_Pnt(22.16914827868, -12.5, 5)
81 midPoint = MultiRotation_1.defaultResult().shape().middlePoint()
82 assert(midPoint.distance(refPoint) < TOLERANCE)
83
84
85 Recover_1 = model.addRecover(Part_1_doc, MultiRotation_1, [Compound_2.result()], True)
86 MultiRotation_2 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "Recover_1_1_2_1")], model.selection("EDGE", "PartSet/OZ"), ANGLE, COPIES)
87 model.testNbResults(MultiRotation_2, 1)
88 model.testNbSubResults(MultiRotation_2, [COPIES])
89 model.testNbSubShapes(MultiRotation_2, GeomAPI_Shape.SOLID, [1 * COPIES])
90 model.testNbSubShapes(MultiRotation_2, GeomAPI_Shape.FACE, [3 * COPIES])
91 model.testNbSubShapes(MultiRotation_2, GeomAPI_Shape.EDGE, [6 * COPIES])
92 model.testNbSubShapes(MultiRotation_2, GeomAPI_Shape.VERTEX, [12 * COPIES])
93 model.testResultsVolumes(MultiRotation_2, [785.39816339745 * COPIES])
94
95 refPoint = GeomAPI_Pnt(43.301270189, 5.3316102395, 5)
96 midPoint = MultiRotation_2.defaultResult().shape().middlePoint()
97 assert(midPoint.distance(refPoint) < TOLERANCE)
98
99
100 Recover_2 = model.addRecover(Part_1_doc, MultiRotation_2, [Recover_1.result()], True)
101 MultiRotation_3 = model.addMultiRotation(Part_1_doc, [model.selection("SOLID", "Recover_2_1_3")], model.selection("EDGE", "PartSet/OZ"), ANGLE, COPIES)
102 model.testNbResults(MultiRotation_3, 1)
103 model.testNbSubResults(MultiRotation_3, [COPIES])
104 model.testNbSubShapes(MultiRotation_3, GeomAPI_Shape.SOLID, [1 * COPIES])
105 model.testNbSubShapes(MultiRotation_3, GeomAPI_Shape.FACE, [3 * COPIES])
106 model.testNbSubShapes(MultiRotation_3, GeomAPI_Shape.EDGE, [6 * COPIES])
107 model.testNbSubShapes(MultiRotation_3, GeomAPI_Shape.VERTEX, [12 * COPIES])
108 model.testResultsVolumes(MultiRotation_3, [785.39816339745 * COPIES])
109
110 refPoint = GeomAPI_Pnt(31.94572, -30.33161024, 5)
111 midPoint = MultiRotation_3.defaultResult().shape().middlePoint()
112 assert(midPoint.distance(refPoint) < TOLERANCE)
113
114
115 Recover_3 = model.addRecover(Part_1_doc, MultiRotation_3, [Recover_2.result()], True)
116 MultiRotation_4 = model.addMultiRotation(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("EDGE", "PartSet/OZ"), ANGLE, COPIES)
117 model.testNbResults(MultiRotation_4, 3)
118 model.testNbSubResults(MultiRotation_4, [COPIES, COPIES, COPIES])
119 model.testNbSubShapes(MultiRotation_4, GeomAPI_Shape.SOLID, [1 * COPIES, 1 * COPIES, 1 * COPIES])
120 model.testNbSubShapes(MultiRotation_4, GeomAPI_Shape.FACE, [6 * COPIES, 3 * COPIES, 3 * COPIES])
121 model.testNbSubShapes(MultiRotation_4, GeomAPI_Shape.EDGE, [24 * COPIES, 6 * COPIES, 6 * COPIES])
122 model.testNbSubShapes(MultiRotation_4, GeomAPI_Shape.VERTEX, [48 * COPIES, 12 * COPIES, 12 * COPIES])
123 model.testResultsVolumes(MultiRotation_4, [3444.394198615 * COPIES, 785.39816339745 * COPIES, 785.39816339745 * COPIES])
124
125 REFERENCE = [GeomAPI_Pnt(32.6022829255, -5.6990653637, 5),
126              GeomAPI_Pnt(1.06046515086, -17.8316102395, 5),
127              GeomAPI_Pnt(31.945720066, -30.3316102395, 5)]
128 for res, ref in zip(MultiRotation_4.results(), REFERENCE):
129     midPoint = res.resultSubShapePair()[0].shape().middlePoint()
130     assert(midPoint.distance(ref) < TOLERANCE)
131
132 model.end()
133
134 assert(model.checkPythonDump())