]> SALOME platform Git repositories - modules/superv.git/blob - src/GraphEditor/DataFlowEditor_DataFlow.lxx
Salome HOME
NRI : Merge from 1.2c.
[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   GraphBase::DataNode::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 ( GetGraphNode( aNodeName ) )
54     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 GraphEditor::OutNode::GetNodes() ; 
102 } ;
103
104 inline GraphBase::ListOfLinks * GraphEditor::DataFlow::GetLinks() const {
105    return GraphEditor::OutNode::GetLinks() ; 
106 } ;
107
108 inline GraphBase::ListOfGraphs * GraphEditor::DataFlow::GetGraphs() const {
109    return GraphEditor::OutNode::GetGraphs() ; 
110 } ;
111
112 inline GraphBase::ListOfLinks * GraphEditor::DataFlow::GetDatas() const {
113    return GraphEditor::OutNode::GetDatas() ; 
114 } ;
115
116 inline const SALOME_ModuleCatalog::Service * GraphEditor::DataFlow::GetService() {
117    IsValid() ;
118    return GraphEditor::OutNode::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 ( GetGraphNode( aNodeName ) ) {
192     return 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     return false ;
247   }
248   CORBA::Any const * theValue = GetNode( FromNodeName )->GetOutPort( FromServiceParameterName )->Value() ; // Keep the type !
249   _EditedAfterExecution = true ;
250   return GraphEditor::OutNode::AddLink( FromNodeName ,
251                                         FromServiceParameterName ,
252                                         ToNodeName ,
253                                         ToServiceParameterName ,
254                                         *theValue ) ; 
255 } ;
256
257 inline bool GraphEditor::DataFlow::GetLink(const char* ToNodeName ,
258                                            const char* ToServiceParameterName ,
259                                            char** FromNodeName ,
260                                            char** FromServiceParameterName ) {
261   return GraphEditor::OutNode::GetLink( ToNodeName , ToServiceParameterName ,
262                                         FromNodeName ,
263                                         FromServiceParameterName ) ;
264 }
265
266 inline GraphBase::SLink * GraphEditor::DataFlow::GetLink(
267                                  GraphBase::ComputingNode * aNode ,
268                                  const char* ToServiceParameterName ) {
269   return GraphBase::Graph::GetLink( aNode ,
270                                     aNode->GetChangeInPort( ToServiceParameterName ) ) ;
271 }
272
273 inline bool GraphEditor::DataFlow::AddLinkCoord(
274                          const char* FromNodeName ,
275                          const char* FromServiceParameterName ,
276                          const char* ToNodeName ,
277                          const char* ToServiceParameterName ,
278                          const int nXY ,
279                          const int* X ,
280                          const int* Y ) {
281   _EditedAfterExecution = true ;
282   return GraphEditor::OutNode::AddLinkCoord( FromNodeName ,
283                                              FromServiceParameterName ,
284                                              ToNodeName ,
285                                              ToServiceParameterName ,
286                                              nXY , X , Y ) ; 
287 } ;
288
289 inline bool GraphEditor::DataFlow::AddLinkCoord(
290                          const char* FromNodeName ,
291                          const char* FromServiceParameterName ,
292                          const char* ToNodeName ,
293                          const char* ToServiceParameterName ,
294                          const int index ,
295                          const int X ,
296                          const int Y ) {
297   _EditedAfterExecution = true ;
298   return GraphEditor::OutNode::AddLinkCoord( FromNodeName ,
299                                              FromServiceParameterName ,
300                                              ToNodeName ,
301                                              ToServiceParameterName ,
302                                              index , X , Y ) ; 
303 } ;
304
305 inline bool GraphEditor::DataFlow::ChangeLinkCoord(
306                          const char* FromNodeName ,
307                          const char* FromServiceParameterName ,
308                          const char* ToNodeName ,
309                          const char* ToServiceParameterName ,
310                          const int index ,
311                          const int X ,
312                          const int Y ) {
313   _EditedAfterExecution = true ;
314   return GraphEditor::OutNode::ChangeLinkCoord( FromNodeName ,
315                                                 FromServiceParameterName ,
316                                                 ToNodeName ,
317                                                 ToServiceParameterName ,
318                                                 index , X , Y ) ; 
319 } ;
320
321 inline bool GraphEditor::DataFlow::RemoveLinkCoord(
322                          const char* FromNodeName ,
323                          const char* FromServiceParameterName ,
324                          const char* ToNodeName ,
325                          const char* ToServiceParameterName ,
326                          const int index ) {
327   _EditedAfterExecution = true ;
328   return GraphEditor::OutNode::RemoveLinkCoord( FromNodeName ,
329                                                 FromServiceParameterName ,
330                                                 ToNodeName ,
331                                                 ToServiceParameterName ,
332                                                 index ) ; 
333 } ;
334
335 inline int GraphEditor::DataFlow::GetLinkCoordSize(
336                          const char* FromNodeName ,
337                          const char* FromServiceParameterName ,
338                          const char* ToNodeName ,
339                          const char* ToServiceParameterName ) {
340   return GraphEditor::OutNode::GetLinkCoordSize( FromNodeName ,
341                                                  FromServiceParameterName ,
342                                                  ToNodeName ,
343                                                  ToServiceParameterName ) ; 
344 } ;
345
346 inline bool GraphEditor::DataFlow::GetLinkCoord(
347                          const char* FromNodeName ,
348                          const char* FromServiceParameterName ,
349                          const char* ToNodeName ,
350                          const char* ToServiceParameterName ,
351                          int *X , int *Y ) {
352   return GraphEditor::OutNode::GetLinkCoord( FromNodeName ,
353                                              FromServiceParameterName ,
354                                              ToNodeName ,
355                                              ToServiceParameterName ,
356                                              X , Y ) ; 
357 } ;
358
359 inline bool GraphEditor::DataFlow::GetLinkCoord(
360                          const char* FromNodeName ,
361                          const char* FromServiceParameterName ,
362                          const char* ToNodeName ,
363                          const char* ToServiceParameterName ,
364                          const int index , long &X , long &Y ) {
365   return GraphEditor::OutNode::GetLinkCoord( FromNodeName ,
366                                              FromServiceParameterName ,
367                                              ToNodeName ,
368                                              ToServiceParameterName ,
369                                              index , X , Y ) ; 
370 } ;
371
372 inline bool GraphEditor::DataFlow::RemoveLink(
373                          const char* FromNodeName ,
374                          const char* FromServiceParameterName ,
375                          const char* ToNodeName ,
376                          const char* ToServiceParameterName ) {
377   if ( _ReadOnly ) {
378     return false ;
379   }
380   _EditedAfterExecution = true ;
381   return GraphEditor::OutNode::RemoveLink( FromNodeName ,
382                                            FromServiceParameterName ,
383                                            ToNodeName ,
384                                            ToServiceParameterName ) ; 
385 } ;
386
387 inline bool GraphEditor::DataFlow::AddInputData( const char* ToNodeName ,
388                                                  const char* ToParameterName ,
389                                                  const CORBA::Any aValue ) {
390 #if 0
391   GraphBase::Node *toNode ;
392   GraphBase::InPort *toPort ;
393   char *aNode ;
394   char *aPort ;
395   NodePort( ToNodeName , ToParameterName , &aNode , &aPort ) ;
396   toNode = GetChangeGraphNode( aNode ) ;
397   if ( toNode ) {
398     toPort = toNode->GetChangeInPort( aPort ) ;
399     if ( toPort && ( toPort->IsConnected() ||
400                      toPort->IsDataConnected() ) ) {
401       RemoveLink( toNode->Name() , toPort->PortName() ) ;
402     }
403   }
404   else {
405     toPort = NULL ;
406   }
407   delete aNode ;
408   delete aPort ;
409 #endif
410   if ( !IsValid() ) {
411     return false ;
412   }
413   return GraphBase::Graph::AddInputData( ToNodeName , ToParameterName ,
414                                          aValue ) ; 
415 } ;
416
417 inline bool GraphEditor::DataFlow::AddInputSharedData(const char* ToNodeName1 ,
418                                                       const char* ToParameterName1 ,
419                                                       const char* ToNodeName2 ,
420                                                       const char* ToParameterName2 ) {
421   if ( !IsValid() ) {
422     return false ;
423   }
424   return GraphEditor::OutNode::AddInputData( ToNodeName1 , ToParameterName1 ,
425                                              ToNodeName2 , ToParameterName2 ) ;
426 } ;
427
428 inline const CORBA::Any *GraphEditor::DataFlow::GetInData(
429                                    const char * ToNodeName ,
430                                    const char * ToParameterName ) {
431   return GraphEditor::OutNode::GetInData( ToNodeName ,
432                                           ToParameterName ) ;
433 }
434 inline const CORBA::Any *GraphEditor::DataFlow::GetOutData(
435                                    const char * FromNodeName ,
436                                    const char * FromParameterName ) {
437   return GraphEditor::OutNode::GetOutData( FromNodeName ,
438                                            FromParameterName ) ;
439 }
440
441 inline bool GraphEditor::DataFlow::IsValid() {
442   return GraphEditor::OutNode::IsValid() ;
443 }
444
445 inline bool GraphEditor::DataFlow::IsExecutable() {
446   return GraphEditor::OutNode::IsExecutable() ;
447 }
448
449 inline bool GraphEditor::DataFlow::IsExecuting() {
450   if ( _DataFlowExecutor ) {
451     if ( _DataFlowExecutor->IsDone() ) {
452       _Executing = false ;
453     }
454     else {
455     _Executing = true ;
456     }
457   }
458   else {
459     _Executing = false ;
460   }
461   return _Executing ;
462 }
463
464 inline bool GraphEditor::DataFlow::IsEditing() {
465   return !IsExecuting() ;
466 }
467
468 inline void GraphEditor::DataFlow::EditedAfterExecution(bool EditedAfterExecution ) {
469   _EditedAfterExecution = EditedAfterExecution ;
470 }
471
472 inline bool GraphEditor::DataFlow::EditedAfterExecution() {
473   return _EditedAfterExecution ;
474 }
475
476 inline bool GraphEditor::DataFlow::IsReadOnly() {
477   return _ReadOnly ;
478 }
479
480 inline long GraphEditor::DataFlow::LevelMax() {
481   if ( !IsValid() ) {
482     return 0 ;
483   }
484   return GraphBase::Graph::LevelMax() ;
485 }
486
487 inline SUPERV::ListOfStrings * GraphEditor::DataFlow::LevelNodes(long aLevel ) {
488   if ( !IsValid() ) {
489     return ((SUPERV::ListOfStrings * ) NULL ) ;
490   }
491   return GraphBase::Graph::LevelNodes( aLevel ) ;
492 }
493
494 inline long GraphEditor::DataFlow::ThreadsMax() {
495   if ( !IsValid() ) {
496     return 0 ;
497   }
498   return GraphBase::Graph::ThreadsMax() ;
499 }
500
501 inline long GraphEditor::DataFlow::GraphsNumber() {
502   if ( !IsValid() ) {
503     return 0 ;
504   }
505   return GraphBase::Graph::GraphsNumber() ;
506 }
507
508 inline void GraphEditor::DataFlow::Executor(
509                                GraphExecutor::DataFlow * DataFlowExecutor ) {
510   _Executing = true ;
511   _DataFlowExecutor = DataFlowExecutor ;
512 }
513
514 inline GraphExecutor::DataFlow * GraphEditor::DataFlow::Executor() const {
515   return _DataFlowExecutor ;
516 }
517
518 #endif
519
520
521