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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : Port_Impl.cxx
25 // Author : Jean Rahuel
35 //#include "utilities.h"
37 #include "Graph_Impl.hxx"
38 #include "Port_Impl.hxx"
40 Port_Impl::Port_Impl( CORBA::ORB_ptr orb ,
41 PortableServer::POA_ptr poa ,
42 PortableServer::ObjectId * contId ,
43 const char *instanceName ,
44 const char *interfaceName ,
45 GraphEditor::DataFlow * DataFlowEditor ,
46 GraphEditor::InNode * DataFlowNode ,
47 GraphBase::Port * DataFlowPort ,
49 const CORBA::Any * anAny ) :
50 Value_Impl(orb, poa, contId, instanceName, interfaceName,
51 DataFlowEditor , DataFlowNode , DataFlowPort->PortName(), anAny ,
53 // MESSAGE("Port_Impl::Port_Impl activate object instanceName("
54 // << instanceName << ") interfaceName(" << interfaceName
55 // << ") IsDataStream " << DataFlowPort->IsDataStream() )
56 _Orb = CORBA::ORB::_duplicate(orb);
59 if ( !DataFlowPort->IsDataStream() ) {
61 _id = _poa->activate_object(_thisObj) ;
63 _DataFlowEditor = DataFlowEditor ;
64 _DataFlowNode = DataFlowNode ;
65 _DataFlowPort = DataFlowPort ;
66 _InputPort = InputPort ;
67 InPort( _InputPort ) ;
70 Port_Impl::Port_Impl( CORBA::ORB_ptr orb ,
71 PortableServer::POA_ptr poa ,
72 PortableServer::ObjectId * contId ,
73 const char *instanceName ,
74 const char *interfaceName ,
75 GraphEditor::DataFlow * DataFlowEditor ,
76 GraphEditor::InNode * DataFlowNode ,
77 GraphBase::Port * DataFlowPort ,
79 Value_Impl(orb, poa, contId, instanceName, interfaceName,
80 DataFlowEditor , DataFlowNode , DataFlowPort->PortName() , false ) {
81 char * nodename = DataFlowEditor->Graph()->Name() ;
83 nodename = DataFlowNode->Name() ;
85 // MESSAGE("Port_Impl::Port_Impl activate object instanceName("
86 // << instanceName << ") interfaceName(" << interfaceName
87 // << ") " << nodename << "(" << DataFlowPort->PortName()
88 // << ") IsDataStream " << DataFlowPort->IsDataStream() ) ;
89 _Orb = CORBA::ORB::_duplicate(orb);
92 if ( !DataFlowPort->IsDataStream() ) {
94 _id = _poa->activate_object(_thisObj) ;
96 _DataFlowEditor = DataFlowEditor ;
97 _DataFlowNode = DataFlowNode ;
98 _DataFlowPort = DataFlowPort ;
99 _InputPort = InputPort ;
100 InPort( _InputPort ) ;
103 Port_Impl::Port_Impl() {
106 Port_Impl::~Port_Impl() {
107 beginService( "Port_Impl::~Port_Impl" );
108 endService( "Port_Impl::~Port_Impl" );
111 void Port_Impl::destroy() {
112 beginService( "Port_Impl::destroy" );
113 bool destroyed = false ;
114 if ( _DataFlowNode->IsOneOfInLineNodes() ) {
116 GraphBase::InPort * anInPort = (GraphBase::InPort * ) _DataFlowPort ;
117 if ( anInPort->GetOutPort() ) {
118 anInPort->GetOutPort()->RemoveInPort( anInPort ) ;
120 if ( _DataFlowNode->IsOneOfInLineNodes() ) {
121 _DataFlowNode->DelInPort( _DataFlowPort->PortName() ) ;
122 if ( _DataFlowNode->IsLoopNode() ) {
123 _DataFlowNode->DelOutPort( _DataFlowPort->PortName() ) ;
124 _DataFlowNode->CoupledNode()->DelInPort( _DataFlowPort->PortName() ) ;
125 _DataFlowNode->CoupledNode()->DelOutPort( _DataFlowPort->PortName() ) ;
132 else if ( _DataFlowNode->IsOneOfInLineNodes() && !_DataFlowNode->IsLoopNode() ) {
133 _DataFlowNode->DelOutPort( _DataFlowPort->PortName() ) ;
140 _DataFlowEditor->UnValid() ;
144 _poa->deactivate_object(*_id) ;
145 CORBA::release(_poa) ;
147 _thisObj->_remove_ref();
149 endService( "Port_Impl::destroy" );
152 void Port_Impl::Remove() {
153 beginService( "Port_Impl::Remove" );
154 _poa->deactivate_object(*_id) ;
155 CORBA::release(_poa) ;
157 _thisObj->_remove_ref();
158 endService( "Port_Impl::Remove" );
161 bool Port_Impl::Input( const SUPERV::Value_ptr aValue ) {
162 return Input( aValue->ToAny() ) ;
165 bool Port_Impl::Input( const CORBA::Any * anAny ) {
166 beginService( "Port_Impl::Input" );
167 bool RetVal = false ;
168 if ( _DataFlowEditor->Graph()->GraphMacroLevel() == 0 ) {
169 if ( _InputPort && _DataFlowEditor->IsEditing() ) {
171 Value_Impl::Input( anAny ) ;
172 RetVal = _DataFlowEditor->AddInputData( _DataFlowNode->Name() ,
173 _DataFlowPort->PortName() ,
176 else if ( _DataFlowEditor->IsExecuting() ) {
177 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
178 // if ( _DataFlowExecutor && ( _DataFlowExecutor->IsSuspended() ||
179 // _DataFlowExecutor->IsSuspended( _DataFlowNode->Name() ) ) ) {
180 if ( _DataFlowExecutor ) {
181 RetVal = _DataFlowExecutor->ChangeInputData( _DataFlowNode->Name() ,
182 _DataFlowPort->PortName() ,
188 MESSAGE( "Port_Impl::Input returns false _InputPort " << _InputPort << " IsEditing "
189 << _DataFlowEditor->IsEditing() << " Executor " << _DataFlowEditor->Executor() ) ;
191 endService( "Port_Impl::Input" );
195 char * Port_Impl::Name() {
196 // beginService( "Port_Impl::Name" ) ;
197 const char * RetVal = _DataFlowPort->PortName() ;
198 // endService( "Port_Impl::Name" ) ;
199 return CORBA::string_dup( RetVal ) ;
202 char * Port_Impl::Type() {
203 // beginService( "Port_Impl::Type" ) ;
204 const char * RetVal = _DataFlowPort->PortType() ;
205 // endService( "Port_Impl::Type" ) ;
206 return CORBA::string_dup( RetVal ) ;
209 SUPERV::CNode_ptr Port_Impl::Node() {
211 SUPERV::CNode_var iobject ;
212 if ( _DataFlowNode ) {
213 // MESSAGE( "Port_Impl::Node " << _DataFlowNode->Name() ) ;
214 iobject = SUPERV::CNode::_narrow( _DataFlowNode->ObjRef() ) ;
215 if ( CORBA::is_nil( iobject ) ) {
217 beginService( "Port_Impl::Node" ) ;
220 PortableServer::ObjectId * id ;
221 CORBA::Object_var obj ;
222 if ( _DataFlowNode->IsComputingNode() ) {
223 CNode_Impl * myNode = NULL ;
224 myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
225 instanceName() , interfaceName() ,
228 id = myNode->getId() ;
229 obj = _poa->id_to_reference(*id);
230 iobject = SUPERV::CNode::_narrow( obj ) ;
231 myNode->SetObjRef( SUPERV::CNode::_duplicate( iobject ) ) ;
233 else if ( _DataFlowNode->IsFactoryNode() ) {
234 FNode_Impl * myNode = NULL ;
235 myNode = new FNode_Impl( _Orb , _Poa , _ContId ,
236 instanceName() , interfaceName() ,
239 id = myNode->getId() ;
240 obj = _poa->id_to_reference(*id);
241 SUPERV::FNode_var Fiobject = SUPERV::FNode::_narrow( obj ) ;
242 iobject = SUPERV::CNode::_narrow( Fiobject ) ;
243 myNode->SetObjRef( SUPERV::FNode::_duplicate( Fiobject ) ) ;
245 else if ( _DataFlowNode->IsInLineNode() ) {
246 INode_Impl * myNode = NULL ;
247 myNode = new INode_Impl( _Orb , _Poa , _ContId ,
248 instanceName() , interfaceName() ,
251 id = myNode->getId() ;
252 obj = _poa->id_to_reference(*id);
253 SUPERV::INode_var Iiobject = SUPERV::INode::_narrow( obj ) ;
254 iobject = SUPERV::CNode::_narrow( Iiobject ) ;
255 myNode->SetObjRef( SUPERV::INode::_duplicate( Iiobject ) ) ;
257 else if ( _DataFlowNode->IsGOTONode() ) {
258 GNode_Impl * myNode = NULL ;
259 myNode = new GNode_Impl( _Orb , _Poa , _ContId ,
260 instanceName() , interfaceName() ,
263 id = myNode->getId() ;
264 obj = _poa->id_to_reference(*id);
265 SUPERV::GNode_var Giobject = SUPERV::GNode::_narrow( obj ) ;
266 iobject = SUPERV::CNode::_narrow( Giobject ) ;
267 myNode->SetObjRef( SUPERV::GNode::_duplicate( Giobject ) ) ;
269 else if ( _DataFlowNode->IsLoopNode() ) {
270 LNode_Impl * myNode = NULL ;
271 myNode = new LNode_Impl( _Orb , _Poa , _ContId ,
272 instanceName() , interfaceName() ,
275 id = myNode->getId() ;
276 obj = _poa->id_to_reference(*id);
277 SUPERV::LNode_var Liobject = SUPERV::LNode::_narrow( obj ) ;
278 iobject = SUPERV::CNode::_narrow( Liobject ) ;
279 myNode->SetObjRef( SUPERV::LNode::_duplicate( Liobject ) ) ;
281 else if ( _DataFlowNode->IsEndLoopNode() ) {
282 ELNode_Impl * myNode = NULL ;
283 myNode = new ELNode_Impl( _Orb , _Poa , _ContId ,
284 instanceName() , interfaceName() ,
287 id = myNode->getId() ;
288 obj = _poa->id_to_reference(*id);
289 SUPERV::ELNode_var ELiobject = SUPERV::ELNode::_narrow( obj ) ;
290 iobject = SUPERV::CNode::_narrow( ELiobject ) ;
291 myNode->SetObjRef( SUPERV::ELNode::_duplicate( ELiobject ) ) ;
293 else if ( _DataFlowNode->IsSwitchNode() ) {
294 SNode_Impl * myNode = NULL ;
295 myNode = new SNode_Impl( _Orb , _Poa , _ContId ,
296 instanceName() , interfaceName() ,
299 id = myNode->getId() ;
300 obj = _poa->id_to_reference(*id);
301 SUPERV::SNode_var Siobject = SUPERV::SNode::_narrow( obj ) ;
302 iobject = SUPERV::CNode::_narrow( Siobject ) ;
303 myNode->SetObjRef( SUPERV::SNode::_duplicate( Siobject ) ) ;
305 else if ( _DataFlowNode->IsEndSwitchNode() ) {
306 ESNode_Impl * myNode = NULL ;
307 myNode = new ESNode_Impl( _Orb , _Poa , _ContId ,
308 instanceName() , interfaceName() ,
311 id = myNode->getId() ;
312 obj = _poa->id_to_reference(*id);
313 SUPERV::ESNode_var ESiobject = SUPERV::ESNode::_narrow( obj ) ;
314 iobject = SUPERV::CNode::_narrow( ESiobject ) ;
315 myNode->SetObjRef( SUPERV::ESNode::_duplicate( ESiobject ) ) ;
319 // MESSAGE( "Port_Impl::Node known objref " << iobject->Name() ) ;
323 MESSAGE( "Port_Impl::GraphNode " << _DataFlowEditor->Graph()->Name() ) ;
324 iobject = SUPERV::CNode::_narrow( _DataFlowEditor->Graph()->ObjRef() ) ;
325 if ( CORBA::is_nil( iobject ) ) {
326 MESSAGE( "Port_Impl::GraphNode NilRef" ) ;
330 endService( "Port_Impl::Node" ) ;
332 return SUPERV::CNode::_duplicate( iobject ) ;
335 SUPERV::ListOfLinks * Port_Impl::Links() {
336 beginService( "Port_Impl::Links" ) ;
337 SUPERV::ListOfLinks_var RetVal = new SUPERV::ListOfLinks ;
338 RetVal = _DataFlowEditor->Graph()->ObjImpl()->Links( _DataFlowNode->ComputingNode() ,
339 _DataFlowPort->PortName() ) ;
340 MESSAGE( "Links of Node " << _DataFlowNode->ComputingNode()->Name()
341 << " and of Port " << _DataFlowPort->PortName()
342 << " _InputPort " << _InputPort ) ;
344 for ( i = 0 ; i < (int ) RetVal->length() ; i++ ) {
345 MESSAGE( "Link " << RetVal[i]->OutPort()->Node()->Name() << "("
346 << RetVal[i]->OutPort()->Name() << ") --> "
347 << RetVal[i]->InPort()->Node()->Name() << "("
348 << RetVal[i]->InPort()->Name() << ")" ) ;
350 endService( "Port_Impl::Links" ) ;
351 return ( RetVal._retn() ) ;
354 SUPERV::Link_ptr Port_Impl::Link() {
356 SUPERV::Link_var iobject = SUPERV::Link::_nil() ;
357 if ( _DataFlowNode->IsEndSwitchNode() ) {
358 beginService( "Port_Impl::Link" ) ;
360 SUPERV::ListOfLinks_var Links = new SUPERV::ListOfLinks ;
361 // cout << "Port_Impl::Link " << _DataFlowNode->Name() << " "
362 // << _DataFlowPort->PortName() << endl ;
363 Links = _DataFlowEditor->Graph()->ObjImpl()->Links( _DataFlowNode->ComputingNode() ,
364 _DataFlowPort->PortName() ) ;
365 if ( Links->length() ) {
366 iobject = Links[ 0 ] ;
370 char * FromNodeName = NULL ;
371 char * FromServiceParameterName = NULL ;
372 bool status = _DataFlowEditor->GetLink( _DataFlowNode->Name() ,
373 _DataFlowPort->PortName() ,
375 & FromServiceParameterName ) ;
377 // cout << "Port_Impl::Link " << FromNodeName << "("
378 // << FromServiceParameterName << ") --> " << _DataFlowNode->Name()
379 // << "(" << _DataFlowPort->PortName() << ")" << endl ;
380 // SUPERV::Port_ptr theOutPort = Port( FromServiceParameterName ) ;
382 GraphBase::InPort * anInPort = _DataFlowNode->GetChangeInPort( _DataFlowPort->PortName() ) ;
383 if ( anInPort->GetOutPort() ) {
384 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
385 if ( _DataFlowNode->IsEndLoopNode() && !strcmp( _DataFlowNode->CoupledNode()->Name() ,
386 anOutPort->NodeName() ) ) {
387 // MESSAGE( "Link " << anOutPort->NodeName() << "("
388 // << anOutPort->PortName() << ") --> " << _DataFlowNode->Name() << "("
389 // << anInPort->PortName() << ")" << " ignored" ) ;
391 else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
393 beginService( "Port_Impl::Link" ) ;
397 Link_Impl * myLink = new Link_Impl( _Orb , _Poa , _ContId ,
398 instanceName() , interfaceName() ,
401 _DataFlowPort->PortName() ,
402 (GraphEditor::InNode * ) _DataFlowEditor->Graph()->GetChangeGraphNode( FromNodeName )->GetInNode() ,
403 FromServiceParameterName ,
404 false , true , Success ) ;
406 PortableServer::ObjectId * id = myLink->getId() ;
407 CORBA::Object_var obj = _poa->id_to_reference(*id);
408 iobject = SUPERV::Link::_narrow(obj) ;
409 anOutPort->AddInPortObjRef( anInPort , SUPERV::Link::_duplicate( iobject ) ) ;
413 iobject = anOutPort->InPortObjRef( anInPort ) ;
419 MESSAGE( "Link " << iobject->OutPort()->Node()->Name() << "( " << iobject->OutPort()->Name() << " ) --> "
420 << iobject->InPort()->Node()->Name() << "( " << iobject->InPort()->Name() << " ) " ) ;
421 endService( "Port_Impl::Link" ) ;
423 return SUPERV::Link::_duplicate( iobject ) ;
426 bool Port_Impl::IsInput() {
427 // beginService( "Port_Impl::IsInput" ) ;
428 bool RetVal = _InputPort ;
429 // MESSAGE( Name() << "IsInput() " << _InputPort ) ;
430 // endService( "Port_Impl::IsInput" ) ;
434 bool Port_Impl::IsLinked() {
435 // beginService( "Port_Impl::IsLinked" ) ;
436 bool RetVal = false ;
437 if ( _DataFlowNode ) {
438 GraphBase::InPort * anInPort = _DataFlowNode->GetChangeInPort( _DataFlowPort->PortName() ) ;
439 GraphBase::OutPort * anOutPort = NULL ;
441 anOutPort = anInPort->GetOutPort() ;
443 if ( _DataFlowNode->IsEndLoopNode() && anOutPort &&
444 !strcmp( _DataFlowNode->CoupledNode()->Name() , anOutPort->NodeName() ) ) {
445 // MESSAGE( "Link " << anOutPort->NodeName() << "("
446 // << anOutPort->PortName() << ") --> " << _DataFlowNode->Name() << "("
447 // << anInPort->PortName() << ")" << " ignored" ) ;
450 RetVal = _DataFlowNode->IsLinked( _DataFlowPort->PortName() ) ;
453 // endService( "Port_Impl::IsLinked" ) ;
457 SUPERV::KindOfPort Port_Impl::Kind() {
458 // beginService( "Port_Impl::Kind" ) ;
459 SUPERV::KindOfPort RetVal = _DataFlowPort->Kind() ;
460 // endService( "Port_Impl::Kind" ) ;
464 void Port_Impl::SetKind( SUPERV::KindOfPort aKindOfPort ) {
465 // beginService( "Port_Impl::SetKind" ) ;
466 _DataFlowPort->Kind( aKindOfPort ) ;
467 // endService( "Port_Impl::SetKind" ) ;
470 bool Port_Impl::IsParam() {
471 // beginService( "Port_Impl::IsParam" ) ;
472 bool RetVal = _DataFlowPort->IsParam() ;
473 // endService( "Port_Impl::IsParam" ) ;
477 bool Port_Impl::IsGate() {
478 // beginService( "Port_Impl::IsGate" ) ;
479 bool RetVal = _DataFlowPort->IsGate() ;
480 // endService( "Port_Impl::IsGate" ) ;
484 bool Port_Impl::IsInLine() {
485 // beginService( "Port_Impl::IsInLine" ) ;
486 // bool RetVal = _DataFlowPort->IsBus() ;
487 bool RetVal = _DataFlowPort->IsInLine() ;
488 // endService( "Port_Impl::IsInLine" ) ;
492 bool Port_Impl::IsLoop() {
493 // beginService( "Port_Impl::IsLoop" ) ;
494 bool RetVal = _DataFlowPort->IsLoop() ;
495 // endService( "Port_Impl::IsLoop" ) ;
499 bool Port_Impl::IsSwitch() {
500 // beginService( "Port_Impl::IsSwitch" ) ;
501 bool RetVal = _DataFlowPort->IsSwitch() ;
502 // endService( "Port_Impl::IsSwitch" ) ;
506 bool Port_Impl::IsEndSwitch() {
507 // beginService( "Port_Impl::IsEndSwitch" ) ;
508 bool RetVal = _DataFlowPort->IsEndSwitch() ;
509 // endService( "Port_Impl::IsEndSwitch" ) ;
513 bool Port_Impl::IsDataStream() {
514 // beginService( "Port_Impl::IsDataStream" ) ;
515 bool RetVal = _DataFlowPort->IsDataStream() ;
516 // endService( "Port_Impl::IsDataStream" ) ;
520 bool Port_Impl::HasInput() {
521 // beginService( "Port_Impl::" ) ;
522 bool RetVal = false ;
523 if ( _DataFlowNode ) {
524 RetVal = _DataFlowNode->HasInput( _DataFlowPort->PortName() ) ;
525 // cout << "Port_Impl::HasInput " << RetVal << " NodeName " << _DataFlowPort->NodeName() << " PortName "
526 // << _DataFlowPort->PortName() << endl ;
528 // endService( "Port_Impl::" ) ;
532 SUPERV::GraphState Port_Impl::State() {
533 // beginService( "Port_Impl::State" );
534 SUPERV::GraphState RetVal = SUPERV::EditingState ;
535 if ( _DataFlowEditor ) {
536 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
537 if ( _DataFlowExecutor ) {
538 RetVal = _DataFlowExecutor->State( _DataFlowPort->NodeName() ,
539 _DataFlowPort->PortName() ) ;
542 // endService( "Port_Impl::State" );
546 bool Port_Impl::IsDone() {
547 // beginService( "Port_Impl::IsDone" );
548 bool RetVal = false ;
549 if ( _DataFlowEditor ) {
550 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
551 if ( _DataFlowExecutor ) {
552 RetVal = _DataFlowExecutor->IsDone( _DataFlowPort->NodeName() ,
553 _DataFlowPort->PortName() ) ;
556 // endService( "Port_Impl::IsDone" );