Salome HOME
updated copyright message
[modules/shaper.git] / src / FeaturesPlugin / Test / TestRotation_MultiLevelCompound_v0_1.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
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 ANGLE = 45
65 TOLERANCE = 1.e-7
66
67 ORIGIN = GeomAPI_Pnt(0, 0, 0)
68 OX = GeomAPI_Ax1(ORIGIN, GeomAPI_Dir(1, 0, 0))
69 OY = GeomAPI_Ax1(ORIGIN, GeomAPI_Dir(0, 1, 0))
70 OZ = GeomAPI_Ax1(ORIGIN, GeomAPI_Dir(0, 0, 1))
71
72
73 model.begin()
74 Rotation_1 = model.addRotation(Part_1_doc, [model.selection("SOLID", "Compound_2_1_1_5")], model.selection("EDGE", "PartSet/OX"), ANGLE)
75 model.testNbResults(Rotation_1, 1)
76 model.testNbSubResults(Rotation_1, [0])
77 model.testNbSubShapes(Rotation_1, GeomAPI_Shape.SOLID, [1])
78 model.testNbSubShapes(Rotation_1, GeomAPI_Shape.FACE, [5])
79 model.testNbSubShapes(Rotation_1, GeomAPI_Shape.EDGE, [18])
80 model.testNbSubShapes(Rotation_1, GeomAPI_Shape.VERTEX, [36])
81 model.testResultsVolumes(Rotation_1, [542.746463956])
82
83 refPoint = Extrusion_1.results()[0].subResult(4).resultSubShapePair()[0].shape().middlePoint()
84 refPoint.rotate(OX, ANGLE)
85 midPoint = Rotation_1.defaultResult().shape().middlePoint()
86 assert(midPoint.distance(refPoint) < TOLERANCE)
87
88
89 Recover_1 = model.addRecover(Part_1_doc, Rotation_1, [Compound_2.result()], True)
90 Rotation_2 = model.addRotation(Part_1_doc, [model.selection("SOLID", "Recover_1_1_2_1")], model.selection("EDGE", "PartSet/OY"), ANGLE)
91 model.testNbResults(Rotation_2, 1)
92 model.testNbSubResults(Rotation_2, [0])
93 model.testNbSubShapes(Rotation_2, GeomAPI_Shape.SOLID, [1])
94 model.testNbSubShapes(Rotation_2, GeomAPI_Shape.FACE, [3])
95 model.testNbSubShapes(Rotation_2, GeomAPI_Shape.EDGE, [6])
96 model.testNbSubShapes(Rotation_2, GeomAPI_Shape.VERTEX, [12])
97 model.testResultsVolumes(Rotation_2, [785.39816339745])
98
99 refPoint = Recover_1.result().subResult(1).subResult(0).resultSubShapePair()[0].shape().middlePoint()
100 refPoint.rotate(OY, ANGLE)
101 midPoint = Rotation_2.defaultResult().shape().middlePoint()
102 assert(midPoint.distance(refPoint) < TOLERANCE)
103
104
105 Recover_2 = model.addRecover(Part_1_doc, Rotation_2, [Recover_1.result()], True)
106 Rotation_3 = model.addRotation(Part_1_doc, [model.selection("SOLID", "Recover_2_1_3")], model.selection("EDGE", "PartSet/OZ"), ANGLE)
107 model.testNbResults(Rotation_3, 1)
108 model.testNbSubResults(Rotation_3, [0])
109 model.testNbSubShapes(Rotation_3, GeomAPI_Shape.SOLID, [1])
110 model.testNbSubShapes(Rotation_3, GeomAPI_Shape.FACE, [3])
111 model.testNbSubShapes(Rotation_3, GeomAPI_Shape.EDGE, [6])
112 model.testNbSubShapes(Rotation_3, GeomAPI_Shape.VERTEX, [12])
113 model.testResultsVolumes(Rotation_3, [785.39816339745])
114
115 refPoint = Recover_2.result().subResult(2).resultSubShapePair()[0].shape().middlePoint()
116 refPoint.rotate(OZ, ANGLE)
117 midPoint = Rotation_3.defaultResult().shape().middlePoint()
118 assert(midPoint.distance(refPoint) < TOLERANCE)
119
120
121 Recover_3 = model.addRecover(Part_1_doc, Rotation_3, [Recover_2.result()], True)
122 Rotation_4 = model.addRotation(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)
123 model.testNbResults(Rotation_4, 3)
124 model.testNbSubResults(Rotation_4, [0, 0, 0])
125 model.testNbSubShapes(Rotation_4, GeomAPI_Shape.SOLID, [1, 1, 1])
126 model.testNbSubShapes(Rotation_4, GeomAPI_Shape.FACE, [6, 3, 3])
127 model.testNbSubShapes(Rotation_4, GeomAPI_Shape.EDGE, [24, 6, 6])
128 model.testNbSubShapes(Rotation_4, GeomAPI_Shape.VERTEX, [48, 12, 12])
129 model.testResultsVolumes(Rotation_4, [3444.394198615, 785.39816339745, 785.39816339745])
130
131 REFERENCE = [Recover_3.result().subResult(0).subResult(0).resultSubShapePair()[0].shape().middlePoint(),
132              Recover_3.result().subResult(1).subResult(1).resultSubShapePair()[0].shape().middlePoint(),
133              Recover_3.result().subResult(2).resultSubShapePair()[0].shape().middlePoint()]
134 for res, ref in zip(Rotation_4.results(), REFERENCE):
135     ref.rotate(OZ, -ANGLE)
136     midPoint = res.resultSubShapePair()[0].shape().middlePoint()
137     assert(midPoint.distance(ref) < TOLERANCE)
138
139 model.end()
140
141 assert(model.checkPythonDump())