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"
32 //GraphBase::OutPort::~OutPort() {
33 // In GraphExecutor::OutPort
35 // for ( i = 1 ; i <= _InPortsSize ; i++ ) {
36 // if ( !_InPorts[ i ]->RemoveLink() )
37 // cout << "GraphBase::OutPort::~OutPort error "
38 // << _InPorts[ i ]->PortName() << endl ;
42 bool GraphBase::OutPort::HasInPort() const {
43 return _InPortsSize != 0 ;
46 const GraphBase::InPort * GraphBase::OutPort::GetInPort(
47 const GraphBase::InPort * toPort ) {
48 const GraphBase::InPort * anInPort = NULL ;
49 int index = _MapOfInPorts[ toPort->NodePortName() ] ;
50 if ( index > 0 && index <= _InPortsSize ) {
51 anInPort = _InPorts[ index-1 ] ;
52 if ( anInPort != toPort ) {
53 cout << "GraphBase::OutPort::GetInPort inconsistency toPort "
54 << hex << (void *) toPort << " != anInPort " << (void *) anInPort
62 SUPERV::Link_var GraphBase::OutPort::InPortObjRef(
63 const GraphBase::InPort * toPort ) {
64 SUPERV::Link_var aLink = SUPERV::Link::_nil() ;
65 int index = _MapOfInPorts[ toPort->NodePortName() ] ;
66 if ( index > 0 && index <= _InPortsSize ) {
67 aLink = _Links[ index-1 ] ;
72 bool GraphBase::OutPort::AddInPort( GraphBase::InPort * toPort ) {
73 int index = _MapOfInPorts[ toPort->NodePortName() ] ;
74 if ( index > 0 && index <= _InPortsSize ) {
78 _InPorts.resize( _InPortsSize ) ;
79 _MapOfInPorts[ toPort->NodePortName() ] = _InPortsSize ;
80 _InPorts[ _InPortsSize-1 ] = toPort ;
81 _Links.resize( _InPortsSize ) ;
82 _Links[ _InPortsSize-1 ] = SUPERV::Link::_nil() ;
83 cdebug << "OutPort " << NodeName() << "(" << PortName() << ") --> InPort "
84 << toPort->NodeName() << "(" << toPort->PortName() << ") SwitchPort "
85 << toPort->IsEndSwitch() << endl ;
89 bool GraphBase::OutPort::AddInPortObjRef( GraphBase::InPort * toPort ,
90 SUPERV::Link_var aLink ) {
91 int index = _MapOfInPorts[ toPort->NodePortName() ] ;
92 if ( index <= 0 || index > _InPortsSize ) {
95 _Links[ index - 1 ] = aLink ;
99 bool GraphBase::OutPort::RemoveInPort( GraphBase::InPort * toPort ) {
101 int index = _MapOfInPorts[ toPort->NodePortName() ] ;
102 if ( index <= 0 || index > _InPortsSize ) {
103 cdebug << "GraphBase::OutPort::RemoveInPort Error " << NodePortName()
104 << " --> " << toPort->NodePortName() << endl ;
108 for ( i = index - 1 ; i < _InPortsSize ; i++ ) {
109 _MapOfInPorts[ _InPorts[ i+1 ]->NodePortName() ] = i + 1 ;
110 _InPorts[ i ] = _InPorts[ i+1 ] ;
111 _Links[ i ] = _Links[ i+1 ] ;
113 _InPorts.resize( _InPortsSize ) ;
114 _Links.resize( _InPortsSize ) ;
115 _MapOfInPorts.erase( toPort->NodePortName() ) ;
116 if ( _InPortsSize == 0 ) {
117 PortStatus(NotConnected ) ;
119 toPort->RemoveOutPort() ;
123 bool GraphBase::OutPort::ReNameInPort( const char* OldNodePortName ,
124 const char* NewNodePortName ) {
125 int index = _MapOfInPorts[ OldNodePortName ] ;
126 if ( index <= 0 || index > _InPortsSize ) {
127 cdebug << "GraphBase::OutPort::ReNameLink Error " << OldNodePortName
128 << " --> " << NewNodePortName << " index " << index << endl ;
131 _MapOfInPorts.erase( OldNodePortName ) ;
132 _MapOfInPorts[ NewNodePortName ] = index ;
137 bool GraphBase::OutPort::RemoveLinks() {
140 for ( i = 0 ; i < _InPortsSize ; i++ ) {
141 MESSAGE( " to " << *_InPorts[ i ] );
142 RetVal = _InPorts[ i ]->RemoveLink() ;
145 RetVal = RemoveLink( _InPorts[ i ] ) ;
149 PortStatus(NotConnected ) ;
154 ostream & operator<< (ostream &f ,const GraphBase::OutPort &P)
156 f << P.PortName() << ", "
157 << "type : " << P.PortType() << ", " ;
161 << P.NodeName() << ", ";