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