Salome HOME
Updated copyright comment
[modules/shaper.git] / src / FiltersPlugin / Test / TestFilter_OnShapeName.py
1 # Copyright (C) 2014-2024  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 import salome
21
22 salome.salome_init()
23
24 from SketchAPI import *
25
26 from salome.shaper import model
27
28 model.begin()
29 partSet = model.moduleDocument()
30
31 ### Create Part
32 Part_1 = model.addPart(partSet)
33 Part_1_doc = Part_1.document()
34 model.addParameter(Part_1_doc, "rayon", '10.')
35 model.addParameter(Part_1_doc, "hauteur", '2.*rayon')
36
37 ### Create Sketch
38 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
39
40 ### Create SketchProjection
41 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
42 SketchPoint_1 = SketchProjection_1.createdFeature()
43
44 ### Create SketchCircle
45 SketchCircle_1 = Sketch_1.addCircle(0, 0, 10)
46 Sketch_1.setCoincident(SketchPoint_1.result(), SketchCircle_1.center())
47 Sketch_1.setRadius(SketchCircle_1.results()[1], "rayon ")
48 model.do()
49
50 ### Create Extrusion
51 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "all-in-Sketch_1")], model.selection(), "hauteur ", "hauteur/4.", "Faces|Wires")
52
53 ### Create Sketch
54 Sketch_2 = model.addSketch(Part_1_doc, model.standardPlane("XOY"))
55
56 ### Create SketchLine
57 SketchLine_1 = Sketch_2.addLine(12.5, -12.5, -12.5, -12.5)
58
59 ### Create SketchProjection
60 SketchProjection_2 = Sketch_2.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
61 SketchPoint_2 = SketchProjection_2.createdFeature()
62
63 ### Create SketchLine
64 SketchLine_2 = Sketch_2.addLine(-12.5, -12.5, -12.5, 12.5)
65
66 ### Create SketchLine
67 SketchLine_3 = Sketch_2.addLine(-12.5, 12.5, 12.5, 12.5)
68
69 ### Create SketchLine
70 SketchLine_4 = Sketch_2.addLine(12.5, 12.5, 12.5, -12.5)
71 Sketch_2.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint())
72 Sketch_2.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
73 Sketch_2.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
74 Sketch_2.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
75
76 ### Create SketchLine
77 SketchLine_5 = Sketch_2.addLine(12.5, -12.5, -12.5, 12.5)
78 SketchLine_5.setAuxiliary(True)
79
80 ### Create SketchLine
81 SketchLine_6 = Sketch_2.addLine(-12.5, -12.5, 12.5, 12.5)
82 SketchLine_6.setAuxiliary(True)
83 Sketch_2.setCoincident(SketchLine_1.startPoint(), SketchLine_5.startPoint())
84 Sketch_2.setCoincident(SketchLine_2.startPoint(), SketchLine_6.startPoint())
85 Sketch_2.setCoincident(SketchLine_3.startPoint(), SketchLine_5.endPoint())
86 Sketch_2.setCoincident(SketchLine_4.startPoint(), SketchLine_6.endPoint())
87 Sketch_2.setCoincident(SketchAPI_Point(SketchPoint_2).coordinates(), SketchLine_5.result())
88 Sketch_2.setCoincident(SketchAPI_Point(SketchPoint_2).coordinates(), SketchLine_6.result())
89 Sketch_2.setHorizontal(SketchLine_1.result())
90 Sketch_2.setVertical(SketchLine_2.result())
91 Sketch_2.setHorizontal(SketchLine_3.result())
92 Sketch_2.setVertical(SketchLine_4.result())
93 Sketch_2.setLength(SketchLine_3.result(), "2.5*rayon")
94 Sketch_2.setEqual(SketchLine_3.result(), SketchLine_2.result())
95 model.do()
96
97 ### Create Extrusion
98 Extrusion_2 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "all-in-Sketch_2")], model.selection(), 0, "2.*rayon", "Faces|Wires")
99
100 ### Create Sketch
101 Sketch_3 = model.addSketch(Part_1_doc, model.standardPlane("XOY"))
102
103 ### Create SketchLine
104 SketchLine_7 = Sketch_3.addLine(-4.930380657631324e-32, -6, -4.930380657631324e-32, 6)
105
106 ### Create SketchProjection
107 SketchProjection_3 = Sketch_3.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
108 SketchPoint_3 = SketchProjection_3.createdFeature()
109 Sketch_3.setMiddlePoint(SketchAPI_Point(SketchPoint_3).coordinates(), SketchLine_7.result())
110 Sketch_3.setVertical(SketchLine_7.result())
111 Sketch_3.setLength(SketchLine_7.result(), "1.2*rayon")
112 model.do()
113
114 ### Create Extrusion
115 Extrusion_3 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "all-in-Sketch_3")], model.selection("EDGE", "PartSet/OZ"), "hauteur*1.4", "hauteur*0.4", "Edges")
116
117 ### Create Extrusion
118 Extrusion_4 = model.addExtrusion(Part_1_doc, [model.selection("VERTEX", "PartSet/Origin")], model.selection("EDGE", "PartSet/OY"), "rayon*1.6", "rayon*1.6")
119
120 ### Create Translation
121 Translation_1 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "all-in-Extrusion_4")], axis = model.selection("EDGE", "PartSet/OZ"), distance = "hauteur*0.5", keepSubResults = True)
122
123 ### Create Partition
124 Partition_1_objects = [model.selection("COMPOUND", "all-in-Extrusion_1"),
125                        model.selection("COMPOUND", "all-in-Extrusion_2"),
126                        model.selection("COMPOUND", "all-in-Extrusion_3"),
127                        model.selection("COMPOUND", "all-in-Translation_1")]
128 Partition_1 = model.addPartition(Part_1_doc, Partition_1_objects, keepSubResults = True)
129 Partition_1.result().subResult(0).setName("Volumes")
130 Partition_1.result().subResult(0).subResult(0).setName("Cylindre bas")
131 Partition_1.result().subResult(0).subResult(1).setName("Cylindre haut")
132 Partition_1.result().subResult(0).subResult(2).setName("Cube Creux")
133 Partition_1.result().subResult(1).setName("Plaque")
134 Partition_1.result().subResult(2).setName("Poutre 1")
135 Partition_1.result().subResult(3).setName("Poutre 2")
136
137 model.end()
138 model.begin()
139 Filters = model.filters(Part_1_doc, [model.addFilter(name = "OnShapeName", args = ["Cube"])])
140 nFaces = len(Filters.select("FACE"))
141 nEdges = len(Filters.select("EDGE"))
142 nVerts = len(Filters.select("VERTEX"))
143 model.end()
144
145 assert nFaces==9, "Wrong number of filtered faces in 1st filter: {}, expected 9".format(nFaces)
146 assert nEdges==19, "Wrong number of filtered edges in 1st filter: {}, expected 19".format(nEdges)
147 assert nVerts==14, "Wrong number of selected vertexes in 1st filter: {}, expected 14".format(nVerts)
148
149 from GeomAPI import *
150
151 Reference = {}
152 RefCube = Partition_1.result().subResult(0).subResult(2).resultSubShapePair()[0]
153 exp = GeomAPI_ShapeExplorer(RefCube.shape(), GeomAPI_Shape.FACE)
154 while exp.more():
155   Reference[model.selection(RefCube, exp.current())] = True
156   exp.next()
157 exp = GeomAPI_ShapeExplorer(RefCube.shape(), GeomAPI_Shape.EDGE)
158 while exp.more():
159   Reference[model.selection(RefCube, exp.current())] = True
160   exp.next()
161 exp = GeomAPI_ShapeExplorer(RefCube.shape(), GeomAPI_Shape.VERTEX)
162 while exp.more():
163   Reference[model.selection(RefCube, exp.current())] = True
164   exp.next()
165
166 ResfCyl= Partition_1.result().subResult(0).subResult(0).resultSubShapePair()[0]
167 exp = GeomAPI_ShapeExplorer(ResfCyl.shape(), GeomAPI_Shape.FACE)
168 while exp.more():
169   Reference[model.selection(ResfCyl, exp.current())] = False
170   exp.next()
171 exp = GeomAPI_ShapeExplorer(ResfCyl.shape(), GeomAPI_Shape.VERTEX)
172 while exp.more():
173   Reference[model.selection(ResfCyl, exp.current())] = False
174   exp.next()
175
176 model.checkFilter(Part_1_doc, model, Filters, Reference)
177
178 ### ------------------------------------------------------------------------------
179 model.begin()
180 Filters = model.filters(Part_1_doc, [model.addFilter(name = "OnShapeName", args = ["Poutre [0-9]"])])
181 nEdges = len(Filters.select("EDGE"))
182 nVerts = len(Filters.select("VERTEX"))
183 model.end()
184
185 assert nEdges==2, "Wrong number of filtered edges in 2d filter: {}, expected 2".format(nEdges)
186 assert nVerts==4, "Wrong number of selected vertexes in 2d filter: {}, expected 4".format(nVerts)
187
188 Reference = {}
189 RefPoutre1 = Partition_1.result().subResult(2).resultSubShapePair()[0]
190 exp = GeomAPI_ShapeExplorer(RefPoutre1.shape(), GeomAPI_Shape.EDGE)
191 while exp.more():
192   Reference[model.selection(RefPoutre1, exp.current())] = True
193   exp.next()
194 exp = GeomAPI_ShapeExplorer(RefPoutre1.shape(), GeomAPI_Shape.VERTEX)
195 while exp.more():
196   Reference[model.selection(RefPoutre1, exp.current())] = True
197   exp.next()
198 RefPoutre2 = Partition_1.result().subResult(3).resultSubShapePair()[0]
199 exp = GeomAPI_ShapeExplorer(RefPoutre2.shape(), GeomAPI_Shape.EDGE)
200 while exp.more():
201   Reference[model.selection(RefPoutre2, exp.current())] = True
202   exp.next()
203 exp = GeomAPI_ShapeExplorer(RefPoutre2.shape(), GeomAPI_Shape.VERTEX)
204 while exp.more():
205   Reference[model.selection(RefPoutre2, exp.current())] = True
206   exp.next()
207
208 exp = GeomAPI_ShapeExplorer(ResfCyl.shape(), GeomAPI_Shape.EDGE)
209 while exp.more():
210   Reference[model.selection(ResfCyl, exp.current())] = False
211   exp.next()
212 exp = GeomAPI_ShapeExplorer(ResfCyl.shape(), GeomAPI_Shape.VERTEX)
213 while exp.more():
214   Reference[model.selection(ResfCyl, exp.current())] = False
215   exp.next()
216
217 model.checkFilter(Part_1_doc, model, Filters, Reference)
218
219 ### ------------------------------------------------------------------------------
220 model.begin()
221 Filters = model.filters(Part_1_doc, [model.addFilter(name = "OnShapeName", args = ["Volumes"])])
222 nSolids = len(Filters.select("SOLID"))
223 nFaces = len(Filters.select("FACE"))
224 nEdges = len(Filters.select("EDGE"))
225 nVerts = len(Filters.select("VERTEX"))
226 model.end()
227
228 assert nSolids==3, "Wrong number of filtered solids in 3rd filter: {}, expected 3".format(nSolids)
229 assert nFaces==15, "Wrong number of filtered faces in 3rd filter: {}, expected 15".format(nFaces)
230 assert nEdges==31, "Wrong number of filtered edges in 3rd filter: {}, expected 31".format(nEdges)
231 assert nVerts==19, "Wrong number of selected vertexes in 3rd filter: {}, expected 19".format(nVerts)
232
233 Reference = {}
234 exp = GeomAPI_ShapeExplorer(RefCube.shape(), GeomAPI_Shape.SOLID)
235 while exp.more():
236   Reference[model.selection(RefCube, exp.current())] = True
237   exp.next()
238 exp = GeomAPI_ShapeExplorer(RefCube.shape(), GeomAPI_Shape.FACE)
239 while exp.more():
240   Reference[model.selection(RefCube, exp.current())] = True
241   exp.next()
242 exp = GeomAPI_ShapeExplorer(RefCube.shape(), GeomAPI_Shape.EDGE)
243 while exp.more():
244   Reference[model.selection(RefCube, exp.current())] = True
245   exp.next()
246 exp = GeomAPI_ShapeExplorer(RefCube.shape(), GeomAPI_Shape.VERTEX)
247 while exp.more():
248   Reference[model.selection(RefCube, exp.current())] = True
249   exp.next()
250
251 exp = GeomAPI_ShapeExplorer(ResfCyl.shape(), GeomAPI_Shape.SOLID)
252 while exp.more():
253   Reference[model.selection(ResfCyl, exp.current())] = True
254   exp.next()
255 exp = GeomAPI_ShapeExplorer(ResfCyl.shape(), GeomAPI_Shape.FACE)
256 while exp.more():
257   Reference[model.selection(ResfCyl, exp.current())] = True
258   exp.next()
259 exp = GeomAPI_ShapeExplorer(ResfCyl.shape(), GeomAPI_Shape.EDGE)
260 while exp.more():
261   Reference[model.selection(ResfCyl, exp.current())] = True
262   exp.next()
263 exp = GeomAPI_ShapeExplorer(ResfCyl.shape(), GeomAPI_Shape.VERTEX)
264 while exp.more():
265   Reference[model.selection(ResfCyl, exp.current())] = True
266   exp.next()
267
268 ResfCyl2= Partition_1.result().subResult(0).subResult(1).resultSubShapePair()[0]
269 exp = GeomAPI_ShapeExplorer(ResfCyl2.shape(), GeomAPI_Shape.SOLID)
270 while exp.more():
271   Reference[model.selection(ResfCyl2, exp.current())] = True
272   exp.next()
273 exp = GeomAPI_ShapeExplorer(ResfCyl2.shape(), GeomAPI_Shape.FACE)
274 while exp.more():
275   Reference[model.selection(ResfCyl2, exp.current())] = True
276   exp.next()
277 exp = GeomAPI_ShapeExplorer(ResfCyl2.shape(), GeomAPI_Shape.EDGE)
278 while exp.more():
279   Reference[model.selection(ResfCyl2, exp.current())] = True
280   exp.next()
281 exp = GeomAPI_ShapeExplorer(ResfCyl2.shape(), GeomAPI_Shape.VERTEX)
282 while exp.more():
283   Reference[model.selection(ResfCyl2, exp.current())] = True
284   exp.next()
285
286 exp = GeomAPI_ShapeExplorer(RefPoutre1.shape(), GeomAPI_Shape.EDGE)
287 while exp.more():
288   Reference[model.selection(RefPoutre1, exp.current())] = False
289   exp.next()
290 exp = GeomAPI_ShapeExplorer(RefPoutre1.shape(), GeomAPI_Shape.VERTEX)
291 while exp.more():
292   Reference[model.selection(RefPoutre1, exp.current())] = False
293   exp.next()
294 RefPoutre2 = Partition_1.result().subResult(3).resultSubShapePair()[0]
295 exp = GeomAPI_ShapeExplorer(RefPoutre2.shape(), GeomAPI_Shape.EDGE)
296 while exp.more():
297   Reference[model.selection(RefPoutre2, exp.current())] = False
298   exp.next()
299 exp = GeomAPI_ShapeExplorer(RefPoutre2.shape(), GeomAPI_Shape.VERTEX)
300 while exp.more():
301   Reference[model.selection(RefPoutre2, exp.current())] = False
302   exp.next()
303
304 model.checkFilter(Part_1_doc, model, Filters, Reference)