1 # Copyright (C) 2006-2008 CEA/DEN, EDF R&D
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.
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.
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
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 import SALOME_ComponentPy
23 import SALOME_DriverPy
34 class proc_i(YACS_ORB__POA.ProcExec):
35 def __init__(self, xmlFile):
36 self.l = loader.YACSLoader()
37 self.e = pilot.ExecutorSwig()
38 self.e.setExecMode(1) # YACS::STEPBYSTEP
40 self.p = self.l.load(xmlFile)
43 def getNodeState(self,numid):
44 return self.p.getNodeState(numid)
46 def getXMLState(self, numid):
47 return self.p.getXMLState(numid)
49 def getInPortValue(self, nodeNumid, portName):
50 return self.p.getInPortValue(nodeNumid, portName)
52 def getOutPortValue(self, nodeNumid, portName):
53 return self.p.getOutPortValue(nodeNumid, portName)
55 def getErrorDetails(self, nodeNumid):
56 return self.p.getNodeErrorDetails(nodeNumid)
58 def getErrorReport(self, nodeNumid):
59 return self.p.getNodeErrorReport(nodeNumid)
61 def getContainerLog(self, nodeNumid):
62 return self.p.getNodeContainerLog(nodeNumid)
64 def getExecutorState(self):
65 return self.e.getExecutorState()
68 numids = self.p.getNumIds()
73 return self.p.getNumIds()
76 return self.p.getIds()
79 execState = self.e.getExecutorState()
81 # --- not clean, value from define.hxx (YACS::FINISHED)
86 self.run1 = threading.Thread(None, self.e.RunPy, "CORBAExec", (self.p,0,1,1))
91 def RunFromState(self, xmlFile):
92 execState = self.e.getExecutorState()
94 # --- not clean, value from define.hxx (YACS::FINISHED)
100 self.p.exUpdateState();
101 sp = loader.stateParser()
102 sl = loader.stateLoader(sp,self.p)
105 print "IO Error: ", ex
107 except ValueError,ex:
108 print "Caught ValueError Exception:",ex
110 except pilot.Exception,ex:
114 print "Unknown exception!"
116 if self.run1 is None:
117 self.run1 = threading.Thread(None, self.e.RunPy, "CORBAExec", (self.p,0,1,0))
122 def addObserver(self, obs, numid, event):
123 disp = SALOMERuntime.SALOMEDispatcher_getSALOMEDispatcher()
124 disp.addObserver(obs, numid, event)
127 def setExecMode(self, mode):
128 if mode == YACS_ORB.CONTINUE:
129 self.e.setExecMode(0)
131 if mode == YACS_ORB.STEPBYSTEP:
132 self.e.setExecMode(1)
134 if mode == YACS_ORB.STOPBEFORENODES:
135 self.e.setExecMode(2)
139 def setListOfBreakPoints(self, listOfBreakPoints):
140 self.e.setListOfBreakPoints(listOfBreakPoints)
143 def getTasksToLoad(self):
144 return self.e.getTasksToLoad()
146 def setStepsToExecute(self, listToExecute):
147 return self.e.setStepsToExecute(listToExecute)
149 def resumeCurrentBreakPoint(self):
150 return self.e.resumeCurrentBreakPoint()
152 def isNotFinished(self):
153 return self.e.isNotFinished()
155 def stopExecution(self):
156 self.e.stopExecution()
159 def saveState(self, xmlFile):
160 return self.e.saveState(xmlFile)
162 def setStopOnError(self, dumpRequested, xmlFile):
163 self.e.setStopOnError(dumpRequested, xmlFile)
166 def unsetStopOnError(self):
167 self.e.unsetStopOnError()
173 class YACS(YACS_ORB__POA.YACS_Gen,
174 SALOME_ComponentPy.SALOME_ComponentPy_i,
175 SALOME_DriverPy.SALOME_DriverPy_i):
177 To be a SALOME component, this Python class must have the component name
178 (YACS) and inherit the YACS_Gen class build from idl compilation
179 with omniidl and also the class SALOME_ComponentPy_i which defines general
180 SALOME component behaviour.
182 def __init__ ( self, orb, poa, contID, containerName, instanceName,
184 print "YACS.__init__: ", containerName, ';', instanceName
185 SALOME_ComponentPy.SALOME_ComponentPy_i.__init__(self, orb, poa, contID,
186 containerName, instanceName,
188 SALOME_DriverPy.SALOME_DriverPy_i.__init__(self, interfaceName)
190 # --- store a naming service interface instance in _naming_service atribute
191 self._naming_service = SALOME_ComponentPy.SALOME_NamingServicePy_i( self._orb )
194 SALOMERuntime.RuntimeSALOME_setRuntime(1)
195 SALOMERuntime.SALOMEDispatcher_setSALOMEDispatcher()
198 def LoadProc(self,xmlFile):
200 load an XML graph in a YACS::ENGINE::proc, create a CORBA servant
201 associated to the proc, and return a ref on the servant.
204 procExec_i = proc_i(xmlFile)
205 logger=procExec_i.p.getLogger("parser")
206 if not logger.isEmpty():
207 print "The imported file has errors :"
208 print logger.getStr()
212 print >> sys.stderr ,"IO Error: ", ex
214 except ValueError,ex:
215 print >> sys.stderr ,"Caught ValueError Exception:",ex
217 except pilot.Exception,ex:
218 print >> sys.stderr ,ex.what()
221 traceback.print_exc()
223 procExec_o = procExec_i._this()
226 def convertSupervFile(self,xmlFile):
228 load a SUPERV xml graph, convert it and return the new filename.
231 r = pilot.getRuntime()
232 lo = salomeloader.SalomeLoader()
233 e = pilot.ExecutorSwig()
235 s = pilot.SchemaSave(p)
236 hnd, convertedFile = tempfile.mkstemp(".xml","yacs_","/tmp")
237 s.save(convertedFile)