Salome HOME
mergefrom branch BR_V511_PR tag mergeto_trunk_03feb09
[modules/yacs.git] / src / engine / Node.hxx
1 //  Copyright (C) 2006-2008  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 #ifndef __NODE_HXX__
20 #define __NODE_HXX__
21
22 #include "InGate.hxx"
23 #include "OutGate.hxx"
24 #include "Exception.hxx"
25 #include "define.hxx"
26
27 #include <set>
28 #include <string>
29 #include <vector>
30 #include <map>
31
32 namespace YACS
33 {
34   namespace ENGINE
35   {
36     void StateLoader(Node* node, YACS::StatesForNode state);
37     class Task;
38     class InPort;
39     class OutPort;
40     class InputPort;
41     class OutputPort;
42     class DynParaLoop;
43     class ForEachLoop;
44     class ComposedNode;
45     class ElementaryNode;
46     class Switch;
47     class InputDataStreamPort;
48     class OutputDataStreamPort;
49     class Visitor;
50     
51 /*! \brief Base class for all nodes
52  *
53  * \ingroup Nodes
54  *
55  *
56  */
57     class Node
58     {
59       friend class Bloc;
60       friend class Loop;
61       friend class Switch;
62       friend class InputPort;
63       friend class OutputPort;
64       friend class DynParaLoop;
65       friend class ForEachLoop;
66       friend class ComposedNode;
67       friend class ElementaryNode;
68       friend class Visitor;
69       friend void StateLoader(Node* node, YACS::StatesForNode state);
70     public:
71       mutable YACS::Colour _colour;
72     protected:
73       InGate _inGate;
74       OutGate _outGate;
75       std::string _name;
76       ComposedNode *_father;
77       YACS::StatesForNode _state;
78       int _modified;
79       std::string _errorDetails;
80       static const char SEP_CHAR_IN_PORT[];
81       static int _total;
82       int _numId;
83       std::string _implementation;
84       std::map<std::string,std::string> _propertyMap;
85     protected:
86       Node(const std::string& name);
87       Node(const Node& other, ComposedNode *father);
88       virtual void performDuplicationOfPlacement(const Node& other) = 0;
89       virtual Node *simpleClone(ComposedNode *father, bool editionOnly=true) const = 0;
90     public:
91       virtual ~Node();
92       virtual void init(bool start=true);
93       //! \b This method \b MUST \b NEVER \b BE \b VIRTUAL
94       Node *clone(ComposedNode *father, bool editionOnly=true) const;
95       void setState(YACS::StatesForNode theState); // To centralize state changes
96       virtual YACS::StatesForNode getState() const { return _state; }
97       virtual YACS::StatesForNode getEffectiveState() const;
98       virtual YACS::StatesForNode getEffectiveState(const Node*) const;
99       std::string getColorState(YACS::StatesForNode state) const;
100       static std::string getStateName(YACS::StatesForNode state);
101       InGate *getInGate() { return &_inGate; }
102       OutGate *getOutGate() { return &_outGate; }
103       const std::string& getName() const { return _name; }
104       void setName(const std::string& name);
105       ComposedNode * getFather() const { return _father; }
106       const std::string getId() const;
107       bool exIsControlReady() const;
108       std::set<Node *> getOutNodes() const;
109       virtual void writeDot(std::ostream &os) const;
110       virtual void exUpdateState();
111       virtual void exFailedState();
112       virtual void exDisabledState();
113       virtual void getReadyTasks(std::vector<Task *>& tasks) = 0;
114       virtual std::list<ElementaryNode *> getRecursiveConstituents() const = 0;
115       virtual int getNumberOfInputPorts() const = 0;
116       virtual int getNumberOfOutputPorts() const = 0;
117       std::list<InPort *> getSetOfInPort() const;
118       std::list<OutPort *> getSetOfOutPort() const;
119       virtual std::list<InputPort *> getSetOfInputPort() const = 0;
120       virtual std::list<OutputPort *> getSetOfOutputPort() const = 0;
121       virtual std::list<InputPort *> getLocalInputPorts() const = 0;
122       virtual std::list<OutputPort *> getLocalOutputPorts() const = 0;
123       virtual std::set<InputPort *> edGetSetOfUnitializedInputPort() const;
124       virtual bool edAreAllInputPortInitialized() const;
125       virtual std::string getInPortName(const InPort *) const throw (Exception) = 0;
126       virtual std::string getOutPortName(const OutPort *) const throw (Exception) = 0;
127       virtual std::list<InputDataStreamPort *> getSetOfInputDataStreamPort() const = 0;
128       virtual std::list<OutputDataStreamPort *> getSetOfOutputDataStreamPort() const = 0;
129       InPort *getInPort(const std::string& name) const throw(Exception);
130       virtual OutPort *getOutPort(const std::string& name) const throw(Exception);
131       virtual std::set<OutPort *> getAllOutPortsLeavingCurrentScope() const = 0;
132       virtual std::set<InPort *> getAllInPortsComingFromOutsideOfCurrentScope() const = 0;
133       virtual std::vector< std::pair<OutPort *, InPort *> > getSetOfLinksLeavingCurrentScope() const = 0;
134       virtual std::vector< std::pair<InPort *, OutPort *> > getSetOfLinksComingInCurrentScope() const =0;
135       virtual InputPort *getInputPort(const std::string& name) const throw(Exception) = 0;
136       virtual OutputPort *getOutputPort(const std::string& name) const throw(Exception) = 0;
137       virtual InputDataStreamPort *getInputDataStreamPort(const std::string& name) const throw(Exception) = 0;
138       virtual OutputDataStreamPort *getOutputDataStreamPort(const std::string& name) const throw(Exception) = 0;
139       std::list<ComposedNode *> getAllAscendanceOf(ComposedNode *levelToStop = 0) const;
140       bool operator>(const Node& other) const;
141       bool operator<(const Node& other) const;
142       std::string getImplementation() const;
143       virtual ComposedNode *getRootNode() const throw(Exception);
144       virtual void setProperty(const std::string& name,const std::string& value);
145       virtual Node *getChildByName(const std::string& name) const throw(Exception) = 0;
146       virtual void accept(Visitor *visitor) = 0;
147       std::string getQualifiedName() const;
148       int getNumId();
149       virtual void sendEvent(const std::string& event);
150       static std::map<int,Node *> idMap;
151       virtual std::string typeName() {return "YACS__ENGINE__Node";}
152       virtual std::string getErrorDetails(){return _errorDetails;};
153       virtual void setErrorDetails(const std::string& error){_errorDetails=error;};
154       virtual void modified();
155       virtual int isModified(){return _modified;}
156       virtual int isValid();
157       virtual void edUpdateState();
158       virtual std::string getErrorReport();
159       virtual std::string getContainerLog();
160       virtual void ensureLoading();
161     protected:
162       virtual void exForwardFailed();
163       virtual void exForwardFinished();
164       virtual void edDisconnectAllLinksWithMe();
165       static void checkValidityOfPortName(const std::string& name) throw(Exception);
166       static ComposedNode *checkHavingCommonFather(Node *node1, Node *node2) throw(Exception);
167       static std::map<int, std::string> _nodeStateName;
168     };
169
170   }
171 }
172
173 #endif