1 # Copyright (C) 2014-2023 CEA, EDF
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.
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.
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
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 from SketchAPI import *
26 from salome.shaper import model
29 partSet = model.moduleDocument()
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')
38 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
40 ### Create SketchProjection
41 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
42 SketchPoint_1 = SketchProjection_1.createdFeature()
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 ")
51 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "all-in-Sketch_1")], model.selection(), "hauteur ", "hauteur/4.", "Faces|Wires")
54 Sketch_2 = model.addSketch(Part_1_doc, model.standardPlane("XOY"))
57 SketchLine_1 = Sketch_2.addLine(12.5, -12.5, -12.5, -12.5)
59 ### Create SketchProjection
60 SketchProjection_2 = Sketch_2.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
61 SketchPoint_2 = SketchProjection_2.createdFeature()
64 SketchLine_2 = Sketch_2.addLine(-12.5, -12.5, -12.5, 12.5)
67 SketchLine_3 = Sketch_2.addLine(-12.5, 12.5, 12.5, 12.5)
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())
77 SketchLine_5 = Sketch_2.addLine(12.5, -12.5, -12.5, 12.5)
78 SketchLine_5.setAuxiliary(True)
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())
98 Extrusion_2 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "all-in-Sketch_2")], model.selection(), 0, "2.*rayon", "Faces|Wires")
101 Sketch_3 = model.addSketch(Part_1_doc, model.standardPlane("XOY"))
103 ### Create SketchLine
104 SketchLine_7 = Sketch_3.addLine(-4.930380657631324e-32, -6, -4.930380657631324e-32, 6)
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")
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")
118 Extrusion_4 = model.addExtrusion(Part_1_doc, [model.selection("VERTEX", "PartSet/Origin")], model.selection("EDGE", "PartSet/OY"), "rayon*1.6", "rayon*1.6")
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)
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")
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"))
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)
149 from GeomAPI import *
152 RefCube = Partition_1.result().subResult(0).subResult(2).resultSubShapePair()[0]
153 exp = GeomAPI_ShapeExplorer(RefCube.shape(), GeomAPI_Shape.FACE)
155 Reference[model.selection(RefCube, exp.current())] = True
157 exp = GeomAPI_ShapeExplorer(RefCube.shape(), GeomAPI_Shape.EDGE)
159 Reference[model.selection(RefCube, exp.current())] = True
161 exp = GeomAPI_ShapeExplorer(RefCube.shape(), GeomAPI_Shape.VERTEX)
163 Reference[model.selection(RefCube, exp.current())] = True
166 ResfCyl= Partition_1.result().subResult(0).subResult(0).resultSubShapePair()[0]
167 exp = GeomAPI_ShapeExplorer(ResfCyl.shape(), GeomAPI_Shape.FACE)
169 Reference[model.selection(ResfCyl, exp.current())] = False
171 exp = GeomAPI_ShapeExplorer(ResfCyl.shape(), GeomAPI_Shape.VERTEX)
173 Reference[model.selection(ResfCyl, exp.current())] = False
176 model.checkFilter(Part_1_doc, model, Filters, Reference)
178 ### ------------------------------------------------------------------------------
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"))
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)
189 RefPoutre1 = Partition_1.result().subResult(2).resultSubShapePair()[0]
190 exp = GeomAPI_ShapeExplorer(RefPoutre1.shape(), GeomAPI_Shape.EDGE)
192 Reference[model.selection(RefPoutre1, exp.current())] = True
194 exp = GeomAPI_ShapeExplorer(RefPoutre1.shape(), GeomAPI_Shape.VERTEX)
196 Reference[model.selection(RefPoutre1, exp.current())] = True
198 RefPoutre2 = Partition_1.result().subResult(3).resultSubShapePair()[0]
199 exp = GeomAPI_ShapeExplorer(RefPoutre2.shape(), GeomAPI_Shape.EDGE)
201 Reference[model.selection(RefPoutre2, exp.current())] = True
203 exp = GeomAPI_ShapeExplorer(RefPoutre2.shape(), GeomAPI_Shape.VERTEX)
205 Reference[model.selection(RefPoutre2, exp.current())] = True
208 exp = GeomAPI_ShapeExplorer(ResfCyl.shape(), GeomAPI_Shape.EDGE)
210 Reference[model.selection(ResfCyl, exp.current())] = False
212 exp = GeomAPI_ShapeExplorer(ResfCyl.shape(), GeomAPI_Shape.VERTEX)
214 Reference[model.selection(ResfCyl, exp.current())] = False
217 model.checkFilter(Part_1_doc, model, Filters, Reference)
219 ### ------------------------------------------------------------------------------
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"))
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)
234 exp = GeomAPI_ShapeExplorer(RefCube.shape(), GeomAPI_Shape.SOLID)
236 Reference[model.selection(RefCube, exp.current())] = True
238 exp = GeomAPI_ShapeExplorer(RefCube.shape(), GeomAPI_Shape.FACE)
240 Reference[model.selection(RefCube, exp.current())] = True
242 exp = GeomAPI_ShapeExplorer(RefCube.shape(), GeomAPI_Shape.EDGE)
244 Reference[model.selection(RefCube, exp.current())] = True
246 exp = GeomAPI_ShapeExplorer(RefCube.shape(), GeomAPI_Shape.VERTEX)
248 Reference[model.selection(RefCube, exp.current())] = True
251 exp = GeomAPI_ShapeExplorer(ResfCyl.shape(), GeomAPI_Shape.SOLID)
253 Reference[model.selection(ResfCyl, exp.current())] = True
255 exp = GeomAPI_ShapeExplorer(ResfCyl.shape(), GeomAPI_Shape.FACE)
257 Reference[model.selection(ResfCyl, exp.current())] = True
259 exp = GeomAPI_ShapeExplorer(ResfCyl.shape(), GeomAPI_Shape.EDGE)
261 Reference[model.selection(ResfCyl, exp.current())] = True
263 exp = GeomAPI_ShapeExplorer(ResfCyl.shape(), GeomAPI_Shape.VERTEX)
265 Reference[model.selection(ResfCyl, exp.current())] = True
268 ResfCyl2= Partition_1.result().subResult(0).subResult(1).resultSubShapePair()[0]
269 exp = GeomAPI_ShapeExplorer(ResfCyl2.shape(), GeomAPI_Shape.SOLID)
271 Reference[model.selection(ResfCyl2, exp.current())] = True
273 exp = GeomAPI_ShapeExplorer(ResfCyl2.shape(), GeomAPI_Shape.FACE)
275 Reference[model.selection(ResfCyl2, exp.current())] = True
277 exp = GeomAPI_ShapeExplorer(ResfCyl2.shape(), GeomAPI_Shape.EDGE)
279 Reference[model.selection(ResfCyl2, exp.current())] = True
281 exp = GeomAPI_ShapeExplorer(ResfCyl2.shape(), GeomAPI_Shape.VERTEX)
283 Reference[model.selection(ResfCyl2, exp.current())] = True
286 exp = GeomAPI_ShapeExplorer(RefPoutre1.shape(), GeomAPI_Shape.EDGE)
288 Reference[model.selection(RefPoutre1, exp.current())] = False
290 exp = GeomAPI_ShapeExplorer(RefPoutre1.shape(), GeomAPI_Shape.VERTEX)
292 Reference[model.selection(RefPoutre1, exp.current())] = False
294 RefPoutre2 = Partition_1.result().subResult(3).resultSubShapePair()[0]
295 exp = GeomAPI_ShapeExplorer(RefPoutre2.shape(), GeomAPI_Shape.EDGE)
297 Reference[model.selection(RefPoutre2, exp.current())] = False
299 exp = GeomAPI_ShapeExplorer(RefPoutre2.shape(), GeomAPI_Shape.VERTEX)
301 Reference[model.selection(RefPoutre2, exp.current())] = False
304 model.checkFilter(Part_1_doc, model, Filters, Reference)