]> SALOME platform Git repositories - modules/superv.git/blob - src/Supervision/INode_Impl.cxx
Salome HOME
IsEqual() method was added for Link.
[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     else {
141       MESSAGE("INode_Impl::destroy ERROR ") ;
142     }
143   }
144   endService( "INode_Impl::Destroy" );
145 }
146
147 bool INode_Impl::Delete() {
148 //  beginService( "INode_Impl::Delete" );
149   bool RetVal = false ;
150   if ( DataFlowEditor()->IsEditing() ) {
151     DeletePorts() ;
152     RetVal = DataFlowEditor()->RemoveNode( Name() ) ;
153     if ( RetVal )
154       DataFlowEditor()->UnValid() ;
155   }
156 //  endService( "INode_Impl::Delete" );
157   return RetVal ;
158 }
159
160 void INode_Impl::SetPyFunction( const char * FuncName ,
161                                 const SUPERV::ListOfStrings & aPyFunction ) {
162   beginService( "INode_Impl::SetPyFunction" );
163   if ( DataFlowEditor()->IsEditing() ) {
164     DataFlowNode()->SetPythonFunction( FuncName , aPyFunction ) ;
165   }
166   endService( "INode_Impl::SetPyFunction" );
167   return ;
168 }
169
170 SUPERV::ListOfStrings * INode_Impl::PyFunction() {
171   beginService( "INode_Impl::PyFunction" );
172   SUPERV::ListOfStrings * aPyFunc = NULL ;
173   if ( DataFlowEditor()->IsEditing() ) {
174     aPyFunc = new SUPERV::ListOfStrings( *DataFlowNode()->PythonFunction() ) ;
175   }
176   else {
177     aPyFunc = new SUPERV::ListOfStrings() ;
178   }
179   endService( "INode_Impl::PyFunction" );
180   return aPyFunc ;
181 }
182
183 char * INode_Impl::PyFuncName() {
184   return CORBA::string_dup( DataFlowNode()->PyFuncName() ) ;
185 }
186
187 SUPERV::Port_ptr INode_Impl::InPort( const char *aParameterName ,
188                                      const char *aParameterType ) {
189   SUPERV::Port_ptr Inobject = SUPERV::Port::_nil() ;
190   SUPERV::Port_ptr Outobject = SUPERV::Port::_nil() ;
191   SUPERV::Port_ptr InEndobject = SUPERV::Port::_nil() ;
192   Port_Impl * myInPort = NULL ;
193   bool InPortCreated = false ;
194 //  MESSAGE( "CNode_Impl::InPort " << DataFlowNode()->Name() << "->AddInPort( " << aParameterName << " , "
195 //           << aParameterType << " )" ) ;
196   GraphBase::InPort * anInPort = DataFlowNode()->GetChangeInPort( aParameterName ) ;
197   if ( anInPort == NULL ) {
198     anInPort = DataFlowNode()->AddInPort( aParameterName , aParameterType , SUPERV::InLineParameter ) ;
199     InPortCreated = true ;
200   }
201   if ( anInPort ) {
202     Inobject = anInPort->ObjRef() ;
203     if ( CORBA::is_nil( Inobject ) ) {
204       myInPort = new Port_Impl( _Orb , _Poa , _ContId ,
205                                 instanceName() , interfaceName() ,
206                                 DataFlowEditor() ,
207                                 DataFlowNode() ,
208                                 (GraphBase::Port * ) anInPort ,
209                                 true ) ;
210       if ( myInPort ) {
211         PortableServer::ObjectId * id = myInPort->getId() ;
212         CORBA::Object_var obj = _poa->id_to_reference(*id) ;
213         Inobject = SUPERV::Port::_narrow(obj) ;
214 //JR 02.09.2005 : set of objref is better
215         anInPort->ObjRef( Inobject ) ;
216       }      
217     }
218   }
219
220   if ( !CORBA::is_nil( Inobject ) && InPortCreated &&
221        ( DataFlowNode()->IsLoopNode() || DataFlowNode()->IsEndLoopNode() ) ) {
222 //         || DataFlowNode()->IsEndSwitchNode() ) ) {
223     Outobject = OutPort( aParameterName , aParameterType ) ;
224 // ==> The OutPort (and ObjRef) with the same name is created in the LoopNode
225     if ( DataFlowNode()->IsLoopNode() ) {
226       LNode_Impl * myLoopNode = (LNode_Impl * ) this ;
227       InEndobject = myLoopNode->Coupled()->InPort( aParameterName , aParameterType ) ;
228 // ==> The In/OutPort (and ObjRef) with the same name are created in the EndLoopNode
229       DataFlowEditor()->AddLink( Outobject->Node()->Name() , Outobject->Name() ,
230                                  InEndobject->Node()->Name() , InEndobject->Name() ) ;
231     }
232   }
233   DataFlowEditor()->UnValid() ;
234   return SUPERV::Port::_duplicate( Inobject ) ;
235 }
236
237 SUPERV::Port_ptr INode_Impl::OutPort( const char *aParameterName ,
238                                       const char *aParameterType ) {
239   Port_Impl * myOutPort = NULL ;
240   SUPERV::Port_ptr Outobject = SUPERV::Port::_nil() ;
241 //  MESSAGE( "CNode_Impl::OutPort " << DataFlowNode()->Name() << "->AddOutPort( " << aParameterName << " , "
242 //           << aParameterType << " )" ) ;
243   GraphBase::OutPort * anOutPort = DataFlowNode()->GetChangeOutPort( aParameterName ) ;
244   if ( anOutPort == NULL ) {
245     anOutPort = DataFlowNode()->AddOutPort( aParameterName , aParameterType , SUPERV::InLineParameter ) ;
246   }
247   if ( anOutPort ) {
248     Outobject = anOutPort->ObjRef() ;
249     if ( CORBA::is_nil( Outobject ) ) {
250 //JR 30.03.2005      const CORBA::Any * anAny = anOutPort->Value() ;
251       const CORBA::Any anAny = anOutPort->Value() ;
252       myOutPort = new Port_Impl( _Orb , _Poa , _ContId ,
253                                  instanceName() , interfaceName() ,
254                                  DataFlowEditor() ,
255                                  DataFlowNode() ,
256                                  (GraphBase::Port * ) anOutPort ,
257                                  false ,
258                                  &anAny ) ;
259       if ( myOutPort ) {
260         PortableServer::ObjectId * id = myOutPort->getId() ;
261         CORBA::Object_var obj = _poa->id_to_reference(*id) ;
262         Outobject = SUPERV::Port::_narrow(obj) ;
263 //JR 02.09.2005 : set of objref is better
264         anOutPort->ObjRef( Outobject ) ;
265       }
266     }
267   }
268   DataFlowEditor()->UnValid() ;
269   return SUPERV::Port::_duplicate( Outobject );
270 }
271
272 SUPERV::StreamPort_ptr INode_Impl::InStreamPort( const char *aParameterName ,
273                                                  const SALOME_ModuleCatalog::DataStreamType aParameterType ,
274                                                  const SALOME_ModuleCatalog::DataStreamDependency aDependency ) {
275   SUPERV::StreamPort_ptr Inobject = SUPERV::StreamPort::_nil() ;
276   if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
277     StreamPort_Impl * myInStreamPort = NULL ;
278     bool InPortCreated = false ;
279     MESSAGE( "INode_Impl::InStreamPort " << DataFlowNode()->Name() << "->AddInPort( " << aParameterName << " , "
280              << aParameterType << " )" ) ;
281     GraphBase::InPort * anInPort = DataFlowNode()->GetChangeInPort( aParameterName ) ;
282     if ( anInPort && !anInPort->IsDataStream() ) {
283       MESSAGE( "INode_Impl::InStreamPort ERROR !IsDataStream " ) ;
284     }
285     else if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
286       if ( anInPort == NULL ) {
287         anInPort = DataFlowNode()->ComputingNode()->AddInDataStreamPort( aParameterName , aParameterType , aDependency , SUPERV::DataStreamParameter ) ;
288         InPortCreated = true ;
289       }
290
291       if ( anInPort ) {
292         Inobject = SUPERV::StreamPort::_narrow( anInPort->ObjRef() ) ;
293         if ( CORBA::is_nil( Inobject ) ) {
294           myInStreamPort = new StreamPort_Impl( _Orb , _Poa , _ContId ,
295                                 instanceName() , interfaceName() ,
296                                 DataFlowEditor() ,
297                                 DataFlowNode() ,
298                                 (GraphBase::Port * ) anInPort ,
299                                 true ) ;
300           if ( myInStreamPort ) {
301             PortableServer::ObjectId * id = myInStreamPort->getId() ;
302             CORBA::Object_var obj = _poa->id_to_reference(*id) ;
303             Inobject = SUPERV::StreamPort::_narrow(obj) ;
304             anInPort->ObjRef( SUPERV::StreamPort::_duplicate( Inobject ) ) ;
305           }
306         }
307       }
308     }
309
310 //    if ( !CORBA::is_nil( Inobject ) && InPortCreated &&
311 //         ( DataFlowNode()->IsLoopNode() || DataFlowNode()->IsEndLoopNode() ||
312 //           DataFlowNode()->IsEndSwitchNode() ) ) {
313 //      Outobject = OutPort( aParameterName , aParameterType ) ;
314 //      if ( DataFlowNode()->IsLoopNode() ) {
315 //        LNode_Impl * myLoopNode = (LNode_Impl * ) this ;
316 //        InEndobject = myLoopNode->Coupled()->InPort( aParameterName , aParameterType ) ;
317 //        DataFlowEditor()->AddLink( Outobject->Node()->Name() , Outobject->Name() ,
318 //                                   InEndobject->Node()->Name() , InEndobject->Name() ) ;
319 //      }
320 //    }
321     DataFlowEditor()->UnValid() ;
322   }
323   return SUPERV::StreamPort::_duplicate( Inobject ) ;
324 }
325
326 SUPERV::StreamPort_ptr INode_Impl::OutStreamPort( const char * aParameterName ,
327                                                   const SALOME_ModuleCatalog::DataStreamType aParameterType ,
328                                                   const SALOME_ModuleCatalog::DataStreamDependency aDependency ) {
329   StreamPort_Impl * myOutStreamPort = NULL ;
330   SUPERV::StreamPort_ptr Outobject = SUPERV::StreamPort::_nil() ;
331   if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
332     MESSAGE( "INode_Impl::OutStreamPort " << DataFlowNode()->Name() << "->AddOutPort( " << aParameterName << " , "
333              << aParameterType << " )" ) ;
334     GraphBase::OutPort * anOutPort = DataFlowNode()->GetChangeOutPort( aParameterName ) ;
335     if ( anOutPort && !anOutPort->IsDataStream() ) {
336       MESSAGE( "INode_Impl::OutStreamPort ERROR !IsDataStream " ) ;
337     }
338     else if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
339       if ( anOutPort == NULL ) {
340         anOutPort = DataFlowNode()->ComputingNode()->AddOutDataStreamPort( aParameterName , aParameterType , aDependency , SUPERV::DataStreamParameter ) ;
341       }
342
343       if ( anOutPort ) {
344         Outobject = SUPERV::StreamPort::_narrow( anOutPort->ObjRef() ) ;
345         if ( CORBA::is_nil( Outobject ) ) {
346 //JR 30.03.2005          const CORBA::Any * anAny = anOutPort->Value() ;
347           const CORBA::Any anAny = anOutPort->Value() ;
348           myOutStreamPort = new StreamPort_Impl( _Orb , _Poa , _ContId ,
349                                  instanceName() , interfaceName() ,
350                                  DataFlowEditor() ,
351                                  DataFlowNode() ,
352                                  (GraphBase::Port * ) anOutPort ,
353                                  false ,
354                                  &anAny ) ;
355           if ( myOutStreamPort ) {
356             PortableServer::ObjectId * id = myOutStreamPort->getId() ;
357             CORBA::Object_var obj = _poa->id_to_reference(*id) ;
358             Outobject = SUPERV::StreamPort::_narrow(obj) ;
359             anOutPort->ObjRef( SUPERV::StreamPort::_duplicate( Outobject ) ) ;
360           }
361         }
362       }
363     }
364     DataFlowEditor()->UnValid() ;
365   }
366   return SUPERV::StreamPort::_duplicate( Outobject );
367 }
368
369