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