1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
37 "findOrCreateComponent",
41 from omniORB import CORBA
42 from SALOME_NamingServicePy import SALOME_NamingServicePy_i
43 from LifeCycleCORBA import LifeCycleCORBA
45 import SALOMEDS_Attributes_idl
72 This provide the name of the module component to be associated to the study.
74 # Note that this name should be (i) the name used for the class implementing
75 # the component CORBA interface and (ii) the name used to declare the component
76 # in the catalog of the module.
79 # _MEM_ we use here the tr() translation methode to manage constant parameters
80 # in the application. We could have specified instead constant values directly
81 # in the code below. It's a matter of convenience.
82 from PyQt4.QtCore import QObject
85 def componentUserName():
90 Get the reference pixmap for this module.
97 if __verbose__ is None:
99 __verbose__ = int( os.getenv( 'SALOME_VERBOSE', 0 ) )
113 __orb__ = CORBA.ORB_init( [''], CORBA.ORB_ID )
118 # Get naming service instance
120 __naming_service__ = None
122 global __naming_service__
123 if __naming_service__ is None:
124 __naming_service__ = SALOME_NamingServicePy_i( getORB() )
126 return __naming_service__
129 # Get life cycle CORBA instance
135 __lcc__ = LifeCycleCORBA( getORB() )
142 __study_manager__ = None
143 def getStudyManager():
144 global __study_manager__
145 if __study_manager__ is None:
146 obj = getNS().Resolve( '/myStudyManager' )
147 __study_manager__ = obj._narrow( SALOMEDS.StudyManager )
149 return __study_manager__
157 if __engine__ is None:
158 __engine__ = getLCC().FindOrLoadComponent( "FactoryServer", componentName() )
167 if getORB() and getEngine():
168 IOR = getORB().object_to_string( getEngine() )
173 # Find or create OMA component object in a study
175 def findOrCreateComponent( study ):
176 father = study.FindComponent( componentName() )
178 builder = study.NewBuilder()
179 father = builder.NewComponent( componentName() )
180 attr = builder.FindOrCreateAttribute( father, "AttributeName" )
181 attr.SetValue( componentName() )
182 attr = builder.FindOrCreateAttribute( father, "AttributePixMap" )
183 attr.SetPixMap( modulePixmap() )
184 attr = builder.FindOrCreateAttribute( father, "AttributeLocalID" )
185 attr.SetValue( moduleID() )
187 builder.DefineComponentInstance( father, getEngine() )
197 def getObjectID( study, entry ):
200 sobj = study.FindObjectID( entry )
202 test, anAttr = sobj.FindAttribute( "AttributeLocalID" )
203 if test: ID = anAttr._narrow( SALOMEDS.AttributeLocalID ).Value()