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