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