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