1 // Copyright (C) 2006-2014 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, or (at your option) any later version.
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
20 #ifndef __DYNPARALOOP_HXX__
21 #define __DYNPARALOOP_HXX__
23 #include "YACSlibEngineExport.hxx"
24 #include "ComposedNode.hxx"
25 #include "AnyInputPort.hxx"
26 #include "AnyOutputPort.hxx"
27 #include "OutputPort.hxx"
34 * \brief Base class for dynamically (fully or semifully) built graphs.
37 class YACSLIBENGINE_EXPORT DynParaLoop : public ComposedNode
50 unsigned _nbOfEltConsumed;
51 std::vector<int> _execIds;
52 AnyInputPort _nbOfBranches;
53 AnyOutputPort _splittedPort;
54 std::vector<Node *> _execNodes;
55 std::vector<Node *> _execInitNodes;
56 std::vector<Node *> _execFinalizeNodes;
57 int _initializingCounter;
58 int _unfinishedCounter;
60 static const char NAME_OF_SPLITTED_SEQ_OUT[];
61 static const char OLD_NAME_OF_SPLITTED_SEQ_OUT[];
62 static const char NAME_OF_NUMBER_OF_BRANCHES[];
64 DynParaLoop(const std::string& name, TypeCode *typeOfDataSplitted);
65 virtual ~DynParaLoop();
66 DynParaLoop(const DynParaLoop& other, ComposedNode *father, bool editionOnly);
69 Node *edRemoveInitNode();
70 Node *edRemoveFinalizeNode();
71 //Node* DISOWNnode is a SWIG notation to indicate that the ownership of the node is transfered to C++
72 Node *edSetNode(Node *DISOWNnode);
73 Node *edSetInitNode(Node *DISOWNnode);
74 Node *edSetFinalizeNode(Node *DISOWNnode);
75 virtual bool edAddDFLink(OutPort *start, InPort *end) throw(Exception);
76 void init(bool start=true);
77 InputPort *edGetNbOfBranchesPort() { return &_nbOfBranches; }
78 int getNumberOfInputPorts() const;
79 int getNumberOfOutputPorts() const;
80 unsigned getNumberOfEltsConsumed() const { return _nbOfEltConsumed; }
81 std::list<OutputPort *> getSetOfOutputPort() const;
82 std::list<OutputPort *> getLocalOutputPorts() const;
83 OutputPort *edGetSamplePort() { return &_splittedPort; }
84 OutPort *getOutPort(const std::string& name) const throw(Exception);
85 InputPort *getInputPort(const std::string& name) const throw(Exception);
86 OutputPort *getOutputPort(const std::string& name) const throw(Exception);
87 //! For the moment false is returned : impovement about it coming soon.
88 bool isPlacementPredictableB4Run() const;
89 void edRemoveChild(Node *node) throw(Exception);
90 virtual bool edAddChild(Node *DISOWNnode) throw(Exception);
91 std::list<Node *> edGetDirectDescendants() const;
92 std::list<InputPort *> getSetOfInputPort() const;
93 std::list<InputPort *> getLocalInputPorts() const;
94 unsigned getNumberOfBranchesCreatedDyn() const throw(Exception);
95 Node *getChildByShortName(const std::string& name) const throw(Exception);
96 Node *getChildByNameExec(const std::string& name, unsigned id) const throw(Exception);
97 std::vector<Node *> getNodes() const { return _execNodes; } // need to use in GUI part for adding observers for clone nodes
98 bool isMultiplicitySpecified(unsigned& value) const;
99 void forceMultiplicity(unsigned value);
100 virtual void checkBasicConsistency() const throw(Exception);
101 virtual std::string getErrorReport();
102 void accept(Visitor *visitor);
103 Node * getInitNode();
104 Node * getExecNode();
105 Node * getFinalizeNode();
107 void buildDelegateOf(InPort * & port, OutPort *initialStart, const std::list<ComposedNode *>& pointsOfView);
108 void buildDelegateOf(std::pair<OutPort *, OutPort *>& port, InPort *finalTarget, const std::list<ComposedNode *>& pointsOfView);
109 void checkCFLinks(const std::list<OutPort *>& starts, InputPort *end, unsigned char& alreadyFed, bool direction, LinkInfo& info) const;
110 void checkControlDependancy(OutPort *start, InPort *end, bool cross,
111 std::map < ComposedNode *, std::list < OutPort * >, SortHierarc >& fw,
112 std::vector<OutPort *>& fwCross,
113 std::map< ComposedNode *, std::list < OutPort *>, SortHierarc >& bw,
114 LinkInfo& info) const;
116 void cleanDynGraph();
117 void prepareInputsFromOutOfScope(int branchNb);
118 void putValueOnBranch(Any *val, unsigned branchId, bool first);
119 TypeOfNode getIdentityOfNotifyerNode(const Node *node, unsigned& id);
120 InputPort *getDynInputPortByAbsName(int branchNb, const std::string& name, bool initNodeAdmitted);
121 virtual void forwardExecStateToOriginalBody(Node *execNode);
122 virtual YACS::Event updateStateOnFailedEventFrom(Node *node);
123 std::vector<Node *> cloneAndPlaceNodesCoherently(const std::vector<Node *> & origNodes);
124 Node * checkConsistencyAndSetNode(Node* &nodeToReplace, Node* DISOWNnode);
125 Node * removeNode(Node* &nodeToRemove);
126 virtual void shutdown(int level);