1 # Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 # File : PYHELLO_utils.py
22 # Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
38 "findOrCreateComponent",
42 from omniORB import CORBA
43 from SALOME_NamingServicePy import SALOME_NamingServicePy_i
44 from LifeCycleCORBA import LifeCycleCORBA
46 import SALOMEDS_Attributes_idl
51 # Get PYHELLO module's ID
58 # Get PYHELLO object's ID
72 # Get PYHELLO module's name
78 # Get module's pixmap name
81 return "PYHELLO_small.png"
89 if __verbose__ is None:
91 __verbose__ = int( os.getenv( 'SALOME_VERBOSE', 0 ) )
105 __orb__ = CORBA.ORB_init( [''], CORBA.ORB_ID )
110 # Get naming service instance
112 __naming_service__ = None
114 global __naming_service__
115 if __naming_service__ is None:
116 __naming_service__ = SALOME_NamingServicePy_i( getORB() )
118 return __naming_service__
121 # Get life cycle CORBA instance
127 __lcc__ = LifeCycleCORBA( getORB() )
134 __study_manager__ = None
135 def getStudyManager():
136 global __study_manager__
137 if __study_manager__ is None:
138 obj = getNS().Resolve( '/myStudyManager' )
139 __study_manager__ = obj._narrow( SALOMEDS.StudyManager )
141 return __study_manager__
149 if __engine__ is None:
150 __engine__ = getLCC().FindOrLoadComponent( "FactoryServerPy", moduleName() )
155 # Get PYHELLO engine IOR
159 if getORB() and getEngine():
160 IOR = getORB().object_to_string( getEngine() )
165 # Find or create PYHELLO component object in a study
167 def findOrCreateComponent( study ):
168 father = study.FindComponent( moduleName() )
170 builder = study.NewBuilder()
171 father = builder.NewComponent( moduleName() )
172 attr = builder.FindOrCreateAttribute( father, "AttributeName" )
173 attr.SetValue( moduleName() )
174 attr = builder.FindOrCreateAttribute( father, "AttributePixMap" )
175 attr.SetPixMap( modulePixmap() )
176 attr = builder.FindOrCreateAttribute( father, "AttributeLocalID" )
177 attr.SetValue( moduleID() )
179 builder.DefineComponentInstance( father, getEngine() )
189 def getObjectID( study, entry ):
192 sobj = study.FindObjectID( entry )
194 test, anAttr = sobj.FindAttribute( "AttributeLocalID" )
195 if test: ID = anAttr._narrow( SALOMEDS.AttributeLocalID ).Value()