Back to index

salome-geom  6.5.0
GEOM_example3.py
Go to the documentation of this file.
00001 #  -*- coding: iso-8859-1 -*-
00002 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00003 #
00004 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00005 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00006 #
00007 # This library is free software; you can redistribute it and/or
00008 # modify it under the terms of the GNU Lesser General Public
00009 # License as published by the Free Software Foundation; either
00010 # version 2.1 of the License.
00011 #
00012 # This library is distributed in the hope that it will be useful,
00013 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 # Lesser General Public License for more details.
00016 #
00017 # You should have received a copy of the GNU Lesser General Public
00018 # License along with this library; if not, write to the Free Software
00019 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00020 #
00021 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00022 #
00023 
00024 #  GEOM GEOM_SWIG : binding of C++ omplementaion with Python
00025 #  File   : GEOM_example3.py
00026 #  Author : Paul RASCLE, EDF
00027 #  Module : GEOM
00028 #  $Header: /home/server/cvs/GEOM/GEOM_SRC/src/GEOM_SWIG/GEOM_example3.py,v 1.11.2.3.10.2.14.1 2012-04-13 05:48:08 vsr Exp $
00029 #
00030 import salome
00031 import geompy
00032 import math
00033 from time import sleep
00034 import salome_ComponentGUI
00035 geom = salome.lcc.FindOrLoadComponent("FactoryServer", "GEOM")
00036 myBuilder = salome.myStudy.NewBuilder()
00037 
00038 gg = salome.ImportComponentGUI("GEOM")
00039 
00040 BasicOp  = geom.GetIBasicOperations(salome.myStudyId)
00041 PrimOp   = geom.GetI3DPrimOperations(salome.myStudyId)
00042 InsertOp = geom.GetIInsertOperations(salome.myStudyId)
00043 TrsfOp   = geom.GetITransformOperations(salome.myStudyId)
00044 
00045 point0  = BasicOp.MakePointXYZ(0.,0.,0.)
00046 pointz1 = BasicOp.MakePointXYZ(0.,0.,1.)
00047 dirz = BasicOp.MakeVectorTwoPnt(point0,pointz1)
00048 
00049 torus1 = PrimOp.MakeTorusPntVecRR(point0,dirz,150.,25.)
00050 id_torus1 = geompy.addToStudy(torus1,"torus1")
00051 if not isinstance(gg, type(salome_ComponentGUI)):
00052     gg.createAndDisplayGO(id_torus1)
00053 
00054 torus2 = InsertOp.MakeCopy(torus1)
00055 
00056 vec1 = BasicOp.MakeVectorDXDYDZ(0.,0.,100.)
00057 torus2 = TrsfOp.TranslateVectorCopy(torus2,vec1)
00058 id_torus2 = geompy.addToStudy(torus2,"torus2")
00059 if not isinstance(gg, type(salome_ComponentGUI)):
00060     gg.createAndDisplayGO(id_torus2)
00061 
00062 cylz1 = PrimOp.MakeCylinderPntVecRH(point0,dirz,25.,100.)
00063 
00064 ind = 0
00065 shapeList = []
00066 idList = []
00067 while ind < 6:
00068     acyl = InsertOp.MakeCopy(cylz1)
00069     x = 150. * math.cos(ind * math.pi/3.)
00070     y = 150. * math.sin(ind * math.pi/3.)
00071     z = 0.
00072     vec_i = BasicOp.MakeVectorDXDYDZ(x,y,z)
00073     name = "cyl%d"%(ind)
00074     acyl = TrsfOp.TranslateVectorCopy(acyl,vec_i)
00075     id_acyl = geompy.addToStudy(acyl,name)
00076     if not isinstance(gg, type(salome_ComponentGUI)):
00077         gg.createAndDisplayGO(id_acyl)
00078     shapeList.append(acyl)
00079     idList.append(id_acyl)
00080     ind = ind +1
00081 
00082 shapeList.append(torus1)
00083 shapeList.append(torus2)
00084 idList.append(id_torus1)
00085 idList.append(id_torus2)
00086 
00087 cage = geompy.MakeCompound(shapeList)
00088 id_cage = geompy.addToStudy(cage,"cage")
00089 if not isinstance(gg, type(salome_ComponentGUI)):
00090     gg.createAndDisplayGO(id_cage)
00091 
00092 from salome import sg
00093 sleep(1)
00094 sg.EraseAll()
00095 for id in idList:
00096     sg.DisplayOnly(id)
00097     sleep(1)
00098 sg.EraseAll()
00099 for id in idList:
00100     sg.Display(id)
00101     sleep(1)
00102 for id in idList:
00103     sg.Erase(id)
00104     sleep(1)
00105 
00106 #sg.Display(id_cage)
00107 sg.Display(id_torus1)
00108 sg.Display(id_torus2)
00109 sg.Display(id_acyl)
00110 if not isinstance(gg, type(salome_ComponentGUI)):
00111     gg.setTransparency(id_torus1,0.5)
00112     
00113     gg.setDisplayMode(id_torus1,1)
00114     gg.setDisplayMode(id_torus2,1)
00115     gg.setVectorsMode(id_acyl,1,1)
00116     #gg.setDisplayMode(id_cage,1)
00117     
00118     gg.setColor(id_torus1,0,0,255)
00119     gg.setColor(id_torus2,255,0,0)
00120     gg.setColor(id_acyl,0,255,0)
00121     #gg.setColor(id_cage,255,255,0)