Salome HOME
f20bd13bd2c87e415c792d90931eabea663e7c86
[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 "Link_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 SUPERV::Value_ptr aValue ) :
51   Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
52 //  MESSAGE("Link_Impl::Link_Impl activate object instanceName("
53 //          << instanceName << ") interfaceName(" << interfaceName << ") --> "
54 //          << hex << (void *) this << dec )
55   bool linksts ;
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     linksts = _DataFlowEditor->AddLink( _DataFlowOutNode->Name() ,
71                                         _OutputParameterName , 
72                                         _DataFlowNode->Name() ,
73                                         _InputParameterName ) ;
74   }
75   else {
76     char * DataFlowOutNodeName = NULL ;
77     char * OutParamName = NULL ;
78     linksts = _DataFlowEditor->GetLink( _DataFlowNode->Name() ,
79                                         _InputParameterName , 
80                                         &DataFlowOutNodeName ,
81                                         &OutParamName ) ;
82   }
83   _thisObj = this ;
84   _id = _poa->activate_object(_thisObj);
85   endService( "Link_Impl::Link_Impl" );
86 }
87
88 Link_Impl::Link_Impl() {
89 }
90
91 Link_Impl::~Link_Impl() {
92   beginService( "Link_Impl::~Link_Impl" );
93   endService( "Link_Impl::~Link_Impl" );
94 }
95
96 void Link_Impl::destroy() {
97   beginService( "Link_Impl::destroy" );
98   Delete() ;
99   _poa->deactivate_object(*_id) ;
100   CORBA::release(_poa) ;
101   delete(_id) ;
102   _thisObj->_remove_ref();
103   endService( "Link_Impl::destroy" );
104 }
105
106 bool Link_Impl::Delete() {
107 //  beginService( "Link_Impl::Delete" ) ;
108   bool RetVal = _DataFlowEditor->RemoveLink( _DataFlowOutNode->Name() ,
109                                              _OutputParameterName ,
110                                              _DataFlowNode->Name() ,
111                                              _InputParameterName ) ;
112 //  endService( "Link_Impl::Delete" );
113   return RetVal ;
114 }
115
116 SUPERV::Port_ptr Link_Impl::InPort() {
117 //  beginService( "Link_Impl::InPort" );
118   GraphBase::InPort * anInPort = _DataFlowNode->GetChangeInPort( _InputParameterName ) ;
119   Port_Impl * myPort = new Port_Impl( _Orb , _Poa , _ContId ,
120                                        instanceName() , interfaceName() ,
121                                        _DataFlowEditor ,
122                                        _DataFlowNode ,
123 //                                       _InputParameterName ) ;
124                                        (GraphBase::Port * ) anInPort ,
125                                        true ) ;
126   PortableServer::ObjectId * id = myPort->getId() ;
127   CORBA::Object_var obj = _poa->id_to_reference(*id);
128   SUPERV::Port_var iobject ;
129   iobject = SUPERV::Port::_narrow(obj) ;
130 //  endService( "Link_Impl::InPort" );
131   return SUPERV::Port::_duplicate( iobject ) ;
132 }
133
134 SUPERV::Port_ptr Link_Impl::OutPort() {
135 //  beginService( "Link_Impl::OutPort" );
136   GraphBase::OutPort * anOutPort = _DataFlowOutNode->GetChangeOutPort( _OutputParameterName ) ;
137   Port_Impl * myPort = new Port_Impl( _Orb , _Poa , _ContId ,
138                                        instanceName() , interfaceName() ,
139                                        _DataFlowEditor ,
140                                        _DataFlowOutNode ,
141 //                                       _OutputParameterName ) ;
142                                        (GraphBase::Port * ) anOutPort ,
143                                        false ) ;
144   PortableServer::ObjectId * id = myPort->getId() ;
145   CORBA::Object_var obj = _poa->id_to_reference(*id);
146   SUPERV::Port_var iobject ;
147   iobject = SUPERV::Port::_narrow(obj) ;
148 //  endService( "Link_Impl::OutPort" );
149   return SUPERV::Port::_duplicate( iobject ) ;
150 }
151
152 GraphBase::SLink * Link_Impl::Info() {
153 //  beginService( "Link_Impl::Info" );
154 //  char* FromNodeName ;
155 //  char* FromServiceParameterName ;
156   GraphBase::SLink * RetVal = _DataFlowEditor->GetLink( _DataFlowNode->ComputingNode() ,
157                                                         _InputParameterName ) ;
158 //  endService( "Link_Impl::Info" );
159   return RetVal ;
160 }
161
162 long Link_Impl::CoordsSize() {
163 //  beginService( "Link_Impl::CoordsSize" ) ;
164   long RetVal = _DataFlowEditor->GetLinkCoordSize( _DataFlowOutNode->Name() ,
165                                                    _OutputParameterName ,
166                                                    _DataFlowNode->Name() ,
167                                                    _InputParameterName ) ;
168 //  endService( "Link_Impl::CoordsSize" );
169   return RetVal ;
170 }
171 bool Link_Impl::AddCoord( const long index ,
172                           const long X ,
173                           const long Y ) {
174 //  beginService( "Link_Impl::AddCoord" ) ;
175   bool RetVal = _DataFlowEditor->AddLinkCoord( _DataFlowOutNode->Name() ,
176                                                _OutputParameterName ,
177                                                _DataFlowNode->Name() ,
178                                                _InputParameterName,
179                                                index , X , Y ) ;
180 //  endService( "Link_Impl::AddCoord" );
181   return RetVal ;
182 }
183 bool Link_Impl::ChangeCoord( const long index ,
184                              const long X ,
185                              const long Y ) {
186 //  beginService( "Link_Impl::ChangeCoord" ) ;
187   bool RetVal = _DataFlowEditor->ChangeLinkCoord( _DataFlowOutNode->Name() ,
188                                                   _OutputParameterName ,
189                                                   _DataFlowNode->Name() ,
190                                                   _InputParameterName,
191                                                   index , X , Y ) ;
192 //  endService( "Link_Impl::ChangeCoord" );
193   return RetVal ;
194 }
195 bool Link_Impl::RemoveCoord( const long index ) {
196 //  beginService( "Link_Impl::RemoveCoord" ) ;
197   bool RetVal = _DataFlowEditor->RemoveLinkCoord( _DataFlowOutNode->Name() ,
198                                                   _OutputParameterName ,
199                                                   _DataFlowNode->Name() ,
200                                                   _InputParameterName,
201                                                   index ) ;
202 //  endService( "Link_Impl::RemoveCoord" );
203   return RetVal ;
204 }
205 bool Link_Impl::Coords( const long index , long & X , long & Y ) {
206 //  beginService( "Link_Impl::Coords" ) ;
207   bool RetVal = _DataFlowEditor->GetLinkCoord( _DataFlowOutNode->Name() ,
208                                                _OutputParameterName ,
209                                                _DataFlowNode->Name() ,
210                                                _InputParameterName,
211                                                index ,  X , Y ) ;
212 //  endService( "Link_Impl::Coords" );
213   return RetVal ;
214 }
215