1 // Copyright (C) 2006-2024 CEA, EDF
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "OutputDataStreamPort.hxx"
21 #include "InputDataStreamPort.hxx"
22 #include "ComposedNode.hxx"
24 #include "TypeCode.hxx"
28 #include "YacsTrace.hxx"
30 using namespace YACS::ENGINE;
33 const char OutputDataStreamPort::NAME[]="OutputDataStreamPort";
35 OutputDataStreamPort::OutputDataStreamPort(const OutputDataStreamPort& other, Node *newHelder):DataStreamPort(other,newHelder),
36 OutPort(other,newHelder),
37 DataPort(other,newHelder),
42 OutputDataStreamPort::OutputDataStreamPort(const std::string& name, Node *node, TypeCode* type):DataStreamPort(name,node,type),
43 OutPort(name,node,type),
44 DataPort(name,node,type),
49 OutputDataStreamPort::~OutputDataStreamPort()
53 OutputDataStreamPort *OutputDataStreamPort::clone(Node *newHelder) const
55 return new OutputDataStreamPort(*this,newHelder);
58 std::set<InPort *> OutputDataStreamPort::edSetInPort() const
61 for(set<InputDataStreamPort *>::const_iterator iter=_setOfInputDataStreamPort.begin();iter!=_setOfInputDataStreamPort.end();iter++)
62 (*iter)->getAllRepresentants(s);
66 bool OutputDataStreamPort::isAlreadyLinkedWith(InPort *with) const
69 set<InputDataStreamPort *>::const_iterator iter;
70 for(iter=_setOfInputDataStreamPort.begin();iter!=_setOfInputDataStreamPort.end();iter++)
73 for(iter=_setOfInputDataStreamPort.begin();iter!=_setOfInputDataStreamPort.end();iter++)
74 (*iter)->getAllRepresentants(s);
75 for(set<InPort *>::iterator iter2=s.begin();iter2!=s.end();iter2++)
81 string OutputDataStreamPort::getNameOfTypeOfCurrentInstance() const
86 bool OutputDataStreamPort::edAddInputDataStreamPort(InputDataStreamPort *port)
88 DEBTRACE("OutputDataStreamPort::edAddInputDataStreamPort");
89 if(!isAlreadyInSet(port))
91 if(!port->edGetType()->isAdaptable(edGetType()))
93 string what="Can not connect 2 ports with incompatible types : ";
94 what=what+ port->edGetType()->id();
95 what=what+" is not a ";
96 what=what+ edGetType()->id();
97 throw ConversionException(what);
99 _setOfInputDataStreamPort.insert(port);
100 port->edAddOutputDataStreamPort(this);
107 int OutputDataStreamPort::edRemoveInputDataStreamPort(InputDataStreamPort *inPort, bool forward)
112 inPort->getAllRepresentants(s);
113 for(set<InPort *>::iterator iter=s.begin();iter!=s.end();iter++)
114 _node->getRootNode()->edRemoveLink(this,*iter);
119 set<InputDataStreamPort *>::iterator iter=_setOfInputDataStreamPort.find(inPort);
120 if(iter!=_setOfInputDataStreamPort.end())
123 _setOfInputDataStreamPort.erase(iter);
125 return edGetNumberOfOutLinks();
128 throw Exception("OutputDataStreamPort::edRemoveInputPort : link does not exist, unable to remove it");
132 bool OutputDataStreamPort::addInPort(InPort *inPort)
134 DEBTRACE("OutputDataStreamPort::addInPort");
135 if(inPort->getNameOfTypeOfCurrentInstance()!=InputDataStreamPort::NAME)
137 string what="not compatible type of port requested during building of link FROM ";
138 what+=NAME; what+=" TO "; what+=inPort->getNameOfTypeOfCurrentInstance();
139 throw Exception(what);
141 return edAddInputDataStreamPort(static_cast<InputDataStreamPort*>(inPort));
144 void OutputDataStreamPort::edRemoveAllLinksLinkedWithMe()
146 set<InputDataStreamPort *>::iterator iter;
147 set<InputDataStreamPort *> vec(_setOfInputDataStreamPort);
148 for( set<InputDataStreamPort *>::iterator iter2=vec.begin();iter2!=vec.end();iter2++)
149 edRemoveInputDataStreamPort(*iter2,true);
150 _setOfInputDataStreamPort.clear();
153 int OutputDataStreamPort::removeInPort(InPort *inPort, bool forward)
155 DEBTRACE("OutputDataStreamPort::removeInPort");
156 if(inPort->getNameOfTypeOfCurrentInstance()!=InputDataStreamPort::NAME && !forward)
158 string what="not compatible type of port requested during destruction of for link FROM ";
159 what+=NAME; what+=" TO "; what+=inPort->getNameOfTypeOfCurrentInstance();
160 throw Exception(what);
162 return edRemoveInputDataStreamPort(static_cast<InputDataStreamPort *>(inPort),forward);
165 bool OutputDataStreamPort::isAlreadyInSet(InputDataStreamPort *inPort) const
167 return _setOfInputDataStreamPort.find(inPort)!=_setOfInputDataStreamPort.end();