Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/superv.git] / src / GraphEditor / DataFlowEditor_OutNode.cxx
1 using namespace std;
2
3 #include "DataFlowEditor_OutNode.hxx"
4 #include "DataFlowBase_EndOfLoopNode.hxx"
5 #include "DataFlowBase_EndOfSwitchNode.hxx"
6
7 // Implementation de la classe GraphEditor::Graph
8
9 GraphEditor::OutNode::OutNode() :
10              Graph() {
11   cdebug_in << "GraphEditor::OutNode::OutNode()" << endl;
12
13   _Imported = false ;
14   _Valid = false ;
15   _Executable = false ;
16
17   cdebug_out << "GraphEditor::OutNode::OutNode()" << endl;
18 }
19
20 GraphEditor::OutNode::OutNode( CORBA::ORB_ptr ORB ,
21                                SALOME_NamingService* ptrNamingService ,
22                                const char *DataFlowName ,
23                                const char * DebugFileName ) :
24              Graph( ORB , ptrNamingService , DataFlowName , DebugFileName ) {
25   cdebug_in << "GraphEditor::OutNode::OutNode(" ;
26   if ( DataFlowName ) {
27     cdebug << DataFlowName ;
28   }
29   cdebug << ")" << endl;
30
31   _Orb = CORBA::ORB::_duplicate( ORB ) ;
32   _Imported = false ;
33   _Valid = false ;
34   _Executable = false ;
35
36   cdebug_out << "GraphEditor::OutNode::OutNode" << endl;
37 }
38
39 GraphEditor::OutNode::OutNode(
40                      CORBA::ORB_ptr ORB ,
41                      SALOME_NamingService* ptrNamingService ,
42                      const SALOME_ModuleCatalog::Service& DataFlowService ,
43                      const char *DataFlowComponentName ,
44                      const char *DataFlowInterfaceName ,
45                      const char *DataFlowName ,
46                      const SUPERV::KindOfNode DataFlowkind ,
47                      const SUPERV::SDate DataFlowFirstCreation ,
48                      const SUPERV::SDate DataFlowLastModification ,
49                      const char * DataFlowEditorRelease ,
50                      const char * DataFlowAuthor ,
51                      const char * DataFlowComputer ,
52                      const char * DataFlowComment ,
53                      const char * DebugFileName ) :
54              Graph( ORB , ptrNamingService , DataFlowService , DataFlowComponentName ,
55                     DataFlowInterfaceName , DataFlowName , DataFlowkind ,
56                     DataFlowFirstCreation , DataFlowLastModification  ,
57                     DataFlowEditorRelease , DataFlowAuthor ,
58                     DataFlowComputer , DataFlowComment , DebugFileName ) {
59
60   _Orb = CORBA::ORB::_duplicate( ORB ) ;
61   _Imported = false ;
62   _Valid = false ;
63   _Executable = false ;
64
65 } ;
66
67 GraphEditor::OutNode::~OutNode() {
68 //  delete _DataFlowNode ;
69 //  delete _DataFlowDatas ;
70 //  delete _GT ;
71 }
72
73 bool GraphEditor::OutNode::LoadDataFlow(
74                          const GraphBase::SGraph *aDataFlow ) {
75   bool RetVal = false ;
76   cdebug_in << "GraphEditor::OutNode::LoadDataFlow() " << aDataFlow->Info.theName.c_str()
77             << endl;
78 //  if ( GraphBase::Service::ServiceName() == NULL ||
79 //       !strlen( GraphBase::Service::ServiceName() ) || !aConstructor ) {
80   if ( !_Imported ) {
81     RetVal = LoadInfo( aDataFlow->Info ) ;
82     _Imported = true ;
83   }
84   else
85     RetVal = true ;
86
87     map< string , int > aMapOfNodes ;
88     if ( RetVal )
89       RetVal = LoadNodes( aMapOfNodes , aDataFlow->Nodes ) ;
90     if ( RetVal )
91       RetVal = LoadLinks( aMapOfNodes , aDataFlow->Links ) ;
92     if ( RetVal ) {
93       Valid() ;
94       RetVal = LoadDatas( aMapOfNodes , aDataFlow->Datas ) ;
95     }
96 //  }
97 //  else {
98 //    cdebug << "GraphEditor::OutNode::LoadDataFlow Error. ServiceName : "
99 //            << (void *) GraphBase::Service::ServiceName() << " '" 
100 //           << GraphBase::Service::ServiceName() << "'" << endl ;
101 //  }
102   cdebug_out << "GraphEditor::OutNode::LoadDataFlow" << endl;
103   return RetVal ;
104 }
105
106 bool GraphEditor::OutNode::LoadXml( const char* myFileName ) {
107   bool RetVal = false ;
108   GraphBase::SGraph aDataFlow ;
109   cdebug_in << "GraphEditor::OutNode::LoadXml() " << endl;
110   if ( myFileName == NULL ) {
111     _Imported = true ;
112     RetVal = true ;
113   }
114   else if ( GraphBase::Graph::LoadXml( _Orb , myFileName , aDataFlow ) ) {
115     RetVal = LoadDataFlow( &aDataFlow ) ;
116 //    if ( RetVal )
117 //      RetVal = Name( aDataFlow.Info.theName.c_str() ) ;
118   }
119   cdebug_out << "GraphEditor::OutNode::LoadXml" << endl;
120   return RetVal ;
121
122
123 bool GraphEditor::OutNode::LoadInfo(const GraphBase::SNode &aDataFlowInfo ) {
124   cdebug_in << "GraphEditor::OutNode::LoadInfo " << aDataFlowInfo.theName.c_str()
125             << endl ;
126 //  MESSAGE( "GraphEditor::OutNode::LoadDataFlow" );
127 //  ComponentName( aDataFlowInfo.theComponentName.c_str() ) ;
128 //  InterfaceName( aDataFlowInfo.theInterfaceName.c_str() ) ;
129   Name( aDataFlowInfo.theName.c_str() ) ;
130   Kind( aDataFlowInfo.theKind ) ;
131   Service( aDataFlowInfo.theService ) ;
132   FirstCreation( aDataFlowInfo.theFirstCreation ) ;
133   LastModification( aDataFlowInfo.theLastModification ) ;
134   EditorRelease( aDataFlowInfo.theEditorRelease.c_str() ) ;
135   Author( aDataFlowInfo.theAuthor.c_str()  ) ;
136 //  Computer( aDataFlowInfo.theContainer.c_str() ) ;
137   Comment( aDataFlowInfo.theComment.c_str() ) ;
138 // Not in OutNode/DataFlow but in InNode/DataFlow_in_an_other_DataFlow
139 //  Coordinates( aDataFlowInfo.theX , aDataFlowInfo.theY ) ;
140   cdebug_out << "GraphEditor::OutNode::LoadInfo" << endl ;
141   return true ;
142 }
143
144 bool GraphEditor::OutNode::LoadNodes(map< string , int > & aMapOfNodes ,
145                                      const GraphBase::ListOfNodes &aListOfNodes ) {
146   GraphEditor::InNode * anInNode ;
147   cdebug_in << "GraphEditor::OutNode::LoadNodes" << endl ;
148   int i ;
149   for ( i = 0 ; i < aListOfNodes.size() ; i++ ) {
150     GraphBase::SNode aNode = aListOfNodes[ i ] ;
151 //    if ( aConstructor ) {
152 //      anInNode = AddNode( aNode.theService , aNode.theComponentName.c_str() ,
153 //                        aNode.theInterfaceName.c_str() ,
154 //                        aNode.theName.c_str() ,
155 //                        aNode.theKind ,
156 //                        aNode.theFirstCreation , aNode.theLastModification ,
157 //                        aNode.theEditorRelease.c_str() ,
158 //                        aNode.theAuthor.c_str() , aNode.theContainer.c_str() ,
159 //                        aNode.theComment.c_str() ,
160 //                        aNode.theCoords.theX , aNode.theCoords.theY ) ;
161 //    }
162 //    else {
163       const char * aNodeName = aNode.theName.c_str() ;
164       if ( aNode.theListOfFuncName.size() == 0 ) {
165         aNode.theListOfFuncName.resize( 1 ) ;
166         aNode.theListOfFuncName[ 0 ] = "" ;
167         aNode.theListOfPythonFunctions.resize( 1 ) ;
168         aNode.theListOfPythonFunctions[ 0 ] = new SUPERV::ListOfStrings() ;
169       }
170       if ( GetGraphNode( aNode.theName.c_str() ) )
171         aNodeName = NULL ;
172       anInNode = AddNode( aNode.theService ,
173                           aNode.theListOfFuncName ,
174                           aNode.theListOfPythonFunctions ,
175                           aNode.theComponentName.c_str() ,
176                           aNode.theInterfaceName.c_str() , aNodeName ,
177                           aNode.theKind ,
178                           aNode.theFirstCreation , aNode.theLastModification ,
179                           aNode.theEditorRelease.c_str() ,
180                           aNode.theAuthor.c_str() , aNode.theContainer.c_str() ,
181                           aNode.theComment.c_str() ,
182                           aNode.theCoords.theX , aNode.theCoords.theY ) ;
183       string * aNodetheName = new string( aNode.theName ) ;
184       aMapOfNodes[ *aNodetheName ] = GetGraphNodeIndex( anInNode->Name() ) ;
185       if ( anInNode->IsOneOfInLineNodes() ) {
186         anInNode->GraphEditor::InNode::InLineNode()->DefPortsOfNode(
187                                 _Orb , aNode.theService , anInNode->NamePtr() ,
188                                 anInNode->Kind() , false ,
189                                 anInNode->IsLoopNode() || anInNode->IsEndLoopNode() ,
190                                 true , true , Graph_prof_debug() , Graph_fdebug() ) ;
191         GraphBase::InLineNode * aINode = anInNode->InLineNode() ;
192         GraphBase::LoopNode * aLNode = NULL ;
193         if ( aINode->IsLoopNode() ) {
194           aLNode = anInNode->LoopNode() ;
195           aLNode->SetPythonFunction( aNode.theListOfFuncName[ 0 ].c_str() ,
196                                      *aNode.theListOfPythonFunctions[ 0 ] ) ;
197           aLNode->SetMorePythonFunction( aNode.theListOfFuncName[ 1 ].c_str() ,
198                                          *aNode.theListOfPythonFunctions[ 1 ] ) ;
199           aLNode->SetNextPythonFunction( aNode.theListOfFuncName[ 2 ].c_str() ,
200                                          *aNode.theListOfPythonFunctions[ 2 ] ) ;
201         }
202         else if ( aINode->IsInLineNode() || aINode->IsGOTONode() ||
203                   aINode->IsSwitchNode() || aINode->IsEndSwitchNode() ) {
204           aINode->SetPythonFunction( aNode.theListOfFuncName[ 0 ].c_str() ,
205                                      *aNode.theListOfPythonFunctions[ 0 ] ) ;
206         }
207       }
208 #if 0
209       if ( aNode.theListOfParameters.size() ) {
210         int j ;
211         for ( j = 0 ; j < aNode.theListOfParameters.size() ; j++ ) {
212           if ( IsInLineNode() ) {
213             GraphBase::InPort * InputPort = anInNode->AddInPort(
214                  aNode.theListOfParameters[ j ].theInParameter.Parametername ,
215                  aNode.theListOfParameters[ j ].theInParameter.Parametertype ) ;
216             GraphBase::OutPort * OutputPort = anInNode->AddOutPort(
217                  aNode.theListOfParameters[ j ].theOutParameter.Parametername ,
218                  aNode.theListOfParameters[ j ].theOutParameter.Parametertype ) ;
219             anInNode->InOutPort( InputPort , OutputPort ) ;
220           }
221         }
222       }
223 #endif
224 //      cout << "LoadNodes " << aNodetheName << " "
225 //           << GetGraphNodeIndex( anInNode->Name() ) << endl ;
226       delete aNodetheName ;
227 //    }
228     if ( !anInNode )
229       return false ;
230   }
231   for ( i = 0 ; i < aListOfNodes.size() ; i++ ) {
232     GraphBase::SNode aNode = aListOfNodes[ i ] ;
233     cdebug << "GraphEditor::OutNode::LoadNodes " << aNode.theName.c_str() << " Coupled to "
234            << aNode.theCoupledNode.c_str() << endl ;
235     anInNode = (GraphEditor::InNode * ) GetChangeGraphNode( aNode.theName.c_str() )->GetInNode() ;
236     if ( anInNode->IsOneOfGOTONodes() && strlen( aNode.theCoupledNode.c_str() ) ) {
237       GraphBase::GOTONode * aCoupledNode ;
238       aCoupledNode = (GraphBase::GOTONode * ) GetGraphNode( aNode.theName.c_str() ) ;
239       aCoupledNode->CoupledNode( (GraphBase::GOTONode * ) GetChangeGraphNode( aNode.theCoupledNode.c_str() ) ) ; 
240     }
241   }
242   cdebug_out << "GraphEditor::OutNode::LoadNodes" << endl ;
243   return true ;
244 }
245
246 bool GraphEditor::OutNode::LoadLinks(map< string , int > & aMapOfNodes ,
247                                      const GraphBase::ListOfLinks &aListOfLinks ) {
248   bool RetVal = true ;
249   cdebug_in << "GraphEditor::OutNode::LoadLinks" << endl ;
250 //  MESSAGE( "GraphEditor::OutNode::LoadLinks" );
251   int i , j ;
252   for ( i = 0 ; i < aListOfLinks.size() ; i++ ) {
253     GraphBase::SLink aLink = aListOfLinks[ i ] ;
254     string * aLinkFromNodeName = new string( aLink.FromNodeName.c_str() ) ;
255     string * aLinkToNodeName = new string( aLink.ToNodeName.c_str() ) ;
256     RetVal = AddLink( GetGraphNode( aMapOfNodes[ aLinkFromNodeName->c_str() ] )->Name() ,
257                       aLink.FromServiceParameterName.c_str() ,
258                       GetGraphNode( aMapOfNodes[ aLinkToNodeName->c_str() ] )->Name() ,
259                       aLink.ToServiceParameterName.c_str() ,
260                       *((GraphBase::ComputingNode *) GetGraphNode( aMapOfNodes[ aLinkFromNodeName->c_str() ] ))->GetOutPort( aLink.FromServiceParameterName.c_str() )->Value() ) ;
261 //                      aLink.aLinkValue ) ;
262     if ( !RetVal )
263       break ;
264     else {
265       for ( j = 0 ; j < aLink.aListOfCoords.size() ; j++ ) {
266         RetVal = AddLinkCoord( GetGraphNode( aMapOfNodes[ aLinkFromNodeName->c_str() ] )->Name() ,
267                                aLink.FromServiceParameterName.c_str() ,
268                                GetGraphNode( aMapOfNodes[ aLink.ToNodeName.c_str() ] )->Name() ,
269                                aLink.ToServiceParameterName.c_str() ,
270                                j + 1 ,
271                                aLink.aListOfCoords[j].theX ,
272                                aLink.aListOfCoords[j].theY ) ;
273         if ( !RetVal )
274           break ;
275       }
276     }
277     delete aLinkFromNodeName ;
278     delete aLinkToNodeName ;
279   }
280   cdebug_out << "GraphEditor::OutNode::LoadLinks" << endl ;
281   return RetVal ;
282 }
283
284 bool GraphEditor::OutNode::LoadDatas(map< string , int > & aMapOfNodes ,
285                                      const GraphBase::ListOfLinks &aListOfDatas ) {
286   bool RetVal = true ;
287   cdebug_in << "GraphEditor::OutNode::LoadDatas" << endl ;
288 //  MESSAGE( "GraphEditor::OutNode::LoadDatas" );
289   int i ;
290   for ( i = 0 ; i < aListOfDatas.size() ; i++ ) {
291     GraphBase::SLink aLink = aListOfDatas[ i ] ;
292     if ( !strcmp( aLink.FromNodeName.c_str() , Name() ) ) {
293       cdebug << "GraphEditor::OutNode::LoadDatas Warning "
294              << aLink.FromNodeName.c_str()
295              << " and " << aLink.ToNodeName.c_str() << " differents from " << Name()
296              << endl ;
297     }
298     string * aLinkFromNodeName = new string( aLink.FromNodeName.c_str() ) ;
299     string * aLinkToNodeName = new string( aLink.ToNodeName.c_str() ) ;
300 //      cout << "LoadDatas " << aLink.FromNodeName.c_str() << " "
301 //           << aMapOfNodes[ aLinkFromNodeName->c_str() ] << endl ;
302 //      cout << "          " << aLink.ToNodeName.c_str() << " "
303 //           << aMapOfNodes[ aLinkToNodeName->c_str() ] << endl ;
304     RetVal = GraphBase::Graph::AddInputData( GetGraphNode( aMapOfNodes[ aLinkToNodeName->c_str() ] )->Name() ,
305                                              aLink.ToServiceParameterName.c_str() ,
306                                              aLink.aLinkValue ) ;
307     delete aLinkFromNodeName ;
308     delete aLinkToNodeName ;
309     if ( !RetVal )
310       break ;
311   }
312   cdebug_out << "GraphEditor::OutNode::LoadDatas" << endl ;
313   return RetVal ;
314 }
315
316 bool GraphEditor::OutNode::SaveXml(const char* filename) {
317   bool test;
318   cdebug_in << "GraphEditor::OutNode::SaveXml(" << filename << ")" << endl;
319   ofstream f(filename);
320   IsValid() ;
321 //  test = SaveXML( f );
322   QDomDocument Graph ;
323   test = SaveXML( Graph );
324   if ( test ) {
325     QString xml = Graph.toString() ;
326 //    cout << "GraphEditor::OutNode::SaveXML " << xml << endl ;
327     f << xml << endl ;
328   }
329   cdebug_out << "GraphEditor::OutNode::SaveXml" << endl;
330   return test;
331 }
332
333
334 bool GraphEditor::OutNode::SavePy( const char* filename ) {
335   bool test;
336   cdebug_in << "GraphEditor::OutNode::SavePy(" << filename << ")" << endl;
337   ofstream f( filename ) ;
338   IsValid() ;
339   test = SavePY( f );
340   cdebug_out << "GraphEditor::OutNode::SavePy" << endl;
341   return test;
342 }
343
344 GraphBase::SGraph * GraphEditor::OutNode::GetDataFlow() {
345   GraphBase::SGraph * aDataFlow = new GraphBase::SGraph;
346   aDataFlow->Info = *GetInfo() ;
347   aDataFlow->Nodes = *GetNodes() ;
348   aDataFlow->Links = *GetLinks() ;
349   aDataFlow->Datas = *GetDatas() ;
350   return aDataFlow ;
351 }
352
353 void GraphEditor::OutNode::DateModification() {
354   time_t T = time(NULL);
355   struct tm * Tm = localtime(&T);
356   SUPERV::SDate aLastModificationDate ;
357
358   aLastModificationDate.Second = Tm->tm_sec;
359   aLastModificationDate.Minute = Tm->tm_min;
360   aLastModificationDate.Hour   = Tm->tm_hour;
361   aLastModificationDate.Day    = Tm->tm_mday;
362   aLastModificationDate.Month  = Tm->tm_mon + 1;
363   aLastModificationDate.Year   = Tm->tm_year + 1900;
364   LastModification( aLastModificationDate ) ;
365 }
366
367 void GraphEditor::OutNode::Coordinates( const char* NodeName ,
368                                         const int X ,
369                                         const int Y ) {
370   ((GraphEditor::InNode * ) GetChangeGraphNode( NodeName ))->Coordinates( X , Y ) ;
371 }
372
373 const int GraphEditor::OutNode::XCoordinate( const char* NodeName ) {
374   return ((GraphEditor::InNode * ) GetChangeGraphNode( NodeName ))->XCoordinate() ;
375 }
376
377 const int GraphEditor::OutNode::YCoordinate( const char* NodeName ) {
378   return ((GraphEditor::InNode * ) GetChangeGraphNode( NodeName ))->YCoordinate() ;
379 }
380
381 GraphEditor::InNode *GraphEditor::OutNode::AddNode(
382                       const SALOME_ModuleCatalog::Service& NodeService ,
383                       GraphBase::ListOfFuncName aFuncName ,
384                       GraphBase::ListOfPythonFunctions aPythonFunction ,
385                       const char *NodeComponentName ,
386                       const char* NodeInterfaceName ,
387                       const char *theNodeName ,
388                       const SUPERV::KindOfNode NodeKindOfNode ,
389                       const SUPERV::SDate NodeFirstCreation ,
390                       const SUPERV::SDate NodeLastModification  ,
391                       const char * NodeEditorRelease ,
392                       const char * NodeAuthor ,
393                       const char * NodeComputer ,
394                       const char * NodeComment ,
395                       const int NodeX ,
396                       const int NodeY ) {
397   cdebug_in << "GraphEditor::OutNode::AddNode(" << NodeComponentName << " , "
398             << theNodeName << ")" << endl;
399   char * RetVal = NULLSTRING ;
400   GraphEditor::InNode *Nd = NULL ;
401   char * aNodeName = NULL ;
402   bool   GeneratedName = false ;
403   if ( NodeKindOfNode == SUPERV::InLineNode ||
404        NodeKindOfNode == SUPERV::LoopNode ||
405        NodeKindOfNode == SUPERV::EndLoopNode ||
406        NodeKindOfNode == SUPERV::SwitchNode ||
407        NodeKindOfNode == SUPERV::EndSwitchNode ||
408        NodeKindOfNode == SUPERV::GOTONode ) {
409     if ( theNodeName == NULL || strlen( theNodeName ) == 0 ) {
410       if ( NodeKindOfNode == SUPERV::InLineNode ) {
411         ((SALOME_ModuleCatalog::Service& ) NodeService).ServiceName = my_strdup( "InLine" ) ;
412       }
413       else if ( NodeKindOfNode == SUPERV::LoopNode ) {
414         ((SALOME_ModuleCatalog::Service& ) NodeService).ServiceName = my_strdup( "Loop" ) ;
415       }
416       else if ( NodeKindOfNode == SUPERV::EndLoopNode ) {
417         ((SALOME_ModuleCatalog::Service& ) NodeService).ServiceName = my_strdup( "EndLoop" ) ;
418       }
419       else if ( NodeKindOfNode == SUPERV::SwitchNode ) {
420         ((SALOME_ModuleCatalog::Service& ) NodeService).ServiceName = my_strdup( "Switch" ) ;
421       }
422       else if ( NodeKindOfNode == SUPERV::EndSwitchNode ) {
423         ((SALOME_ModuleCatalog::Service& ) NodeService).ServiceName = my_strdup( "EndSwitch" ) ;
424       }
425       else if ( NodeKindOfNode == SUPERV::GOTONode ) {
426         ((SALOME_ModuleCatalog::Service& ) NodeService).ServiceName = my_strdup( "GOTO" ) ;
427       }
428     }
429     else {
430       ((SALOME_ModuleCatalog::Service& ) NodeService).ServiceName = CORBA::string_dup( theNodeName ) ;
431     }
432     theNodeName = NULL ;
433   }
434   if ( theNodeName == NULL ) {
435     aNodeName = new char[ strlen( NodeService.ServiceName )+1 ] ;
436     strcpy( aNodeName , NodeService.ServiceName ) ;
437     if ( GetGraphNode( NodeService.ServiceName ) ) {
438       GeneratedName = true ;
439       while ( GetGraphNode( aNodeName ) ) {
440         if ( aNodeName )
441           delete [] aNodeName ;
442         int num = GetServiceNameNumber( NodeService.ServiceName ) ;
443         ostrstream s ;
444         s << num << ends ;
445         const char * n_instance = s.str() ;
446         int lname = strlen( NodeService.ServiceName ) + 1 +
447                     strlen( n_instance ) + 1 ;
448         aNodeName = new char[lname] ;
449         strcpy( aNodeName , NodeService.ServiceName ) ;
450         strcat( aNodeName , "_" ) ;
451         strcat( aNodeName , n_instance ) ;
452       }
453     }
454   }
455   else {
456     if ( GetGraphNode( theNodeName ) == NULL ) {
457       aNodeName = new char[ strlen( theNodeName )+1 ] ;
458       strcpy( aNodeName , theNodeName ) ;
459     }
460   }
461   if ( aNodeName != NULL ) {
462     Nd = new GraphEditor::InNode( _Orb , NamingService() ,
463                                   aFuncName , aPythonFunction , NodeService ,
464                                   NodeComponentName , NodeInterfaceName ,
465                                   aNodeName , NodeKindOfNode ,
466                                   NodeFirstCreation , NodeLastModification ,
467                                   NodeEditorRelease , NodeAuthor ,
468                                   NodeComputer , NodeComment , GeneratedName ,
469                                   NodeX , NodeY ,
470                                   Graph_prof_debug() , Graph_fdebug() ) ;
471 //    MESSAGE( "GraphEditor::OutNode::AddNode " << hex << (void *) Nd << dec );
472 //    if ( GraphBase::Graph::AddNode( Nd ) ) {
473     if ( GraphBase::Graph::AddNode( Nd->ComputingNode() ) ) {
474       DateModification() ;
475       RetVal = Nd->Name() ;
476     }
477     else {
478       cdebug << "NodeName already exists." << endl ;
479     }
480   }
481   else {
482     cdebug << "NodeName is NULL or already exists." << endl ;
483   }
484 //  delete [] aNodeName ;
485   cdebug_out << "GraphEditor::OutNode::AddNode" << endl;
486   _Valid = false ;
487   return Nd ;
488 }
489
490 bool GraphEditor::OutNode::AddLinkCoord( const char* FromNodeName ,
491                                          const char* FromServiceParameterName ,
492                                          const char* ToNodeName ,
493                                          const char* ToServiceParameterName ,
494                                          const int nXY ,
495                                          const int* X ,
496                                          const int* Y ) {
497   GraphBase::InPort * aLink = GraphBase::Graph::GetChangeInPort( ToNodeName ,
498                                                ToServiceParameterName ) ;
499   if ( aLink ) {
500     if ( aLink->IsSwitch() ) {
501       return GraphBase::Graph::GetChangeOutPort( FromNodeName , FromServiceParameterName )->AddCoord( nXY , X , Y ) ;
502     }
503     else {
504       return aLink->AddCoord( nXY , X , Y ) ;
505     }
506   }
507   return false ;
508 }
509
510 bool GraphEditor::OutNode::AddLinkCoord( const char* FromNodeName ,
511                                          const char* FromServiceParameterName ,
512                                          const char* ToNodeName ,
513                                          const char* ToServiceParameterName ,
514                                          const int index ,
515                                          const int X ,
516                                          const int Y ) {
517   GraphBase::InPort * aLink = GraphBase::Graph::GetChangeInPort( ToNodeName ,
518                                                ToServiceParameterName ) ;
519   if ( aLink ) {
520     if ( aLink->IsSwitch() ) {
521       return GraphBase::Graph::GetChangeOutPort( FromNodeName , FromServiceParameterName )->AddCoord( index , X , Y ) ;
522     }
523     else {
524       return aLink->AddCoord( index , X , Y ) ;
525     }
526   }
527   return false ;
528 }
529
530 bool GraphEditor::OutNode::ChangeLinkCoord(
531                                          const char* FromNodeName ,
532                                          const char* FromServiceParameterName ,
533                                          const char* ToNodeName ,
534                                          const char* ToServiceParameterName ,
535                                          const int index ,
536                                          const int X ,
537                                          const int Y ) {
538   GraphBase::InPort * aLink = GraphBase::Graph::GetChangeInPort( ToNodeName ,
539                                                ToServiceParameterName ) ;
540   if ( aLink ) {
541     if ( aLink->IsSwitch() ) {
542       return GraphBase::Graph::GetChangeOutPort( FromNodeName , FromServiceParameterName )->ChangeCoord( index , X , Y ) ;
543     }
544     else {
545       return aLink->ChangeCoord( index , X , Y ) ;
546     }
547   }
548   return false ;
549 }
550
551 bool GraphEditor::OutNode::RemoveLinkCoord(
552                                          const char* FromNodeName ,
553                                          const char* FromServiceParameterName ,
554                                          const char* ToNodeName ,
555                                          const char* ToServiceParameterName ,
556                                          const int index ) {
557   GraphBase::InPort * aLink = GraphBase::Graph::GetChangeInPort( ToNodeName ,
558                                                ToServiceParameterName ) ;
559   if ( aLink ) {
560     if ( aLink->IsSwitch() ) {
561       return GraphBase::Graph::GetChangeOutPort( FromNodeName , FromServiceParameterName )->RemoveCoord( index ) ;
562     }
563     else {
564       return aLink->RemoveCoord( index ) ;
565     }
566   }
567   return false ;
568 }
569
570 int GraphEditor::OutNode::GetLinkCoordSize(
571                                          const char* FromNodeName ,
572                                          const char* FromServiceParameterName ,
573                                          const char* ToNodeName ,
574                                          const char* ToServiceParameterName ) {
575   const GraphBase::InPort * aLink = GraphBase::Graph::GetInPort( ToNodeName , ToServiceParameterName ) ;
576   if ( aLink ) {
577     if ( aLink->IsSwitch() ) {
578       return GraphBase::Graph::GetChangeOutPort( FromNodeName , FromServiceParameterName )->GetCoord() ;
579     }
580     else {
581       return aLink->GetCoord() ;
582     }
583   }
584   return 0 ;
585 }
586
587 bool GraphEditor::OutNode::GetLinkCoord( const char* FromNodeName ,
588                                          const char* FromServiceParameterName ,
589                                          const char* ToNodeName ,
590                                          const char* ToServiceParameterName ,
591                                          int *X , int *Y ) {
592   const GraphBase::InPort * aLink = GraphBase::Graph::GetInPort( ToNodeName , ToServiceParameterName ) ;
593   if ( aLink ) {
594     if ( aLink->IsSwitch() ) {
595       return GraphBase::Graph::GetChangeOutPort( FromNodeName , FromServiceParameterName )->GetCoord( X , Y ) ;
596     }
597     else {
598       return aLink->GetCoord( X , Y ) ;
599     }
600   }
601   return false ;
602 }
603
604 bool GraphEditor::OutNode::GetLinkCoord(
605                                   const char* FromNodeName ,
606                                   const char* FromServiceParameterName ,
607                                   const char* ToNodeName ,
608                                   const char* ToServiceParameterName ,
609                                   const int index , long &X , long &Y ) {
610   GraphBase::InPort * aLink = GraphBase::Graph::GetChangeInPort( ToNodeName ,
611                                                ToServiceParameterName ) ;
612   if ( aLink ) {
613     if ( aLink->IsSwitch() ) {
614       return GraphBase::Graph::GetChangeOutPort( FromNodeName , FromServiceParameterName )->GetCoord( index , X , Y ) ;
615     }
616     else {
617       return aLink->GetCoord( index , X , Y ) ;
618     }
619   }
620   return false ;
621 }
622
623 bool GraphEditor::OutNode::AddInputData( const char* ToNodeName1 ,
624                                          const char* ToParameterName1 ,
625                                          const char* ToNodeName2 ,
626                                          const char* ToParameterName2 ) {
627   cdebug_in << "GraphEditor::OutNode::AddInputData" << endl;
628   bool RetVal = GraphBase::Graph::AddInputData( ToNodeName1 ,
629                                                 ToParameterName1 ,
630                                                 ToNodeName2 ,
631                                                 ToParameterName2 ) ;
632   cdebug_out << "GraphEditor::OutNode::AddInputData" << endl;
633   _Valid = false ;
634   return RetVal ;
635 }
636
637 bool GraphEditor::OutNode::Valid() {
638   if ( _Valid )
639     return true ;
640
641   cdebug_in << "GraphEditor::OutNode::Valid" << endl;
642   _Executable = false ;
643
644   CreateService() ;
645
646   if ( !Sort() ) {
647     cdebug << "This DataFlow is not valid." << endl ;
648     return false ;
649   }
650
651 //  CreateService() ;
652
653   InLineServices() ;
654
655   ComputingNodes() ;
656   
657   _Valid = true ;
658
659   cdebug_out << "GraphEditor::OutNode::Valid" << endl;
660   return _Valid ;
661 }
662
663 bool GraphEditor::OutNode::Executable() {
664
665   cdebug_in << "GraphEditor::OutNode::Executable" << endl;
666   if ( !IsValid() )
667     Valid() ;
668   if ( !IsValid() )
669     return false ;
670 //  if ( !_GT )
671 //  GraphExecutor::GraphControl _GT = new GraphExecutor::GraphControl( this );
672
673   if ( DataServerNodes() )
674     _Executable = true ;
675   else {
676     cdebug << "This DataFlow is not executable." << endl ;
677     _Executable = false ;
678   }
679
680   cdebug_out << "GraphEditor::OutNode::Executable" << endl;
681   return _Executable ;
682 }
683
684 const CORBA::Any *GraphEditor::OutNode::GetInData(
685                               const char * ToNodeName ,
686                               const char * ToParameterName ) {
687   cdebug_in << "GraphEditor::OutNode::GetInData" << endl ;
688   const CORBA::Any * retdata = PortInData( ToNodeName , ToParameterName ) ;
689   cdebug_out << "GraphEditor::OutNode::GetInData " << ToNodeName
690              << " " << ToParameterName << endl ;
691   return retdata ;
692 }
693
694 const CORBA::Any *GraphEditor::OutNode::GetOutData(
695                               const char * FromNodeName ,
696                               const char * FromParameterName ) {
697   cdebug_in << "GraphEditor::OutNode::GetOutData" << endl ;
698   const CORBA::Any * retdata = PortOutData( FromNodeName , FromParameterName ) ;
699   cdebug_out << "GraphEditor::OutNode::GetOutData " << FromNodeName
700              << " " << FromParameterName << endl ;
701   return retdata ;
702 }
703
704 //bool GraphEditor::OutNode::LinkSaveXML( ostream &f , char *Tabs ,
705 bool GraphEditor::OutNode::LinkSaveXML( QDomDocument & Graph , QDomElement & link ,
706                                         GraphBase::SLink aLink ,
707                                         bool wdata ) const {
708   QDomElement fromnodename = Graph.createElement( "fromnode-name" ) ;
709   QDomText aField ;
710   if ( strlen( aLink.FromNodeName.c_str() ) ) {
711 //    f << Tabs << "<fromnode-name>" << aLink.FromNodeName.c_str()
712 //      << "</fromnode-name>" << endl ;
713     aField = Graph.createTextNode( aLink.FromNodeName.c_str() ) ;
714   }
715   else {
716 //    f << Tabs << "<fromnode-name>?</fromnode-name>" << endl ;
717     aField = Graph.createTextNode( "?" ) ;
718   }
719   link.appendChild( fromnodename ) ;
720   fromnodename.appendChild( aField ) ;
721
722 //  f << Tabs << "<fromserviceparameter-name>"
723 //    << aLink.FromServiceParameterName.c_str() << "</fromserviceparameter-name>"
724 //    << endl ;
725   QDomElement fromserviceparametername = Graph.createElement( "fromserviceparameter-name" ) ;
726   aField = Graph.createTextNode( aLink.FromServiceParameterName.c_str() ) ;
727   link.appendChild( fromserviceparametername ) ;
728   fromserviceparametername.appendChild( aField ) ;
729
730   QDomElement tonodename = Graph.createElement( "tonode-name" ) ;
731   if ( strlen( aLink.ToNodeName.c_str() ) ) {
732 //    f << Tabs << "<tonode-name>" << aLink.ToNodeName.c_str()
733 //      << "</tonode-name>" << endl ;
734     aField = Graph.createTextNode( aLink.ToNodeName.c_str() ) ;
735   }
736   else {
737 //    f << Tabs << "<tonode-name>?</tonode-name>" << endl ;
738     aField = Graph.createTextNode( "?" ) ;
739   }
740   link.appendChild( tonodename ) ;
741   tonodename.appendChild( aField ) ;
742
743 //  f << Tabs << "<toserviceparameter-name>"
744 //    << aLink.ToServiceParameterName.c_str() << "</toserviceparameter-name>"
745 //    << endl ;
746   QDomElement toserviceparametername = Graph.createElement( "toserviceparameter-name" ) ;
747   aField = Graph.createTextNode( aLink.ToServiceParameterName.c_str() ) ;
748   link.appendChild( toserviceparametername ) ;
749   toserviceparametername.appendChild( aField ) ;
750
751   if ( wdata ) {
752 //    f << Tabs << "<data-value>" << endl ;
753     QDomElement datavalue = Graph.createElement( "data-value" ) ;
754     link.appendChild( datavalue ) ;
755 //    f << Tabs << "    <value-type>" << aLink.aLinkValue.type()->kind()
756 //      << "</value-type>" << endl ;
757     QDomElement valuetype = Graph.createElement( "value-type" ) ;
758     QString aKind ;
759     aKind = aKind.setNum( aLink.aLinkValue.type()->kind() ) ;
760     aField = Graph.createTextNode( aKind ) ;
761     datavalue.appendChild( valuetype ) ;
762     valuetype.appendChild( aField ) ;
763     switch (aLink.aLinkValue.type()->kind()) {
764       case CORBA::tk_string: {
765         char* retstr ;
766         aLink.aLinkValue >>= retstr;
767 //        f << Tabs << "        <value>" << retstr << "</value>" << endl ;
768         QDomElement value = Graph.createElement( "value" ) ;
769         aField = Graph.createTextNode( retstr ) ;
770         datavalue.appendChild( value ) ;
771         value.appendChild( aField ) ;
772 //        MESSAGE( "ToString( string ) " << retstr );
773         break ;
774       }
775       case CORBA::tk_double: {
776         double d;
777         aLink.aLinkValue >>= d;
778 //        f << Tabs << "        <value>" << d << "</value>" << endl ;
779         QDomElement value = Graph.createElement( "value" ) ;
780         QString aKind ;
781         aKind = aKind.setNum( d ) ;
782         aField = Graph.createTextNode( aKind ) ;
783         datavalue.appendChild( value ) ;
784         value.appendChild( aField ) ;
785 //        MESSAGE( "ToString( double ) " << d );
786         break ;
787       }
788       case CORBA::tk_long: {
789         long l;
790         aLink.aLinkValue >>= l;
791 //        f << Tabs << "        <value>" << l << "</value>" << endl ;
792         QDomElement value = Graph.createElement( "value" ) ;
793         QString aKind ;
794         aKind = aKind.setNum( l ) ;
795         aField = Graph.createTextNode( aKind ) ;
796         datavalue.appendChild( value ) ;
797         value.appendChild( aField ) ;
798 //        MESSAGE( "ToString( long ) " << l );
799         break ;
800       }
801       case CORBA::tk_objref: {
802         char* retstr ;
803         CORBA::Object_ptr obj ;
804         aLink.aLinkValue >>= obj ;
805         retstr = _Orb->object_to_string(obj );
806 //        f << Tabs << "        <value>" << retstr << "</value>" << endl ;
807         QDomElement value = Graph.createElement( "value" ) ;
808         aField = Graph.createTextNode( retstr ) ;
809         datavalue.appendChild( value ) ;
810         value.appendChild( aField ) ;
811 //        MESSAGE( "ToString( object ) " << retstr );
812         break ;
813       }
814       default: {
815 //        f << Tabs << "        <value>?</value>" << endl ;
816         QDomElement value = Graph.createElement( "value" ) ;
817         aField = Graph.createTextNode( "?" ) ;
818         datavalue.appendChild( value ) ;
819         value.appendChild( aField ) ;
820 //        MESSAGE( "Unknown CORBA::Any Type" );
821         break ;
822       }
823     }
824 //    f << Tabs << "</data-value>" << endl ;
825   }
826 //  f << Tabs << "<coord-list>" << endl ;
827   QDomElement coordlist = Graph.createElement( "coord-list" ) ;
828   link.appendChild( coordlist ) ;
829   
830   int i ;
831   for ( i = 0 ; i < aLink.aListOfCoords.size() ; i++ ) {
832 //    f << Tabs << "    <coord>" << endl ;
833     QDomElement coord = Graph.createElement( "coord" ) ;
834     coordlist.appendChild( coord ) ;
835 //    f << Tabs << "            <x>" << aLink.aListOfCoords[ i ].theX << "</x>" << endl ;
836     QDomElement x = Graph.createElement( "x" ) ;
837     QString ax ;
838     ax = ax.setNum( aLink.aListOfCoords[ i ].theX ) ;
839     aField = Graph.createTextNode( ax ) ;
840     coord.appendChild( x ) ;
841     x.appendChild( aField ) ;    
842 //    f << Tabs << "            <y>" << aLink.aListOfCoords[ i ].theY << "</y>" << endl ;
843     QDomElement y = Graph.createElement( "y" ) ;
844     QString ay ;
845     ay = ay.setNum( aLink.aListOfCoords[ i ].theY ) ;
846     aField = Graph.createTextNode( ay ) ;
847     coord.appendChild( y ) ;
848     y.appendChild( aField ) ;    
849 //    f << Tabs << "    </coord>" << endl ;
850   }
851 //  f << Tabs << "</coord-list>" << endl ;
852   return true ;
853 }
854
855 bool GraphEditor::OutNode::LinkSavePY( ostream &f , const char * aGraphName ,
856                                        GraphBase::SLink aLink ,
857                                        bool intervar , bool wdata ) const {
858   if ( !wdata ) {
859     if ( intervar ) {
860       f << aLink.FromNodeName.c_str() << aLink.FromServiceParameterName.c_str()
861         << " = "
862         << aLink.FromNodeName.c_str() << ".Port( '"
863         << aLink.FromServiceParameterName.c_str()
864         << "' )" << endl ;
865     }
866     f << aLink.ToNodeName.c_str() << aLink.ToServiceParameterName.c_str()
867       << " = " << aGraphName << ".Link( " << aLink.FromNodeName.c_str()
868       << aLink.FromServiceParameterName.c_str() << " , "
869       << aLink.ToNodeName.c_str() << ".Port( '"
870       << aLink.ToServiceParameterName.c_str() << "' ) )" << endl ;
871   }
872   else {
873     f << aLink.ToNodeName.c_str() << aLink.ToServiceParameterName.c_str()
874       << " = " << aLink.ToNodeName.c_str() << ".Input( '"
875       << aLink.ToServiceParameterName.c_str() << "' , " ;
876     switch (aLink.aLinkValue.type()->kind()) {
877       case CORBA::tk_string: {
878         char* retstr ;
879         aLink.aLinkValue >>= retstr;
880         f << "'" << retstr << "'" ;
881         break ;
882       }
883       case CORBA::tk_double: {
884         double d;
885         aLink.aLinkValue >>= d;
886         f << d ;
887         break ;
888       }
889       case CORBA::tk_long: {
890         long l;
891         aLink.aLinkValue >>= l;
892         f << l ;
893         break ;
894       }
895       case CORBA::tk_objref: {
896         char* retstr ;
897         CORBA::Object_ptr obj ;
898         aLink.aLinkValue >>= obj ;
899         retstr = _Orb->object_to_string(obj );
900         f << "'" << retstr << "'" ;
901         break ;
902       }
903       default: {
904         f << "?" ;
905 //        MESSAGE( "Unknown CORBA::Any Type" );
906         break ;
907       }
908     }
909     f << ")" << endl ;
910   }
911   int i ;
912   for ( i = 0 ; i < aLink.aListOfCoords.size() ; i++ ) {
913     f << aLink.ToNodeName.c_str()
914       << aLink.ToServiceParameterName.c_str() << ".AddCoord( " << i+1 << " , "
915       << aLink.aListOfCoords[ i ].theX << " , "
916       << aLink.aListOfCoords[ i ].theY << " )" << endl ;
917   }
918   return true ;
919 }
920
921 //bool GraphEditor::OutNode::SaveXML(ostream & f ) {
922 bool GraphEditor::OutNode::SaveXML(QDomDocument & Graph ) {
923   int i ;
924 //  f << "<?xml version='1.0' encoding='us-ascii' ?>" << endl << endl ;
925 //  f << "<!-- XML Dataflow -->" << endl << endl ;
926 //  f << "<!-- Dataflow information -->" << endl ;
927   QString Dataflow("Dataflow") ;
928   Graph = QDomDocument(Dataflow) ;
929 //  f << "<dataflow>" << endl ;
930   QDomElement dataflow = Graph.createElement( "dataflow" ) ;
931   Graph.appendChild( dataflow ) ;
932 //  f << "      <info-list>" << endl ;
933   QDomElement info = Graph.createElement( "info-list" ) ;
934   dataflow.appendChild( info ) ;
935
936 //  f << "              <node>" << endl ;
937
938 //  GraphBase::DataNode::SaveXML( f , "                 " , 0 , 0 ) ;
939   GraphBase::DataNode::SaveXML( Graph , info , 0 , 0 ) ;
940
941 //  f << "              </node>" << endl ;
942
943 //  f << "      </info-list>" << endl << endl ;
944
945 //  f << "      <node-list>" << endl ;
946   QDomElement nodelist = Graph.createElement( "node-list" ) ;
947   dataflow.appendChild( nodelist ) ;
948   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
949 //      f << "          <node>" << endl ;
950       if ( GraphNodes( i )->IsComputingNode() ) {
951 //        ((GraphBase::ComputingNode *)GraphNodes( i ))->SaveXML( f ,
952 //                    "                 " ,
953         ((GraphBase::ComputingNode *)GraphNodes( i ))->SaveXML( Graph , nodelist ,
954                     GraphNodes( i )->XCoordinate() ,
955                     GraphNodes( i )->YCoordinate() ) ;
956       }
957       else if ( GraphNodes( i )->IsFactoryNode() ) {
958 //        ((GraphBase::FactoryNode * ) GraphNodes( i ))->SaveXML( f ,
959 //                    "                 " ,
960         ((GraphBase::FactoryNode * ) GraphNodes( i ))->SaveXML( Graph , nodelist ,
961                     GraphNodes( i )->XCoordinate() ,
962                     GraphNodes( i )->YCoordinate() ) ;
963       }
964       else if ( GraphNodes( i )->IsInLineNode() ) {
965 //        ((GraphBase::InLineNode * ) GraphNodes( i ))->SaveXML( f ,
966 //                    "                 " ,
967         ((GraphBase::InLineNode * ) GraphNodes( i ))->SaveXML( Graph , nodelist ,
968                     GraphNodes( i )->XCoordinate() ,
969                     GraphNodes( i )->YCoordinate() ) ;
970       }
971       else if ( GraphNodes( i )->IsGOTONode() ) {
972 //        ((GraphBase::GOTONode * ) GraphNodes( i ))->SaveXML( f ,
973 //                    "                 " ,
974         ((GraphBase::GOTONode * ) GraphNodes( i ))->SaveXML( Graph , nodelist ,
975                     GraphNodes( i )->XCoordinate() ,
976                     GraphNodes( i )->YCoordinate() ) ;
977       }
978       else if ( GraphNodes( i )->IsLoopNode() ) {
979 //        ((GraphBase::LoopNode * ) GraphNodes( i ))->SaveXML( f ,
980 //                    "                 " ,
981         ((GraphBase::LoopNode * ) GraphNodes( i ))->SaveXML( Graph , nodelist ,
982                     GraphNodes( i )->XCoordinate() ,
983                     GraphNodes( i )->YCoordinate() ) ;
984       }
985       else if ( GraphNodes( i )->IsEndLoopNode() ) {
986 //        ((GraphBase::EndOfLoopNode * ) GraphNodes( i ))->SaveXML( f ,
987 //                    "                 " ,
988         ((GraphBase::EndOfLoopNode * ) GraphNodes( i ))->SaveXML( Graph , nodelist ,
989                     GraphNodes( i )->XCoordinate() ,
990                     GraphNodes( i )->YCoordinate() ) ;
991       }
992       else if ( GraphNodes( i )->IsSwitchNode() ) {
993 //        ((GraphBase::SwitchNode * ) GraphNodes( i ))->SaveXML( f ,
994 //                    "                 " ,
995         ((GraphBase::SwitchNode * ) GraphNodes( i ))->SaveXML( Graph , nodelist ,
996                     GraphNodes( i )->XCoordinate() ,
997                     GraphNodes( i )->YCoordinate() ) ;
998       }
999       else if ( GraphNodes( i )->IsEndSwitchNode() ) {
1000 //        ((GraphBase::EndOfSwitchNode * ) GraphNodes( i ))->SaveXML( f ,
1001 //                    "                 " ,
1002         ((GraphBase::EndOfSwitchNode * ) GraphNodes( i ))->SaveXML( Graph , nodelist ,
1003                     GraphNodes( i )->XCoordinate() ,
1004                     GraphNodes( i )->YCoordinate() ) ;
1005       }
1006 //      f << "          </node>" << endl ;
1007 //    }
1008   }
1009 //  f << "      </node-list>" << endl << endl ;
1010
1011 //  f << "      <link-list>" << endl ;
1012   QDomElement linklist = Graph.createElement( "link-list" ) ;
1013   dataflow.appendChild( linklist ) ;
1014   const GraphBase::ListOfLinks * Links = GetLinks() ;
1015   for ( i = 0 ; i < Links->size() ; i++ ) {
1016 //    f << "            <link>" << endl ;
1017     QDomElement link = Graph.createElement( "link" ) ;
1018     linklist.appendChild( link ) ;
1019 //    LinkSaveXML( f , "                        " , (*Links)[ i ] , false ) ;
1020     LinkSaveXML( Graph , link , (*Links)[ i ] , false ) ;
1021 //    f << "            </link>" << endl ;
1022   }
1023 //  f << "      </link-list>" << endl << endl ;
1024
1025 //  f << "      <data-list>" << endl ;
1026   QDomElement datalist = Graph.createElement( "data-list" ) ;
1027   dataflow.appendChild( datalist ) ;
1028   const GraphBase::ListOfLinks * Datas = GetDatas() ;
1029   for ( i = 0 ; i < Datas->size() ; i++ ) {
1030 //    f << "            <data>" << endl ;
1031     QDomElement data = Graph.createElement( "data" ) ;
1032     datalist.appendChild( data ) ;
1033 //    LinkSaveXML( f , "                        " , (*Datas)[ i ] , true ) ;
1034     LinkSaveXML( Graph , data , (*Datas)[ i ] , true ) ;
1035 //    f << "            </data>" << endl ;
1036   }
1037 //#if 0
1038 //  const GraphEditor::OutNode * aDataNode = (GraphEditor::OutNode *) this ;
1039 //  if ( aDataNode ) {
1040 //    int i ;
1041 //    for ( i = 0 ; i < aDataNode->GetNodeOutPortsSize() ; i++ ) {
1042 //      const GraphBase::InPort *aLink = aDataNode->GetNodeOutPort(i)->GetLink() ;
1043 //      if ( aLink ) {
1044 //        f << "                <data>" << endl ;
1045 //        aLink->SaveXML( f , "                 " ) ;
1046 //        f << "                </data>" << endl ;
1047 //      }
1048 //    }
1049 //    for ( i = 0 ; i < aDataNode->GetNodeInPortsSize() ; i++ ) {
1050 //      const GraphBase::InPort *aLink = aDataNode->GetNodeInPort(i)->GetLink() ;
1051 //      if ( aLink ) {
1052 //        f << "                <data>" << endl ;
1053 //        aLink->SaveXML( f , "                 " ) ;
1054 //        f << "                </data>" << endl ;
1055 //      }
1056 //    }
1057 //  }
1058 //#endif
1059
1060 #if 0
1061   f << "        </data-list>" << endl << endl ;
1062   f << "</dataflow>" << endl ;
1063 #endif
1064
1065   return true ;
1066 }
1067
1068 bool GraphEditor::OutNode::SavePY( ostream & f ) {
1069   int i ;
1070   f << endl << "# Generated python file of Graph " << Name() << endl << endl ;
1071
1072   f << "from SuperV import *" << endl ;
1073
1074   f << "# Graph creation " << endl ;
1075   GraphBase::DataNode::SavePY( f , Name() , 0 , 0 ) ;
1076
1077   f << endl << "# Creation of Factory Nodes" << endl ;
1078   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1079     if ( GraphNodes( i )->IsFactoryNode() ) {
1080       ((GraphBase::FactoryNode * ) GraphNodes( i ))->SavePY( f , Name() ,
1081                 GraphNodes( i )->XCoordinate() ,
1082                 GraphNodes( i )->YCoordinate() ) ;
1083     }
1084   }
1085
1086   bool first = true ;
1087   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1088     if ( GraphNodes( i )->IsComputingNode() ) {
1089       if ( first ) {
1090         f << endl << "# Creation of Computing Nodes" << endl ;
1091         first = false ;
1092       }
1093       ((GraphBase::ComputingNode * ) GraphNodes( i ))->SavePY( f , Name() ,
1094                 GraphNodes( i )->XCoordinate() ,
1095                 GraphNodes( i )->YCoordinate() ) ;
1096     }
1097   }
1098
1099   first = true ;
1100   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1101     if ( GraphNodes( i )->IsInLineNode() ) {
1102       if ( first ) {
1103         f << endl << "# Creation of InLine Nodes" << endl ;
1104         first = false ;
1105       }
1106       ((GraphBase::InLineNode * ) GraphNodes( i ))->SavePY( f , Name() ,
1107                 GraphNodes( i )->XCoordinate() ,
1108                 GraphNodes( i )->YCoordinate() ) ;
1109     }
1110   }
1111
1112   first = true ;
1113   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1114     if ( GraphNodes( i )->IsLoopNode() ) {
1115       if ( first ) {
1116         f << endl << "# Creation of Loop Nodes" << endl ;
1117         first = false ;
1118       }
1119       ((GraphBase::LoopNode * ) GraphNodes( i ))->SavePY( f , Name() ,
1120                 GraphNodes( i )->XCoordinate() ,
1121                 GraphNodes( i )->YCoordinate() ) ;
1122     }
1123   }
1124
1125   first = true ;
1126   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1127     if ( GraphNodes( i )->IsSwitchNode() ) {
1128       if ( first ) {
1129         f << endl << "# Creation of Switch Nodes" << endl ;
1130         first = false ;
1131       }
1132       ((GraphBase::SwitchNode * ) GraphNodes( i ))->SavePY( f , Name() ,
1133                 GraphNodes( i )->XCoordinate() ,
1134                 GraphNodes( i )->YCoordinate() ) ;
1135     }
1136   }
1137
1138   first = true ;
1139   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1140     if ( GraphNodes( i )->IsGOTONode() ) {
1141       if ( first ) {
1142         f << endl << "# Creation of GOTO Nodes" << endl ;
1143         first = false ;
1144       }
1145       ((GraphBase::GOTONode * ) GraphNodes( i ))->SavePY( f , Name() ,
1146                 GraphNodes( i )->XCoordinate() ,
1147                 GraphNodes( i )->YCoordinate() ) ;
1148     }
1149   }
1150
1151   const GraphBase::ListOfLinks * Links = GetLinks() ;
1152   bool intervar ;
1153   map< string , int > aMapOfOutPorts ;
1154   first = true ;
1155   for ( i = 0 ; i < Links->size() ; i++ ) {
1156     if ( GetGraphNode( (*Links)[ i ].FromNodeName.c_str() )->IsComputingNode() &&
1157          GetGraphNode( (*Links)[ i ].ToNodeName.c_str() )->IsComputingNode() ) {
1158       if ( first ) {
1159         f << endl
1160           << "# Creation of intermediate Output variables and of Computing Links"
1161           << endl ;
1162         first = false ;
1163       }
1164       char * NodePort = new char [ strlen( (*Links)[ i ].FromNodeName.c_str() ) +
1165                                    strlen( (*Links)[ i ].FromServiceParameterName.c_str() ) + 1 ] ;
1166       strcpy( NodePort , (*Links)[ i ].FromNodeName.c_str() ) ;
1167       strcat( NodePort , (*Links)[ i ].FromServiceParameterName.c_str() ) ;
1168       if ( aMapOfOutPorts[ NodePort ] == 0 ) {
1169         aMapOfOutPorts[ NodePort ] = i + 1 ;
1170         intervar = true ;
1171       }
1172       else {
1173         intervar = false ;
1174       }
1175       LinkSavePY( f , Name() , (*Links)[ i ] , intervar , false ) ;
1176       delete [] NodePort ;
1177     }
1178   }
1179
1180 #if 0
1181   first = true ;
1182   for ( i = 0 ; i < GraphNodesSize() ; i++ ) {
1183     if ( GraphNodes( i )->IsInLineNode() ||
1184          GraphNodes( i )->IsGOTONode() ) {
1185       int j ;
1186       for ( j = 0 ; j < GraphNodes( i )->GetNodeInPortsSize() ; j++ ) {
1187         if ( GraphNodes( i )->GetNodeInPort( j )->IsBus() ) {
1188           if ( first ) {
1189             f << endl
1190               << "# Creation of Output variables and of Bus Ports"
1191               << endl ;
1192             first = false ;
1193           }
1194           f << GraphNodes( i )->Name() << ".InOutPort( '"
1195             << GraphNodes( i )->GetNodeInPort( j )->PortName() << "' , '"
1196             << GraphNodes( i )->GetNodeInPort( j )->PortType() << "' , '"
1197             << GraphNodes( i )->GetNodeOutPort( GraphNodes( i )->GetNodeInPort( j )->PortIndex() )->PortName()
1198             << "' , '"
1199             << GraphNodes( i )->GetNodeOutPort( GraphNodes( i )->GetNodeInPort( j )->PortIndex() )->PortType()
1200             << "' )" << endl ;
1201         }
1202       }
1203     }
1204   }
1205 #endif
1206
1207   first = true ;
1208   for ( i = 0 ; i < Links->size() ; i++ ) {
1209     if ( !( GetGraphNode( (*Links)[ i ].FromNodeName.c_str() )->IsComputingNode() &&
1210            GetGraphNode( (*Links)[ i ].ToNodeName.c_str() )->IsComputingNode() ) &&
1211          !( GetGraphNode( (*Links)[ i ].FromNodeName.c_str() )->IsGOTONode() &&
1212            GetGraphNode( (*Links)[ i ].ToNodeName.c_str() )->IsInLineNode() ) ) {
1213       if ( first ) {
1214         f << endl
1215           << "# Creation of intermediate Output variables and of Control Links"
1216           << endl ;
1217         first = false ;
1218       }
1219       char * NodePort = new char [ strlen( (*Links)[ i ].FromNodeName.c_str() ) +
1220                                    strlen( (*Links)[ i ].FromServiceParameterName.c_str() ) + 1 ] ;
1221       strcpy( NodePort , (*Links)[ i ].FromNodeName.c_str() ) ;
1222       strcat( NodePort , (*Links)[ i ].FromServiceParameterName.c_str() ) ;
1223       if ( aMapOfOutPorts[ NodePort ] == 0 ) {
1224         aMapOfOutPorts[ NodePort ] = i + 1 ;
1225         intervar = true ;
1226       }
1227       else {
1228         intervar = false ;
1229       }
1230       LinkSavePY( f , Name() , (*Links)[ i ] , intervar , false ) ;
1231       delete [] NodePort ;
1232     }
1233   }
1234
1235   first = true ;
1236   for ( i = 0 ; i < Links->size() ; i++ ) {
1237     if ( GetGraphNode( (*Links)[ i ].FromNodeName.c_str() )->IsGOTONode() &&
1238          GetGraphNode( (*Links)[ i ].ToNodeName.c_str() )->IsInLineNode() ) {
1239       if ( first ) {
1240         f << endl
1241           << "# Creation of intermediate Output variables and of Loop Links"
1242           << endl ;
1243         first = false ;
1244       }
1245       char * NodePort = new char [ strlen( (*Links)[ i ].FromNodeName.c_str() ) +
1246                                    strlen( (*Links)[ i ].FromServiceParameterName.c_str() ) + 1 ] ;
1247       strcpy( NodePort , (*Links)[ i ].FromNodeName.c_str() ) ;
1248       strcat( NodePort , (*Links)[ i ].FromServiceParameterName.c_str() ) ;
1249       if ( aMapOfOutPorts[ NodePort ] == 0 ) {
1250         aMapOfOutPorts[ NodePort ] = i + 1 ;
1251         intervar = true ;
1252       }
1253       else {
1254         intervar = false ;
1255       }
1256       LinkSavePY( f , Name() , (*Links)[ i ] , intervar , false ) ;
1257       delete [] NodePort ;
1258     }
1259   }
1260
1261   const GraphBase::ListOfLinks * Datas = GetDatas() ;
1262   first = true ;
1263   for ( i = 0 ; i < Datas->size() ; i++ ) {
1264     if ( first ) {
1265       f << endl << "# Creation of Input datas" << endl ;
1266       first = false ;
1267     }
1268     LinkSavePY( f , Name() , (*Datas)[ i ] , false , true ) ;
1269   }
1270
1271   first = true ;
1272   const SALOME_ModuleCatalog::ListOfServicesParameter ListOfInParam = ServiceInParameter() ;
1273   for ( i = 0 ; i < ListOfInParam.length() ; i++ ) {
1274     string _aParam = CORBA::string_dup(ListOfInParam[ i ].Parametername) ;
1275     const char * aParam = _aParam.c_str() ;
1276     char * aNodeName ;
1277     char * aPortName ;
1278     int j , k ;
1279     for ( j = 0 ; j < strlen( aParam ) ; j++ ) {
1280       if ( aParam[ j ] == '\\' ) {
1281         aNodeName = new char[ j+1 ] ;
1282         strncpy( aNodeName , aParam , j ) ;
1283         aNodeName[ j ] = '\0' ;
1284         aPortName = new char[ strlen( aParam ) - j ] ;
1285         strncpy( aPortName , &aParam[ j+1 ] , strlen( aParam ) - j ) ;
1286         break ;
1287       }
1288     }
1289     if ( !GetChangeGraphNode( aNodeName )->GetInPort( aPortName )->IsDataConnected() ) {
1290       if ( first ) {
1291         f << endl << "# Missing Input datas" << endl ;
1292         first = false ;
1293       }
1294       f << aNodeName << aPortName << " = " << aNodeName << ".Port( '"
1295         << aPortName << "' )" << endl ;
1296     }
1297     delete [] aNodeName ;
1298     delete [] aPortName ;
1299   }
1300
1301   f << endl << "# Creation of Output variables" << endl ;
1302   const SALOME_ModuleCatalog::ListOfServicesParameter ListOfOutParam = ServiceOutParameter() ;
1303   for ( i = 0 ; i < ListOfOutParam.length() ; i++ ) {
1304     string _aParam = CORBA::string_dup(ListOfOutParam[ i ].Parametername) ;
1305     const char * aParam = _aParam.c_str() ;
1306     char * aNodeName ;
1307     char * aPortName ;
1308     int j , k ;
1309     for ( j = 0 ; j < strlen( aParam ) ; j++ ) {
1310       if ( aParam[ j ] == '\\' ) {
1311         aNodeName = new char[ j+1 ] ;
1312         strncpy( aNodeName , aParam , j ) ;
1313         aNodeName[ j ] = '\0' ;
1314         aPortName = new char[ strlen( aParam ) - j ] ;
1315         strncpy( aPortName , &aParam[ j+1 ] , strlen( aParam ) - j ) ;
1316         break ;
1317       }
1318     }
1319     f << aNodeName << aPortName << " = " << aNodeName << ".Port( '"
1320       << aPortName << "' )" << endl ;
1321     delete [] aNodeName ;
1322     delete [] aPortName ;
1323   }
1324   return true ;
1325 }
1326
1327
1328
1329 ostrstream & operator<< (ostrstream & f,const GraphEditor::OutNode & G) {
1330   f << (GraphBase::ComputingNode ) G ;
1331   f << endl ;
1332
1333   f << "  Nodes : " << G.GraphNodesSize() << " node" 
1334     << (G.GraphNodesSize() > 1 ? "s" : "") << endl;
1335   
1336   int i ;
1337   for ( i = 0 ; i < G.GraphNodesSize() ; i++ ) {
1338     f
1339 //      << hex << (void *) G.GraphNodes( i ) << dec << " "
1340       << *G.GraphNodes( i ) << endl;
1341   }
1342
1343   f << "  Links : " << endl ;
1344   for ( i = 0 ; i < G.GraphNodesSize() ; i++ ) {
1345     G.GraphNodes( i )->ListLinks( f ) ;
1346   }
1347
1348   f << "  Datas : " << endl ;
1349   G.ListDatas( f ) ;
1350
1351   f << "DataFlow " << G.Name() << " is " ;
1352   if ( G.IsNotValid() )
1353     f << "not " ;
1354   f << "valid and is " ;
1355   if ( G.IsNotExecutable() )
1356     f << "not " ;
1357   f << "executable." << endl ;
1358
1359   f << endl ;
1360   
1361   return f;
1362 }
1363
1364 ostream & operator<< (ostream &fOut,const SUPERV::SDate &D)
1365 {
1366 //  cdebug_in << "operator<< GraphEditor::Date" << endl;
1367
1368   fOut  << D.Day << "/" 
1369         << D.Month << "/" 
1370         << D.Year << " - " 
1371         << D.Hour << ":" 
1372         << D.Minute <<  ":"  
1373         << D.Second;
1374
1375 //  cdebug_out << "operator<< GraphEditor::Date" << endl;
1376   return fOut;
1377 }
1378
1379
1380
1381
1382
1383
1384
1385