Salome HOME
If there is a syntax error in a python function (InLine Node), the states
[modules/superv.git] / src / Supervision / Link_Impl.cxx
1 //  SUPERV Supervision : contains the implementation of interfaces of SuperVision described in SUPERV.idl
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : Link_Impl.cxx
25 //  Author : Jean Rahuel
26 //  Module : SUPERV
27 //  $Header: 
28
29 using namespace std;
30 #include <stdio.h>
31 #include <fstream>
32 //#include <sstream>
33 #include <string>
34
35 //#include "utilities.h"
36
37 #include "StreamLink_Impl.hxx"
38
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 ,
49                       const bool Create ,
50                       const bool Get ,
51                       bool & Success ) :
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);
58   _Poa = poa ;
59   _ContId = contId ;
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 ) ;
69   if ( Create ) {
70     Success = _DataFlowEditor->AddLink( _DataFlowOutNode->Name() ,
71                                         _OutputParameterName , 
72                                         _DataFlowNode->Name() ,
73                                         _InputParameterName ) ;
74   }
75   else if ( Get ) {
76     char * DataFlowOutNodeName = NULL ;
77     char * OutParamName = NULL ;
78     Success = _DataFlowEditor->GetLink( _DataFlowNode->Name() ,
79                                         _InputParameterName , 
80                                         &DataFlowOutNodeName ,
81                                         &OutParamName ) ;
82   }
83   else {
84     Success = false ;
85   }
86   if ( Success ) {
87     _thisObj = this ;
88     _id = _poa->activate_object(_thisObj) ;
89   }
90 //  endService( "Link_Impl::Link_Impl" );
91 }
92
93 Link_Impl::Link_Impl() {
94 }
95
96 Link_Impl::~Link_Impl() {
97   beginService( "Link_Impl::~Link_Impl" );
98   endService( "Link_Impl::~Link_Impl" );
99 }
100
101 void Link_Impl::destroy() {
102   beginService( "Link_Impl::destroy" );
103   Delete() ;
104   _poa->deactivate_object(*_id) ;
105   CORBA::release(_poa) ;
106   delete(_id) ;
107   _thisObj->_remove_ref();
108   endService( "Link_Impl::destroy" );
109 }
110
111 bool Link_Impl::Delete() {
112 //  beginService( "Link_Impl::Delete" ) ;
113   bool RetVal = _DataFlowEditor->RemoveLink( _DataFlowOutNode->Name() ,
114                                              _OutputParameterName ,
115                                              _DataFlowNode->Name() ,
116                                              _InputParameterName ) ;
117 //  endService( "Link_Impl::Delete" );
118   return RetVal ;
119 }
120
121 SUPERV::Port_ptr Link_Impl::InPort() {
122 //  beginService( "Link_Impl::InPort" );
123   SUPERV::Port_var iobject = SUPERV::Port::_nil() ;
124   GraphBase::InPort * anInPort = _DataFlowNode->GetChangeInPort( _InputParameterName ) ;
125   if ( anInPort ) {
126     iobject = anInPort->ObjRef() ;
127     if ( CORBA::is_nil( iobject ) ) {
128       if ( !anInPort->IsDataStream() ) {
129         Port_Impl * myPort = new Port_Impl( _Orb , _Poa , _ContId ,
130                                              instanceName() , interfaceName() ,
131                                              _DataFlowEditor ,
132                                              _DataFlowNode ,
133                                              (GraphBase::Port * ) anInPort ,
134                                              true ) ;
135         PortableServer::ObjectId * id = myPort->getId() ;
136         CORBA::Object_var obj = _poa->id_to_reference(*id);
137         iobject = SUPERV::Port::_narrow(obj) ;
138         anInPort->ObjRef( SUPERV::Port::_duplicate( iobject ) ) ;
139       }
140       else {
141         StreamPort_Impl * myStreamPort = new StreamPort_Impl(
142                                        _Orb , _Poa , _ContId ,
143                                        instanceName() , interfaceName() ,
144                                        DataFlowEditor() ,
145                                        DataFlowOutNode() ,
146                                        (GraphBase::Port * ) anInPort ,
147                                        false ) ;
148         PortableServer::ObjectId * id = myStreamPort->getId() ;
149         CORBA::Object_var obj = _poa->id_to_reference(*id);
150         SUPERV::StreamPort_var iStreamobject ;
151         iStreamobject = SUPERV::StreamPort::_narrow(obj) ;
152         anInPort->ObjRef( SUPERV::StreamPort::_duplicate( iStreamobject ) ) ;
153         iobject = SUPERV::Port::_narrow( iStreamobject ) ;
154       }
155     }
156     else {
157       iobject = anInPort->ObjRef() ;
158     }
159   }
160 //  endService( "Link_Impl::InPort" );
161   return SUPERV::Port::_duplicate( iobject ) ;
162 }
163
164 SUPERV::Port_ptr Link_Impl::OutPort() {
165 //  beginService( "Link_Impl::OutPort" );
166   SUPERV::Port_var iobject = SUPERV::Port::_nil() ;
167   GraphBase::OutPort * anOutPort = _DataFlowOutNode->GetChangeOutPort( _OutputParameterName ) ;
168   if ( anOutPort ) {
169     iobject = anOutPort->ObjRef() ;
170     if ( CORBA::is_nil( iobject ) ) {
171       if ( !anOutPort->IsDataStream() ) {
172         Port_Impl * myPort = new Port_Impl( _Orb , _Poa , _ContId ,
173                                              instanceName() , interfaceName() ,
174                                              _DataFlowEditor ,
175                                              _DataFlowOutNode ,
176                                              (GraphBase::Port * ) anOutPort ,
177                                              false ) ;
178         PortableServer::ObjectId * id = myPort->getId() ;
179         CORBA::Object_var obj = _poa->id_to_reference(*id);
180         iobject = SUPERV::Port::_narrow(obj) ;
181         anOutPort->ObjRef( SUPERV::Port::_duplicate( iobject ) ) ;
182       }
183       else {
184         StreamPort_Impl * myStreamPort = new StreamPort_Impl(
185                                        _Orb , _Poa , _ContId ,
186                                        instanceName() , interfaceName() ,
187                                        DataFlowEditor() ,
188                                        DataFlowOutNode() ,
189                                        (GraphBase::Port * ) anOutPort ,
190                                        false ) ;
191         PortableServer::ObjectId * id = myStreamPort->getId() ;
192         CORBA::Object_var obj = _poa->id_to_reference(*id);
193         SUPERV::StreamPort_var iStreamobject ;
194         iStreamobject = SUPERV::StreamPort::_narrow(obj) ;
195         anOutPort->ObjRef( SUPERV::StreamPort::_duplicate( iStreamobject ) ) ;
196         iobject = SUPERV::Port::_narrow( iStreamobject ) ;
197       }
198     }
199     else {
200       iobject = anOutPort->ObjRef() ;
201     }
202   }
203 //  endService( "Link_Impl::OutPort" );
204   return SUPERV::Port::_duplicate( iobject ) ;
205 }
206
207 GraphBase::SLink * Link_Impl::Info() {
208 //  beginService( "Link_Impl::Info" );
209 //  char* FromNodeName ;
210 //  char* FromServiceParameterName ;
211   GraphBase::SLink * RetVal = _DataFlowEditor->GetLink( _DataFlowNode->ComputingNode() ,
212                                                         _InputParameterName ) ;
213 //  endService( "Link_Impl::Info" );
214   return RetVal ;
215 }
216
217 long Link_Impl::CoordsSize() {
218 //  beginService( "Link_Impl::CoordsSize" ) ;
219   long RetVal = _DataFlowEditor->GetLinkCoordSize( _DataFlowOutNode->Name() ,
220                                                    _OutputParameterName ,
221                                                    _DataFlowNode->Name() ,
222                                                    _InputParameterName ) ;
223 //  endService( "Link_Impl::CoordsSize" );
224   return RetVal ;
225 }
226 bool Link_Impl::AddCoord( const long index ,
227                           const long X ,
228                           const long Y ) {
229 //  beginService( "Link_Impl::AddCoord" ) ;
230   bool RetVal = _DataFlowEditor->AddLinkCoord( _DataFlowOutNode->Name() ,
231                                                _OutputParameterName ,
232                                                _DataFlowNode->Name() ,
233                                                _InputParameterName,
234                                                index , X , Y ) ;
235 //  endService( "Link_Impl::AddCoord" );
236   return RetVal ;
237 }
238 bool Link_Impl::ChangeCoord( const long index ,
239                              const long X ,
240                              const long Y ) {
241 //  beginService( "Link_Impl::ChangeCoord" ) ;
242   bool RetVal = _DataFlowEditor->ChangeLinkCoord( _DataFlowOutNode->Name() ,
243                                                   _OutputParameterName ,
244                                                   _DataFlowNode->Name() ,
245                                                   _InputParameterName,
246                                                   index , X , Y ) ;
247 //  endService( "Link_Impl::ChangeCoord" );
248   return RetVal ;
249 }
250 bool Link_Impl::RemoveCoord( const long index ) {
251 //  beginService( "Link_Impl::RemoveCoord" ) ;
252   bool RetVal = _DataFlowEditor->RemoveLinkCoord( _DataFlowOutNode->Name() ,
253                                                   _OutputParameterName ,
254                                                   _DataFlowNode->Name() ,
255                                                   _InputParameterName,
256                                                   index ) ;
257 //  endService( "Link_Impl::RemoveCoord" );
258   return RetVal ;
259 }
260 bool Link_Impl::Coords( const long index , long & X , long & Y ) {
261 //  beginService( "Link_Impl::Coords" ) ;
262   bool RetVal = _DataFlowEditor->GetLinkCoord( _DataFlowOutNode->Name() ,
263                                                _OutputParameterName ,
264                                                _DataFlowNode->Name() ,
265                                                _InputParameterName,
266                                                index ,  X , Y ) ;
267 //  endService( "Link_Impl::Coords" );
268   return RetVal ;
269 }
270