Salome HOME
*** empty log message ***
[modules/superv.git] / src / GraphEditor / DataFlowEditor_DataFlow.lxx
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_DataFlow.lxx
25 //  Module : SUPERV
26
27 #ifndef _DATAFLOWEDITOR_DATAFLOW_LXX
28 #define _DATAFLOWEDITOR_DATAFLOW_LXX
29
30 #include "DataFlowEditor_OutNode.hxx"
31
32 inline void GraphEditor::DataFlow::ReadOnly() {
33   _ReadOnly = true ;
34 }
35
36 inline char * GraphEditor::DataFlow::DataFlowInfo() {
37   ostringstream s;
38   IsValid() ;
39   GraphEditor::DataFlow::DataFlow aDataFlow = *this ;
40   s << aDataFlow << ends ;
41   return CORBA::string_dup( s.str().c_str() );
42 }
43
44 inline char * GraphEditor::DataFlow::DataNodeInfo() {
45   ostringstream s;
46   IsValid() ;
47   Graph()->DataNodeInfo( s ) ;
48   return CORBA::string_dup( s.str().c_str() );
49 }
50
51 inline char * GraphEditor::DataFlow::NodeInfo( const char * aNodeName ) {
52   ostringstream s;
53   if ( Graph()->GetGraphNode( aNodeName ) )
54     Graph()->GetGraphNode( aNodeName )->NodeInfo( s ) ;
55   else
56     s << aNodeName << " not found" << ends ;
57   return CORBA::string_dup( s.str().c_str() );
58 }
59
60 inline bool GraphEditor::DataFlow::LoadDataFlow( const GraphBase::SGraph *aDataFlow ) {
61   if ( _ReadOnly )
62     return false ;
63   _EditedAfterExecution = true ;
64   return GraphEditor::OutNode::LoadDataFlow( aDataFlow ) ; 
65 } ;
66
67 inline bool GraphEditor::DataFlow::LoadXml( const char* myFileName ) {
68   if ( _ReadOnly )
69     return false ;
70   _EditedAfterExecution = true ;
71   return GraphEditor::OutNode::LoadXml( myFileName ) ; 
72 } ;
73
74 inline bool GraphEditor::DataFlow::LoadInfo( const GraphBase::SNode &aDataFlowInfo ) {
75   if ( _ReadOnly )
76     return false ;
77   _EditedAfterExecution = true ;
78   return GraphEditor::OutNode::LoadInfo( aDataFlowInfo ) ; 
79 } ;
80
81 inline bool GraphEditor::DataFlow::SaveXml(const char* myFileName ) {
82   return GraphEditor::OutNode::SaveXml( myFileName ) ; 
83 } ;
84
85 inline bool GraphEditor::DataFlow::SavePy(const char* myFileName ) {
86   return GraphEditor::OutNode::SavePy( myFileName ) ; 
87 } ;
88
89 // get all DataFlow informations (for a .XML file) :
90 inline GraphBase::SGraph * GraphEditor::DataFlow::GetDataFlow() {
91    return GraphEditor::OutNode::GetDataFlow() ; 
92 } ;
93
94 //    void DateModification() ;
95
96 //inline GraphBase::SNode * GraphEditor::DataFlow::GetInfo() const {
97 //   return GraphEditor::OutNode::GetInfo() ; 
98 //} ;
99
100 inline GraphBase::ListOfNodes * GraphEditor::DataFlow::GetNodes() const {
101    return Graph()->GetNodes() ; 
102 } ;
103
104 inline GraphBase::ListOfLinks * GraphEditor::DataFlow::GetLinks() const {
105    return Graph()->GetLinks() ; 
106 } ;
107
108 inline GraphBase::ListOfGraphs * GraphEditor::DataFlow::GetGraphs() const {
109    return Graph()->GetGraphs() ; 
110 } ;
111
112 inline GraphBase::ListOfLinks * GraphEditor::DataFlow::GetDatas() const {
113    return Graph()->GetDatas() ; 
114 } ;
115
116 inline const SALOME_ModuleCatalog::Service * GraphEditor::DataFlow::GetService() {
117    IsValid() ;
118    return Graph()->GetService() ; 
119 } ;
120
121 inline GraphEditor::InNode * GraphEditor::DataFlow::AddNode(
122                       const SALOME_ModuleCatalog::Service& NodeService ,
123                       const char* NodeComponentName ,
124                       const char* NodeInterfaceName ,
125                       const char* NodeName,
126                       const SUPERV::KindOfNode NodeKindOfNode,
127                       GraphBase::ListOfFuncName aFuncName ,
128                       GraphBase::ListOfPythonFunctions aPythonFunction ,
129                       const SUPERV::SDate NodeFirstCreation,
130                       const SUPERV::SDate NodeLastModification,
131                       const char * NodeEditorRelease,
132                       const char * NodeAuthor,
133                       const char * NodeComputer,
134                       const char * NodeComment,
135                       const int NodeX,
136                       const int NodeY) {
137   if ( NodeName != NULLSTRING && strlen( NodeName ) ) {
138 //    MESSAGE( "--> GraphEditor::DataFlow::AddNode( " << NodeName << " )" ) ;
139 //    cout << "--> GraphEditor::DataFlow::AddNode( " << NodeName << " )" << endl ;
140     cdebug_in << "GraphEditor::DataFlow::AddNode( " << NodeName << " )" << endl ;
141   }
142   else {
143 //    MESSAGE( "--> GraphEditor::DataFlow::AddNode( NULL )" ) ;
144 //    cout << "--> GraphEditor::DataFlow::AddNode( NULL )" << endl ;
145     NodeName = NULLSTRING ;
146     cdebug_in << "GraphEditor::DataFlow::AddNode( NULL )" << endl ;
147   }
148   if ( _ReadOnly ) {
149     return (GraphEditor::InNode * ) NULL ;
150   }
151   _EditedAfterExecution = true ;
152   GraphEditor::InNode * aNode = GraphEditor::OutNode::AddNode( NodeService ,
153                                         aFuncName , aPythonFunction ,
154                                         NodeComponentName ,
155                                         NodeInterfaceName ,
156                                         NodeName , NodeKindOfNode ,
157                                         NodeFirstCreation ,
158                                         NodeLastModification ,
159                                         NodeEditorRelease ,
160                                         NodeAuthor , NodeComputer ,
161                                         NodeComment , NodeX , NodeY ) ;
162 //  MESSAGE( "<-- GraphEditor::DataFlow::AddNode( " << aNode->Name() << " )" ) ;
163 //  cout << "<-- GraphEditor::DataFlow::AddNode( " << aNode->Name() << " )" << endl ;
164   cdebug_out << "GraphEditor::DataFlow::AddNode( " << aNode->Name() << " )" << endl ;
165   return aNode ;
166 } ;
167
168 inline GraphEditor::InNode * GraphEditor::DataFlow::GetNode( const char* NodeName ) {
169   return GraphEditor::OutNode::GetNode( NodeName ) ; 
170 } ;
171
172 inline bool GraphEditor::DataFlow::RemoveNode( const char* NodeName ) {
173   if ( _ReadOnly ) {
174     return false ;
175   }
176   _EditedAfterExecution = true ;
177   return GraphEditor::OutNode::RemoveNode( NodeName ) ; 
178 } ;
179
180 inline bool GraphEditor::DataFlow::ReNameNode( const char* OldNodeName ,
181                                                const char* NewNodeName ) {
182   if ( _ReadOnly ) {
183     return false ;
184   }
185   _EditedAfterExecution = true ;
186   return GraphEditor::OutNode::ReNameNode( OldNodeName , NewNodeName ) ; 
187 } ;
188
189 inline const SALOME_ModuleCatalog::Service * GraphEditor::DataFlow::NodeService(
190                                              const char * aNodeName ) {
191   if ( Graph()->GetGraphNode( aNodeName ) ) {
192     return Graph()->GetGraphNode( aNodeName )->GetService() ;
193   }
194   return NULL ;
195 }
196
197 inline void GraphEditor::DataFlow::Coordinates( const int X , const int Y ) {
198   _EditedAfterExecution = true ;
199   return GraphEditor::OutNode::Coordinates( X , Y ) ; 
200 } ;
201
202 inline const int GraphEditor::DataFlow::XCoordinate() {
203    return GraphEditor::OutNode::XCoordinate() ; 
204 } ;
205
206 inline const int GraphEditor::DataFlow::YCoordinate() {
207    return GraphEditor::OutNode::YCoordinate() ; 
208 } ;
209
210 inline void GraphEditor::DataFlow::Coordinates( const char* NodeName ,
211                                                 const int X , const int Y ) {
212   return GraphEditor::OutNode::Coordinates( NodeName , X , Y ) ; 
213 } ;
214
215 inline const int GraphEditor::DataFlow::XCoordinate( const char* NodeName ) {
216    return GraphEditor::OutNode::XCoordinate( NodeName ) ; 
217 } ;
218
219 inline const int GraphEditor::DataFlow::YCoordinate( const char* NodeName ) {
220    return GraphEditor::OutNode::YCoordinate( NodeName ) ; 
221 } ;
222
223 inline const GraphBase::InPort *GraphEditor::DataFlow::GetInPort( const char *name ) {
224   return GraphEditor::OutNode::GetInPort( name ) ; 
225 }
226 inline const GraphBase::OutPort *GraphEditor::DataFlow::GetOutPort( const char *name ) {
227   return GraphEditor::OutNode::GetOutPort( name ) ; 
228 }
229 inline GraphBase::InPort *GraphEditor::DataFlow::GetChangeInPort( const char *name ) {
230   return GraphEditor::OutNode::GetChangeInPort( name ) ; 
231 }
232 inline GraphBase::OutPort *GraphEditor::DataFlow::GetChangeOutPort( const char *name ) {
233   return GraphEditor::OutNode::GetChangeOutPort( name ) ; 
234 }
235
236 inline bool GraphEditor::DataFlow::HasInput(const char * ToServiceParameterName ) {
237   return GraphEditor::OutNode::HasInput( ToServiceParameterName ) ;
238 }
239
240 inline bool GraphEditor::DataFlow::AddLink( const char* FromNodeName ,
241                                             const char* FromServiceParameterName ,
242                                             const char* ToNodeName ,
243                                             const char* ToServiceParameterName ,
244                                             const CORBA::Any aValue ) {
245   if ( !_ReadOnly ) {
246     GraphEditor::InNode * aFromNode = GetNode( FromNodeName ) ;
247     if ( aFromNode ) {
248       GraphBase::OutPort * anOutPort = aFromNode->GetChangeOutPort( FromServiceParameterName ) ;
249       if ( anOutPort ) {
250         CORBA::Any const * theValue = anOutPort->Value() ; // Keep the type !
251         _EditedAfterExecution = true ;
252         return GraphEditor::OutNode::AddLink( FromNodeName ,
253                                               FromServiceParameterName ,
254                                               ToNodeName ,
255                                               ToServiceParameterName ,
256                                               *theValue ) ;
257       }
258     }
259   }
260   return false ;
261 } ;
262
263 inline bool GraphEditor::DataFlow::GetLink(const char* ToNodeName ,
264                                            const char* ToServiceParameterName ,
265                                            char** FromNodeName ,
266                                            char** FromServiceParameterName ) {
267   return GraphEditor::OutNode::GetLink( ToNodeName , ToServiceParameterName ,
268                                         FromNodeName ,
269                                         FromServiceParameterName ) ;
270 }
271
272 inline GraphBase::SLink * GraphEditor::DataFlow::GetLink(
273                                  GraphBase::ComputingNode * aNode ,
274                                  const char* ToServiceParameterName ) {
275   return Graph()->GetLink( aNode , aNode->GetChangeInPort( ToServiceParameterName ) ) ;
276 }
277
278 inline bool GraphEditor::DataFlow::AddLinkCoord(
279                          const char* FromNodeName ,
280                          const char* FromServiceParameterName ,
281                          const char* ToNodeName ,
282                          const char* ToServiceParameterName ,
283                          const int nXY ,
284                          const int* X ,
285                          const int* Y ) {
286   _EditedAfterExecution = true ;
287   return GraphEditor::OutNode::AddLinkCoord( FromNodeName ,
288                                              FromServiceParameterName ,
289                                              ToNodeName ,
290                                              ToServiceParameterName ,
291                                              nXY , X , Y ) ; 
292 } ;
293
294 inline bool GraphEditor::DataFlow::AddLinkCoord(
295                          const char* FromNodeName ,
296                          const char* FromServiceParameterName ,
297                          const char* ToNodeName ,
298                          const char* ToServiceParameterName ,
299                          const int index ,
300                          const int X ,
301                          const int Y ) {
302   _EditedAfterExecution = true ;
303   return GraphEditor::OutNode::AddLinkCoord( FromNodeName ,
304                                              FromServiceParameterName ,
305                                              ToNodeName ,
306                                              ToServiceParameterName ,
307                                              index , X , Y ) ; 
308 } ;
309
310 inline bool GraphEditor::DataFlow::ChangeLinkCoord(
311                          const char* FromNodeName ,
312                          const char* FromServiceParameterName ,
313                          const char* ToNodeName ,
314                          const char* ToServiceParameterName ,
315                          const int index ,
316                          const int X ,
317                          const int Y ) {
318   _EditedAfterExecution = true ;
319   return GraphEditor::OutNode::ChangeLinkCoord( FromNodeName ,
320                                                 FromServiceParameterName ,
321                                                 ToNodeName ,
322                                                 ToServiceParameterName ,
323                                                 index , X , Y ) ; 
324 } ;
325
326 inline bool GraphEditor::DataFlow::RemoveLinkCoord(
327                          const char* FromNodeName ,
328                          const char* FromServiceParameterName ,
329                          const char* ToNodeName ,
330                          const char* ToServiceParameterName ,
331                          const int index ) {
332   _EditedAfterExecution = true ;
333   return GraphEditor::OutNode::RemoveLinkCoord( FromNodeName ,
334                                                 FromServiceParameterName ,
335                                                 ToNodeName ,
336                                                 ToServiceParameterName ,
337                                                 index ) ; 
338 } ;
339
340 inline int GraphEditor::DataFlow::GetLinkCoordSize(
341                          const char* FromNodeName ,
342                          const char* FromServiceParameterName ,
343                          const char* ToNodeName ,
344                          const char* ToServiceParameterName ) {
345   return GraphEditor::OutNode::GetLinkCoordSize( FromNodeName ,
346                                                  FromServiceParameterName ,
347                                                  ToNodeName ,
348                                                  ToServiceParameterName ) ; 
349 } ;
350
351 inline bool GraphEditor::DataFlow::GetLinkCoord(
352                          const char* FromNodeName ,
353                          const char* FromServiceParameterName ,
354                          const char* ToNodeName ,
355                          const char* ToServiceParameterName ,
356                          int *X , int *Y ) {
357   return GraphEditor::OutNode::GetLinkCoord( FromNodeName ,
358                                              FromServiceParameterName ,
359                                              ToNodeName ,
360                                              ToServiceParameterName ,
361                                              X , Y ) ; 
362 } ;
363
364 inline bool GraphEditor::DataFlow::GetLinkCoord(
365                          const char* FromNodeName ,
366                          const char* FromServiceParameterName ,
367                          const char* ToNodeName ,
368                          const char* ToServiceParameterName ,
369                          const int index , long &X , long &Y ) {
370   return GraphEditor::OutNode::GetLinkCoord( FromNodeName ,
371                                              FromServiceParameterName ,
372                                              ToNodeName ,
373                                              ToServiceParameterName ,
374                                              index , X , Y ) ; 
375 } ;
376
377 inline bool GraphEditor::DataFlow::RemoveLink(
378                          const char* FromNodeName ,
379                          const char* FromServiceParameterName ,
380                          const char* ToNodeName ,
381                          const char* ToServiceParameterName ) {
382   if ( _ReadOnly ) {
383     return false ;
384   }
385   _EditedAfterExecution = true ;
386   return GraphEditor::OutNode::RemoveLink( FromNodeName ,
387                                            FromServiceParameterName ,
388                                            ToNodeName ,
389                                            ToServiceParameterName ) ; 
390 } ;
391
392 inline bool GraphEditor::DataFlow::AddInputData( const char* ToNodeName ,
393                                                  const char* ToParameterName ,
394                                                  const CORBA::Any aValue ) {
395 #if 0
396   GraphBase::Node *toNode ;
397   GraphBase::InPort *toPort ;
398   char *aNode ;
399   char *aPort ;
400   NodePort( ToNodeName , ToParameterName , &aNode , &aPort ) ;
401   toNode = GetChangeGraphNode( aNode ) ;
402   if ( toNode ) {
403     toPort = toNode->GetChangeInPort( aPort ) ;
404     if ( toPort && ( toPort->IsConnected() ||
405                      toPort->IsDataConnected() ) ) {
406       RemoveLink( toNode->Name() , toPort->PortName() ) ;
407     }
408   }
409   else {
410     toPort = NULL ;
411   }
412   delete aNode ;
413   delete aPort ;
414 #endif
415   if ( !IsValid() ) {
416     return false ;
417   }
418   return Graph()->AddInputData( ToNodeName , ToParameterName , aValue ) ; 
419 } ;
420
421 inline bool GraphEditor::DataFlow::AddInputSharedData(const char* ToNodeName1 ,
422                                                       const char* ToParameterName1 ,
423                                                       const char* ToNodeName2 ,
424                                                       const char* ToParameterName2 ) {
425   if ( !IsValid() ) {
426     return false ;
427   }
428   return GraphEditor::OutNode::AddInputData( ToNodeName1 , ToParameterName1 ,
429                                              ToNodeName2 , ToParameterName2 ) ;
430 } ;
431
432 inline const CORBA::Any *GraphEditor::DataFlow::GetInData(
433                                    const char * ToNodeName ,
434                                    const char * ToParameterName ) {
435   return GraphEditor::OutNode::GetInData( ToNodeName ,
436                                           ToParameterName ) ;
437 }
438 inline const CORBA::Any *GraphEditor::DataFlow::GetOutData(
439                                    const char * FromNodeName ,
440                                    const char * FromParameterName ) {
441   return GraphEditor::OutNode::GetOutData( FromNodeName ,
442                                            FromParameterName ) ;
443 }
444
445 inline bool GraphEditor::DataFlow::IsValid() {
446   return GraphEditor::OutNode::IsValid() ;
447 }
448
449 inline bool GraphEditor::DataFlow::IsExecutable() {
450   return GraphEditor::OutNode::IsExecutable() ;
451 }
452
453 inline bool GraphEditor::DataFlow::IsExecuting() {
454   if ( _DataFlowExecutor ) {
455     if ( _DataFlowExecutor->IsDone() ) {
456       _Executing = false ;
457     }
458     else {
459     _Executing = true ;
460     }
461   }
462   else {
463     _Executing = false ;
464   }
465   return _Executing ;
466 }
467
468 inline bool GraphEditor::DataFlow::IsEditing() {
469   return !IsExecuting() ;
470 }
471
472 inline void GraphEditor::DataFlow::EditedAfterExecution(bool EditedAfterExecution ) {
473   _EditedAfterExecution = EditedAfterExecution ;
474 }
475
476 inline bool GraphEditor::DataFlow::EditedAfterExecution() {
477   return _EditedAfterExecution ;
478 }
479
480 inline bool GraphEditor::DataFlow::IsReadOnly() {
481   return _ReadOnly ;
482 }
483
484 inline long GraphEditor::DataFlow::LevelMax() {
485   if ( !IsValid() ) {
486     return 0 ;
487   }
488   return Graph()->LevelMax() ;
489 }
490
491 inline SUPERV::ListOfStrings * GraphEditor::DataFlow::LevelNodes(long aLevel ) {
492   if ( !IsValid() ) {
493     return ((SUPERV::ListOfStrings * ) NULL ) ;
494   }
495   return Graph()->LevelNodes( aLevel ) ;
496 }
497
498 inline long GraphEditor::DataFlow::ThreadsMax() {
499   if ( !IsValid() ) {
500     return 0 ;
501   }
502   return Graph()->ThreadsMax() ;
503 }
504
505 inline long GraphEditor::DataFlow::SubGraphsNumber() {
506   if ( !IsValid() ) {
507     return 0 ;
508   }
509   return Graph()->SubGraphsNumber() ;
510 }
511
512 inline long GraphEditor::DataFlow::SubStreamGraphsNumber() {
513   if ( !IsValid() ) {
514     return 0 ;
515   }
516   return StreamGraph()->SubStreamGraphsNumber() ;
517 }
518
519 inline void GraphEditor::DataFlow::Executor(
520                                GraphExecutor::DataFlow * DataFlowExecutor ) {
521   _Executing = true ;
522   _DataFlowExecutor = DataFlowExecutor ;
523 }
524
525 inline GraphExecutor::DataFlow * GraphEditor::DataFlow::Executor() const {
526   return _DataFlowExecutor ;
527 }
528
529 #endif
530
531
532