]> SALOME platform Git repositories - modules/yacs.git/blob - src/runtime/CalStreamPort.cxx
Salome HOME
[EDF30875] : mistype leading to a non activation of squeeze mode
[modules/yacs.git] / src / runtime / CalStreamPort.cxx
1 // Copyright (C) 2006-2024  CEA, EDF
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "CalStreamPort.hxx"
21 #include "SalomeComponent.hxx"
22 #include "CORBANode.hxx"
23 #include "Calcium_Ports.hh"
24 #include <iostream>
25
26 //#define _DEVDEBUG_
27 #include "YacsTrace.hxx"
28
29 using namespace YACS::ENGINE;
30 using namespace std;
31
32 const char InputCalStreamPort::NAME[]="InputCalStreamPort";
33
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")
39 {
40 }
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)
46 {
47 }
48
49 InputCalStreamPort::~InputCalStreamPort()
50 {
51 }
52
53 void InputCalStreamPort::setDepend(const std::string& depend)
54 {
55   DEBTRACE("InputCalStreamPort::setDepend: " << edGetNumberOfLinks());
56   if(edGetNumberOfLinks() > 0)
57     {
58       throw Exception("Can not modify DependencyType property on a connected port");
59     }
60   if(depend != "TIME_DEPENDENCY" && depend != "ITERATION_DEPENDENCY")
61     {
62       throw Exception("DependencyType property must be TIME_DEPENDENCY or ITERATION_DEPENDENCY");
63     }
64   _depend=depend;
65 }
66
67 void InputCalStreamPort::setSchema(const std::string& schema)
68 {
69   if(schema != "TI_SCHEM" && schema != "TF_SCHEM" && schema != "ALPHA_SCHEM")
70     {
71       throw Exception("DateCalSchem property must be TI_SCHEM, TF_SCHEM or ALPHA_SCHEM");
72     }
73   _schema=schema;
74 }
75 void InputCalStreamPort::setLevel(const std::string& value)
76 {
77   DEBTRACE("InputCalStreamPort::setLevel: " << value);
78   std::istringstream iss(value);
79   int temp;
80   if (!(iss >> temp)|| temp<1)
81     throw Exception("StorageLevel property must be an integer > 0");
82   _level=temp;
83 }
84 void InputCalStreamPort::setAlpha(const std::string& value)
85 {
86   std::istringstream iss(value);
87   double temp;
88   if (!(iss >> temp)||temp<0. || temp >1.)
89     throw Exception("Alpha property must be a float > 0 and < 1");
90   _alpha=temp;
91 }
92 void InputCalStreamPort::setDelta(const std::string& value)
93 {
94   std::istringstream iss(value);
95   double temp;
96   if (!(iss >> temp)||temp<0. || temp >1.)
97     throw Exception("DeltaT property must be > 0 and < 1");
98   _delta=temp;
99 }
100 void InputCalStreamPort::setInterp(const std::string& value)
101 {
102   if(value != "L0_SCHEM" && value != "L1_SCHEM")
103     {
104       throw Exception("InterpolationSchem property must be L0_SCHEM or L1_SCHEM");
105     }
106   _interp=value;
107 }
108 void InputCalStreamPort::setExtrap(const std::string& value)
109 {
110   if(value != "E0_SCHEM" && value != "E1_SCHEM")
111     {
112       throw Exception("ExtrapolationSchem property must be E0_SCHEM or E1_SCHEM");
113     }
114   _extrap=value;
115 }
116
117 void InputCalStreamPort::setProperty(const std::string& name, const std::string& value)
118 {
119   DEBTRACE("InputCalStreamPort::setProperty: " << name << " " << value);
120   if(name == "DependencyType")
121     setDepend(value);
122   else if(name == "DateCalSchem")
123     setSchema(value);
124   else if(name == "StorageLevel")
125     setLevel(value);
126   else if(name == "Alpha")
127     setAlpha(value);
128   else if(name == "DeltaT")
129     setDelta(value);
130   else if(name == "InterpolationSchem")
131     setInterp(value);
132   else if(name == "ExtrapolationSchem")
133     setExtrap(value);
134   InputDataStreamPort::setProperty(name,value);
135 }
136
137 #ifdef DSC_PORTS
138 void InputCalStreamPort::initPortProperties()
139 {
140
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());
144   CORBA::Any a;
145   std::string prop;
146   try
147     {
148       DEBTRACE(_level);
149       if(_level>0)
150         {
151           prop="StorageLevel";
152           a <<= (CORBA::Long)_level;
153           port_properties->set_property(prop.c_str(),a);
154         }
155
156       if(_schema != "TI_SCHEM")
157         {
158           prop="DateCalSchem";
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);
164         }
165
166       if(_schema == "ALPHA_SCHEM" && _alpha > 0.)
167         {
168           prop="Alpha";
169           a <<= (CORBA::Double)_alpha;
170           port_properties->set_property(prop.c_str(),a);
171         }
172
173       if(_delta >= 0.)
174         {
175           prop="DeltaT";
176           a <<= (CORBA::Double)_delta;
177           port_properties->set_property(prop.c_str(),a);
178         }
179       if(_interp == "L0_SCHEM" )
180         {
181           prop="InterpolationSchem";
182           a <<= Ports::Calcium_Ports::L0_SCHEM;
183           port_properties->set_property(prop.c_str(),a);
184         }
185       if(_extrap != "UNDEFINED_EXTRA_SCHEM" )
186         {
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);
193         }
194     }
195   catch(Ports::NotDefined& ex)
196     {
197       throw Exception("Property "+prop+ " not defined on that port: "+getName());
198     }
199 }
200 #endif
201
202 std::string InputCalStreamPort::getNameOfTypeOfCurrentInstance() const
203 {
204   return NAME;
205 }
206
207 InputCalStreamPort *InputCalStreamPort::clone(Node *newHelder) const
208 {
209   return new InputCalStreamPort(*this,newHelder);
210 }
211
212 const char OutputCalStreamPort::NAME[]="OutputCalStreamPort";
213
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)
218 {
219 }
220
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)
226 {
227 }
228
229 OutputCalStreamPort::~OutputCalStreamPort()
230 {
231 }
232
233 void OutputCalStreamPort::setDepend(const std::string& depend)
234 {
235   DEBTRACE("OutputCalStreamPort::setDepend: " << edGetNumberOfOutLinks());
236   if(edGetNumberOfOutLinks() > 0)
237     {
238       throw Exception("Can not modify DependencyType property on a connected port");
239     }
240   if(depend != "TIME_DEPENDENCY" && depend != "ITERATION_DEPENDENCY")
241     {
242       throw Exception("DependencyType property must be TIME_DEPENDENCY or ITERATION_DEPENDENCY");
243     }
244   _depend=depend;
245 }
246
247 void OutputCalStreamPort::setSchema(const std::string& schema)
248 {
249   if(schema != "TI_SCHEM" && schema != "TF_SCHEM" && schema != "ALPHA_SCHEM")
250     {
251       throw Exception("DateCalSchem property must be TI_SCHEM, TF_SCHEM or ALPHA_SCHEM");
252     }
253   _schema=schema;
254 }
255 void OutputCalStreamPort::setLevel(const std::string& level)
256 {
257   _level =atoi(level.c_str());
258 }
259
260 void OutputCalStreamPort::setProperty(const std::string& name, const std::string& value)
261 {
262   if(name == "DependencyType")
263     setDepend(value);
264   else if(name == "DateCalSchem")
265     setSchema(value);
266   else if(name == "StorageLevel")
267     setLevel(value);
268   OutputDataStreamPort::setProperty(name,value);
269 }
270
271 std::string OutputCalStreamPort::getNameOfTypeOfCurrentInstance() const
272 {
273   return NAME;
274 }
275
276 OutputCalStreamPort *OutputCalStreamPort::clone(Node *newHelder) const
277 {
278   return new OutputCalStreamPort(*this,newHelder);
279 }
280
281 bool OutputCalStreamPort::addInPort(InPort *inPort)
282 {
283   DEBTRACE("OutputCalStreamPort::addInPort " << InputCalStreamPort::NAME );
284   if(inPort->getNameOfTypeOfCurrentInstance()!=InputCalStreamPort::NAME)
285     {
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);
289     }
290
291   InputCalStreamPort* port=static_cast<InputCalStreamPort*>(inPort);
292   if(port->getDepend() != _depend)
293     {
294       std::string what= "incompatible DependencyType properties: "+_depend+" != "+ port->getDepend();
295       throw Exception(what);
296     }
297   bool ret;
298   ret= edAddInputDataStreamPort(port);
299   return ret;
300 }
301
302
303 int OutputCalStreamPort::removeInPort(InPort *inPort, bool forward)
304 {
305   DEBTRACE("OutputCalStreamPort::removeInPort");
306   if(inPort->getNameOfTypeOfCurrentInstance()!=InputCalStreamPort::NAME && !forward)
307     {
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);
311     }
312   return edRemoveInputDataStreamPort(static_cast<InputDataStreamPort *>(inPort),forward);
313 }
314