Salome HOME
3c5bd049861f853eec4a5ec910d439b4a3a572b5
[modules/geom.git] / src / GEOM_SWIG / GEOM_example3.py
1 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 #
6 #  This library is free software; you can redistribute it and/or
7 #  modify it under the terms of the GNU Lesser General Public
8 #  License as published by the Free Software Foundation; either
9 #  version 2.1 of the License.
10 #
11 #  This library is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 #  Lesser General Public License for more details.
15 #
16 #  You should have received a copy of the GNU Lesser General Public
17 #  License along with this library; if not, write to the Free Software
18 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 #
20 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22 #  GEOM GEOM_SWIG : binding of C++ omplementaion with Python
23 #  File   : GEOM_example3.py
24 #  Author : Paul RASCLE, EDF
25 #  Module : GEOM
26 #  $Header$
27 #
28 import salome
29 import geompy
30 import math
31 from time import sleep
32 import salome_ComponentGUI
33 geom = salome.lcc.FindOrLoadComponent("FactoryServer", "GEOM")
34 myBuilder = salome.myStudy.NewBuilder()
35
36 gg = salome.ImportComponentGUI("GEOM")
37
38 BasicOp  = geom.GetIBasicOperations(salome.myStudyId)
39 PrimOp   = geom.GetI3DPrimOperations(salome.myStudyId)
40 InsertOp = geom.GetIInsertOperations(salome.myStudyId)
41 TrsfOp   = geom.GetITransformOperations(salome.myStudyId)
42
43 point0  = BasicOp.MakePointXYZ(0.,0.,0.)
44 pointz1 = BasicOp.MakePointXYZ(0.,0.,1.)
45 dirz = BasicOp.MakeVectorTwoPnt(point0,pointz1)
46
47 torus1 = PrimOp.MakeTorusPntVecRR(point0,dirz,150.,25.)
48 id_torus1 = geompy.addToStudy(torus1,"torus1")
49 if not isinstance(gg, type(salome_ComponentGUI)):
50     gg.createAndDisplayGO(id_torus1)
51
52 torus2 = InsertOp.MakeCopy(torus1)
53
54 vec1 = BasicOp.MakeVectorDXDYDZ(0.,0.,100.)
55 torus2 = TrsfOp.TranslateVectorCopy(torus2,vec1)
56 id_torus2 = geompy.addToStudy(torus2,"torus2")
57 if not isinstance(gg, type(salome_ComponentGUI)):
58     gg.createAndDisplayGO(id_torus2)
59
60 cylz1 = PrimOp.MakeCylinderPntVecRH(point0,dirz,25.,100.)
61
62 ind = 0
63 shapeList = []
64 idList = []
65 while ind < 6:
66     acyl = InsertOp.MakeCopy(cylz1)
67     x = 150. * math.cos(ind * math.pi/3.)
68     y = 150. * math.sin(ind * math.pi/3.)
69     z = 0.
70     vec_i = BasicOp.MakeVectorDXDYDZ(x,y,z)
71     name = "cyl%d"%(ind)
72     acyl = TrsfOp.TranslateVectorCopy(acyl,vec_i)
73     id_acyl = geompy.addToStudy(acyl,name)
74     if not isinstance(gg, type(salome_ComponentGUI)):
75         gg.createAndDisplayGO(id_acyl)
76     shapeList.append(acyl)
77     idList.append(id_acyl)
78     ind = ind +1
79
80 shapeList.append(torus1)
81 shapeList.append(torus2)
82 idList.append(id_torus1)
83 idList.append(id_torus2)
84
85 cage = geompy.MakeCompound(shapeList)
86 id_cage = geompy.addToStudy(cage,"cage")
87 if not isinstance(gg, type(salome_ComponentGUI)):
88     gg.createAndDisplayGO(id_cage)
89
90 from salome import sg
91 sleep(1)
92 sg.EraseAll()
93 for id in idList:
94     sg.DisplayOnly(id)
95     sleep(1)
96 sg.EraseAll()
97 for id in idList:
98     sg.Display(id)
99     sleep(1)
100 for id in idList:
101     sg.Erase(id)
102     sleep(1)
103
104 #sg.Display(id_cage)
105 sg.Display(id_torus1)
106 sg.Display(id_torus2)
107 sg.Display(id_acyl)
108 if not isinstance(gg, type(salome_ComponentGUI)):
109     gg.setTransparency(id_torus1,0.5)
110     
111     gg.setDisplayMode(id_torus1,1)
112     gg.setDisplayMode(id_torus2,1)
113     gg.setDisplayMode(id_acyl,1)
114     #gg.setDisplayMode(id_cage,1)
115     
116     gg.setColor(id_torus1,0,0,255)
117     gg.setColor(id_torus2,255,0,0)
118     gg.setColor(id_acyl,0,255,0)
119     #gg.setColor(id_cage,255,255,0)