1 // Copyright (C) 2006-2008 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.
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
19 #include "OutputDataStreamPort.hxx"
20 #include "InputDataStreamPort.hxx"
21 #include "ComposedNode.hxx"
23 #include "TypeCode.hxx"
27 #include "YacsTrace.hxx"
29 using namespace YACS::ENGINE;
32 const char OutputDataStreamPort::NAME[]="OutputDataStreamPort";
34 OutputDataStreamPort::OutputDataStreamPort(const OutputDataStreamPort& other, Node *newHelder):DataStreamPort(other,newHelder),
35 OutPort(other,newHelder),
36 DataPort(other,newHelder),
41 OutputDataStreamPort::OutputDataStreamPort(const std::string& name, Node *node, TypeCode* type):DataStreamPort(name,node,type),
42 OutPort(name,node,type),
43 DataPort(name,node,type),
48 OutputDataStreamPort::~OutputDataStreamPort()
52 OutputDataStreamPort *OutputDataStreamPort::clone(Node *newHelder) const
54 return new OutputDataStreamPort(*this,newHelder);
57 std::set<InPort *> OutputDataStreamPort::edSetInPort() const
60 for(set<InputDataStreamPort *>::iterator iter=_setOfInputDataStreamPort.begin();iter!=_setOfInputDataStreamPort.end();iter++)
61 (*iter)->getAllRepresentants(s);
65 bool OutputDataStreamPort::isAlreadyLinkedWith(InPort *with) const
68 set<InputDataStreamPort *>::iterator iter;
69 for(iter=_setOfInputDataStreamPort.begin();iter!=_setOfInputDataStreamPort.end();iter++)
72 for(iter=_setOfInputDataStreamPort.begin();iter!=_setOfInputDataStreamPort.end();iter++)
73 (*iter)->getAllRepresentants(s);
74 for(set<InPort *>::iterator iter2=s.begin();iter2!=s.end();iter2++)
80 string OutputDataStreamPort::getNameOfTypeOfCurrentInstance() const
85 bool OutputDataStreamPort::edAddInputDataStreamPort(InputDataStreamPort *port)
86 throw(ConversionException)
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);
106 int OutputDataStreamPort::edRemoveInputDataStreamPort(InputDataStreamPort *inPort, bool forward) throw(Exception)
111 inPort->getAllRepresentants(s);
112 for(set<InPort *>::iterator iter=s.begin();iter!=s.end();iter++)
113 _node->getRootNode()->edRemoveLink(this,*iter);
118 set<InputDataStreamPort *>::iterator iter=_setOfInputDataStreamPort.find(inPort);
119 if(iter!=_setOfInputDataStreamPort.end())
122 _setOfInputDataStreamPort.erase(iter);
124 return edGetNumberOfOutLinks();
127 throw Exception("OutputDataStreamPort::edRemoveInputPort : link does not exist, unable to remove it");
131 bool OutputDataStreamPort::addInPort(InPort *inPort) throw(Exception)
133 DEBTRACE("OutputDataStreamPort::addInPort");
134 if(inPort->getNameOfTypeOfCurrentInstance()!=InputDataStreamPort::NAME)
136 string what="not compatible type of port requested during building of link FROM ";
137 what+=NAME; what+=" TO "; what+=inPort->getNameOfTypeOfCurrentInstance();
138 throw Exception(what);
140 return edAddInputDataStreamPort(static_cast<InputDataStreamPort*>(inPort));
143 void OutputDataStreamPort::edRemoveAllLinksLinkedWithMe() throw(Exception)
145 set<InputDataStreamPort *>::iterator iter;
146 set<InputDataStreamPort *> vec(_setOfInputDataStreamPort);
147 for( set<InputDataStreamPort *>::iterator iter2=vec.begin();iter2!=vec.end();iter2++)
148 edRemoveInputDataStreamPort(*iter2,true);
149 _setOfInputDataStreamPort.clear();
152 int OutputDataStreamPort::removeInPort(InPort *inPort, bool forward) throw(Exception)
154 DEBTRACE("OutputDataStreamPort::removeInPort");
155 if(inPort->getNameOfTypeOfCurrentInstance()!=InputDataStreamPort::NAME && !forward)
157 string what="not compatible type of port requested during destruction of for link FROM ";
158 what+=NAME; what+=" TO "; what+=inPort->getNameOfTypeOfCurrentInstance();
159 throw Exception(what);
161 return edRemoveInputDataStreamPort(static_cast<InputDataStreamPort *>(inPort),forward);
164 bool OutputDataStreamPort::isAlreadyInSet(InputDataStreamPort *inPort) const
166 return _setOfInputDataStreamPort.find(inPort)!=_setOfInputDataStreamPort.end();