Salome HOME
Mantis issue 0021703: [CEA 577] Boolean operations on groups.
[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_projection
250 <br><h2>Projection</h2>
251
252 \code
253 import geompy
254 import salome
255
256 # create a cylindric face and a curve(edge)
257 cylinder = geompy.MakeCylinderRH(100, 300)
258 [face_cyl] = geompy.SubShapes(cylinder, [3])
259
260 p1 = geompy.MakeVertex(200, 0, 100)
261 p2 = geompy.MakeVertex(200, 80, 100)
262 p3 = geompy.MakeVertex(200, 80, 180)
263 p4 = geompy.MakeVertex(130, 80, 180)
264 p5 = geompy.MakeVertex(90, 80, 240)
265
266 curve = geompy.MakeInterpol([p1, p2, p3, p4, p5], False, False)
267
268 # create a new object as projection of the
269 # given curve on the given cylindric face
270 projection = geompy.MakeProjection(curve, face_cyl)
271
272 # add objects in the study
273 geompy.addToStudy(cylinder, "cylinder")
274 geompy.addToStudyInFather(cylinder, face_cyl, "face_cyl")
275 geompy.addToStudy(p1, "p1")
276 geompy.addToStudy(p2, "p2")
277 geompy.addToStudy(p3, "p3")
278 geompy.addToStudy(p4, "p4")
279 geompy.addToStudy(p5, "p5")
280 geompy.addToStudy(curve, "curve")
281 geompy.addToStudy(projection, "projection")
282 \endcode
283
284 \anchor tui_multi_translation 
285 <br><h2>Multi Translation</h2>
286
287 \code
288 import geompy
289 import salome
290 gg = salome.ImportComponentGUI("GEOM")
291
292 # create vertices and vectors
293 p0  = geompy.MakeVertex( 0.,  0.,  0.)
294 px  = geompy.MakeVertex(20.,  0.,  0.)
295 py  = geompy.MakeVertex( 0., 20.,  0.)
296 pz  = geompy.MakeVertex( 0.,  0., 20.)
297 pxy = geompy.MakeVertex( 50., 0., 0.)
298 pxyz = geompy.MakeVertex( 50., 50., 50.)
299 vz  = geompy.MakeVector(p0, pz)
300 vxy = geompy.MakeVector(px, py)
301 vtr1d = geompy.MakeVector(p0, pxyz)
302 vtr2d = geompy.MakeVector(p0, pxy)
303
304 # create an arc
305 arc = geompy.MakeArc(py, pz, px)
306
307 # create a wire
308 wire = geompy.MakeWire([vxy, arc])
309
310 # create a planar face
311 face = geompy.MakeFace(wire, 1)
312
313 # create a prism
314 prism = geompy.MakePrismVecH(face, vz, 20.0)
315
316 # translate the given object along the given vector a given number of times
317 tr1d = geompy.MakeMultiTranslation1D(prism, vtr1d, 20, 4)
318
319 # consequently apply two specified translations to the object a given number of times
320 tr2d = geompy.MakeMultiTranslation2D(prism, vtr1d, 20, 4, vtr2d, 80, 3)
321
322 # add objects in the study
323 id_prism = geompy.addToStudy(prism,"Prism")
324 id_tr1d = geompy.addToStudy(tr1d,"Translation 1D")
325 id_tr2d = geompy.addToStudy(tr2d,"Translation 2D")
326
327 # display the prism and the results of fillet operation
328 gg.createAndDisplayGO(id_prism)
329 gg.setDisplayMode(id_prism,1)
330 gg.createAndDisplayGO(id_tr1d)
331 gg.setDisplayMode(id_tr1d,1)
332 gg.createAndDisplayGO(id_tr2d)
333 gg.setDisplayMode(id_tr2d,1) 
334 \endcode
335
336 \anchor tui_multi_rotation
337 <br><h2>Multi Rotation</h2>
338
339 \code
340 import geompy
341 import salome
342 gg = salome.ImportComponentGUI("GEOM")
343
344 # create vertices and vectors
345 p0  = geompy.MakeVertex( 0.,  0.,  0.)
346 px  = geompy.MakeVertex(20.,  0.,  0.)
347 py  = geompy.MakeVertex( 0., 20.,  0.)
348 pz  = geompy.MakeVertex( 0.,  0., 20.)
349 pxyz = geompy.MakeVertex( 50., 50., 10.)
350 vz  = geompy.MakeVector(p0, pz)
351 vxy = geompy.MakeVector(px, py)
352 vrot1d = geompy.MakeVector(p0, pxyz)
353
354 # create an arc
355 arc = geompy.MakeArc(py, pz, px)
356
357 # create a wire
358 wire = geompy.MakeWire([vxy, arc])
359
360 # create a planar face
361 face = geompy.MakeFace(wire, 1)
362
363 # create a prism
364 prism = geompy.MakePrismVecH(face, vz, 20.0)
365
366 # rotate the given object around the given axis by the given angle a given number of times
367 rot1d = geompy.MultiRotate1D(prism, vrot1d, 4)
368
369 # rotate the given object around the given axis by the given angle a given number of times
370 # and multi-translate the result of each rotation
371 rot2d = geompy.MultiRotate2D(prism, vrot1d, 60, 4, 50, 5)
372
373 # add objects in the study
374 id_prism = geompy.addToStudy(prism,"Prism")
375 id_rot1d = geompy.addToStudy(rot1d,"Rotation 1D")
376 id_rot2d = geompy.addToStudy(rot2d,"Rotation 2D")
377
378 # display the prism and the results of fillet operation
379 gg.createAndDisplayGO(id_prism)
380 gg.setDisplayMode(id_prism,1)
381 gg.createAndDisplayGO(id_rot1d)
382 gg.setDisplayMode(id_rot1d,1)
383 gg.createAndDisplayGO(id_rot2d)
384 gg.setDisplayMode(id_rot2d,1) 
385 \endcode
386
387 \anchor tui_fillet2d
388 <br><h2>Fillet 2D</h2>
389
390 \code
391 import geompy
392 import salome
393 gg = salome.ImportComponentGUI("GEOM")
394
395 # create a face in OXY plane
396 face = geompy.MakeFaceHW(100, 100, 1)
397 fillet2d = geompy.MakeFillet2D(face, 30, [7, 9])
398
399 # add objects in the study
400 id_face  = geompy.addToStudy(face,"Face_1")
401 id_fillet2d  = geompy.addToStudy(fillet2d,"Fillet 2D_1")
402
403 # display disks
404 gg.createAndDisplayGO(id_face)
405 gg.createAndDisplayGO(id_fillet2d)
406 \endcode
407
408 \anchor tui_fillet1d
409 <br><h2>Fillet 1D</h2>
410
411 \code
412 import geompy
413 import salome
414 gg = salome.ImportComponentGUI("GEOM")
415
416 # create box
417 Box_1 = geompy.MakeBoxDXDYDZ(200, 200, 200)
418 # take box edges to create custom complex wire
419 [Edge_1,Edge_2,Edge_3,Edge_4,Edge_5,Edge_6,Edge_7,Edge_8,Edge_9,Edge_10,Edge_11,Edge_12] = geompy.SubShapeAllSortedCentres(Box_1, geompy.ShapeType["EDGE"])
420 # create wire
421 Wire_1 = geompy.MakeWire([Edge_12, Edge_7, Edge_11, Edge_6, Edge_1,Edge_4])
422 # make fillet at given wire vertices with giver radius
423 Fillet_1D_1 = geompy.MakeFillet1D(Wire_1, 55, [3, 4, 6, 8, 10])
424
425
426 # display disks
427 gg.createAndDisplayGO(Wire_1)
428 gg.createAndDisplayGO(Fillet_1D_1)
429 \endcode
430
431 \anchor tui_fillet
432 <br><h2>Fillet</h2>
433
434 \code
435 import geompy
436 import salome
437 gg = salome.ImportComponentGUI("GEOM")
438 radius  = 10.
439 ShapeTypeEdge = geompy.ShapeType["EDGE"]
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 fillet
462 prism_edges = geompy.SubShapeAllSortedCentres(prism, ShapeTypeEdge)
463 IDlist_e = []
464 IDlist_e.append(geompy.GetSubShapeID(prism, prism_edges[0]))
465 IDlist_e.append(geompy.GetSubShapeID(prism, prism_edges[1]))
466 IDlist_e.append(geompy.GetSubShapeID(prism, prism_edges[2]))
467
468 # make a fillet on the specified edges of the given shape
469 fillet = geompy.MakeFillet(prism, radius, ShapeTypeEdge, IDlist_e)
470
471 # make a fillet on all edges of the given shape
472 filletall = geompy.MakeFilletAll(prism, radius)
473
474 # add objects in the study
475 id_prism = geompy.addToStudy(prism,"Prism")
476 id_fillet = geompy.addToStudy(fillet,"Fillet")
477 id_filletall = geompy.addToStudy(filletall,"Fillet all")
478
479 # display the prism and the results of fillet operation
480 gg.createAndDisplayGO(id_prism)
481 gg.setDisplayMode(id_prism,1)
482 gg.createAndDisplayGO(id_fillet)
483 gg.setDisplayMode(id_fillet,1)
484 gg.createAndDisplayGO(id_filletall)
485 gg.setDisplayMode(id_filletall,1) 
486 \endcode
487
488 \anchor tui_chamfer
489 <br><h2>Chamfer</h2>
490
491 \code
492 import geompy
493 import salome
494 gg = salome.ImportComponentGUI("GEOM")
495 d1 = 10.
496 d2 = 10.
497 ShapeTypeFace = geompy.ShapeType["FACE"]
498
499 # create vertices and vectors
500 p0  = geompy.MakeVertex(  0.,   0.,   0.)
501 px  = geompy.MakeVertex(100.,   0.,   0.)
502 py  = geompy.MakeVertex(  0., 100.,   0.)
503 pz  = geompy.MakeVertex(  0.,   0., 100.)
504 vz  = geompy.MakeVector(p0, pz)
505 vxy = geompy.MakeVector(px, py)
506
507 # create an arc
508 arc = geompy.MakeArc(py, pz, px)
509
510 # create a wire
511 wire = geompy.MakeWire([vxy, arc])
512
513 # create a planar face
514 face = geompy.MakeFace(wire, 1)
515
516 # create a prism
517 prism = geompy.MakePrismVecH(face, vz, 100.0)
518
519 # get the list of IDs (IDList) for the chamfer
520 prism_faces = geompy.SubShapeAllSortedCentres(prism, ShapeTypeFace)
521 f_ind_1 = geompy.GetSubShapeID(prism, prism_faces[0])
522 f_ind_2 = geompy.GetSubShapeID(prism, prism_faces[1])
523 IDlist_f = [f_ind_1, f_ind_2]
524
525 # perform a chamfer on the edges common to the specified faces
526 chamfer_e = geompy.MakeChamferEdge(prism, d1, d2, f_ind_1, f_ind_2)
527
528 # perform a chamfer on all edges of the specified faces
529 chamfer_f = geompy.MakeChamferFaces(prism, d1, d2, IDlist_f)
530 chamfer_f1 = geompy.MakeChamfer(prism, d1, d2, ShapeTypeFace, IDlist_f)
531
532 # perform a symmetric chamfer on all edges of the given shape
533 chamfer_all = geompy.MakeChamferAll(prism, d1)
534
535 # add objects in the study
536 id_prism = geompy.addToStudy(prism,"Prism")
537 id_chamfer_e = geompy.addToStudy(chamfer_e,"Chamfer edge")
538 id_chamfer_f = geompy.addToStudy(chamfer_f,"Chamfer faces")
539 id_chamfer_f1 = geompy.addToStudy(chamfer_f1,"Chamfer faces 1")
540 id_chamfer_all = geompy.addToStudy(chamfer_all,"Chamfer all")
541
542 # display the prism and the results of chamfer operation
543 gg.createAndDisplayGO(id_prism)
544 gg.setDisplayMode(id_prism,1)
545 gg.createAndDisplayGO(id_chamfer_e)
546 gg.setDisplayMode(id_chamfer_e,1)
547 gg.createAndDisplayGO(id_chamfer_f)
548 gg.setDisplayMode(id_chamfer_f,1)
549 gg.createAndDisplayGO(id_chamfer_f1)
550 gg.setDisplayMode(id_chamfer_f1,1)
551 gg.createAndDisplayGO(id_chamfer_all)
552 gg.setDisplayMode(id_chamfer_all,1) 
553 \endcode
554
555 */