Salome HOME
e98ecd11d51928ed037a78931fb29543807d2644
[modules/geom.git] / src / GEOM_SWIG / GEOM_example3.py
1 #  GEOM GEOM_SWIG : binding of C++ omplementaion with Python
2 #
3 #  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 #
22 #
23 #
24 #  File   : GEOM_example3.py
25 #  Author : Paul RASCLE, EDF
26 #  Module : GEOM
27 #  $Header$
28
29 import salome
30 import geompy
31 import math
32 from time import sleep
33
34 geom = salome.lcc.FindOrLoadComponent("FactoryServer", "GEOM")
35 myBuilder = salome.myStudy.NewBuilder()
36
37 gg = salome.ImportComponentGUI("GEOM")
38
39 point0  = geom.MakePointStruct(0.,0.,0.)
40 pointz1 = geom.MakePointStruct(0.,0.,1.)
41 dirz = geom.MakeDirection(pointz1)
42
43 torus1 = geompy.MakeTorus(point0,dirz,150.,25.)
44 id_torus1 = geompy.addToStudy(torus1,"torus1")
45 gg.createAndDisplayGO(id_torus1)
46
47 torus2 = geom.MakeCopy(torus1)
48 torus2 = geom.MakeTranslation(torus2,0.,0.,100.)
49 id_torus2 = geompy.addToStudy(torus2,"torus2")
50 gg.createAndDisplayGO(id_torus2)
51
52 cylz1 = geompy.MakeCylinder(point0,dirz,25.,100.)
53
54 ind = 0
55 shapeList = []
56 idList = []
57 while ind < 6:
58     acyl = geom.MakeCopy(cylz1)
59     x = 150. * math.cos(ind * math.pi/3.)
60     y = 150. * math.sin(ind * math.pi/3.)
61     z = 0.
62     name = "cyl%d"%(ind)
63     acyl = geompy.MakeTranslation(acyl,x,y,z)
64     id_acyl = geompy.addToStudy(acyl,name)
65     gg.createAndDisplayGO(id_acyl)
66     shapeList.append(acyl)
67     idList.append(id_acyl)
68     ind = ind +1
69
70 shapeList.append(torus1)
71 shapeList.append(torus2)
72 idList.append(id_torus1)
73 idList.append(id_torus2)
74
75 iorStringList = []
76 for shape in shapeList:
77     iorStringList.append(shape._get_Name())
78
79 cage = geompy.MakeCompound(iorStringList)
80 id_cage = geompy.addToStudy(cage,"cage")
81 gg.createAndDisplayGO(id_cage)
82
83 from salome import sg
84 sleep(1)
85 sg.EraseAll()
86 for id in idList:
87     sg.DisplayOnly(id)
88     sleep(1)
89 sg.EraseAll()
90 for id in idList:
91     sg.Display(id)
92     sleep(1)
93 for id in idList:
94     sg.Erase(id)
95     sleep(1)
96
97 #sg.Display(id_cage)
98 sg.Display(id_torus1)
99 sg.Display(id_torus2)
100 sg.Display(id_acyl)
101
102 gg.setTransparency(id_torus1,0.5)
103
104 gg.setDisplayMode(id_torus1,1)
105 gg.setDisplayMode(id_torus2,1)
106 gg.setDisplayMode(id_acyl,1)
107 #gg.setDisplayMode(id_cage,1)
108
109 gg.setColor(id_torus1,0,0,255)
110 gg.setColor(id_torus2,255,0,0)
111 gg.setColor(id_acyl,0,255,0)
112 #gg.setColor(id_cage,255,255,0)