Salome HOME
Minor source update for OM compatibility
[modules/adao.git] / src / daSalome / daGUI / daGuiImpl / adaoModuleHelper.py
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2008-2024 EDF R&D
4 #
5 # Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
6 #
7 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
8 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
9 #
10 # This library is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU Lesser General Public
12 # License as published by the Free Software Foundation; either
13 # version 2.1 of the License.
14 #
15 # This library is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 # Lesser General Public License for more details.
19 #
20 # You should have received a copy of the GNU Lesser General Public
21 # License along with this library; if not, write to the Free Software
22 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
23 #
24 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
25 #
26
27 __all__ = [
28     "moduleID",
29     "objectID",
30     "unknownID",
31     "componentName",
32     "modulePixmap",
33     "verbose",
34     "getORB",
35     "getLCC",
36     "getStudyManager",
37     "getEngine",
38     "getEngineIOR",
39     "findOrCreateComponent",
40     "getObjectID",
41     ]
42
43 import os
44 from omniORB import CORBA
45 from SALOME_NamingServicePy import SALOME_NamingServicePy_i
46 from LifeCycleCORBA import LifeCycleCORBA
47 import salome
48 import SALOMEDS
49 import SALOMEDS_Attributes_idl
50 from salome.kernel.studyedit import getStudyEditor
51
52 #import OMA_ORB
53
54 ###
55 # Get OMA module's ID
56 ###
57 def moduleID():
58     MODULE_ID = 6100
59     return MODULE_ID
60
61 ###
62 # Get OMA object's ID
63 ###
64 def objectID():
65     OBJECT_ID = 6110
66     return OBJECT_ID
67
68 ###
69 # Get unknown ID
70 ###
71 def unknownID():
72     FOREIGN_ID = -1
73     return FOREIGN_ID
74
75 def componentName():
76     """
77     This provide the name of the module component to be associated to the study.
78     """
79     # Note that this name should be (i) the name used for the class implementing
80     # the component CORBA interface and (ii) the name used to declare the component
81     # in the catalog of the module.
82     return "ADAO"
83
84 # _MEM_ we use here the tr() translation methode to manage constant parameters
85 # in the application. We could have specified instead constant values directly
86 # in the code below. It's a matter of convenience.
87 from PyQt5.QtCore import QObject
88 QObjectTR=QObject()
89
90 def componentUserName():
91     return "ADAO"
92
93 def modulePixmap():
94     """
95     Get the reference pixmap for this module.
96     """
97     return "ADAO_small.png"
98
99 def studyItemPixmapOk():
100     """
101     Get the reference pixmap for items of this module.
102     """
103     return "ADAO_small_vert.png"
104
105 def studyItemPixmapNOk():
106     """
107     Get the reference pixmap for items of this module.
108     """
109     return "ADAO_small_rouge.png"
110
111 __verbose__ = None
112 def verbose():
113     global __verbose__
114     if __verbose__ is None:
115         try:
116             __verbose__ = int( os.getenv( 'SALOME_VERBOSE', 0 ) )
117         except:
118             __verbose__ = 0
119             pass
120         pass
121     return __verbose__
122
123 ###
124 # Get ORB reference
125 ###
126 def getORB():
127     salome.salome_init()
128     return salome.orb
129
130 ##
131 # Get life cycle CORBA instance
132 ##
133 def getLCC():
134     salome.salome_init()
135     return salome.lcc
136
137 ##
138 # Get study manager
139 ###
140 def getStudyManager():
141     salome.salome_init()
142     return salome.myStudy
143
144 ###
145 # Get OMA engine
146 ###
147 __engine__ = None
148 def getEngine():
149     global __engine__
150     if __engine__ is None:
151         __engine__ = getLCC().FindOrLoadComponent( "FactoryServer", componentName() )
152         pass
153     return __engine__
154
155 ###
156 # Get OMA engine IOR
157 ###
158 def getEngineIOR():
159     IOR = ""
160     if getORB() and getEngine():
161         IOR = getORB().object_to_string( getEngine() )
162         pass
163     return IOR
164
165 ###
166 # Find or create OMA component object in a study
167 ###
168 def findOrCreateComponent( study ):
169     father = study.FindComponent( componentName() )
170     if father is None:
171         builder = study.NewBuilder()
172         father = builder.NewComponent( componentName() )
173         attr = builder.FindOrCreateAttribute( father, "AttributeName" )
174         attr.SetValue( componentName() )
175         attr = builder.FindOrCreateAttribute( father, "AttributePixMap" )
176         attr.SetPixMap( modulePixmap() )
177         attr = builder.FindOrCreateAttribute( father, "AttributeLocalID" )
178         attr.SetValue( moduleID() )
179         try:
180             builder.DefineComponentInstance( father, getEngine() )
181             pass
182         except:
183             pass
184         pass
185     return father
186
187 ###
188 # Get object's ID
189 ###
190 def getObjectID( entry ): # study, entry ):
191     ID = unknownID()
192     if entry: # study and entry:
193         sobj = getStudyEditor().study.FindObjectID( entry )
194         if sobj is not None:
195             test, anAttr = sobj.FindAttribute( "AttributeLocalID" )
196             if test: ID = anAttr._narrow( SALOMEDS.AttributeLocalID ).Value()
197             pass
198         pass
199     return
200