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