1 // Copyright (C) 2006-2014 CEA/DEN, EDF R&D
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)
87 throw(ConversionException)
89 DEBTRACE("OutputDataStreamPort::edAddInputDataStreamPort");
90 if(!isAlreadyInSet(port))
92 if(!port->edGetType()->isAdaptable(edGetType()))
94 string what="Can not connect 2 ports with incompatible types : ";
95 what=what+ port->edGetType()->id();
96 what=what+" is not a ";
97 what=what+ edGetType()->id();
98 throw ConversionException(what);
100 _setOfInputDataStreamPort.insert(port);
101 port->edAddOutputDataStreamPort(this);
108 int OutputDataStreamPort::edRemoveInputDataStreamPort(InputDataStreamPort *inPort, bool forward) throw(YACS::Exception)
113 inPort->getAllRepresentants(s);
114 for(set<InPort *>::iterator iter=s.begin();iter!=s.end();iter++)
115 _node->getRootNode()->edRemoveLink(this,*iter);
120 set<InputDataStreamPort *>::iterator iter=_setOfInputDataStreamPort.find(inPort);
121 if(iter!=_setOfInputDataStreamPort.end())
124 _setOfInputDataStreamPort.erase(iter);
126 return edGetNumberOfOutLinks();
129 throw Exception("OutputDataStreamPort::edRemoveInputPort : link does not exist, unable to remove it");
133 bool OutputDataStreamPort::addInPort(InPort *inPort) throw(YACS::Exception)
135 DEBTRACE("OutputDataStreamPort::addInPort");
136 if(inPort->getNameOfTypeOfCurrentInstance()!=InputDataStreamPort::NAME)
138 string what="not compatible type of port requested during building of link FROM ";
139 what+=NAME; what+=" TO "; what+=inPort->getNameOfTypeOfCurrentInstance();
140 throw Exception(what);
142 return edAddInputDataStreamPort(static_cast<InputDataStreamPort*>(inPort));
145 void OutputDataStreamPort::edRemoveAllLinksLinkedWithMe() throw(YACS::Exception)
147 set<InputDataStreamPort *>::iterator iter;
148 set<InputDataStreamPort *> vec(_setOfInputDataStreamPort);
149 for( set<InputDataStreamPort *>::iterator iter2=vec.begin();iter2!=vec.end();iter2++)
150 edRemoveInputDataStreamPort(*iter2,true);
151 _setOfInputDataStreamPort.clear();
154 int OutputDataStreamPort::removeInPort(InPort *inPort, bool forward) throw(YACS::Exception)
156 DEBTRACE("OutputDataStreamPort::removeInPort");
157 if(inPort->getNameOfTypeOfCurrentInstance()!=InputDataStreamPort::NAME && !forward)
159 string what="not compatible type of port requested during destruction of for link FROM ";
160 what+=NAME; what+=" TO "; what+=inPort->getNameOfTypeOfCurrentInstance();
161 throw Exception(what);
163 return edRemoveInputDataStreamPort(static_cast<InputDataStreamPort *>(inPort),forward);
166 bool OutputDataStreamPort::isAlreadyInSet(InputDataStreamPort *inPort) const
168 return _setOfInputDataStreamPort.find(inPort)!=_setOfInputDataStreamPort.end();