Salome HOME
Bug fix: don't set "Loading" state for MacroNodes in InitialState() function (called...
[modules/superv.git] / src / GraphEditor / DataFlowEditor_OutNode.cxx
1 //  SUPERV GraphEditor : contains classes that permit edition of graphs
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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : DataFlowEditor_OutNode.cxx
25 //  Module : SUPERV
26
27 using namespace std;
28 #include <sstream>
29 #include <iostream>
30 #include "DataFlowEditor_DataFlow.hxx"
31 #include "DataFlowEditor_OutNode.hxx"
32 #include "DataFlowBase_EndOfLoopNode.hxx"
33 #include "DataFlowBase_EndOfSwitchNode.hxx"
34
35 //map< string , GraphBase::Graph * > GraphEditor::OutNode::_MapOfGraphs;
36 map< string , int > _MapOfGraphNames;
37
38 string GraphInstanceName( const char * aGraphName ) {
39   int GraphInstanceNumber = _MapOfGraphNames[ aGraphName ] ;
40   if ( GraphInstanceNumber ) {
41     _MapOfGraphNames[ aGraphName ] = GraphInstanceNumber + 1 ;
42   }
43   else {
44     GraphInstanceNumber = 0 ;
45     _MapOfGraphNames[ aGraphName ] = GraphInstanceNumber + 1 ;
46   }
47   string theGraphInstanceName = string( aGraphName ) ;
48   if ( GraphInstanceNumber ) {
49     theGraphInstanceName += "_" ;
50     ostringstream astr ;
51     astr << GraphInstanceNumber ;
52     theGraphInstanceName += astr.str() ;
53   }
54   return theGraphInstanceName ;
55 }
56
57
58 // Implementation de la classe GraphEditor::Graph
59
60 GraphEditor::OutNode::OutNode() {
61 //             Graph() {
62   cdebug_in << "GraphEditor::OutNode::OutNode()" << endl;
63
64   _Graph = NULL ;
65   _Imported = false ;
66   _Valid = false ;
67   _Executable = false ;
68
69   cdebug_out << "GraphEditor::OutNode::OutNode()" << endl;
70 }
71
72 GraphEditor::OutNode::OutNode( CORBA::ORB_ptr ORB ,
73                                SALOME_NamingService * ptrNamingService ,
74                                const char * DataFlowName ,
75                                const char * DebugFileName ,
76                                const SUPERV::KindOfNode aKindOfNode ) {
77 //             Graph( ORB , ptrNamingService , DataFlowName , DebugFileName ) {
78   _Graph = NULL ;
79   Set_prof_debug( ORB , DebugFileName ) ;
80   cdebug_in << "GraphEditor::OutNode::OutNode(" ;
81   if ( DataFlowName ) {
82     cdebug << DataFlowName ;
83   }
84   cdebug << ")" << endl;
85
86   if ( aKindOfNode == SUPERV::DataFlowGraph ) {
87     _StreamGraph = NULL ;
88     _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowName , aKindOfNode ,
89                                    _prof_debug , _fdebug ) ; 
90 //    MapGraph( _Graph , _Graph->Name() ) ;
91   }
92   else if ( aKindOfNode == SUPERV::DataStreamGraph ) {
93     _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowName , aKindOfNode ,
94                                                _prof_debug , _fdebug ) ;
95     _Graph = _StreamGraph ;
96 //    MapGraph( _Graph , _Graph->Name() ) ;
97   }
98   _Orb = CORBA::ORB::_duplicate( ORB ) ;
99   _Imported = false ;
100   _Valid = false ;
101   _Executable = false ;
102
103   cdebug_out << "GraphEditor::OutNode::OutNode" << endl;
104 }
105
106 GraphEditor::OutNode::OutNode(
107                      CORBA::ORB_ptr ORB ,
108                      SALOME_NamingService * ptrNamingService ,
109                      const SALOME_ModuleCatalog::Service& DataFlowService ,
110                      const char * DataFlowComponentName ,
111                      const char * DataFlowInterfaceName ,
112                      const char * DataFlowName ,
113                      const SUPERV::KindOfNode DataFlowkind ,
114                      const SUPERV::SDate DataFlowFirstCreation ,
115                      const SUPERV::SDate DataFlowLastModification ,
116                      const char * DataFlowEditorRelease ,
117                      const char * DataFlowAuthor ,
118                      const char * DataFlowComputer ,
119                      const char * DataFlowComment ,
120                      const char * DebugFileName ) {
121   _Graph = NULL ;
122   Set_prof_debug( ORB , DebugFileName ) ;
123
124   if ( DataFlowkind == SUPERV::DataFlowGraph ) {
125     _StreamGraph = NULL ;
126     _Graph = new GraphBase::Graph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
127                                    DataFlowInterfaceName , DataFlowName , DataFlowkind ,
128                                    DataFlowFirstCreation , DataFlowLastModification  ,
129                                    DataFlowEditorRelease , DataFlowAuthor ,
130                                    DataFlowComputer , DataFlowComment ,
131                                    _prof_debug , _fdebug ) ;
132 //    MapGraph( _Graph , _Graph->Name() ) ;
133   }
134   else if ( DataFlowkind == SUPERV::DataStreamGraph ) {
135     _StreamGraph = new GraphBase::StreamGraph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
136                                                DataFlowInterfaceName , DataFlowName , DataFlowkind ,
137                                                DataFlowFirstCreation , DataFlowLastModification  ,
138                                                DataFlowEditorRelease , DataFlowAuthor ,
139                                                DataFlowComputer , DataFlowComment ,
140                                                _prof_debug , _fdebug ) ;
141     _Graph = _StreamGraph ;
142 //    MapGraph( _Graph , _Graph->Name() ) ;
143   }
144   _Orb = CORBA::ORB::_duplicate( ORB ) ;
145   _Imported = false ;
146   _Valid = false ;
147   _Executable = false ;
148
149 } ;
150
151 GraphEditor::OutNode::~OutNode() {
152 //  EraseGraph( Graph->Name() ) ;
153 //  delete _DataFlowNode ;
154 //  delete _DataFlowDatas ;
155 //  delete _GT ;
156 }
157
158 bool GraphEditor::OutNode::Name( const char * aName ) {
159   bool RetVal = false ;
160 //  if ( !GraphName( aName ) ) {
161 //    char * aGraphName = Graph()->Name() ;
162     RetVal = Graph()->Name( aName ) ;
163 //    if ( RetVal ) {
164 //      EraseGraph( aGraphName ) ;
165 //      MapGraph( Graph() , aName ) ;
166 //    }
167 //  }
168   return RetVal ;
169 }
170
171 void GraphEditor::OutNode::Set_prof_debug( CORBA::ORB_ptr ORB ,
172                                            const char * DebugFileName ) {
173   _Graph_prof_debug = 0 ;
174   _prof_debug = 0 ;
175   if ( DebugFileName ) {
176     _fdebug = new ofstream( DebugFileName );
177     SetDebug( ORB , &_Graph_prof_debug , _fdebug ) ;
178     MESSAGE( endl << "Trace redirected to file " << DebugFileName << endl)
179   }
180 }
181
182 bool GraphEditor::OutNode::LoadDataFlow( const GraphBase::SGraph * aDataFlow ) {
183   bool RetVal = false ;
184   cdebug_in << "GraphEditor::OutNode::LoadDataFlow() " << (*aDataFlow).Info.theName.c_str()
185             << " GraphNodesSize " << Graph()->GraphNodesSize() << endl;
186   if ( !_Imported ) {
187     RetVal = LoadInfo( (*aDataFlow).Info ) ;
188     _Imported = true ;
189   }
190   else if ( Graph()->IsDataStreamNode() || (*aDataFlow).Info.theKind == SUPERV::DataFlowGraph ) {
191     RetVal = true ;
192   }
193   cdebug << "GraphEditor::OutNode::LoadDataFlow() _Imported " << _Imported << " RetVal " << RetVal << endl;
194
195   map< string , int > aMapOfNodes ;
196   if ( RetVal ) {
197     cdebug << "GraphEditor::OutNode::LoadDataFlow() LoadNodes GraphNodesSize " << Graph()->GraphNodesSize() << endl;
198     RetVal = LoadNodes( aMapOfNodes , (*aDataFlow).Nodes ) ;
199   }
200   if ( RetVal ) {
201     cdebug << "GraphEditor::OutNode::LoadDataFlow() LoadLinks GraphNodesSize " << Graph()->GraphNodesSize() << endl;
202     RetVal = LoadLinks( aMapOfNodes , (*aDataFlow).Links ) ;
203   }
204   if ( RetVal ) {
205     Valid() ;
206     cdebug << "GraphEditor::OutNode::LoadDataFlow() LoadDatas GraphNodesSize " << Graph()->GraphNodesSize() << endl;
207     RetVal = LoadDatas( aMapOfNodes , (*aDataFlow).Datas ) ;
208   }
209   cdebug_out << "GraphEditor::OutNode::LoadDataFlow done GraphNodesSize " << Graph()->GraphNodesSize() << endl;
210   return RetVal ;
211 }
212
213 bool GraphEditor::OutNode::LoadXml( const char* myFileName , GraphBase::ListOfSGraphs & aListOfDataFlows ) {
214   bool RetVal = false ;
215 //  GraphBase::ListOfSGraphs aListOfDataFlows ;
216   if ( myFileName == NULL ) {
217     cdebug << "GraphEditor::OutNode::LoadXml() No file" << endl;
218     _Imported = true ;
219     char * aDataFlowName = Graph()->Name() ;
220 //  Name( Graph()->Name() ) ;
221     Name( GraphInstanceName( Graph()->Name() ).c_str() ) ;
222 //    MapGraph( Graph() , Graph()->Name() ) ;
223     cdebug << "GraphEditor::OutNode::LoadXml() " << aDataFlowName << " --> " << Graph()->Name() << endl;
224     RetVal = true ;
225   }
226   else {
227     cdebug_in << "GraphEditor::OutNode::LoadXml() " << myFileName << endl;
228     RetVal = Graph()->LoadXml( _Orb , myFileName , aListOfDataFlows ) ;
229 //    RetVal = LoadDataFlows( &aListOfDataFlows ) ;
230     cdebug_out << "GraphEditor::OutNode::LoadXml " << RetVal << " " << aListOfDataFlows.size()
231                << " Graphs" << endl;
232   }
233   return RetVal ;
234
235
236 #if 0
237 bool GraphEditor::OutNode::LoadXml( const char* myFileName ) {
238   bool RetVal = false ;
239   GraphBase::ListOfSGraphs aListOfDataFlows ;
240   if ( myFileName == NULL ) {
241     cdebug << "GraphEditor::OutNode::LoadXml() No file" << endl;
242     _Imported = true ;
243     RetVal = true ;
244   }
245   else if ( Graph()->LoadXml( _Orb , myFileName , aListOfDataFlows ) ) {
246     cdebug_in << "GraphEditor::OutNode::LoadXml() " << myFileName << endl;
247     RetVal = LoadDataFlows( &aListOfDataFlows ) ;
248     cdebug_out << "GraphEditor::OutNode::LoadXml " << RetVal << endl;
249   }
250   return RetVal ;
251 }
252 #endif
253
254 bool GraphEditor::OutNode::LoadInfo(const GraphBase::SNode &aDataFlowInfo ) {
255   bool RetVal = false ;
256   cdebug_in << "GraphEditor::OutNode::LoadInfo " << aDataFlowInfo.theName.c_str()
257             << endl ;
258 //  MESSAGE( "GraphEditor::OutNode::LoadInfo" );
259 //  ComponentName( aDataFlowInfo.theComponentName.c_str() ) ;
260 //  InterfaceName( aDataFlowInfo.theInterfaceName.c_str() ) ;
261   if ( Graph()->IsDataStreamNode() || aDataFlowInfo.theKind == SUPERV::DataFlowGraph ) {
262     char * aDataFlowName = Graph()->Name() ;
263 //    Graph()->Name( aDataFlowInfo.theName.c_str() ) ;
264     Graph()->Name( GraphInstanceName( aDataFlowInfo.theName.c_str() ).c_str() ) ;
265 //    MapGraph( Graph() , Graph()->Name() ) ;
266     cdebug << "GraphEditor::OutNode::LoadInfo " << aDataFlowName << " --> " << Graph()->Name()
267            << " aDataFlowInfo.Kind " << aDataFlowInfo.theKind << " Kind() " << Graph()->Kind() << endl ;
268     if ( Graph()->IsDataStreamNode() ) {
269       Graph()->Kind( SUPERV::DataStreamGraph ) ;
270       StreamGraph()->SetStreamParams( aDataFlowInfo.theTimeout , aDataFlowInfo.theDataStreamTrace , aDataFlowInfo.theDeltaTime ) ;
271     }
272     else {
273       Graph()->Kind( SUPERV::DataFlowGraph ) ;
274     }
275     Graph()->SetService( aDataFlowInfo.theService ) ;
276     Graph()->FirstCreation( aDataFlowInfo.theFirstCreation ) ;
277     Graph()->LastModification( aDataFlowInfo.theLastModification ) ;
278     Graph()->EditorRelease( aDataFlowInfo.theEditorRelease.c_str() ) ;
279     Graph()->Author( aDataFlowInfo.theAuthor.c_str()  ) ;
280 //    Graph()->Computer( aDataFlowInfo.theContainer.c_str() ) ;
281     Graph()->Comment( aDataFlowInfo.theComment.c_str() ) ;
282 // Not in OutNode/DataFlow but in InNode/DataFlow_in_an_other_DataFlow
283 //    Graph()->Coordinates( aDataFlowInfo.theX , aDataFlowInfo.theY ) ;
284     RetVal = true ;
285   }
286   else {
287     Graph()->Kind( aDataFlowInfo.theKind ) ;
288     cdebug << "GraphEditor::OutNode::LoadInfo aDataFlowInfo.Kind " << aDataFlowInfo.theKind
289            << " != IsDataStreamNode() " << Graph()->IsDataStreamNode() << endl ;
290   }
291   cdebug_out << "GraphEditor::OutNode::LoadInfo " << RetVal << endl ;
292   return RetVal ;
293 }
294
295 bool GraphEditor::OutNode::LoadNodes(map< string , int > & aMapOfNodes ,
296                                      const GraphBase::ListOfSNodes &aListOfNodes ) {
297   GraphEditor::InNode * anInNode ;
298   cdebug_in << "GraphEditor::OutNode::LoadNodes " << endl ;
299   int i ;
300   for ( i = 0 ; i < (int ) aListOfNodes.size() ; i++ ) {
301     GraphBase::SNode aNode = aListOfNodes[ i ] ;
302     const char * aNodeName = aNode.theName.c_str() ;
303 //    cout << "GraphEditor::OutNode::LoadNodes " << aNodeName << " "
304 //         << aNode.theService.ServiceinParameter.length() << " InParameters "
305 //         << aNode.theService.ServiceoutParameter.length() << " OutParameters "
306 //         << aNode.theListOfInDataStreams.size() << " InDataStreams "
307 //         << aNode.theListOfOutDataStreams.size() << " OutDataStreams "
308 //         << " _prof_debug " << _prof_debug << endl ;
309     cdebug << "GraphEditor::OutNode::LoadNodes " << aNodeName << " "
310            << aNode.theService.ServiceinParameter.length() << " InParameters "
311            << aNode.theService.ServiceoutParameter.length() << " OutParameters "
312            << aNode.theListOfInDataStreams.size() << " InDataStreams "
313            << aNode.theListOfOutDataStreams.size() << " OutDataStreams "
314            << endl ;
315     if ( aNode.theListOfFuncName.size() == 0 ) {
316       aNode.theListOfFuncName.resize( 1 ) ;
317       aNode.theListOfFuncName[ 0 ] = "" ;
318       aNode.theListOfPythonFunctions.resize( 1 ) ;
319       aNode.theListOfPythonFunctions[ 0 ] = new SUPERV::ListOfStrings() ;
320     }
321     if ( Graph()->GetGraphNode( aNode.theName.c_str() ) ) {
322       aNodeName = NULLSTRING ;
323     }
324
325     aNode.theService.ServiceinDataStreamParameter.length( aNode.theListOfInDataStreams.size() ) ;
326     aNode.theService.ServiceoutDataStreamParameter.length( aNode.theListOfOutDataStreams.size() ) ;
327     unsigned int j ;
328     for ( j = 0 ; j < aNode.theListOfInDataStreams.size() ; j++ ) {
329       aNode.theService.ServiceinDataStreamParameter[ j ].Parametername = aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parametername ,
330       aNode.theService.ServiceinDataStreamParameter[ j ].Parametertype = aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parametertype ,
331       aNode.theService.ServiceinDataStreamParameter[ j ].Parameterdependency = aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parameterdependency ;
332     }
333     for ( j = 0 ; j < aNode.theListOfOutDataStreams.size() ; j++ ) {
334       aNode.theService.ServiceoutDataStreamParameter[ j ].Parametername = aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parametername ,
335       aNode.theService.ServiceoutDataStreamParameter[ j ].Parametertype = aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parametertype ,
336       aNode.theService.ServiceoutDataStreamParameter[ j ].Parameterdependency = aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parameterdependency ;
337     }
338
339     anInNode = AddNode( aNode.theService ,
340                         aNode.theListOfFuncName ,
341                         aNode.theListOfPythonFunctions ,
342                         aNode.theComponentName.c_str() ,
343                         aNode.theInterfaceName.c_str() , aNodeName ,
344                         aNode.theKind ,
345                         aNode.theFirstCreation , aNode.theLastModification ,
346                         aNode.theEditorRelease.c_str() ,
347                         aNode.theAuthor.c_str() , aNode.theContainer.c_str() ,
348                         aNode.theComment.c_str() ,
349                         aNode.theCoords.theX , aNode.theCoords.theY ) ;
350     string * aNodetheName = new string( aNode.theName ) ;
351     aMapOfNodes[ *aNodetheName ] = Graph()->GetGraphNodeIndex( anInNode->Name() ) ;
352     if ( anInNode->IsOneOfInLineNodes() || anInNode->IsMacroNode() ) {
353       anInNode->GraphEditor::InNode::InLineNode()->DefPortsOfNode(
354                 _Orb , aNode.theService , anInNode->NamePtr() ,
355                 anInNode->Kind() ,
356                 _prof_debug , _fdebug ) ;
357       GraphBase::InLineNode * aINode = anInNode->InLineNode() ;
358       GraphBase::LoopNode * aLNode = NULL ;
359       if ( aINode->IsLoopNode() ) {
360         aLNode = anInNode->LoopNode() ;
361         aLNode->SetPythonFunction( aNode.theListOfFuncName[ 0 ].c_str() ,
362                                    *aNode.theListOfPythonFunctions[ 0 ] ) ;
363         aLNode->SetMorePythonFunction( aNode.theListOfFuncName[ 1 ].c_str() ,
364                                        *aNode.theListOfPythonFunctions[ 1 ] ) ;
365         aLNode->SetNextPythonFunction( aNode.theListOfFuncName[ 2 ].c_str() ,
366                                        *aNode.theListOfPythonFunctions[ 2 ] ) ;
367       }
368       else if ( aINode->IsMacroNode() || aINode->IsInLineNode() || aINode->IsGOTONode() ||
369                 aINode->IsSwitchNode() || aINode->IsEndSwitchNode() ) {
370         aINode->SetPythonFunction( aNode.theListOfFuncName[ 0 ].c_str() ,
371                                    *aNode.theListOfPythonFunctions[ 0 ] ) ;
372       }
373     }
374
375     for ( j = 0 ; j < aNode.theListOfInDataStreams.size() ; j++ ) {
376       GraphBase::InPort * anInPort ;
377       if ( anInNode->IsOneOfInLineNodes() ) {
378         anInPort = anInNode->ComputingNode()->AddInDataStreamPort( aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parametername ,
379                                                                    aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parametertype ,
380                                                                    aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parameterdependency ,
381                                                                    SUPERV::DataStreamParameter ) ;
382       }
383       else {
384         anInPort = anInNode->ComputingNode()->GetChangeInPort( aNode.theListOfInDataStreams[ j ].theDataStreamParameter.Parametername ) ;
385       }
386       ((GraphBase::InDataStreamPort * ) anInPort)->SetParams( aNode.theListOfInDataStreams[ j ].theKindOfSchema ,
387                                                               aNode.theListOfInDataStreams[ j ].theKindOfInterpolation ,
388                                                               aNode.theListOfInDataStreams[ j ].theKindOfExtrapolation ) ;
389     }
390     for ( j = 0 ; j < aNode.theListOfOutDataStreams.size() ; j++ ) {
391       GraphBase::OutPort * anOutPort ;
392       if ( anInNode->IsOneOfInLineNodes() ) {
393         anOutPort = anInNode->ComputingNode()->AddOutDataStreamPort( aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parametername ,
394                                                                      aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parametertype ,
395                                                                      aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parameterdependency ,
396                                                                      SUPERV::DataStreamParameter ) ;
397       }
398       else {
399         anOutPort = anInNode->ComputingNode()->GetChangeOutPort( aNode.theListOfOutDataStreams[ j ].theDataStreamParameter.Parametername ) ;
400       }
401       ((GraphBase::OutDataStreamPort * ) anOutPort)->NumberOfValues( aNode.theListOfOutDataStreams[ j ].theNumberOfValues ) ;
402     }
403     delete aNodetheName ;
404     if ( !anInNode ) {
405       return false ;
406     }
407   }
408
409   // setting coupled pairs of nodes: Loop-EndLoop, Switch-EndSwitch, InLine-GOTO, MacroNode-Graph
410   for ( i = 0 ; i < (int ) aListOfNodes.size() ; i++ ) {
411     GraphBase::SNode aNode = aListOfNodes[ i ] ;
412     cdebug << "GraphEditor::OutNode::LoadNodes " << aNode.theName.c_str() << " Coupled to "
413            << aNode.theCoupledNode.c_str() << endl ;
414     anInNode = (GraphEditor::InNode * ) Graph()->GetChangeGraphNode( aMapOfNodes[ aNode.theName.c_str() ] )->GetInNode() ;
415
416     if ( anInNode->IsOneOfGOTONodes() && strlen( aNode.theCoupledNode.c_str() ) ) {
417       GraphBase::GOTONode * aGOTONode;
418       aGOTONode = (GraphBase::GOTONode * ) anInNode->ComputingNode() ;
419
420       // asv : 25.10.04 : if aNode is a MacroNode, then its coupled node (another Graph) is NOT in aMapOfNodes 
421       //                  and we must couple MacroNode only with name to its subgraph
422       if ( aGOTONode->IsMacroNode() ) {
423         cdebug << "GraphEditor::OutNode::LoadNodes MacroNode " << aNode.theName.c_str()
424                << " is Coupled ONLY WITH NAME to its subgraph " << aNode.theCoupledNode.c_str() << endl;
425         aGOTONode->CoupledNodeName( aNode.theCoupledNode.c_str() ) ;
426       }
427       else { // coupling Loop-EndLoop, Switch-EndSwitch, InLine-GOTO
428         // asv : fix for 6822 : using map because if aNode's name is the same as some existing node's name
429         // aMap will give the correct index any way (aMap has already a different name for aNode, SNode still has old name)
430         int aCoupledNodeIndex = aMapOfNodes[ aNode.theCoupledNode.c_str() ] ;
431         cdebug << "GraphEditor::OutNode::LoadNodes " << aNode.theCoupledNode.c_str()
432                << " index " << aCoupledNodeIndex << endl ;
433         GraphBase::GOTONode * aCoupledNode ;
434         aCoupledNode = (GraphBase::GOTONode * ) Graph()->GetChangeGraphNode( aCoupledNodeIndex ) ;
435         cdebug << "GraphEditor::OutNode::LoadNodes " << aNode.theName.c_str()
436                << " is now Coupled to " << aNode.theCoupledNode.c_str() << endl ;
437         aGOTONode->CoupledNode( aCoupledNode ) ;
438       }
439     }
440   }
441   cdebug_out << "GraphEditor::OutNode::LoadNodes" << endl ;
442   return true ;
443 }
444
445 bool GraphEditor::OutNode::LoadLinks(map< string , int > & aMapOfNodes ,
446                                      const GraphBase::ListOfSLinks &aListOfLinks ) {
447   bool RetVal = true ;
448   cdebug_in << "GraphEditor::OutNode::LoadLinks" << endl ;
449 //  MESSAGE( "GraphEditor::OutNode::LoadLinks" );
450   int i , j ;
451   for ( i = 0 ; i < (int ) aListOfLinks.size() ; i++ ) {
452     GraphBase::SLink aLink = aListOfLinks[ i ] ;
453     string * aLinkFromNodeName = new string( aLink.FromNodeName.c_str() ) ;
454     string * aLinkToNodeName = new string( aLink.ToNodeName.c_str() ) ;
455     cdebug << "LoadLinks " << aLinkFromNodeName->c_str() << "( "
456            << aLink.FromServiceParameterName.c_str() << " ) --> "
457            << aLinkToNodeName->c_str() << "( "
458            << aLink.ToServiceParameterName.c_str() << " )" << endl ;
459     if ( Graph()->GetGraphNode( aMapOfNodes[ aLinkFromNodeName->c_str() ] ) &&
460          Graph()->GetGraphNode( aMapOfNodes[ aLinkToNodeName->c_str() ] ) ) {
461 //      GraphBase::ComputingNode * aFromNode = (GraphBase::ComputingNode * ) Graph()->GetGraphNode( aMapOfNodes[ aLinkFromNodeName->c_str() ] ) ;
462 //      const GraphBase::OutPort * anOutPort = aFromNode->GetOutPort( aLink.FromServiceParameterName.c_str() ) ;
463       RetVal = AddLink( Graph()->GetGraphNode( aMapOfNodes[ aLinkFromNodeName->c_str() ] )->Name() ,
464                         aLink.FromServiceParameterName.c_str() ,
465                         Graph()->GetGraphNode( aMapOfNodes[ aLinkToNodeName->c_str() ] )->Name() ,
466                         aLink.ToServiceParameterName.c_str() ) ;
467 //                        , *anOutPort->Value() ) ;
468     }
469     else {
470       RetVal = false ;
471     }
472 //                      aLink.aLinkValue ) ;
473     if ( !RetVal )
474       break ;
475     else {
476       for ( j = 0 ; j < (int ) aLink.aListOfCoords.size() ; j++ ) {
477         RetVal = AddLinkCoord( Graph()->GetGraphNode( aMapOfNodes[ aLinkFromNodeName->c_str() ] )->Name() ,
478                                         aLink.FromServiceParameterName.c_str() ,
479                                         Graph()->GetGraphNode( aMapOfNodes[ aLink.ToNodeName.c_str() ] )->Name() ,
480                                         aLink.ToServiceParameterName.c_str() ,
481                                        j + 1 ,
482                                        aLink.aListOfCoords[j].theX ,
483                                        aLink.aListOfCoords[j].theY ) ;
484         if ( !RetVal )
485           break ;
486       }
487     }
488     delete aLinkFromNodeName ;
489     delete aLinkToNodeName ;
490   }
491   cdebug_out << "GraphEditor::OutNode::LoadLinks" << endl ;
492   return RetVal ;
493 }
494
495 bool GraphEditor::OutNode::LoadDatas(map< string , int > & aMapOfNodes ,
496                                      const GraphBase::ListOfSLinks &aListOfDatas ) {
497   bool RetVal = true ;
498   cdebug_in << "GraphEditor::OutNode::LoadDatas" << endl ;
499 //  MESSAGE( "GraphEditor::OutNode::LoadDatas" );
500   int i ;
501   for ( i = 0 ; i < (int ) aListOfDatas.size() ; i++ ) {
502     GraphBase::SLink aLink = aListOfDatas[ i ] ;
503     cdebug << "OutNode::LoadDatas " << i << aLink.FromNodeName.c_str() << "(" << aLink.FromServiceParameterName
504            << ") --> " << aLink.ToNodeName.c_str() << "(" << aLink.ToServiceParameterName << ") CORBA::tk_xxx "
505            << aLink.aLinkValue.type()->kind() << endl ;
506     string * aLinkFromNodeName = new string( aLink.FromNodeName.c_str() ) ;
507     string * aLinkToNodeName = new string( aLink.ToNodeName.c_str() ) ;
508 //      cout << "LoadDatas " << aLink.FromNodeName.c_str() << " "
509 //           << aMapOfNodes[ aLinkFromNodeName->c_str() ] << endl ;
510 //      cout << "          " << aLink.ToNodeName.c_str() << " "
511 //           << aMapOfNodes[ aLinkToNodeName->c_str() ] << endl ;
512     RetVal = Graph()->AddInputData( Graph()->GetGraphNode( aMapOfNodes[ aLinkToNodeName->c_str() ] )->Name() ,
513                                     aLink.ToServiceParameterName.c_str() ,
514                                     aLink.aLinkValue ) ;
515     delete aLinkFromNodeName ;
516     delete aLinkToNodeName ;
517     if ( !RetVal )
518       break ;
519   }
520   cdebug_out << "GraphEditor::OutNode::LoadDatas" << endl ;
521   return RetVal ;
522 }
523
524 bool GraphEditor::OutNode::SaveXml(const char* filename) {
525   bool test;
526   cdebug_in << "GraphEditor::OutNode::SaveXml(" << filename << ")" << endl;
527   ofstream f(filename);
528   IsValid() ;
529   QDomDocument DomGraph ;
530   QDomElement Domsupergraph ;
531   cdebug << "OutNode::SaveXML("<< filename << ") ---> OutNode::SaveXML( ostream & f , QDomDocument & , true "
532          << " , QDomElement & ) " << Graph()->Name() << endl ;
533   test = SaveXML( f , DomGraph , true , Domsupergraph );
534   QString xml = DomGraph.toString() ;
535   f << xml << endl ;
536
537   cdebug << "OutNode::SaveXML("<< filename << ") done" << endl ;
538 //  if ( test ) {
539 //    QString xml = Graph.toString() ;
540 //    cout << "GraphEditor::OutNode::SaveXML " << xml << endl ;
541 //    f << xml << endl ;
542 //  }
543   cdebug_out << "GraphEditor::OutNode::SaveXml" << endl;
544   return test;
545 }
546
547
548 bool GraphEditor::OutNode::SavePy( const char* filename ) {
549   bool test;
550   cdebug_in << "GraphEditor::OutNode::SavePy(" << filename << ")" << endl;
551   ofstream f( filename ) ;
552   IsValid() ;
553   test = SavePY( f , true );
554   f << endl << Graph()->Name() << " = Def" << Graph()->Name() << "()" << endl ;
555   cdebug_out << "GraphEditor::OutNode::SavePy" << endl;
556   return test;
557 }
558
559 GraphBase::ListOfSGraphs * GraphEditor::OutNode::GetDataFlows( GraphBase::ListOfSGraphs * aListOfDataFlows ) {
560 //  GraphBase::ListOfSGraphs * aListOfDataFlows = new GraphBase::ListOfSGraphs;
561   int index = aListOfDataFlows->size() ;
562   aListOfDataFlows->resize( index + 1 ) ;
563   if ( Graph()->IsDataFlowNode() ) {
564     (*aListOfDataFlows)[ index ].Info = *Graph()->GetInfo() ;
565     (*aListOfDataFlows)[ index ].Nodes = *Graph()->GetNodes() ;
566     (*aListOfDataFlows)[ index ].Links = *Graph()->GetLinks( true ) ;
567     (*aListOfDataFlows)[ index ].Datas = *Graph()->GetDatas() ;
568   }
569   else {
570     (*aListOfDataFlows)[ index ].Info = *StreamGraph()->GetInfo() ;
571     (*aListOfDataFlows)[ index ].Nodes = *StreamGraph()->GetNodes() ;
572     (*aListOfDataFlows)[ index ].Links = *StreamGraph()->GetLinks( true ) ;
573     (*aListOfDataFlows)[ index ].Datas = *StreamGraph()->GetDatas() ;
574   }
575   int i ;
576   for ( i = 0 ; i < (int ) (*aListOfDataFlows)[ index ].Nodes.size() ; i++ ) {
577     const GraphBase::ComputingNode * aNode = Graph()->GetGraphNode( (*aListOfDataFlows)[ index ].Nodes[i].theName.c_str() ) ;
578     if ( aNode->IsMacroNode() ) {
579 //      string aCoupledNodeName = (*aListOfDataFlows)[ index ].Nodes[i].theCoupledNode ;
580       GraphBase::Graph * aGraph = (GraphBase::Graph * ) ((GraphBase::GOTONode * ) aNode )->CoupledNode() ;
581 //      GraphBase::Graph * aGraph = MapGraph( aCoupledNodeName.c_str() ) ;
582       aGraph->GraphEditor()->GraphEditor::OutNode::GetDataFlows( aListOfDataFlows ) ;
583     }
584   }
585   return aListOfDataFlows ;
586 }
587
588 void GraphEditor::OutNode::DateModification() {
589   time_t T = time(NULL);
590   struct tm * Tm = localtime(&T);
591   SUPERV::SDate aLastModificationDate ;
592
593   aLastModificationDate.Second = Tm->tm_sec;
594   aLastModificationDate.Minute = Tm->tm_min;
595   aLastModificationDate.Hour   = Tm->tm_hour;
596   aLastModificationDate.Day    = Tm->tm_mday;
597   aLastModificationDate.Month  = Tm->tm_mon + 1;
598   aLastModificationDate.Year   = Tm->tm_year + 1900;
599   Graph()->LastModification( aLastModificationDate ) ;
600 }
601
602 void GraphEditor::OutNode::Coordinates( const char* NodeName ,
603                                         const int X ,
604                                         const int Y ) {
605   ((GraphEditor::InNode * ) Graph()->GetChangeGraphNode( NodeName ))->Coordinates( X , Y ) ;
606 }
607
608 const int GraphEditor::OutNode::XCoordinate( const char* NodeName ) {
609   return ((GraphEditor::InNode * ) Graph()->GetChangeGraphNode( NodeName ))->XCoordinate() ;
610 }
611
612 const int GraphEditor::OutNode::YCoordinate( const char* NodeName ) {
613   return ((GraphEditor::InNode * ) Graph()->GetChangeGraphNode( NodeName ))->YCoordinate() ;
614 }
615
616 GraphEditor::InNode * GraphEditor::OutNode::AddNode(
617                       const SALOME_ModuleCatalog::Service& NodeService ,
618                       GraphBase::ListOfFuncName aFuncName ,
619                       GraphBase::ListOfPythonFunctions aPythonFunction ,
620                       const char * NodeComponentName ,
621                       const char * NodeInterfaceName ,
622                       const char * theNodeName ,
623                       const SUPERV::KindOfNode NodeKindOfNode ,
624                       const SUPERV::SDate NodeFirstCreation ,
625                       const SUPERV::SDate NodeLastModification  ,
626                       const char * NodeEditorRelease ,
627                       const char * NodeAuthor ,
628                       const char * NodeComputer ,
629                       const char * NodeComment ,
630                       const int NodeX ,
631                       const int NodeY ) {
632   cdebug_in << "GraphEditor::OutNode::AddNode( " ;
633   if ( NodeComponentName != NULLSTRING && strlen( NodeComponentName ) ) {
634     cdebug << "Component('" << NodeComponentName << "') , Node('" ;
635   }
636   else {
637     cdebug << "NodeComponentName[NULL] )" << endl;
638   }
639   if ( theNodeName == NULL ) {
640     theNodeName = NULLSTRING ;
641   }
642   if ( theNodeName != NULLSTRING && strlen( theNodeName ) ) {
643     cdebug << theNodeName << "' )" ;
644   }
645   else {
646     cdebug << "NodeName[NULLSTRING]' )" ;
647   }
648   cdebug << " " << NodeKindOfNode << endl ;
649   char * RetVal = NULLSTRING ;
650   GraphEditor::InNode *Nd = NULL ;
651   char * aNodeName = NULLSTRING ;
652   bool   GeneratedName = false ;
653   if ( NodeKindOfNode == SUPERV::InLineNode ||
654        NodeKindOfNode == SUPERV::LoopNode ||
655        NodeKindOfNode == SUPERV::EndLoopNode ||
656        NodeKindOfNode == SUPERV::SwitchNode ||
657        NodeKindOfNode == SUPERV::EndSwitchNode ||
658        NodeKindOfNode == SUPERV::GOTONode ) {
659     if ( theNodeName == NULLSTRING || strlen( theNodeName ) == 0 ) {
660       if ( NodeKindOfNode == SUPERV::InLineNode ) {
661         ((SALOME_ModuleCatalog::Service& ) NodeService).ServiceName = my_strdup( "InLine" ) ;
662       }
663       else if ( NodeKindOfNode == SUPERV::LoopNode ) {
664         ((SALOME_ModuleCatalog::Service& ) NodeService).ServiceName = my_strdup( "Loop" ) ;
665       }
666       else if ( NodeKindOfNode == SUPERV::EndLoopNode ) {
667         ((SALOME_ModuleCatalog::Service& ) NodeService).ServiceName = my_strdup( "EndLoop" ) ;
668       }
669       else if ( NodeKindOfNode == SUPERV::SwitchNode ) {
670         ((SALOME_ModuleCatalog::Service& ) NodeService).ServiceName = my_strdup( "Switch" ) ;
671       }
672       else if ( NodeKindOfNode == SUPERV::EndSwitchNode ) {
673         ((SALOME_ModuleCatalog::Service& ) NodeService).ServiceName = my_strdup( "EndSwitch" ) ;
674       }
675       else if ( NodeKindOfNode == SUPERV::GOTONode ) {
676         ((SALOME_ModuleCatalog::Service& ) NodeService).ServiceName = my_strdup( "GOTO" ) ;
677       }
678     }
679     else {
680       ((SALOME_ModuleCatalog::Service& ) NodeService).ServiceName = CORBA::string_dup( theNodeName ) ;
681     }
682     theNodeName = NULLSTRING ;
683   }
684   if ( theNodeName == NULLSTRING || strlen( theNodeName ) == 0 || Graph()->GetGraphNode( theNodeName ) ) {
685     aNodeName = new char[ strlen( NodeService.ServiceName )+1 ] ;
686     strcpy( aNodeName , NodeService.ServiceName ) ;
687     if ( Graph()->GetGraphNode( NodeService.ServiceName ) ) {
688       GeneratedName = true ;
689       while ( Graph()->GetGraphNode( aNodeName ) ) {
690         if ( aNodeName ) {
691           delete [] aNodeName ;
692         }
693         int num = Graph()->GetServiceNameNumber( NodeService ) ;
694         ostringstream astr ;
695         astr << num << ends ;
696         const char * n_instance = astr.str().c_str() ;
697         int lname = strlen( NodeService.ServiceName ) + 1 +
698                     strlen( n_instance ) + 1 ;
699         aNodeName = new char[lname] ;
700         strcpy( aNodeName , NodeService.ServiceName ) ;
701         strcat( aNodeName , "_" ) ;
702         strcat( aNodeName , n_instance ) ;
703       }
704     }
705   }
706   else {
707     if ( Graph()->GetGraphNode( theNodeName ) == NULL ) {
708       aNodeName = new char[ strlen( theNodeName )+1 ] ;
709       strcpy( aNodeName , theNodeName ) ;
710     }
711     else {
712       aNodeName = NULLSTRING ;
713     }
714   }
715   if ( aNodeName != NULLSTRING ) {
716     Nd = new GraphEditor::InNode( _Orb , Graph()->NamingService() ,
717                                   aFuncName , aPythonFunction , NodeService ,
718                                   NodeComponentName , NodeInterfaceName ,
719                                   aNodeName , NodeKindOfNode ,
720                                   NodeFirstCreation , NodeLastModification ,
721                                   NodeEditorRelease , NodeAuthor ,
722                                   NodeComputer , NodeComment , GeneratedName ,
723                                   NodeX , NodeY ,
724                                   _prof_debug , _fdebug ) ;
725     
726     // asv: 28.09.04 fix for 6621
727     //if ( Nd->IsMacroNode() )
728     //  MapGraph( Nd->GraphMacroNode(), aNodeName );
729
730     if ( Graph()->IsDataStreamNode() && ( Nd->IsComputingNode() || Nd->IsFactoryNode() ) ) {
731       unsigned int i ;
732       for ( i = 0 ; i < NodeService.ServiceinDataStreamParameter.length() ; i++ ) {
733         GraphBase::InDataStreamPort * aDataStreamPort ;
734         aDataStreamPort = Nd->ComputingNode()->AddInDataStreamPort(
735                                          my_strdup( NodeService.ServiceinDataStreamParameter[i].Parametername ) ,
736                                          NodeService.ServiceinDataStreamParameter[i].Parametertype ,
737                                          NodeService.ServiceinDataStreamParameter[i].Parameterdependency ,
738                                          SUPERV::DataStreamParameter ) ;
739       }
740       for ( i = 0 ; i < NodeService.ServiceoutDataStreamParameter.length() ; i++ ) {
741         GraphBase::OutDataStreamPort * aDataStreamPort ;
742         aDataStreamPort = Nd->ComputingNode()->AddOutDataStreamPort(
743                                          my_strdup( NodeService.ServiceoutDataStreamParameter[i].Parametername ) ,
744                                          NodeService.ServiceoutDataStreamParameter[i].Parametertype ,
745                                          NodeService.ServiceoutDataStreamParameter[i].Parameterdependency ,
746                                          SUPERV::DataStreamParameter ) ;
747       }
748     }
749
750     if ( Graph()->AddNode( Nd->ComputingNode() ) ) {
751       DateModification() ;
752       RetVal = Nd->Name() ;
753     }
754     else {
755       cdebug << "NodeName already exists." << endl ;
756     }
757   }
758   else {
759     cdebug << "ERROR NodeName is NULL or already exists." << endl ;
760   }
761 //  delete [] aNodeName ;
762   cdebug_out << "GraphEditor::OutNode::AddNode" << endl;
763   _Valid = false ;
764   return Nd ;
765 }
766
767 bool GraphEditor::OutNode::AddLinkCoord( const char* FromNodeName ,
768                                          const char* FromServiceParameterName ,
769                                          const char* ToNodeName ,
770                                          const char* ToServiceParameterName ,
771                                          const int nXY ,
772                                          const int* X ,
773                                          const int* Y ) {
774   GraphBase::InPort * anInPort = Graph()->GetChangeInPort( ToNodeName ,
775                                                            ToServiceParameterName ) ;
776 //  cdebug << "GraphEditor::OutNode::AddLinkCoord " << ToNodeName << "( " << ToServiceParameterName
777 //         << " ) " << anInPort << " IsEndSwitch " << anInPort->IsEndSwitch() << endl ;
778   if ( anInPort ) {
779     if ( anInPort->IsEndSwitch() ) {
780 //      cdebug << "GraphEditor::OutNode::AddLinkCoord " << FromNodeName << "( " << FromServiceParameterName
781 //             << " )" << endl ;
782       return Graph()->GetChangeOutPort( FromNodeName , FromServiceParameterName )->AddCoord( nXY , X , Y ) ;
783     }
784     else {
785       return anInPort->AddCoord( nXY , X , Y ) ;
786     }
787   }
788   return false ;
789 }
790
791 bool GraphEditor::OutNode::AddLinkCoord( const char* FromNodeName ,
792                                          const char* FromServiceParameterName ,
793                                          const char* ToNodeName ,
794                                          const char* ToServiceParameterName ,
795                                          const int index ,
796                                          const int X ,
797                                          const int Y ) {
798   GraphBase::InPort * anInPort = Graph()->GetChangeInPort( ToNodeName ,
799                                                            ToServiceParameterName ) ;
800 //  cdebug << "GraphEditor::OutNode::AddLinkCoord " << ToNodeName << "( " << ToServiceParameterName
801 //         << " ) " << anInPort << " IsEndSwitch " << anInPort->IsEndSwitch() << endl ;
802   if ( anInPort ) {
803     if ( anInPort->IsEndSwitch() ) {
804 //      cdebug << "GraphEditor::OutNode::AddLinkCoord " << FromNodeName << "( " << FromServiceParameterName
805 //             << " )" << endl ;
806       return Graph()->GetChangeOutPort( FromNodeName , FromServiceParameterName )->AddCoord( index , X , Y ) ;
807     }
808     else {
809       return anInPort->AddCoord( index , X , Y ) ;
810     }
811   }
812   return false ;
813 }
814
815 bool GraphEditor::OutNode::ChangeLinkCoord( const char* FromNodeName ,
816                                             const char* FromServiceParameterName ,
817                                             const char* ToNodeName ,
818                                             const char* ToServiceParameterName ,
819                                             const int index ,
820                                             const int X ,
821                                             const int Y ) {
822   GraphBase::InPort * anInPort = Graph()->GetChangeInPort( ToNodeName ,
823                                                            ToServiceParameterName ) ;
824 //  cdebug << "GraphEditor::OutNode::ChangeLinkCoord " << ToNodeName << "( " << ToServiceParameterName
825 //         << " ) " << anInPort << " IsEndSwitch " << anInPort->IsEndSwitch() << endl ;
826   if ( anInPort ) {
827     if ( anInPort->IsEndSwitch() ) {
828 //      cdebug << "GraphEditor::OutNode::ChangeLinkCoord " << FromNodeName << "( " << FromServiceParameterName
829 //             << " )" << endl ;
830       return Graph()->GetChangeOutPort( FromNodeName , FromServiceParameterName )->ChangeCoord( index , X , Y ) ;
831     }
832     else {
833       return anInPort->ChangeCoord( index , X , Y ) ;
834     }
835   }
836   return false ;
837 }
838
839 bool GraphEditor::OutNode::RemoveLinkCoord( const char* FromNodeName ,
840                                             const char* FromServiceParameterName ,
841                                             const char* ToNodeName ,
842                                             const char* ToServiceParameterName ,
843                                             const int index ) {
844   GraphBase::InPort * anInPort = Graph()->GetChangeInPort( ToNodeName ,
845                                                            ToServiceParameterName ) ;
846 //  cdebug << "GraphEditor::OutNode::RemoveLinkCoord " << ToNodeName << "( " << ToServiceParameterName
847 //         << " ) " << anInPort << " IsEndSwitch " << anInPort->IsEndSwitch() << endl ;
848   if ( anInPort ) {
849     if ( anInPort->IsEndSwitch() ) {
850 //      cdebug << "GraphEditor::OutNode::RemoveLinkCoord " << FromNodeName << "( " << FromServiceParameterName
851 //             << " )" << endl ;
852       return Graph()->GetChangeOutPort( FromNodeName , FromServiceParameterName )->RemoveCoord( index ) ;
853     }
854     else {
855       return anInPort->RemoveCoord( index ) ;
856     }
857   }
858   return false ;
859 }
860
861 int GraphEditor::OutNode::GetLinkCoordSize( const char* FromNodeName ,
862                                             const char* FromServiceParameterName ,
863                                             const char* ToNodeName ,
864                                             const char* ToServiceParameterName ) {
865   const GraphBase::InPort * anInPort = Graph()->GetInPort( ToNodeName , ToServiceParameterName ) ;
866 //  cdebug << "GraphEditor::OutNode::GetLinkCoordSize " << ToNodeName << "( " << ToServiceParameterName
867 //         << " ) " << anInPort << " IsEndSwitch " << anInPort->IsEndSwitch() << endl ;
868   if ( anInPort ) {
869     if ( anInPort->IsEndSwitch() ) {
870 //      cdebug << "GraphEditor::OutNode::GetLinkCoordSize " << FromNodeName << "( " << FromServiceParameterName
871 //             << " )" << endl ;
872       return Graph()->GetChangeOutPort( FromNodeName , FromServiceParameterName )->GetCoord() ;
873     }
874     else {
875       return anInPort->GetCoord() ;
876     }
877   }
878   return 0 ;
879 }
880
881 bool GraphEditor::OutNode::GetLinkCoord( const char* FromNodeName ,
882                                          const char* FromServiceParameterName ,
883                                          const char* ToNodeName ,
884                                          const char* ToServiceParameterName ,
885                                          int *X , int *Y ) {
886   const GraphBase::InPort * anInPort = Graph()->GetInPort( ToNodeName , ToServiceParameterName ) ;
887 //  cdebug << "GraphEditor::OutNode::GetLinkCoord " << ToNodeName << "( " << ToServiceParameterName
888 //         << " ) " << anInPort << " IsEndSwitch " << anInPort->IsEndSwitch() << endl ;
889   if ( anInPort ) {
890     if ( anInPort->IsEndSwitch() ) {
891 //      cdebug << "GraphEditor::OutNode::GetLinkCoord " << FromNodeName << "( " << FromServiceParameterName
892 //             << " )" << endl ;
893       return Graph()->GetChangeOutPort( FromNodeName , FromServiceParameterName )->GetCoord( X , Y ) ;
894     }
895     else {
896       return anInPort->GetCoord( X , Y ) ;
897     }
898   }
899   return false ;
900 }
901
902 bool GraphEditor::OutNode::GetLinkCoord( const char* FromNodeName ,
903                                          const char* FromServiceParameterName ,
904                                          const char* ToNodeName ,
905                                          const char* ToServiceParameterName ,
906                                          const int index , long &X , long &Y ) {
907   GraphBase::InPort * anInPort = Graph()->GetChangeInPort( ToNodeName ,
908                                                            ToServiceParameterName ) ;
909 //  cdebug << "GraphEditor::OutNode::GetLinkCoord " << ToNodeName << "( " << ToServiceParameterName
910 //         << " ) " << anInPort << " IsEndSwitch " << anInPort->IsEndSwitch() << endl ;
911   if ( anInPort ) {
912     if ( anInPort->IsEndSwitch() ) {
913 //      cdebug << "GraphEditor::OutNode::GetLinkCoord " << FromNodeName << "( " << FromServiceParameterName
914 //             << " )" << endl ;
915       return Graph()->GetChangeOutPort( FromNodeName , FromServiceParameterName )->GetCoord( index , X , Y ) ;
916     }
917     else {
918       return anInPort->GetCoord( index , X , Y ) ;
919     }
920   }
921   return false ;
922 }
923
924 bool GraphEditor::OutNode::UnValid() {
925   bool RetVal = _Valid ;
926   _Valid = false ;
927   if ( Graph()->GraphMacroLevel() != 0 ) {
928     cdebug << "GraphEditor::OutNode::UnValid() GraphMacroLevel " << Graph()->GraphMacroLevel() << endl ;
929     RetVal = Valid() ;
930   }
931   return RetVal ;
932 }
933
934 bool GraphEditor::OutNode::Valid() {
935   if ( _Valid )
936     return true ;
937
938   cdebug_in << "GraphEditor::OutNode::Valid" << endl;
939   _Executable = false ;
940
941   if ( !Graph()->CreateService() ) {
942     cdebug_out << "GraphEditor::OutNode::Valid " << _Valid << endl;
943     return false ;
944   }
945   
946   if ( Graph()->GraphMacroLevel() != 0 ) {
947     cdebug << "CoupledNode " << Graph()->CoupledNode() << endl ;
948     cdebug << "GraphEditor " << Graph()->CoupledNode()->GraphEditor() << endl ;
949     cdebug << "Graph " << Graph()->CoupledNode()->GraphEditor()->Graph() << endl ;
950     cdebug << "Name " << Graph()->CoupledNode()->GraphEditor()->Graph()->Name() << endl ;
951     cdebug << "Valid --> UpdateMacroPorts of " << Graph()->CoupledNodeName() << " of "
952            << Graph()->CoupledNode()->GraphEditor()->Graph()->Name() << endl ;
953     cdebug << Graph()->CoupledNode() << endl ;
954     Graph()->CoupledNode()->UpdateMacroPorts( Graph() ) ;
955     cdebug << Graph()->CoupledNode()->Name() << " Valid --> UnValid of graph "
956            << Graph()->CoupledNode()->GraphEditor()->Graph()->Name()
957            << " GraphMacroLevel " << Graph()->CoupledNode()->GraphEditor()->Graph()->GraphMacroLevel()  << endl ;
958     Graph()->CoupledNode()->GraphEditor()->UnValid() ;
959   }
960
961   int SubStreamGraphsNumber = 0 ;
962   if ( !Graph()->Sort( SubStreamGraphsNumber ) ) {
963     cdebug_out << "This DataFlow is not valid." << endl ;
964     return false ;
965   }
966   if ( Graph()->IsDataStreamNode() ) {
967     StreamGraph()->SubStreamGraphsNumber( SubStreamGraphsNumber ) ;
968   }
969   
970 //  CreateService() ;
971
972   Graph()->InLineServices() ;
973
974   Graph()->ComputingNodes() ;
975
976   _Valid = true ;
977
978   cdebug_out << "GraphEditor::OutNode::Valid " << _Valid << endl;
979   return _Valid ;
980 }
981
982 bool GraphEditor::OutNode::Executable() {
983   cdebug_in << "GraphEditor::OutNode::Executable" << endl;
984   bool NewLink ;
985   if ( Graph()->LinkLoopNodes( NewLink ) ) {
986     if ( NewLink ) {
987       _Valid = false ;
988     }
989   }
990   else {
991     cdebug << "This DataFlow is not executable." << endl ;
992     _Executable = false ;
993   }
994   if ( !IsValid() ) {
995     Valid() ;
996   }
997   if ( !IsValid() ) {
998     return false ;
999   }
1000   if ( Graph()->DataServerNodes() )
1001     _Executable = true ;
1002   else {
1003     cdebug << "This DataFlow is not executable." << endl ;
1004     _Executable = false ;
1005   }
1006
1007   if ( _Executable && Graph()->IsDataStreamNode() ) {
1008     StreamGraph()->CreateStreamTopology( "/tmp/" ) ;
1009   }
1010
1011   // asv : 13.12.04 : introducing check for compatibility of linked ports' types.
1012   if ( !IsLinksCompatible() ) {
1013     _Executable = false;
1014   }    
1015
1016   cdebug_out << "GraphEditor::OutNode::Executable" << endl;
1017   return _Executable ;
1018 }
1019
1020 const CORBA::Any *GraphEditor::OutNode::GetInData(
1021                               const char * ToNodeName ,
1022                               const char * ToParameterName ) {
1023 //  cdebug_in << "GraphEditor::OutNode::GetInData " << ToNodeName
1024 //            << " " << ToParameterName << endl ;
1025   const CORBA::Any * retdata = Graph()->PortInData( ToNodeName , ToParameterName ) ;
1026 //  cdebug_out << "GraphEditor::OutNode::GetInData" << endl ;
1027   return retdata ;
1028 }
1029
1030 const CORBA::Any *GraphEditor::OutNode::GetOutData(
1031                               const char * FromNodeName ,
1032                               const char * FromParameterName ) {
1033 //  cdebug_in << "GraphEditor::OutNode::GetOutData " << FromNodeName
1034 //            << " " << FromParameterName << endl ;
1035   const CORBA::Any * retdata = Graph()->PortOutData( FromNodeName , FromParameterName ) ;
1036 //  cdebug_out << "GraphEditor::OutNode::GetOutData" << endl ;
1037   return retdata ;
1038 }
1039
1040 //bool GraphEditor::OutNode::LinkSaveXML( ostream &f , char *Tabs ,
1041 bool GraphEditor::OutNode::LinkSaveXML( QDomDocument & Graph , QDomElement & link ,
1042                                         GraphBase::SLink aLink ,
1043                                         bool wdata ) const {
1044   cdebug_in << "GraphEditor::OutNode::LinkSaveXML " << aLink.FromNodeName
1045             << "(" << aLink.FromServiceParameterName << ") --> "
1046             << aLink.ToNodeName << "(" << aLink.ToServiceParameterName << ")" << endl ;
1047   QDomElement fromnodename = Graph.createElement( "fromnode-name" ) ;
1048   QDomText aField ;
1049   if ( strlen( aLink.FromNodeName.c_str() ) ) {
1050 //    f << Tabs << "<fromnode-name>" << aLink.FromNodeName.c_str()
1051 //      << "</fromnode-name>" << endl ;
1052     aField = Graph.createTextNode( aLink.FromNodeName.c_str() ) ;
1053   }
1054   else {
1055 //    f << Tabs << "<fromnode-name>?</fromnode-name>" << endl ;
1056     aField = Graph.createTextNode( "?" ) ;
1057   }
1058   link.appendChild( fromnodename ) ;
1059   fromnodename.appendChild( aField ) ;
1060
1061 //  f << Tabs << "<fromserviceparameter-name>"
1062 //    << aLink.FromServiceParameterName.c_str() << "</fromserviceparameter-name>"
1063 //    << endl ;
1064   QDomElement fromserviceparametername = Graph.createElement( "fromserviceparameter-name" ) ;
1065   aField = Graph.createTextNode( aLink.FromServiceParameterName.c_str() ) ;
1066   link.appendChild( fromserviceparametername ) ;
1067   fromserviceparametername.appendChild( aField ) ;
1068
1069   QDomElement tonodename = Graph.createElement( "tonode-name" ) ;
1070   if ( strlen( aLink.ToNodeName.c_str() ) ) {
1071 //    f << Tabs << "<tonode-name>" << aLink.ToNodeName.c_str()
1072 //      << "</tonode-name>" << endl ;
1073     aField = Graph.createTextNode( aLink.ToNodeName.c_str() ) ;
1074   }
1075   else {
1076 //    f << Tabs << "<tonode-name>?</tonode-name>" << endl ;
1077     aField = Graph.createTextNode( "?" ) ;
1078   }
1079   link.appendChild( tonodename ) ;
1080   tonodename.appendChild( aField ) ;
1081
1082 //  f << Tabs << "<toserviceparameter-name>"
1083 //    << aLink.ToServiceParameterName.c_str() << "</toserviceparameter-name>"
1084 //    << endl ;
1085   QDomElement toserviceparametername = Graph.createElement( "toserviceparameter-name" ) ;
1086   aField = Graph.createTextNode( aLink.ToServiceParameterName.c_str() ) ;
1087   link.appendChild( toserviceparametername ) ;
1088   toserviceparametername.appendChild( aField ) ;
1089
1090   if ( wdata ) {
1091 //    f << Tabs << "<data-value>" << endl ;
1092     QDomElement datavalue = Graph.createElement( "data-value" ) ;
1093     link.appendChild( datavalue ) ;
1094 //    f << Tabs << "    <value-type>" << aLink.aLinkValue.type()->kind()
1095 //      << "</value-type>" << endl ;
1096     QDomElement valuetype = Graph.createElement( "value-type" ) ;
1097     QString aKind ;
1098     aKind = aKind.setNum( aLink.aLinkValue.type()->kind() ) ;
1099     aField = Graph.createTextNode( aKind ) ;
1100     datavalue.appendChild( valuetype ) ;
1101     valuetype.appendChild( aField ) ;
1102     switch (aLink.aLinkValue.type()->kind()) {
1103       case CORBA::tk_string: {
1104         char* retstr ;
1105         aLink.aLinkValue >>= retstr;
1106 //        f << Tabs << "        <value>" << retstr << "</value>" << endl ;
1107         QDomElement value = Graph.createElement( "value" ) ;
1108         aField = Graph.createTextNode( retstr ) ;
1109         datavalue.appendChild( value ) ;
1110         value.appendChild( aField ) ;
1111 //        MESSAGE( "ToString( string ) " << retstr );
1112         break ;
1113       }
1114       case CORBA::tk_double: {
1115         double d;
1116         aLink.aLinkValue >>= d;
1117 //        f << Tabs << "        <value>" << d << "</value>" << endl ;
1118         QDomElement value = Graph.createElement( "value" ) ;
1119         QString aKind ;
1120         aKind = aKind.setNum( d ) ;
1121         aField = Graph.createTextNode( aKind ) ;
1122         datavalue.appendChild( value ) ;
1123         value.appendChild( aField ) ;
1124 //        MESSAGE( "ToString( double ) " << d );
1125         break ;
1126       }
1127       case CORBA::tk_long: {
1128         long l;
1129         aLink.aLinkValue >>= l;
1130 //        f << Tabs << "        <value>" << l << "</value>" << endl ;
1131         QDomElement value = Graph.createElement( "value" ) ;
1132         QString aKind ;
1133         aKind = aKind.setNum( l ) ;
1134         aField = Graph.createTextNode( aKind ) ;
1135         datavalue.appendChild( value ) ;
1136         value.appendChild( aField ) ;
1137 //        MESSAGE( "ToString( long ) " << l );
1138         break ;
1139       }
1140       case CORBA::tk_objref: {
1141         char* retstr ;
1142         CORBA::Object_ptr obj ;
1143         aLink.aLinkValue >>= obj ;
1144         retstr = _Orb->object_to_string(obj );
1145 //        f << Tabs << "        <value>" << retstr << "</value>" << endl ;
1146         QDomElement value = Graph.createElement( "value" ) ;
1147         aField = Graph.createTextNode( retstr ) ;
1148         datavalue.appendChild( value ) ;
1149         value.appendChild( aField ) ;
1150 //        MESSAGE( "ToString( object ) " << retstr );
1151         break ;
1152       }
1153       default: {
1154 //        f << Tabs << "        <value>?</value>" << endl ;
1155         QDomElement value = Graph.createElement( "value" ) ;
1156         aField = Graph.createTextNode( "?" ) ;
1157         datavalue.appendChild( value ) ;
1158         value.appendChild( aField ) ;
1159 //        MESSAGE( "Unknown CORBA::Any Type" );
1160         break ;
1161       }
1162     }
1163 //    f << Tabs << "</data-value>" << endl ;
1164   }
1165 //  f << Tabs << "<coord-list>" << endl ;
1166   QDomElement coordlist = Graph.createElement( "coord-list" ) ;
1167   link.appendChild( coordlist ) ;
1168   
1169   int i ;
1170   for ( i = 0 ; i < (int ) aLink.aListOfCoords.size() ; i++ ) {
1171 //    f << Tabs << "    <coord>" << endl ;
1172     QDomElement coord = Graph.createElement( "coord" ) ;
1173     coordlist.appendChild( coord ) ;
1174 //    f << Tabs << "            <x>" << aLink.aListOfCoords[ i ].theX << "</x>" << endl ;
1175     QDomElement x = Graph.createElement( "x" ) ;
1176     QString ax ;
1177     ax = ax.setNum( aLink.aListOfCoords[ i ].theX ) ;
1178     aField = Graph.createTextNode( ax ) ;
1179     coord.appendChild( x ) ;
1180     x.appendChild( aField ) ;    
1181 //    f << Tabs << "            <y>" << aLink.aListOfCoords[ i ].theY << "</y>" << endl ;
1182     QDomElement y = Graph.createElement( "y" ) ;
1183     QString ay ;
1184     ay = ay.setNum( aLink.aListOfCoords[ i ].theY ) ;
1185     aField = Graph.createTextNode( ay ) ;
1186     coord.appendChild( y ) ;
1187     y.appendChild( aField ) ;    
1188 //    f << Tabs << "    </coord>" << endl ;
1189   }
1190 //  f << Tabs << "</coord-list>" << endl ;
1191   cdebug_out << "GraphEditor::OutNode::LinkSaveXML " << aLink.FromNodeName
1192              << "(" << aLink.FromServiceParameterName << ") --> "
1193              << aLink.ToNodeName << "(" << aLink.ToServiceParameterName << ")"
1194              << endl ;
1195   return true ;
1196 }
1197
1198 bool GraphEditor::OutNode::LinkSavePY( ostream &f , const char * aGraphName ,
1199                                        GraphBase::SLink aLink ,
1200                                        bool fromparam , bool toparam ,
1201                                        bool wdata ) const {
1202   if ( !wdata ) {
1203 //    if ( intervar ) {
1204 //      f << "O" << aLink.FromNodeName.c_str() << aLink.FromServiceParameterName.c_str()
1205 //        << " = "
1206 //        << aLink.FromNodeName.c_str() << ".GetOutPort( '"
1207 //        << aLink.FromServiceParameterName.c_str()
1208 //        << "' )" << endl ;
1209 //    }
1210     f << "    " << "L" << aLink.FromNodeName.c_str() << aLink.FromServiceParameterName.c_str()
1211       << aLink.ToNodeName.c_str() << aLink.ToServiceParameterName.c_str() ;
1212     if ( ((GraphBase::Graph *) Graph())->GetChangeGraphNode( aLink.FromNodeName.c_str() )->GetChangeOutPort( aLink.FromServiceParameterName.c_str() )->IsDataStream() ) {
1213       f << " = " << aGraphName << ".StreamLink( " ;
1214     }
1215     else {
1216       f << " = " << aGraphName << ".Link( " ;
1217     }
1218 //    if ( !fromparam ) {
1219       f << "O" ;
1220 //    }
1221     f << aLink.FromNodeName.c_str() << aLink.FromServiceParameterName.c_str() << " , " ;
1222 //    if ( !toparam ) {
1223       f << "I" ;
1224 //    }
1225     f << aLink.ToNodeName.c_str() << aLink.ToServiceParameterName.c_str() << " )" << endl ;
1226   }
1227   else {
1228     f << "    " << "I"<< aLink.ToNodeName.c_str() << aLink.ToServiceParameterName.c_str()
1229 //      << " = " << aLink.ToNodeName.c_str() << ".Input( '"
1230 //      << aLink.ToServiceParameterName.c_str() << "' , " ;
1231       << ".Input( " ;
1232     switch (aLink.aLinkValue.type()->kind()) {
1233       case CORBA::tk_string: {
1234         char* retstr ;
1235         aLink.aLinkValue >>= retstr;
1236         f << "'" << retstr << "'" ;
1237         break ;
1238       }
1239       case CORBA::tk_double: {
1240         double d;
1241         aLink.aLinkValue >>= d;
1242         f << d ;
1243         break ;
1244       }
1245       case CORBA::tk_long: {
1246         long l;
1247         aLink.aLinkValue >>= l;
1248         f << l ;
1249         break ;
1250       }
1251       case CORBA::tk_objref: {
1252         char* retstr ;
1253         CORBA::Object_ptr obj ;
1254         aLink.aLinkValue >>= obj ;
1255         retstr = _Orb->object_to_string(obj );
1256         f << "'" << retstr << "'" ;
1257         break ;
1258       }
1259       default: {
1260         f << "?" ;
1261 //        MESSAGE( "Unknown CORBA::Any Type" );
1262         break ;
1263       }
1264     }
1265     f << " )" << endl ;
1266   }
1267   int i ;
1268   for ( i = 0 ; i < (int ) aLink.aListOfCoords.size() ; i++ ) {
1269     f << "    " << "L" << aLink.FromNodeName.c_str() << aLink.FromServiceParameterName.c_str()
1270       << aLink.ToNodeName.c_str() << aLink.ToServiceParameterName.c_str() << ".AddCoord( " << i+1 << " , "
1271       << aLink.aListOfCoords[ i ].theX << " , "
1272       << aLink.aListOfCoords[ i ].theY << " )" << endl ;
1273   }
1274   return true ;
1275 }
1276
1277 //bool GraphEditor::OutNode::SaveXML(ostream & f ) {
1278 bool GraphEditor::OutNode::SaveXML( ostream & f , QDomDocument & GraphQDom ,
1279                                     bool aSuperGraph , QDomElement & supergraph ) {
1280   cdebug_in << "OutNode::SaveXML( ostream & f , QDomDocument & , " << aSuperGraph << " , QDomElement & ) "
1281             << Graph()->Name() << endl ;
1282   int i ;
1283
1284   QDomElement dataflow ;
1285   if ( aSuperGraph ) {
1286     QString SuperGraph("SuperGraph") ;
1287     GraphQDom = QDomDocument(SuperGraph) ;
1288
1289     supergraph = GraphQDom.createElement( "supergraph" ) ;
1290     GraphQDom.appendChild( supergraph ) ;
1291
1292     dataflow = GraphQDom.createElement( "dataflow" ) ;
1293     supergraph.appendChild( dataflow ) ;
1294   }
1295   else {
1296 //    QString Dataflow("Dataflow") ;
1297 //    GraphQDom = QDomDocument(Dataflow) ;
1298
1299     dataflow = GraphQDom.createElement( "dataflow" ) ;
1300     supergraph.appendChild( dataflow ) ;
1301   }
1302
1303   QDomElement info = GraphQDom.createElement( "info-list" ) ;
1304   dataflow.appendChild( info ) ;
1305
1306   Graph()->SaveXML( GraphQDom , info , 0 , 0 ) ;
1307
1308   QDomElement nodelist = GraphQDom.createElement( "node-list" ) ;
1309   dataflow.appendChild( nodelist ) ;
1310   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1311 //      f << "          <node>" << endl ;
1312       if ( Graph()->GraphNodes( i )->IsComputingNode() ) {
1313 //        ((GraphBase::ComputingNode *)GraphNodes( i ))->SaveXML( f ,
1314 //                    "                 " ,
1315         ((GraphBase::ComputingNode *) Graph()->GraphNodes( i ))->SaveXML( GraphQDom , nodelist ,
1316                     Graph()->GraphNodes( i )->XCoordinate() ,
1317                     Graph()->GraphNodes( i )->YCoordinate() ) ;
1318       }
1319       else if ( Graph()->GraphNodes( i )->IsFactoryNode() ) {
1320 //        ((GraphBase::FactoryNode * ) GraphNodes( i ))->SaveXML( f ,
1321 //                    "                 " ,
1322         ((GraphBase::FactoryNode * ) Graph()->GraphNodes( i ))->SaveXML( GraphQDom , nodelist ,
1323                     Graph()->GraphNodes( i )->XCoordinate() ,
1324                     Graph()->GraphNodes( i )->YCoordinate() ) ;
1325       }
1326       else if ( Graph()->GraphNodes( i )->IsInLineNode()  ) {
1327 //        ((GraphBase::InLineNode * ) GraphNodes( i ))->SaveXML( f ,
1328 //                    "                 " ,
1329         ((GraphBase::InLineNode * ) Graph()->GraphNodes( i ))->SaveXML( GraphQDom , nodelist ,
1330                     Graph()->GraphNodes( i )->XCoordinate() ,
1331                     Graph()->GraphNodes( i )->YCoordinate() ) ;
1332       }
1333       else if ( Graph()->GraphNodes( i )->IsMacroNode() ) {
1334 //        ((GraphBase::InLineNode * ) GraphNodes( i ))->SaveXML( f ,
1335 //                    "                 " ,
1336         ((GraphBase::GOTONode * ) Graph()->GraphNodes( i ))->SaveXML( GraphQDom , nodelist ,
1337                     Graph()->GraphNodes( i )->XCoordinate() ,
1338                     Graph()->GraphNodes( i )->YCoordinate() ) ;
1339       }
1340       else if ( Graph()->GraphNodes( i )->IsGOTONode() ) {
1341 //        ((GraphBase::GOTONode * ) GraphNodes( i ))->SaveXML( f ,
1342 //                    "                 " ,
1343         ((GraphBase::GOTONode * ) Graph()->GraphNodes( i ))->SaveXML( GraphQDom , nodelist ,
1344                     Graph()->GraphNodes( i )->XCoordinate() ,
1345                     Graph()->GraphNodes( i )->YCoordinate() ) ;
1346       }
1347       else if ( Graph()->GraphNodes( i )->IsLoopNode() ) {
1348 //        ((GraphBase::LoopNode * ) GraphNodes( i ))->SaveXML( f ,
1349 //                    "                 " ,
1350         ((GraphBase::LoopNode * ) Graph()->GraphNodes( i ))->SaveXML( GraphQDom , nodelist ,
1351                     Graph()->GraphNodes( i )->XCoordinate() ,
1352                     Graph()->GraphNodes( i )->YCoordinate() ) ;
1353       }
1354       else if ( Graph()->GraphNodes( i )->IsEndLoopNode() ) {
1355 //        ((GraphBase::EndOfLoopNode * ) GraphNodes( i ))->SaveXML( f ,
1356 //                    "                 " ,
1357         ((GraphBase::EndOfLoopNode * ) Graph()->GraphNodes( i ))->SaveXML( GraphQDom , nodelist ,
1358                     Graph()->GraphNodes( i )->XCoordinate() ,
1359                     Graph()->GraphNodes( i )->YCoordinate() ) ;
1360       }
1361       else if ( Graph()->GraphNodes( i )->IsSwitchNode() ) {
1362 //        ((GraphBase::SwitchNode * ) GraphNodes( i ))->SaveXML( f ,
1363 //                    "                 " ,
1364         ((GraphBase::SwitchNode * ) Graph()->GraphNodes( i ))->SaveXML( GraphQDom , nodelist ,
1365                     Graph()->GraphNodes( i )->XCoordinate() ,
1366                     Graph()->GraphNodes( i )->YCoordinate() ) ;
1367       }
1368       else if ( Graph()->GraphNodes( i )->IsEndSwitchNode() ) {
1369 //        ((GraphBase::EndOfSwitchNode * ) GraphNodes( i ))->SaveXML( f ,
1370 //                    "                 " ,
1371         ((GraphBase::EndOfSwitchNode * ) Graph()->GraphNodes( i ))->SaveXML( GraphQDom , nodelist ,
1372                     Graph()->GraphNodes( i )->XCoordinate() ,
1373                     Graph()->GraphNodes( i )->YCoordinate() ) ;
1374       }
1375 //      f << "          </node>" << endl ;
1376 //    }
1377   }
1378 //  f << "      </node-list>" << endl << endl ;
1379
1380 //  f << "      <link-list>" << endl ;
1381   QDomElement linklist = GraphQDom.createElement( "link-list" ) ;
1382   dataflow.appendChild( linklist ) ;
1383   const GraphBase::ListOfSLinks * Links = Graph()->GetLinks( true ) ;
1384   for ( i = 0 ; i < (int ) Links->size() ; i++ ) {
1385 //    f << "            <link>" << endl ;
1386     QDomElement link = GraphQDom.createElement( "link" ) ;
1387     linklist.appendChild( link ) ;
1388 //    LinkSaveXML( f , "                        " , (*Links)[ i ] , false ) ;
1389     LinkSaveXML( GraphQDom , link , (*Links)[ i ] , false ) ;
1390 //    f << "            </link>" << endl ;
1391   }
1392 //  f << "      </link-list>" << endl << endl ;
1393
1394 //  f << "      <data-list>" << endl ;
1395   QDomElement datalist = GraphQDom.createElement( "data-list" ) ;
1396   dataflow.appendChild( datalist ) ;
1397   if ( Graph()->GraphMacroLevel() == 0 ) {
1398     const GraphBase::ListOfSLinks * Datas = Graph()->GetDatas() ;
1399     for ( i = 0 ; i < (int ) Datas->size() ; i++ ) {
1400 //    f << "            <data>" << endl ;
1401       QDomElement data = GraphQDom.createElement( "data" ) ;
1402       datalist.appendChild( data ) ;
1403 //    LinkSaveXML( f , "                        " , (*Datas)[ i ] , true ) ;
1404       LinkSaveXML( GraphQDom , data , (*Datas)[ i ] , true ) ;
1405 //    f << "            </data>" << endl ;
1406     }
1407   }
1408
1409   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1410     if ( Graph()->GraphNodes( i )->IsMacroNode() ) {
1411       GraphBase::GOTONode * aMacroNode = (GraphBase::GOTONode * ) Graph()->GraphNodes( i ) ;
1412       GraphBase::Graph * aMacroGraph = (GraphBase::Graph * ) aMacroNode->CoupledNode() ;
1413       cdebug << "OutNode::SaveXML ---> OutNode::SaveXML( ostream & f , QDomDocument & , false "
1414              << " , QDomElement & ) MacroGraph " << aMacroGraph->Name() << endl ;
1415       if ( !aMacroGraph->GraphEditor()->SaveXML( f , GraphQDom , false , supergraph ) ) {
1416         return false ;
1417       cdebug << "OutNode::SaveXML MacroGraph "<< aMacroGraph->Name() << " done" << endl ;
1418       }
1419     }
1420   }
1421
1422   cdebug_out << "OutNode::SaveXML( ostream & f , QDomDocument & , " << aSuperGraph << " , QDomElement & ) "
1423              << Graph()->Name() << endl ;
1424
1425   return true ;
1426 }
1427
1428 bool GraphEditor::OutNode::SavePY( ostream & f , bool importSuperV ) {
1429   int i ;
1430   int j ;
1431   if ( importSuperV ) {
1432     f << endl << "# Generated python file of Graph " << Graph()->Name() << endl << endl ;
1433
1434     f << "from SuperV import *" << endl << endl ;
1435   }
1436
1437   f << "# Graph creation of " << Graph()->Name() << endl ;
1438   f << "def Def" << Graph()->Name() << "() :" << endl ;
1439   Graph()->SavePY( f , Graph()->Name() , 0 , 0 ) ;
1440
1441   f << "    " << endl << "    " << "# Creation of Factory Nodes" << endl ;
1442   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1443     if ( Graph()->GraphNodes( i )->IsFactoryNode() ) {
1444       f << "    " << endl ;
1445       ((GraphBase::FactoryNode * ) Graph()->GraphNodes( i ))->SavePY( f , Graph()->Name() ,
1446                                                                       Graph()->GraphNodes( i )->XCoordinate() ,
1447                                                                       Graph()->GraphNodes( i )->YCoordinate() ) ;
1448     }
1449   }
1450
1451   bool first = true ;
1452   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1453     if ( Graph()->GraphNodes( i )->IsComputingNode() ) {
1454       if ( first ) {
1455         f << "    " << endl << "    " << "# Creation of Computing Nodes" << endl ;
1456         first = false ;
1457       }
1458       else {
1459         f << "    " << endl ;
1460       }
1461       ((GraphBase::ComputingNode * ) Graph()->GraphNodes( i ))->SavePY( f , Graph()->Name() ,
1462                                                                         Graph()->GraphNodes( i )->XCoordinate() ,
1463                                                                         Graph()->GraphNodes( i )->YCoordinate() ) ;
1464     }
1465   }
1466
1467   first = true ;
1468   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1469     if ( Graph()->GraphNodes( i )->IsInLineNode() ) {
1470       if ( first ) {
1471         f << "    " << endl << "    " << "# Creation of InLine Nodes" << endl ;
1472         first = false ;
1473       }
1474       else {
1475         f << "    " << endl ;
1476       }
1477       ((GraphBase::InLineNode * ) Graph()->GraphNodes( i ))->SavePY( f , Graph()->Name() ,
1478                                                                      Graph()->GraphNodes( i )->XCoordinate() ,
1479                                                                      Graph()->GraphNodes( i )->YCoordinate() ) ;
1480     }
1481   }
1482
1483   first = true ;
1484   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1485     if ( Graph()->GraphNodes( i )->IsLoopNode() ) {
1486       if ( first ) {
1487         f << "    " << endl << "    " << "# Creation of Loop Nodes" << endl ;
1488         first = false ;
1489       }
1490       else {
1491         f << "    " << endl ;
1492       }
1493       ((GraphBase::LoopNode * ) Graph()->GraphNodes( i ))->SavePY( f , Graph()->Name() ,
1494                                                                    Graph()->GraphNodes( i )->XCoordinate() ,
1495                                                                    Graph()->GraphNodes( i )->YCoordinate() ) ;
1496     }
1497   }
1498
1499   first = true ;
1500   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1501     if ( Graph()->GraphNodes( i )->IsSwitchNode() ) {
1502       if ( first ) {
1503         f << "    " << endl << "    " << "# Creation of Switch Nodes" << endl ;
1504         first = false ;
1505       }
1506       else {
1507         f << "    " << endl ;
1508       }
1509       ((GraphBase::SwitchNode * ) Graph()->GraphNodes( i ))->SavePY( f , Graph()->Name() ,
1510                                                                      Graph()->GraphNodes( i )->XCoordinate() ,
1511                                                                      Graph()->GraphNodes( i )->YCoordinate() ) ;
1512     }
1513   }
1514
1515   first = true ;
1516   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1517     if ( Graph()->GraphNodes( i )->IsGOTONode() ) {
1518       if ( first ) {
1519         f << "    " << endl << "    " << "# Creation of GOTO Nodes" << endl ;
1520         first = false ;
1521       }
1522       else {
1523         f << "    " << endl ;
1524       }
1525       ((GraphBase::GOTONode * ) Graph()->GraphNodes( i ))->SavePY( f , Graph()->Name() ,
1526                                                                    Graph()->GraphNodes( i )->XCoordinate() ,
1527                                                                    Graph()->GraphNodes( i )->YCoordinate() ) ;
1528     }
1529   }
1530
1531   first = true ;
1532   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1533     if ( Graph()->GraphNodes( i )->IsMacroNode() ) {
1534       if ( first ) {
1535         f << "    " << endl << "    " << "# Creation of Macro Nodes" << endl ;
1536         first = false ;
1537       }
1538       else {
1539         f << "    " << endl ;
1540       }
1541       ((GraphBase::GOTONode * ) Graph()->GraphNodes( i ))->SavePY( f , Graph()->Name() ,
1542                                                                    Graph()->GraphNodes( i )->XCoordinate() ,
1543                                                                    Graph()->GraphNodes( i )->YCoordinate() ) ;
1544     }
1545   }
1546
1547   const GraphBase::ListOfSLinks * Links = Graph()->GetLinks() ;
1548 //  bool intervar ;
1549 //  map< string , int > aMapOfOutPorts ;
1550   first = true ;
1551   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1552     for ( j = 0 ; j < (int ) Links->size() ; j++ ) {
1553       if ( !strcmp( Graph()->GraphNodes( i )->Name() , (*Links)[ j ].FromNodeName.c_str() ) ) {
1554         if ( first ) {
1555           f << "    " << endl
1556             << "    " << "# Creation of Links"
1557             << endl ;
1558           first = false ;
1559         }
1560         else {
1561           f << "    " << endl ;
1562         }
1563 //        char * NodePort = new char [ strlen( (*Links)[ j ].FromNodeName.c_str() ) +
1564 //                                     strlen( (*Links)[ j ].FromServiceParameterName.c_str() ) + 1 ] ;
1565 //        strcpy( NodePort , (*Links)[ j ].FromNodeName.c_str() ) ;
1566 //        strcat( NodePort , (*Links)[ j ].FromServiceParameterName.c_str() ) ;
1567 //        if ( aMapOfOutPorts[ NodePort ] == 0 ) {
1568 //          aMapOfOutPorts[ NodePort ] = j + 1 ;
1569 //          intervar = true ;
1570 //        }
1571 //        else {
1572 //          intervar = false ;
1573 //        }
1574         bool fromparam = false ;
1575         if ( Graph()->GraphNodes( i )->GetOutPort( (*Links)[ j ].FromServiceParameterName.c_str() )->IsParam() ) {
1576           fromparam = true ;
1577         }
1578         bool toparam = false ;
1579         if ( Graph()->GetChangeGraphNode( (*Links)[ j ].ToNodeName.c_str() )->GetInPort( (*Links)[ j ].ToServiceParameterName.c_str() )->IsParam() ) {
1580           toparam = true ;
1581         }
1582         LinkSavePY( f , Graph()->Name() , (*Links)[ j ] , fromparam , toparam , false ) ;
1583 //        delete [] NodePort ;
1584       }
1585     }
1586   }
1587
1588   if ( Graph()->GraphMacroLevel() == 0 ) {
1589     const GraphBase::ListOfSLinks * Datas = Graph()->GetDatas() ;
1590     first = true ;
1591     for ( i = 0 ; i < (int ) Datas->size() ; i++ ) {
1592       if ( first ) {
1593         f << "    " << endl << "    " << "# Input datas" << endl ;
1594         first = false ;
1595       }
1596       bool fromparam = true ;
1597       bool toparam = true ;
1598       LinkSavePY( f , Graph()->Name() , (*Datas)[ i ] , fromparam , toparam , true ) ;
1599     }
1600   }
1601
1602   first = true ;
1603   const SALOME_ModuleCatalog::ListOfServicesParameter ListOfInParam = Graph()->ServiceInParameter() ;
1604   for ( i = 0 ; i < (int ) ListOfInParam.length() ; i++ ) {
1605     string _aParam = CORBA::string_dup(ListOfInParam[ i ].Parametername) ;
1606     const char * aParam = _aParam.c_str() ;
1607     char * aNodeName ;
1608     char * aPortName ;
1609     int j ;
1610     for ( j = 0 ; j < (int ) strlen( aParam ) ; j++ ) {
1611 //      if ( aParam[ j ] == '\\' ) {
1612       if ( aParam[ j ] == '_' && aParam[ j+1 ] == '_' ) {
1613         aNodeName = new char[ j+1 ] ;
1614         strncpy( aNodeName , aParam , j ) ;
1615         aNodeName[ j ] = '\0' ;
1616         aPortName = new char[ strlen( aParam ) - j-1 ] ;
1617         strncpy( aPortName , &aParam[ j+2 ] , strlen( aParam ) - j-1 ) ;
1618         break ;
1619       }
1620     }
1621     const GraphBase::InPort * anInPort = Graph()->GetChangeGraphNode( aNodeName )->GetInPort( aPortName ) ;
1622     if ( !anInPort->IsDataConnected() ) {
1623       if ( first ) {
1624         f << "    " << endl << "    " << "# Input Ports of the graph" << endl ;
1625         first = false ;
1626       }
1627       f << "    " << "#I" << aNodeName << aPortName << " = " << aNodeName << ".GetInPort( '"
1628         << aPortName << "' )" << endl ;
1629     }
1630     delete [] aNodeName ;
1631     delete [] aPortName ;
1632   }
1633
1634   f << "    " << endl << "    # Output Ports of the graph" << endl ;
1635   const SALOME_ModuleCatalog::ListOfServicesParameter ListOfOutParam = Graph()->ServiceOutParameter() ;
1636   for ( i = 0 ; i < (int ) ListOfOutParam.length() ; i++ ) {
1637     string _aParam = CORBA::string_dup(ListOfOutParam[ i ].Parametername) ;
1638     const char * aParam = _aParam.c_str() ;
1639     char * aNodeName ;
1640     char * aPortName ;
1641     int j ;
1642     for ( j = 0 ; j < (int ) strlen( aParam ) ; j++ ) {
1643 //      if ( aParam[ j ] == '\\' ) {
1644       if ( aParam[ j ] == '_' && aParam[ j+1 ] == '_' ) {
1645         aNodeName = new char[ j+1 ] ;
1646         strncpy( aNodeName , aParam , j ) ;
1647         aNodeName[ j ] = '\0' ;
1648         aPortName = new char[ strlen( aParam ) - j-1 ] ;
1649         strncpy( aPortName , &aParam[ j+2 ] , strlen( aParam ) - j-1 ) ;
1650         break ;
1651       }
1652     }
1653     f << "    " << "#O" << aNodeName << aPortName << " = " << aNodeName << ".GetOutPort( '"
1654       << aPortName << "' )" << endl ;
1655     delete [] aNodeName ;
1656     delete [] aPortName ;
1657   }
1658
1659   f << "    " << "return " << Graph()->Name() << endl << endl ;
1660
1661 // RECURSIVE CREATION OF GRAPHS OF MACRONODES
1662   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1663     if ( Graph()->GraphNodes( i )->IsMacroNode() ) {
1664       GraphBase::GOTONode * aMacroNode = (GraphBase::GOTONode * ) Graph()->GraphNodes( i ) ;
1665       GraphBase::Graph * aMacroGraph = (GraphBase::Graph * ) aMacroNode->CoupledNode() ;
1666       cdebug << "OutNode::SavePY ---> OutNode::SavePY( ostream & f ) MacroGraph " << aMacroGraph->Name() << endl ;
1667       GraphEditor::DataFlow * aDataFlow = aMacroGraph->GraphEditor() ;
1668       cdebug << "SavePY of the Graph " << aDataFlow->Graph() << " of the MacroNode "
1669              << aMacroGraph->Name() << endl ;
1670       if ( !aDataFlow->SavePY( f , false ) ) {
1671         return false ;
1672       }
1673     }
1674   }
1675
1676 //  f << Graph()->Name() << " = " << Graph()->Name() << "()" << endl ;
1677
1678   return true ;
1679 }
1680
1681 /** Iterate through ALL links (OutPort-InPort pairs) and check if their types are 
1682  *  compatible - call GraphEditor::DataFlow::IsCompatible(type1, type2).
1683  *  Returns true if all are compatible.
1684  */
1685 bool GraphEditor::OutNode::IsLinksCompatible() {
1686   const GraphBase::ListOfSLinks * Links = Graph()->GetLinks( true ) ;
1687   bool b = true;
1688   for ( int i = 0 ; i < (int ) Links->size() && b ; i++ ) {
1689     GraphBase::SLink aLink = (*Links)[i];
1690     GraphBase::ComputingNode* anOutNode = Graph()->GetChangeGraphNode( aLink.FromNodeName.c_str() );
1691     GraphBase::ComputingNode* anInNode = Graph()->GetChangeGraphNode( aLink.ToNodeName.c_str() );
1692     const GraphBase::OutPort* anOutPort = anOutNode->GetOutPort( aLink.FromServiceParameterName.c_str() );
1693     const GraphBase::InPort* anInPort = anInNode->GetInPort( aLink.ToServiceParameterName.c_str() );    
1694     b = IsCompatible( anOutPort->PortType(), anInPort->PortType() );
1695     cdebug << "GraphEditor::OutNode::IsLinksCompatible:  "<<aLink.FromNodeName << "("<<aLink.FromServiceParameterName
1696       <<")  -->  "<<aLink.ToNodeName<<"("<<aLink.ToServiceParameterName<<") = " << (b ? "OK" : "Not compatible (ERROR)") << endl;
1697     if ( !b )
1698       MESSAGE( "Graph structure ERROR: type of port \""<<aLink.FromServiceParameterName<<"\" of node \""
1699               <<aLink.FromNodeName<<"\" is not compatible with type of linked port \""
1700               <<aLink.ToServiceParameterName<<"\" of node \""<<aLink.ToNodeName<<"\"" );
1701   }
1702   return b;
1703 }
1704
1705 /**Returns true if an out-port of type "OutPortType" can be bound with in-port of type "InPortType". 
1706  * Types: {"string", "boolean", "char", "short", "int", "long", "float", "double", "objref"};
1707  * Currently considered compatible ALL types except for objref - they must match exactly
1708  */
1709 bool GraphEditor::OutNode::IsCompatible( const char* OutPortType, const char* InPortType ) const {
1710   bool ret = true;
1711   string t1 = OutPortType;
1712   string t2 = InPortType;
1713   // if ANY is an objref - the other one must be objref as well
1714   if ( ( t1 == "objref" || t2 == "objref" ) && t1 != t2 ) 
1715     ret = false; 
1716   return ret;
1717 }
1718
1719 ostream & operator<< (ostream & f,const GraphEditor::OutNode & G) {
1720   f << (GraphBase::ComputingNode ) *(G.Graph()) ;
1721   f << endl ;
1722
1723   f << "  Nodes : " << (G.Graph())->GraphNodesSize() << " node" 
1724     << ((G.Graph())->GraphNodesSize() > 1 ? "s" : "") << endl;
1725   
1726   int i ;
1727   for ( i = 0 ; i < (G.Graph())->GraphNodesSize() ; i++ ) {
1728     f
1729 //      << hex << (void *) G.Graph().GraphNodes( i ) << dec << " "
1730       << (G.Graph())->GraphNodes( i ) << endl;
1731   }
1732
1733   f << "  Links : " << endl ;
1734   for ( i = 0 ; i < (G.Graph())->GraphNodesSize() ; i++ ) {
1735     (G.Graph())->GraphNodes( i )->ListLinks( f ) ;
1736   }
1737
1738   f << "  Datas : " << endl ;
1739   (G.Graph())->ListDatas( f ) ;
1740
1741   f << "DataFlow " << (G.Graph())->Name() << " is " ;
1742   if ( G.IsNotValid() )
1743     f << "not " ;
1744   f << "valid and is " ;
1745   if ( G.IsNotExecutable() )
1746     f << "not " ;
1747   f << "executable." << endl ;
1748
1749   f << endl ;
1750   
1751   return f;
1752 }
1753
1754 ostream & operator<< (ostream &fOut,const SUPERV::SDate &D)
1755 {
1756 //  cdebug_in << "operator<< GraphEditor::Date" << endl;
1757
1758   fOut  << D.Day << "/" 
1759         << D.Month << "/" 
1760         << D.Year << " - " 
1761         << D.Hour << ":" 
1762         << D.Minute <<  ":"  
1763         << D.Second;
1764
1765 //  cdebug_out << "operator<< GraphEditor::Date" << endl;
1766   return fOut;
1767 }
1768
1769 /*
1770 GraphBase::Graph * GraphEditor::OutNode::MapGraph( const char * aGraphName ) {
1771   GraphBase::Graph * aGraph = _MapOfGraphs[ aGraphName ] ;
1772   return aGraph ;
1773 }
1774
1775 bool GraphEditor::OutNode::MapGraph( GraphBase::Graph * aGraph , const char * aGraphName ) {
1776   if ( MapGraph( aGraphName ) ) {
1777     return false ;
1778   }
1779   _MapOfGraphs[ aGraphName ] = aGraph ;
1780   return true ;
1781 }
1782
1783 void GraphEditor::OutNode::EraseGraph( const char * aGraphName ) {
1784   _MapOfGraphs.erase( aGraphName ) ;
1785 }
1786
1787 bool GraphEditor::OutNode::GraphName( const char * aGraphName ) {
1788   return  _MapOfGraphNames[ aGraphName ] ;
1789 }
1790 */
1791
1792