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