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 // const char *ParameterName ,
48 GraphBase::Port * DataFlowPort ,
50 const CORBA::Any * anAny ) :
51 // const SUPERV::Value_ptr aValue ) :
52 Value_Impl(orb, poa, contId, instanceName, interfaceName,
53 // DataFlowEditor , DataFlowNode , ParameterName, aValue->ToAny() ,
54 DataFlowEditor , DataFlowNode , DataFlowPort->PortName(), anAny ,
56 // MESSAGE("Value_Impl::Value_Impl activate object instanceName("
57 // << instanceName << ") interfaceName(" << interfaceName << ") --> "
58 // << hex << (void *) this << dec )
59 _Orb = CORBA::ORB::_duplicate(orb);
63 _id = _poa->activate_object(_thisObj);
64 _DataFlowEditor = DataFlowEditor ;
65 _DataFlowNode = DataFlowNode ;
66 // _DataFlowPort = _DataFlowNode->GetChangeInPort( ParameterName ) ;
67 _DataFlowPort = DataFlowPort ;
68 // _InputPort = true ;
69 _InputPort = InputPort ;
70 // if ( _DataFlowPort == NULL ) {
71 // _DataFlowPort = _DataFlowNode->GetChangeOutPort( ParameterName ) ;
72 // _InputPort = false ;
74 InPort( _InputPort ) ;
77 Port_Impl::Port_Impl( CORBA::ORB_ptr orb ,
78 PortableServer::POA_ptr poa ,
79 PortableServer::ObjectId * contId ,
80 const char *instanceName ,
81 const char *interfaceName ,
82 GraphEditor::DataFlow * DataFlowEditor ,
83 GraphEditor::InNode * DataFlowNode ,
84 // const char *ParameterName ) :
85 GraphBase::Port * DataFlowPort ,
87 Value_Impl(orb, poa, contId, instanceName, interfaceName,
88 DataFlowEditor , DataFlowNode , DataFlowPort->PortName() , false ) {
89 // DataFlowEditor , DataFlowNode , ParameterName , false ) {
90 // MESSAGE("Value_Impl::Value_Impl activate object instanceName("
91 // << instanceName << ") interfaceName(" << interfaceName << ") --> "
92 // << hex << (void *) this << dec )
93 _Orb = CORBA::ORB::_duplicate(orb);
97 _id = _poa->activate_object(_thisObj);
98 _DataFlowEditor = DataFlowEditor ;
99 _DataFlowNode = DataFlowNode ;
100 // _DataFlowPort = _DataFlowNode->GetChangeInPort( ParameterName ) ;
101 _DataFlowPort = DataFlowPort ;
102 // _InputPort = true ;
103 _InputPort = InputPort ;
104 // if ( _DataFlowPort == NULL ) {
105 // _DataFlowPort = _DataFlowNode->GetChangeOutPort( ParameterName ) ;
106 // _InputPort = false ;
108 InPort( _InputPort ) ;
111 Port_Impl::Port_Impl() {
114 Port_Impl::~Port_Impl() {
115 beginService( "Port_Impl::~Port_Impl" );
116 endService( "Port_Impl::~Port_Impl" );
119 void Port_Impl::destroy() {
120 beginService( "Port_Impl::destroy" );
121 bool destroyed = false ;
122 if ( _DataFlowNode->IsOneOfInLineNodes() ) {
124 GraphBase::InPort * anInPort = (GraphBase::InPort * ) _DataFlowPort ;
125 if ( anInPort->GetOutPort() ) {
126 anInPort->GetOutPort()->RemoveInPort( anInPort ) ;
128 _DataFlowNode->DelInPort( _DataFlowPort->PortName() ) ;
129 if ( _DataFlowNode->IsLoopNode() ) {
130 _DataFlowNode->DelOutPort( _DataFlowPort->PortName() ) ;
131 _DataFlowNode->CoupledNode()->DelInPort( _DataFlowPort->PortName() ) ;
132 _DataFlowNode->CoupledNode()->DelOutPort( _DataFlowPort->PortName() ) ;
136 else if ( !_DataFlowNode->IsLoopNode() ) {
137 _DataFlowNode->DelOutPort( _DataFlowPort->PortName() ) ;
141 _DataFlowEditor->UnValid() ;
142 // _DataFlowEditor->IsValid() ;
146 _poa->deactivate_object(*_id) ;
147 CORBA::release(_poa) ;
149 _thisObj->_remove_ref();
151 endService( "Port_Impl::destroy" );
154 bool Port_Impl::Input( const SUPERV::Value_ptr aValue ) {
155 return Input( aValue->ToAny() ) ;
158 bool Port_Impl::Input( const CORBA::Any * anAny ) {
159 beginService( "Port_Impl::Input" );
160 bool RetVal = false ;
161 if ( _InputPort && _DataFlowEditor->IsEditing() ) {
163 Value_Impl::Input( anAny ) ;
164 RetVal = _DataFlowEditor->AddInputData( _DataFlowNode->Name() ,
165 _DataFlowPort->PortName() ,
168 else if ( _DataFlowEditor->IsExecuting() ) {
169 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
170 // if ( _DataFlowExecutor && ( _DataFlowExecutor->IsSuspended() ||
171 // _DataFlowExecutor->IsSuspended( _DataFlowNode->Name() ) ) ) {
172 if ( _DataFlowExecutor ) {
173 RetVal = _DataFlowExecutor->ChangeInputData( _DataFlowNode->Name() ,
174 _DataFlowPort->PortName() ,
179 MESSAGE( "Port_Impl::Input returns false _InputPort " << _InputPort << " IsEditing "
180 << _DataFlowEditor->IsEditing() << " Executor " << _DataFlowEditor->Executor() ) ;
182 endService( "Port_Impl::Input" );
186 char * Port_Impl::Name() {
187 // beginService( "Port_Impl::Name" ) ;
188 const char * RetVal = _DataFlowPort->PortName() ;
189 // endService( "Port_Impl::Name" ) ;
190 return CORBA::string_dup( RetVal ) ;
193 char * Port_Impl::Type() {
194 // beginService( "Port_Impl::Type" ) ;
195 const char * RetVal = _DataFlowPort->PortType() ;
196 // endService( "Port_Impl::Type" ) ;
197 return CORBA::string_dup( RetVal ) ;
200 SUPERV::CNode_ptr Port_Impl::Node() {
202 SUPERV::CNode_var iobject = SUPERV::CNode::_nil() ;
203 if ( CORBA::is_nil( _DataFlowNode->ObjRef() ) ) {
205 beginService( "Port_Impl::Node" ) ;
208 CNode_Impl * myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
209 instanceName() , interfaceName() ,
212 PortableServer::ObjectId * id = myNode->getId() ;
213 CORBA::Object_var obj = _poa->id_to_reference(*id);
214 SUPERV::CNode_var iobject ;
215 iobject = SUPERV::CNode::_narrow(obj) ;
216 myNode->SetObjRef( SUPERV::CNode::_duplicate( iobject ) ) ;
219 iobject = _DataFlowNode->ObjRef() ;
222 endService( "Port_Impl::Node" ) ;
224 return SUPERV::CNode::_duplicate( iobject ) ;
227 SUPERV::ListOfLinks * Port_Impl::Links() {
228 beginService( "Port_Impl::Links" ) ;
229 SUPERV::ListOfLinks_var RetVal = new SUPERV::ListOfLinks ;
230 RetVal = _DataFlowEditor->ObjImpl()->Links( _DataFlowNode->ComputingNode() ,
231 _DataFlowPort->PortName() ) ;
232 endService( "Port_Impl::Links" ) ;
233 return ( RetVal._retn() ) ;
236 SUPERV::Link_ptr Port_Impl::Link() {
238 SUPERV::Link_var iobject = SUPERV::Link::_nil() ;
239 if ( _DataFlowNode->IsEndSwitchNode() ) {
240 beginService( "Port_Impl::Link" ) ;
242 SUPERV::ListOfLinks_var Links = new SUPERV::ListOfLinks ;
243 // cout << "Port_Impl::Link " << _DataFlowNode->Name() << " "
244 // << _DataFlowPort->PortName() << endl ;
245 Links = _DataFlowEditor->ObjImpl()->Links( _DataFlowNode->ComputingNode() ,
246 _DataFlowPort->PortName() ) ;
247 if ( Links->length() ) {
248 iobject = Links[ 0 ] ;
252 char * FromNodeName = NULL ;
253 char * FromServiceParameterName = NULL ;
254 bool status = _DataFlowEditor->GetLink( _DataFlowNode->Name() ,
255 _DataFlowPort->PortName() ,
257 & FromServiceParameterName ) ;
259 // cout << "Port_Impl::Link " << FromNodeName << "("
260 // << FromServiceParameterName << ") --> " << _DataFlowNode->Name()
261 // << "(" << _DataFlowPort->PortName() << ")" << endl ;
262 // SUPERV::Port_ptr theOutPort = Port( FromServiceParameterName ) ;
264 GraphBase::InPort * anInPort = _DataFlowNode->GetChangeInPort( _DataFlowPort->PortName() ) ;
265 if ( anInPort->GetOutPort() ) {
266 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
267 if ( _DataFlowNode->IsEndLoopNode() && !strcmp( _DataFlowNode->CoupledNode()->Name() ,
268 anOutPort->NodeName() ) ) {
269 // MESSAGE( "Link " << anOutPort->NodeName() << "("
270 // << anOutPort->PortName() << ") --> " << _DataFlowNode->Name() << "("
271 // << anInPort->PortName() << ")" << " ignored" ) ;
273 else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
275 beginService( "Port_Impl::Link" ) ;
278 Link_Impl * myLink = new Link_Impl( _Orb , _Poa , _ContId ,
279 instanceName() , interfaceName() ,
282 _DataFlowPort->PortName() ,
283 (GraphEditor::InNode * ) _DataFlowEditor->GetChangeGraphNode( FromNodeName )->GetInNode() ,
284 FromServiceParameterName ,
286 PortableServer::ObjectId * id = myLink->getId() ;
287 CORBA::Object_var obj = _poa->id_to_reference(*id);
288 iobject = SUPERV::Link::_narrow(obj) ;
289 anOutPort->AddInPortObjRef( anInPort , SUPERV::Link::_duplicate( iobject ) ) ;
292 iobject = anOutPort->InPortObjRef( anInPort ) ;
298 MESSAGE( "Link " << iobject->OutPort()->Node()->Name() << "( " << iobject->OutPort()->Name() << " ) --> "
299 << iobject->InPort()->Node()->Name() << "( " << iobject->InPort()->Name() << " ) " ) ;
300 endService( "Port_Impl::Link" ) ;
302 return SUPERV::Link::_duplicate( iobject ) ;
305 bool Port_Impl::IsInput() {
306 // beginService( "Port_Impl::IsInput" ) ;
307 bool RetVal = _InputPort ;
308 // MESSAGE( Name() << "IsInput() " << _InputPort ) ;
309 // endService( "Port_Impl::IsInput" ) ;
313 bool Port_Impl::IsLinked() {
314 // beginService( "Port_Impl::IsLinked" ) ;
315 bool RetVal = false ;
316 GraphBase::InPort * anInPort = _DataFlowNode->GetChangeInPort( _DataFlowPort->PortName() ) ;
317 GraphBase::OutPort * anOutPort = NULL ;
319 anOutPort = anInPort->GetOutPort() ;
321 if ( _DataFlowNode->IsEndLoopNode() && anOutPort &&
322 !strcmp( _DataFlowNode->CoupledNode()->Name() , anOutPort->NodeName() ) ) {
323 // MESSAGE( "Link " << anOutPort->NodeName() << "("
324 // << anOutPort->PortName() << ") --> " << _DataFlowNode->Name() << "("
325 // << anInPort->PortName() << ")" << " ignored" ) ;
328 RetVal = _DataFlowNode->IsLinked( _DataFlowPort->PortName() ) ;
330 // endService( "Port_Impl::IsLinked" ) ;
334 SUPERV::KindOfPort Port_Impl::Kind() {
335 // beginService( "Port_Impl::Kind" ) ;
336 SUPERV::KindOfPort RetVal = _DataFlowPort->Kind() ;
337 // endService( "Port_Impl::Kind" ) ;
341 void Port_Impl::SetKind( SUPERV::KindOfPort aKindOfPort ) {
342 // beginService( "Port_Impl::SetKind" ) ;
343 _DataFlowPort->Kind( aKindOfPort ) ;
344 // endService( "Port_Impl::SetKind" ) ;
347 bool Port_Impl::IsParam() {
348 // beginService( "Port_Impl::IsParam" ) ;
349 bool RetVal = _DataFlowPort->IsParam() ;
350 // endService( "Port_Impl::IsParam" ) ;
354 bool Port_Impl::IsGate() {
355 // beginService( "Port_Impl::IsGate" ) ;
356 bool RetVal = _DataFlowPort->IsGate() ;
357 // endService( "Port_Impl::IsGate" ) ;
361 bool Port_Impl::IsInLine() {
362 // beginService( "Port_Impl::IsInLine" ) ;
363 // bool RetVal = _DataFlowPort->IsBus() ;
364 bool RetVal = _DataFlowPort->IsInLine() ;
365 // endService( "Port_Impl::IsInLine" ) ;
369 bool Port_Impl::IsLoop() {
370 // beginService( "Port_Impl::IsLoop" ) ;
371 bool RetVal = _DataFlowPort->IsLoop() ;
372 // endService( "Port_Impl::IsLoop" ) ;
376 bool Port_Impl::IsSwitch() {
377 // beginService( "Port_Impl::IsSwitch" ) ;
378 bool RetVal = _DataFlowPort->IsSwitch() ;
379 // endService( "Port_Impl::IsSwitch" ) ;
383 bool Port_Impl::IsEndSwitch() {
384 // beginService( "Port_Impl::IsEndSwitch" ) ;
385 bool RetVal = _DataFlowPort->IsEndSwitch() ;
386 // endService( "Port_Impl::IsEndSwitch" ) ;
390 bool Port_Impl::IsDataStream() {
391 // beginService( "Port_Impl::IsDataStream" ) ;
392 bool RetVal = _DataFlowPort->IsDataStream() ;
393 // endService( "Port_Impl::IsDataStream" ) ;
397 bool Port_Impl::HasInput() {
398 // beginService( "Port_Impl::" ) ;
399 bool RetVal = false ;
400 if ( _DataFlowNode ) {
401 RetVal = _DataFlowNode->HasInput( _DataFlowPort->PortName() ) ;
402 // cout << "Port_Impl::HasInput " << RetVal << " NodeName " << _DataFlowPort->NodeName() << " PortName "
403 // << _DataFlowPort->PortName() << endl ;
405 // endService( "Port_Impl::" ) ;
409 SUPERV::GraphState Port_Impl::State() {
410 // beginService( "Port_Impl::State" );
411 SUPERV::GraphState RetVal = SUPERV::EditingState ;
412 if ( _DataFlowEditor ) {
413 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
414 if ( _DataFlowExecutor ) {
415 RetVal = _DataFlowExecutor->State( _DataFlowPort->NodeName() ,
416 _DataFlowPort->PortName() ) ;
419 // endService( "Port_Impl::State" );
423 bool Port_Impl::IsDone() {
424 // beginService( "Port_Impl::IsDone" );
425 bool RetVal = false ;
426 if ( _DataFlowEditor ) {
427 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
428 if ( _DataFlowExecutor ) {
429 RetVal = _DataFlowExecutor->IsDone( _DataFlowPort->NodeName() ,
430 _DataFlowPort->PortName() ) ;
433 // endService( "Port_Impl::IsDone" );