1 # Copyright (C) 2007-2010 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.
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 : :sat:{PYCMP}_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
47 import :sat:{PYCMP}_ORB
50 # Get :sat:{PYCMP} module's ID
57 # Get :sat:{PYCMP} object's ID
71 # Get :sat:{PYCMP} module's name
77 # Get module's pixmap name
80 return ":sat:{PYCMP}_small.png"
88 if __verbose__ is None:
90 __verbose__ = int( os.getenv( 'SALOME_VERBOSE', 0 ) )
104 __orb__ = CORBA.ORB_init( [''], CORBA.ORB_ID )
109 # Get naming service instance
111 __naming_service__ = None
113 global __naming_service__
114 if __naming_service__ is None:
115 __naming_service__ = SALOME_NamingServicePy_i( getORB() )
117 return __naming_service__
120 # Get life cycle CORBA instance
126 __lcc__ = LifeCycleCORBA( getORB() )
133 __study_manager__ = None
134 def getStudyManager():
135 global __study_manager__
136 if __study_manager__ is None:
137 obj = getNS().Resolve( '/myStudyManager' )
138 __study_manager__ = obj._narrow( SALOMEDS.StudyManager )
140 return __study_manager__
143 # Get :sat:{PYCMP} engine
148 if __engine__ is None:
149 __engine__ = getLCC().FindOrLoadComponent( "FactoryServerPy", moduleName() )
154 # Get :sat:{PYCMP} engine IOR
158 if getORB() and getEngine():
159 IOR = getORB().object_to_string( getEngine() )
164 # Find or create :sat:{PYCMP} component object in a study
166 def findOrCreateComponent( study ):
167 father = study.FindComponent( moduleName() )
169 builder = study.NewBuilder()
170 father = builder.NewComponent( moduleName() )
171 attr = builder.FindOrCreateAttribute( father, "AttributeName" )
172 attr.SetValue( moduleName() )
173 attr = builder.FindOrCreateAttribute( father, "AttributePixMap" )
174 attr.SetPixMap( modulePixmap() )
175 attr = builder.FindOrCreateAttribute( father, "AttributeLocalID" )
176 attr.SetValue( moduleID() )
178 builder.DefineComponentInstance( father, getEngine() )
188 def getObjectID( study, entry ):
191 sobj = study.FindObjectID( entry )
193 test, anAttr = sobj.FindAttribute( "AttributeLocalID" )
194 if test: ID = anAttr._narrow( SALOMEDS.AttributeLocalID ).Value()