Salome HOME
Copyright update 2021
[modules/shaper_study.git] / src / PY / SHAPERSTUDY_utils.py
1 # Copyright (C) 2019-2021  CEA/DEN, EDF R&D
2 #
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, or (at your option) any later version.
7 #
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.
12 #
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
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 # ---
21 # File   : SHAPERSTUDY_utils.py
22 # Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
23 # ---
24 #
25 __all__ = [
26     #"moduleID",
27     #"objectID",
28     #"unknownID",
29     "moduleName",
30     "modulePixmap",
31     "verbose",
32     "getORB",
33     "getNS",
34     "getLCC",
35     "getEngine",
36     "getStudy",
37     "getEngineIOR",
38     "findOrCreateComponent",
39     "getObjectID",
40     ]
41
42
43 from omniORB import CORBA
44 from SALOME_NamingServicePy import SALOME_NamingServicePy_i
45 from LifeCycleCORBA import LifeCycleCORBA
46 import SALOMEDS
47 import SALOMEDS_Attributes_idl
48 import SHAPERSTUDY_ORB
49 import os
50    
51 ###
52 # Get SHAPERSTUDY module's name
53 ###
54 def moduleName():
55     return "SHAPERSTUDY"
56
57 ###
58 # Get module's pixmap name
59 ###
60 def modulePixmap():
61     return "shaper.png"
62
63 ###
64 # Get verbose level
65 ### 
66 __verbose__ = None
67 def verbose():
68     global __verbose__
69     if __verbose__ is None:
70         try:
71             __verbose__ = int( os.getenv( 'SALOME_VERBOSE', 0 ) )
72         except:
73             __verbose__ = 0
74             pass
75         pass
76     return __verbose__
77
78 ###
79 # Get ORB reference
80 ###
81 __orb__ = None
82 def getORB():
83     import salome
84     global __orb__
85     if __orb__ is None:
86         __orb__ = CORBA.ORB_init( [''], CORBA.ORB_ID )
87         pass
88     return __orb__
89
90 ###
91 # Get POA
92 ###
93 __poa__ = None
94 def getPOA():
95     global __poa__
96     if __poa__ is None:
97         import salome
98         __poa__ = salome.orb.resolve_initial_references("RootPOA")
99         pass
100     return __poa__
101
102 ###
103 # Get naming service instance
104 ###
105 def getNS():
106     import salome
107     return salome.naming_service
108
109 ##
110 # Get life cycle CORBA instance
111 ##
112 def getLCC():
113     import salome
114     return salome.lcc
115
116 ##
117 # Get study
118 ###
119
120 def getStudy():
121     import salome
122     return salome.myStudy
123
124 ###
125 # Get SHAPERSTUDY engine
126 ###
127 __engine__ = None
128 def getEngine():
129     global __engine__
130     if __engine__ is None:
131         import salome
132         __engine__ = salome.lcc.FindOrLoadComponent( "FactoryServer", moduleName() )
133         pass
134     return __engine__
135
136 ###
137 # Get SHAPERSTUDY engine IOR
138 ###
139 def getEngineIOR():
140     IOR = ""
141     if getORB() and getEngine():
142         IOR = getORB().object_to_string( getEngine() )
143         pass
144     return IOR
145
146 ###
147 # Find or create SHAPERSTUDY component object in a study
148 ###
149 def findOrCreateComponent():
150     study = getStudy()
151     builder = study.NewBuilder()
152     father = study.FindComponent( moduleName() )
153     if father is None:
154         father = builder.NewComponent( moduleName() )
155         attr = builder.FindOrCreateAttribute( father, "AttributeName" )
156         attr.SetValue( "ShaperResults" )
157         attr = builder.FindOrCreateAttribute( father, "AttributePixMap" )
158         attr.SetPixMap( modulePixmap() )
159         #attr = builder.FindOrCreateAttribute( father, "AttributeLocalID" )
160         #attr.SetValue( moduleID() )
161         try:
162             builder.DefineComponentInstance( father, getEngine() )
163             pass
164         except:
165             pass
166         pass
167     # load the SHAPER-STUDY file if it is not done yet
168     builder.LoadWith(father, getEngine())
169     return father
170