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() ;
179 // asv: turn off Editor::_Executing flag
180 if ( _DataFlowExecutor->IsDone() ) {
181 _DataFlowEditor->Executing( false );
184 RetVal = _DataFlowExecutor->ChangeInputData( _DataFlowNode->Name() ,
185 _DataFlowPort->PortName() ,
191 MESSAGE( "Port_Impl::Input returns false _InputPort " << _InputPort << " IsEditing "
192 << _DataFlowEditor->IsEditing() << " Executor " << _DataFlowEditor->Executor() ) ;
194 endService( "Port_Impl::Input" );
198 char * Port_Impl::Name() {
199 // beginService( "Port_Impl::Name" ) ;
200 const char * RetVal = _DataFlowPort->PortName() ;
201 // endService( "Port_Impl::Name" ) ;
202 return CORBA::string_dup( RetVal ) ;
205 char * Port_Impl::Type() {
206 // beginService( "Port_Impl::Type" ) ;
207 const char * RetVal = _DataFlowPort->PortType() ;
208 // endService( "Port_Impl::Type" ) ;
209 return CORBA::string_dup( RetVal ) ;
212 SUPERV::CNode_ptr Port_Impl::Node() {
214 SUPERV::CNode_var iobject ;
215 if ( _DataFlowNode ) {
216 // MESSAGE( "Port_Impl::Node " << _DataFlowNode->Name() ) ;
217 iobject = SUPERV::CNode::_narrow( _DataFlowNode->ObjRef() ) ;
218 if ( CORBA::is_nil( iobject ) ) {
220 beginService( "Port_Impl::Node" ) ;
223 PortableServer::ObjectId * id ;
224 CORBA::Object_var obj ;
225 if ( _DataFlowNode->IsComputingNode() ) {
226 CNode_Impl * myNode = NULL ;
227 myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
228 instanceName() , interfaceName() ,
231 id = myNode->getId() ;
232 obj = _poa->id_to_reference(*id);
233 iobject = SUPERV::CNode::_narrow( obj ) ;
234 myNode->SetObjRef( SUPERV::CNode::_duplicate( iobject ) ) ;
236 else if ( _DataFlowNode->IsFactoryNode() ) {
237 FNode_Impl * myNode = NULL ;
238 myNode = new FNode_Impl( _Orb , _Poa , _ContId ,
239 instanceName() , interfaceName() ,
242 id = myNode->getId() ;
243 obj = _poa->id_to_reference(*id);
244 SUPERV::FNode_var Fiobject = SUPERV::FNode::_narrow( obj ) ;
245 iobject = SUPERV::CNode::_narrow( Fiobject ) ;
246 myNode->SetObjRef( SUPERV::FNode::_duplicate( Fiobject ) ) ;
248 else if ( _DataFlowNode->IsInLineNode() ) {
249 INode_Impl * myNode = NULL ;
250 myNode = new INode_Impl( _Orb , _Poa , _ContId ,
251 instanceName() , interfaceName() ,
254 id = myNode->getId() ;
255 obj = _poa->id_to_reference(*id);
256 SUPERV::INode_var Iiobject = SUPERV::INode::_narrow( obj ) ;
257 iobject = SUPERV::CNode::_narrow( Iiobject ) ;
258 myNode->SetObjRef( SUPERV::INode::_duplicate( Iiobject ) ) ;
260 else if ( _DataFlowNode->IsGOTONode() ) {
261 GNode_Impl * myNode = NULL ;
262 myNode = new GNode_Impl( _Orb , _Poa , _ContId ,
263 instanceName() , interfaceName() ,
266 id = myNode->getId() ;
267 obj = _poa->id_to_reference(*id);
268 SUPERV::GNode_var Giobject = SUPERV::GNode::_narrow( obj ) ;
269 iobject = SUPERV::CNode::_narrow( Giobject ) ;
270 myNode->SetObjRef( SUPERV::GNode::_duplicate( Giobject ) ) ;
272 else if ( _DataFlowNode->IsLoopNode() ) {
273 LNode_Impl * myNode = NULL ;
274 myNode = new LNode_Impl( _Orb , _Poa , _ContId ,
275 instanceName() , interfaceName() ,
278 id = myNode->getId() ;
279 obj = _poa->id_to_reference(*id);
280 SUPERV::LNode_var Liobject = SUPERV::LNode::_narrow( obj ) ;
281 iobject = SUPERV::CNode::_narrow( Liobject ) ;
282 myNode->SetObjRef( SUPERV::LNode::_duplicate( Liobject ) ) ;
284 else if ( _DataFlowNode->IsEndLoopNode() ) {
285 ELNode_Impl * myNode = NULL ;
286 myNode = new ELNode_Impl( _Orb , _Poa , _ContId ,
287 instanceName() , interfaceName() ,
290 id = myNode->getId() ;
291 obj = _poa->id_to_reference(*id);
292 SUPERV::ELNode_var ELiobject = SUPERV::ELNode::_narrow( obj ) ;
293 iobject = SUPERV::CNode::_narrow( ELiobject ) ;
294 myNode->SetObjRef( SUPERV::ELNode::_duplicate( ELiobject ) ) ;
296 else if ( _DataFlowNode->IsSwitchNode() ) {
297 SNode_Impl * myNode = NULL ;
298 myNode = new SNode_Impl( _Orb , _Poa , _ContId ,
299 instanceName() , interfaceName() ,
302 id = myNode->getId() ;
303 obj = _poa->id_to_reference(*id);
304 SUPERV::SNode_var Siobject = SUPERV::SNode::_narrow( obj ) ;
305 iobject = SUPERV::CNode::_narrow( Siobject ) ;
306 myNode->SetObjRef( SUPERV::SNode::_duplicate( Siobject ) ) ;
308 else if ( _DataFlowNode->IsEndSwitchNode() ) {
309 ESNode_Impl * myNode = NULL ;
310 myNode = new ESNode_Impl( _Orb , _Poa , _ContId ,
311 instanceName() , interfaceName() ,
314 id = myNode->getId() ;
315 obj = _poa->id_to_reference(*id);
316 SUPERV::ESNode_var ESiobject = SUPERV::ESNode::_narrow( obj ) ;
317 iobject = SUPERV::CNode::_narrow( ESiobject ) ;
318 myNode->SetObjRef( SUPERV::ESNode::_duplicate( ESiobject ) ) ;
322 // MESSAGE( "Port_Impl::Node known objref " << iobject->Name() ) ;
326 MESSAGE( "Port_Impl::GraphNode " << _DataFlowEditor->Graph()->Name() ) ;
327 iobject = SUPERV::CNode::_narrow( _DataFlowEditor->Graph()->ObjRef() ) ;
328 if ( CORBA::is_nil( iobject ) ) {
329 MESSAGE( "Port_Impl::GraphNode NilRef" ) ;
333 endService( "Port_Impl::Node" ) ;
335 return SUPERV::CNode::_duplicate( iobject ) ;
338 SUPERV::ListOfLinks * Port_Impl::Links() {
339 beginService( "Port_Impl::Links" ) ;
340 SUPERV::ListOfLinks_var RetVal = new SUPERV::ListOfLinks ;
341 RetVal = _DataFlowEditor->Graph()->ObjImpl()->Links( /*_DataFlowNode->ComputingNode() ,
342 _DataFlowPort->PortName()*/ ) ;
343 MESSAGE( "Links of Node " << _DataFlowNode->ComputingNode()->Name()
344 << " and of Port " << _DataFlowPort->PortName()
345 << " _InputPort " << _InputPort ) ;
347 for ( i = 0 ; i < (int ) RetVal->length() ; i++ ) {
348 MESSAGE( "Link " << RetVal[i]->OutPort()->Node()->Name() << "("
349 << RetVal[i]->OutPort()->Name() << ") --> "
350 << RetVal[i]->InPort()->Node()->Name() << "("
351 << RetVal[i]->InPort()->Name() << ")" ) ;
353 endService( "Port_Impl::Links" ) ;
354 return ( RetVal._retn() ) ;
357 SUPERV::Link_ptr Port_Impl::Link() {
359 SUPERV::Link_var iobject = SUPERV::Link::_nil() ;
360 if ( _DataFlowNode->IsEndSwitchNode() ) {
361 beginService( "Port_Impl::Link" ) ;
363 SUPERV::ListOfLinks_var Links = new SUPERV::ListOfLinks ;
364 // cout << "Port_Impl::Link " << _DataFlowNode->Name() << " "
365 // << _DataFlowPort->PortName() << endl ;
366 Links = _DataFlowEditor->Graph()->ObjImpl()->Links( /*_DataFlowNode->ComputingNode() ,
367 _DataFlowPort->PortName()*/ ) ;
368 if ( Links->length() ) {
369 iobject = Links[ 0 ] ;
373 char * FromNodeName = NULL ;
374 char * FromServiceParameterName = NULL ;
375 bool status = _DataFlowEditor->GetLink( _DataFlowNode->Name() ,
376 _DataFlowPort->PortName() ,
378 & FromServiceParameterName ) ;
380 // cout << "Port_Impl::Link " << FromNodeName << "("
381 // << FromServiceParameterName << ") --> " << _DataFlowNode->Name()
382 // << "(" << _DataFlowPort->PortName() << ")" << endl ;
383 // SUPERV::Port_ptr theOutPort = Port( FromServiceParameterName ) ;
385 GraphBase::InPort * anInPort = _DataFlowNode->GetChangeInPort( _DataFlowPort->PortName() ) ;
386 if ( anInPort->GetOutPort() ) {
387 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
388 if ( _DataFlowNode->IsEndLoopNode() && !strcmp( _DataFlowNode->CoupledNode()->Name() ,
389 anOutPort->NodeName() ) ) {
390 // MESSAGE( "Link " << anOutPort->NodeName() << "("
391 // << anOutPort->PortName() << ") --> " << _DataFlowNode->Name() << "("
392 // << anInPort->PortName() << ")" << " ignored" ) ;
394 else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
396 beginService( "Port_Impl::Link" ) ;
400 Link_Impl * myLink = new Link_Impl( _Orb , _Poa , _ContId ,
401 instanceName() , interfaceName() ,
404 _DataFlowPort->PortName() ,
405 (GraphEditor::InNode * ) _DataFlowEditor->Graph()->GetChangeGraphNode( FromNodeName )->GetInNode() ,
406 FromServiceParameterName ,
407 false , true , Success ) ;
409 PortableServer::ObjectId * id = myLink->getId() ;
410 CORBA::Object_var obj = _poa->id_to_reference(*id);
411 iobject = SUPERV::Link::_narrow(obj) ;
412 anOutPort->AddInPortObjRef( anInPort , SUPERV::Link::_duplicate( iobject ) ) ;
416 iobject = anOutPort->InPortObjRef( anInPort ) ;
422 MESSAGE( "Link " << iobject->OutPort()->Node()->Name() << "( " << iobject->OutPort()->Name() << " ) --> "
423 << iobject->InPort()->Node()->Name() << "( " << iobject->InPort()->Name() << " ) " ) ;
424 endService( "Port_Impl::Link" ) ;
426 return SUPERV::Link::_duplicate( iobject ) ;
429 bool Port_Impl::IsInput() {
430 // beginService( "Port_Impl::IsInput" ) ;
431 bool RetVal = _InputPort ;
432 // MESSAGE( Name() << "IsInput() " << _InputPort ) ;
433 // endService( "Port_Impl::IsInput" ) ;
437 bool Port_Impl::IsLinked() {
438 // beginService( "Port_Impl::IsLinked" ) ;
439 bool RetVal = false ;
440 if ( _DataFlowNode ) {
441 GraphBase::InPort * anInPort = _DataFlowNode->GetChangeInPort( _DataFlowPort->PortName() ) ;
442 GraphBase::OutPort * anOutPort = NULL ;
444 anOutPort = anInPort->GetOutPort() ;
446 if ( _DataFlowNode->IsEndLoopNode() && anOutPort &&
447 !strcmp( _DataFlowNode->CoupledNode()->Name() , anOutPort->NodeName() ) ) {
448 // MESSAGE( "Link " << anOutPort->NodeName() << "("
449 // << anOutPort->PortName() << ") --> " << _DataFlowNode->Name() << "("
450 // << anInPort->PortName() << ")" << " ignored" ) ;
453 RetVal = _DataFlowNode->IsLinked( _DataFlowPort->PortName() ) ;
456 // endService( "Port_Impl::IsLinked" ) ;
460 SUPERV::KindOfPort Port_Impl::Kind() {
461 // beginService( "Port_Impl::Kind" ) ;
462 SUPERV::KindOfPort RetVal = _DataFlowPort->Kind() ;
463 // endService( "Port_Impl::Kind" ) ;
467 void Port_Impl::SetKind( SUPERV::KindOfPort aKindOfPort ) {
468 // beginService( "Port_Impl::SetKind" ) ;
469 _DataFlowPort->Kind( aKindOfPort ) ;
470 // endService( "Port_Impl::SetKind" ) ;
473 bool Port_Impl::IsParam() {
474 // beginService( "Port_Impl::IsParam" ) ;
475 bool RetVal = _DataFlowPort->IsParam() ;
476 // endService( "Port_Impl::IsParam" ) ;
480 bool Port_Impl::IsGate() {
481 // beginService( "Port_Impl::IsGate" ) ;
482 bool RetVal = _DataFlowPort->IsGate() ;
483 // endService( "Port_Impl::IsGate" ) ;
487 bool Port_Impl::IsInLine() {
488 // beginService( "Port_Impl::IsInLine" ) ;
489 // bool RetVal = _DataFlowPort->IsBus() ;
490 bool RetVal = _DataFlowPort->IsInLine() ;
491 // endService( "Port_Impl::IsInLine" ) ;
495 bool Port_Impl::IsLoop() {
496 // beginService( "Port_Impl::IsLoop" ) ;
497 bool RetVal = _DataFlowPort->IsLoop() ;
498 // endService( "Port_Impl::IsLoop" ) ;
502 bool Port_Impl::IsSwitch() {
503 // beginService( "Port_Impl::IsSwitch" ) ;
504 bool RetVal = _DataFlowPort->IsSwitch() ;
505 // endService( "Port_Impl::IsSwitch" ) ;
509 bool Port_Impl::IsEndSwitch() {
510 // beginService( "Port_Impl::IsEndSwitch" ) ;
511 bool RetVal = _DataFlowPort->IsEndSwitch() ;
512 // endService( "Port_Impl::IsEndSwitch" ) ;
516 bool Port_Impl::IsDataStream() {
517 // beginService( "Port_Impl::IsDataStream" ) ;
518 bool RetVal = _DataFlowPort->IsDataStream() ;
519 // endService( "Port_Impl::IsDataStream" ) ;
523 bool Port_Impl::HasInput() {
524 // beginService( "Port_Impl::" ) ;
525 bool RetVal = false ;
526 if ( _DataFlowNode ) {
527 RetVal = _DataFlowNode->HasInput( _DataFlowPort->PortName() ) ;
528 // cout << "Port_Impl::HasInput " << RetVal << " NodeName " << _DataFlowPort->NodeName() << " PortName "
529 // << _DataFlowPort->PortName() << endl ;
531 // endService( "Port_Impl::" ) ;
535 SUPERV::GraphState Port_Impl::State() {
536 // beginService( "Port_Impl::State" );
537 SUPERV::GraphState RetVal = SUPERV::EditingState ;
538 if ( _DataFlowEditor ) {
539 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
540 if ( _DataFlowExecutor ) {
541 RetVal = _DataFlowExecutor->State( _DataFlowPort->NodeName() ,
542 _DataFlowPort->PortName() ) ;
545 // endService( "Port_Impl::State" );
549 bool Port_Impl::IsDone() {
550 // beginService( "Port_Impl::IsDone" );
551 bool RetVal = false ;
552 if ( _DataFlowEditor ) {
553 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
554 if ( _DataFlowExecutor ) {
555 RetVal = _DataFlowExecutor->IsDone( _DataFlowPort->NodeName() ,
556 _DataFlowPort->PortName() ) ;
559 // endService( "Port_Impl::IsDone" );