Salome HOME
*** empty log message ***
[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         ostringstream astr ;
693         astr << num << ends ;
694         const char * n_instance = astr.str().c_str() ;
695         int lname = strlen( NodeService.ServiceName ) + 1 +
696                     strlen( n_instance ) + 1 ;
697         aNodeName = new char[lname] ;
698         strcpy( aNodeName , NodeService.ServiceName ) ;
699         strcat( aNodeName , "_" ) ;
700         strcat( aNodeName , n_instance ) ;
701       }
702     }
703   }
704   else {
705     if ( Graph()->GetGraphNode( theNodeName ) == NULL ) {
706       aNodeName = new char[ strlen( theNodeName )+1 ] ;
707       strcpy( aNodeName , theNodeName ) ;
708     }
709     else {
710       aNodeName = NULLSTRING ;
711     }
712   }
713   if ( aNodeName != NULLSTRING ) {
714     Nd = new GraphEditor::InNode( _Orb , Graph()->NamingService() ,
715                                   aFuncName , aPythonFunction , NodeService ,
716                                   NodeComponentName , NodeInterfaceName ,
717                                   aNodeName , NodeKindOfNode ,
718                                   NodeFirstCreation , NodeLastModification ,
719                                   NodeEditorRelease , NodeAuthor ,
720                                   NodeComputer , NodeComment , GeneratedName ,
721                                   NodeX , NodeY ,
722                                   _prof_debug , _fdebug ) ;
723     
724     // asv: 28.09.04 fix for 6621
725     //if ( Nd->IsMacroNode() )
726     //  MapGraph( Nd->GraphMacroNode(), aNodeName );
727
728     if ( Graph()->IsDataStreamNode() && ( Nd->IsComputingNode() || Nd->IsFactoryNode() ) ) {
729       unsigned int i ;
730       for ( i = 0 ; i < NodeService.ServiceinDataStreamParameter.length() ; i++ ) {
731         GraphBase::InDataStreamPort * aDataStreamPort ;
732         aDataStreamPort = Nd->ComputingNode()->AddInDataStreamPort(
733 //JR 17.02.2005 Memory Leak                                         my_strdup( NodeService.ServiceinDataStreamParameter[i].Parametername ) ,
734                                          NodeService.ServiceinDataStreamParameter[i].Parametername ,
735                                          NodeService.ServiceinDataStreamParameter[i].Parametertype ,
736                                          NodeService.ServiceinDataStreamParameter[i].Parameterdependency ,
737                                          SUPERV::DataStreamParameter ) ;
738       }
739       for ( i = 0 ; i < NodeService.ServiceoutDataStreamParameter.length() ; i++ ) {
740         GraphBase::OutDataStreamPort * aDataStreamPort ;
741         aDataStreamPort = Nd->ComputingNode()->AddOutDataStreamPort(
742 //JR 17.02.2005 Memory Leak                                         my_strdup( NodeService.ServiceoutDataStreamParameter[i].Parametername ) ,
743                                          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 //JR Optional parameter kLoopSwitch (default = true) :
935 //In some cases we do not need to check the validity of loops and switchs
936 bool GraphEditor::OutNode::Valid(bool kLoopSwitch ) {
937   if ( _Valid )
938     return true ;
939
940   cdebug_in << "GraphEditor::OutNode::Valid" << endl;
941   _Executable = false ;
942
943   if ( !Graph()->CreateService() ) {
944     cdebug_out << "GraphEditor::OutNode::Valid " << _Valid << endl;
945     return false ;
946   }
947   
948   if ( Graph()->GraphMacroLevel() != 0 ) {
949     cdebug << "CoupledNode " << Graph()->CoupledNode() << endl ;
950     cdebug << "GraphEditor " << Graph()->CoupledNode()->GraphEditor() << endl ;
951     cdebug << "Graph " << Graph()->CoupledNode()->GraphEditor()->Graph() << endl ;
952     cdebug << "Name " << Graph()->CoupledNode()->GraphEditor()->Graph()->Name() << endl ;
953     cdebug << "Valid --> UpdateMacroPorts of " << Graph()->CoupledNodeName() << " of "
954            << Graph()->CoupledNode()->GraphEditor()->Graph()->Name() << endl ;
955     cdebug << Graph()->CoupledNode() << endl ;
956     Graph()->CoupledNode()->UpdateMacroPorts( Graph() ) ;
957     cdebug << Graph()->CoupledNode()->Name() << " Valid --> UnValid of graph "
958            << Graph()->CoupledNode()->GraphEditor()->Graph()->Name()
959            << " GraphMacroLevel " << Graph()->CoupledNode()->GraphEditor()->Graph()->GraphMacroLevel()  << endl ;
960     Graph()->CoupledNode()->GraphEditor()->UnValid() ;
961   }
962
963   int SubStreamGraphsNumber = 0 ;
964   if ( !Graph()->Sort( SubStreamGraphsNumber ) ) {
965     cdebug_out << "This DataFlow is not valid." << endl ;
966     return false ;
967   }
968   if ( Graph()->IsDataStreamNode() ) {
969     StreamGraph()->SubStreamGraphsNumber( SubStreamGraphsNumber ) ;
970   }
971
972   Graph()->InLineServices() ;
973
974   if ( kLoopSwitch ) {
975     if ( !Graph()->ValidLoops() ) {
976       cdebug_out << "This DataFlow have not valid Loops." << endl ;
977       return false ;
978     }
979     if ( !Graph()->ValidSwitchs() ) {
980       cdebug_out << "This DataFlow have not valid Switchs." << endl ;
981       return false ;
982     }
983   }
984   
985 //  CreateService() ;
986
987   Graph()->ComputingNodes() ;
988
989   if ( kLoopSwitch ) {
990     _Valid = true ;
991   }
992
993   cdebug_out << "GraphEditor::OutNode::Valid " << _Valid << endl;
994   return true ;
995 }
996
997 bool GraphEditor::OutNode::Executable() {
998   cdebug_in << "GraphEditor::OutNode::Executable" << endl;
999   bool NewLink ;
1000 // LinkLoopNodes manage input values of LoopNodes and EndLoopNodes
1001   if ( Graph()->LinkLoopNodes( NewLink ) ) {
1002     if ( NewLink ) {
1003       _Valid = false ;
1004     }
1005   }
1006   else {
1007     cdebug << "This DataFlow is not executable." << endl ;
1008     _Executable = false ;
1009   }
1010   if ( !IsValid() ) {
1011     Valid() ;
1012   }
1013   if ( !IsValid() ) {
1014     return false ;
1015   }
1016   if ( Graph()->DataServerNodes() )
1017     _Executable = true ;
1018   else {
1019     cdebug << "This DataFlow is not executable." << endl ;
1020     _Executable = false ;
1021   }
1022
1023   if ( _Executable && Graph()->IsDataStreamNode() ) {
1024     StreamGraph()->CreateStreamTopology( "/tmp/" ) ;
1025   }
1026
1027   // asv : 13.12.04 : introducing check for compatibility of linked ports' types.
1028   if ( !IsLinksCompatible() ) {
1029     _Executable = false;
1030   }    
1031
1032   cdebug_out << "GraphEditor::OutNode::Executable" << endl;
1033   return _Executable ;
1034 }
1035
1036 const CORBA::Any *GraphEditor::OutNode::GetInData(
1037                               const char * ToNodeName ,
1038                               const char * ToParameterName ) {
1039 //  cdebug_in << "GraphEditor::OutNode::GetInData " << ToNodeName
1040 //            << " " << ToParameterName << endl ;
1041   const CORBA::Any * retdata = Graph()->PortInData( ToNodeName , ToParameterName ) ;
1042 //  cdebug_out << "GraphEditor::OutNode::GetInData" << endl ;
1043   return retdata ;
1044 }
1045
1046 const CORBA::Any *GraphEditor::OutNode::GetOutData(
1047                               const char * FromNodeName ,
1048                               const char * FromParameterName ) {
1049 //  cdebug_in << "GraphEditor::OutNode::GetOutData " << FromNodeName
1050 //            << " " << FromParameterName << endl ;
1051   const CORBA::Any * retdata = Graph()->PortOutData( FromNodeName , FromParameterName ) ;
1052 //  cdebug_out << "GraphEditor::OutNode::GetOutData" << endl ;
1053   return retdata ;
1054 }
1055
1056 //bool GraphEditor::OutNode::LinkSaveXML( ostream &f , char *Tabs ,
1057 bool GraphEditor::OutNode::LinkSaveXML( QDomDocument & Graph , QDomElement & link ,
1058                                         GraphBase::SLink aLink ,
1059                                         bool wdata ) const {
1060   cdebug_in << "GraphEditor::OutNode::LinkSaveXML " << aLink.FromNodeName
1061             << "(" << aLink.FromServiceParameterName << ") --> "
1062             << aLink.ToNodeName << "(" << aLink.ToServiceParameterName << ")" << endl ;
1063   QDomElement fromnodename = Graph.createElement( "fromnode-name" ) ;
1064   QDomText aField ;
1065   if ( strlen( aLink.FromNodeName.c_str() ) ) {
1066 //    f << Tabs << "<fromnode-name>" << aLink.FromNodeName.c_str()
1067 //      << "</fromnode-name>" << endl ;
1068     aField = Graph.createTextNode( aLink.FromNodeName.c_str() ) ;
1069   }
1070   else {
1071 //    f << Tabs << "<fromnode-name>?</fromnode-name>" << endl ;
1072     aField = Graph.createTextNode( "?" ) ;
1073   }
1074   link.appendChild( fromnodename ) ;
1075   fromnodename.appendChild( aField ) ;
1076
1077 //  f << Tabs << "<fromserviceparameter-name>"
1078 //    << aLink.FromServiceParameterName.c_str() << "</fromserviceparameter-name>"
1079 //    << endl ;
1080   QDomElement fromserviceparametername = Graph.createElement( "fromserviceparameter-name" ) ;
1081   aField = Graph.createTextNode( aLink.FromServiceParameterName.c_str() ) ;
1082   link.appendChild( fromserviceparametername ) ;
1083   fromserviceparametername.appendChild( aField ) ;
1084
1085   QDomElement tonodename = Graph.createElement( "tonode-name" ) ;
1086   if ( strlen( aLink.ToNodeName.c_str() ) ) {
1087 //    f << Tabs << "<tonode-name>" << aLink.ToNodeName.c_str()
1088 //      << "</tonode-name>" << endl ;
1089     aField = Graph.createTextNode( aLink.ToNodeName.c_str() ) ;
1090   }
1091   else {
1092 //    f << Tabs << "<tonode-name>?</tonode-name>" << endl ;
1093     aField = Graph.createTextNode( "?" ) ;
1094   }
1095   link.appendChild( tonodename ) ;
1096   tonodename.appendChild( aField ) ;
1097
1098 //  f << Tabs << "<toserviceparameter-name>"
1099 //    << aLink.ToServiceParameterName.c_str() << "</toserviceparameter-name>"
1100 //    << endl ;
1101   QDomElement toserviceparametername = Graph.createElement( "toserviceparameter-name" ) ;
1102   aField = Graph.createTextNode( aLink.ToServiceParameterName.c_str() ) ;
1103   link.appendChild( toserviceparametername ) ;
1104   toserviceparametername.appendChild( aField ) ;
1105
1106   if ( wdata ) {
1107 //    f << Tabs << "<data-value>" << endl ;
1108     QDomElement datavalue = Graph.createElement( "data-value" ) ;
1109     link.appendChild( datavalue ) ;
1110 //    f << Tabs << "    <value-type>" << aLink.aLinkValue.type()->kind()
1111 //      << "</value-type>" << endl ;
1112     QDomElement valuetype = Graph.createElement( "value-type" ) ;
1113     QString aKind ;
1114     aKind = aKind.setNum( aLink.aLinkValue.type()->kind() ) ;
1115     aField = Graph.createTextNode( aKind ) ;
1116     datavalue.appendChild( valuetype ) ;
1117     valuetype.appendChild( aField ) ;
1118     switch (aLink.aLinkValue.type()->kind()) {
1119       case CORBA::tk_string: {
1120         char* retstr ;
1121         aLink.aLinkValue >>= retstr;
1122 //        f << Tabs << "        <value>" << retstr << "</value>" << endl ;
1123         QDomElement value = Graph.createElement( "value" ) ;
1124         aField = Graph.createTextNode( retstr ) ;
1125         datavalue.appendChild( value ) ;
1126         value.appendChild( aField ) ;
1127 //        MESSAGE( "ToString( string ) " << retstr );
1128         break ;
1129       }
1130       case CORBA::tk_double: {
1131         double d;
1132         aLink.aLinkValue >>= d;
1133 //        f << Tabs << "        <value>" << d << "</value>" << endl ;
1134         QDomElement value = Graph.createElement( "value" ) ;
1135         QString aKind ;
1136         aKind = aKind.setNum( d ) ;
1137         aField = Graph.createTextNode( aKind ) ;
1138         datavalue.appendChild( value ) ;
1139         value.appendChild( aField ) ;
1140 //        MESSAGE( "ToString( double ) " << d );
1141         break ;
1142       }
1143       case CORBA::tk_long: {
1144         long l;
1145         aLink.aLinkValue >>= l;
1146 //        f << Tabs << "        <value>" << l << "</value>" << endl ;
1147         QDomElement value = Graph.createElement( "value" ) ;
1148         QString aKind ;
1149         aKind = aKind.setNum( l ) ;
1150         aField = Graph.createTextNode( aKind ) ;
1151         datavalue.appendChild( value ) ;
1152         value.appendChild( aField ) ;
1153 //        MESSAGE( "ToString( long ) " << l );
1154         break ;
1155       }
1156       case CORBA::tk_objref: {
1157         char* retstr ;
1158         CORBA::Object_ptr obj ;
1159         aLink.aLinkValue >>= obj ;
1160         retstr = _Orb->object_to_string(obj );
1161 //        f << Tabs << "        <value>" << retstr << "</value>" << endl ;
1162         QDomElement value = Graph.createElement( "value" ) ;
1163         aField = Graph.createTextNode( retstr ) ;
1164         datavalue.appendChild( value ) ;
1165         value.appendChild( aField ) ;
1166 //        MESSAGE( "ToString( object ) " << retstr );
1167         break ;
1168       }
1169       default: {
1170 //        f << Tabs << "        <value>?</value>" << endl ;
1171         QDomElement value = Graph.createElement( "value" ) ;
1172         aField = Graph.createTextNode( "?" ) ;
1173         datavalue.appendChild( value ) ;
1174         value.appendChild( aField ) ;
1175 //        MESSAGE( "Unknown CORBA::Any Type" );
1176         break ;
1177       }
1178     }
1179 //    f << Tabs << "</data-value>" << endl ;
1180   }
1181 //  f << Tabs << "<coord-list>" << endl ;
1182   QDomElement coordlist = Graph.createElement( "coord-list" ) ;
1183   link.appendChild( coordlist ) ;
1184   
1185   int i ;
1186   for ( i = 0 ; i < (int ) aLink.aListOfCoords.size() ; i++ ) {
1187 //    f << Tabs << "    <coord>" << endl ;
1188     QDomElement coord = Graph.createElement( "coord" ) ;
1189     coordlist.appendChild( coord ) ;
1190 //    f << Tabs << "            <x>" << aLink.aListOfCoords[ i ].theX << "</x>" << endl ;
1191     QDomElement x = Graph.createElement( "x" ) ;
1192     QString ax ;
1193     ax = ax.setNum( aLink.aListOfCoords[ i ].theX ) ;
1194     aField = Graph.createTextNode( ax ) ;
1195     coord.appendChild( x ) ;
1196     x.appendChild( aField ) ;    
1197 //    f << Tabs << "            <y>" << aLink.aListOfCoords[ i ].theY << "</y>" << endl ;
1198     QDomElement y = Graph.createElement( "y" ) ;
1199     QString ay ;
1200     ay = ay.setNum( aLink.aListOfCoords[ i ].theY ) ;
1201     aField = Graph.createTextNode( ay ) ;
1202     coord.appendChild( y ) ;
1203     y.appendChild( aField ) ;    
1204 //    f << Tabs << "    </coord>" << endl ;
1205   }
1206 //  f << Tabs << "</coord-list>" << endl ;
1207   cdebug_out << "GraphEditor::OutNode::LinkSaveXML " << aLink.FromNodeName
1208              << "(" << aLink.FromServiceParameterName << ") --> "
1209              << aLink.ToNodeName << "(" << aLink.ToServiceParameterName << ")"
1210              << endl ;
1211   return true ;
1212 }
1213
1214 bool GraphEditor::OutNode::LinkSavePY( ostream &f , const char * aGraphName ,
1215                                        GraphBase::SLink aLink ,
1216                                        bool fromparam , bool toparam ,
1217                                        bool wdata ) const {
1218   if ( !wdata ) {
1219 //    if ( intervar ) {
1220 //      f << "O" << aLink.FromNodeName.c_str() << aLink.FromServiceParameterName.c_str()
1221 //        << " = "
1222 //        << aLink.FromNodeName.c_str() << ".GetOutPort( '"
1223 //        << aLink.FromServiceParameterName.c_str()
1224 //        << "' )" << endl ;
1225 //    }
1226     f << "    " << "L" << aLink.FromNodeName.c_str() << aLink.FromServiceParameterName.c_str()
1227       << aLink.ToNodeName.c_str() << aLink.ToServiceParameterName.c_str() ;
1228     if ( ((GraphBase::Graph *) Graph())->GetChangeGraphNode( aLink.FromNodeName.c_str() )->GetChangeOutPort( aLink.FromServiceParameterName.c_str() )->IsDataStream() ) {
1229       f << " = " << aGraphName << ".StreamLink( " ;
1230     }
1231     else {
1232       f << " = " << aGraphName << ".Link( " ;
1233     }
1234 //    if ( !fromparam ) {
1235       f << "O" ;
1236 //    }
1237     f << aLink.FromNodeName.c_str() << aLink.FromServiceParameterName.c_str() << " , " ;
1238 //    if ( !toparam ) {
1239       f << "I" ;
1240 //    }
1241     f << aLink.ToNodeName.c_str() << aLink.ToServiceParameterName.c_str() << " )" << endl ;
1242   }
1243   else {
1244     f << "    " << "I"<< aLink.ToNodeName.c_str() << aLink.ToServiceParameterName.c_str()
1245 //      << " = " << aLink.ToNodeName.c_str() << ".Input( '"
1246 //      << aLink.ToServiceParameterName.c_str() << "' , " ;
1247       << ".Input( " ;
1248     switch (aLink.aLinkValue.type()->kind()) {
1249       case CORBA::tk_string: {
1250         char* retstr ;
1251         aLink.aLinkValue >>= retstr;
1252         f << "'" << retstr << "'" ;
1253         break ;
1254       }
1255       case CORBA::tk_double: {
1256         double d;
1257         aLink.aLinkValue >>= d;
1258         f << d ;
1259         break ;
1260       }
1261       case CORBA::tk_long: {
1262         long l;
1263         aLink.aLinkValue >>= l;
1264         f << l ;
1265         break ;
1266       }
1267       case CORBA::tk_objref: {
1268         char* retstr ;
1269         CORBA::Object_ptr obj ;
1270         aLink.aLinkValue >>= obj ;
1271         retstr = _Orb->object_to_string(obj );
1272         f << "'" << retstr << "'" ;
1273         break ;
1274       }
1275       default: {
1276         f << "?" ;
1277 //        MESSAGE( "Unknown CORBA::Any Type" );
1278         break ;
1279       }
1280     }
1281     f << " )" << endl ;
1282   }
1283   int i ;
1284   for ( i = 0 ; i < (int ) aLink.aListOfCoords.size() ; i++ ) {
1285     f << "    " << "L" << aLink.FromNodeName.c_str() << aLink.FromServiceParameterName.c_str()
1286       << aLink.ToNodeName.c_str() << aLink.ToServiceParameterName.c_str() << ".AddCoord( " << i+1 << " , "
1287       << aLink.aListOfCoords[ i ].theX << " , "
1288       << aLink.aListOfCoords[ i ].theY << " )" << endl ;
1289   }
1290   return true ;
1291 }
1292
1293 //bool GraphEditor::OutNode::SaveXML(ostream & f ) {
1294 bool GraphEditor::OutNode::SaveXML( ostream & f , QDomDocument & GraphQDom ,
1295                                     bool aSuperGraph , QDomElement & supergraph ) {
1296   cdebug_in << "OutNode::SaveXML( ostream & f , QDomDocument & , " << aSuperGraph << " , QDomElement & ) "
1297             << Graph()->Name() << endl ;
1298   int i ;
1299
1300   QDomElement dataflow ;
1301   if ( aSuperGraph ) {
1302     QString SuperGraph("SuperGraph") ;
1303     GraphQDom = QDomDocument(SuperGraph) ;
1304
1305     supergraph = GraphQDom.createElement( "supergraph" ) ;
1306     GraphQDom.appendChild( supergraph ) ;
1307
1308     dataflow = GraphQDom.createElement( "dataflow" ) ;
1309     supergraph.appendChild( dataflow ) ;
1310   }
1311   else {
1312 //    QString Dataflow("Dataflow") ;
1313 //    GraphQDom = QDomDocument(Dataflow) ;
1314
1315     dataflow = GraphQDom.createElement( "dataflow" ) ;
1316     supergraph.appendChild( dataflow ) ;
1317   }
1318
1319   QDomElement info = GraphQDom.createElement( "info-list" ) ;
1320   dataflow.appendChild( info ) ;
1321
1322   Graph()->SaveXML( GraphQDom , info , 0 , 0 ) ;
1323
1324   QDomElement nodelist = GraphQDom.createElement( "node-list" ) ;
1325   dataflow.appendChild( nodelist ) ;
1326   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1327 //      f << "          <node>" << endl ;
1328       if ( Graph()->GraphNodes( i )->IsComputingNode() ) {
1329 //        ((GraphBase::ComputingNode *)GraphNodes( i ))->SaveXML( f ,
1330 //                    "                 " ,
1331         ((GraphBase::ComputingNode *) Graph()->GraphNodes( i ))->SaveXML( GraphQDom , nodelist ,
1332                     Graph()->GraphNodes( i )->XCoordinate() ,
1333                     Graph()->GraphNodes( i )->YCoordinate() ) ;
1334       }
1335       else if ( Graph()->GraphNodes( i )->IsFactoryNode() ) {
1336 //        ((GraphBase::FactoryNode * ) GraphNodes( i ))->SaveXML( f ,
1337 //                    "                 " ,
1338         ((GraphBase::FactoryNode * ) Graph()->GraphNodes( i ))->SaveXML( GraphQDom , nodelist ,
1339                     Graph()->GraphNodes( i )->XCoordinate() ,
1340                     Graph()->GraphNodes( i )->YCoordinate() ) ;
1341       }
1342       else if ( Graph()->GraphNodes( i )->IsInLineNode()  ) {
1343 //        ((GraphBase::InLineNode * ) GraphNodes( i ))->SaveXML( f ,
1344 //                    "                 " ,
1345         ((GraphBase::InLineNode * ) Graph()->GraphNodes( i ))->SaveXML( GraphQDom , nodelist ,
1346                     Graph()->GraphNodes( i )->XCoordinate() ,
1347                     Graph()->GraphNodes( i )->YCoordinate() ) ;
1348       }
1349       else if ( Graph()->GraphNodes( i )->IsMacroNode() ) {
1350 //        ((GraphBase::InLineNode * ) GraphNodes( i ))->SaveXML( f ,
1351 //                    "                 " ,
1352         ((GraphBase::GOTONode * ) Graph()->GraphNodes( i ))->SaveXML( GraphQDom , nodelist ,
1353                     Graph()->GraphNodes( i )->XCoordinate() ,
1354                     Graph()->GraphNodes( i )->YCoordinate() ) ;
1355       }
1356       else if ( Graph()->GraphNodes( i )->IsGOTONode() ) {
1357 //        ((GraphBase::GOTONode * ) GraphNodes( i ))->SaveXML( f ,
1358 //                    "                 " ,
1359         ((GraphBase::GOTONode * ) Graph()->GraphNodes( i ))->SaveXML( GraphQDom , nodelist ,
1360                     Graph()->GraphNodes( i )->XCoordinate() ,
1361                     Graph()->GraphNodes( i )->YCoordinate() ) ;
1362       }
1363       else if ( Graph()->GraphNodes( i )->IsLoopNode() ) {
1364 //        ((GraphBase::LoopNode * ) GraphNodes( i ))->SaveXML( f ,
1365 //                    "                 " ,
1366         ((GraphBase::LoopNode * ) Graph()->GraphNodes( i ))->SaveXML( GraphQDom , nodelist ,
1367                     Graph()->GraphNodes( i )->XCoordinate() ,
1368                     Graph()->GraphNodes( i )->YCoordinate() ) ;
1369       }
1370       else if ( Graph()->GraphNodes( i )->IsEndLoopNode() ) {
1371 //        ((GraphBase::EndOfLoopNode * ) GraphNodes( i ))->SaveXML( f ,
1372 //                    "                 " ,
1373         ((GraphBase::EndOfLoopNode * ) Graph()->GraphNodes( i ))->SaveXML( GraphQDom , nodelist ,
1374                     Graph()->GraphNodes( i )->XCoordinate() ,
1375                     Graph()->GraphNodes( i )->YCoordinate() ) ;
1376       }
1377       else if ( Graph()->GraphNodes( i )->IsSwitchNode() ) {
1378 //        ((GraphBase::SwitchNode * ) GraphNodes( i ))->SaveXML( f ,
1379 //                    "                 " ,
1380         ((GraphBase::SwitchNode * ) Graph()->GraphNodes( i ))->SaveXML( GraphQDom , nodelist ,
1381                     Graph()->GraphNodes( i )->XCoordinate() ,
1382                     Graph()->GraphNodes( i )->YCoordinate() ) ;
1383       }
1384       else if ( Graph()->GraphNodes( i )->IsEndSwitchNode() ) {
1385 //        ((GraphBase::EndOfSwitchNode * ) GraphNodes( i ))->SaveXML( f ,
1386 //                    "                 " ,
1387         ((GraphBase::EndOfSwitchNode * ) Graph()->GraphNodes( i ))->SaveXML( GraphQDom , nodelist ,
1388                     Graph()->GraphNodes( i )->XCoordinate() ,
1389                     Graph()->GraphNodes( i )->YCoordinate() ) ;
1390       }
1391 //      f << "          </node>" << endl ;
1392 //    }
1393   }
1394 //  f << "      </node-list>" << endl << endl ;
1395
1396 //  f << "      <link-list>" << endl ;
1397   QDomElement linklist = GraphQDom.createElement( "link-list" ) ;
1398   dataflow.appendChild( linklist ) ;
1399   const GraphBase::ListOfSLinks * Links = Graph()->GetLinks( true ) ;
1400   for ( i = 0 ; i < (int ) Links->size() ; i++ ) {
1401 //    f << "            <link>" << endl ;
1402     QDomElement link = GraphQDom.createElement( "link" ) ;
1403     linklist.appendChild( link ) ;
1404 //    LinkSaveXML( f , "                        " , (*Links)[ i ] , false ) ;
1405     LinkSaveXML( GraphQDom , link , (*Links)[ i ] , false ) ;
1406 //    f << "            </link>" << endl ;
1407   }
1408 //  f << "      </link-list>" << endl << endl ;
1409
1410 //  f << "      <data-list>" << endl ;
1411   QDomElement datalist = GraphQDom.createElement( "data-list" ) ;
1412   dataflow.appendChild( datalist ) ;
1413   if ( Graph()->GraphMacroLevel() == 0 ) {
1414     const GraphBase::ListOfSLinks * Datas = Graph()->GetDatas() ;
1415     for ( i = 0 ; i < (int ) Datas->size() ; i++ ) {
1416 //    f << "            <data>" << endl ;
1417       QDomElement data = GraphQDom.createElement( "data" ) ;
1418       datalist.appendChild( data ) ;
1419 //    LinkSaveXML( f , "                        " , (*Datas)[ i ] , true ) ;
1420       LinkSaveXML( GraphQDom , data , (*Datas)[ i ] , true ) ;
1421 //    f << "            </data>" << endl ;
1422     }
1423   }
1424
1425   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1426     if ( Graph()->GraphNodes( i )->IsMacroNode() ) {
1427       GraphBase::GOTONode * aMacroNode = (GraphBase::GOTONode * ) Graph()->GraphNodes( i ) ;
1428       GraphBase::Graph * aMacroGraph = (GraphBase::Graph * ) aMacroNode->CoupledNode() ;
1429       cdebug << "OutNode::SaveXML ---> OutNode::SaveXML( ostream & f , QDomDocument & , false "
1430              << " , QDomElement & ) MacroGraph " << aMacroGraph->Name() << endl ;
1431       if ( !aMacroGraph->GraphEditor()->SaveXML( f , GraphQDom , false , supergraph ) ) {
1432         return false ;
1433       cdebug << "OutNode::SaveXML MacroGraph "<< aMacroGraph->Name() << " done" << endl ;
1434       }
1435     }
1436   }
1437
1438   cdebug_out << "OutNode::SaveXML( ostream & f , QDomDocument & , " << aSuperGraph << " , QDomElement & ) "
1439              << Graph()->Name() << endl ;
1440
1441   return true ;
1442 }
1443
1444 bool GraphEditor::OutNode::SavePY( ostream & f , bool importSuperV ) {
1445   int i ;
1446   int j ;
1447   const GraphBase::ListOfSLinks * Links ;
1448   if ( importSuperV ) {
1449     f << endl << "# Generated python file of Graph " << Graph()->Name() << endl << endl ;
1450
1451     f << "from SuperV import *" << endl << endl ;
1452   }
1453
1454   f << "# Graph creation of " << Graph()->Name() << endl ;
1455   f << "def Def" << Graph()->Name() << "() :" << endl ;
1456   Graph()->SavePY( f , Graph()->Name() , 0 , 0 ) ;
1457
1458   f << "    " << endl << "    " << "# Creation of Factory Nodes" << endl ;
1459   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1460     if ( Graph()->GraphNodes( i )->IsFactoryNode() ) {
1461       f << "    " << endl ;
1462       ((GraphBase::FactoryNode * ) Graph()->GraphNodes( i ))->SavePY( f , Graph()->Name() ,
1463                                                                       Graph()->GraphNodes( i )->XCoordinate() ,
1464                                                                       Graph()->GraphNodes( i )->YCoordinate() ) ;
1465     }
1466   }
1467
1468   bool first = true ;
1469   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1470     if ( Graph()->GraphNodes( i )->IsComputingNode() ) {
1471       if ( first ) {
1472         f << "    " << endl << "    " << "# Creation of Computing Nodes" << endl ;
1473         first = false ;
1474       }
1475       else {
1476         f << "    " << endl ;
1477       }
1478       ((GraphBase::ComputingNode * ) Graph()->GraphNodes( i ))->SavePY( f , Graph()->Name() ,
1479                                                                         Graph()->GraphNodes( i )->XCoordinate() ,
1480                                                                         Graph()->GraphNodes( i )->YCoordinate() ) ;
1481     }
1482   }
1483
1484   first = true ;
1485   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1486     if ( Graph()->GraphNodes( i )->IsInLineNode() ) {
1487       if ( first ) {
1488         f << "    " << endl << "    " << "# Creation of InLine Nodes" << endl ;
1489         first = false ;
1490       }
1491       else {
1492         f << "    " << endl ;
1493       }
1494       ((GraphBase::InLineNode * ) Graph()->GraphNodes( i ))->SavePY( f , Graph()->Name() ,
1495                                                                      Graph()->GraphNodes( i )->XCoordinate() ,
1496                                                                      Graph()->GraphNodes( i )->YCoordinate() ) ;
1497     }
1498   }
1499
1500   first = true ;
1501   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1502     if ( Graph()->GraphNodes( i )->IsLoopNode() ) {
1503       if ( first ) {
1504         f << "    " << endl << "    " << "# Creation of Loop Nodes" << endl ;
1505         first = false ;
1506       }
1507       else {
1508         f << "    " << endl ;
1509       }
1510       ((GraphBase::LoopNode * ) Graph()->GraphNodes( i ))->SavePY( f , Graph()->Name() ,
1511                                                                    Graph()->GraphNodes( i )->XCoordinate() ,
1512                                                                    Graph()->GraphNodes( i )->YCoordinate() ) ;
1513     }
1514   }
1515
1516   first = true ;
1517   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1518     if ( Graph()->GraphNodes( i )->IsSwitchNode() ) {
1519       if ( first ) {
1520         f << "    " << endl << "    " << "# Creation of Switch Nodes" << endl ;
1521         first = false ;
1522       }
1523       else {
1524         f << "    " << endl ;
1525       }
1526       ((GraphBase::SwitchNode * ) Graph()->GraphNodes( i ))->SavePY( f , Graph()->Name() ,
1527                                                                      Graph()->GraphNodes( i )->XCoordinate() ,
1528                                                                      Graph()->GraphNodes( i )->YCoordinate() ) ;
1529     }
1530   }
1531
1532   first = true ;
1533   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1534     if ( Graph()->GraphNodes( i )->IsGOTONode() ) {
1535       if ( first ) {
1536         f << "    " << endl << "    " << "# Creation of GOTO Nodes" << endl ;
1537         first = false ;
1538       }
1539       else {
1540         f << "    " << endl ;
1541       }
1542       ((GraphBase::GOTONode * ) Graph()->GraphNodes( i ))->SavePY( f , Graph()->Name() ,
1543                                                                    Graph()->GraphNodes( i )->XCoordinate() ,
1544                                                                    Graph()->GraphNodes( i )->YCoordinate() ) ;
1545     }
1546   }
1547
1548   first = true ;
1549   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1550     if ( Graph()->GraphNodes( i )->IsMacroNode() ) {
1551       if ( first ) {
1552         f << "    " << endl << "    " << "# Creation of Macro Nodes" << endl ;
1553         first = false ;
1554       }
1555       else {
1556         f << "    " << endl ;
1557       }
1558       ((GraphBase::GOTONode * ) Graph()->GraphNodes( i ))->SavePY( f , Graph()->Name() ,
1559                                                                    Graph()->GraphNodes( i )->XCoordinate() ,
1560                                                                    Graph()->GraphNodes( i )->YCoordinate() ) ;
1561     }
1562   }
1563
1564   Links = Graph()->GetLinks() ;
1565 //  bool intervar ;
1566 //  map< string , int > aMapOfOutPorts ;
1567   first = true ;
1568   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1569     for ( j = 0 ; j < (int ) Links->size() ; j++ ) {
1570       if ( !strcmp( Graph()->GraphNodes( i )->Name() , (*Links)[ j ].FromNodeName.c_str() ) ) {
1571         if ( first ) {
1572           f << "    " << endl
1573             << "    " << "# Creation of Links"
1574             << endl ;
1575           first = false ;
1576         }
1577         else {
1578           f << "    " << endl ;
1579         }
1580 //        char * NodePort = new char [ strlen( (*Links)[ j ].FromNodeName.c_str() ) +
1581 //                                     strlen( (*Links)[ j ].FromServiceParameterName.c_str() ) + 1 ] ;
1582 //        strcpy( NodePort , (*Links)[ j ].FromNodeName.c_str() ) ;
1583 //        strcat( NodePort , (*Links)[ j ].FromServiceParameterName.c_str() ) ;
1584 //        if ( aMapOfOutPorts[ NodePort ] == 0 ) {
1585 //          aMapOfOutPorts[ NodePort ] = j + 1 ;
1586 //          intervar = true ;
1587 //        }
1588 //        else {
1589 //          intervar = false ;
1590 //        }
1591         bool fromparam = false ;
1592         if ( Graph()->GraphNodes( i )->GetOutPort( (*Links)[ j ].FromServiceParameterName.c_str() )->IsParam() ) {
1593           fromparam = true ;
1594         }
1595         bool toparam = false ;
1596         if ( Graph()->GetChangeGraphNode( (*Links)[ j ].ToNodeName.c_str() )->GetInPort( (*Links)[ j ].ToServiceParameterName.c_str() )->IsParam() ) {
1597           toparam = true ;
1598         }
1599         LinkSavePY( f , Graph()->Name() , (*Links)[ j ] , fromparam , toparam , false ) ;
1600 //        delete [] NodePort ;
1601       }
1602     }
1603   }
1604
1605   if ( Graph()->GraphMacroLevel() == 0 ) {
1606     const GraphBase::ListOfSLinks * Datas = Graph()->GetDatas() ;
1607     first = true ;
1608     for ( i = 0 ; i < (int ) Datas->size() ; i++ ) {
1609       if ( first ) {
1610         f << "    " << endl << "    " << "# Input datas" << endl ;
1611         first = false ;
1612       }
1613       bool fromparam = true ;
1614       bool toparam = true ;
1615       LinkSavePY( f , Graph()->Name() , (*Datas)[ i ] , fromparam , toparam , true ) ;
1616     }
1617   }
1618
1619   first = true ;
1620   const SALOME_ModuleCatalog::ListOfServicesParameter ListOfInParam = Graph()->ServiceInParameter() ;
1621   for ( i = 0 ; i < (int ) ListOfInParam.length() ; i++ ) {
1622     string _aParam = CORBA::string_dup(ListOfInParam[ i ].Parametername) ;
1623     const char * aParam = _aParam.c_str() ;
1624     char * aNodeName ;
1625     char * aPortName ;
1626     int j ;
1627     for ( j = 0 ; j < (int ) strlen( aParam ) ; j++ ) {
1628 //      if ( aParam[ j ] == '\\' ) {
1629       if ( aParam[ j ] == '_' && aParam[ j+1 ] == '_' ) {
1630         aNodeName = new char[ j+1 ] ;
1631         strncpy( aNodeName , aParam , j ) ;
1632         aNodeName[ j ] = '\0' ;
1633         aPortName = new char[ strlen( aParam ) - j-1 ] ;
1634         strncpy( aPortName , &aParam[ j+2 ] , strlen( aParam ) - j-1 ) ;
1635         break ;
1636       }
1637     }
1638     const GraphBase::InPort * anInPort = Graph()->GetChangeGraphNode( aNodeName )->GetInPort( aPortName ) ;
1639     if ( !anInPort->IsDataConnected() ) {
1640       if ( first ) {
1641         f << "    " << endl << "    " << "# Input Ports of the graph" << endl ;
1642         first = false ;
1643       }
1644       f << "    " << "#I" << aNodeName << aPortName << " = " << aNodeName << ".GetInPort( '"
1645         << aPortName << "' )" << endl ;
1646     }
1647     delete [] aNodeName ;
1648     delete [] aPortName ;
1649   }
1650
1651   f << "    " << endl << "    # Output Ports of the graph" << endl ;
1652   const SALOME_ModuleCatalog::ListOfServicesParameter ListOfOutParam = Graph()->ServiceOutParameter() ;
1653   for ( i = 0 ; i < (int ) ListOfOutParam.length() ; i++ ) {
1654     string _aParam = CORBA::string_dup(ListOfOutParam[ i ].Parametername) ;
1655     const char * aParam = _aParam.c_str() ;
1656     char * aNodeName ;
1657     char * aPortName ;
1658     int j ;
1659     for ( j = 0 ; j < (int ) strlen( aParam ) ; j++ ) {
1660 //      if ( aParam[ j ] == '\\' ) {
1661       if ( aParam[ j ] == '_' && aParam[ j+1 ] == '_' ) {
1662         aNodeName = new char[ j+1 ] ;
1663         strncpy( aNodeName , aParam , j ) ;
1664         aNodeName[ j ] = '\0' ;
1665         aPortName = new char[ strlen( aParam ) - j-1 ] ;
1666         strncpy( aPortName , &aParam[ j+2 ] , strlen( aParam ) - j-1 ) ;
1667         break ;
1668       }
1669     }
1670     f << "    " << "#O" << aNodeName << aPortName << " = " << aNodeName << ".GetOutPort( '"
1671       << aPortName << "' )" << endl ;
1672     delete [] aNodeName ;
1673     delete [] aPortName ;
1674   }
1675
1676   f << "    " << "return " << Graph()->Name() << endl << endl ;
1677
1678 // RECURSIVE CREATION OF GRAPHS OF MACRONODES
1679   for ( i = 0 ; i < Graph()->GraphNodesSize() ; i++ ) {
1680     if ( Graph()->GraphNodes( i )->IsMacroNode() ) {
1681       GraphBase::GOTONode * aMacroNode = (GraphBase::GOTONode * ) Graph()->GraphNodes( i ) ;
1682       GraphBase::Graph * aMacroGraph = (GraphBase::Graph * ) aMacroNode->CoupledNode() ;
1683       cdebug << "OutNode::SavePY ---> OutNode::SavePY( ostream & f ) MacroGraph " << aMacroGraph->Name() << endl ;
1684       GraphEditor::DataFlow * aDataFlow = aMacroGraph->GraphEditor() ;
1685       cdebug << "SavePY of the Graph " << aDataFlow->Graph() << " of the MacroNode "
1686              << aMacroGraph->Name() << endl ;
1687       if ( !aDataFlow->SavePY( f , false ) ) {
1688         return false ;
1689       }
1690     }
1691   }
1692
1693 //  f << Graph()->Name() << " = " << Graph()->Name() << "()" << endl ;
1694
1695   return true ;
1696 }
1697
1698 /** Iterate through ALL links (OutPort-InPort pairs) and check if their types are 
1699  *  compatible - call GraphEditor::DataFlow::IsCompatible(type1, type2).
1700  *  Returns true if all are compatible.
1701  */
1702 bool GraphEditor::OutNode::IsLinksCompatible() {
1703   const GraphBase::ListOfSLinks * Links = Graph()->GetLinks( true ) ;
1704   bool b = true;
1705   for ( int i = 0 ; i < (int ) Links->size() && b ; i++ ) {
1706     GraphBase::SLink aLink = (*Links)[i];
1707     GraphBase::ComputingNode* anOutNode = Graph()->GetChangeGraphNode( aLink.FromNodeName.c_str() );
1708     GraphBase::ComputingNode* anInNode = Graph()->GetChangeGraphNode( aLink.ToNodeName.c_str() );
1709     const GraphBase::OutPort* anOutPort = anOutNode->GetOutPort( aLink.FromServiceParameterName.c_str() );
1710     const GraphBase::InPort* anInPort = anInNode->GetInPort( aLink.ToServiceParameterName.c_str() );    
1711     b = IsCompatible( anOutPort->PortType(), anInPort->PortType() );
1712     cdebug << "GraphEditor::OutNode::IsLinksCompatible:  "<<aLink.FromNodeName << "("<<aLink.FromServiceParameterName
1713       <<")  -->  "<<aLink.ToNodeName<<"("<<aLink.ToServiceParameterName<<") = " << (b ? "OK" : "Not compatible (ERROR)") << endl;
1714     if ( !b )
1715       MESSAGE( "Graph structure ERROR: type of port \""<<aLink.FromServiceParameterName<<"\" of node \""
1716               <<aLink.FromNodeName<<"\" is not compatible with type of linked port \""
1717               <<aLink.ToServiceParameterName<<"\" of node \""<<aLink.ToNodeName<<"\"" ); 
1718   }
1719   return b;
1720 }
1721
1722 static const char* gSimpleTypes[] = 
1723   {"boolean", "char", "short", "int", "long", "float", "double"};
1724 bool isSimpleType( string type ) {
1725   for ( int i = 0; i < 7; i++ )
1726     if ( type == gSimpleTypes[i] )
1727       return true;
1728   return false;
1729 }
1730
1731 /**Returns true if an out-port of type "OutPortType" can be bound with in-port of type "InPortType". 
1732  * Types: {"string", "boolean", "char", "short", "int", "long", "float", "double", "objref"};
1733  * Currently considered compatible ALL types except for objref - they must match exactly
1734  */
1735 bool GraphEditor::OutNode::IsCompatible( const char* OutPortType, const char* InPortType ) const {
1736   bool ret = true;
1737   string t1 = OutPortType;
1738   string t2 = InPortType;
1739   // if ANY is a string - the link is OK
1740   if ( t1 == "string" || t2 == "string" )
1741     ret = true;
1742
1743   // the next check prohibits linkage of "objref" to any simple type (int, char, etc.)
1744   // it is still possible to link "objref" to some UNKNOWN type (probably objref, too,
1745   // which interface name came from Cataloge
1746   else if ( ( t1 == "objref" && isSimpleType( t2 ) ) ||  
1747             ( t2 == "objref" && isSimpleType( t1 ) ) )
1748     ret = false; 
1749   return ret;
1750 }
1751
1752 ostream & operator<< (ostream & f,const GraphEditor::OutNode & G) {
1753   f << (GraphBase::ComputingNode ) *(G.Graph()) ;
1754   f << endl ;
1755
1756   f << "  Nodes : " << (G.Graph())->GraphNodesSize() << " node" 
1757     << ((G.Graph())->GraphNodesSize() > 1 ? "s" : "") << endl;
1758   
1759   int i ;
1760   for ( i = 0 ; i < (G.Graph())->GraphNodesSize() ; i++ ) {
1761     f
1762 //      << hex << (void *) G.Graph().GraphNodes( i ) << dec << " "
1763       << (G.Graph())->GraphNodes( i ) << endl;
1764   }
1765
1766   f << "  Links : " << endl ;
1767   for ( i = 0 ; i < (G.Graph())->GraphNodesSize() ; i++ ) {
1768     (G.Graph())->GraphNodes( i )->ListLinks( f ) ;
1769   }
1770
1771   f << "  Datas : " << endl ;
1772   (G.Graph())->ListDatas( f ) ;
1773
1774   f << "DataFlow " << (G.Graph())->Name() << " is " ;
1775   if ( G.IsNotValid() )
1776     f << "not " ;
1777   f << "valid and is " ;
1778   if ( G.IsNotExecutable() )
1779     f << "not " ;
1780   f << "executable." << endl ;
1781
1782   f << endl ;
1783   
1784   return f;
1785 }
1786
1787 ostream & operator<< (ostream &fOut,const SUPERV::SDate &D)
1788 {
1789 //  cdebug_in << "operator<< GraphEditor::Date" << endl;
1790
1791   fOut  << D.Day << "/" 
1792         << D.Month << "/" 
1793         << D.Year << " - " 
1794         << D.Hour << ":" 
1795         << D.Minute <<  ":"  
1796         << D.Second;
1797
1798 //  cdebug_out << "operator<< GraphEditor::Date" << endl;
1799   return fOut;
1800 }
1801
1802 /*
1803 GraphBase::Graph * GraphEditor::OutNode::MapGraph( const char * aGraphName ) {
1804   GraphBase::Graph * aGraph = _MapOfGraphs[ aGraphName ] ;
1805   return aGraph ;
1806 }
1807
1808 bool GraphEditor::OutNode::MapGraph( GraphBase::Graph * aGraph , const char * aGraphName ) {
1809   if ( MapGraph( aGraphName ) ) {
1810     return false ;
1811   }
1812   _MapOfGraphs[ aGraphName ] = aGraph ;
1813   return true ;
1814 }
1815
1816 void GraphEditor::OutNode::EraseGraph( const char * aGraphName ) {
1817   _MapOfGraphs.erase( aGraphName ) ;
1818 }
1819
1820 bool GraphEditor::OutNode::GraphName( const char * aGraphName ) {
1821   return  _MapOfGraphNames[ aGraphName ] ;
1822 }
1823 */
1824
1825