1 // SUPERV Supervision : contains the implementation of interfaces of SuperVision described in SUPERV.idl
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : INode_Impl.cxx
23 // Author : Jean Rahuel
32 //#include "utilities.h"
34 #include "LNode_Impl.hxx"
36 INode_Impl::INode_Impl( CORBA::ORB_ptr orb ,
37 PortableServer::POA_ptr poa ,
38 PortableServer::ObjectId * contId ,
39 const char *instanceName ,
40 const char *interfaceName ,
41 const char *aDataFlowName ,
42 const SUPERV::KindOfNode aKindOfNode ) :
43 // Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
44 CNode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowName , aKindOfNode ) {
45 // MESSAGE("INode_Impl::INode_Impl activate object instanceName("
46 // << instanceName << ") interfaceName(" << interfaceName << ") --> "
47 // << hex << (void *) this << dec )
49 // _id = _poa->activate_object(_thisObj);
50 // MESSAGE( "INode_Impl::INode_Impl " << aDataFlowName );
51 // beginService( "INode_Impl::INode_Impl" );
52 _Orb = CORBA::ORB::_duplicate(orb);
55 // endService( "INode_Impl::INode_Impl" );
58 INode_Impl::INode_Impl() {
61 INode_Impl::INode_Impl( CORBA::ORB_ptr orb ,
62 PortableServer::POA_ptr poa ,
63 PortableServer::ObjectId * contId ,
64 const char *instanceName ,
65 const char *interfaceName ,
66 GraphEditor::DataFlow * aDataFlowEditor ,
67 const char * FuncName ,
68 const SUPERV::ListOfStrings & aPythonFunction ,
69 const SUPERV::KindOfNode NodeKindOfNode ) :
70 // Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
71 CNode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowEditor , SALOME_ModuleCatalog::Service() , FuncName , NodeKindOfNode , FuncName , aPythonFunction ) {
72 // beginService( "INode_Impl::INode_Impl" );
74 // cout << "INode_Impl::CNode_Impl " << (void *) FuncName << " " << FuncName
75 // << " " << strlen( FuncName ) << endl ;
77 if ( NodeKindOfNode == SUPERV::InLineNode ) {
78 // MESSAGE( "INode_Impl::INode_Impl " << FuncName << " _poa->activate_object" );
80 _id = _poa->activate_object(_thisObj);
82 // MESSAGE("INode_Impl::INode_Impl " << FuncName << " " << strlen( FuncName ) ) ;
83 _Orb = CORBA::ORB::_duplicate(orb);
86 // DataFlowNode()->SetPythonFunction( FuncName , aPythonFunction ) ;
87 // endService( "INode_Impl::INode_Impl" );
90 INode_Impl::INode_Impl( CORBA::ORB_ptr orb ,
91 PortableServer::POA_ptr poa ,
92 PortableServer::ObjectId * contId ,
93 const char *instanceName ,
94 const char *interfaceName ,
95 GraphEditor::DataFlow * aDataFlowEditor ,
96 const GraphBase::ListOfFuncName FuncName ,
97 const GraphBase::ListOfPythonFunctions aPythonFunction ,
98 const SUPERV::KindOfNode NodeKindOfNode ) :
99 // Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
100 CNode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowEditor , SALOME_ModuleCatalog::Service() , FuncName[0].c_str() , NodeKindOfNode , FuncName , aPythonFunction ) {
101 // beginService( "INode_Impl::INode_Impl" );
102 if ( NodeKindOfNode == SUPERV::InLineNode ) {
103 // MESSAGE( "INode_Impl::INode_Impl " << FuncName[0] << " _poa->activate_object" );
105 _id = _poa->activate_object(_thisObj);
107 // MESSAGE("INode_Impl::INode_Impl " << FuncName[0].c_str() << " " << strlen( FuncName[0].c_str() ) ) ;
108 _Orb = CORBA::ORB::_duplicate(orb);
111 // DataFlowNode()->SetPythonFunction( FuncName , aPythonFunction ) ;
112 // endService( "INode_Impl::INode_Impl" );
115 INode_Impl::INode_Impl( CORBA::ORB_ptr orb ,
116 PortableServer::POA_ptr poa ,
117 PortableServer::ObjectId * contId ,
118 const char *instanceName ,
119 const char *interfaceName ,
120 GraphEditor::DataFlow * aDataFlowEditor ,
121 GraphEditor::InNode * aDataFlowNode ) :
122 // Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
123 CNode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowEditor , aDataFlowNode ) {
124 // beginService( "INode_Impl::INode_Impl" );
125 if ( DataFlowNode() && DataFlowNode()->IsInLineNode() ) {
126 // MESSAGE( "INode_Impl::INode_Impl " << DataFlowNode()->PyFuncName()
127 // << " _poa->activate_object" );
129 _id = _poa->activate_object(_thisObj);
132 // MESSAGE( "INode_Impl::INode_Impl NO _poa->activate_object" );
134 _Orb = CORBA::ORB::_duplicate(orb);
137 // endService( "INode_Impl::INode_Impl" );
140 INode_Impl::~INode_Impl() {
141 beginService( "INode_Impl::~INode_Impl" );
142 endService( "INode_Impl::~INode_Impl" );
145 void INode_Impl::destroy() {
146 beginService( "INode_Impl::Destroy" );
147 if ( DataFlowEditor()->IsEditing() ) {
149 _poa->deactivate_object(*_id) ;
150 // CORBA::release(_poa) ;
152 // _thisObj->_remove_ref();
155 MESSAGE("INode_Impl::destroy ERROR ") ;
158 endService( "INode_Impl::Destroy" );
161 bool INode_Impl::Delete() {
162 // beginService( "INode_Impl::Delete" );
163 bool RetVal = false ;
164 if ( DataFlowEditor()->IsEditing() ) {
166 RetVal = DataFlowEditor()->RemoveNode( Name() ) ;
168 DataFlowEditor()->UnValid() ;
170 // endService( "INode_Impl::Delete" );
174 void INode_Impl::SetPyFunction( const char * FuncName ,
175 const SUPERV::ListOfStrings & aPyFunction ) {
176 beginService( "INode_Impl::SetPyFunction" );
177 if ( DataFlowEditor()->IsEditing() ) {
178 DataFlowNode()->SetPythonFunction( FuncName , aPyFunction ) ;
180 endService( "INode_Impl::SetPyFunction" );
184 SUPERV::ListOfStrings * INode_Impl::PyFunction() {
185 beginService( "INode_Impl::PyFunction" );
186 SUPERV::ListOfStrings * aPyFunc = NULL ;
187 if ( DataFlowEditor()->IsEditing() ) {
188 aPyFunc = new SUPERV::ListOfStrings( *DataFlowNode()->PythonFunction() ) ;
191 aPyFunc = new SUPERV::ListOfStrings() ;
193 endService( "INode_Impl::PyFunction" );
197 char * INode_Impl::PyFuncName() {
198 return CORBA::string_dup( DataFlowNode()->PyFuncName() ) ;
201 SUPERV::Port_ptr INode_Impl::InPort( const char *aParameterName ,
202 const char *aParameterType ) {
203 SUPERV::Port_ptr Inobject = SUPERV::Port::_nil() ;
204 SUPERV::Port_ptr Outobject = SUPERV::Port::_nil() ;
205 SUPERV::Port_ptr InEndobject = SUPERV::Port::_nil() ;
206 Port_Impl * myInPort = NULL ;
207 bool InPortCreated = false ;
208 // MESSAGE( "CNode_Impl::InPort " << DataFlowNode()->Name() << "->AddInPort( " << aParameterName << " , "
209 // << aParameterType << " )" ) ;
210 GraphBase::InPort * anInPort = DataFlowNode()->GetChangeInPort( aParameterName ) ;
211 if ( anInPort == NULL ) {
212 anInPort = DataFlowNode()->AddInPort( aParameterName , aParameterType , SUPERV::InLineParameter ) ;
213 InPortCreated = true ;
216 Inobject = anInPort->ObjRef() ;
217 if ( CORBA::is_nil( Inobject ) ) {
218 myInPort = new Port_Impl( _Orb , _Poa , _ContId ,
219 instanceName() , interfaceName() ,
222 (GraphBase::Port * ) anInPort ,
225 PortableServer::ObjectId * id = myInPort->getId() ;
226 CORBA::Object_var obj = _poa->id_to_reference(*id) ;
227 Inobject = SUPERV::Port::_narrow(obj) ;
228 //JR 02.09.2005 : set of objref is better
229 anInPort->ObjRef( Inobject ) ;
234 if ( !CORBA::is_nil( Inobject ) && InPortCreated &&
235 ( DataFlowNode()->IsLoopNode() || DataFlowNode()->IsEndLoopNode() ) ) {
236 // || DataFlowNode()->IsEndSwitchNode() ) ) {
237 Outobject = OutPort( aParameterName , aParameterType ) ;
238 // ==> The OutPort (and ObjRef) with the same name is created in the LoopNode
239 if ( DataFlowNode()->IsLoopNode() ) {
240 LNode_Impl * myLoopNode = (LNode_Impl * ) this ;
241 InEndobject = myLoopNode->Coupled()->InPort( aParameterName , aParameterType ) ;
242 // ==> The In/OutPort (and ObjRef) with the same name are created in the EndLoopNode
243 DataFlowEditor()->AddLink( Outobject->Node()->Name() , Outobject->Name() ,
244 InEndobject->Node()->Name() , InEndobject->Name() ) ;
247 DataFlowEditor()->UnValid() ;
248 return SUPERV::Port::_duplicate( Inobject ) ;
251 SUPERV::Port_ptr INode_Impl::OutPort( const char *aParameterName ,
252 const char *aParameterType ) {
253 Port_Impl * myOutPort = NULL ;
254 SUPERV::Port_ptr Outobject = SUPERV::Port::_nil() ;
255 // MESSAGE( "CNode_Impl::OutPort " << DataFlowNode()->Name() << "->AddOutPort( " << aParameterName << " , "
256 // << aParameterType << " )" ) ;
257 GraphBase::OutPort * anOutPort = DataFlowNode()->GetChangeOutPort( aParameterName ) ;
258 if ( anOutPort == NULL ) {
259 anOutPort = DataFlowNode()->AddOutPort( aParameterName , aParameterType , SUPERV::InLineParameter ) ;
262 Outobject = anOutPort->ObjRef() ;
263 if ( CORBA::is_nil( Outobject ) ) {
264 //JR 30.03.2005 const CORBA::Any * anAny = anOutPort->Value() ;
265 const CORBA::Any anAny = anOutPort->Value() ;
266 myOutPort = new Port_Impl( _Orb , _Poa , _ContId ,
267 instanceName() , interfaceName() ,
270 (GraphBase::Port * ) anOutPort ,
274 PortableServer::ObjectId * id = myOutPort->getId() ;
275 CORBA::Object_var obj = _poa->id_to_reference(*id) ;
276 Outobject = SUPERV::Port::_narrow(obj) ;
277 //JR 02.09.2005 : set of objref is better
278 anOutPort->ObjRef( Outobject ) ;
282 DataFlowEditor()->UnValid() ;
283 return SUPERV::Port::_duplicate( Outobject );
286 SUPERV::StreamPort_ptr INode_Impl::InStreamPort( const char * aParameterName ,
287 const char * aParameterType ,
288 const SALOME_ModuleCatalog::DataStreamDependency aDependency ) {
289 SUPERV::StreamPort_ptr Inobject = SUPERV::StreamPort::_nil() ;
290 if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
291 StreamPort_Impl * myInStreamPort = NULL ;
292 bool InPortCreated = false ;
293 MESSAGE( "INode_Impl::InStreamPort " << DataFlowNode()->Name() << "->AddInPort( " << aParameterName << " , "
294 << aParameterType << " )" ) ;
295 GraphBase::InPort * anInPort = DataFlowNode()->GetChangeInPort( aParameterName ) ;
296 if ( anInPort && !anInPort->IsDataStream() ) {
297 MESSAGE( "INode_Impl::InStreamPort ERROR !IsDataStream " ) ;
299 else if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
300 if ( anInPort == NULL ) {
301 anInPort = DataFlowNode()->ComputingNode()->AddInDataStreamPort( aParameterName , aParameterType , aDependency , SUPERV::DataStreamParameter ) ;
302 InPortCreated = true ;
306 Inobject = SUPERV::StreamPort::_narrow( anInPort->ObjRef() ) ;
307 if ( CORBA::is_nil( Inobject ) ) {
308 myInStreamPort = new StreamPort_Impl( _Orb , _Poa , _ContId ,
309 instanceName() , interfaceName() ,
312 (GraphBase::Port * ) anInPort ,
314 if ( myInStreamPort ) {
315 PortableServer::ObjectId * id = myInStreamPort->getId() ;
316 CORBA::Object_var obj = _poa->id_to_reference(*id) ;
317 Inobject = SUPERV::StreamPort::_narrow(obj) ;
318 anInPort->ObjRef( SUPERV::StreamPort::_duplicate( Inobject ) ) ;
324 // if ( !CORBA::is_nil( Inobject ) && InPortCreated &&
325 // ( DataFlowNode()->IsLoopNode() || DataFlowNode()->IsEndLoopNode() ||
326 // DataFlowNode()->IsEndSwitchNode() ) ) {
327 // Outobject = OutPort( aParameterName , aParameterType ) ;
328 // if ( DataFlowNode()->IsLoopNode() ) {
329 // LNode_Impl * myLoopNode = (LNode_Impl * ) this ;
330 // InEndobject = myLoopNode->Coupled()->InPort( aParameterName , aParameterType ) ;
331 // DataFlowEditor()->AddLink( Outobject->Node()->Name() , Outobject->Name() ,
332 // InEndobject->Node()->Name() , InEndobject->Name() ) ;
335 DataFlowEditor()->UnValid() ;
337 return SUPERV::StreamPort::_duplicate( Inobject ) ;
340 SUPERV::StreamPort_ptr INode_Impl::OutStreamPort( const char * aParameterName ,
341 const char * aParameterType ,
342 const SALOME_ModuleCatalog::DataStreamDependency aDependency ) {
343 StreamPort_Impl * myOutStreamPort = NULL ;
344 SUPERV::StreamPort_ptr Outobject = SUPERV::StreamPort::_nil() ;
345 if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
346 MESSAGE( "INode_Impl::OutStreamPort " << DataFlowNode()->Name() << "->AddOutPort( " << aParameterName << " , "
347 << aParameterType << " )" ) ;
348 GraphBase::OutPort * anOutPort = DataFlowNode()->GetChangeOutPort( aParameterName ) ;
349 if ( anOutPort && !anOutPort->IsDataStream() ) {
350 MESSAGE( "INode_Impl::OutStreamPort ERROR !IsDataStream " ) ;
352 else if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
353 if ( anOutPort == NULL ) {
354 anOutPort = DataFlowNode()->ComputingNode()->AddOutDataStreamPort( aParameterName , aParameterType , aDependency , SUPERV::DataStreamParameter ) ;
358 Outobject = SUPERV::StreamPort::_narrow( anOutPort->ObjRef() ) ;
359 if ( CORBA::is_nil( Outobject ) ) {
360 //JR 30.03.2005 const CORBA::Any * anAny = anOutPort->Value() ;
361 const CORBA::Any anAny = anOutPort->Value() ;
362 myOutStreamPort = new StreamPort_Impl( _Orb , _Poa , _ContId ,
363 instanceName() , interfaceName() ,
366 (GraphBase::Port * ) anOutPort ,
369 if ( myOutStreamPort ) {
370 PortableServer::ObjectId * id = myOutStreamPort->getId() ;
371 CORBA::Object_var obj = _poa->id_to_reference(*id) ;
372 Outobject = SUPERV::StreamPort::_narrow(obj) ;
373 anOutPort->ObjRef( SUPERV::StreamPort::_duplicate( Outobject ) ) ;
378 DataFlowEditor()->UnValid() ;
380 return SUPERV::StreamPort::_duplicate( Outobject );