]> SALOME platform Git repositories - modules/shaper_study.git/blob - src/PY/SHAPERSTUDY_utils.py
Salome HOME
21dd6cfe40cb279e52f99f97d64d1ddd20bb825e
[modules/shaper_study.git] / src / PY / SHAPERSTUDY_utils.py
1 # Copyright (C) 2007-2019  CEA/DEN, EDF R&D, OPEN CASCADE
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     global __orb__
84     if __orb__ is None:
85         __orb__ = CORBA.ORB_init( [''], CORBA.ORB_ID )
86         pass
87     return __orb__
88
89 ###
90 # Get POA
91 ###
92 __poa__ = None
93 def getPOA():
94     global __poa__
95     if __poa__ is None:
96         __poa__ = getORB().resolve_initial_references("RootPOA")
97         pass
98     return __poa__
99
100 ###
101 # Get naming service instance
102 ###
103 __naming_service__ = None
104 def getNS():
105     global __naming_service__
106     if __naming_service__ is None:
107         __naming_service__ = SALOME_NamingServicePy_i( getORB() )
108         pass
109     return __naming_service__
110
111 ##
112 # Get life cycle CORBA instance
113 ##
114 __lcc__ = None
115 def getLCC():
116     global __lcc__
117     if __lcc__ is None:
118         __lcc__ = LifeCycleCORBA( getORB() )
119         pass
120     return __lcc__
121
122 ##
123 # Get study
124 ###
125 __study__ = None
126 def getStudy():
127     global __study__
128     if __study__ is None:
129         obj = getNS().Resolve( '/Study' )
130         __study__ = obj._narrow( SALOMEDS.Study )
131         pass
132     return __study__
133
134 ###
135 # Get SHAPERSTUDY engine
136 ###
137 __engine__ = None
138 def getEngine():
139     global __engine__
140     if __engine__ is None:
141         __engine__ = getLCC().FindOrLoad_Component( "FactoryServer", moduleName() )
142         pass
143     return __engine__
144
145 ###
146 # Get SHAPERSTUDY engine IOR
147 ###
148 def getEngineIOR():
149     IOR = ""
150     if getORB() and getEngine():
151         IOR = getORB().object_to_string( getEngine() )
152         pass
153     return IOR
154
155 ###
156 # Find or create SHAPERSTUDY component object in a study
157 ###
158 def findOrCreateComponent():
159     study = getStudy()
160     builder = study.NewBuilder()
161     father = study.FindComponent( moduleName() )
162     if father is None:
163         father = builder.NewComponent( moduleName() )
164         attr = builder.FindOrCreateAttribute( father, "AttributeName" )
165         attr.SetValue( "ShaperResults" )
166         attr = builder.FindOrCreateAttribute( father, "AttributePixMap" )
167         attr.SetPixMap( modulePixmap() )
168         #attr = builder.FindOrCreateAttribute( father, "AttributeLocalID" )
169         #attr.SetValue( moduleID() )
170         try:
171             builder.DefineComponentInstance( father, getEngine() )
172             pass
173         except:
174             pass
175         pass
176     # load the SHAPER-STUDY file if it is not done yet
177     builder.LoadWith(father, getEngine())
178     return father
179