]> SALOME platform Git repositories - modules/superv.git/blob - src/GraphBase/DataFlowBase_StreamNode.hxx
Salome HOME
method getViewType() added that returns CANVAS, CONTROL or CANVASTABLE constant corre...
[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                  _HeadNode ;
55       int                   _LevelNumber ;
56       int                   _SortedIndex ;
57
58       GraphEditor::DataFlow   * _GraphEditor ;
59 // If DataFlowGraph/DataStreamGraph in another graph :
60 // the Graph if MacroNode and MacroNode if Graph
61       SUPERV::Graph_var       _GraphMacroNode ;
62       GraphBase::Graph        * _GraphOfNode ;
63
64       int                   _GraphMacroLevel ;
65       int                   _SubGraphNumber ;
66       int                   _SubStreamGraphNumber ;
67
68     protected:
69
70       int                  * _Graph_prof_debug ;
71       ofstream             * _Graph_fdebug ;
72
73       StreamNode() ;
74
75       StreamNode( const char * NodeName ,
76                   const SUPERV::KindOfNode DataFlowkind ,
77                   int * Graph_prof_debug ,
78                   ofstream * Graph_fdebug ) ;
79
80       StreamNode( int * Graph_prof_debug ,
81                   ofstream * Graph_fdebug ) ;
82
83       virtual ~StreamNode() ;
84
85     public:
86
87       char * Name() const { return my_strdup( _Name ) ; } ;
88       const char *const * NamePtr() const { return &_Name ; } ;
89       bool Name( const char * aName ) ;
90
91       SUPERV::KindOfNode Kind() const {
92             return _Kind; } ;
93       bool Kind( SUPERV::KindOfNode aKind) {
94         _Kind = aKind ;
95         return true ; } ;
96       const bool IsComputingNode() const {
97             return (Kind() == SUPERV::ComputingNode ) ; } ;
98       const bool IsFactoryNode() const {
99             return (Kind() == SUPERV::FactoryNode ) ; } ;
100       const bool IsOneOfGOTONodes() const {
101             return (Kind() == SUPERV::LoopNode ||
102                     Kind() == SUPERV::EndLoopNode ||
103                     Kind() == SUPERV::SwitchNode ||
104                     Kind() == SUPERV::EndSwitchNode ||
105                     Kind() == SUPERV::GOTONode ||
106                     Kind() == SUPERV::MacroNode ) ; } ;
107       const bool IsOneOfInLineNodes() const {
108             return (Kind() == SUPERV::InLineNode || IsOneOfGOTONodes() ) ; } ;
109       const bool IsInLineNode() const {
110             return (Kind() == SUPERV::InLineNode ) ; } ;
111       const bool IsMacroNode() const {
112             return (Kind() == SUPERV::MacroNode ) ; } ;
113       const bool IsDataFlowNode() const {
114             return (Kind() == SUPERV::DataFlowGraph ) ; } ;
115       const bool IsDataStreamNode() const {
116             return (Kind() == SUPERV::DataStreamGraph ) ; } ;
117       const bool IsLoopNode() const {
118             return (Kind() == SUPERV::LoopNode ) ; } ;
119       const bool IsEndLoopNode() const {
120             return (Kind() == SUPERV::EndLoopNode ) ; } ;
121       const bool IsSwitchNode() const {
122             return (Kind() == SUPERV::SwitchNode ) ; } ;
123       const bool IsEndSwitchNode() const {
124             return (Kind() == SUPERV::EndSwitchNode ) ; } ;
125       const bool IsGOTONode() const {
126             return (Kind() == SUPERV::GOTONode ) ; } ;
127
128       int GetLinkedNodeIndex( const char * name ) {
129           int index = _MapOfLinkedNodes[ name ] -1 ;
130           if ( index >= 0 ) {
131             cdebug << "GetLinkedNodeIndex of " << name
132                    << " in _MapOfLinkedNodes : "
133                    << index << " Node " << hex << (void *) _LinkedNodes[ index ]
134                    << dec << " '" << _LinkedNodes[ index ]->Name() << "'"
135                    << endl ;
136           }
137           return index ; } ;
138       void SetLinkedNodeIndex( const char * name , const int index ) {
139           _MapOfLinkedNodes[ name ] = index +1 ;
140           cdebug << "SetLinkedNodeIndex of " << name << " in _MapOfLinkedNodes : index "
141                  << index << " of " << Name() << " Node " << hex << (void *) _LinkedNodes[ index ]
142                  << dec << " '" << _LinkedNodes[ index ]->Name() << "'"
143                  << " _MapOfLinkedNodes " << _MapOfLinkedNodes[ name ] - 1
144                  << endl ;
145           } ;
146       void DelLinkedNodeIndex( const char * name ) {
147            _MapOfLinkedNodes.erase( name ) ; } ;
148
149       int LinkedNodesSize() const { return _LinkedNodesSize ; } ;
150
151       const int LinkedInPortsNumber( int i ) const { return _LinkedInPortsNumber[ i ] ; } ;
152
153       StreamNode * LinkedNodes( int i ) const { return _LinkedNodes[ i ] ; } ;
154
155       int GetLinkedFromNodeIndex( const char * name ) {
156           int index = _MapOfLinkedFromNodes[ name ] -1 ;
157           if ( index >= 0 ) {
158             cdebug << "GetLinkedFromNodeIndex of " << name
159                    << " in _MapOfLinkedFromNodes : "
160                    << index << " FromNode " << hex << (void *) _LinkedFromNodes[ index ]
161                    << dec << " '" << _LinkedFromNodes[ index ]->Name() << "'"
162                    << endl ;
163           }
164           return index ; } ;
165       void SetLinkedFromNodeIndex( const char * name , const int index ) {
166           _MapOfLinkedFromNodes[ name ] = index +1 ;
167           cdebug << "SetLinkedFromNodeIndex of " << name << " in _MapOfLinkedFromNodes : index "
168                  << index << " of " << Name() << " FromNode " << hex
169                  << (void *) _LinkedFromNodes[ index ]
170                  << dec << " '" << _LinkedFromNodes[ index ]->Name() << "'"
171                  << " _MapOfLinkedFromNodes " << _MapOfLinkedFromNodes[ name ] - 1
172                  << endl ;
173           } ;
174       void DelLinkedFromNodeIndex( const char * name ) {
175            _MapOfLinkedFromNodes.erase( name ) ; } ;
176
177       int LinkedFromNodesSize() const { return _LinkedFromNodesSize ; } ;
178
179       const int LinkedFromInPortsNumber( int i ) const { return _LinkedFromInPortsNumber[ i ] ; } ;
180
181       StreamNode * LinkedFromNodes( int i ) const { return _LinkedFromNodes[ i ] ; } ;
182
183       int GetLinkedStreamNodeIndex( const char * name ) {
184           int index = _MapOfLinkedStreamNodes[ name ] -1 ;
185           if ( index >= 0 ) {
186             cdebug << "GetLinkedStreamNodeIndex of " << name
187                    << " in _MapOfLinkedStreamNodes : "
188                    << index << " Node " << hex << (void *) _LinkedStreamNodes[ index ]
189                    << dec << " '" << _LinkedStreamNodes[ index ]->Name() << "'"
190                    << endl ;
191           }
192           return index ; } ;
193       void SetLinkedStreamNodeIndex( const char * name , const int index ) {
194           _MapOfLinkedStreamNodes[ name ] = index +1 ;
195           cdebug << "SetLinkedStreamNodeIndex of " << name << " in _MapOfLinkedStreamNodes : "
196                  << index << " Node " << hex << (void *) _LinkedStreamNodes[ index ]
197                  << dec << " '" << _LinkedStreamNodes[ index ]->Name() << "'"
198                  << " _MapOfLinkedStreamNodes " << _MapOfLinkedStreamNodes[ name ] - 1
199                  << endl ;
200           } ;
201       void DelLinkedStreamNodeIndex( const char * name ) {
202            _MapOfLinkedStreamNodes.erase( name ) ; } ;
203
204       int LinkedStreamNodesSize() const { return _LinkedStreamNodesSize ; } ;
205
206       const int LinkedInStreamPortsNumber( int i ) const { return _LinkedInStreamPortsNumber[ i ] ; } ;
207
208       StreamNode * LinkedStreamNodes( int i ) const { return _LinkedStreamNodes[ i ] ; } ;
209
210       void HeadNode( bool aHeadNode ) { _HeadNode = aHeadNode ; } ;
211       const bool IsHeadNode() const { return _HeadNode ; } ;
212
213       int Level() const { return _LevelNumber ; } ;
214       void Level( int LevelNumber ) {
215            _LevelNumber = LevelNumber ; } ;
216
217       void SortedIndex( int aSortedIndex ) {
218            _SortedIndex = aSortedIndex ; } ;
219       int SortedIndex() const {
220            return _SortedIndex ; } ;
221
222       void SetSubStreamGraph( int SubStreamGraphsNumber , int & RetVal ) ;
223
224       void GraphEditor( GraphEditor::DataFlow * aGraphEditor ) {
225            cdebug << "StreamNode::GraphEditor this " << this << " " << Name() << " : _GraphEditor = " << aGraphEditor << endl ;
226            _GraphEditor = aGraphEditor ; } ;
227       GraphEditor::DataFlow * GraphEditor() const {
228            cdebug << "StreamNode::GraphEditor this " << this << " " << Name() << " : " << _GraphEditor << endl ;
229                           return _GraphEditor ; } ;
230
231       void GraphMacroLevel( int aGraphMacroLevel ) {
232            cdebug << "GraphMacroLevel " << Name() << " " << aGraphMacroLevel << endl ;
233            _GraphMacroLevel = aGraphMacroLevel ; } ;
234       int GraphMacroLevel() const {
235           return _GraphMacroLevel ; } ;
236
237       void MacroObject( SUPERV::Graph_var aGraphMacroNode ) {
238            if ( CORBA::is_nil( aGraphMacroNode ) ) {
239              cdebug << "MacroObject GraphMacroNode " << this << " " << Name()
240                     << " MacroObject(nil object). Error" << endl ;
241            }
242            else {
243              cdebug << "MacroObject GraphMacroNode " << this << " " << Name()
244                     << " MacroObject " << _GraphMacroNode << endl ;
245            }
246            _GraphMacroNode = aGraphMacroNode ; } ;
247       SUPERV::Graph_var MacroObject() const {
248                         if ( CORBA::is_nil( _GraphMacroNode ) ) {
249                           cdebug << "MacroObject GraphMacroNode " << this << " " << Name()
250                                  << " returns nil object. Error" << endl ;
251                         }
252                         return _GraphMacroNode ; } ;
253
254       void GraphOfNode( GraphBase::Graph * aGraph ) {
255            _GraphOfNode = aGraph ; } ;
256       GraphBase::Graph * GraphOfNode() const {
257                          return _GraphOfNode ; } ;
258       GraphBase::Graph * GraphOfNode() {
259                          return _GraphOfNode ; } ;
260
261       int SubGraph() const { return _SubGraphNumber ; } ;
262       void SubGraph( int SubGraphNumber ) {
263            _SubGraphNumber = SubGraphNumber ; } ;
264
265       int SubStreamGraph() const { return _SubStreamGraphNumber ; } ;
266       void SubStreamGraph( int SubStreamGraphNumber ) {
267            _SubStreamGraphNumber = SubStreamGraphNumber ; } ;
268
269       void AddLinkedNode( StreamNode * ToNode ) ;
270       bool RemoveLinkedNode( StreamNode * ToNode ,
271                              bool DoLinkedFromNode = true ) ;
272       void ReNameLinkedNode( const char* OldNodeName ,
273                              const char* NewNodeName ) ;
274       void ReNameLinkedFromNode( const char* OldNodeName ,
275                                  const char* NewNodeName ) ;
276
277       void AddStreamLinkedNode( StreamNode * ToNode ) ;
278       bool RemoveStreamLinkedNode( StreamNode * ToNode ) ;
279       void ReNameStreamLinkedNode( const char* OldNodeName ,
280                                    const char* NewNodeName ) ;
281
282   };
283   
284 };
285
286 #endif