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 "CalStreamPort.hxx"
21 #include "SalomeComponent.hxx"
22 #include "CORBANode.hxx"
23 #include "Calcium_Ports.hh"
27 #include "YacsTrace.hxx"
29 using namespace YACS::ENGINE;
32 const char InputCalStreamPort::NAME[]="InputCalStreamPort";
34 InputCalStreamPort::InputCalStreamPort(const std::string& name, Node *node, TypeCode* type):
35 InputDataStreamPort(name, node, type),
36 DataPort(name, node, type),
37 Port(node),_depend("TIME_DEPENDENCY"),_schema("TI_SCHEM"),_delta(-1.),_level(-1),_alpha(0.),
38 _interp("L1_SCHEM"),_extrap("UNDEFINED_EXTRA_SCHEM")
41 InputCalStreamPort::InputCalStreamPort(const InputCalStreamPort& other, Node *newHelder):
42 InputDataStreamPort(other,newHelder),
43 DataPort(other,newHelder),
44 Port(other,newHelder),_depend(other._depend),_schema(other._schema),_delta(other._delta),_level(other._level),
45 _alpha(other._alpha),_interp(other._interp),_extrap(other._extrap)
49 InputCalStreamPort::~InputCalStreamPort()
53 void InputCalStreamPort::setDepend(const std::string& depend)
55 DEBTRACE("InputCalStreamPort::setDepend: " << edGetNumberOfLinks());
56 if(edGetNumberOfLinks() > 0)
58 throw Exception("Can not modify DependencyType property on a connected port");
60 if(depend != "TIME_DEPENDENCY" && depend != "ITERATION_DEPENDENCY")
62 throw Exception("DependencyType property must be TIME_DEPENDENCY or ITERATION_DEPENDENCY");
67 void InputCalStreamPort::setSchema(const std::string& schema)
69 if(schema != "TI_SCHEM" && schema != "TF_SCHEM" && schema != "ALPHA_SCHEM")
71 throw Exception("DateCalSchem property must be TI_SCHEM, TF_SCHEM or ALPHA_SCHEM");
75 void InputCalStreamPort::setLevel(const std::string& value)
77 DEBTRACE("InputCalStreamPort::setLevel: " << value);
78 std::istringstream iss(value);
80 if (!(iss >> temp)|| temp<1)
81 throw Exception("StorageLevel property must be an integer > 0");
84 void InputCalStreamPort::setAlpha(const std::string& value)
86 std::istringstream iss(value);
88 if (!(iss >> temp)||temp<0. || temp >1.)
89 throw Exception("Alpha property must be a float > 0 and < 1");
92 void InputCalStreamPort::setDelta(const std::string& value)
94 std::istringstream iss(value);
96 if (!(iss >> temp)||temp<0. || temp >1.)
97 throw Exception("DeltaT property must be > 0 and < 1");
100 void InputCalStreamPort::setInterp(const std::string& value)
102 if(value != "L0_SCHEM" && value != "L1_SCHEM")
104 throw Exception("InterpolationSchem property must be L0_SCHEM or L1_SCHEM");
108 void InputCalStreamPort::setExtrap(const std::string& value)
110 if(value != "E0_SCHEM" && value != "E1_SCHEM")
112 throw Exception("ExtrapolationSchem property must be E0_SCHEM or E1_SCHEM");
117 void InputCalStreamPort::setProperty(const std::string& name, const std::string& value)
119 DEBTRACE("InputCalStreamPort::setProperty: " << name << " " << value);
120 if(name == "DependencyType")
122 else if(name == "DateCalSchem")
124 else if(name == "StorageLevel")
126 else if(name == "Alpha")
128 else if(name == "DeltaT")
130 else if(name == "InterpolationSchem")
132 else if(name == "ExtrapolationSchem")
134 InputDataStreamPort::setProperty(name,value);
138 void InputCalStreamPort::initPortProperties()
141 CORBA::Object_var objComponent=((SalomeComponent*)((SalomeNode*)_node)->getComponent())->getCompoPtr();
142 Engines::Superv_Component_var compo=Engines::Superv_Component::_narrow(objComponent);
143 Ports::PortProperties_var port_properties=compo->get_port_properties(getName().c_str());
152 a <<= (CORBA::Long)_level;
153 port_properties->set_property(prop.c_str(),a);
156 if(_schema != "TI_SCHEM")
159 if(_schema == "TF_SCHEM")
160 a <<= Ports::Calcium_Ports::TF_SCHEM;
161 else if(_schema == "ALPHA_SCHEM")
162 a <<= Ports::Calcium_Ports::ALPHA_SCHEM;
163 port_properties->set_property(prop.c_str(),a);
166 if(_schema == "ALPHA_SCHEM" && _alpha > 0.)
169 a <<= (CORBA::Double)_alpha;
170 port_properties->set_property(prop.c_str(),a);
176 a <<= (CORBA::Double)_delta;
177 port_properties->set_property(prop.c_str(),a);
179 if(_interp == "L0_SCHEM" )
181 prop="InterpolationSchem";
182 a <<= Ports::Calcium_Ports::L0_SCHEM;
183 port_properties->set_property(prop.c_str(),a);
185 if(_extrap != "UNDEFINED_EXTRA_SCHEM" )
187 prop="ExtrapolationSchem";
188 if(_extrap == "E0_SCHEM" )
189 a <<= Ports::Calcium_Ports::E0_SCHEM;
190 else if(_extrap == "E1_SCHEM" )
191 a <<= Ports::Calcium_Ports::E1_SCHEM;
192 port_properties->set_property(prop.c_str(),a);
195 catch(Ports::NotDefined& ex)
197 throw Exception("Property "+prop+ " not defined on that port: "+getName());
202 std::string InputCalStreamPort::getNameOfTypeOfCurrentInstance() const
207 InputCalStreamPort *InputCalStreamPort::clone(Node *newHelder) const
209 return new InputCalStreamPort(*this,newHelder);
212 const char OutputCalStreamPort::NAME[]="OutputCalStreamPort";
214 OutputCalStreamPort::OutputCalStreamPort(const std::string& name, Node *node, TypeCode* type):
215 OutputDataStreamPort(name, node, type),
216 DataPort(name, node, type),
217 Port(node),_depend("TIME_DEPENDENCY"),_schema("TI_SCHEM"),_level(-1)
221 OutputCalStreamPort::OutputCalStreamPort(const OutputCalStreamPort& other, Node *newHelder):
222 OutputDataStreamPort(other,newHelder),
223 DataPort(other,newHelder),
224 Port(other,newHelder),
225 _depend(other._depend),_schema(other._schema),_level(other._level)
229 OutputCalStreamPort::~OutputCalStreamPort()
233 void OutputCalStreamPort::setDepend(const std::string& depend)
235 DEBTRACE("OutputCalStreamPort::setDepend: " << edGetNumberOfOutLinks());
236 if(edGetNumberOfOutLinks() > 0)
238 throw Exception("Can not modify DependencyType property on a connected port");
240 if(depend != "TIME_DEPENDENCY" && depend != "ITERATION_DEPENDENCY")
242 throw Exception("DependencyType property must be TIME_DEPENDENCY or ITERATION_DEPENDENCY");
247 void OutputCalStreamPort::setSchema(const std::string& schema)
249 if(schema != "TI_SCHEM" && schema != "TF_SCHEM" && schema != "ALPHA_SCHEM")
251 throw Exception("DateCalSchem property must be TI_SCHEM, TF_SCHEM or ALPHA_SCHEM");
255 void OutputCalStreamPort::setLevel(const std::string& level)
257 _level =atoi(level.c_str());
260 void OutputCalStreamPort::setProperty(const std::string& name, const std::string& value)
262 if(name == "DependencyType")
264 else if(name == "DateCalSchem")
266 else if(name == "StorageLevel")
268 OutputDataStreamPort::setProperty(name,value);
271 std::string OutputCalStreamPort::getNameOfTypeOfCurrentInstance() const
276 OutputCalStreamPort *OutputCalStreamPort::clone(Node *newHelder) const
278 return new OutputCalStreamPort(*this,newHelder);
281 bool OutputCalStreamPort::addInPort(InPort *inPort)
283 DEBTRACE("OutputCalStreamPort::addInPort " << InputCalStreamPort::NAME );
284 if(inPort->getNameOfTypeOfCurrentInstance()!=InputCalStreamPort::NAME)
286 string what="not compatible type of port requested during building of link FROM ";
287 what+=NAME; what+=" TO "; what+=inPort->getNameOfTypeOfCurrentInstance();
288 throw Exception(what);
291 InputCalStreamPort* port=static_cast<InputCalStreamPort*>(inPort);
292 if(port->getDepend() != _depend)
294 std::string what= "incompatible DependencyType properties: "+_depend+" != "+ port->getDepend();
295 throw Exception(what);
298 ret= edAddInputDataStreamPort(port);
303 int OutputCalStreamPort::removeInPort(InPort *inPort, bool forward)
305 DEBTRACE("OutputCalStreamPort::removeInPort");
306 if(inPort->getNameOfTypeOfCurrentInstance()!=InputCalStreamPort::NAME && !forward)
308 string what="not compatible type of port requested during destruction of for link FROM ";
309 what+=NAME; what+=" TO "; what+=inPort->getNameOfTypeOfCurrentInstance();
310 throw Exception(what);
312 return edRemoveInputDataStreamPort(static_cast<InputDataStreamPort *>(inPort),forward);