Salome HOME
Correction for Qt5/Eficas/Adao/Salome embedded frames compatibility
[modules/adao.git] / src / daSalome / daGUI / daGuiImpl / adaoModuleHelper.py
1 # -*- coding: utf-8 -*-
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 __all__ = [
25     "moduleID",
26     "objectID",
27     "unknownID",
28     "componentName",
29     "modulePixmap",
30     "verbose",
31     "getORB",
32     "getNS",
33     "getLCC",
34     "getStudyManager",
35     "getEngine",
36     "getEngineIOR",
37     "findOrCreateComponent",
38     "getObjectID",
39     ]
40
41 from omniORB import CORBA
42 from SALOME_NamingServicePy import SALOME_NamingServicePy_i
43 from LifeCycleCORBA import LifeCycleCORBA
44 import SALOMEDS
45 import SALOMEDS_Attributes_idl
46
47 #import OMA_ORB
48
49 ###
50 # Get OMA module's ID
51 ###
52 def moduleID():
53     MODULE_ID = 6100
54     return MODULE_ID
55
56 ###
57 # Get OMA object's ID
58 ###
59 def objectID():
60     OBJECT_ID = 6110
61     return OBJECT_ID
62
63 ###
64 # Get unknown ID
65 ###
66 def unknownID():
67     FOREIGN_ID = -1
68     return FOREIGN_ID
69
70 def componentName():
71     """
72     This provide the name of the module component to be associated to the study.
73     """
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.
77     return "ADAO"
78
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 daUtils.qtversion import useQT5
83 if useQT5:
84     from PyQt5.QtCore import QObject
85 else:
86     from PyQt4.QtCore import QObject
87 QObjectTR=QObject()
88
89 def componentUserName():
90     return "ADAO"
91
92 def modulePixmap():
93     """
94     Get the reference pixmap for this module.
95     """
96     return "ADAO_small.png"
97
98 def studyItemPixmapOk():
99     """
100     Get the reference pixmap for items of this module.
101     """
102     return "ADAO_small_vert.png"
103
104 def studyItemPixmapNOk():
105     """
106     Get the reference pixmap for items of this module.
107     """
108     return "ADAO_small_rouge.png"
109
110 __verbose__ = None
111 def verbose():
112     global __verbose__
113     if __verbose__ is None:
114         try:
115             __verbose__ = int( os.getenv( 'SALOME_VERBOSE', 0 ) )
116         except:
117             __verbose__ = 0
118             pass
119         pass
120     return __verbose__
121
122 ###
123 # Get ORB reference
124 ###
125 __orb__ = None
126 def getORB():
127     global __orb__
128     if __orb__ is None:
129         __orb__ = CORBA.ORB_init( [''], CORBA.ORB_ID )
130         pass
131     return __orb__
132
133 ###
134 # Get naming service instance
135 ###
136 __naming_service__ = None
137 def getNS():
138     global __naming_service__
139     if __naming_service__ is None:
140         __naming_service__ = SALOME_NamingServicePy_i( getORB() )
141         pass
142     return __naming_service__
143
144 ##
145 # Get life cycle CORBA instance
146 ##
147 __lcc__ = None
148 def getLCC():
149     global __lcc__
150     if __lcc__ is None:
151         __lcc__ = LifeCycleCORBA( getORB() )
152         pass
153     return __lcc__
154
155 ##
156 # Get study manager
157 ###
158 __study_manager__ = None
159 def getStudyManager():
160     global __study_manager__
161     if __study_manager__ is None:
162         obj = getNS().Resolve( '/myStudyManager' )
163         __study_manager__ = obj._narrow( SALOMEDS.StudyManager )
164         pass
165     return __study_manager__
166
167 ###
168 # Get OMA engine
169 ###
170 __engine__ = None
171 def getEngine():
172     global __engine__
173     if __engine__ is None:
174         __engine__ = getLCC().FindOrLoadComponent( "FactoryServer", componentName() )
175         pass
176     return __engine__
177
178 ###
179 # Get OMA engine IOR
180 ###
181 def getEngineIOR():
182     IOR = ""
183     if getORB() and getEngine():
184         IOR = getORB().object_to_string( getEngine() )
185         pass
186     return IOR
187
188 ###
189 # Find or create OMA component object in a study
190 ###
191 def findOrCreateComponent( study ):
192     father = study.FindComponent( componentName() )
193     if father is None:
194         builder = study.NewBuilder()
195         father = builder.NewComponent( componentName() )
196         attr = builder.FindOrCreateAttribute( father, "AttributeName" )
197         attr.SetValue( componentName() )
198         attr = builder.FindOrCreateAttribute( father, "AttributePixMap" )
199         attr.SetPixMap( modulePixmap() )
200         attr = builder.FindOrCreateAttribute( father, "AttributeLocalID" )
201         attr.SetValue( moduleID() )
202         try:
203             builder.DefineComponentInstance( father, getEngine() )
204             pass
205         except:
206             pass
207         pass
208     return father
209
210 ###
211 # Get object's ID
212 ###
213 def getObjectID( study, entry ):
214     ID = unknownID()
215     if study and entry:
216         sobj = study.FindObjectID( entry )
217         if sobj is not None:
218             test, anAttr = sobj.FindAttribute( "AttributeLocalID" )
219             if test: ID = anAttr._narrow( SALOMEDS.AttributeLocalID ).Value()
220             pass
221         pass
222     return
223