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