]> SALOME platform Git repositories - modules/superv.git/blob - src/Supervision/INode_Impl.cxx
Salome HOME
2) new Editing() method of Graph added.
[modules/superv.git] / src / Supervision / INode_Impl.cxx
1 //  SUPERV Supervision : contains the implementation of interfaces of SuperVision described in SUPERV.idl
2 //
3 //  Copyright (C) 2003  CEA/DEN, EDF R&D
4 //
5 //
6 //
7 //  File   : INode_Impl.cxx
8 //  Author : Jean Rahuel
9 //  Module : SUPERV
10 //  $Header: 
11
12 using namespace std;
13 #include <stdio.h>
14 #include <fstream>
15 //#include <sstream>
16 #include <string>
17
18 //#include "utilities.h"
19
20 #include "LNode_Impl.hxx"
21
22 INode_Impl::INode_Impl( CORBA::ORB_ptr orb ,
23                        PortableServer::POA_ptr poa ,
24                        PortableServer::ObjectId * contId , 
25                        const char *instanceName ,
26                        const char *interfaceName ,
27                        const char *aDataFlowName ,
28                        const SUPERV::KindOfNode aKindOfNode ) :
29 //  Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
30   CNode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowName , aKindOfNode ) {
31 //  MESSAGE("INode_Impl::INode_Impl activate object instanceName("
32 //          << instanceName << ") interfaceName(" << interfaceName << ") --> "
33 //          << hex << (void *) this << dec )
34 //  _thisObj = this ;
35 //  _id = _poa->activate_object(_thisObj);
36 //  MESSAGE( "INode_Impl::INode_Impl " << aDataFlowName );
37 //  beginService( "INode_Impl::INode_Impl" );
38   _Orb = CORBA::ORB::_duplicate(orb);
39   _Poa = poa ;
40   _ContId = contId ;
41 //  endService( "INode_Impl::INode_Impl" );  
42 }
43
44 INode_Impl::INode_Impl() {
45 }
46
47 INode_Impl::INode_Impl( CORBA::ORB_ptr orb ,
48                         PortableServer::POA_ptr poa ,
49                         PortableServer::ObjectId * contId , 
50                         const char *instanceName ,
51                         const char *interfaceName ,
52                         GraphEditor::DataFlow * aDataFlowEditor ,
53                         const char * FuncName , 
54                         const SUPERV::ListOfStrings & aPythonFunction ,
55                         const SUPERV::KindOfNode NodeKindOfNode ) :
56 //  Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
57   CNode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowEditor , SALOME_ModuleCatalog::Service() , FuncName , NodeKindOfNode , FuncName , aPythonFunction ) {
58 //  beginService( "INode_Impl::INode_Impl" );
59   if ( FuncName ) {
60 //    cout << "INode_Impl::CNode_Impl " << (void *) FuncName << " " << FuncName
61 //         << " " << strlen( FuncName ) << endl ;
62   }
63   if ( NodeKindOfNode == SUPERV::InLineNode ) {
64 //    MESSAGE( "INode_Impl::INode_Impl " << FuncName << " _poa->activate_object" );
65     _thisObj = this ;
66     _id = _poa->activate_object(_thisObj);
67   }
68 //  MESSAGE("INode_Impl::INode_Impl " << FuncName << " " << strlen( FuncName ) ) ;
69   _Orb = CORBA::ORB::_duplicate(orb);
70   _Poa = poa ;
71   _ContId = contId ;
72 //  DataFlowNode()->SetPythonFunction( FuncName , aPythonFunction ) ;
73 //  endService( "INode_Impl::INode_Impl" );  
74 }
75
76 INode_Impl::INode_Impl( CORBA::ORB_ptr orb ,
77                         PortableServer::POA_ptr poa ,
78                         PortableServer::ObjectId * contId , 
79                         const char *instanceName ,
80                         const char *interfaceName ,
81                         GraphEditor::DataFlow * aDataFlowEditor ,
82                         const GraphBase::ListOfFuncName FuncName , 
83                         const GraphBase::ListOfPythonFunctions aPythonFunction ,
84                         const SUPERV::KindOfNode NodeKindOfNode ) :
85 //  Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
86   CNode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowEditor , SALOME_ModuleCatalog::Service() , FuncName[0].c_str() , NodeKindOfNode , FuncName , aPythonFunction ) {
87 //  beginService( "INode_Impl::INode_Impl" );
88   if ( NodeKindOfNode == SUPERV::InLineNode ) {
89 //    MESSAGE( "INode_Impl::INode_Impl " << FuncName[0] << " _poa->activate_object" );
90     _thisObj = this ;
91     _id = _poa->activate_object(_thisObj);
92   }
93 //  MESSAGE("INode_Impl::INode_Impl " << FuncName[0].c_str() << " " << strlen( FuncName[0].c_str() ) ) ;
94   _Orb = CORBA::ORB::_duplicate(orb);
95   _Poa = poa ;
96   _ContId = contId ;
97 //  DataFlowNode()->SetPythonFunction( FuncName , aPythonFunction ) ;
98 //  endService( "INode_Impl::INode_Impl" );  
99 }
100
101 INode_Impl::INode_Impl( CORBA::ORB_ptr orb ,
102                         PortableServer::POA_ptr poa ,
103                         PortableServer::ObjectId * contId , 
104                         const char *instanceName ,
105                         const char *interfaceName ,
106                         GraphEditor::DataFlow * aDataFlowEditor ,
107                         GraphEditor::InNode * aDataFlowNode ) :
108 //  Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
109   CNode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowEditor , aDataFlowNode ) {
110 //  beginService( "INode_Impl::INode_Impl" );
111   if ( DataFlowNode() && DataFlowNode()->IsInLineNode() ) {
112 //    MESSAGE( "INode_Impl::INode_Impl " << DataFlowNode()->PyFuncName()
113 //             << " _poa->activate_object" );
114     _thisObj = this ;
115     _id = _poa->activate_object(_thisObj);
116   }
117   else {
118 //    MESSAGE( "INode_Impl::INode_Impl NO _poa->activate_object" );
119   }
120   _Orb = CORBA::ORB::_duplicate(orb);
121   _Poa = poa ;
122   _ContId = contId ;
123 //  endService( "INode_Impl::INode_Impl" );  
124 }
125
126 INode_Impl::~INode_Impl() {
127   beginService( "INode_Impl::~INode_Impl" );
128   endService( "INode_Impl::~INode_Impl" );
129 }
130
131 void INode_Impl::destroy() {
132   beginService( "INode_Impl::Destroy" );
133   if ( DataFlowEditor()->IsEditing() ) {
134     if ( Delete() ) {
135       _poa->deactivate_object(*_id) ;
136       CORBA::release(_poa) ;
137       delete(_id) ;
138       _thisObj->_remove_ref();
139     }
140   }
141   endService( "INode_Impl::Destroy" );
142 }
143
144 bool INode_Impl::Delete() {
145 //  beginService( "INode_Impl::Delete" );
146   bool RetVal = false ;
147   if ( DataFlowEditor()->IsEditing() ) {
148     DeletePorts() ;
149     RetVal = DataFlowEditor()->RemoveNode( Name() ) ;
150     if ( RetVal )
151       RetVal = DataFlowEditor()->UnValid() ;
152   }
153 //  endService( "INode_Impl::Delete" );
154   return RetVal ;
155 }
156
157 void INode_Impl::SetPyFunction( const char * FuncName ,
158                                 const SUPERV::ListOfStrings & aPyFunction ) {
159   beginService( "INode_Impl::SetPyFunction" );
160   if ( DataFlowEditor()->IsEditing() ) {
161     DataFlowNode()->SetPythonFunction( FuncName , aPyFunction ) ;
162   }
163   endService( "INode_Impl::SetPyFunction" );
164   return ;
165 }
166
167 SUPERV::ListOfStrings * INode_Impl::PyFunction() {
168   beginService( "INode_Impl::PyFunction" );
169   SUPERV::ListOfStrings * aPyFunc = NULL ;
170   if ( DataFlowEditor()->IsEditing() ) {
171     aPyFunc = new SUPERV::ListOfStrings( *DataFlowNode()->PythonFunction() ) ;
172   }
173   else {
174     aPyFunc = new SUPERV::ListOfStrings() ;
175   }
176   endService( "INode_Impl::PyFunction" );
177   return aPyFunc ;
178 }
179
180 char * INode_Impl::PyFuncName() {
181   return CORBA::string_dup( DataFlowNode()->PyFuncName() ) ;
182 }
183
184 SUPERV::Port_ptr INode_Impl::InPort( const char *aParameterName ,
185                                      const char *aParameterType ) {
186   SUPERV::Port_ptr Inobject = SUPERV::Port::_nil() ;
187   SUPERV::Port_ptr Outobject = SUPERV::Port::_nil() ;
188   SUPERV::Port_ptr InEndobject = SUPERV::Port::_nil() ;
189   Port_Impl * myInPort = NULL ;
190   bool InPortCreated = false ;
191 //  MESSAGE( "CNode_Impl::InPort " << DataFlowNode()->Name() << "->AddInPort( " << aParameterName << " , "
192 //           << aParameterType << " )" ) ;
193   GraphBase::InPort * anInPort = DataFlowNode()->GetChangeInPort( aParameterName ) ;
194   if ( anInPort == NULL ) {
195     anInPort = DataFlowNode()->AddInPort( aParameterName , aParameterType , SUPERV::InLineParameter ) ;
196     InPortCreated = true ;
197   }
198   if ( anInPort ) {
199     Inobject = anInPort->ObjRef() ;
200     if ( CORBA::is_nil( Inobject ) ) {
201       myInPort = new Port_Impl( _Orb , _Poa , _ContId ,
202                                 instanceName() , interfaceName() ,
203                                 DataFlowEditor() ,
204                                 DataFlowNode() ,
205                                 (GraphBase::Port * ) anInPort ,
206                                 true ) ;
207       if ( myInPort ) {
208         PortableServer::ObjectId * id = myInPort->getId() ;
209         CORBA::Object_var obj = _poa->id_to_reference(*id) ;
210         Inobject = SUPERV::Port::_narrow(obj) ;
211       }      
212     }
213   }
214
215   if ( !CORBA::is_nil( Inobject ) && InPortCreated &&
216        ( DataFlowNode()->IsLoopNode() || DataFlowNode()->IsEndLoopNode() ) ) {
217 //         || DataFlowNode()->IsEndSwitchNode() ) ) {
218     Outobject = OutPort( aParameterName , aParameterType ) ;
219     if ( DataFlowNode()->IsLoopNode() ) {
220       LNode_Impl * myLoopNode = (LNode_Impl * ) this ;
221       InEndobject = myLoopNode->Coupled()->InPort( aParameterName , aParameterType ) ;
222       DataFlowEditor()->AddLink( Outobject->Node()->Name() , Outobject->Name() ,
223                                  InEndobject->Node()->Name() , InEndobject->Name() ) ;
224     }
225   }
226   DataFlowEditor()->UnValid() ;
227   return SUPERV::Port::_duplicate( Inobject ) ;
228 }
229
230 SUPERV::Port_ptr INode_Impl::OutPort( const char *aParameterName ,
231                                       const char *aParameterType ) {
232   Port_Impl * myOutPort = NULL ;
233   SUPERV::Port_ptr Outobject = SUPERV::Port::_nil() ;
234 //  MESSAGE( "CNode_Impl::OutPort " << DataFlowNode()->Name() << "->AddOutPort( " << aParameterName << " , "
235 //           << aParameterType << " )" ) ;
236   GraphBase::OutPort * anOutPort = DataFlowNode()->GetChangeOutPort( aParameterName ) ;
237   if ( anOutPort == NULL ) {
238     anOutPort = DataFlowNode()->AddOutPort( aParameterName , aParameterType , SUPERV::InLineParameter ) ;
239   }
240   if ( anOutPort ) {
241     Outobject = anOutPort->ObjRef() ;
242     if ( CORBA::is_nil( Outobject ) ) {
243       const CORBA::Any * anAny = anOutPort->Value() ;
244       myOutPort = new Port_Impl( _Orb , _Poa , _ContId ,
245                                  instanceName() , interfaceName() ,
246                                  DataFlowEditor() ,
247                                  DataFlowNode() ,
248                                  (GraphBase::Port * ) anOutPort ,
249                                  false ,
250                                  anAny ) ;
251       if ( myOutPort ) {
252         PortableServer::ObjectId * id = myOutPort->getId() ;
253         CORBA::Object_var obj = _poa->id_to_reference(*id) ;
254         Outobject = SUPERV::Port::_narrow(obj) ;
255       }
256     }
257   }
258   DataFlowEditor()->UnValid() ;
259   return SUPERV::Port::_duplicate( Outobject );
260 }
261
262 SUPERV::StreamPort_ptr INode_Impl::InStreamPort( const char *aParameterName ,
263                                                  const SALOME_ModuleCatalog::DataStreamType aParameterType ,
264                                                  const SALOME_ModuleCatalog::DataStreamDependency aDependency ) {
265   SUPERV::StreamPort_ptr Inobject = SUPERV::StreamPort::_nil() ;
266   if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
267     StreamPort_Impl * myInStreamPort = NULL ;
268     bool InPortCreated = false ;
269     MESSAGE( "INode_Impl::InStreamPort " << DataFlowNode()->Name() << "->AddInPort( " << aParameterName << " , "
270              << aParameterType << " )" ) ;
271     GraphBase::InPort * anInPort = DataFlowNode()->GetChangeInPort( aParameterName ) ;
272     if ( anInPort && !anInPort->IsDataStream() ) {
273       MESSAGE( "INode_Impl::InStreamPort ERROR !IsDataStream " ) ;
274     }
275     else if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
276       if ( anInPort == NULL ) {
277         anInPort = DataFlowNode()->ComputingNode()->AddInDataStreamPort( aParameterName , aParameterType , aDependency , SUPERV::DataStreamParameter ) ;
278         InPortCreated = true ;
279       }
280
281       if ( anInPort ) {
282         Inobject = SUPERV::StreamPort::_narrow( anInPort->ObjRef() ) ;
283         if ( CORBA::is_nil( Inobject ) ) {
284           myInStreamPort = new StreamPort_Impl( _Orb , _Poa , _ContId ,
285                                 instanceName() , interfaceName() ,
286                                 DataFlowEditor() ,
287                                 DataFlowNode() ,
288                                 (GraphBase::Port * ) anInPort ,
289                                 true ) ;
290           if ( myInStreamPort ) {
291             PortableServer::ObjectId * id = myInStreamPort->getId() ;
292             CORBA::Object_var obj = _poa->id_to_reference(*id) ;
293             Inobject = SUPERV::StreamPort::_narrow(obj) ;
294             anInPort->ObjRef( SUPERV::StreamPort::_duplicate( Inobject ) ) ;
295           }
296         }
297       }
298     }
299
300 //    if ( !CORBA::is_nil( Inobject ) && InPortCreated &&
301 //         ( DataFlowNode()->IsLoopNode() || DataFlowNode()->IsEndLoopNode() ||
302 //           DataFlowNode()->IsEndSwitchNode() ) ) {
303 //      Outobject = OutPort( aParameterName , aParameterType ) ;
304 //      if ( DataFlowNode()->IsLoopNode() ) {
305 //        LNode_Impl * myLoopNode = (LNode_Impl * ) this ;
306 //        InEndobject = myLoopNode->Coupled()->InPort( aParameterName , aParameterType ) ;
307 //        DataFlowEditor()->AddLink( Outobject->Node()->Name() , Outobject->Name() ,
308 //                                   InEndobject->Node()->Name() , InEndobject->Name() ) ;
309 //      }
310 //    }
311     DataFlowEditor()->UnValid() ;
312   }
313   return SUPERV::StreamPort::_duplicate( Inobject ) ;
314 }
315
316 SUPERV::StreamPort_ptr INode_Impl::OutStreamPort( const char * aParameterName ,
317                                                   const SALOME_ModuleCatalog::DataStreamType aParameterType ,
318                                                   const SALOME_ModuleCatalog::DataStreamDependency aDependency ) {
319   StreamPort_Impl * myOutStreamPort = NULL ;
320   SUPERV::StreamPort_ptr Outobject = SUPERV::StreamPort::_nil() ;
321   if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
322     MESSAGE( "INode_Impl::OutStreamPort " << DataFlowNode()->Name() << "->AddOutPort( " << aParameterName << " , "
323              << aParameterType << " )" ) ;
324     GraphBase::OutPort * anOutPort = DataFlowNode()->GetChangeOutPort( aParameterName ) ;
325     if ( anOutPort && !anOutPort->IsDataStream() ) {
326       MESSAGE( "INode_Impl::OutStreamPort ERROR !IsDataStream " ) ;
327     }
328     else if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
329       if ( anOutPort == NULL ) {
330         anOutPort = DataFlowNode()->ComputingNode()->AddOutDataStreamPort( aParameterName , aParameterType , aDependency , SUPERV::DataStreamParameter ) ;
331       }
332
333       if ( anOutPort ) {
334         Outobject = SUPERV::StreamPort::_narrow( anOutPort->ObjRef() ) ;
335         if ( CORBA::is_nil( Outobject ) ) {
336           const CORBA::Any * anAny = anOutPort->Value() ;
337           myOutStreamPort = new StreamPort_Impl( _Orb , _Poa , _ContId ,
338                                  instanceName() , interfaceName() ,
339                                  DataFlowEditor() ,
340                                  DataFlowNode() ,
341                                  (GraphBase::Port * ) anOutPort ,
342                                  false ,
343                                  anAny ) ;
344           if ( myOutStreamPort ) {
345             PortableServer::ObjectId * id = myOutStreamPort->getId() ;
346             CORBA::Object_var obj = _poa->id_to_reference(*id) ;
347             Outobject = SUPERV::StreamPort::_narrow(obj) ;
348             anOutPort->ObjRef( SUPERV::StreamPort::_duplicate( Outobject ) ) ;
349           }
350         }
351       }
352     }
353     DataFlowEditor()->UnValid() ;
354   }
355   return SUPERV::StreamPort::_duplicate( Outobject );
356 }
357
358