1 // Copyright (C) 2006-2008 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "WhileLoop.hxx"
20 #include "Runtime.hxx"
21 #include "OutputPort.hxx"
22 #include "Visitor.hxx"
26 #include "YacsTrace.hxx"
28 using namespace YACS::ENGINE;
31 const char WhileLoop::NAME_OF_INPUT_CONDITION[]="condition";
33 WhileLoop::WhileLoop(const std::string& name):Loop(name),_conditionPort(NAME_OF_INPUT_CONDITION,this)
37 WhileLoop::WhileLoop(const WhileLoop& other, ComposedNode *father, bool editionOnly):Loop(other,father,editionOnly),
38 _conditionPort(other._conditionPort,this)
42 void WhileLoop::init(bool start)
45 _conditionPort.exInit(start);
48 void WhileLoop::exUpdateState()
50 if(_state == YACS::DISABLED)
52 if(_inGate.exIsReady())
54 setState(YACS::TOACTIVATE);
55 _node->exUpdateState();
56 if(_conditionPort.isLinkedOutOfScope())
57 if(_conditionPort.isEmpty())
59 delete _nodeForNullTurnOfLoops;
60 _nodeForNullTurnOfLoops=new FakeNodeForLoop(this,false,true);
63 if(!_conditionPort.getValue())
65 bool normalFinish=getAllOutPortsLeavingCurrentScope().empty();
66 delete _nodeForNullTurnOfLoops;
67 _nodeForNullTurnOfLoops=new FakeNodeForLoop(this,normalFinish);
71 delete _nodeForNullTurnOfLoops;
72 _nodeForNullTurnOfLoops=0;
77 Node *WhileLoop::simpleClone(ComposedNode *father, bool editionOnly) const
79 return new WhileLoop(*this,father,editionOnly);
82 InputPort *WhileLoop::getInputPort(const std::string& name) const throw(Exception)
84 if(name==NAME_OF_INPUT_CONDITION)
85 return (InputPort*)&_conditionPort;
86 return Loop::getInputPort(name);
89 //! Method used to notify the node that a child node has ended
91 * Update the loop state and return the loop change state
93 * \param node : the child node that has ended
94 * \return the loop state change
96 YACS::Event WhileLoop::updateStateOnFinishedEventFrom(Node *node)
99 if(!_conditionPort.getValue())
101 setState(YACS::DONE);
107 node->exUpdateState();
109 return YACS::NOEVENT;
112 void WhileLoop::checkLinkPossibility(OutPort *start,
113 const std::list<ComposedNode *>& pointsOfViewStart,
115 const std::list<ComposedNode *>& pointsOfViewEnd) throw(Exception)
117 DEBTRACE("WhileLoop::checkLinkPossibility");
120 void WhileLoop::accept(Visitor *visitor)
122 visitor->visitWhileLoop(this);
125 std::list<InputPort *> WhileLoop::getLocalInputPorts() const
127 list<InputPort *> ret;
128 ret.push_back((InputPort *)&_conditionPort);