Salome HOME
Implementation of 0022326: [CEA 930] YACS: progression of a loop "ForEach"
authoralexander.kovalev <alexander.kovalev@opencascade.com>
Wed, 12 Feb 2014 09:11:01 +0000 (13:11 +0400)
committeralexander.kovalev <alexander.kovalev@opencascade.com>
Wed, 12 Feb 2014 09:11:01 +0000 (13:11 +0400)
27 files changed:
idl/yacsgui.idl
src/engine/ComposedNode.hxx
src/engine/ForEachLoop.cxx
src/engine/ForEachLoop.hxx
src/engine/ForLoop.cxx
src/engine/ForLoop.hxx
src/engine/Proc.cxx
src/engine/Proc.hxx
src/genericgui/CMakeLists.txt
src/genericgui/GenericGui.cxx
src/genericgui/GuiExecutor.cxx
src/genericgui/Resource.cxx
src/genericgui/Resource.hxx
src/genericgui/SceneComposedNodeItem.cxx
src/genericgui/SceneHeaderNodeItem.cxx
src/genericgui/SceneHeaderNodeItem.hxx
src/genericgui/SceneItem.cxx
src/genericgui/SceneItem.hxx
src/genericgui/SceneNodeItem.cxx
src/genericgui/SceneNodeItem.hxx
src/genericgui/SceneProgressItem.cxx [new file with mode: 0644]
src/genericgui/SceneProgressItem.hxx [new file with mode: 0644]
src/hmi/guiObservers.cxx
src/hmi/guiObservers.hxx
src/salomegui/Yacsgui_Resource.cxx
src/salomegui/resources/SalomeApp.xml.in
src/yacsorb/YACS.py

index 6ac3beb0ea967f68699ee12e052abd70b85736f1..577538abf56a4548b41b7f2396ddef8342d370a9 100644 (file)
@@ -41,6 +41,7 @@ module YACS_ORB
   interface ProcExec
   {
     long getNodeState(in long numid);
+    string getNodeProgress(in long numid);
     string getXMLState(in long numid);
     string getInPortValue(in long nodeNumid, in string portName);
     string setInPortValue(in string nodeName, in string portName, in string value);
index 9f1780bfc0bf9890289e6ed48817e3cd23fa4f3a..9b9414ddfb50436535dba7ada6c4f00f2aaf8d7d 100644 (file)
@@ -118,6 +118,7 @@ namespace YACS
       void connected();
       void accept(Visitor *visitor);
       virtual void cleanNodes();
+      virtual std::string getProgress() const {return "0";};
     protected:
       struct SortHierarc
       {
index 29cf49595c8f4fefe35ae6873793d6119c89f80a..9f277975fe3e8ef3bd88a5275e48a5c04d582ab8 100644 (file)
@@ -293,13 +293,13 @@ void FakeNodeForForEachLoop::finished()
 
 ForEachLoop::ForEachLoop(const std::string& name, TypeCode *typeOfDataSplitted):DynParaLoop(name,typeOfDataSplitted),
                                                                                 _splitterNode(NAME_OF_SPLITTERNODE,typeOfDataSplitted,this),
-                                                                                _execCurrentId(0),_nodeForSpecialCases(0)
+                                                                                _execCurrentId(0),_nodeForSpecialCases(0),_currentIndex(0)
 {
 }
 
 ForEachLoop::ForEachLoop(const ForEachLoop& other, ComposedNode *father, bool editionOnly):DynParaLoop(other,father,editionOnly),
                                                                                            _splitterNode(other._splitterNode,this),
-                                                                                           _execCurrentId(0),_nodeForSpecialCases(0)
+                                                                                           _execCurrentId(0),_nodeForSpecialCases(0),_currentIndex(0)
 {
   int i=0;
   if(!editionOnly)
@@ -334,6 +334,8 @@ void ForEachLoop::init(bool start)
   _splitterNode.init(start);
   _execCurrentId=0;
   cleanDynGraph();
+  _currentIndex = 0;
+  exUpdateProgress();
 }
 
 void ForEachLoop::exUpdateState()
@@ -435,6 +437,12 @@ void ForEachLoop::exUpdateState()
     }
 }
 
+void ForEachLoop::exUpdateProgress()
+{
+  // emit notification to all observers registered with the dispatcher on any change of the node's state
+  sendEvent("progress");
+}
+
 void ForEachLoop::getReadyTasks(std::vector<Task *>& tasks)
 {
   if(!_node)
@@ -541,6 +549,8 @@ YACS::Event ForEachLoop::updateStateOnFinishedEventFrom(Node *node)
       if (_initializingCounter == 0) _initNode->setState(DONE);
       break;
     case WORK_NODE:
+      _currentIndex++;
+      exUpdateProgress();
       storeOutValsInSeqForOutOfScopeUse(_execIds[id],id);
       if(_execCurrentId==_splitterNode.getNumberOfElements())
         {//No more elements of _dataPortToDispatch to treat
@@ -618,6 +628,8 @@ YACS::Event ForEachLoop::updateStateOnFinishedEventFrom(Node *node)
     {
       DEBTRACE("Finalize node finished on branch " << id);
       _unfinishedCounter--;
+      _currentIndex++;
+      exUpdateProgress();
       DEBTRACE(_unfinishedCounter << " finalize nodes still running");
       if (_unfinishedCounter == 0)
         {
@@ -826,3 +838,14 @@ void ForEachLoop::resetState(int level)
   //Note: cleanDynGraph is not a virtual method (must be called from ForEachLoop object) 
   cleanDynGraph();
 }
+
+std::string ForEachLoop::getProgress() const
+{
+  int nbElems = _splitterNode.getNumberOfElements();
+  char* aProgress = new char[];
+  if (nbElems > 0)
+    sprintf(aProgress, "%i/%i", _currentIndex, nbElems);
+  else
+    sprintf(aProgress, "0");
+  return aProgress;
+}
index 6aacd34c6630b3ec9b0688482c50d8d4155d11bc..7648f89e85aab207d759c30c7775e65e926e9087 100644 (file)
@@ -133,6 +133,7 @@ namespace YACS
     protected:
       static const int NOT_RUNNING_BRANCH_ID;
     protected:
+      int _currentIndex;
       SplitterNode _splitterNode;
       FakeNodeForForEachLoop *_nodeForSpecialCases;
       std::vector<AnySplitOutputPort *> _outGoingPorts;//! ports linked to node outside the current scope
@@ -147,6 +148,7 @@ namespace YACS
       ~ForEachLoop();
       void init(bool start=true);
       void exUpdateState();
+      void exUpdateProgress();
       void getReadyTasks(std::vector<Task *>& tasks);
       int getNumberOfInputPorts() const;
       //
@@ -166,6 +168,7 @@ namespace YACS
       void writeDot(std::ostream &os) const;
       virtual std::string typeName() {return "YACS__ENGINE__ForEachLoop";}
       virtual void resetState(int level);
+      std::string getProgress() const;
     protected:
       Node *simpleClone(ComposedNode *father, bool editionOnly=true) const;
       void checkLinkPossibility(OutPort *start, const std::list<ComposedNode *>& pointsOfViewStart,
index 36511f266f15d5903808c65f316c0ffed11605bd..30fcb66ea13d5ee510b9b223a13419bdbdfe9d8f 100644 (file)
@@ -91,6 +91,7 @@ void ForLoop::init(bool start)
   Any* tmp=AtomAny::New(_nbOfTurns);
   _indexPort.put(tmp);
   tmp->decrRef();
+  exUpdateProgress();
 }
 
 //! Update the state of the for loop
@@ -145,6 +146,7 @@ void ForLoop::exUpdateState()
 YACS::Event ForLoop::updateStateOnFinishedEventFrom(Node *node)
 {
   DEBTRACE("ForLoop::updateStateOnFinishedEventFrom " << node->getName());
+  exUpdateProgress();
   if((++_nbOfTurns)>=_nbOfTimesPort.getIntValue())
     {
       setState(YACS::DONE);
@@ -162,6 +164,12 @@ YACS::Event ForLoop::updateStateOnFinishedEventFrom(Node *node)
   return YACS::NOEVENT;
 }
 
+void ForLoop::exUpdateProgress()
+{
+  // emit notification to all observers registered with the dispatcher on any change of the node's state
+  sendEvent("progress");
+}
+
 void ForLoop::accept(Visitor *visitor)
 {
   visitor->visitForLoop(this);
@@ -257,3 +265,16 @@ std::list<OutputPort *> ForLoop::getSetOfOutputPort() const
   return ret;
 }
 
+std::string ForLoop::getProgress() const
+{
+  char* aProgress = new char[];
+  sprintf(aProgress, "0");
+  AnyInputPort* aNbStepsPort = (AnyInputPort*)&_nbOfTimesPort;
+  if (aNbStepsPort && !aNbStepsPort->isEmpty()) {
+    int nbSteps = aNbStepsPort->getIntValue();
+    if (nbSteps > 0 && _nbOfTurns >= 0) {
+      sprintf(aProgress, "%i/%i", _nbOfTurns, nbSteps);
+    }
+  }
+  return aProgress;
+}
index 82c1d9f6bfdbe60adb45ca8c5426fde1a258c319..bd580f997b7a61a459ecf9ad4986a16d67b6189b 100644 (file)
@@ -40,6 +40,7 @@ namespace YACS
       ForLoop(const ForLoop& other, ComposedNode *father, bool editionOnly);
       ForLoop(const std::string& name);
       void exUpdateState();
+      void exUpdateProgress();
       void init(bool start=true);
       InputPort *edGetNbOfTimesInputPort() { return &_nbOfTimesPort; }
       Node *simpleClone(ComposedNode *father, bool editionOnly=true) const;
@@ -53,6 +54,7 @@ namespace YACS
       InputPort *getDecisionPort() const { return (InputPort *)&_nbOfTimesPort; }
       OutputPort *edGetIndexPort() { return &_indexPort; }
       virtual std::string typeName() {return "YACS__ENGINE__ForLoop";}
+      std::string getProgress() const;
     protected:
       YACS::Event updateStateOnFinishedEventFrom(Node *node);
       void checkCFLinks(const std::list<OutPort *>& starts, InputPort *end, unsigned char& alreadyFed,
index 990b80f8c87c8d9d15649b28c6ef05e329b73cc3..584e336a5eba040995f1ec64c9fc1ef10a2393a4 100644 (file)
@@ -221,6 +221,18 @@ YACS::StatesForNode Proc::getNodeState(int numId)
   return state;
 }
 
+std::string Proc::getNodeProgress(int numId)
+{
+  std::string progress = "0";
+  if(YACS::ENGINE::Node::idMap.count(numId) == 0)
+    {
+      cerr << "Unknown node id " << numId << endl;
+    }
+  else if (YACS::ENGINE::ComposedNode* node = dynamic_cast<YACS::ENGINE::ComposedNode*>(YACS::ENGINE::Node::idMap[numId]))
+    progress = node->getProgress();
+  return progress;
+}
+
 std::string Proc::getXMLState(int numId)
 {
   if(YACS::ENGINE::Node::idMap.count(numId) == 0)
index 1da58cad32183f80643e553df8bfdb5fd439f342..5300ce684e8883f4f6709c31729d855045924edf 100644 (file)
@@ -65,6 +65,7 @@ namespace YACS
       virtual const Proc * getProc() const;
 
       YACS::StatesForNode getNodeState(int numId);
+      std::string Proc::getNodeProgress(int numId);
       std::string getInPortValue(int nodeNumId, std::string portName);
       std::string setInPortValue(std::string nodeName, std::string portName, std::string value);
       std::string getOutPortValue(int nodeNumId, std::string portName);
index 1174e762f70c43debdcf32f661662a91dd8b3149..466e06b989872fa638ca1c95ba415769bcc2563b 100644 (file)
@@ -308,6 +308,8 @@ SET(GenericGui_SOURCES
   ScenePortItem.cxx               
   SceneProcItem.hxx               
   SceneProcItem.cxx               
+  SceneProgressItem.hxx
+  SceneProgressItem.cxx
   SceneTextItem.hxx               
   SceneTextItem.cxx               
   SchemaComponentItem.hxx         
index 11f87b006f099f59331246ef9e847aa6a19ae124..92db4a50fe674cfb896979684a394718da596eb8 100644 (file)
@@ -1213,6 +1213,7 @@ void GenericGui::setLoadedPresentation(YACS::ENGINE::Proc* proc)
 {
   DEBTRACE("GenericGui::setLoadedPresentation");
   QtGuiContext::getQtCurrent()->setLoadingPresentation(true);
+  map<SceneNodeItem*, QPointF> nodesToMove;
   map<YACS::ENGINE::Node*, PrsData> presNodes = _loader->getPrsData(proc);
   if (!presNodes.empty())
     {
@@ -1233,8 +1234,24 @@ void GenericGui::setLoadedPresentation(YACS::ENGINE::Proc* proc)
           inode->setExpandedPos(QPointF(pres._expx, pres._expy));
           inode->setExpandedWH(pres._expWidth, pres._expHeight);
           inode->setShownState(shownState(pres._shownState));
+
+          // collect nodes to correct it's Y-position if this collides with parent's header
+          if (inode->getParent() && inode->y() < inode->getParent()->getHeaderBottom())
+            nodesToMove[inode] = QPointF(inode->x(), inode->getParent()->getHeaderBottom()+1);
         }
     }
+  QtGuiContext::getQtCurrent()->setLoadingPresentation(false);
+  
+  //after loading of presentation:
+
+  //move nodes because of progress bar, if any was added
+  map<SceneNodeItem*, QPointF>::iterator it = nodesToMove.begin();
+  for (; it!= nodesToMove.end(); ++it)
+    {
+      (*it).first->setTopLeft((*it).second);
+    }
+
+  //update links
   if (Scene::_autoComputeLinks)
     _guiEditor->rebuildLinks();
   else
@@ -1244,8 +1261,6 @@ void GenericGui::setLoadedPresentation(YACS::ENGINE::Proc* proc)
       SceneComposedNodeItem *proc = dynamic_cast<SceneComposedNodeItem*>(item);
       proc->updateLinks();
     }
-
-  QtGuiContext::getQtCurrent()->setLoadingPresentation(false);
 }
 
 // -----------------------------------------------------------------------------
index 0b857e80ffdc33262f0d5f96720c8ffbc70398d1..b1ca2d285360c2bd568bb326c18f1ff2491e9b9e 100644 (file)
@@ -392,6 +392,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 +520,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;
index 7ed0121859389d8d6fb459d46d2a18a20c3d6a3f..ae6b06310f4abadb8ed291b8bcb26b97ab57f442 100644 (file)
@@ -33,6 +33,8 @@ bool Resource::autoComputeLinks = AUTOCOMPUTELINKS;
 bool Resource::simplifyLink = SIMPLIFYLINK;
 bool Resource::ensureVisibleWhenMoved = ENSUREVISIBLEWHENMOVED;
 int Resource::dockWidgetPriority = DOCKWIDGETPRIORITY;
+QColor Resource::progressBarColor = PROGRESSBARCOLOR;
+int Resource::progressBarLabel = PROGRESSBARLABEL;
 QFont  Resource::pythonfont = PYTHONFONT;
 
 // Statics for color of states
@@ -144,6 +146,8 @@ int Resource::Corner_Margin   = ( Resource::Border_Margin + Resource::Space_Marg
 int Resource::Header_Height   = ( Resource::Corner_Margin + Resource::CtrlPort_Height + Resource::Line_Space + Resource::Line_Width + Resource::Line_Space );
 int Resource::Radius          =  3;
 
+int Resource::progressBar_Height =  20;
+
 bool Resource::tabPanelsUp = TABPANELSUP;
 
 // Constructor
index 25d54916e31441ee8257f8f9a6909b2a2eb85f45..623bd6caf4227b984a0982bbb18fdfd81c16664f 100644 (file)
 #define ENSUREVISIBLEWHENMOVED  true
 #define TABPANELSUP             true
 #define DOCKWIDGETPRIORITY      0
+#define PROGRESSBARCOLOR        Qt::darkGreen
+#define PROGRESSBARLABEL        2
 
 #define EDITEDNODEBRUSHCOLOR    QColor(255, 255, 190)
 #define NORMALNODEBRUSHCOLOR    QColor(230, 235, 255)
@@ -210,6 +212,8 @@ namespace YACS {
         static bool simplifyLink;
         static bool ensureVisibleWhenMoved;
         static int  dockWidgetPriority;
+        static QColor progressBarColor;
+        static int    progressBarLabel;
 
         // Colors of state of nodes
         static QColor editedNodeBrushColor;
@@ -315,6 +319,8 @@ namespace YACS {
         static int Header_Height;
         static int Radius;
 
+        static int progressBar_Height;
+
         static bool tabPanelsUp;
     };
   }
index 83f89e5e1b36bf158743b873956fe5f509fdebf1..a85b2f4e1bfc929e8408f4fc6d6f4f9630b74c61 100644 (file)
@@ -30,6 +30,7 @@
 #include "SceneLinkItem.hxx"
 #include "SceneDSLinkItem.hxx"
 #include "SceneCtrlLinkItem.hxx"
+#include "SceneProgressItem.hxx"
 #include "LinkMatrix.hxx"
 #include "LinkAStar.hxx"
 #include "ItemMimeData.hxx"
@@ -144,6 +145,11 @@ void SceneComposedNodeItem::update(GuiEvent event, int type, Subject* son)
                                             son->getName().c_str(),
                                             son);
           item->addHeader();
+          if ( !QtGuiContext::getQtCurrent()->isEdition()
+            && (type == YACS::HMI::FORLOOP || type == YACS::HMI::FOREACHLOOP) )
+            {
+              item->addProgressItem();
+            }
           autoPosNewChild(item, _children, true);
           break;
         case YACS::HMI::PYTHONNODE:
@@ -316,6 +322,15 @@ void SceneComposedNodeItem::update(GuiEvent event, int type, Subject* son)
         autoPosNewChild(sinode, _children, true);
       }
       break;
+    case PROGRESS:
+      {
+        if (dynamic_cast<SubjectForLoop*>(son) || dynamic_cast<SubjectForEachLoop*>(son))
+        {
+          if (SceneProgressItem* spitem = getProgressItem())
+            spitem->setProgress(son->getProgress().c_str());
+        }
+      }
+      break;
     default:
        ;
 //       DEBTRACE("SceneComposedNodeItem::update(), event not handled: "<< eventName(event));
@@ -464,6 +479,8 @@ void SceneComposedNodeItem::shrinkExpandRecursive(bool isExpanding, bool fromHer
       else
         setPos(_expandedPos);
       adjustHeader();
+      if (_progressItem)
+        _progressItem->adjustGeometry();
     }
   else
     { // --- expanding: resize, then show children
@@ -500,6 +517,8 @@ void SceneComposedNodeItem::shrinkExpandRecursive(bool isExpanding, bool fromHer
         }
       setPos(_expandedPos);
       adjustHeader();
+      if (_progressItem)
+        _progressItem->adjustGeometry();
     }
 }
 
@@ -538,6 +557,8 @@ void SceneComposedNodeItem::setShownState(shownState ss)
       show();
     }
   adjustHeader();
+  if (_progressItem)
+    _progressItem->adjustGeometry();
 }
 
 void SceneComposedNodeItem::collisionResolv(SceneItem* child, QPointF oldPos)
index 67c5801d435c9c82bda63006d4d3d7a27f788667..a58790d9851e65f5808e264dead8d79ceae63475 100644 (file)
@@ -47,6 +47,7 @@ SceneHeaderNodeItem::SceneHeaderNodeItem(QGraphicsScene *scene, SceneItem *paren
                                          QString label)
   : SceneHeaderItem(scene, parent, label)
 {
+   _fatherNode= dynamic_cast<SceneNodeItem*>(parent);
   _width  = 2*Resource::Corner_Margin + 2*Resource::DataPort_Width + Resource::Space_Margin;
   _height = Resource::Header_Height;
   _maxPorts = 0;
@@ -92,6 +93,8 @@ void SceneHeaderNodeItem::paint(QPainter *painter,
 
   int x = Resource::Border_Margin + 1;
   int y = Resource::Header_Height - Resource::Line_Space;
+  if (_fatherNode && _fatherNode->hasProgressBar())
+    y += Resource::progressBar_Height;
   int w = Resource::Corner_Margin + 2*Resource::DataPort_Width + 2*Resource::Space_Margin;
   if (_parent->getWidth() > w) w = _parent->getWidth() - Resource::Border_Margin;
   QPen pen(getPenColor());
@@ -106,8 +109,7 @@ void SceneHeaderNodeItem::paint(QPainter *painter,
   pen.setWidth(Resource::Thickness);
   painter->setPen(pen);
   
-  SceneNodeItem* father = dynamic_cast<SceneNodeItem*>(_parent);
-  bool expanded = (father && father->isExpanded());
+  bool expanded = (_fatherNode && _fatherNode->isExpanded());
   QColor baseColor = getBrushColor();
   if (expanded)
     painter->setBrush(baseColor);
@@ -139,11 +141,13 @@ void SceneHeaderNodeItem::setText(QString label)
 
 qreal SceneHeaderNodeItem::getHeaderBottom() const
 {
+  qreal res = 0;
   if (_hasHeader) {
-    return Resource::Header_Height + _maxPorts * (Resource::DataPort_Height + Resource::Space_Margin);
-  } else {
-    return 0;
-  };
+    res += Resource::Header_Height + _maxPorts * (Resource::DataPort_Height + Resource::Space_Margin);
+    if (_fatherNode && _fatherNode->hasProgressBar())
+      res += Resource::progressBar_Height;
+  }
+  return res;
 }
 
 void SceneHeaderNodeItem::autoPosControl(AbstractSceneItem *item)
@@ -171,6 +175,8 @@ void SceneHeaderNodeItem::autoPosNewPort(AbstractSceneItem *item)
     _outPorts.push_back(dynamic_cast<SceneOutPortItem*>(item));
   };
   qreal yTop   = Resource::Header_Height;
+  if (_fatherNode && _fatherNode->hasProgressBar())
+    yTop += Resource::progressBar_Height;
   qreal deltaY = Resource::DataPort_Height + Resource::Space_Margin;
   yTop += nbPorts * deltaY;
   if (nbPorts >=_maxPorts) {
@@ -188,10 +194,12 @@ void SceneHeaderNodeItem::reorganizePorts(shownState ss)
 
   qreal yTop;
   qreal href = Resource::Header_Height;
+  if (_fatherNode && _fatherNode->hasProgressBar())
+    href += Resource::progressBar_Height;
   bool isShown = (ss != shrinkHidden);
   if (!isShown) href = Resource::Corner_Margin;
 
-std::list<SceneInPortItem*>::iterator iti = _inPorts.begin();
+  std::list<SceneInPortItem*>::iterator iti = _inPorts.begin();
   int nbPorts = 0;
   for (; iti != _inPorts.end(); ++iti)
     {
@@ -238,9 +246,8 @@ void SceneHeaderNodeItem::adjustGeometry()
 
 void SceneHeaderNodeItem::adjustPosPorts()
 {
-  SceneNodeItem* father = dynamic_cast<SceneNodeItem*>(_parent);
-  YASSERT(father);
-  shownState ss = father->getShownState();
+  YASSERT(_fatherNode);
+  shownState ss = _fatherNode->getShownState();
   if (_controlOut)
     {
       int x = Resource::Corner_Margin + 2*Resource::DataPort_Width + Resource::Space_Margin;
@@ -258,6 +265,8 @@ QRectF SceneHeaderNodeItem::getMinimalBoundingRect() const
   int nbPorts  = _inPorts.size();
   if (_outPorts.size() > nbPorts) nbPorts = _outPorts.size();
   if (nbPorts) height += nbPorts*(Resource::DataPort_Height + Resource::Space_Margin);
+  if (_fatherNode && _fatherNode->hasProgressBar())
+    height += Resource::progressBar_Height;
   //DEBTRACE(nbPorts << " " << width << " " << height);
   return QRectF(x(), y(), width, height);
 }
index 99b26db09ba83a5bee992e23a3d228e0553965e1..a22357da72cb154f6149b021d21c1800f7094c17 100644 (file)
@@ -62,6 +62,7 @@ namespace YACS
       virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
       virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
 
+      SceneNodeItem* _fatherNode;
       SceneHeaderItem *_header;
       SceneCtrlPortItem *_controlIn;
       SceneCtrlPortItem *_controlOut;
index e0a6b0a10554e9670396348d2c5d9bebff7167a7..80872f39e698193978fb4d63c94b0d9e2b3d451f 100644 (file)
@@ -141,10 +141,15 @@ void AbstractSceneItem::addHeader()
 {
 }
 
+void AbstractSceneItem::addProgressItem()
+{
+}
+
 qreal AbstractSceneItem::getHeaderBottom()
 {
   return 0;
 }
+
 qreal AbstractSceneItem::getWidth()
 {
   return _width;
index aeedd699540ca9a9bd2e3f9c25a09af72c868708..26f19e79626c99ea0f032c6d1957b9366118982f 100644 (file)
@@ -73,6 +73,7 @@ namespace YACS
       virtual void reorganize();
       virtual QString getLabel();
       virtual void addHeader();
+      virtual void addProgressItem();
       virtual qreal getHeaderBottom();
       qreal getWidth();
       qreal getHeight();
@@ -132,6 +133,8 @@ namespace YACS
       virtual void shrinkExpandLink(bool se);
       virtual void shrinkExpandRecursive(bool isExpanding, bool fromHere);
       bool isAncestorShrinked() { return _ancestorShrinked; };
+      bool _blocX;
+      bool _blocY;
 
     protected:
 //       virtual bool sceneEvent(QEvent *event);
index 844ec6681bbcfa5287222abe1ac699f4a7e9a922..0a528615a882821181195a18514bf5c25e6d98f1 100644 (file)
@@ -21,6 +21,7 @@
 #include "SceneComposedNodeItem.hxx"
 #include "SceneProcItem.hxx"
 #include "SceneHeaderNodeItem.hxx"
+#include "SceneProgressItem.hxx"
 #include "SceneInPortItem.hxx"
 #include "SceneOutPortItem.hxx"
 #include "SceneCtrlInPortItem.hxx"
@@ -58,6 +59,7 @@ SceneNodeItem::SceneNodeItem(QGraphicsScene *scene, SceneItem *parent,
   _inPorts.clear();
   _outPorts.clear();
   _header = 0;
+  _progressItem = 0;
   _brushColor = Resource::Scene_pen;
   _moving = false;
   _moved = false;
@@ -121,6 +123,20 @@ SceneHeaderItem* SceneNodeItem::getHeader()
   return _header;
 }
 
+void SceneNodeItem::addProgressItem()
+{
+  DEBTRACE("SceneNodeItem::addProgressItem ");
+  if (!_progressItem)
+    {
+      _progressItem = new SceneProgressItem(_scene,
+                                        this,
+                                        "progress");
+      _progressItem->setText("0");
+      updateState();
+      checkGeometryChange();
+    }
+}
+
 void SceneNodeItem::paint(QPainter *painter,
                           const QStyleOptionGraphicsItem *option,
                           QWidget *widget)
@@ -441,3 +457,8 @@ void SceneNodeItem::setShownState(shownState ss)
 {
   _shownState = ss;
 }
+
+bool SceneNodeItem::hasProgressBar() const
+{
+  return _progressItem != 0;
+}
index 8f3b58e0e6befae99e30bcbb66ae52e0083a3355..46a76a88a991674d003447cf318a89e6999e1a8b 100644 (file)
@@ -39,6 +39,7 @@ namespace YACS
     class SceneHeaderNodeItem;
     class SceneComposedNodeItem;
     class ScenePortItem;
+    class SceneProgressItem;
 
     class SceneNodeItem: public SceneObserverItem
     {
@@ -51,6 +52,8 @@ namespace YACS
       virtual void setHeight(qreal height);
       virtual void addHeader();
       virtual SceneHeaderItem* getHeader();
+      virtual void addProgressItem();
+      virtual SceneProgressItem* getProgressItem() { return _progressItem; };
       virtual void paint(QPainter *painter,
                          const QStyleOptionGraphicsItem *option,
                          QWidget *widget);
@@ -85,8 +88,7 @@ namespace YACS
       qreal getExpandedWidth() { return _expandedWidth; };
       qreal getExpandedHeight() { return _expandedHeight; };
       shownState getShownState() {return _shownState; };
-      bool _blocX;
-      bool _blocY;
+      bool hasProgressBar() const;
 
     protected:
       virtual QString getMimeFormat();
@@ -102,6 +104,7 @@ namespace YACS
       std::list<AbstractSceneItem*> _inPorts;
       std::list<AbstractSceneItem*> _outPorts;    
       SceneHeaderNodeItem *_header;
+      SceneProgressItem *_progressItem;
       int _execState;
       bool _moving;
       bool _moved;
diff --git a/src/genericgui/SceneProgressItem.cxx b/src/genericgui/SceneProgressItem.cxx
new file mode 100644 (file)
index 0000000..a54054a
--- /dev/null
@@ -0,0 +1,167 @@
+// Copyright (C) 2006-2013  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.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "SceneProgressItem.hxx"
+#include "SceneHeaderNodeItem.hxx"
+#include "SceneTextItem.hxx"
+#include "Scene.hxx"
+#include <QGraphicsSceneMouseEvent>
+
+#include "Resource.hxx"
+
+#include <cassert>
+
+//#define _DEVDEBUG_
+#include "YacsTrace.hxx"
+
+using namespace std;
+using namespace YACS::ENGINE;
+using namespace YACS::HMI;
+
+
+SceneProgressItem::SceneProgressItem(QGraphicsScene *scene, SceneItem *parent,
+                                 QString label)
+  : SceneItem(scene, parent, label)
+{
+  YASSERT(_parent);
+  _progress = 0;
+  _width  = Resource::Corner_Margin + 2*Resource::DataPort_Width + 2*Resource::Space_Margin;
+  _height = Resource::progressBar_Height;
+  _text=0;
+  _tooltip = "";
+  _brushColor   = Resource::Header_brush;
+  _hiBrushColor = Resource::Header_hiBrush;
+  _penColor     = Resource::Header_pen;
+  _hiPenColor   = Resource::Header_hiPen;
+  int x = Resource::Border_Margin;
+  int y = Resource::DataPort_Height + 2*Resource::Space_Margin;
+  setTopLeft(QPointF(x, y));
+}
+
+SceneProgressItem::~SceneProgressItem()
+{
+}
+
+QRectF SceneProgressItem::getMinimalBoundingRect() const
+{
+  return QRectF(x(), y(), _width, _height);
+}
+
+void SceneProgressItem::paint(QPainter *painter,
+                            const QStyleOptionGraphicsItem *option,
+                            QWidget *widget)
+{
+//   DEBTRACE("SceneProgressItem::paint");
+  painter->save();
+
+  int w = Resource::Corner_Margin + 2*Resource::DataPort_Width + 2*Resource::Space_Margin;
+  if (_parent->getWidth() > w) w = _parent->getWidth() - Resource::Corner_Margin - Resource::Space_Margin;
+  int h = Resource::progressBar_Height;
+  QPen pen(getPenColor());
+  pen.setWidth(Resource::Thickness);
+  painter->setPen(pen);
+  QRect boundRect(0, 0, w, h);
+  painter->drawRect(boundRect);
+  
+  painter->setBrush(Resource::progressBarColor);
+  //correct width according to progress
+  int corr_w = w * _progress / 100;
+  painter->drawRect(QRect(0, 0, corr_w, h));
+  painter->restore();
+}
+
+void SceneProgressItem::setProgress(QString newProgress)
+{
+  QString percentageLabel;
+  QString nbStepsLabel = "-/-";
+  QStringList aSteps = newProgress.split('/');
+  if (aSteps.count() == 2)
+  { //case '5/10' view of progress
+    _progress = aSteps.at(0).toInt() * 100 / aSteps.at(1).toInt();
+    nbStepsLabel = newProgress;
+  }
+  else
+  { //case '50' view of progress
+    _progress = newProgress.toInt(); //set 0 if the conversion fails.
+  }
+  percentageLabel = QString("%1\%").arg(_progress);
+  QString resultLabel;
+  switch(Resource::progressBarLabel)
+  {
+    case 0: //Percentage: 50%
+      resultLabel = QString("%1").arg(percentageLabel);
+      break;
+    case 1: //Nb.steps:   5/10
+      resultLabel = QString("%1").arg(nbStepsLabel);
+      break;
+    case 2: //Both:       50% (5/10)
+      resultLabel = QString("%1 (%2)").arg(percentageLabel).arg(nbStepsLabel);
+      break;
+  }
+  setText(resultLabel);
+  _tooltip = QString("%1 (%2)").arg(percentageLabel).arg(nbStepsLabel);
+  update();
+}
+
+void SceneProgressItem::setText(QString label)
+{
+  if (!_text)
+    _text = new SceneTextItem(_scene, this, label, true);
+  else
+    _text->setPlainTextTrunc(label);
+  //QGraphicsItem::update();
+}
+
+void SceneProgressItem::popupMenu(QWidget *caller, const QPoint &globalPos)
+{
+  if (_parent) _parent->popupMenu(caller, globalPos);
+}
+
+void SceneProgressItem::adjustGeometry()
+{
+  prepareGeometryChange();
+  _width = _parent->getWidth() - Resource::Corner_Margin - Resource::Space_Margin;
+  update();
+}
+
+QColor SceneProgressItem::getPenColor()
+{
+  return _hiPenColor;
+}
+
+QColor SceneProgressItem::getBrushColor()
+{
+  QColor color = _brushColor;
+  if (dynamic_cast<SceneHeaderNodeItem*>(this))
+    if (getParent()->isSelected())
+      color = _hiBrushColor;
+  if (_hover)
+    color = hoverColor(color);
+  return color;
+}
+
+void SceneProgressItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
+{
+  event->ignore();
+}
+
+QString SceneProgressItem::getToolTip()
+{
+  return _tooltip;;
+}
diff --git a/src/genericgui/SceneProgressItem.hxx b/src/genericgui/SceneProgressItem.hxx
new file mode 100644 (file)
index 0000000..77a42ca
--- /dev/null
@@ -0,0 +1,60 @@
+// Copyright (C) 2006-2013  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.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef _SCENEPROGRESSITEM_HXX_
+#define _SCENEPROGRESSITEM_HXX_
+
+#include "SceneItem.hxx"
+
+namespace YACS
+{
+  namespace HMI
+  {
+    class SceneTextItem;
+
+    class SceneProgressItem: public SceneItem
+    {
+    public:
+      SceneProgressItem(QGraphicsScene *scene, SceneItem *parent,
+                      QString label);
+      virtual ~SceneProgressItem();
+      virtual QRectF getMinimalBoundingRect() const;
+      virtual void paint(QPainter *painter,
+                         const QStyleOptionGraphicsItem *option,
+                         QWidget *widget);
+      virtual void setProgress(QString newProgress);
+      virtual int getProgress() { return _progress; };
+      virtual void setText(QString label);
+      virtual void popupMenu(QWidget *caller, const QPoint &globalPos);
+      virtual void adjustGeometry();
+
+    protected:
+      virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
+      virtual QString getToolTip();
+      QColor getPenColor();
+      QColor getBrushColor();
+      SceneTextItem* _text;
+      QString _tooltip;
+      int _progress;
+
+    };
+  }
+}
+
+#endif
index 01709dfacc2378eae08b4e324df83862161e81ce..2a767256dddd2271b7197280ac8c2f9fdd4a11de 100644 (file)
@@ -325,6 +325,11 @@ void Subject::addSubjectReference(Subject *ref)
   update(ADDREF, 0, son);
 }
 
+void Subject::setProgress( std::string newProgress )
+{
+  _progress = newProgress;
+}
+
 // ----------------------------------------------------------------------------
 
 GuiObserver::GuiObserver()
index 12e79257099473108317c3012fb8073307116254..535d29f922e770192820f533e51dd504898a139c 100644 (file)
@@ -104,7 +104,8 @@ namespace YACS
         SETSELECT,
         GEOMETRY,
         EMPHASIZE,
-        SWITCHSHAPE
+        SWITCHSHAPE,
+        PROGRESS
       } GuiEvent;
     
     class ProcInvoc;
@@ -139,11 +140,14 @@ namespace YACS
       bool isDestructible() { return _destructible; };
       static void erase(Subject* sub, Command *command=0, bool post=false);
       virtual TypeOfElem getType(){return UNKNOWN;}
+      virtual void setProgress( std::string newProgress );
+      virtual std::string getProgress() { return _progress; };
     protected:
       std::set<GuiObserver *> _setObs;
       Subject *_parent;
       bool _destructible;
       bool _askRegisterUndo;
+      std::string _progress;
     };
     
     class HMI_EXPORT GuiObserver
index e9822d4e566369c891357955e21be4fd18fd2f8a..862a76444f0b4007512ff330e519259db36ff888 100644 (file)
@@ -118,18 +118,26 @@ void Yacsgui_Resource::createPreferences(Yacsgui* swm)
   swm->addPreference( "Ensure Node Visible When Moved", presentationGroup, LightApp_Preferences::Bool, RESOURCE_YACS, "ensureVisibleWhenMoved" );
   swm->addPreference( "Tabified Panels Up", presentationGroup, LightApp_Preferences::Bool, RESOURCE_YACS, "tabPanelsUp" );
   int priority = swm->addPreference( "DockWidget priority", presentationGroup, LightApp_Preferences::Selector, RESOURCE_YACS, "dockWidgetPriority" );
+  swm->addPreference( "Progress bar color", presentationGroup, LightApp_Preferences::Color, RESOURCE_YACS, "progressBarColor" );
+  int progressLabel = swm->addPreference( "Progress bar label", presentationGroup, LightApp_Preferences::Selector, RESOURCE_YACS, "progressBarLabel" );
 
-  QStringList priorityList;
-  priorityList.append( "Horizontal" );
-  priorityList.append( "Vertical" );
-
+  QStringList stringsList;
+  stringsList.append( "Horizontal" );
+  stringsList.append( "Vertical" );
   QList<QVariant> indexesList;
   indexesList.append(0);
   indexesList.append(1);
-
-  swm->setPreferenceProperty( priority, "strings", priorityList );
+  swm->setPreferenceProperty( priority, "strings", stringsList );
   swm->setPreferenceProperty( priority, "indexes", indexesList );
 
+  stringsList.clear();
+  indexesList.clear();
+
+  stringsList << "Percentage: \"50%\"" << "Nb.steps: \"5/10\"" << "Both: \"50% (5/10)\"";
+  indexesList << 0 << 1 << 2;
+  swm->setPreferenceProperty( progressLabel, "strings", stringsList );
+  swm->setPreferenceProperty( progressLabel, "indexes", indexesList );
+
   int pythonGroup = swm->addPreference( "Python", genTab );
 
   swm->addPreference( "Python Script Font", pythonGroup, LightApp_Preferences::Font, RESOURCE_YACS, "font" );
@@ -286,6 +294,8 @@ void Yacsgui_Resource::preferencesChanged()
   Resource::ensureVisibleWhenMoved = booleanValue("ensureVisibleWhenMoved", ENSUREVISIBLEWHENMOVED);
   Resource::tabPanelsUp = booleanValue("tabPanelsUp", TABPANELSUP);
   Resource::dockWidgetPriority   = integerValue( "dockWidgetPriority" , DOCKWIDGETPRIORITY);
+  Resource::progressBarColor = colorValue("progressBarColor", PROGRESSBARCOLOR);
+  Resource::progressBarLabel = integerValue( "progressBarLabel" , PROGRESSBARLABEL);
 
   // Color of state of nodes
   Resource::editedNodeBrushColor = colorValue(_editedNodeBrushColor, EDITEDNODEBRUSHCOLOR);
index a82603ef9956b1625345b0a9243b459aa1b88726..d18e7c5aa100d6b406560c66ed9195d985973323 100644 (file)
@@ -45,6 +45,8 @@
     <parameter name="addRowCols" value="false" />
     <parameter name="ensureVisibleWhenMoved" value="true" />
     <parameter name="tabPanelsUp" value="true" />
+    <parameter name="progressBarColor" value="#008000" />
+    <parameter name="progressBarLabel" value="2" />
     <parameter name="documentation" value="yacs_help"/>
 
     <parameter name="editedNodeBrushColor" value="255, 255, 190" />
index 4d868dca8f45b4c3dfdd8bd58d4ab89b3499cb3f..488334d7a4339509a92f7edc04c18bef35f07e04 100644 (file)
@@ -46,6 +46,9 @@ class proc_i(YACS_ORB__POA.ProcExec):
     def getNodeState(self,numid):
         return self.p.getNodeState(numid)
 
+    def getNodeProgress(self,numid):
+        return self.p.getNodeProgress(numid)
+
     def getXMLState(self, numid):
         return self.p.getXMLState(numid)