Salome HOME
Porting GUI documentation on Doxygen tool.
[modules/smesh.git] / doc / salome / gui / SMESH / input / tui_grouping_elements.doc
1 /*!
2
3 \page tui_grouping_elements_page Grouping Elements
4
5 <br>
6 \anchor tui_create_standalone_group
7 <h2>Create a Standalone Group</h2>
8
9 \code
10 import SMESH_mechanic
11
12 smesh  = SMESH_mechanic.smesh
13 mesh   = SMESH_mechanic.mesh
14 salome = SMESH_mechanic.salome
15
16 # Get ids of all faces with area > 100 
17 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_MoreThan, 100.)
18
19 anIds = mesh.GetIdsFromFilter(aFilter) 
20
21 # create a group consisting of faces with area > 100
22 aGroup = mesh.MakeGroupByIds("Area > 100", smesh.FACE, anIds)
23
24 salome.sg.updateObjBrowser(1)
25 \endcode
26
27 \image html create_group.png
28
29 <br>
30 \anchor tui_create_group_on_geometry
31 <h2>Create a Group on Geometry</h2>
32
33 \code
34 import salome
35 import geompy
36 import smesh
37
38 # create a box
39 box = geompy.MakeBox(0., 0., 0., 100., 100., 100.)
40 geompy.addToStudy(box, "box")
41
42 # add the first face of the box to the study
43 subShapeList = geompy.SubShapeAll(box, geompy.ShapeType["FACE"])
44 face = subShapeList[0]
45 geompy.addToStudyInFather(box, face, "face 1") 
46
47 # create group of edges on the face
48 aGeomGroupE = geompy.CreateGroup(face, geompy.ShapeType["EDGE"])
49 geompy.AddObject(aGeomGroupE, 3)
50 geompy.AddObject(aGeomGroupE, 6)
51 geompy.AddObject(aGeomGroupE, 8)
52 geompy.AddObject(aGeomGroupE, 10)
53 geompy.addToStudyInFather(face, aGeomGroupE, "Group of Edges")
54
55 # create quadrangle 2D mesh on the box
56 quadra = smesh.Mesh(box, "Box : quadrangle 2D mesh")
57 algo1D = quadra.Segment()
58 quadra.Quadrangle()
59 algo1D.NumberOfSegments(7) 
60
61 # compute the mesh
62 quadra.Compute()
63
64 # create SMESH group on the face with name "SMESHGroup1"
65 aSmeshGroup1 = quadra.GroupOnGeom(face, "SMESHGroup1")
66
67 # create SMESH group on <aGeomGroupE> with default name
68 aSmeshGroup2 = quadra.GroupOnGeom(aGeomGroupE) 
69
70 salome.sg.updateObjBrowser(1)
71 \endcode
72
73 <br>
74 \anchor tui_edit_group
75 <h2>Edit a Group</h2>
76
77 \code
78 import SMESH_mechanic
79
80 smesh  = SMESH_mechanic.smesh
81 mesh   = SMESH_mechanic.mesh
82 salome = SMESH_mechanic.salome
83
84 # Get ids of all faces with area > 35
85 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_MoreThan, 35.)
86
87 anIds = mesh.GetIdsFromFilter(aFilter) 
88
89 print "Criterion: Area > 35, Nb = ", len(anIds)
90
91 # create a group by adding elements with area > 35
92 aGroup = mesh.CreateEmptyGroup(smesh.FACE, "Area > 35")
93 aGroup.Add(anIds) 
94
95 # Get ids of all faces with area > 40
96 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_MoreThan, 40.)
97
98 anIds = mesh.GetIdsFromFilter(aFilter)
99
100 print "Criterion: Area > 40, Nb = ", len(anIds) 
101
102 # create a group of elements with area [35; 40] by removing elements with area > 40 from group aGroup
103 aGroup.Remove(anIds) 
104
105 # print the result
106 aGroupElemIDs = aGroup.GetListOfID()
107
108 print "Criterion: 35 < Area < 40, Nb = ", len(aGroupElemIDs)
109
110 j = 1
111 for i in range(len(aGroupElemIDs)):
112   if j > 20: j = 1; print ""
113   print aGroupElemIDs[i],
114   j = j + 1
115   pass
116 print ""
117
118 salome.sg.updateObjBrowser(1)
119 \endcode
120
121 \image html editing_groups1.png
122
123 \image html editing_groups2.png
124
125 <br>
126 \anchor tui_union_of_two_groups
127 <h2>Union of two groups</h2>
128
129 \code
130 import SMESH_mechanic
131
132 smesh  = SMESH_mechanic.smesh
133 mesh   = SMESH_mechanic.mesh
134 salome = SMESH_mechanic.salome
135
136 # Criterion : AREA > 20
137 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_MoreThan, 20.)
138
139 anIds = mesh.GetIdsFromFilter(aFilter)
140
141 print "Criterion: Area > 20, Nb = ", len( anIds ) 
142
143 # create a group by adding elements with area > 20
144 aGroup1 = mesh.CreateEmptyGroup(SMESH.FACE, "Area > 20")
145 aGroup1.Add(anIds)
146
147 # Criterion : AREA = 20
148 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_EqualTo, 20.)
149
150 anIds = mesh.GetIdsFromFilter(aFilter)
151
152 print "Criterion: Area = 20, Nb = ", len( anIds ) 
153
154 # create a group by adding elements with area = 20
155 aGroup2 = mesh.CreateEmptyGroup( smesh.FACE, "Area = 20" )
156
157 aGroup2.Add(anIds)
158
159 # create union group : area >= 20
160 aGroup3 = mesh.UnionGroups(aGroup1, aGroup2, "Area >= 20")
161 print "Criterion: Area >= 20, Nb = ", len(aGroup3.GetListOfID())
162
163 # Criterion : AREA < 20
164 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_LessThan, 20.)
165
166 anIds = mesh.GetIdsFromFilter(aFilter)
167
168 print "Criterion: Area < 20, Nb = ", len(anIds)
169
170 # create a group by adding elements with area < 20
171 aGroup4 = mesh.CreateEmptyGroup(smesh.FACE, "Area < 20")
172 aGroup4.Add(anIds)
173
174 # create union group : area >= 20 and area < 20
175 aGroup5 = mesh.UnionGroups(aGroup3, aGroup4, "Any Area")
176 print "Criterion: Any Area, Nb = ", len(aGroup5.GetListOfID())
177
178 salome.sg.updateObjBrowser(1)
179 \endcode
180
181 \image html union_groups1.png
182
183 \image html union_groups2.png
184
185 \image html union_groups3.png
186
187 <br>
188 \anchor tui_intersection_of_two_groups
189 <h2>Intersection of two groups</h2>
190
191 \code
192 import SMESH_mechanic
193
194 smesh  = SMESH_mechanic.smesh
195 mesh   = SMESH_mechanic.mesh
196 salome = SMESH_mechanic.salome
197
198 # Criterion : AREA > 20
199 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_MoreThan, 20.)
200
201 anIds = mesh.GetIdsFromFilter(aFilter)
202
203 print "Criterion: Area > 20, Nb = ", len(anIds) 
204
205 # create a group by adding elements with area > 20
206 aGroup1 = mesh.CreateEmptyGroup(SMESH.FACE, "Area > 20")
207 aGroup1.Add(anIds)
208
209 # Criterion : AREA < 60
210 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_LessThan, 60.)
211
212 anIds = mesh.GetIdsFromFilter(aFilter)
213
214 print "Criterion: Area < 60, Nb = ", len(anIds) 
215
216 # create a group by adding elements with area < 60
217 aGroup2 = mesh.CreateEmptyGroup(SMESH.FACE, "Area < 60")
218 aGroup2.Add(anIds)
219
220 # create an intersection of groups : 20 < area < 60
221 aGroup3 = mesh.IntersectGroups(aGroup1, aGroup2, "20 < Area < 60")
222 print "Criterion: 20 < Area < 60, Nb = ", len(aGroup3.GetListOfID())
223
224 salome.sg.updateObjBrowser(1)
225 \endcode
226
227 \image html intersect_groups1.png
228
229 \image html intersect_groups2.png
230
231 \image html intersect_groups3.png
232
233 <br>
234 \anchor tui_cut_of_two_groups
235 <h2>Cut of two groups</h2>
236
237 \code
238 import SMESH_mechanic
239
240 smesh  = SMESH_mechanic.smesh
241 mesh   = SMESH_mechanic.mesh
242 salome = SMESH_mechanic.salome
243
244 # Criterion : AREA > 20
245 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_MoreThan, 20.)
246
247 anIds = mesh.GetIdsFromFilter(aFilter)
248
249 print "Criterion: Area > 20, Nb = ", len(anIds) 
250
251 # create a group by adding elements with area > 20
252 aGroupMain = mesh.MakeGroupByIds("Area > 20", smesh.FACE, anIds)
253
254 # Criterion : AREA < 60
255 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_LessThan, 60.)
256
257 anIds = mesh.GetIdsFromFilter(aFilter)
258
259 print "Criterion: Area < 60, Nb = ", len(anIds) 
260
261 # create a group by adding elements with area < 60
262 aGroupTool = mesh.MakeGroupByIds("Area < 60", smesh.FACE, anIds)
263  
264 # create a cut of groups : area >= 60
265 aGroupRes = mesh.CutGroups(aGroupMain, aGroupTool, "Area >= 60")
266 print "Criterion: Area >= 60, Nb = ", len(aGroupRes.GetListOfID())
267
268 salome.sg.updateObjBrowser(1)
269 \endcode
270
271 \image html cut_groups1.png
272
273 \image html cut_groups2.png
274
275 \image html cut_groups3.png
276
277 */