1 // SUPERV GraphBase : contains fondamental classes for Services, Input Ports, Output Ports Links and Nodes.
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : DataFlowBase_StreamNode.hxx
23 // Author : Jean Rahuel
26 #ifndef _DATAFLOWBASE_STREAMNODE_HXX
27 #define _DATAFLOWBASE_STREAMNODE_HXX
29 #include "DataFlowBase_PortsOfNode.hxx"
31 namespace GraphEditor {
41 class StreamNode : public PortsOfNode {
46 SUPERV::KindOfNode _Kind ;
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 ;
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 ;
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 ;
68 bool _NodeDoneInBranchOfSwitch ;
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 ;
80 int _GraphMacroLevel ;
82 int _SubStreamGraphNumber ;
86 int * _Graph_prof_debug ;
87 ofstream * _Graph_fdebug ;
91 StreamNode( const char * NodeName ,
92 const SUPERV::KindOfNode DataFlowkind ,
93 int * Graph_prof_debug ,
94 ofstream * Graph_fdebug ) ;
96 StreamNode( int * Graph_prof_debug ,
97 ofstream * Graph_fdebug ) ;
99 virtual ~StreamNode() ;
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 ) ; } ;
108 const char *const * NamePtr() const {
109 // cdebug << "StreamNode::NamePtr " << (void ** ) &_Name << " = Name " << (void * ) _Name
110 // << " = " << _Name << endl ;
112 bool Name( const char * aName ) ;
114 SUPERV::KindOfNode Kind() const {
116 bool Kind( SUPERV::KindOfNode aKind) {
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 ) ; } ;
151 int GetLinkedNodeIndex( const char * name ) {
152 int index = _MapOfLinkedNodes[ name ] -1 ;
154 cdebug << "GetLinkedNodeIndex of " << name
155 << " in _MapOfLinkedNodes : "
156 << index << " Node " << hex << (void *) _LinkedNodes[ index ]
157 << dec << " '" << _LinkedNodes[ index ]->Name() << "'"
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
169 void DelLinkedNodeIndex( const char * name ) {
170 _MapOfLinkedNodes.erase( name ) ; } ;
172 int LinkedNodesSize() const { return _LinkedNodesSize ; } ;
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 ]-- ; } ;
184 StreamNode * LinkedNodes( int i ) const { return _LinkedNodes[ i ] ; } ;
186 int GetLinkedFromNodeIndex( const char * name ) {
187 int index = _MapOfLinkedFromNodes[ name ] -1 ;
189 cdebug << "StreamNode::GetLinkedFromNodeIndex of " << name
190 << " in _MapOfLinkedFromNodes : "
191 << index << " FromNode " << hex << (void *) _LinkedFromNodes[ index ]
192 << dec << " '" << _LinkedFromNodes[ index ]->Name() << "'"
196 cdebug << "StreamNode::GetLinkedFromNodeIndex of " << name
197 << " in _MapOfLinkedFromNodes not found. Known nodes :" << endl ;
199 map< string , int >::iterator aMapOfLinkedFromNodesIterator1 ;
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()
212 cdebug << "_MapOfLinkedFromNodes" << iifrom << " of " << ToNode->Name() << " : "
213 << aMapOfLinkedFromNodesIterator1->second - 1 << endl ;
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
228 void DelLinkedFromNodeIndex( const char * name ) {
229 _MapOfLinkedFromNodes.erase( name ) ; } ;
231 int LinkedFromNodesSize() const {
232 return _LinkedFromNodesSize ; } ;
233 void DecrLinkedFromNodesSize() {
234 _LinkedFromNodesSize-- ; } ;
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 ]-- ; } ;
247 StreamNode * LinkedFromNodes( int i ) const { return _LinkedFromNodes[ i ] ; } ;
249 int GetLinkedStreamNodeIndex( const char * name ) {
250 int index = _MapOfLinkedStreamNodes[ name ] -1 ;
252 cdebug << "GetLinkedStreamNodeIndex of " << name
253 << " in _MapOfLinkedStreamNodes : "
254 << index << " Node " << hex << (void *) _LinkedStreamNodes[ index ]
255 << dec << " '" << _LinkedStreamNodes[ index ]->Name() << "'"
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
267 void DelLinkedStreamNodeIndex( const char * name ) {
268 _MapOfLinkedStreamNodes.erase( name ) ; } ;
270 int LinkedStreamNodesSize() const { return _LinkedStreamNodesSize ; } ;
272 const int LinkedInStreamPortsNumber( int i ) const {
273 return _LinkedInStreamPortsNumber[ i ] ; } ;
275 StreamNode * LinkedStreamNodes( int i ) const {
276 return _LinkedStreamNodes[ i ] ; } ;
278 bool BranchOfSwitchDone( bool aNodeDoneInBranchOfSwitch ) {
279 bool prevalue = _NodeDoneInBranchOfSwitch ;
280 _NodeDoneInBranchOfSwitch = aNodeDoneInBranchOfSwitch ;
281 if ( prevalue && !aNodeDoneInBranchOfSwitch ) {
285 bool BranchOfSwitchDone() {
286 return _NodeDoneInBranchOfSwitch ; } ;
288 void HeadNode( bool aHeadNode ) { _HeadNode = aHeadNode ; } ;
289 const bool IsHeadNode() const { return _HeadNode ; } ;
291 int Level() const { return _LevelNumber ; } ;
292 void Level( int LevelNumber ) {
293 _LevelNumber = LevelNumber ; } ;
295 void SortedIndex( int aSortedIndex ) {
296 _SortedIndex = aSortedIndex ; } ;
297 int SortedIndex() const {
298 return _SortedIndex ; } ;
300 void SetSubStreamGraph( int SubStreamGraphsNumber , int & RetVal ) ;
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 ; } ;
309 void GraphMacroLevel( int aGraphMacroLevel ) {
310 cdebug << "GraphMacroLevel " << Name() << " " << aGraphMacroLevel << endl ;
311 _GraphMacroLevel = aGraphMacroLevel ; } ;
312 int GraphMacroLevel() const {
313 return _GraphMacroLevel ; } ;
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 ;
321 cdebug << "MacroObject GraphMacroNode " << this << " " << Name()
322 << " MacroObject " << _GraphMacroNode << endl ;
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 ;
330 return _GraphMacroNode ; } ;
332 void GraphOfNode( GraphBase::Graph * aGraph ) {
333 _GraphOfNode = aGraph ; } ;
334 GraphBase::Graph * GraphOfNode() const {
335 return _GraphOfNode ; } ;
336 GraphBase::Graph * GraphOfNode() {
337 return _GraphOfNode ; } ;
339 int SubGraph() const { return _SubGraphNumber ; } ;
340 void SubGraph( int SubGraphNumber ) {
341 _SubGraphNumber = SubGraphNumber ; } ;
343 int SubStreamGraph() const { return _SubStreamGraphNumber ; } ;
344 void SubStreamGraph( int SubStreamGraphNumber ) {
345 _SubStreamGraphNumber = SubStreamGraphNumber ; } ;
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 ) ;
355 void AddStreamLinkedNode( StreamNode * ToNode ) ;
356 bool RemoveStreamLinkedNode( StreamNode * ToNode ) ;
357 void ReNameStreamLinkedNode( const char* OldNodeName ,
358 const char* NewNodeName ) ;