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