1 // SUPERV GraphBase : contains fondamental classes for Services, Input Ports, Output Ports Links and Nodes.
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 : DataFlowBase_OutPort.cxx
25 // Author : Jean Rahuel, CEA
30 #include "DataFlowBase_OutPort.hxx"
31 #include "DataFlowBase_InPort.hxx"
33 //GraphBase::OutPort::~OutPort() {
34 // In GraphExecutor::OutPort
36 // for ( i = 1 ; i <= _InPortsSize ; i++ ) {
37 // if ( !_InPorts[ i ]->RemoveLink() )
38 // cout << "GraphBase::OutPort::~OutPort error "
39 // << _InPorts[ i ]->PortName() << endl ;
43 bool GraphBase::OutPort::HasInPort() const {
44 return _InPortsSize != 0 ;
47 const GraphBase::InPort * GraphBase::OutPort::GetInPort(
48 const GraphBase::InPort * toPort ) {
49 const GraphBase::InPort * anInPort = NULL ;
50 int index = _MapOfInPorts[ toPort->NodePortName() ] ;
51 if ( index > 0 && index <= _InPortsSize ) {
52 anInPort = _InPorts[ index-1 ] ;
53 if ( anInPort != toPort ) {
54 //cout << "GraphBase::OutPort::GetInPort inconsistency toPort "
55 // << hex << (void *) toPort << " != anInPort " << (void *) anInPort
63 SUPERV::Link_var GraphBase::OutPort::InPortObjRef(
64 const GraphBase::InPort * toPort ) {
65 SUPERV::Link_var aLink = SUPERV::Link::_nil() ;
66 int index = _MapOfInPorts[ toPort->NodePortName() ] ;
67 if ( index > 0 && index <= _InPortsSize ) {
68 aLink = _Links[ index-1 ] ;
73 bool GraphBase::OutPort::AddInPort( GraphBase::InPort * toPort ) {
74 int index = _MapOfInPorts[ toPort->NodePortName() ] ;
75 if ( index > 0 && index <= _InPortsSize ) {
79 _InPorts.resize( _InPortsSize ) ;
80 _MapOfInPorts[ toPort->NodePortName() ] = _InPortsSize ;
81 _InPorts[ _InPortsSize-1 ] = toPort ;
82 _Links.resize( _InPortsSize ) ;
83 _Links[ _InPortsSize-1 ] = SUPERV::Link::_nil() ;
84 cdebug << "OutPort " << NodeName() << "(" << PortName() << ") --> InPort "
85 << toPort->NodeName() << "(" << toPort->PortName() << ") SwitchPort "
86 << toPort->IsEndSwitch() << endl ;
90 bool GraphBase::OutPort::AddInPortObjRef( GraphBase::InPort * toPort ,
91 SUPERV::Link_var aLink ) {
92 int index = _MapOfInPorts[ toPort->NodePortName() ] ;
93 if ( index <= 0 || index > _InPortsSize ) {
96 _Links[ index - 1 ] = aLink ;
100 bool GraphBase::OutPort::RemoveInPort() {
101 if ( _InPortsSize != 1 ) {
105 GraphBase::InPort * toPort = _InPorts[ index - 1 ] ;
107 _InPorts.resize( _InPortsSize ) ;
108 _Links.resize( _InPortsSize ) ;
109 _MapOfInPorts.erase( toPort->NodePortName() ) ;
110 if ( _InPortsSize == 0 ) {
111 PortStatus(NotConnected ) ;
113 Kind( SUPERV::InLineParameter ) ;
116 toPort->RemoveOutPort() ;
117 cdebug << "OutPort::RemoveInPort " << NodeName() << "( " << PortName() << " " << PortStatus()
118 << " " << Kind() << " ) _InPortsSize " << _InPortsSize << " --> "
119 << toPort->NodeName() << "( " << toPort->PortName() << " " << toPort->PortStatus()
120 << " " << toPort->Kind() << " )" << endl ;
124 bool GraphBase::OutPort::RemoveInPort( GraphBase::InPort * toPort ) {
126 int index = _MapOfInPorts[ toPort->NodePortName() ] ;
127 if ( index <= 0 || index > _InPortsSize ) {
128 cdebug << "GraphBase::OutPort::RemoveInPort Error " << NodeName() << "( " << PortName()<< " ) --> "
129 << toPort->NodeName() << "( " << toPort->PortName() << " )" << endl ;
132 cdebug << "OutPort::RemoveInPort " << NodeName() << "(" << PortName() << ") --> "
133 << _InPorts[ index - 1 ]->NodeName() << "(" << _InPorts[ index - 1 ]->PortName() << ")" << endl ;
135 for ( i = index - 1 ; i < _InPortsSize ; i++ ) {
136 _MapOfInPorts[ _InPorts[ i+1 ]->NodePortName() ] = i + 1 ;
137 _InPorts[ i ] = _InPorts[ i+1 ] ;
138 _Links[ i ] = _Links[ i+1 ] ;
140 _InPorts.resize( _InPortsSize ) ;
141 _Links.resize( _InPortsSize ) ;
142 _MapOfInPorts.erase( toPort->NodePortName() ) ;
143 if ( _InPortsSize == 0 ) {
144 PortStatus(NotConnected ) ;
146 Kind( SUPERV::InLineParameter ) ;
149 toPort->RemoveOutPort() ;
153 bool GraphBase::OutPort::ReNameInPort( const char* OldNodePortName ,
154 const char* NewNodePortName ) {
155 int index = _MapOfInPorts[ OldNodePortName ] ;
156 if ( index <= 0 || index > _InPortsSize ) {
157 cdebug << "GraphBase::OutPort::ReNameInPort Error " << OldNodePortName
158 << " --> " << NewNodePortName << " index " << index << endl ;
161 _MapOfInPorts.erase( OldNodePortName ) ;
162 _MapOfInPorts[ NewNodePortName ] = index ;
167 bool GraphBase::OutPort::RemoveLinks() {
170 for ( i = 0 ; i < _InPortsSize ; i++ ) {
171 MESSAGE( " to " << *_InPorts[ i ] );
172 RetVal = _InPorts[ i ]->RemoveLink() ;
175 RetVal = RemoveLink( _InPorts[ i ] ) ;
179 PortStatus(NotConnected ) ;
184 ostream & operator<< (ostream &f ,const GraphBase::OutPort &P)
186 f << P.PortName() << ", " << "type : " << P.PortType() << ", " ;
187 f << "kind " << P.Kind() << ", ";
188 f << "Status " << P.PortStatus() << ", ";
189 f << "from Node " << P.NodeName() << ", ";