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