]> SALOME platform Git repositories - modules/yacs.git/blob - src/runtime/CalStreamPort.cxx
Salome HOME
merge from branch DEV tag mergeto_trunk_04apr08
[modules/yacs.git] / src / runtime / CalStreamPort.cxx
1 #include "CalStreamPort.hxx"
2 #include "SalomeComponent.hxx"
3 #include "CORBANode.hxx"
4 #include <iostream>
5
6 //#define _DEVDEBUG_
7 #include "YacsTrace.hxx"
8
9 using namespace YACS::ENGINE;
10 using namespace std;
11
12 const char InputCalStreamPort::NAME[]="InputCalStreamPort";
13
14 InputCalStreamPort::InputCalStreamPort(const std::string& name, Node *node, TypeCode* type):
15   InputDataStreamPort(name, node, type),
16   DataPort(name, node, type),
17   Port(node),_depend("T"),_schema("TI"),_delta(0.),_level(-1)
18 {
19 }
20 InputCalStreamPort::InputCalStreamPort(const InputCalStreamPort& other, Node *newHelder):
21   InputDataStreamPort(other,newHelder),
22   DataPort(other,newHelder),
23   Port(other,newHelder),_depend(other._depend),_schema(other._schema),_delta(other._delta),_level(other._level)
24 {
25 }
26
27 InputCalStreamPort::~InputCalStreamPort()
28 {
29 }
30
31 void InputCalStreamPort::setDepend(const std::string& depend)
32 {
33   DEBTRACE("InputCalStreamPort::setDepend: " << edGetNumberOfLinks());
34   if(edGetNumberOfLinks() > 0)
35     {
36       throw Exception("Can not modify depend parameter on a connected port");
37     }
38   if(depend != "T" && depend != "I")
39     {
40       throw Exception("depend parameter must be T or I");
41     }
42   _depend=depend;
43 }
44
45 void InputCalStreamPort::setSchema(const std::string& schema)
46 {
47   if(schema != "TI" && schema != "TF" && schema != "DELTA")
48     {
49       throw Exception("schema parameter must be TI, TF or DELTA");
50     }
51   _schema=schema;
52 }
53 void InputCalStreamPort::setLevel(const std::string& level)
54 {
55   _level =atoi(level.c_str());
56 }
57
58 void InputCalStreamPort::setProperty(const std::string& name, const std::string& value)
59 {
60   if(name == "depend")
61     setDepend(value);
62   else if(name == "schema")
63     setSchema(value);
64   else if(name == "level")
65     setLevel(value);
66   InputDataStreamPort::setProperty(name,value);
67 }
68
69 #ifdef DSC_PORTS
70 void InputCalStreamPort::initPortProperties()
71 {
72
73   DEBTRACE(_level);
74   if(_level>0)
75     {
76       CORBA::Object_var objComponent=((SalomeComponent*)((SalomeNode*)_node)->getComponent())->getCompoPtr();
77       Engines::Superv_Component_var compo=Engines::Superv_Component::_narrow(objComponent);
78       Ports::PortProperties_var port_properties=compo->get_port_properties(getName().c_str());
79       CORBA::Any a;
80       a <<= (CORBA::Long)_level;
81       try
82         {
83           port_properties->set_property("StorageLevel",a);
84         }
85       catch(Ports::NotDefined& ex)
86         {
87           throw Exception("Property StorageLevel not defined on that port: "+getName());
88         }
89     }
90 }
91 #endif
92
93 std::string InputCalStreamPort::getNameOfTypeOfCurrentInstance() const
94 {
95   return NAME;
96 }
97
98 InputCalStreamPort *InputCalStreamPort::clone(Node *newHelder) const
99 {
100   return new InputCalStreamPort(*this,newHelder);
101 }
102
103 const char OutputCalStreamPort::NAME[]="OutputCalStreamPort";
104
105 OutputCalStreamPort::OutputCalStreamPort(const std::string& name, Node *node, TypeCode* type):
106   OutputDataStreamPort(name, node, type),
107   DataPort(name, node, type),
108   Port(node),_depend("T")
109 {
110 }
111
112 OutputCalStreamPort::OutputCalStreamPort(const OutputCalStreamPort& other, Node *newHelder):
113   OutputDataStreamPort(other,newHelder),
114   DataPort(other,newHelder),
115   Port(other,newHelder),
116   _depend(other._depend)
117 {
118 }
119
120 OutputCalStreamPort::~OutputCalStreamPort()
121 {
122 }
123
124 void OutputCalStreamPort::setDepend(const std::string& depend)
125 {
126   DEBTRACE("OutputCalStreamPort::setDepend: " << edGetNumberOfOutLinks());
127   if(edGetNumberOfOutLinks() > 0)
128     {
129       throw Exception("Can not modify depend parameter on a connected port");
130     }
131   if(depend != "T" && depend != "I" )
132     {
133       throw Exception("depend parameter must be T or I");
134     }
135   _depend=depend;
136 }
137
138 void OutputCalStreamPort::setSchema(const std::string& schema)
139 {
140   if(schema != "TI" && schema != "TF" && schema != "DELTA")
141     {
142       throw Exception("schema parameter must be TI, TF or DELTA");
143     }
144   _schema=schema;
145 }
146 void OutputCalStreamPort::setLevel(const std::string& level)
147 {
148   _level =atoi(level.c_str());
149 }
150
151 void OutputCalStreamPort::setProperty(const std::string& name, const std::string& value)
152 {
153   if(name == "depend")
154     setDepend(value);
155   else if(name == "schema")
156     setSchema(value);
157   else if(name == "level")
158     setLevel(value);
159   OutputDataStreamPort::setProperty(name,value);
160 }
161
162 std::string OutputCalStreamPort::getNameOfTypeOfCurrentInstance() const
163 {
164   return NAME;
165 }
166
167 OutputCalStreamPort *OutputCalStreamPort::clone(Node *newHelder) const
168 {
169   return new OutputCalStreamPort(*this,newHelder);
170 }
171
172 bool OutputCalStreamPort::addInPort(InPort *inPort) throw(Exception)
173 {
174   DEBTRACE("OutputCalStreamPort::addInPort " << InputCalStreamPort::NAME );
175   if(inPort->getNameOfTypeOfCurrentInstance()!=InputCalStreamPort::NAME)
176     {
177       string what="not compatible type of port requested during building of link FROM ";
178       what+=NAME; what+=" TO "; what+=inPort->getNameOfTypeOfCurrentInstance();
179       throw Exception(what);
180     }
181
182   InputCalStreamPort* port=static_cast<InputCalStreamPort*>(inPort);
183   if(port->getDepend() != _depend)
184     {
185       std::string what= "incompatible depend parameters: "+_depend+" != "+ port->getDepend();
186       throw Exception(what);
187     }
188   bool ret;
189   ret= edAddInputDataStreamPort(port);
190   return ret;
191 }
192
193
194 int OutputCalStreamPort::removeInPort(InPort *inPort, bool forward) throw(Exception)
195 {
196   DEBTRACE("OutputCalStreamPort::removeInPort");
197   if(inPort->getNameOfTypeOfCurrentInstance()!=InputCalStreamPort::NAME && !forward)
198     {
199       string what="not compatible type of port requested during destruction of for link FROM ";
200       what+=NAME; what+=" TO "; what+=inPort->getNameOfTypeOfCurrentInstance();
201       throw Exception(what);
202     }
203   return edRemoveInputDataStreamPort(static_cast<InputDataStreamPort *>(inPort),forward);
204 }
205