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