Salome HOME
5e0d34bd98c77db410dee7285426ee108e0777e4
[modules/shaper.git] / src / FeaturesPlugin / Test / TestLoft.py
1 # Copyright (C) 2018-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 model.begin()
23 partSet = model.moduleDocument()
24
25 ### Create Part
26 Part_1 = model.addPart(partSet)
27 Part_1_doc = Part_1.document()
28
29 ### Create Sketch
30 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
31
32 ### Create SketchLine
33 SketchLine_1 = Sketch_1.addLine(65.56914119359536, 34.84279475982533, -62.33478893740904, 34.84279475982533)
34
35 ### Create SketchLine
36 SketchLine_2 = Sketch_1.addLine(-62.33478893740904, 34.84279475982533, -62.33478893740904, -28.08005822416302)
37
38 ### Create SketchLine
39 SketchLine_3 = Sketch_1.addLine(-62.33478893740904, -28.08005822416302, 65.56914119359536, -28.08005822416302)
40
41 ### Create SketchLine
42 SketchLine_4 = Sketch_1.addLine(65.56914119359536, -28.08005822416302, 65.56914119359536, 34.84279475982533)
43 Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint())
44 Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
45 Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
46 Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
47 Sketch_1.setHorizontal(SketchLine_1.result())
48 Sketch_1.setVertical(SketchLine_2.result())
49 Sketch_1.setHorizontal(SketchLine_3.result())
50 Sketch_1.setVertical(SketchLine_4.result())
51 model.do()
52
53 ### Create Plane
54 Plane_4 = model.addPlane(Part_1_doc, model.selection("EDGE", "Sketch_1/SketchLine_4"), model.selection("VERTEX", "Sketch_1/SketchLine_3_StartVertex"), False)
55
56 ### Create Plane
57 Plane_5 = model.addPlane(Part_1_doc, model.selection("FACE", "Sketch_1/Face-SketchLine_1r-SketchLine_2f-SketchLine_3f-SketchLine_4f"), 100, False)
58
59 ### Create Sketch
60 Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("YOZ"))
61
62 ### Create SketchCircle
63 SketchCircle_1 = Sketch_2.addCircle(60.9581866489876, 39.76685108527785, 26.86156014153439)
64 model.do()
65
66 ### Create Plane
67 Plane_6 = model.addPlane(Part_1_doc, model.selection("FACE", "Sketch_2/Face-SketchCircle_1_2r"), 100, False)
68
69 ### Create Box
70 Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
71
72 ### Create Box
73 Box_2 = model.addBox(Part_1_doc, 10, 10, 10)
74
75 ### Create Translation
76 Translation_1 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "all-in-Box_2")], axis = model.selection("EDGE", "PartSet/OY"), distance = 100, keepSubResults = True)
77
78 ### Create Wire
79 Wire_1_objects = [model.selection("EDGE", "[Box_1_1/Front][Box_1_1/Right]"),
80                   model.selection("EDGE", "[Box_1_1/Right][Box_1_1/Top]"),
81                   model.selection("EDGE", "[Box_1_1/Back][Box_1_1/Right]"),
82                   model.selection("EDGE", "[Box_1_1/Right][Box_1_1/Bottom]")]
83 Wire_1 = model.addWire(Part_1_doc, Wire_1_objects, False)
84
85 ### Create Wire
86 Wire_2_objects = [model.selection("EDGE", "[Translation_1_1_1/MF:Translated&Box_2_1/Left][Translation_1_1_1/MF:Translated&Box_2_1/Top]"),
87                   model.selection("EDGE", "[Translation_1_1_1/MF:Translated&Box_2_1/Front][Translation_1_1_1/MF:Translated&Box_2_1/Left]"),
88                   model.selection("EDGE", "[Translation_1_1_1/MF:Translated&Box_2_1/Left][Translation_1_1_1/MF:Translated&Box_2_1/Bottom]"),
89                   model.selection("EDGE", "[Translation_1_1_1/MF:Translated&Box_2_1/Back][Translation_1_1_1/MF:Translated&Box_2_1/Left]")]
90 Wire_2 = model.addWire(Part_1_doc, Wire_2_objects, False)
91
92 ### Create Box
93 Box_3 = model.addBox(Part_1_doc, 10, 10, 10)
94
95 ### Create Wire
96 Wire_3 = model.addWire(Part_1_doc, [model.selection("EDGE", "[Box_3_1/Left][Box_3_1/Top]"), model.selection("EDGE", "[Box_3_1/Front][Box_3_1/Left]")], False)
97
98 ### Create Box
99 Box_4 = model.addBox(Part_1_doc, 10, 10, 10)
100
101 ### Create Translation
102 Translation_2 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "all-in-Box_4")], axis = model.selection("EDGE", "PartSet/OY"), distance = 40, keepSubResults = True)
103
104 ### Create Wire
105 Wire_4 = model.addWire(Part_1_doc, [model.selection("EDGE", "[Translation_2_1_1/MF:Translated&Box_4_1/Left][Translation_2_1_1/MF:Translated&Box_4_1/Top]"), model.selection("EDGE", "[Translation_2_1_1/MF:Translated&Box_4_1/Front][Translation_2_1_1/MF:Translated&Box_4_1/Left]")], False)
106
107 ### Create Loft
108 Loft_1 = model.addLoft(Part_1_doc, model.selection("FACE", "Plane_2"), model.selection("FACE", "Plane_1"))
109
110 ### Create Loft
111 Loft_2 = model.addLoft(Part_1_doc, model.selection("WIRE", "Wire_2_1"), model.selection("WIRE", "Wire_1_1"))
112
113 ### Create Loft
114 Loft_3 = model.addLoft(Part_1_doc, model.selection("WIRE", "Wire_3_1"), model.selection("WIRE", "Wire_4_1"))
115
116 ### Create Loft
117 Loft_4 = model.addLoft(Part_1_doc, model.selection("EDGE", "Sketch_1/SketchLine_2"), model.selection("EDGE", "Sketch_1/SketchLine_4"))
118
119 # # Errors tests
120 # Wire and Edge
121 Box_5 = model.addBox(Part_1_doc, 10, 10, 10)
122 Wire_5_objects = [model.selection("EDGE", "[Box_5_1/Back][Box_5_1/Left]"),
123                   model.selection("EDGE", "[Box_5_1/Left][Box_5_1/Top]"),
124                   model.selection("EDGE", "[Box_5_1/Front][Box_5_1/Left]"),
125                   model.selection("EDGE", "[Box_5_1/Left][Box_5_1/Bottom]")]
126 Wire_5 = model.addWire(Part_1_doc, Wire_5_objects, False)
127 Box_6 = model.addBox(Part_1_doc, 10, 10, 10)
128 Loft_5 = model.addLoft(Part_1_doc, model.selection("WIRE", "Wire_5_1"), model.selection("EDGE", "[Box_6_1/Right][Box_6_1/Top]"))
129 assert(Loft_5.feature().error() == "Error: the shapes have different type")
130
131 # Wire and Face
132 Wire_6_objects = [model.selection("EDGE", "[Loft_1_1/Loft_Face_1][Loft_1_1/Loft_Face_5]"),
133                   model.selection("EDGE", "[Loft_1_1/Loft_Face_1][Loft_1_1/Loft_Face_4]"),
134                   model.selection("EDGE", "[Loft_1_1/Loft_Face_1][Loft_1_1/Loft_Face_2]"),
135                   model.selection("EDGE", "[Loft_1_1/Loft_Face_1][Loft_1_1/Loft_Face_6]")]
136 Wire_6 = model.addWire(Part_1_doc, Wire_6_objects, False)
137 Loft_6 = model.addLoft(Part_1_doc, model.selection("WIRE", "Wire_6_1"), model.selection("EDGE", "Plane_3"))
138 assert(Loft_6.feature().error() == "Error: the shapes have different type")
139
140 # Only one element
141 Box_7 = model.addBox(Part_1_doc, 10, 10, 10)
142 Loft_7 = model.addLoft(Part_1_doc, model.selection("SOLID", "Box_7_1"), model.selection())
143 assert(Loft_7.feature().error() == 'Error: Could not get "second_object" attribute.')
144
145 # Two faces with different number of edges
146 Cone_1 = model.addCone(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 10, 5, 10)
147 Loft_8 = model.addLoft(Part_1_doc, model.selection("FACE", "Cone_1_1/Face_2"), model.selection("EDGE", "Plane_3"))
148
149 model.end()
150
151 from GeomAPI import GeomAPI_Shape
152
153 #test loft with two face
154 model.testNbResults(Loft_1, 1)
155 model.testNbSubResults(Loft_1, [0])
156 model.testNbSubShapes(Loft_1, GeomAPI_Shape.SOLID, [1])
157 model.testNbSubShapes(Loft_1, GeomAPI_Shape.FACE, [6])
158 model.testNbSubShapes(Loft_1, GeomAPI_Shape.EDGE, [24])
159 model.testNbSubShapes(Loft_1, GeomAPI_Shape.VERTEX, [48])
160 model.testResultsVolumes(Loft_1, [996988.58940])
161
162 #test loft with two wire
163 model.testNbResults(Loft_2, 1)
164 model.testNbSubResults(Loft_2, [0])
165 model.testNbSubShapes(Loft_2, GeomAPI_Shape.SHELL, [1])
166 model.testNbSubShapes(Loft_2, GeomAPI_Shape.FACE, [4])
167 model.testNbSubShapes(Loft_2, GeomAPI_Shape.EDGE, [16])
168 model.testNbSubShapes(Loft_2, GeomAPI_Shape.VERTEX, [32])
169 model.testResultsVolumes(Loft_2, [0.0])
170
171 #test loft with two wire
172 model.testNbResults(Loft_3, 1)
173 model.testNbSubResults(Loft_3, [0])
174 model.testNbSubShapes(Loft_3, GeomAPI_Shape.SHELL, [1])
175 model.testNbSubShapes(Loft_3, GeomAPI_Shape.FACE, [2])
176 model.testNbSubShapes(Loft_3, GeomAPI_Shape.EDGE, [8])
177 model.testNbSubShapes(Loft_3, GeomAPI_Shape.VERTEX, [16])
178 model.testResultsVolumes(Loft_3, [0.0])
179
180 #test loft with two edge
181 model.testNbResults(Loft_4, 1)
182 model.testNbSubResults(Loft_4, [0])
183 model.testNbSubShapes(Loft_4, GeomAPI_Shape.FACE, [1])
184 model.testNbSubShapes(Loft_4, GeomAPI_Shape.EDGE, [4])
185 model.testNbSubShapes(Loft_4, GeomAPI_Shape.VERTEX, [8])
186 model.testResultsVolumes(Loft_4, [0.0])
187
188 #test loft with faces with different number of edges
189 model.testNbResults(Loft_8, 1)
190 model.testNbSubResults(Loft_8, [0])
191 model.testNbSubShapes(Loft_8, GeomAPI_Shape.FACE, [7])
192 model.testNbSubShapes(Loft_8, GeomAPI_Shape.EDGE, [30])
193 model.testNbSubShapes(Loft_8, GeomAPI_Shape.VERTEX, [60])
194 model.testResultsVolumes(Loft_8, [151868.70541])
195
196
197
198