Salome HOME
2f2270cf8b0e555a341adab6f775ea0362e2a925
[modules/superv.git] / src / GraphBase / DataFlowBase_StreamNode.hxx
1 //  SUPERV GraphBase : contains fondamental classes for Services, Input Ports, Output Ports Links and Nodes.
2 //
3 //  Copyright (C) 2003  CEA/DEN, EDF R&D
4 //
5 //
6 //
7 //  File   : DataFlowBase_StreamNode.hxx
8 //  Author : Jean Rahuel
9 //  Module : SUPERV
10 //  $Header:
11
12 #ifndef _DATAFLOWBASE_STREAMNODE_HXX
13 #define _DATAFLOWBASE_STREAMNODE_HXX
14
15 #include "DataFlowBase_PortsOfNode.hxx"
16
17 namespace GraphEditor {
18
19   class DataFlow ;
20
21 }
22
23 namespace GraphBase {
24
25   class Graph ;
26
27   class StreamNode : public PortsOfNode {
28
29     private:
30     
31       char                 * _Name ;
32       SUPERV::KindOfNode     _Kind ;
33
34 // _LinkedNodes are the nodes with link(s) from OutPort(s) of this node
35 // Nodes with LinkedInPortsNumber InPort(s) linked to Outport(s) of this node :
36       map< string , int >   _MapOfLinkedNodes ;
37       int                   _LinkedNodesSize ;
38       vector<StreamNode * > _LinkedNodes ;
39       vector<int >          _LinkedInPortsNumber ;
40
41 // _LinkedFromNodes are the nodes with link(s) to InPort(s) of this node
42       map< string , int >   _MapOfLinkedFromNodes ;
43       int                   _LinkedFromNodesSize ;
44       vector<StreamNode * > _LinkedFromNodes ;
45       vector<int >          _LinkedFromInPortsNumber ;
46
47 // Nodes with InStreamPort(s) linked to OutStreamport(s) of this node :
48 // NodeName <--> index of that linked node in _LinkedNodes
49       map< string , int >   _MapOfLinkedStreamNodes ;
50       int                   _LinkedStreamNodesSize ;
51       vector<StreamNode * > _LinkedStreamNodes ;
52       vector<int >          _LinkedInStreamPortsNumber ;
53
54       bool                  _NodeDoneInBranchOfSwitch ;
55
56       bool                  _HeadNode ;
57       int                   _LevelNumber ;
58       int                   _SortedIndex ;
59
60       GraphEditor::DataFlow   * _GraphEditor ;
61 // If DataFlowGraph/DataStreamGraph in another graph :
62 // the Graph if MacroNode and MacroNode if Graph
63       SUPERV::Graph_var       _GraphMacroNode ;
64       GraphBase::Graph        * _GraphOfNode ;
65
66       int                   _GraphMacroLevel ;
67       int                   _SubGraphNumber ;
68       int                   _SubStreamGraphNumber ;
69
70     protected:
71
72       int                  * _Graph_prof_debug ;
73       ofstream             * _Graph_fdebug ;
74
75       StreamNode() ;
76
77       StreamNode( const char * NodeName ,
78                   const SUPERV::KindOfNode DataFlowkind ,
79                   int * Graph_prof_debug ,
80                   ofstream * Graph_fdebug ) ;
81
82       StreamNode( int * Graph_prof_debug ,
83                   ofstream * Graph_fdebug ) ;
84
85       virtual ~StreamNode() ;
86
87     public:
88
89 //JR 17.02.2005 Memory Leak      char * Name() const { return my_strdup( _Name ) ; } ;
90       char * Name() const {
91 //             cdebug << "StreamNode::Name " << (void * ) _Name << " = " << _Name << endl ;
92 //JR 21.02.2005 Memory Leak             return my_strdup( _Name ) ; } ;
93              return _Name ; } ;
94       const char *const * NamePtr() const {
95 //            cdebug << "StreamNode::NamePtr " << (void ** ) &_Name << " = Name " << (void * ) _Name
96 //                   << " = " << _Name << endl ;
97             return &_Name ; } ;
98       bool Name( const char * aName ) ;
99
100       SUPERV::KindOfNode Kind() const {
101             return _Kind; } ;
102       bool Kind( SUPERV::KindOfNode aKind) {
103         _Kind = aKind ;
104         return true ; } ;
105       const bool IsComputingNode() const {
106             return (Kind() == SUPERV::ComputingNode ) ; } ;
107       const bool IsFactoryNode() const {
108             return (Kind() == SUPERV::FactoryNode ) ; } ;
109       const bool IsOneOfGOTONodes() const {
110             return (Kind() == SUPERV::LoopNode ||
111                     Kind() == SUPERV::EndLoopNode ||
112                     Kind() == SUPERV::SwitchNode ||
113                     Kind() == SUPERV::EndSwitchNode ||
114                     Kind() == SUPERV::GOTONode ||
115                     Kind() == SUPERV::MacroNode ) ; } ;
116       const bool IsOneOfInLineNodes() const {
117             return (Kind() == SUPERV::InLineNode || IsOneOfGOTONodes() ) ; } ;
118       const bool IsInLineNode() const {
119             return (Kind() == SUPERV::InLineNode ) ; } ;
120       const bool IsMacroNode() const {
121             return (Kind() == SUPERV::MacroNode ) ; } ;
122       const bool IsDataFlowNode() const {
123             return (Kind() == SUPERV::DataFlowGraph ) ; } ;
124       const bool IsDataStreamNode() const {
125             return (Kind() == SUPERV::DataStreamGraph ) ; } ;
126       const bool IsLoopNode() const {
127             return (Kind() == SUPERV::LoopNode ) ; } ;
128       const bool IsEndLoopNode() const {
129             return (Kind() == SUPERV::EndLoopNode ) ; } ;
130       const bool IsSwitchNode() const {
131             return (Kind() == SUPERV::SwitchNode ) ; } ;
132       const bool IsEndSwitchNode() const {
133             return (Kind() == SUPERV::EndSwitchNode ) ; } ;
134       const bool IsGOTONode() const {
135             return (Kind() == SUPERV::GOTONode ) ; } ;
136
137       int GetLinkedNodeIndex( const char * name ) {
138           int index = _MapOfLinkedNodes[ name ] -1 ;
139           if ( index >= 0 ) {
140             cdebug << "GetLinkedNodeIndex of " << name
141                    << " in _MapOfLinkedNodes : "
142                    << index << " Node " << hex << (void *) _LinkedNodes[ index ]
143                    << dec << " '" << _LinkedNodes[ index ]->Name() << "'"
144                    << endl ;
145           }
146           return index ; } ;
147       void SetLinkedNodeIndex( const char * name , const int index ) {
148           _MapOfLinkedNodes[ name ] = index +1 ;
149           cdebug << "SetLinkedNodeIndex of " << name << " in _MapOfLinkedNodes : index "
150                  << index << " of " << Name() << " Node " << hex << (void *) _LinkedNodes[ index ]
151                  << dec << " '" << _LinkedNodes[ index ]->Name() << "'"
152                  << " _MapOfLinkedNodes " << _MapOfLinkedNodes[ name ] - 1
153                  << endl ;
154           } ;
155       void DelLinkedNodeIndex( const char * name ) {
156            _MapOfLinkedNodes.erase( name ) ; } ;
157
158       int LinkedNodesSize() const { return _LinkedNodesSize ; } ;
159
160       const int LinkedInPortsNumber( int i ) const { return _LinkedInPortsNumber[ i ] ; } ;
161       void IncrLinkedInPortsNumber( int i ) {
162            cdebug << Name() << "->IncrLinkedInPortsNumber LinkedInPortsNumber --> "
163                   << _LinkedInPortsNumber[ i ] + 1 << endl ;
164            _LinkedInPortsNumber[ i ]++ ; } ;
165       void DecrLinkedInPortsNumber( int i ) {
166            cdebug << Name() << "->DecrLinkedInPortsNumber LinkedInPortsNumber --> "
167                   << _LinkedInPortsNumber[ i ] - 1 << endl ;
168            _LinkedInPortsNumber[ i ]-- ; } ;
169
170       StreamNode * LinkedNodes( int i ) const { return _LinkedNodes[ i ] ; } ;
171
172       int GetLinkedFromNodeIndex( const char * name ) {
173           int index = _MapOfLinkedFromNodes[ name ] -1 ;
174           if ( index >= 0 ) {
175             cdebug << "StreamNode::GetLinkedFromNodeIndex of " << name
176                    << " in _MapOfLinkedFromNodes : "
177                    << index << " FromNode " << hex << (void *) _LinkedFromNodes[ index ]
178                    << dec << " '" << _LinkedFromNodes[ index ]->Name() << "'"
179                    << endl ;
180           }
181           else {
182             cdebug << "StreamNode::GetLinkedFromNodeIndex of " << name
183                    << " in _MapOfLinkedFromNodes not found. Known nodes :" << endl ;
184 #if 0
185             map< string , int >::iterator aMapOfLinkedFromNodesIterator1 ;
186             int iifrom = 0 ;
187             for ( aMapOfLinkedFromNodesIterator1 = ToNode->_MapOfLinkedFromNodes.begin() ;
188                   aMapOfLinkedFromNodesIterator1 != ToNode->_MapOfLinkedFromNodes.end() &&
189                   iifrom < ToNode->_LinkedFromNodesSize ; aMapOfLinkedFromNodesIterator1++ ) {
190               if ( aMapOfLinkedFromNodesIterator1->second ) {
191                 cdebug << "_MapOfLinkedFromNodes" << iifrom++ << " of " << ToNode->Name() << " : "
192                        << aMapOfLinkedFromNodesIterator1->first << " --> "
193                        << aMapOfLinkedFromNodesIterator1->second << " "
194                        << ToNode->_LinkedFromNodes[ aMapOfLinkedFromNodesIterator1->second - 1 ]->Name()
195                        << endl ;
196               }
197               else {
198                 cdebug << "_MapOfLinkedFromNodes" << iifrom << " of " << ToNode->Name() << " : "
199                        << aMapOfLinkedFromNodesIterator1->second - 1 << endl ;
200               }
201             }
202 #endif
203           }
204           return index ; } ;
205       void SetLinkedFromNodeIndex( const char * name , const int index ) {
206           _MapOfLinkedFromNodes[ name ] = index +1 ;
207           cdebug << "SetLinkedFromNodeIndex of " << name << " in _MapOfLinkedFromNodes : index "
208                  << index << " of " << Name() << " FromNode " << hex
209                  << (void *) _LinkedFromNodes[ index ]
210                  << dec << " '" << _LinkedFromNodes[ index ]->Name() << "'"
211                  << " _MapOfLinkedFromNodes " << _MapOfLinkedFromNodes[ name ] - 1
212                  << endl ;
213           } ;
214       void DelLinkedFromNodeIndex( const char * name ) {
215            _MapOfLinkedFromNodes.erase( name ) ; } ;
216
217       int LinkedFromNodesSize() const {
218           return _LinkedFromNodesSize ; } ;
219       void DecrLinkedFromNodesSize() {
220            _LinkedFromNodesSize-- ; } ;
221
222       const int LinkedFromInPortsNumber( int i ) const {
223             return _LinkedFromInPortsNumber[ i ] ; } ;
224       void IncrLinkedFromInPortsNumber( int i ) {
225            cdebug << Name() << "->IncrLinkedFromInPortsNumber LinkedFromInPortsNumber --> "
226                   << _LinkedFromInPortsNumber[ i ] + 1 << endl ;
227            _LinkedFromInPortsNumber[ i ]++ ; } ;
228       void DecrLinkedFromInPortsNumber( int i ) {
229            cdebug << Name() << "->DecrLinkedFromInPortsNumber LinkedFromInPortsNumber --> "
230                   << _LinkedFromInPortsNumber[ i ] - 1 << endl ;
231            _LinkedFromInPortsNumber[ i ]-- ; } ;
232
233       StreamNode * LinkedFromNodes( int i ) const { return _LinkedFromNodes[ i ] ; } ;
234
235       int GetLinkedStreamNodeIndex( const char * name ) {
236           int index = _MapOfLinkedStreamNodes[ name ] -1 ;
237           if ( index >= 0 ) {
238             cdebug << "GetLinkedStreamNodeIndex of " << name
239                    << " in _MapOfLinkedStreamNodes : "
240                    << index << " Node " << hex << (void *) _LinkedStreamNodes[ index ]
241                    << dec << " '" << _LinkedStreamNodes[ index ]->Name() << "'"
242                    << endl ;
243           }
244           return index ; } ;
245       void SetLinkedStreamNodeIndex( const char * name , const int index ) {
246           _MapOfLinkedStreamNodes[ name ] = index +1 ;
247           cdebug << "SetLinkedStreamNodeIndex of " << name << " in _MapOfLinkedStreamNodes : "
248                  << index << " Node " << hex << (void *) _LinkedStreamNodes[ index ]
249                  << dec << " '" << _LinkedStreamNodes[ index ]->Name() << "'"
250                  << " _MapOfLinkedStreamNodes " << _MapOfLinkedStreamNodes[ name ] - 1
251                  << endl ;
252           } ;
253       void DelLinkedStreamNodeIndex( const char * name ) {
254            _MapOfLinkedStreamNodes.erase( name ) ; } ;
255
256       int LinkedStreamNodesSize() const { return _LinkedStreamNodesSize ; } ;
257
258       const int LinkedInStreamPortsNumber( int i ) const {
259             return _LinkedInStreamPortsNumber[ i ] ; } ;
260
261       StreamNode * LinkedStreamNodes( int i ) const {
262                    return _LinkedStreamNodes[ i ] ; } ;
263
264       bool BranchOfSwitchDone( bool aNodeDoneInBranchOfSwitch ) {
265            bool prevalue = _NodeDoneInBranchOfSwitch ;
266            _NodeDoneInBranchOfSwitch = aNodeDoneInBranchOfSwitch ;
267            if ( prevalue && !aNodeDoneInBranchOfSwitch ) {
268              return false ;
269            }
270            return true ; } ;
271       bool BranchOfSwitchDone() {
272            return _NodeDoneInBranchOfSwitch ; } ;
273
274       void HeadNode( bool aHeadNode ) { _HeadNode = aHeadNode ; } ;
275       const bool IsHeadNode() const { return _HeadNode ; } ;
276
277       int Level() const { return _LevelNumber ; } ;
278       void Level( int LevelNumber ) {
279            _LevelNumber = LevelNumber ; } ;
280
281       void SortedIndex( int aSortedIndex ) {
282            _SortedIndex = aSortedIndex ; } ;
283       int SortedIndex() const {
284            return _SortedIndex ; } ;
285
286       void SetSubStreamGraph( int SubStreamGraphsNumber , int & RetVal ) ;
287
288       void GraphEditor( GraphEditor::DataFlow * aGraphEditor ) {
289            cdebug << "StreamNode::GraphEditor this " << this << " " << Name() << " : _GraphEditor = " << aGraphEditor << endl ;
290            _GraphEditor = aGraphEditor ; } ;
291       GraphEditor::DataFlow * GraphEditor() const {
292            cdebug << "StreamNode::GraphEditor this " << this << " " << Name() << " : " << _GraphEditor << endl ;
293                           return _GraphEditor ; } ;
294
295       void GraphMacroLevel( int aGraphMacroLevel ) {
296            cdebug << "GraphMacroLevel " << Name() << " " << aGraphMacroLevel << endl ;
297            _GraphMacroLevel = aGraphMacroLevel ; } ;
298       int GraphMacroLevel() const {
299           return _GraphMacroLevel ; } ;
300
301       void MacroObject( SUPERV::Graph_var aGraphMacroNode ) {
302            if ( CORBA::is_nil( aGraphMacroNode ) ) {
303              cdebug << "MacroObject GraphMacroNode " << this << " " << Name()
304                     << " MacroObject(nil object). Error" << endl ;
305            }
306            else {
307              cdebug << "MacroObject GraphMacroNode " << this << " " << Name()
308                     << " MacroObject " << _GraphMacroNode << endl ;
309            }
310            _GraphMacroNode = aGraphMacroNode ; } ;
311       SUPERV::Graph_var MacroObject() const {
312                         if ( CORBA::is_nil( _GraphMacroNode ) ) {
313                           cdebug << "MacroObject GraphMacroNode " << this << " " << Name()
314                                  << " returns nil object. Error" << endl ;
315                         }
316                         return _GraphMacroNode ; } ;
317
318       void GraphOfNode( GraphBase::Graph * aGraph ) {
319            _GraphOfNode = aGraph ; } ;
320       GraphBase::Graph * GraphOfNode() const {
321                          return _GraphOfNode ; } ;
322       GraphBase::Graph * GraphOfNode() {
323                          return _GraphOfNode ; } ;
324
325       int SubGraph() const { return _SubGraphNumber ; } ;
326       void SubGraph( int SubGraphNumber ) {
327            _SubGraphNumber = SubGraphNumber ; } ;
328
329       int SubStreamGraph() const { return _SubStreamGraphNumber ; } ;
330       void SubStreamGraph( int SubStreamGraphNumber ) {
331            _SubStreamGraphNumber = SubStreamGraphNumber ; } ;
332
333       void AddLinkedNode( StreamNode * ToNode ) ;
334       bool RemoveLinkedNode( StreamNode * ToNode ,
335                              bool DoLinkedFromNode = true ) ;
336       void ReNameLinkedNode( const char* OldNodeName ,
337                              const char* NewNodeName ) ;
338       void ReNameLinkedFromNode( const char* OldNodeName ,
339                                  const char* NewNodeName ) ;
340
341       void AddStreamLinkedNode( StreamNode * ToNode ) ;
342       bool RemoveStreamLinkedNode( StreamNode * ToNode ) ;
343       void ReNameStreamLinkedNode( const char* OldNodeName ,
344                                    const char* NewNodeName ) ;
345
346   };
347   
348 };
349
350 #endif