Salome HOME
Fix for bug IPAL9558 : Maintainance Mandrake porting: black rectangle in table view.
[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
162       StreamNode * LinkedNodes( int i ) const { return _LinkedNodes[ i ] ; } ;
163
164       int GetLinkedFromNodeIndex( const char * name ) {
165           int index = _MapOfLinkedFromNodes[ name ] -1 ;
166           if ( index >= 0 ) {
167             cdebug << "GetLinkedFromNodeIndex of " << name
168                    << " in _MapOfLinkedFromNodes : "
169                    << index << " FromNode " << hex << (void *) _LinkedFromNodes[ index ]
170                    << dec << " '" << _LinkedFromNodes[ index ]->Name() << "'"
171                    << endl ;
172           }
173           return index ; } ;
174       void SetLinkedFromNodeIndex( const char * name , const int index ) {
175           _MapOfLinkedFromNodes[ name ] = index +1 ;
176           cdebug << "SetLinkedFromNodeIndex of " << name << " in _MapOfLinkedFromNodes : index "
177                  << index << " of " << Name() << " FromNode " << hex
178                  << (void *) _LinkedFromNodes[ index ]
179                  << dec << " '" << _LinkedFromNodes[ index ]->Name() << "'"
180                  << " _MapOfLinkedFromNodes " << _MapOfLinkedFromNodes[ name ] - 1
181                  << endl ;
182           } ;
183       void DelLinkedFromNodeIndex( const char * name ) {
184            _MapOfLinkedFromNodes.erase( name ) ; } ;
185
186       int LinkedFromNodesSize() const { return _LinkedFromNodesSize ; } ;
187
188       const int LinkedFromInPortsNumber( int i ) const { return _LinkedFromInPortsNumber[ i ] ; } ;
189
190       StreamNode * LinkedFromNodes( int i ) const { return _LinkedFromNodes[ i ] ; } ;
191
192       int GetLinkedStreamNodeIndex( const char * name ) {
193           int index = _MapOfLinkedStreamNodes[ name ] -1 ;
194           if ( index >= 0 ) {
195             cdebug << "GetLinkedStreamNodeIndex of " << name
196                    << " in _MapOfLinkedStreamNodes : "
197                    << index << " Node " << hex << (void *) _LinkedStreamNodes[ index ]
198                    << dec << " '" << _LinkedStreamNodes[ index ]->Name() << "'"
199                    << endl ;
200           }
201           return index ; } ;
202       void SetLinkedStreamNodeIndex( const char * name , const int index ) {
203           _MapOfLinkedStreamNodes[ name ] = index +1 ;
204           cdebug << "SetLinkedStreamNodeIndex of " << name << " in _MapOfLinkedStreamNodes : "
205                  << index << " Node " << hex << (void *) _LinkedStreamNodes[ index ]
206                  << dec << " '" << _LinkedStreamNodes[ index ]->Name() << "'"
207                  << " _MapOfLinkedStreamNodes " << _MapOfLinkedStreamNodes[ name ] - 1
208                  << endl ;
209           } ;
210       void DelLinkedStreamNodeIndex( const char * name ) {
211            _MapOfLinkedStreamNodes.erase( name ) ; } ;
212
213       int LinkedStreamNodesSize() const { return _LinkedStreamNodesSize ; } ;
214
215       const int LinkedInStreamPortsNumber( int i ) const { return _LinkedInStreamPortsNumber[ i ] ; } ;
216
217       StreamNode * LinkedStreamNodes( int i ) const { return _LinkedStreamNodes[ i ] ; } ;
218
219       bool BranchOfSwitchDone( bool aNodeDoneInBranchOfSwitch ) {
220            bool prevalue = _NodeDoneInBranchOfSwitch ;
221            _NodeDoneInBranchOfSwitch = aNodeDoneInBranchOfSwitch ;
222            if ( prevalue && !aNodeDoneInBranchOfSwitch ) {
223              return false ;
224            }
225            return true ; } ;
226       bool BranchOfSwitchDone() {
227            return _NodeDoneInBranchOfSwitch ; } ;
228
229       void HeadNode( bool aHeadNode ) { _HeadNode = aHeadNode ; } ;
230       const bool IsHeadNode() const { return _HeadNode ; } ;
231
232       int Level() const { return _LevelNumber ; } ;
233       void Level( int LevelNumber ) {
234            _LevelNumber = LevelNumber ; } ;
235
236       void SortedIndex( int aSortedIndex ) {
237            _SortedIndex = aSortedIndex ; } ;
238       int SortedIndex() const {
239            return _SortedIndex ; } ;
240
241       void SetSubStreamGraph( int SubStreamGraphsNumber , int & RetVal ) ;
242
243       void GraphEditor( GraphEditor::DataFlow * aGraphEditor ) {
244            cdebug << "StreamNode::GraphEditor this " << this << " " << Name() << " : _GraphEditor = " << aGraphEditor << endl ;
245            _GraphEditor = aGraphEditor ; } ;
246       GraphEditor::DataFlow * GraphEditor() const {
247            cdebug << "StreamNode::GraphEditor this " << this << " " << Name() << " : " << _GraphEditor << endl ;
248                           return _GraphEditor ; } ;
249
250       void GraphMacroLevel( int aGraphMacroLevel ) {
251            cdebug << "GraphMacroLevel " << Name() << " " << aGraphMacroLevel << endl ;
252            _GraphMacroLevel = aGraphMacroLevel ; } ;
253       int GraphMacroLevel() const {
254           return _GraphMacroLevel ; } ;
255
256       void MacroObject( SUPERV::Graph_var aGraphMacroNode ) {
257            if ( CORBA::is_nil( aGraphMacroNode ) ) {
258              cdebug << "MacroObject GraphMacroNode " << this << " " << Name()
259                     << " MacroObject(nil object). Error" << endl ;
260            }
261            else {
262              cdebug << "MacroObject GraphMacroNode " << this << " " << Name()
263                     << " MacroObject " << _GraphMacroNode << endl ;
264            }
265            _GraphMacroNode = aGraphMacroNode ; } ;
266       SUPERV::Graph_var MacroObject() const {
267                         if ( CORBA::is_nil( _GraphMacroNode ) ) {
268                           cdebug << "MacroObject GraphMacroNode " << this << " " << Name()
269                                  << " returns nil object. Error" << endl ;
270                         }
271                         return _GraphMacroNode ; } ;
272
273       void GraphOfNode( GraphBase::Graph * aGraph ) {
274            _GraphOfNode = aGraph ; } ;
275       GraphBase::Graph * GraphOfNode() const {
276                          return _GraphOfNode ; } ;
277       GraphBase::Graph * GraphOfNode() {
278                          return _GraphOfNode ; } ;
279
280       int SubGraph() const { return _SubGraphNumber ; } ;
281       void SubGraph( int SubGraphNumber ) {
282            _SubGraphNumber = SubGraphNumber ; } ;
283
284       int SubStreamGraph() const { return _SubStreamGraphNumber ; } ;
285       void SubStreamGraph( int SubStreamGraphNumber ) {
286            _SubStreamGraphNumber = SubStreamGraphNumber ; } ;
287
288       void AddLinkedNode( StreamNode * ToNode ) ;
289       bool RemoveLinkedNode( StreamNode * ToNode ,
290                              bool DoLinkedFromNode = true ) ;
291       void ReNameLinkedNode( const char* OldNodeName ,
292                              const char* NewNodeName ) ;
293       void ReNameLinkedFromNode( const char* OldNodeName ,
294                                  const char* NewNodeName ) ;
295
296       void AddStreamLinkedNode( StreamNode * ToNode ) ;
297       bool RemoveStreamLinkedNode( StreamNode * ToNode ) ;
298       void ReNameStreamLinkedNode( const char* OldNodeName ,
299                                    const char* NewNodeName ) ;
300
301   };
302   
303 };
304
305 #endif