1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2011 CEA/DEN, EDF R&D, OPEN CASCADE
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 # Author : Guillaume Boulant (EDF)
23 # ===============================================================
24 # This functions are to be used to notify the USER of some events
25 # arising on the field operation. It is NOT to be used for logging
27 # ===============================================================
30 print "INF: "+str(msg)
33 print "WRN: "+str(msg)
36 print "ERR: "+str(msg)
39 print "DBG: "+str(msg)
42 # ===============================================================
43 # Initializing some CORBA stuff
44 # ===============================================================
47 # Remember SALOME definitions:
48 # ---------------------------
50 # componentName = Name of the component (a library lib<componentName>Engine
51 # should exist with a C function named <componentName>Engine_factory, and the
52 # component should be registered in the catalog MEDCatalog.xml).
54 # corbaModule = Name of the corba module that contains the IDL
55 # specifications of the component (name as defined in the idl file)
57 # containerType = Name of the container factory
59 componentName = "MEDOPFactory"
61 containerType = "FactoryServer"
64 if salome.lcc is None:
66 __import__(corbaModule)
67 factory = salome.lcc.FindOrLoadComponent(containerType,componentName)
68 # The factory is not the main CORBA component of the SALOME module MED
69 # (i.e. the engine associated to the active study), but the CORBA
70 # entry point for MED fields operations (i.e. a CORBA component
71 # reachable throught the LifeCycleCORBA). This entry point is used to
72 # get the other SALOME CORBA components required for MED field
73 # operations, in particular the dataManager and the calculator
76 # ===============================================================
77 # Initializing the MED components required for MED fields operations
78 # ===============================================================
80 dataManager = factory.getDataManager()
81 calculator = factory.getCalculator()
84 # ===============================================================
85 # Initializing the notification system (events from components to GUI)
86 # ===============================================================
89 # The MEDEventListener is created in the GUI (WorkspaceController) and
90 # a reference is transmitted to the python context throw its IOR. The
91 # transmission consists in initializing the variable below from the
92 # GUI (who knows the IOR) when importing xmed in the python console
93 # (see WorkspaceController)
96 def connectEventListener():
99 eventListenerIOR = dataManager.getEventListenerIOR()
100 eventListener = salome.orb.string_to_object(eventListenerIOR)
101 except SALOME.SALOME_Exception, e:
102 wrn("The event listener is not running yet")
103 msg ="When you'll have loaded the MED GUI, "
104 msg+="call explicitely \"xmed.connectEventListener()\" "
105 msg+="to connect the GUI event listener"
109 err("An unknown error occurs. Check if this ior=%s is valid."%eventListenerIOR)
111 def eventListenerIsRunning():
113 if eventListener is not None:
116 # Try to define the event listener
117 connectEventListener()
118 if eventListener is None:
119 # it definitly does not work
120 wrn("the GUI is not loaded yet and will not be notified of the modification")
125 # One can try to connect to the eventListener, but it will fail if the
126 # MED GUI is not loaded. That does not matter, because the event
127 # listener is used only to notify the GUI of some event. If the GUI is
128 # not loaded, there is no use of notification.
129 connectEventListener()
132 # ===============================================================
133 # Automatic import of some elements of the package
134 # ===============================================================
136 from fieldtools import load, get, put, dup, ls, la, save, view
137 from fieldguide import doc
138 from cmdtools import cls, wipe
141 # ===============================================================
142 # Some helper functions to deal with the fields and meshes
143 # ===============================================================
146 __mapTypeOfFieldLabel={
147 MEDCoupling.ON_CELLS:"ON_CELLS",
148 MEDCoupling.ON_NODES:"ON_NODES",
149 MEDCoupling.ON_GAUSS_PT:"ON_GAUSS_PT",
150 MEDCoupling.ON_GAUSS_NE:"ON_GAUSS_NE"}
152 def typeOfFieldLabel(typeOfField):
153 # A field name could identify several MEDCoupling fields, that
154 # differ by their spatial discretization on the mesh (values on
155 # cells, values on nodes, ...). This spatial discretization is
156 # specified (at least) by the TypeOfField that is an integer value
163 return __mapTypeOfFieldLabel[typeOfField]
164 except IndexError, e:
168 # This function is to be called from the working python console to
169 # specify the globals() dictionnary (used in fieldtools for stat analysis)
171 # >>> xmed.setConsoleGlobals(globals())
174 def setConsoleGlobals(pyConsoleGlobals):
175 fieldtools.pyConsoleGlobals = pyConsoleGlobals
178 # ===================================================================
179 # unit test functions
180 # ===================================================================
182 def TEST_typeOfFieldLabel():
183 print typeOfFieldLabel(0)
184 print typeOfFieldLabel(5)
186 # ===================================================================
187 if __name__ == "__main__":
188 TEST_typeOfFieldLabel()