Salome HOME
Edit popup
[modules/adao.git] / src / daSalome / daGUI / daGuiImpl / datassimModuleHelper.py
1 # -*- coding: iso-8859-1 -*-
2 #  Copyright (C) 2007-2008  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 # Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
25 # ---
26 #
27
28 __all__ = [
29     "moduleID",
30     "objectID",
31     "unknownID",
32     "componentName",
33     "modulePixmap",
34     "verbose",
35     "getORB",
36     "getNS",
37     "getLCC",
38     "getStudyManager",
39     "getEngine",
40     "getEngineIOR",
41     "findOrCreateComponent",
42     "getObjectID",
43     ]
44
45 from omniORB import CORBA
46 from SALOME_NamingServicePy import SALOME_NamingServicePy_i
47 from LifeCycleCORBA import LifeCycleCORBA
48 import SALOMEDS
49 import SALOMEDS_Attributes_idl
50
51 #import OMA_ORB
52
53 ###
54 # Get OMA module's ID
55 ###
56 def moduleID():
57     MODULE_ID = 1100
58     return MODULE_ID
59
60 ###
61 # Get OMA object's ID
62 ###
63 def objectID():
64     OBJECT_ID = 1110
65     return OBJECT_ID
66
67 ###
68 # Get unknown ID
69 ###
70 def unknownID():
71     FOREIGN_ID = -1
72     return FOREIGN_ID
73
74 def componentName():
75     """
76     This provide the name of the module component to be associated to the study.
77     """
78     # Note that this name should be (i) the name used for the class implementing
79     # the component CORBA interface and (ii) the name used to declare the component
80     # in the catalog of the module.
81     return "DATASSIM"
82
83 # _MEM_ we use here the tr() translation methode to manage constant parameters
84 # in the application. We could have specified instead constant values directly
85 # in the code below. It's a matter of convenience.
86 from PyQt4.QtCore import QObject
87 QObjectTR=QObject()
88
89 def componentUserName():
90     return "DATASSIM"
91
92 def modulePixmap():
93     """
94     Get the reference pixmap for this module.
95     """
96     return "DATASSIM_small.png"
97
98 __verbose__ = None
99 def verbose():
100     global __verbose__
101     if __verbose__ is None:
102         try:
103             __verbose__ = int( os.getenv( 'SALOME_VERBOSE', 0 ) )
104         except:
105             __verbose__ = 0
106             pass
107         pass
108     return __verbose__
109
110 ###
111 # Get ORB reference
112 ###
113 __orb__ = None
114 def getORB():
115     global __orb__
116     if __orb__ is None:
117         __orb__ = CORBA.ORB_init( [''], CORBA.ORB_ID )
118         pass
119     return __orb__
120
121 ###
122 # Get naming service instance
123 ###
124 __naming_service__ = None
125 def getNS():
126     global __naming_service__
127     if __naming_service__ is None:
128         __naming_service__ = SALOME_NamingServicePy_i( getORB() )
129         pass
130     return __naming_service__
131
132 ##
133 # Get life cycle CORBA instance
134 ##
135 __lcc__ = None
136 def getLCC():
137     global __lcc__
138     if __lcc__ is None:
139         __lcc__ = LifeCycleCORBA( getORB() )
140         pass
141     return __lcc__
142
143 ##
144 # Get study manager
145 ###
146 __study_manager__ = None
147 def getStudyManager():
148     global __study_manager__
149     if __study_manager__ is None:
150         obj = getNS().Resolve( '/myStudyManager' )
151         __study_manager__ = obj._narrow( SALOMEDS.StudyManager )
152         pass
153     return __study_manager__
154
155 ###
156 # Get OMA engine
157 ###
158 __engine__ = None
159 def getEngine():
160     global __engine__
161     if __engine__ is None:
162         __engine__ = getLCC().FindOrLoadComponent( "FactoryServer", componentName() )
163         pass
164     return __engine__
165
166 ###
167 # Get OMA engine IOR
168 ###
169 def getEngineIOR():
170     IOR = ""
171     if getORB() and getEngine():
172         IOR = getORB().object_to_string( getEngine() )
173         pass
174     return IOR
175
176 ###
177 # Find or create OMA component object in a study
178 ###
179 def findOrCreateComponent( study ):
180     father = study.FindComponent( componentName() )
181     if father is None:
182         builder = study.NewBuilder()
183         father = builder.NewComponent( componentName() )
184         attr = builder.FindOrCreateAttribute( father, "AttributeName" )
185         attr.SetValue( componentName() )
186         attr = builder.FindOrCreateAttribute( father, "AttributePixMap" )
187         attr.SetPixMap( modulePixmap() )
188         attr = builder.FindOrCreateAttribute( father, "AttributeLocalID" )
189         attr.SetValue( moduleID() )
190         try:
191             builder.DefineComponentInstance( father, getEngine() )
192             pass
193         except:
194             pass
195         pass
196     return father
197
198 ###
199 # Get object's ID
200 ###
201 def getObjectID( study, entry ):
202     ID = unknownID()
203     if study and entry:
204         sobj = study.FindObjectID( entry )
205         if sobj is not None:
206             test, anAttr = sobj.FindAttribute( "AttributeLocalID" )
207             if test: ID = anAttr._narrow( SALOMEDS.AttributeLocalID ).Value()
208             pass
209         pass
210     return
211