1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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 // SUPERV Supervision : contains the implementation of interfaces of SuperVision described in SUPERV.idl
23 // File : INode_Impl.cxx
24 // Author : Jean Rahuel
33 //#include "utilities.h"
35 #include "LNode_Impl.hxx"
37 INode_Impl::INode_Impl( CORBA::ORB_ptr orb ,
38 PortableServer::POA_ptr poa ,
39 PortableServer::ObjectId * contId ,
40 const char *instanceName ,
41 const char *interfaceName ,
42 const char *aDataFlowName ,
43 const SUPERV::KindOfNode aKindOfNode ) :
44 // Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
45 CNode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowName , aKindOfNode ) {
46 // MESSAGE("INode_Impl::INode_Impl activate object instanceName("
47 // << instanceName << ") interfaceName(" << interfaceName << ") --> "
48 // << hex << (void *) this << dec )
50 // _id = _poa->activate_object(_thisObj);
51 // MESSAGE( "INode_Impl::INode_Impl " << aDataFlowName );
52 // beginService( "INode_Impl::INode_Impl" );
53 _Orb = CORBA::ORB::_duplicate(orb);
56 // endService( "INode_Impl::INode_Impl" );
59 INode_Impl::INode_Impl() {
62 INode_Impl::INode_Impl( CORBA::ORB_ptr orb ,
63 PortableServer::POA_ptr poa ,
64 PortableServer::ObjectId * contId ,
65 const char *instanceName ,
66 const char *interfaceName ,
67 GraphEditor::DataFlow * aDataFlowEditor ,
68 const char * FuncName ,
69 const SUPERV::ListOfStrings & aPythonFunction ,
70 const SUPERV::KindOfNode NodeKindOfNode ) :
71 // Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
72 CNode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowEditor , SALOME_ModuleCatalog::Service() , FuncName , NodeKindOfNode , FuncName , aPythonFunction ) {
73 // beginService( "INode_Impl::INode_Impl" );
75 // cout << "INode_Impl::CNode_Impl " << (void *) FuncName << " " << FuncName
76 // << " " << strlen( FuncName ) << endl ;
78 if ( NodeKindOfNode == SUPERV::InLineNode ) {
79 // MESSAGE( "INode_Impl::INode_Impl " << FuncName << " _poa->activate_object" );
81 _id = _poa->activate_object(_thisObj);
83 // MESSAGE("INode_Impl::INode_Impl " << FuncName << " " << strlen( FuncName ) ) ;
84 _Orb = CORBA::ORB::_duplicate(orb);
87 // DataFlowNode()->SetPythonFunction( FuncName , aPythonFunction ) ;
88 // endService( "INode_Impl::INode_Impl" );
91 INode_Impl::INode_Impl( CORBA::ORB_ptr orb ,
92 PortableServer::POA_ptr poa ,
93 PortableServer::ObjectId * contId ,
94 const char *instanceName ,
95 const char *interfaceName ,
96 GraphEditor::DataFlow * aDataFlowEditor ,
97 const GraphBase::ListOfFuncName FuncName ,
98 const GraphBase::ListOfPythonFunctions aPythonFunction ,
99 const SUPERV::KindOfNode NodeKindOfNode ) :
100 // Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
101 CNode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowEditor , SALOME_ModuleCatalog::Service() , FuncName[0].c_str() , NodeKindOfNode , FuncName , aPythonFunction ) {
102 // beginService( "INode_Impl::INode_Impl" );
103 if ( NodeKindOfNode == SUPERV::InLineNode ) {
104 // MESSAGE( "INode_Impl::INode_Impl " << FuncName[0] << " _poa->activate_object" );
106 _id = _poa->activate_object(_thisObj);
108 // MESSAGE("INode_Impl::INode_Impl " << FuncName[0].c_str() << " " << strlen( FuncName[0].c_str() ) ) ;
109 _Orb = CORBA::ORB::_duplicate(orb);
112 // DataFlowNode()->SetPythonFunction( FuncName , aPythonFunction ) ;
113 // endService( "INode_Impl::INode_Impl" );
116 INode_Impl::INode_Impl( CORBA::ORB_ptr orb ,
117 PortableServer::POA_ptr poa ,
118 PortableServer::ObjectId * contId ,
119 const char *instanceName ,
120 const char *interfaceName ,
121 GraphEditor::DataFlow * aDataFlowEditor ,
122 GraphEditor::InNode * aDataFlowNode ) :
123 // Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
124 CNode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowEditor , aDataFlowNode ) {
125 // beginService( "INode_Impl::INode_Impl" );
126 if ( DataFlowNode() && DataFlowNode()->IsInLineNode() ) {
127 // MESSAGE( "INode_Impl::INode_Impl " << DataFlowNode()->PyFuncName()
128 // << " _poa->activate_object" );
130 _id = _poa->activate_object(_thisObj);
133 // MESSAGE( "INode_Impl::INode_Impl NO _poa->activate_object" );
135 _Orb = CORBA::ORB::_duplicate(orb);
138 // endService( "INode_Impl::INode_Impl" );
141 INode_Impl::~INode_Impl() {
142 beginService( "INode_Impl::~INode_Impl" );
143 endService( "INode_Impl::~INode_Impl" );
146 void INode_Impl::destroy() {
147 beginService( "INode_Impl::Destroy" );
148 if ( DataFlowEditor()->IsEditing() ) {
150 _poa->deactivate_object(*_id) ;
151 // CORBA::release(_poa) ;
153 // _thisObj->_remove_ref();
156 MESSAGE("INode_Impl::destroy ERROR ") ;
159 endService( "INode_Impl::Destroy" );
162 bool INode_Impl::Delete() {
163 // beginService( "INode_Impl::Delete" );
164 bool RetVal = false ;
165 if ( DataFlowEditor()->IsEditing() ) {
167 RetVal = DataFlowEditor()->RemoveNode( Name() ) ;
169 DataFlowEditor()->UnValid() ;
171 // endService( "INode_Impl::Delete" );
175 void INode_Impl::SetPyFunction( const char * FuncName ,
176 const SUPERV::ListOfStrings & aPyFunction ) {
177 beginService( "INode_Impl::SetPyFunction" );
178 if ( DataFlowEditor()->IsEditing() ) {
179 DataFlowNode()->SetPythonFunction( FuncName , aPyFunction ) ;
181 endService( "INode_Impl::SetPyFunction" );
185 SUPERV::ListOfStrings * INode_Impl::PyFunction() {
186 beginService( "INode_Impl::PyFunction" );
187 SUPERV::ListOfStrings * aPyFunc = NULL ;
188 if ( DataFlowEditor()->IsEditing() ) {
189 aPyFunc = new SUPERV::ListOfStrings( *DataFlowNode()->PythonFunction() ) ;
192 aPyFunc = new SUPERV::ListOfStrings() ;
194 endService( "INode_Impl::PyFunction" );
198 char * INode_Impl::PyFuncName() {
199 return CORBA::string_dup( DataFlowNode()->PyFuncName() ) ;
202 SUPERV::Port_ptr INode_Impl::InPort( const char *aParameterName ,
203 const char *aParameterType ) {
204 SUPERV::Port_ptr Inobject = SUPERV::Port::_nil() ;
205 SUPERV::Port_ptr Outobject = SUPERV::Port::_nil() ;
206 SUPERV::Port_ptr InEndobject = SUPERV::Port::_nil() ;
207 Port_Impl * myInPort = NULL ;
208 bool InPortCreated = false ;
209 // MESSAGE( "CNode_Impl::InPort " << DataFlowNode()->Name() << "->AddInPort( " << aParameterName << " , "
210 // << aParameterType << " )" ) ;
211 GraphBase::InPort * anInPort = DataFlowNode()->GetChangeInPort( aParameterName ) ;
212 if ( anInPort == NULL ) {
213 anInPort = DataFlowNode()->AddInPort( aParameterName , aParameterType , SUPERV::InLineParameter ) ;
214 InPortCreated = true ;
217 Inobject = anInPort->ObjRef() ;
218 if ( CORBA::is_nil( Inobject ) ) {
219 myInPort = new Port_Impl( _Orb , _Poa , _ContId ,
220 instanceName() , interfaceName() ,
223 (GraphBase::Port * ) anInPort ,
226 PortableServer::ObjectId * id = myInPort->getId() ;
227 CORBA::Object_var obj = _poa->id_to_reference(*id) ;
228 Inobject = SUPERV::Port::_narrow(obj) ;
229 //JR 02.09.2005 : set of objref is better
230 anInPort->ObjRef( Inobject ) ;
235 if ( !CORBA::is_nil( Inobject ) && InPortCreated &&
236 ( DataFlowNode()->IsLoopNode() || DataFlowNode()->IsEndLoopNode() ) ) {
237 // || DataFlowNode()->IsEndSwitchNode() ) ) {
238 Outobject = OutPort( aParameterName , aParameterType ) ;
239 // ==> The OutPort (and ObjRef) with the same name is created in the LoopNode
240 if ( DataFlowNode()->IsLoopNode() ) {
241 LNode_Impl * myLoopNode = (LNode_Impl * ) this ;
242 InEndobject = myLoopNode->Coupled()->InPort( aParameterName , aParameterType ) ;
243 // ==> The In/OutPort (and ObjRef) with the same name are created in the EndLoopNode
244 DataFlowEditor()->AddLink( Outobject->Node()->Name() , Outobject->Name() ,
245 InEndobject->Node()->Name() , InEndobject->Name() ) ;
248 DataFlowEditor()->UnValid() ;
249 return SUPERV::Port::_duplicate( Inobject ) ;
252 SUPERV::Port_ptr INode_Impl::OutPort( const char *aParameterName ,
253 const char *aParameterType ) {
254 Port_Impl * myOutPort = NULL ;
255 SUPERV::Port_ptr Outobject = SUPERV::Port::_nil() ;
256 // MESSAGE( "CNode_Impl::OutPort " << DataFlowNode()->Name() << "->AddOutPort( " << aParameterName << " , "
257 // << aParameterType << " )" ) ;
258 GraphBase::OutPort * anOutPort = DataFlowNode()->GetChangeOutPort( aParameterName ) ;
259 if ( anOutPort == NULL ) {
260 anOutPort = DataFlowNode()->AddOutPort( aParameterName , aParameterType , SUPERV::InLineParameter ) ;
263 Outobject = anOutPort->ObjRef() ;
264 if ( CORBA::is_nil( Outobject ) ) {
265 //JR 30.03.2005 const CORBA::Any * anAny = anOutPort->Value() ;
266 const CORBA::Any anAny = anOutPort->Value() ;
267 myOutPort = new Port_Impl( _Orb , _Poa , _ContId ,
268 instanceName() , interfaceName() ,
271 (GraphBase::Port * ) anOutPort ,
275 PortableServer::ObjectId * id = myOutPort->getId() ;
276 CORBA::Object_var obj = _poa->id_to_reference(*id) ;
277 Outobject = SUPERV::Port::_narrow(obj) ;
278 //JR 02.09.2005 : set of objref is better
279 anOutPort->ObjRef( Outobject ) ;
283 DataFlowEditor()->UnValid() ;
284 return SUPERV::Port::_duplicate( Outobject );
287 SUPERV::StreamPort_ptr INode_Impl::InStreamPort( const char * aParameterName ,
288 const char * aParameterType ,
289 const SALOME_ModuleCatalog::DataStreamDependency aDependency ) {
290 SUPERV::StreamPort_ptr Inobject = SUPERV::StreamPort::_nil() ;
291 if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
292 StreamPort_Impl * myInStreamPort = NULL ;
293 bool InPortCreated = false ;
294 MESSAGE( "INode_Impl::InStreamPort " << DataFlowNode()->Name() << "->AddInPort( " << aParameterName << " , "
295 << aParameterType << " )" ) ;
296 GraphBase::InPort * anInPort = DataFlowNode()->GetChangeInPort( aParameterName ) ;
297 if ( anInPort && !anInPort->IsDataStream() ) {
298 MESSAGE( "INode_Impl::InStreamPort ERROR !IsDataStream " ) ;
300 else if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
301 if ( anInPort == NULL ) {
302 anInPort = DataFlowNode()->ComputingNode()->AddInDataStreamPort( aParameterName , aParameterType , aDependency , SUPERV::DataStreamParameter ) ;
303 InPortCreated = true ;
307 Inobject = SUPERV::StreamPort::_narrow( anInPort->ObjRef() ) ;
308 if ( CORBA::is_nil( Inobject ) ) {
309 myInStreamPort = new StreamPort_Impl( _Orb , _Poa , _ContId ,
310 instanceName() , interfaceName() ,
313 (GraphBase::Port * ) anInPort ,
315 if ( myInStreamPort ) {
316 PortableServer::ObjectId * id = myInStreamPort->getId() ;
317 CORBA::Object_var obj = _poa->id_to_reference(*id) ;
318 Inobject = SUPERV::StreamPort::_narrow(obj) ;
319 anInPort->ObjRef( SUPERV::StreamPort::_duplicate( Inobject ) ) ;
325 // if ( !CORBA::is_nil( Inobject ) && InPortCreated &&
326 // ( DataFlowNode()->IsLoopNode() || DataFlowNode()->IsEndLoopNode() ||
327 // DataFlowNode()->IsEndSwitchNode() ) ) {
328 // Outobject = OutPort( aParameterName , aParameterType ) ;
329 // if ( DataFlowNode()->IsLoopNode() ) {
330 // LNode_Impl * myLoopNode = (LNode_Impl * ) this ;
331 // InEndobject = myLoopNode->Coupled()->InPort( aParameterName , aParameterType ) ;
332 // DataFlowEditor()->AddLink( Outobject->Node()->Name() , Outobject->Name() ,
333 // InEndobject->Node()->Name() , InEndobject->Name() ) ;
336 DataFlowEditor()->UnValid() ;
338 return SUPERV::StreamPort::_duplicate( Inobject ) ;
341 SUPERV::StreamPort_ptr INode_Impl::OutStreamPort( const char * aParameterName ,
342 const char * aParameterType ,
343 const SALOME_ModuleCatalog::DataStreamDependency aDependency ) {
344 StreamPort_Impl * myOutStreamPort = NULL ;
345 SUPERV::StreamPort_ptr Outobject = SUPERV::StreamPort::_nil() ;
346 if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
347 MESSAGE( "INode_Impl::OutStreamPort " << DataFlowNode()->Name() << "->AddOutPort( " << aParameterName << " , "
348 << aParameterType << " )" ) ;
349 GraphBase::OutPort * anOutPort = DataFlowNode()->GetChangeOutPort( aParameterName ) ;
350 if ( anOutPort && !anOutPort->IsDataStream() ) {
351 MESSAGE( "INode_Impl::OutStreamPort ERROR !IsDataStream " ) ;
353 else if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
354 if ( anOutPort == NULL ) {
355 anOutPort = DataFlowNode()->ComputingNode()->AddOutDataStreamPort( aParameterName , aParameterType , aDependency , SUPERV::DataStreamParameter ) ;
359 Outobject = SUPERV::StreamPort::_narrow( anOutPort->ObjRef() ) ;
360 if ( CORBA::is_nil( Outobject ) ) {
361 //JR 30.03.2005 const CORBA::Any * anAny = anOutPort->Value() ;
362 const CORBA::Any anAny = anOutPort->Value() ;
363 myOutStreamPort = new StreamPort_Impl( _Orb , _Poa , _ContId ,
364 instanceName() , interfaceName() ,
367 (GraphBase::Port * ) anOutPort ,
370 if ( myOutStreamPort ) {
371 PortableServer::ObjectId * id = myOutStreamPort->getId() ;
372 CORBA::Object_var obj = _poa->id_to_reference(*id) ;
373 Outobject = SUPERV::StreamPort::_narrow(obj) ;
374 anOutPort->ObjRef( SUPERV::StreamPort::_duplicate( Outobject ) ) ;
379 DataFlowEditor()->UnValid() ;
381 return SUPERV::StreamPort::_duplicate( Outobject );