From b1d9aaddeca3d5779537741601e7ef93e50ea71b Mon Sep 17 00:00:00 2001 From: Lauffenburger Thomas Date: Tue, 18 Aug 2015 09:54:42 +0200 Subject: [PATCH] new method returning calculation progress tmp commit --- src/engine/ComposedNode.cxx | 44 +++++++++++++++++++++++++++++++++++++ src/engine/ComposedNode.hxx | 1 + src/engine/Proc.cxx | 16 ++++++++++++++ src/engine/Proc.hxx | 1 + 4 files changed, 62 insertions(+) diff --git a/src/engine/ComposedNode.cxx b/src/engine/ComposedNode.cxx index 39fa5bef8..418f18ea8 100644 --- a/src/engine/ComposedNode.cxx +++ b/src/engine/ComposedNode.cxx @@ -28,6 +28,7 @@ #include "DataStreamPort.hxx" #include "ElementaryNode.hxx" #include "ComponentInstance.hxx" +#include "ForEachLoop.hxx" #include #include @@ -1131,6 +1132,49 @@ list ComposedNode::getAllRecursiveNodes() return ret; } + +//! Get the progress weight for all elementary nodes +/*! + * Only elementary nodes have weight. If a node is in a for each loop, his weight is modified by the size of the loop + * + */ +list > ComposedNode::getProgressWeight() +{ + list > ret; + list setOfNode=edGetDirectDescendants(); + int elemDone, elemTotal; + for(list::const_iterator iter=setOfNode.begin();iter!=setOfNode.end();iter++) + { + if ( dynamic_cast (*iter) ) + { + elemDone=((ForEachLoop*)(*iter))->getCurrentIndex(); + elemTotal=((ForEachLoop*)(*iter))->getNbOfElementsToBeProcessed(); + list > myCurrentSet=((ComposedNode*)(*iter))->getProgressWeight(); + myCurrentSet.pop_front(); + myCurrentSet.pop_back(); + for(list >::iterator iter=myCurrentSet.begin();iter!=myCurrentSet.end();iter++) + { + (*iter).first=(*iter).second*elemDone; + (*iter).second*=elemTotal; + } + ret.insert(ret.end(),myCurrentSet.begin(),myCurrentSet.end()); + } + else if ( dynamic_cast (*iter) ) + { + list > myCurrentSet=((ComposedNode*)(*iter))->getProgressWeight(); + ret.insert(ret.end(),myCurrentSet.begin(),myCurrentSet.end()); + } + else + { + if ((*iter)->getState() == YACS::DONE) + ret.push_back(pair(1,1)); + else + ret.push_back(pair(0,1)); + } + } + return ret; +} + //! Get the input port name /*! * get the input port name used by the current node, recursively built with children names. diff --git a/src/engine/ComposedNode.hxx b/src/engine/ComposedNode.hxx index d3663c368..84e4d5555 100644 --- a/src/engine/ComposedNode.hxx +++ b/src/engine/ComposedNode.hxx @@ -80,6 +80,7 @@ namespace YACS std::list getRecursiveConstituents() const; std::list getAllRecursiveNodes(); virtual std::list getAllRecursiveConstituents(); // first implementation + std::list > getProgressWeight(); std::string getInPortName(const InPort *) const throw (Exception); std::string getOutPortName(const OutPort *) const throw (Exception); // diff --git a/src/engine/Proc.cxx b/src/engine/Proc.cxx index 5f83fe162..4cb742955 100644 --- a/src/engine/Proc.cxx +++ b/src/engine/Proc.cxx @@ -230,6 +230,22 @@ std::string Proc::getNodeProgress(int numId) return progress; } +int Proc::getGlobalProgressPercent() +{ + list > weightList = getProgressWeight(); + int weightDone = 0; + int weightTotal = 0; + int progressPercent = 0; + for(list >::const_iterator iter=weightList.begin();iter!=weightList.end();iter++) + { + weightDone += (*iter).first; + weightTotal += (*iter).second; + } + if (weightTotal > 0) + progressPercent = int(float(weightDone) / float(weightTotal) * 100); + return progressPercent; +} + std::string Proc::getXMLState(int numId) { if(YACS::ENGINE::Node::idMap.count(numId) == 0) diff --git a/src/engine/Proc.hxx b/src/engine/Proc.hxx index e4b8329a3..a09b026c9 100644 --- a/src/engine/Proc.hxx +++ b/src/engine/Proc.hxx @@ -67,6 +67,7 @@ namespace YACS YACS::StatesForNode getNodeState(int numId); std::string getNodeProgress(int numId); + int getGlobalProgressPercent(); 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); -- 2.30.2