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
24 // File : Link_Impl.cxx
25 // Author : Jean Rahuel
35 //#include "utilities.h"
37 #include "StreamLink_Impl.hxx"
39 Link_Impl::Link_Impl( CORBA::ORB_ptr orb ,
40 PortableServer::POA_ptr poa ,
41 PortableServer::ObjectId * contId ,
42 const char *instanceName ,
43 const char *interfaceName ,
44 GraphEditor::DataFlow * DataFlowEditor ,
45 GraphEditor::InNode * DataFlowNode ,
46 const char *InputParameterName ,
47 GraphEditor::InNode * DataFlowOutNode ,
48 const char *OutputParameterName ,
52 Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
53 // MESSAGE("Link_Impl::Link_Impl activate object instanceName("
54 // << instanceName << ") interfaceName(" << interfaceName << ") --> "
55 // << hex << (void *) this << dec )
56 // beginService( "Link_Impl::Link_Impl" );
57 _Orb = CORBA::ORB::_duplicate(orb);
60 _DataFlowEditor = DataFlowEditor ;
61 _DataFlowNode = DataFlowNode ;
62 _DataFlowNodeName = DataFlowNode->Name() ;
63 _InputParameterName = new char[ strlen( InputParameterName ) + 1 ] ;
64 strcpy( _InputParameterName , InputParameterName ) ;
65 _DataFlowOutNode = DataFlowOutNode ;
66 _DataFlowOutNodeName = DataFlowOutNode->Name() ;
67 _OutputParameterName = new char[ strlen( OutputParameterName ) + 1 ] ;
68 strcpy( _OutputParameterName , OutputParameterName ) ;
70 Success = _DataFlowEditor->AddLink( _DataFlowOutNode->Name() ,
71 _OutputParameterName ,
72 _DataFlowNode->Name() ,
73 _InputParameterName ) ;
76 char * DataFlowOutNodeName = NULL ;
77 char * OutParamName = NULL ;
78 Success = _DataFlowEditor->GetLink( _DataFlowNode->Name() ,
80 &DataFlowOutNodeName ,
88 _id = _poa->activate_object(_thisObj) ;
90 // endService( "Link_Impl::Link_Impl" );
93 Link_Impl::Link_Impl() {
96 Link_Impl::~Link_Impl() {
97 beginService( "Link_Impl::~Link_Impl" );
98 endService( "Link_Impl::~Link_Impl" );
101 void Link_Impl::destroy() {
102 beginService( "Link_Impl::destroy" );
104 _poa->deactivate_object(*_id) ;
105 // CORBA::release(_poa) ;
107 // _thisObj->_remove_ref();
108 endService( "Link_Impl::destroy" );
111 bool Link_Impl::Delete() {
112 // beginService( "Link_Impl::Delete" ) ;
113 bool RetVal = _DataFlowEditor->RemoveLink( _DataFlowOutNode->Name() ,
114 _OutputParameterName ,
115 _DataFlowNode->Name() ,
116 _InputParameterName ) ;
118 DataFlowEditor()->UnValid() ;
120 // endService( "Link_Impl::Delete" );
124 SUPERV::Port_ptr Link_Impl::InPort() {
125 // beginService( "Link_Impl::InPort" );
126 SUPERV::Port_var iobject = SUPERV::Port::_nil() ;
127 GraphBase::InPort * anInPort = _DataFlowNode->GetChangeInPort( _InputParameterName ) ;
129 iobject = anInPort->ObjRef() ;
130 if ( CORBA::is_nil( iobject ) ) {
131 if ( !anInPort->IsDataStream() ) {
132 Port_Impl * myPort = new Port_Impl( _Orb , _Poa , _ContId ,
133 instanceName() , interfaceName() ,
136 (GraphBase::Port * ) anInPort ,
138 PortableServer::ObjectId * id = myPort->getId() ;
139 CORBA::Object_var obj = _poa->id_to_reference(*id);
140 iobject = SUPERV::Port::_narrow(obj) ;
141 anInPort->ObjRef( SUPERV::Port::_duplicate( iobject ) ) ;
144 StreamPort_Impl * myStreamPort = new StreamPort_Impl(
145 _Orb , _Poa , _ContId ,
146 instanceName() , interfaceName() ,
149 (GraphBase::Port * ) anInPort ,
151 PortableServer::ObjectId * id = myStreamPort->getId() ;
152 CORBA::Object_var obj = _poa->id_to_reference(*id);
153 SUPERV::StreamPort_var iStreamobject ;
154 iStreamobject = SUPERV::StreamPort::_narrow(obj) ;
155 anInPort->ObjRef( SUPERV::StreamPort::_duplicate( iStreamobject ) ) ;
156 iobject = SUPERV::Port::_narrow( iStreamobject ) ;
160 iobject = anInPort->ObjRef() ;
163 // endService( "Link_Impl::InPort" );
164 return SUPERV::Port::_duplicate( iobject ) ;
167 SUPERV::Port_ptr Link_Impl::OutPort() {
168 // beginService( "Link_Impl::OutPort" );
169 SUPERV::Port_var iobject = SUPERV::Port::_nil() ;
170 GraphBase::OutPort * anOutPort = _DataFlowOutNode->GetChangeOutPort( _OutputParameterName ) ;
172 iobject = anOutPort->ObjRef() ;
173 if ( CORBA::is_nil( iobject ) ) {
174 if ( !anOutPort->IsDataStream() ) {
175 Port_Impl * myPort = new Port_Impl( _Orb , _Poa , _ContId ,
176 instanceName() , interfaceName() ,
179 (GraphBase::Port * ) anOutPort ,
181 PortableServer::ObjectId * id = myPort->getId() ;
182 CORBA::Object_var obj = _poa->id_to_reference(*id);
183 iobject = SUPERV::Port::_narrow(obj) ;
184 anOutPort->ObjRef( SUPERV::Port::_duplicate( iobject ) ) ;
187 StreamPort_Impl * myStreamPort = new StreamPort_Impl(
188 _Orb , _Poa , _ContId ,
189 instanceName() , interfaceName() ,
192 (GraphBase::Port * ) anOutPort ,
194 PortableServer::ObjectId * id = myStreamPort->getId() ;
195 CORBA::Object_var obj = _poa->id_to_reference(*id);
196 SUPERV::StreamPort_var iStreamobject ;
197 iStreamobject = SUPERV::StreamPort::_narrow(obj) ;
198 anOutPort->ObjRef( SUPERV::StreamPort::_duplicate( iStreamobject ) ) ;
199 iobject = SUPERV::Port::_narrow( iStreamobject ) ;
203 iobject = anOutPort->ObjRef() ;
206 // endService( "Link_Impl::OutPort" );
207 return SUPERV::Port::_duplicate( iobject ) ;
210 GraphBase::SLink * Link_Impl::Info() {
211 // beginService( "Link_Impl::Info" );
212 // char* FromNodeName ;
213 // char* FromServiceParameterName ;
214 GraphBase::SLink * RetVal = _DataFlowEditor->GetLink( _DataFlowNode->ComputingNode() ,
215 _InputParameterName ) ;
216 // endService( "Link_Impl::Info" );
220 CORBA::Long Link_Impl::CoordsSize() {
221 // beginService( "Link_Impl::CoordsSize" ) ;
222 CORBA::Long RetVal = _DataFlowEditor->GetLinkCoordSize( _DataFlowOutNode->Name() ,
223 _OutputParameterName ,
224 _DataFlowNode->Name() ,
225 _InputParameterName ) ;
226 // endService( "Link_Impl::CoordsSize" );
229 bool Link_Impl::AddCoord( CORBA::Long index ,
232 // beginService( "Link_Impl::AddCoord" ) ;
233 bool RetVal = _DataFlowEditor->AddLinkCoord( _DataFlowOutNode->Name() ,
234 _OutputParameterName ,
235 _DataFlowNode->Name() ,
238 // endService( "Link_Impl::AddCoord" );
241 bool Link_Impl::ChangeCoord( CORBA::Long index ,
244 // beginService( "Link_Impl::ChangeCoord" ) ;
245 bool RetVal = _DataFlowEditor->ChangeLinkCoord( _DataFlowOutNode->Name() ,
246 _OutputParameterName ,
247 _DataFlowNode->Name() ,
250 // endService( "Link_Impl::ChangeCoord" );
253 bool Link_Impl::RemoveCoord( CORBA::Long index ) {
254 // beginService( "Link_Impl::RemoveCoord" ) ;
255 bool RetVal = _DataFlowEditor->RemoveLinkCoord( _DataFlowOutNode->Name() ,
256 _OutputParameterName ,
257 _DataFlowNode->Name() ,
260 // endService( "Link_Impl::RemoveCoord" );
263 bool Link_Impl::Coords( CORBA::Long index , CORBA::Long & X , CORBA::Long & Y ) {
264 // beginService( "Link_Impl::Coords" ) ;
265 bool RetVal = _DataFlowEditor->GetLinkCoord( _DataFlowOutNode->Name() ,
266 _OutputParameterName ,
267 _DataFlowNode->Name() ,
270 // endService( "Link_Impl::Coords" );
275 * Return true if InPort's and OutPort's types are compatible
276 * {"string", "boolean", "char", "short", "int", "long", "float", "double", "objref"};
277 * Currently considered compatible ALL types except for objref - they must match exactly
278 * To make sure no other rule of compatibility is used - see Editor::OutNode::IsCompatible().
280 bool Link_Impl::IsValid() {
281 if ( InPort() && OutPort() ) {
282 return DataFlowEditor()->IsCompatible( OutPort()->Type(), InPort()->Type() );
288 * Return true the ports of this link and theLink are equal. If you do on the GUI side - it does not
289 * return the correct value..
291 bool Link_Impl::IsEqual( SUPERV::Link_ptr theLink ) {
292 if ( InPort() && OutPort() && !CORBA::is_nil(theLink) ) {
293 return ( InPort() == theLink->InPort() && OutPort() == theLink->OutPort() );