1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2011-2013 CEA/DEN, EDF R&D
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 # The functions of this module must be imported as global functions in
25 # the SALOME python console. It provides the console context with Tool
26 # functions to manipulate field throw there fieldproxy.
27 # ===================================================================
31 from xmed.fieldproxy import FieldProxy, newFieldProxy
33 # ===================================================================
34 # Operations on fields
38 This function returns a duplicate of the specified field.
39 It's equivalent to the call '>>> copy = f.dup()'.
42 clone = aFieldProxy.dup()
44 print "ERR: the argument can't be duplicated as a field object"
48 # ===================================================================
49 # Get list a field with information using the commands ls and/or la
52 # the pyConsoleGlobals variable should holds the globals() dictionnary of
53 # the python console context
56 def status(local=True,remote=False):
58 This function return the status of the medop context, i.e. the
59 list of fields defined in this python session.
63 dvars = pyConsoleGlobals
65 xmed.wrn("The stat function required the specification of the python context")
66 xmed.inf("Type this command \"import xmed; xmed.setConsoleGlobals(globals())")
68 status="========= Fields used in the current context ===\n"
69 for varkey in dvars.keys():
71 if isinstance(var, FieldProxy):
72 status+="%s \t(id=%s, name=%s)\n"%(varkey,var.id,var.fieldname)
76 status+="\n========= Fields available in the data manager ===\n"
77 fieldHandlerList = xmed.dataManager.getFieldHandlerList()
78 for fieldHandler in fieldHandlerList:
79 status+="id=%s\tname\t= %s\n\tmesh\t= %s\n\t(it,dt)\t= (%s,%s)\n\tsource\t= %s\n"%(
81 fieldHandler.fieldname,
82 fieldHandler.meshname,
83 fieldHandler.iteration,
88 if len(fieldHandlerList) > 0:
89 status+="(use 'f=get(id)' to get a field in the current context)"
93 # For simpler typing, one can create a python command for status
94 # (avoid to type "print status()")
95 class ListFields(object):
97 A stat object displays the status of the med operating context, i.e. the
98 list of fields defined in this python session.
100 def __init__(self,all=False):
103 # all = True means that the local metadata (fieldproxy) and the
104 # remote metadata on the engine (MEDCouplingFieldDouble) are
105 # displayed by the stat command. Otherwise, only the local
106 # metadata are displayed.
109 return status(self.__local, self.__remote)
111 # Creating the commands list (ls) and list all (la)
112 ls=ListFields(all=False)
113 la=ListFields(all=True)
115 # ===================================================================
116 # Field Data Management
117 from xmed import properties
118 filepath = properties.testFilePath
120 def load(medFileName=filepath):
122 This function indicates that we want to use the fields from the
123 specified med file. The fields meta-data are loaded in the engine
124 part of the module. To get a fieldproxy on a field, call the get
125 function with the id of the required field. To display the whole
126 list of fields loaded in the engine, type 'ls' (la verbose).
128 xmed.dataManager.addDatasource(filepath)
129 print status(local=False,remote=True)
131 def get(fieldHandlerId):
133 This return a field proxy on the field identified by the specified
136 return newFieldProxy(fieldHandlerId)
138 from xmed.fieldproxy import notifyGui_add
139 def put(aFieldProxy):
141 This function puts a reference to this field in the GUI data
142 model. When a field is referenced in the GUI data model, then it
143 belongs to the workspace. When the workspace is saved, all the
144 field that belongs to the workspace are saved.
146 xmed.dataManager.markAsPersistent(aFieldProxy.id, True)
147 notifyGui_add(aFieldProxy.id)
152 Dump your job in a med file. Only the fields marked as persistent
153 are saved in the specified file.
156 xmed.dataManager.savePersistentFields(filename)
157 except SALOME.SALOME_Exception, ex:
158 xmed.err(ex.details.text)
160 # ===================================================================
161 # Field Data visualization
163 VIEWER_PARAVIS = "PARAVIS"
164 VIEWER_DEFAULT = VIEWER_VISU
166 VIEWER_TMP_FILE = "/tmp/medop_viewer.med"
168 def view_using_paravis(aFieldProxy):
169 # __GBO__ TO BE IMPROVED: we used a tmp file in this first step of
170 # development, but we should used at last a MEDCoupling corba
171 # object (see how to use the stuff in PARAVIS/src/Plugins)
172 xmed.dataManager.saveFields(VIEWER_TMP_FILE, [aFieldProxy.id])
174 from xmed.driver_pvis import pvis_scalarmap
175 pvis_scalarmap(VIEWER_TMP_FILE,
176 aFieldProxy.meshname,
177 aFieldProxy.fieldname,
179 aFieldProxy.iteration)
181 def view_using_visu(aFieldProxy):
182 # __GBO__ TO BE IMPROVED: we used a tmp file in this first step of
183 # development, but we should used at last a MEDCoupling corba
184 # object (see how to use the stuff in PARAVIS/src/Plugins)
185 xmed.dataManager.saveFields(VIEWER_TMP_FILE, [aFieldProxy.id])
187 # __GBO__: WARN due to a specific feature of VISU, when only one
188 # field timestamps exists in the med file, we have to specify an
189 # iteration number of 1, whatever the iteration value is in the
191 iteration = 1 # __GBO__ for bug VISU
193 # iteration = aFieldProxy.iteration
195 from xmed.driver_visu import visu_scalarmap
196 result = visu_scalarmap(VIEWER_TMP_FILE,
197 aFieldProxy.meshname,
198 aFieldProxy.fieldname,
202 xmed.err("the field can't be displayed")
204 def view(aFieldProxy, using=VIEWER_DEFAULT):
206 This displays a 3D view of the field using VISU or PARAVIS,
207 depending on the configuration. This view is for quick visual
208 control of a field and is not intended to be parametrizable. For
209 custom display, you should import the fields in VISU or PARAVIS
210 and continue the job in one of this SALOME module.
212 if using == VIEWER_PARAVIS:
213 view_using_paravis(aFieldProxy)
215 view_using_visu(aFieldProxy)