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