-// Copyright (C) 2006-2012 CEA/DEN, EDF R&D
+// Copyright (C) 2006-2023 CEA, EDF
//
// 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
return new ForLoop(*this,father,editionOnly);
}
-InputPort* ForLoop::getInputPort(const std::string& name) const throw(YACS::Exception)
+InputPort* ForLoop::getInputPort(const std::string& name) const
{
if(name == NAME_OF_NSTEPS_NUMBER)return (InputPort*)&_nbOfTimesPort;
return Loop::getInputPort(name);
Any* tmp=AtomAny::New(_nbOfTurns);
_indexPort.put(tmp);
tmp->decrRef();
+ exUpdateProgress();
}
//! Update the state of the for loop
YACS::Event ForLoop::updateStateOnFinishedEventFrom(Node *node)
{
DEBTRACE("ForLoop::updateStateOnFinishedEventFrom " << node->getName());
+ exUpdateProgress();
if((++_nbOfTurns)>=_nbOfTimesPort.getIntValue())
{
setState(YACS::DONE);
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);
return ret;
}
-OutPort *ForLoop::getOutPort(const std::string& name) const throw(YACS::Exception)
+OutPort *ForLoop::getOutPort(const std::string& name) const
{
if(name==NAME_OF_INDEX)
return (OutPort *)&_indexPort;
return Loop::getOutPort(name);
}
-OutputPort *ForLoop::getOutputPort(const std::string& name) const throw(YACS::Exception)
+OutputPort *ForLoop::getOutputPort(const std::string& name) const
{
if(name==NAME_OF_INDEX)
return (OutputPort *)&_indexPort;
return ret;
}
+
+int ForLoop::getNbSteps() const
+{
+ AnyInputPort* aNbStepsPort = (AnyInputPort*)&_nbOfTimesPort;
+ int nbSteps = 0;
+ if (aNbStepsPort && !aNbStepsPort->isEmpty())
+ nbSteps = aNbStepsPort->getIntValue();
+ return nbSteps;
+}
+
+std::string ForLoop::getProgress() const
+{
+ std::stringstream aProgress;
+ aProgress << "0";
+ int nbSteps = getNbSteps();
+ if (nbSteps > 0 && _nbOfTurns >= 0)
+ {
+ aProgress.str("");
+ aProgress << _nbOfTurns << "/" << nbSteps;
+ }
+ return aProgress.str();
+}
+
+//! Get the progress weight for all elementary nodes
+/*!
+ * Only elementary nodes have weight. For each node in the loop, the weight done is multiplied
+ * by the number of steps done and the weight total by the number total of steps
+ *
+ */
+list<ProgressWeight> ForLoop::getProgressWeight() const
+{
+ list<ProgressWeight> ret;
+ list<Node *> setOfNode=edGetDirectDescendants();
+ int nbStepsDone=getNbOfTurns();
+ int nbStepsTotal=getNbSteps();
+ for(list<Node *>::const_iterator iter=setOfNode.begin();iter!=setOfNode.end();iter++)
+ {
+ list<ProgressWeight> myCurrentSet=(*iter)->getProgressWeight();
+ for(list<ProgressWeight>::iterator iter=myCurrentSet.begin();iter!=myCurrentSet.end();iter++)
+ {
+ (*iter).weightDone=((*iter).weightTotal) * nbStepsDone;
+ (*iter).weightTotal*=nbStepsTotal;
+ }
+ ret.insert(ret.end(),myCurrentSet.begin(),myCurrentSet.end());
+ }
+ return ret;
+}
+