]> SALOME platform Git repositories - modules/shaper.git/blob - src/FiltersPlugin/Test/TestFilter_OnShapeName.py
Salome HOME
Non planar faces 35156
[modules/shaper.git] / src / FiltersPlugin / Test / TestFilter_OnShapeName.py
1 # Copyright (C) 2014-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 import sys
21 import salome
22
23 salome.salome_init()
24 import salome_notebook
25 notebook = salome_notebook.NoteBook()
26 sys.path.insert(0, r'/home/eksu/S2')
27
28 ###
29 ### SHAPER component
30 ###
31
32 from SketchAPI import *
33
34 from salome.shaper import model
35
36 model.begin()
37 partSet = model.moduleDocument()
38
39 ### Create Part
40 Part_1 = model.addPart(partSet)
41 Part_1_doc = Part_1.document()
42 model.addParameter(Part_1_doc, "rayon", '10.')
43 model.addParameter(Part_1_doc, "hauteur", '2.*rayon')
44
45 ### Create Sketch
46 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
47
48 ### Create SketchProjection
49 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
50 SketchPoint_1 = SketchProjection_1.createdFeature()
51
52 ### Create SketchCircle
53 SketchCircle_1 = Sketch_1.addCircle(0, 0, 10)
54 Sketch_1.setCoincident(SketchPoint_1.result(), SketchCircle_1.center())
55 Sketch_1.setRadius(SketchCircle_1.results()[1], "rayon ")
56 model.do()
57
58 ### Create Extrusion
59 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "all-in-Sketch_1")], model.selection(), "hauteur ", "hauteur/4.", "Faces|Wires")
60
61 ### Create Sketch
62 Sketch_2 = model.addSketch(Part_1_doc, model.standardPlane("XOY"))
63
64 ### Create SketchLine
65 SketchLine_1 = Sketch_2.addLine(12.5, -12.5, -12.5, -12.5)
66
67 ### Create SketchProjection
68 SketchProjection_2 = Sketch_2.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
69 SketchPoint_2 = SketchProjection_2.createdFeature()
70
71 ### Create SketchLine
72 SketchLine_2 = Sketch_2.addLine(-12.5, -12.5, -12.5, 12.5)
73
74 ### Create SketchLine
75 SketchLine_3 = Sketch_2.addLine(-12.5, 12.5, 12.5, 12.5)
76
77 ### Create SketchLine
78 SketchLine_4 = Sketch_2.addLine(12.5, 12.5, 12.5, -12.5)
79 Sketch_2.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint())
80 Sketch_2.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
81 Sketch_2.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
82 Sketch_2.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
83
84 ### Create SketchLine
85 SketchLine_5 = Sketch_2.addLine(12.5, -12.5, -12.5, 12.5)
86 SketchLine_5.setAuxiliary(True)
87
88 ### Create SketchLine
89 SketchLine_6 = Sketch_2.addLine(-12.5, -12.5, 12.5, 12.5)
90 SketchLine_6.setAuxiliary(True)
91 Sketch_2.setCoincident(SketchLine_1.startPoint(), SketchLine_5.startPoint())
92 Sketch_2.setCoincident(SketchLine_2.startPoint(), SketchLine_6.startPoint())
93 Sketch_2.setCoincident(SketchLine_3.startPoint(), SketchLine_5.endPoint())
94 Sketch_2.setCoincident(SketchLine_4.startPoint(), SketchLine_6.endPoint())
95 Sketch_2.setCoincident(SketchAPI_Point(SketchPoint_2).coordinates(), SketchLine_5.result())
96 Sketch_2.setCoincident(SketchAPI_Point(SketchPoint_2).coordinates(), SketchLine_6.result())
97 Sketch_2.setHorizontal(SketchLine_1.result())
98 Sketch_2.setVertical(SketchLine_2.result())
99 Sketch_2.setHorizontal(SketchLine_3.result())
100 Sketch_2.setVertical(SketchLine_4.result())
101 Sketch_2.setLength(SketchLine_3.result(), "2.5*rayon")
102 Sketch_2.setEqual(SketchLine_3.result(), SketchLine_2.result())
103 model.do()
104
105 ### Create Extrusion
106 Extrusion_2 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "all-in-Sketch_2")], model.selection(), 0, "2.*rayon", "Faces|Wires")
107
108 ### Create Sketch
109 Sketch_3 = model.addSketch(Part_1_doc, model.standardPlane("XOY"))
110
111 ### Create SketchLine
112 SketchLine_7 = Sketch_3.addLine(-4.930380657631324e-32, -6, -4.930380657631324e-32, 6)
113
114 ### Create SketchProjection
115 SketchProjection_3 = Sketch_3.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
116 SketchPoint_3 = SketchProjection_3.createdFeature()
117 Sketch_3.setMiddlePoint(SketchAPI_Point(SketchPoint_3).coordinates(), SketchLine_7.result())
118 Sketch_3.setVertical(SketchLine_7.result())
119 Sketch_3.setLength(SketchLine_7.result(), "1.2*rayon")
120 model.do()
121
122 ### Create Extrusion
123 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")
124
125 ### Create Extrusion
126 Extrusion_4 = model.addExtrusion(Part_1_doc, [model.selection("VERTEX", "PartSet/Origin")], model.selection("EDGE", "PartSet/OY"), "rayon*1.6", "rayon*1.6")
127
128 ### Create Translation
129 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)
130
131 ### Create Partition
132 Partition_1_objects = [model.selection("COMPOUND", "all-in-Extrusion_1"),
133                        model.selection("COMPOUND", "all-in-Extrusion_2"),
134                        model.selection("COMPOUND", "all-in-Extrusion_3"),
135                        model.selection("COMPOUND", "all-in-Translation_1")]
136 Partition_1 = model.addPartition(Part_1_doc, Partition_1_objects, keepSubResults = True)
137 Partition_1.result().subResult(0).setName("Volumes")
138 Partition_1.result().subResult(0).subResult(0).setName("Cylindre bas")
139 Partition_1.result().subResult(0).subResult(1).setName("Cylindre haut")
140 Partition_1.result().subResult(0).subResult(2).setName("Cube Creux")
141 Partition_1.result().subResult(1).setName("Plaque")
142 Partition_1.result().subResult(2).setName("Poutre 1")
143 Partition_1.result().subResult(3).setName("Poutre 2")
144
145 ### Create Group
146 Group_1_objects = [model.selection("VERTEX", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchLine_4][Extrusion_2_1/Generated_Face&Sketch_2/SketchLine_3][Extrusion_2_1/From_Face]"),
147                    model.selection("VERTEX", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchLine_4][Extrusion_2_1/Generated_Face&Sketch_2/SketchLine_3][Cube Creux/Modified_Face&Extrusion_2_1/To_Face]"),
148                    model.selection("VERTEX", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchLine_4][Extrusion_2_1/Generated_Face&Sketch_2/SketchLine_1][Extrusion_2_1/From_Face]"),
149                    model.selection("VERTEX", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchLine_4][Extrusion_2_1/Generated_Face&Sketch_2/SketchLine_1][Cube Creux/Modified_Face&Extrusion_2_1/To_Face]"),
150                    model.selection("VERTEX", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchLine_3][Extrusion_2_1/From_Face][Extrusion_2_1/Generated_Face&Sketch_2/SketchLine_2]"),
151                    model.selection("VERTEX", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchLine_3][Cube Creux/Modified_Face&Extrusion_2_1/To_Face][Extrusion_2_1/Generated_Face&Sketch_2/SketchLine_2]"),
152                    model.selection("VERTEX", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchLine_1][Extrusion_2_1/From_Face][Extrusion_2_1/Generated_Face&Sketch_2/SketchLine_2]"),
153                    model.selection("VERTEX", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchLine_1][Cube Creux/Modified_Face&Extrusion_2_1/To_Face][Extrusion_2_1/Generated_Face&Sketch_2/SketchLine_2]"),
154                    model.selection("VERTEX", "[Extrusion_3_1/From_Edge]e[Cube Creux/Modified_Edge&Sketch_3/SketchLine_7_StartVertex]e"),
155                    model.selection("VERTEX", "[Extrusion_3_1/From_Edge]e[Cube Creux/Modified_Edge&Sketch_3/SketchLine_7_EndVertex]e"), model.filters(Part_1_doc, [model.addFilter(name = "OnShapeName", args = ["Cube"])])]
156 Group_1 = model.addGroup(Part_1_doc, "Vertices", Group_1_objects)
157 Group_1.setName("CubeVertices_1")
158 Group_1.result().setName("CubeVertices_1")
159
160 ### Create Group
161 Group_2_objects = [model.selection("EDGE", "(Cylindre haut/Generated_Edge&Extrusion_2_1/To_Face&Sketch_1/SketchCircle_1_2)([Cylindre haut/Modified_Face&Sketch_1/SketchCircle_1_2][Cylindre haut/Modified_Face&Extrusion_1_1/To_Face])"),
162                    model.selection("EDGE", "[Cylindre haut/Modified_Face&Sketch_1/SketchCircle_1_2][Cylindre haut/Modified_Face&Extrusion_1_1/To_Face]"),
163                    model.selection("EDGE", "Cylindre haut/Generated_Edge&Sketch_3/Sketch_3&Extrusion_1_1/To_Face"),
164                    model.selection("EDGE", "Cylindre haut/Modified_Edge&Sketch_3/SketchLine_7_EndVertex&new_weak_name_1"),
165                    model.selection("EDGE", "Cylindre haut/Modified_Edge&PartSet/Origin/Origin&new_weak_name_2"),
166                    model.selection("EDGE", "Cylindre haut/Modified_Edge&Sketch_3/SketchLine_7_StartVertex&new_weak_name_1"),
167                    model.selection("EDGE", "Cylindre haut/Modified_Edge&Sketch_3/SketchLine_7_EndVertex&new_weak_name_2"),
168                    model.selection("EDGE", "Cylindre haut/Modified_Edge&Sketch_3/SketchLine_7_StartVertex&new_weak_name_2"),
169                    model.selection("EDGE", "Cylindre haut/Modified_Edge&PartSet/Origin/Origin&new_weak_name_1"),
170                    model.selection("EDGE", "Cylindre haut/Modified_Edge&PartSet/Origin/Origin&new_weak_name_3"),
171                    model.selection("SOLID", "Cylindre bas"), model.filters(Part_1_doc, [model.addFilter(name = "OnShapeName", args = ["Cyl"])])]
172 Group_2 = model.addGroup(Part_1_doc, "Edges", Group_2_objects)
173 Group_2.setName("CylEdges_2")
174 Group_2.result().setName("CylEdges_2")
175
176 ### Create Group
177 Group_3 = model.addGroup(Part_1_doc, "Faces", [model.selection("FACE", "Plaque"), model.filters(Part_1_doc, [model.addFilter(name = "OnShapeName", args = ["Plaq"])])])
178 Group_3.setName("Plaque_3")
179 Group_3.result().setName("Plaque_3")
180
181 ### Create Group
182 Group_4 = model.addGroup(Part_1_doc, "Solids", [model.selection("SOLID", "Cylindre haut"), model.selection("SOLID", "Cylindre bas"), model.filters(Part_1_doc, [model.addFilter(name = "OnShapeName", args = ["Cyl"])])])
183 Group_4.setName("Cyllindres_4")
184 Group_4.result().setName("Cyllindres_4")
185
186 model.end()
187
188 ###
189 ### SHAPERSTUDY component
190 ###
191
192 model.publishToShaperStudy()
193 import SHAPERSTUDY
194 Partition_1_1, CubeVertices_1, CylEdges_2, Plaque_3, Cyllindres_4, = SHAPERSTUDY.shape(model.featureStringId(Partition_1))
195
196 if salome.sg.hasDesktop():
197   salome.sg.updateObjBrowser()