Salome HOME
PR: synchro V6_main tag mergeto_V7_main_11Feb13
[modules/geom.git] / doc / salome / examples / basic_operations_ex03.py
1 # Restore presentation parameters and sub-shapes
2
3 import geompy
4 import GEOM
5 import SALOMEDS
6
7 # create a box and a cylinder
8 box = geompy.MakeBoxDXDYDZ(200, 200, 200)
9 cyl = geompy.MakeCylinderRH(100, 300)
10
11 # create translated box
12 vec = geompy.MakeVectorDXDYDZ(100, 50, 0)
13 tra = geompy.MakeTranslationVector(box, vec)
14
15 # create partition objects
16 partition1 = geompy.MakePartition([box, cyl])
17 partition2 = geompy.MakePartition([box], [cyl])
18 partition3 = geompy.MakePartition([box], [tra])
19
20 # set colours
21 box.SetColor(SALOMEDS.Color(1,0,0))
22 cyl.SetColor(SALOMEDS.Color(0,1,0))
23
24 # add objects in the study
25 geompy.addToStudy(box, "Box")
26 geompy.addToStudy(cyl, "Cylinder")
27 geompy.addToStudy(vec, "Vector")
28 geompy.addToStudy(tra, "Translation")
29 geompy.addToStudy(partition1, "Partition_1")
30 geompy.addToStudy(partition2, "Partition_2")
31 geompy.addToStudy(partition3, "Partition_3")
32
33 # Restore presentation parameters and sub-shapes
34 # different methods can be used to find the sub-shapes in the result:
35 # GetInPlace, GetSame, GetInPlaceByHistory, GetShapesOnShape.
36 # By default, GetInPlace method is used (GEOM.FSM_GetInPlace)
37 geompy.RestoreSubShapes(partition1)
38
39 geompy.RestoreSubShapes(partition2, [], GEOM.FSM_GetInPlace)
40
41 # The list of arguments can be used to avoid restoring all arguments,
42 # but restore only the passed.
43 geompy.RestoreSubShapes(partition3, [tra], GEOM.FSM_GetInPlaceByHistory)
44
45 # To find sub-shapes in a transformed shape only one method could be
46 # used: pass GEOM.FSM_Transformed for that.
47 # True passed for the last argument, means that the transformed shape
48 # will inherit colour and sub-shapes from its first argument (see above
49 # MakeTranslation).
50 geompy.RestoreSubShapes(tra, [], GEOM.FSM_Transformed, True)
51
52 # Also we could do this directly with method addToStudy:
53 partition4 = geompy.MakePartition([box, tra])
54 geompy.addToStudy(partition4, "Partition_4", True, [],
55                   GEOM.FSM_GetInPlaceByHistory, False)