Salome HOME
Merge branch 'omu/update_doc_77'
[modules/yacs.git] / src / genericgui / GuiExecutor.cxx
index 0b857e80ffdc33262f0d5f96720c8ffbc70398d1..4bd977c69451a22148d5ac76b68957558d519ee6 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2006-2013  CEA/DEN, EDF R&D
+// Copyright (C) 2006-2015  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -279,8 +279,12 @@ void GuiExecutor::saveState(const std::string& xmlFile)
   bool StartFinish = (getExecutorState() == YACS::NOTYETINITIALIZED ||
                       getExecutorState() == YACS::FINISHED);
   if ( _isRunning ||
-       !(CORBA::is_nil(_procRef)) && StartFinish )
-    _procRef->saveState(xmlFile.c_str());
+       !(CORBA::is_nil(_procRef)) && StartFinish ) {
+    if ( !_procRef->saveState(xmlFile.c_str()) ) {
+      string what = "Impossible to open file for writing: " + xmlFile;
+      throw Exception(what);
+    }
+  }
 }
 
 void GuiExecutor::setLoadStateFile(std::string xmlFile)
@@ -392,6 +396,7 @@ void GuiExecutor::registerStatusObservers()
   for ( std::list<Node*>::iterator it = aNodeSet.begin(); it != aNodeSet.end(); it++ )
     {
       _procRef->addObserver(_observerRef, _serv->getEngineId((*it)->getNumId()) , "status");
+      _procRef->addObserver(_observerRef, _serv->getEngineId((*it)->getNumId()) , "progress");
     }
   _procRef->addObserver(_observerRef, _serv->getEngineId(_proc->getNumId()) , "executor"); 
 }
@@ -519,32 +524,39 @@ bool GuiExecutor::event(QEvent *e)
       SubjectNode *snode = _context->_mapOfExecSubjectNode[iGui];
       DEBTRACE("node " << snode->getName() << " state=" << state);
 
-      YACS::ENGINE::Node *node = snode->getNode();
-      list<InputPort*> inports = node->getLocalInputPorts();
-      list<InputPort*>::iterator iti = inports.begin();
-      for ( ; iti != inports.end(); ++iti)
-        {
-          string val = _procRef->getInPortValue(numid, (*iti)->getName().c_str());
-          DEBTRACE("node " << snode->getName() << " inport " << (*iti)->getName() 
-                   << " value " << val);
-          YASSERT(_context->_mapOfSubjectDataPort.count(*iti));
-          SubjectDataPort* port = _context->_mapOfSubjectDataPort[*iti];
-          port->setExecValue(val);
-          port->update(YACS::HMI::UPDATEPROGRESS, 0, port);
-        }
-      list<OutputPort*> outports = node->getLocalOutputPorts();
-      list<OutputPort*>::iterator ito = outports.begin();
-      for ( ; ito != outports.end(); ++ito)
-        {
-          string val = _procRef->getOutPortValue(numid, (*ito)->getName().c_str());
-          DEBTRACE("node " << snode->getName() << " outport " << (*ito)->getName() 
-                   << " value " << val);
-          YASSERT(_context->_mapOfSubjectDataPort.count(*ito));
-          SubjectDataPort* port = _context->_mapOfSubjectDataPort[*ito];
-          port->setExecValue(val);
-          port->update(YACS::HMI::UPDATEPROGRESS, 0, port);
-        }
-      snode->update(YACS::HMI::UPDATEPROGRESS, state, snode);
+      if (event == "progress") { // --- Update progress bar
+        std::string progress = _procRef->getNodeProgress(numid);
+        snode->setProgress( progress );
+        snode->update(YACS::HMI::PROGRESS, state, snode);
+      }
+      else { // --- Update node ports
+        YACS::ENGINE::Node *node = snode->getNode();
+        list<InputPort*> inports = node->getLocalInputPorts();
+        list<InputPort*>::iterator iti = inports.begin();
+        for ( ; iti != inports.end(); ++iti)
+          {
+            string val = _procRef->getInPortValue(numid, (*iti)->getName().c_str());
+            DEBTRACE("node " << snode->getName() << " inport " << (*iti)->getName() 
+                     << " value " << val);
+            YASSERT(_context->_mapOfSubjectDataPort.count(*iti));
+            SubjectDataPort* port = _context->_mapOfSubjectDataPort[*iti];
+            port->setExecValue(val);
+            port->update(YACS::HMI::UPDATEPROGRESS, 0, port);
+          }
+        list<OutputPort*> outports = node->getLocalOutputPorts();
+        list<OutputPort*>::iterator ito = outports.begin();
+        for ( ; ito != outports.end(); ++ito)
+          {
+            string val = _procRef->getOutPortValue(numid, (*ito)->getName().c_str());
+            DEBTRACE("node " << snode->getName() << " outport " << (*ito)->getName() 
+                     << " value " << val);
+            YASSERT(_context->_mapOfSubjectDataPort.count(*ito));
+            SubjectDataPort* port = _context->_mapOfSubjectDataPort[*ito];
+            port->setExecValue(val);
+            port->update(YACS::HMI::UPDATEPROGRESS, 0, port);
+          }
+        snode->update(YACS::HMI::UPDATEPROGRESS, state, snode);
+      }
    }
 
   return true;