Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/geom.git] / doc / salome / gui / GEOM / input / tui_transformation_operations.doc
1 /*!
2
3 \page tui_transformation_operations_page Transformation Operations
4
5 \anchor tui_translation
6 <br><h2>Translation</h2>
7
8 \code
9 import geompy
10 import salome
11 gg = salome.ImportComponentGUI("GEOM")
12
13 # create a vertex and a vector
14 p1 = geompy.MakeVertex(10, 40, 0)
15 p2 = geompy.MakeVertex( 0,  0, 50)
16 p3 = geompy.MakeVertex(50, 80, 0)
17 v = geompy.MakeVector(p1, p2)
18 vt = geompy.MakeVector(p1, p3)
19
20 # create a cylinder
21 height = 35
22 radius1 = 20
23 cylinder = geompy.MakeCylinder(p1, v, radius1, height)
24
25 # translate the given object along the vector, specified by its end points
26 # (all three functions produce the same result)
27 translation1 = geompy.MakeTranslationTwoPoints(cylinder, p1, p3)
28 translation2 = geompy.MakeTranslation(cylinder, 40, 40, 0)
29 translation3 = geompy.MakeTranslationVector(cylinder, vt)
30
31 # add objects in the study
32 id_cylinder = geompy.addToStudy(cylinder, "Cylinder")
33 id_translation1 = geompy.addToStudy(translation1, "Translation1")
34 id_translation2 = geompy.addToStudy(translation2, "Translation2")
35 id_translation3 = geompy.addToStudy(translation3, "Translation3")
36
37 # display the results
38 gg.createAndDisplayGO(id_cylinder)
39 gg.setDisplayMode(id_cylinder,1)
40 gg.createAndDisplayGO(id_translation1)
41 gg.setDisplayMode(id_translation1,1)
42 gg.createAndDisplayGO(id_translation2)
43 gg.setDisplayMode(id_translation2,1)
44 gg.createAndDisplayGO(id_translation3)
45 gg.setDisplayMode(id_translation3,1) 
46 \endcode
47
48 \anchor tui_rotation
49 <br><h2>Rotation</h2>
50
51 \code
52 import geompy
53 import salome
54 import math
55 gg = salome.ImportComponentGUI("GEOM")
56
57 # create a vertex and a vector
58 p1 = geompy.MakeVertex(10, 40,  0)
59 p2 = geompy.MakeVertex( 0,  0, 50)
60 p3 = geompy.MakeVertex(10, 50,-20)
61 p4 = geompy.MakeVertex(10, 50, 60)
62 v = geompy.MakeVector(p1, p2)
63 vr = geompy.MakeVector(p3, p4)
64
65 # create a cylinder
66 height = 35
67 radius1 = 20
68 cylinder = geompy.MakeCylinder(p1, v, radius1, height)
69
70 # rotate the given object around the given axis by the given angle
71 rotation1 = geompy.MakeRotation(cylinder, vr, math.pi)
72 rotation2 = geompy.MakeRotationThreePoints(cylinder, p4, p1, p2)
73
74 # add objects in the study
75 id_vr = geompy.addToStudy(vr, "Rotation 1 axis")
76 id_p4 = geompy.addToStudy(p4, "Rotation 2 center")
77 id_p1 = geompy.addToStudy(p1, "Rotation 2 point 1")
78 id_p2 = geompy.addToStudy(p2, "Rotation 2 point 2")
79 id_cylinder = geompy.addToStudy(cylinder, "Cylinder")
80 id_rotation1 = geompy.addToStudy(rotation1, "Rotation 1")
81 id_rotation2 = geompy.addToStudy(rotation2, "Rotation 2")
82
83 # display the results
84 gg.createAndDisplayGO(id_vr)
85 gg.createAndDisplayGO(id_p4)
86 gg.createAndDisplayGO(id_p1)
87 gg.createAndDisplayGO(id_p2)
88 gg.createAndDisplayGO(id_cylinder)
89 gg.setDisplayMode(id_cylinder,1)
90 gg.createAndDisplayGO(id_rotation1)
91 gg.createAndDisplayGO(id_rotation2)
92 gg.setDisplayMode(id_rotation1,1)
93 gg.setDisplayMode(id_rotation2,1)
94 \endcode
95
96 \anchor tui_modify_location 
97 <br><h2>Modify Location</h2>
98
99 \code
100 import geompy
101 import salome
102 import math
103 gg = salome.ImportComponentGUI("GEOM")
104
105 # create a vertex and a vector
106 p1 = geompy.MakeVertex(10, 40, 0)
107 p2 = geompy.MakeVertex( 0,  0, 50)
108 v = geompy.MakeVector(p1, p2)
109
110 # create a cylinder
111 height = 35
112 radius1 = 20
113 cylinder = geompy.MakeCylinder(p1, v, radius1, height)
114
115 # create local coordinate systems
116 cs1 = geompy.MakeMarker( 0, 0, 0, 1,0,0, 0,1,0)
117 cs2 = geompy.MakeMarker(30,40,40, 1,0,0, 0,1,0)
118
119 # modify the location of the given object
120 position = geompy.MakePosition(cylinder, cs1, cs2)
121
122 # add objects in the study
123 id_cs1 = geompy.addToStudy(cs1, "Coordinate system 1")
124 id_cs2 = geompy.addToStudy(cs2, "Coordinate system 2")
125 id_cylinder = geompy.addToStudy(cylinder, "Cylinder")
126 id_position = geompy.addToStudy(position, "Position")
127
128 # display the results
129 gg.createAndDisplayGO(id_cylinder)
130 gg.setDisplayMode(id_cylinder,1)
131 gg.createAndDisplayGO(id_position)
132 gg.setDisplayMode(id_position,1)
133 \endcode
134
135 \anchor tui_mirror
136 <br><h2>Mirror Image</h2>
137
138 \code
139 import geompy
140 import salome
141 gg = salome.ImportComponentGUI("GEOM")
142
143 # create a box
144 box = geompy.MakeBoxDXDYDZ(200, 200, 200)
145
146 # create an object, symmetrical to another object through the given plane
147 p1 = geompy.MakeVertex( 0, 25,  0)
148 p2 = geompy.MakeVertex( 5, 25,  0)
149 p3 = geompy.MakeVertex( 0,-30, 40)
150 plane = geompy.MakePlaneThreePnt(p1, p2, p3, 1000.)
151 mirror1 = geompy.MakeMirrorByPlane(box, plane)
152
153 # create an object, symmetrical to another object through the given axis
154 p4 = geompy.MakeVertex( 210, 210, -20)
155 p5 = geompy.MakeVertex( 210, 210, 220)
156 axis = geompy.MakeVector(p4, p5)
157 mirror2 = geompy.MakeMirrorByAxis(box, axis)
158
159 # create an object, symmetrical to another object through the given point
160 mirror3 = geompy.MakeMirrorByPoint(box, p4)
161
162 # add objects in the study
163 id_box = geompy.addToStudy(box, "Box")
164 id_plane = geompy.addToStudy(plane, "Plane")
165 id_mirror1 = geompy.addToStudy(mirror1, "Mirror plane")
166 id_axis = geompy.addToStudy(axis, "Axis")
167 id_mirror2 = geompy.addToStudy(mirror2, "Mirror axis")
168 id_p4 = geompy.addToStudy(p4, "Point")
169 id_mirror3 = geompy.addToStudy(mirror3, "Mirror point")
170
171 # display the results
172 gg.createAndDisplayGO(id_box)
173 gg.setDisplayMode(id_box,1)
174 gg.createAndDisplayGO(id_plane)
175 gg.createAndDisplayGO(id_mirror1)
176 gg.setDisplayMode(id_mirror1,1)
177 gg.createAndDisplayGO(id_axis)
178 gg.createAndDisplayGO(id_mirror2)
179 gg.setDisplayMode(id_mirror2,1)
180 gg.createAndDisplayGO(id_p4)
181 gg.createAndDisplayGO(id_mirror3)
182 gg.setDisplayMode(id_mirror3,1) 
183 \endcode
184
185 \anchor tui_scale
186 <br><h2>Scale Transform</h2>
187
188 \code
189 import geompy
190 import salome
191 gg = salome.ImportComponentGUI("GEOM")
192
193 # create a box and a sphere
194 box = geompy.MakeBoxDXDYDZ(200, 200, 200)
195
196 # scale the given object by the factor
197 p0 = geompy.MakeVertex(100, 100, 100)
198 factor = 0.5
199 scale = geompy.MakeScaleTransform(box, p0, factor)
200
201 # add objects in the study
202 id_box = geompy.addToStudy(box, "Box")
203 id_scale = geompy.addToStudy(scale, "Scale")
204
205 # display the results
206 gg.createAndDisplayGO(id_box)
207 gg.setDisplayMode(id_box,1)
208 gg.setTransparency(id_box,0.5)
209 gg.createAndDisplayGO(id_scale)
210 gg.setDisplayMode(id_scale,1)
211 \endcode
212
213 \anchor tui_offset 
214 <br><h2>Offset Surface</h2>
215
216 \code
217 import geompy
218 import salome
219 gg = salome.ImportComponentGUI("GEOM")
220
221 # create a box and a sphere
222 box = geompy.MakeBox(20, 20, 20, 200, 200, 200)
223
224 # create a new object as offset of the given object
225 offset = geompy.MakeOffset(box, 70.)
226
227 # add objects in the study
228 id_box = geompy.addToStudy(box, "Box")
229 id_offset = geompy.addToStudy(offset, "Offset")
230
231 # display the results
232 gg.createAndDisplayGO(id_box)
233 gg.setDisplayMode(id_box,1)
234 gg.createAndDisplayGO(id_offset) 
235 \endcode
236
237 \anchor tui_multi_translation 
238 <br><h2>Multi Translation</h2>
239
240 \code
241 import geompy
242 import salome
243 gg = salome.ImportComponentGUI("GEOM")
244
245 # create vertices and vectors
246 p0  = geompy.MakeVertex( 0.,  0.,  0.)
247 px  = geompy.MakeVertex(20.,  0.,  0.)
248 py  = geompy.MakeVertex( 0., 20.,  0.)
249 pz  = geompy.MakeVertex( 0.,  0., 20.)
250 pxy = geompy.MakeVertex( 50., 0., 0.)
251 pxyz = geompy.MakeVertex( 50., 50., 50.)
252 vz  = geompy.MakeVector(p0, pz)
253 vxy = geompy.MakeVector(px, py)
254 vtr1d = geompy.MakeVector(p0, pxyz)
255 vtr2d = geompy.MakeVector(p0, pxy)
256
257 # create an arc
258 arc = geompy.MakeArc(py, pz, px)
259
260 # create a wire
261 wire = geompy.MakeWire([vxy, arc])
262
263 # create a planar face
264 face = geompy.MakeFace(wire, 1)
265
266 # create a prism
267 prism = geompy.MakePrismVecH(face, vz, 20.0)
268
269 # translate the given object along the given vector a given number of times
270 tr1d = geompy.MakeMultiTranslation1D(prism, vtr1d, 20, 4)
271
272 # consequently apply two specified translations to the object a given number of times
273 tr2d = geompy.MakeMultiTranslation2D(prism, vtr1d, 20, 4, vtr2d, 80, 3)
274
275 # add objects in the study
276 id_prism = geompy.addToStudy(prism,"Prism")
277 id_tr1d = geompy.addToStudy(tr1d,"Translation 1D")
278 id_tr2d = geompy.addToStudy(tr2d,"Translation 2D")
279
280 # display the prism and the results of fillet operation
281 gg.createAndDisplayGO(id_prism)
282 gg.setDisplayMode(id_prism,1)
283 gg.createAndDisplayGO(id_tr1d)
284 gg.setDisplayMode(id_tr1d,1)
285 gg.createAndDisplayGO(id_tr2d)
286 gg.setDisplayMode(id_tr2d,1) 
287 \endcode
288
289 \anchor tui_multi_rotation
290 <br><h2>Multi Rotation</h2>
291
292 \code
293 import geompy
294 import salome
295 gg = salome.ImportComponentGUI("GEOM")
296
297 # create vertices and vectors
298 p0  = geompy.MakeVertex( 0.,  0.,  0.)
299 px  = geompy.MakeVertex(20.,  0.,  0.)
300 py  = geompy.MakeVertex( 0., 20.,  0.)
301 pz  = geompy.MakeVertex( 0.,  0., 20.)
302 pxyz = geompy.MakeVertex( 50., 50., 10.)
303 vz  = geompy.MakeVector(p0, pz)
304 vxy = geompy.MakeVector(px, py)
305 vrot1d = geompy.MakeVector(p0, pxyz)
306
307 # create an arc
308 arc = geompy.MakeArc(py, pz, px)
309
310 # create a wire
311 wire = geompy.MakeWire([vxy, arc])
312
313 # create a planar face
314 face = geompy.MakeFace(wire, 1)
315
316 # create a prism
317 prism = geompy.MakePrismVecH(face, vz, 20.0)
318
319 # rotate the given object around the given axis by the given angle a given number of times
320 rot1d = geompy.MultiRotate1D(prism, vrot1d, 4)
321
322 # rotate the given object around the given axis by the given angle a given number of times
323 # and multi-translate the result of each rotation
324 rot2d = geompy.MultiRotate2D(prism, vrot1d, 60, 4, 50, 5)
325
326 # add objects in the study
327 id_prism = geompy.addToStudy(prism,"Prism")
328 id_rot1d = geompy.addToStudy(rot1d,"Rotation 1D")
329 id_rot2d = geompy.addToStudy(rot2d,"Rotation 2D")
330
331 # display the prism and the results of fillet operation
332 gg.createAndDisplayGO(id_prism)
333 gg.setDisplayMode(id_prism,1)
334 gg.createAndDisplayGO(id_rot1d)
335 gg.setDisplayMode(id_rot1d,1)
336 gg.createAndDisplayGO(id_rot2d)
337 gg.setDisplayMode(id_rot2d,1) 
338 \endcode
339
340 \anchor tui_fillet
341 <br><h2>Fillet</h2>
342
343 \code
344 import geompy
345 import salome
346 gg = salome.ImportComponentGUI("GEOM")
347 radius  = 10.
348 ShapeTypeEdge = geompy.ShapeType["EDGE"]
349
350 # create vertices and vectors
351 p0  = geompy.MakeVertex(  0.,   0.,   0.)
352 px  = geompy.MakeVertex(100.,   0.,   0.)
353 py  = geompy.MakeVertex(  0., 100.,   0.)
354 pz  = geompy.MakeVertex(  0.,   0., 100.)
355 vz  = geompy.MakeVector(p0, pz)
356 vxy = geompy.MakeVector(px, py)
357
358 # create an arc
359 arc = geompy.MakeArc(py, pz, px)
360
361 # create a wire
362 wire = geompy.MakeWire([vxy, arc])
363
364 # create a planar face
365 face = geompy.MakeFace(wire, 1)
366
367 # create a prism
368 prism = geompy.MakePrismVecH(face, vz, 100.0)
369
370 # get the list of IDs (IDList) for the fillet
371 prism_edges = geompy.SubShapeAllSorted(prism, ShapeTypeEdge)
372 IDlist_e = []
373 IDlist_e.append(geompy.GetSubShapeID(prism, prism_edges[0]))
374 IDlist_e.append(geompy.GetSubShapeID(prism, prism_edges[1]))
375 IDlist_e.append(geompy.GetSubShapeID(prism, prism_edges[2]))
376
377 # make a fillet on the specified edges of the given shape
378 fillet = geompy.MakeFillet(prism, radius, ShapeTypeEdge, IDlist_e)
379
380 # make a fillet on all edges of the given shape
381 filletall = geompy.MakeFilletAll(prism, radius)
382
383 # add objects in the study
384 id_prism = geompy.addToStudy(prism,"Prism")
385 id_fillet = geompy.addToStudy(fillet,"Fillet")
386 id_filletall = geompy.addToStudy(filletall,"Fillet all")
387
388 # display the prism and the results of fillet operation
389 gg.createAndDisplayGO(id_prism)
390 gg.setDisplayMode(id_prism,1)
391 gg.createAndDisplayGO(id_fillet)
392 gg.setDisplayMode(id_fillet,1)
393 gg.createAndDisplayGO(id_filletall)
394 gg.setDisplayMode(id_filletall,1) 
395 \endcode
396
397 \anchor tui_chamfer
398 <br><h2>Chamfer</h2>
399
400 \code
401 import geompy
402 import salome
403 gg = salome.ImportComponentGUI("GEOM")
404 d1 = 10.
405 d2 = 10.
406 ShapeTypeFace = geompy.ShapeType["FACE"]
407
408 # create vertices and vectors
409 p0  = geompy.MakeVertex(  0.,   0.,   0.)
410 px  = geompy.MakeVertex(100.,   0.,   0.)
411 py  = geompy.MakeVertex(  0., 100.,   0.)
412 pz  = geompy.MakeVertex(  0.,   0., 100.)
413 vz  = geompy.MakeVector(p0, pz)
414 vxy = geompy.MakeVector(px, py)
415
416 # create an arc
417 arc = geompy.MakeArc(py, pz, px)
418
419 # create a wire
420 wire = geompy.MakeWire([vxy, arc])
421
422 # create a planar face
423 face = geompy.MakeFace(wire, 1)
424
425 # create a prism
426 prism = geompy.MakePrismVecH(face, vz, 100.0)
427
428 # get the list of IDs (IDList) for the chamfer
429 prism_faces = geompy.SubShapeAllSorted(prism, ShapeTypeFace)
430 f_ind_1 = geompy.GetSubShapeID(prism, prism_faces[0])
431 f_ind_2 = geompy.GetSubShapeID(prism, prism_faces[1])
432 IDlist_f = [f_ind_1, f_ind_2]
433
434 # perform a chamfer on the edges common to the specified faces
435 chamfer_e = geompy.MakeChamferEdge(prism, d1, d2, f_ind_1, f_ind_2)
436
437 # perform a chamfer on all edges of the specified faces
438 chamfer_f = geompy.MakeChamferFaces(prism, d1, d2, IDlist_f)
439 chamfer_f1 = geompy.MakeChamfer(prism, d1, d2, ShapeTypeFace, IDlist_f)
440
441 # perform a symmetric chamfer on all edges of the given shape
442 chamfer_all = geompy.MakeChamferAll(prism, d1)
443
444 # add objects in the study
445 id_prism = geompy.addToStudy(prism,"Prism")
446 id_chamfer_e = geompy.addToStudy(chamfer_e,"Chamfer edge")
447 id_chamfer_f = geompy.addToStudy(chamfer_f,"Chamfer faces")
448 id_chamfer_f1 = geompy.addToStudy(chamfer_f1,"Chamfer faces 1")
449 id_chamfer_all = geompy.addToStudy(chamfer_all,"Chamfer all")
450
451 # display the prism and the results of chamfer operation
452 gg.createAndDisplayGO(id_prism)
453 gg.setDisplayMode(id_prism,1)
454 gg.createAndDisplayGO(id_chamfer_e)
455 gg.setDisplayMode(id_chamfer_e,1)
456 gg.createAndDisplayGO(id_chamfer_f)
457 gg.setDisplayMode(id_chamfer_f,1)
458 gg.createAndDisplayGO(id_chamfer_f1)
459 gg.setDisplayMode(id_chamfer_f1,1)
460 gg.createAndDisplayGO(id_chamfer_all)
461 gg.setDisplayMode(id_chamfer_all,1) 
462 \endcode
463
464 */