X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2Fengine%2FForLoop.cxx;h=be7cae3713e0d6dca0b1346bdb5e292cd09ce0b2;hb=c9208a8ef7f32a620d9650908588320ff159a167;hp=31b5c36a1e999cfe64aaf2c90ab77d92fcd9f5ba;hpb=c81be9b5e74b26e207bd6efd0ccf68418ac536a3;p=modules%2Fyacs.git diff --git a/src/engine/ForLoop.cxx b/src/engine/ForLoop.cxx index 31b5c36a1..be7cae371 100644 --- a/src/engine/ForLoop.cxx +++ b/src/engine/ForLoop.cxx @@ -1,9 +1,9 @@ -// Copyright (C) 2006-2012 CEA/DEN, EDF R&D +// Copyright (C) 2006-2019 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 @@ -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,51 @@ std::list ForLoop::getSetOfOutputPort() const 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 ForLoop::getProgressWeight() const +{ + list ret; + list setOfNode=edGetDirectDescendants(); + int nbStepsDone=getNbOfTurns(); + int nbStepsTotal=getNbSteps(); + for(list::const_iterator iter=setOfNode.begin();iter!=setOfNode.end();iter++) + { + list myCurrentSet=(*iter)->getProgressWeight(); + for(list::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; +} +