Salome HOME
98dccc6f0e461a89ec71474eec60a5a5c5e03240
[modules/geom.git] / doc / salome / gui / GEOM / input / tui_repairing_operations.doc
1 /*!
2
3 \page tui_repairing_operations_page Repairing Operations
4
5 \anchor tui_shape_processing
6 <br><h2>Shape Processing</h2>
7
8 \code
9 import geompy
10 import salome
11 gg = salome.ImportComponentGUI("GEOM")
12
13 # create vertices, an edge, an arc, a wire, a face and a prism
14 p1 = geompy.MakeVertex(0,0,0)
15 p2 = geompy.MakeVertex(200,0,0)
16 p3 = geompy.MakeVertex(100,150,0)
17 edge = geompy.MakeEdge(p1,p2)
18 arc  = geompy.MakeArc(p1,p3,p2)
19 wire = geompy.MakeWire([edge,arc])
20 face = geompy.MakeFace(wire, 1)
21 theShape = geompy.MakePrismVecH(face, edge, 130)
22
23 # check the shape at the beginning
24 print "Before ProcessShape:"
25 isValid = geompy.CheckShape(theShape)
26 if isValid == 0:
27     print "The shape is not valid"
28 else:
29     print "The shape seems to be valid"
30
31 # process the Shape
32 Operators = ["FixShape"]
33 Parameters = ["FixShape.Tolerance3d"]
34 Values = ["1e-7"]
35 PS = geompy.ProcessShape(theShape, Operators, Parameters, Values)
36
37 # check the shape at the end
38 print "After ProcessShape:"
39 isValid = geompy.CheckShape(PS)
40 if isValid == 0:
41     print "The shape is not valid"
42     raise RuntimeError, "It seems, that the ProcessShape() has failed"
43 else:
44     print "The shape seems to be valid"
45
46 # add in the study and display
47 Id_Shape = geompy.addToStudy(theShape, "Invalid Shape")
48 Id_PS    = geompy.addToStudy(PS, "Processed Shape")
49 gg.createAndDisplayGO(Id_Shape)
50 gg.setDisplayMode(Id_Shape,1)
51 gg.createAndDisplayGO(Id_PS)
52 gg.setDisplayMode(Id_PS,1) 
53 \endcode
54
55 \anchor tui_suppress_faces
56 <br><h2>Suppress Faces</h2>
57
58 \code
59 import geompy
60 import salome
61 gg = salome.ImportComponentGUI("GEOM")
62
63 # create a box
64 box = geompy.MakeBoxDXDYDZ(200, 200, 200)
65
66 # The list of IDs (IDList) for suppress faces
67 sup_faces = []
68 sup_faces = geompy.SubShapeAllSorted(box, geompy.ShapeType["FACE"])
69
70 # get indices of the sub-shape
71 f1_id = geompy.GetSubShapeID(box, sup_faces[3])
72
73 # remove faces from the given object (shape)
74 result = geompy.SuppressFaces(box, [f1_id])
75
76 # add objects in the study
77 id_box = geompy.addToStudy(box, "Box")
78 id_result = geompy.addToStudy(result, "Result")
79
80 # display the results
81 gg.createAndDisplayGO(id_box)
82 gg.setDisplayMode(id_box,1)
83 gg.createAndDisplayGO(id_result)
84 gg.setDisplayMode(id_result,1)
85 \endcode
86
87 \anchor tui_close_contour
88 <br><h2>Close Contour</h2>
89
90 \code
91 import geompy
92 import salome
93 gg = salome.ImportComponentGUI("GEOM")
94
95 # create vertices and vectors
96 p0  = geompy.MakeVertex(  0.,   0.,   0.)
97 px  = geompy.MakeVertex(100.,   0.,   0.)
98 py  = geompy.MakeVertex(  0., 100.,   0.)
99 py1 = geompy.MakeVertex(  0., 140.,   0.)
100 pz  = geompy.MakeVertex(  0.,   0., 100.)
101 vxy = geompy.MakeVector(px, py)
102
103 # create an arc
104 arc = geompy.MakeArc(py1, pz, px)
105
106 # create a wire
107 wire = geompy.MakeWire([vxy, arc])
108
109 # close an open wire by creation of an edge between ends
110 wire_close = geompy.CloseContour(wire, [1], 0)
111
112 # add objects in the study
113 id_wire = geompy.addToStudy(wire, "Wire")
114 id_wire_close = geompy.addToStudy(wire_close, "Wire close")
115
116 # display the results
117 gg.createAndDisplayGO(id_wire)
118 gg.createAndDisplayGO(id_wire_close) 
119 \endcode
120
121 \anchor tui_suppress_internal_wires 
122 <br><h2>Suppress Internal Wires</h2>
123
124 \code
125 import geompy
126 import salome
127 gg = salome.ImportComponentGUI("GEOM")
128
129 # create a vertex and a vector
130 p1 = geompy.MakeVertex(55, 65, 50)
131 p2 = geompy.MakeVertex(55,  0, 50)
132 v = geompy.MakeVector(p1, p2)
133
134 # create a cylinder
135 height = 100
136 radius1 = 40
137 cylinder = geompy.MakeCylinder(p1, v, radius1, height)
138
139 # create a box
140 box = geompy.MakeBoxDXDYDZ(100, 100, 100)
141
142 # make a cut
143 cut = geompy.MakeCut(box, cylinder)
144
145 # suppress all internal wires
146 result = geompy.SuppressInternalWires(cut, [])
147
148 # add objects in the study
149 id_cut = geompy.addToStudy(cut, "Cut")
150 id_result = geompy.addToStudy(result, "Result")
151
152 # display the results
153 gg.createAndDisplayGO(id_cut)
154 gg.setDisplayMode(id_cut,1)
155 gg.createAndDisplayGO(id_result)
156 gg.setDisplayMode(id_result,1) 
157 \endcode
158
159 \anchor tui_suppress_holes
160 <br><h2>Suppress Holes</h2>
161
162 \code
163 import geompy
164 import salome
165 gg = salome.ImportComponentGUI("GEOM")
166
167 # create a vertex and a vector
168 p1 = geompy.MakeVertex(35, 35, 0)
169 p2 = geompy.MakeVertex(35, 35, 50)
170 v = geompy.MakeVector(p1, p2)
171
172 # create a cylinder
173 height = 20
174 radius1 = 20
175 cylinder = geompy.MakeCylinder(p1, v, radius1, height)
176
177 # create a cone
178 cone = geompy.MakeCone(p1, v, 70, 0, 80)
179
180 # make a cut
181 cut = geompy.MakeCut(cone, cylinder)
182
183 # get faces as sub-shapes
184 faces = []
185 faces = geompy.SubShapeAllSorted(cut, geompy.ShapeType["FACE"])
186 f_2 = geompy.GetSubShapeID(cut, faces[2])
187
188 # remove one face from the shape
189 cut_without_f_2 = geompy.SuppressFaces(cut, [f_2])
190
191 # get wires as sub-shapes
192 wires = []
193 wires = geompy.SubShapeAllSorted(cut_without_f_2, geompy.ShapeType["WIRE"])
194 w_0 = geompy.GetSubShapeID(cut_without_f_2, wires[0])
195
196 # suppress the selected wire
197 result = geompy.SuppressHoles(cut_without_f_2, [w_0])
198
199 # add objects in the study
200 id_cut = geompy.addToStudy(cut, "Cut")
201 id_cut_without_f_2 = geompy.addToStudy(cut_without_f_2, "Cut without f_2")
202 id_result = geompy.addToStudy(result, "Result")
203
204 # display the results
205 gg.createAndDisplayGO(id_cut)
206 gg.setDisplayMode(id_cut,1)
207 gg.createAndDisplayGO(id_cut_without_f_2)
208 gg.setDisplayMode(id_cut_without_f_2,1)
209 gg.createAndDisplayGO(id_result)
210 gg.setDisplayMode(id_result,1) 
211 \endcode
212
213 \anchor tui_sewing
214 <br><h2>Sewing</h2>
215
216 \code
217 import geompy
218 import salome
219 import math
220 gg = salome.ImportComponentGUI("GEOM")
221
222 # create base points
223 px = geompy.MakeVertex(100., 0., 0.)
224 py = geompy.MakeVertex(0., 100., 0.)
225 pz = geompy.MakeVertex(0., 0., 100.)
226
227 # create base geometry 2D & 3D
228 vector = geompy.MakeVector(px, py)
229 arc = geompy.MakeArc(py, pz, px)
230
231 # create base objects
232 angle = 45. * math.pi / 180
233 WantPlanarFace = 1 #True
234 wire = geompy.MakeWire([vector, arc])
235 face = geompy.MakeFace(wire, WantPlanarFace)
236 face_rot = geompy.MakeRotation(face, vector, angle)
237
238 # make sewing
239 precision = 0.00001
240 sewing = geompy.MakeSewing([face, face_rot], precision)
241
242 # add objects in the study
243 id_face = geompy.addToStudy(face, "Face")
244 id_face_rot = geompy.addToStudy(face_rot, "Face rotation")
245 id_sewing = geompy.addToStudy(sewing, "Sewing")
246
247 # display the results
248 gg.createAndDisplayGO(id_face)
249 gg.setDisplayMode(id_face,1)
250 gg.createAndDisplayGO(id_face_rot)
251 gg.setDisplayMode(id_face_rot,1)
252 gg.createAndDisplayGO(id_sewing)
253 gg.setDisplayMode(id_sewing,1) 
254 \endcode
255
256 \anchor tui_glue_faces
257 <br><h2>Glue Faces</h2>
258
259 \code
260 import geompy
261 import salome
262 gg = salome.ImportComponentGUI("GEOM")
263
264 # create boxes
265 box1 = geompy.MakeBox(0,0,0,100,50,100)
266 box2 = geompy.MakeBox(100,0,0,250,50,100)
267
268 # make compound
269 compound = geompy.MakeCompound([box1, box2])
270
271 # glue compound's faces
272 tolerance = 1e-5
273 glue = geompy.MakeGlueFaces(compound, tolerance)
274
275 # add objects in study
276 id_box1 = geompy.addToStudy(box1, "Box1")
277 id_box2 = geompy.addToStudy(box2, "Box2")
278 id_compound = geompy.addToStudy(compound, "Compound")
279 id_glue = geompy.addToStudy(glue, "Glue faces")
280
281 # display results
282 gg.createAndDisplayGO(id_box1)
283 gg.setDisplayMode(id_box1,1)
284 gg.createAndDisplayGO(id_box2)
285 gg.setDisplayMode(id_box2,1)
286 gg.createAndDisplayGO(id_compound)
287 gg.setDisplayMode(id_compound,1)
288 gg.createAndDisplayGO(id_glue)
289 gg.setDisplayMode(id_glue,1) 
290 \endcode
291
292 \anchor tui_add_point_on_edge
293 <br><h2>Add Point on Edge</h2>
294
295 \code
296 import geompy
297 import salome
298
299 # create vertices
300 p1 = geompy.MakeVertex(0,0,50)
301 p2 = geompy.MakeVertex(60,0,50)
302
303 # make an edge
304 edge = geompy.MakeEdge(p1, p2) #geompy.GetSubShape(box, edge_ind)
305
306 # divide an edge
307 divide = geompy.DivideEdge(edge, -1, 0.5, 0)
308
309 # add objects in the study
310 id_edge = geompy.addToStudy(edge, "Edge")
311 edge_points = geompy.SubShapeAllSorted(edge, geompy.ShapeType["VERTEX"])
312 for point in edge_points:
313     geompy.addToStudyInFather(edge, point, "Edge's point")
314
315 id_divide = geompy.addToStudy(divide, "Divided edge")
316 edge_points = geompy.SubShapeAllSorted(divide, geompy.ShapeType["VERTEX"])
317 for point in edge_points:
318     geompy.addToStudyInFather(divide, point, "Edge's point after divide")
319
320 salome.sg.updateObjBrowser(1) 
321 \endcode
322
323
324 */