Salome HOME
NRI : Merge from V1_2.
[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 <strstream>
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 //  Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
29   CNode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowName ) {
30 //  MESSAGE("INode_Impl::INode_Impl activate object instanceName("
31 //          << instanceName << ") interfaceName(" << interfaceName << ") --> "
32 //          << hex << (void *) this << dec )
33 //  _thisObj = this ;
34 //  _id = _poa->activate_object(_thisObj);
35   MESSAGE( "INode_Impl::INode_Impl " << aDataFlowName );
36   beginService( "INode_Impl::INode_Impl" );
37   _Orb = CORBA::ORB::_duplicate(orb);
38   _Poa = poa ;
39   _ContId = contId ;
40   endService( "INode_Impl::INode_Impl" );  
41 }
42
43 INode_Impl::INode_Impl() {
44 }
45
46 INode_Impl::INode_Impl( CORBA::ORB_ptr orb ,
47                         PortableServer::POA_ptr poa ,
48                         PortableServer::ObjectId * contId , 
49                         const char *instanceName ,
50                         const char *interfaceName ,
51                         GraphEditor::DataFlow * aDataFlowEditor ,
52                         const char * FuncName , 
53                         const SUPERV::ListOfStrings & aPythonFunction ,
54                         const SUPERV::KindOfNode NodeKindOfNode ) :
55 //  Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
56   CNode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowEditor , SALOME_ModuleCatalog::Service() , FuncName , NodeKindOfNode , FuncName , aPythonFunction ) {
57   beginService( "INode_Impl::INode_Impl" );
58   if ( FuncName ) {
59     cout << "INode_Impl::CNode_Impl " << (void *) FuncName << " " << FuncName
60          << " " << strlen( FuncName ) << endl ;
61   }
62   if ( NodeKindOfNode == SUPERV::InLineNode ) {
63     MESSAGE( "INode_Impl::INode_Impl " << FuncName << " _poa->activate_object" );
64     _thisObj = this ;
65     _id = _poa->activate_object(_thisObj);
66   }
67   MESSAGE("INode_Impl::INode_Impl " << FuncName << " " << strlen( FuncName ) ) ;
68   _Orb = CORBA::ORB::_duplicate(orb);
69   _Poa = poa ;
70   _ContId = contId ;
71 //  DataFlowNode()->SetPythonFunction( FuncName , aPythonFunction ) ;
72   endService( "INode_Impl::INode_Impl" );  
73 }
74
75 INode_Impl::INode_Impl( CORBA::ORB_ptr orb ,
76                         PortableServer::POA_ptr poa ,
77                         PortableServer::ObjectId * contId , 
78                         const char *instanceName ,
79                         const char *interfaceName ,
80                         GraphEditor::DataFlow * aDataFlowEditor ,
81                         const GraphBase::ListOfFuncName FuncName , 
82                         const GraphBase::ListOfPythonFunctions aPythonFunction ,
83                         const SUPERV::KindOfNode NodeKindOfNode ) :
84 //  Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
85   CNode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowEditor , SALOME_ModuleCatalog::Service() , FuncName[0].c_str() , NodeKindOfNode , FuncName , aPythonFunction ) {
86   beginService( "INode_Impl::INode_Impl" );
87   if ( NodeKindOfNode == SUPERV::InLineNode ) {
88     MESSAGE( "INode_Impl::INode_Impl " << FuncName[0] << " _poa->activate_object" );
89     _thisObj = this ;
90     _id = _poa->activate_object(_thisObj);
91   }
92   MESSAGE("INode_Impl::INode_Impl " << FuncName[0].c_str() << " " << strlen( FuncName[0].c_str() ) ) ;
93   _Orb = CORBA::ORB::_duplicate(orb);
94   _Poa = poa ;
95   _ContId = contId ;
96 //  DataFlowNode()->SetPythonFunction( FuncName , aPythonFunction ) ;
97   endService( "INode_Impl::INode_Impl" );  
98 }
99
100 INode_Impl::INode_Impl( CORBA::ORB_ptr orb ,
101                         PortableServer::POA_ptr poa ,
102                         PortableServer::ObjectId * contId , 
103                         const char *instanceName ,
104                         const char *interfaceName ,
105                         GraphEditor::DataFlow * aDataFlowEditor ,
106                         GraphEditor::InNode * aDataFlowNode ) :
107 //  Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
108   CNode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowEditor , aDataFlowNode ) {
109   MESSAGE( DataFlowNode()->Name() << " " );
110   beginService( "INode_Impl::INode_Impl" );
111   if ( 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   _Orb = CORBA::ORB::_duplicate(orb);
118   _Poa = poa ;
119   _ContId = contId ;
120   endService( "INode_Impl::INode_Impl" );  
121 }
122
123 INode_Impl::~INode_Impl() {
124   beginService( "INode_Impl::~INode_Impl" );
125   endService( "INode_Impl::~INode_Impl" );
126 }
127
128 void INode_Impl::destroy() {
129   beginService( "INode_Impl::Destroy" );
130   if ( DataFlowEditor()->IsEditing() ) {
131     if ( Delete() ) {
132       _poa->deactivate_object(*_id) ;
133       CORBA::release(_poa) ;
134       delete(_id) ;
135       _thisObj->_remove_ref();
136     }
137   }
138   endService( "INode_Impl::Destroy" );
139 }
140
141 bool INode_Impl::Delete() {
142 //  beginService( "INode_Impl::Delete" );
143   bool RetVal = false ;
144   if ( DataFlowEditor()->IsEditing() ) {
145     RetVal = DataFlowEditor()->RemoveNode( Name() ) ;
146     if ( RetVal )
147       RetVal = DataFlowEditor()->IsValid() ;
148   }
149 //  endService( "INode_Impl::Delete" );
150   return RetVal ;
151 }
152
153 void INode_Impl::SetPyFunction( const char * FuncName ,
154                                 const SUPERV::ListOfStrings & aPyFunction ) {
155   beginService( "INode_Impl::SetPyFunction" );
156   if ( DataFlowEditor()->IsEditing() ) {
157     DataFlowNode()->SetPythonFunction( FuncName , aPyFunction ) ;
158   }
159   endService( "INode_Impl::SetPyFunction" );
160   return ;
161 }
162
163 SUPERV::ListOfStrings * INode_Impl::PyFunction() {
164   beginService( "INode_Impl::PyFunction" );
165   SUPERV::ListOfStrings * aPyFunc = NULL ;
166   if ( DataFlowEditor()->IsEditing() ) {
167     aPyFunc = new SUPERV::ListOfStrings( *DataFlowNode()->PythonFunction() ) ;
168   }
169   else {
170     aPyFunc = new SUPERV::ListOfStrings() ;
171   }
172   endService( "INode_Impl::PyFunction" );
173   return aPyFunc ;
174 }
175
176 char * INode_Impl::PyFuncName() {
177   return CORBA::string_dup( DataFlowNode()->PyFuncName() ) ;
178 }
179
180 SUPERV::Port_ptr INode_Impl::InPort( const char *aParameterName ,
181                                      const char *aParameterType ) {
182   SUPERV::Port_ptr Inobject = SUPERV::Port::_nil() ;
183   SUPERV::Port_ptr Outobject = SUPERV::Port::_nil() ;
184   SUPERV::Port_ptr InEndobject = SUPERV::Port::_nil() ;
185   Port_Impl * myInPort = NULL ;
186   bool InPortCreated = false ;
187   GraphBase::InPort * anInPort = DataFlowNode()->GetChangeInPort( aParameterName ) ;
188   if ( anInPort == NULL && DataFlowNode()->IsOneOfInLineNodes() ) {
189     anInPort = DataFlowNode()->AddInPort( aParameterName , aParameterType ) ;
190     InPortCreated = true ;
191   }
192   if ( anInPort ) {
193     Inobject = anInPort->ObjRef() ;
194     if ( CORBA::is_nil( Inobject ) ) {
195       myInPort = new Port_Impl( _Orb , _Poa , _ContId ,
196                                 instanceName() , interfaceName() ,
197                                 DataFlowEditor() ,
198                                 DataFlowNode() ,
199                                 (GraphBase::Port * ) anInPort ,
200                                 true ) ;
201       if ( myInPort ) {
202         PortableServer::ObjectId * id = myInPort->getId() ;
203         CORBA::Object_var obj = _poa->id_to_reference(*id) ;
204         Inobject = SUPERV::Port::_narrow(obj) ;
205       }      
206     }
207   }
208
209   if ( !CORBA::is_nil( Inobject ) && InPortCreated &&
210        ( DataFlowNode()->IsLoopNode() || DataFlowNode()->IsEndLoopNode() ||
211          DataFlowNode()->IsEndSwitchNode() ) ) {
212     Outobject = OutPort( aParameterName , aParameterType ) ;
213     if ( DataFlowNode()->IsLoopNode() ) {
214       LNode_Impl * myLoopNode = (LNode_Impl * ) this ;
215       InEndobject = myLoopNode->Coupled()->InPort( aParameterName , aParameterType ) ;
216       DataFlowEditor()->AddLink( Outobject->Node()->Name() , Outobject->Name() ,
217                                  InEndobject->Node()->Name() , InEndobject->Name() ) ;
218     }
219   }
220   DataFlowEditor()->UnValid() ;
221   return SUPERV::Port::_duplicate( Inobject ) ;
222 }
223
224 SUPERV::Port_ptr INode_Impl::OutPort( const char *aParameterName ,
225                                       const char *aParameterType ) {
226   Port_Impl * myOutPort = NULL ;
227   SUPERV::Port_ptr Outobject = SUPERV::Port::_nil() ;
228   GraphBase::OutPort * anOutPort = DataFlowNode()->GetChangeOutPort( aParameterName ) ;
229   if ( anOutPort == NULL && DataFlowNode()->IsOneOfInLineNodes() ) {
230     anOutPort = DataFlowNode()->AddOutPort( aParameterName , aParameterType ) ;
231   }
232   if ( anOutPort ) {
233     Outobject = anOutPort->ObjRef() ;
234     if ( CORBA::is_nil( Outobject ) ) {
235       const CORBA::Any * anAny = anOutPort->Value() ;
236       myOutPort = new Port_Impl( _Orb , _Poa , _ContId ,
237                                  instanceName() , interfaceName() ,
238                                  DataFlowEditor() ,
239                                  DataFlowNode() ,
240                                  (GraphBase::Port * ) anOutPort ,
241                                  false ,
242                                  anAny ) ;
243       if ( myOutPort ) {
244         PortableServer::ObjectId * id = myOutPort->getId() ;
245         CORBA::Object_var obj = _poa->id_to_reference(*id) ;
246         Outobject = SUPERV::Port::_narrow(obj) ;
247       }
248     }
249   }
250   DataFlowEditor()->UnValid() ;
251   return SUPERV::Port::_duplicate( Outobject );
252 }
253
254 #if 0
255 bool INode_Impl::BusPort( const char * InOutParameterName ,
256                          const char * InOutParameterType ,
257                          SUPERV::Port_out InputPort ,
258                          SUPERV::Port_out OutputPort ) {
259   return BusPorts( InOutParameterName , InOutParameterType ,
260                    InOutParameterName , InOutParameterType ,
261                    InputPort , OutputPort ) ;
262 }
263
264 bool INode_Impl::BusPorts( const char * InputParameterName ,
265                           const char * InputParameterType ,
266                           const char * OutputParameterName ,
267                           const char * OutputParameterType ,
268                           SUPERV::Port_out InputPort ,
269                           SUPERV::Port_out OutputPort ) {
270   beginService( "INode_Impl::BusPorts" );
271   bool RetVal = false ;
272   Port_Impl * myInPort = NULL ;
273   Port_Impl * myOutPort = NULL ;
274   SUPERV::Port_var Inobject = SUPERV::Port::_nil() ;
275   SUPERV::Port_var Outobject = SUPERV::Port::_nil() ;
276 //  if ( DataFlowNode()->GetInPort( InputParameterName ) ||
277 //       DataFlowNode()->GetOutPort( OutputParameterName ) ) {
278 //  }
279 //  else {
280     GraphBase::InPort * anInPort = DataFlowNode()->AddInPort( InputParameterName ,
281                                                              InputParameterType ) ;
282     if ( anInPort ) {
283       myInPort = new Port_Impl( _Orb , _Poa , _ContId ,
284                                 instanceName() , interfaceName() ,
285                                 DataFlowEditor() ,
286                                 DataFlowNode() ,
287 //                                InputParameterName ) ;
288                                 (GraphBase::Port * ) anInPort ,
289                                 true ) ;
290       GraphBase::OutPort * anOutPort = DataFlowNode()->AddOutPort( OutputParameterName ,
291                                                                   OutputParameterType ) ;
292       if ( anOutPort ) {
293         const CORBA::Any * anAny = anOutPort->Value() ;
294         myOutPort = new Port_Impl( _Orb , _Poa , _ContId ,
295                                   instanceName() , interfaceName() ,
296                                   DataFlowEditor() ,
297                                   DataFlowNode() ,
298 //                                  OutputParameterName ,
299                                   (GraphBase::Port * ) anOutPort ,
300                                   false ,
301                                   anAny ) ;
302         DataFlowNode()->InOutPort( anInPort , anOutPort ) ;
303         RetVal = true ;
304       }
305     }
306 //  }
307   if ( RetVal && myInPort && myOutPort ) {
308     if ( DataFlowNode()->CoupledNode() ) {
309       GraphBase::InPort * anInPort ;
310       anInPort = DataFlowNode()->CoupledNode()->AddInPort( OutputParameterName ,
311                                                           OutputParameterType ) ;
312       GraphBase::OutPort * anOutPort ;
313       anOutPort = DataFlowNode()->CoupledNode()->AddOutPort( InputParameterName ,
314                                                             InputParameterType ) ;
315       DataFlowNode()->CoupledNode()->InOutPort( anInPort , anOutPort ) ;
316     }
317     PortableServer::ObjectId * id = myInPort->getId() ;
318     CORBA::Object_var obj = _poa->id_to_reference(*id) ;
319     Inobject = SUPERV::Port::_narrow(obj) ;
320     InputPort = SUPERV::Port::_duplicate( Inobject ) ;
321     id = myOutPort->getId() ;
322     obj = _poa->id_to_reference(*id);
323     Outobject = SUPERV::Port::_narrow(obj) ;
324     OutputPort = SUPERV::Port::_duplicate( Outobject ) ;
325   }
326   endService( "INode_Impl::BusPorts" );
327   return RetVal ;
328 }
329 #endif
330