Version: 9.16.0
PresetPorts.cxx
Go to the documentation of this file.
1// Copyright (C) 2006-2026 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 "TypeConversions.hxx"
21#include "PresetPorts.hxx"
22#include "PythonPorts.hxx"
23#include "TypeCode.hxx"
24#include <iostream>
25
26//#define _DEVDEBUG_
27#include "YacsTrace.hxx"
28
29using namespace YACS::ENGINE;
30using namespace std;
31
40OutputPresetPort::OutputPresetPort(const std::string& name, Node* node, TypeCode* type)
41 : OutputXmlPort(name, node, type),
42 DataPort(name, node, type),
43 Port(node)
44{
45}
46
48 : OutputXmlPort(other,newHelder),
49 DataPort(other,newHelder),
50 Port(other,newHelder),_storeData(other._storeData)
51{
52}
53
55{
56 return new OutputPresetPort(*this,newHelder);
57}
58
59void OutputPresetPort::setData(std::string data)
60{
61 _storeData = data;
62 DEBTRACE( "OutputPresetPort::setData " << _storeData );
63 modified();
64}
65
67{
68 DEBTRACE("OutputPresetPort::checkBasicConsistency " << _storeData);
69 if (_storeData.empty())
70 {
71 std::string what("OutputPresetPort: ");
72 what += getName();
73 what += " is not initialised";
74 throw Exception(what);
75 }
76}
77
79{
80 DEBTRACE("OutputPresetPort::getData " << _storeData);
81 if(_storeData.substr(0,7) == "<value>")
82 {
83 return _storeData;
84 }
85 else
86 {
87 std::string value;
88 switch(edGetType()->kind())
89 {
90 case Double:
91 value="<value><double>"+_storeData+"</double></value>";
92 break;
93 case Int:
94 value="<value><int>"+_storeData+"</int></value>";
95 break;
96 case String:
97 value="<value><string>"+_storeData+"</string></value>";
98 break;
99 case Bool:
100 value="<value><boolean>"+_storeData+"</boolean></value>";
101 break;
102 case Objref:
103 value="<value><objref>"+_storeData+"</objref></value>";
104 break;
105 case Sequence:
106 case Array:
107 value="<value><array><data>"+_storeData+"</data></array></value>";
108 break;
109 case Struct:
110 value="<value><struct><data>"+_storeData+"</data></struct></value>";
111 break;
112 default:
113 break;
114 }
115 return value;
116 }
117}
118
120{
121 return getData();
122}
123
125{
126 DEBTRACE(getData());
127 if(_storeData=="")
128 {
129 Py_INCREF(Py_None);
130 return Py_None;
131 }
132 else
134}
135
137{
139 PyObject* ob=getPyObj();
140 DEBTRACE(PyObject_Str(ob));
141 std::string s=convertPyObjectToString(ob);
142 DEBTRACE(s);
143 Py_DECREF(ob);
144 return s;
145}
146
155InputPresetPort::InputPresetPort(const std::string& name, Node* node, TypeCode* type)
156 : InputXmlPort(name, node, type),
157 DataPort(name, node, type),
158 Port(node)
159{
160}
161
163 : InputXmlPort(other,newHelder),
164 DataPort(other,newHelder),
165 Port(other,newHelder),_storeData(other._storeData)
166{
167}
168
170{
171 return new InputPresetPort(*this,newHelder);
172}
173
174void InputPresetPort::setData(std::string data)
175{
176 _storeData = data;
177 DEBTRACE( "InputPresetPort::setData " << _storeData );
178 modified();
179}
180
182{
183 DEBTRACE("InputPresetPort::getData " << _storeData);
184 return _storeData;
185}
186
188{
189 return _data;
190}
191
193{
194 DEBTRACE(dump());
195 if(_data=="")
196 {
197 Py_INCREF(Py_None);
198 return Py_None;
199 }
200 else
202}
203
205{
207 PyObject* ob=getPyObj();
208 DEBTRACE(PyObject_Str(ob));
209 std::string s=convertPyObjectToString(ob);
210 DEBTRACE(s);
211 Py_DECREF(ob);
212 return s;
213}
214
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
TypeCode * edGetType() const
Definition: DataPort.hxx:53
std::string getName() const
Definition: DataPort.hxx:55
Base class for Input Ports.
Definition: InputPort.hxx:44
Class for PRESET input Ports.
Definition: PresetPorts.hxx:50
void setData(std::string data)
InputPresetPort(const std::string &name, Node *node, TypeCode *type)
virtual std::string dump()
InputPort * clone(Node *newHelder) const
virtual PyObject * getPyObj()
virtual std::string getAsString()
returns port value as a string that can be used in a GUI for example
Class for XML Input Ports.
Definition: XMLPorts.hxx:38
Base class for all nodes.
Definition: Node.hxx:70
Class for PRESET output Ports.
Definition: PresetPorts.hxx:33
virtual PyObject * getPyObj()
OutputPresetPort(const std::string &name, Node *node, TypeCode *type)
Definition: PresetPorts.cxx:40
virtual std::string getAsString()
returns port value as a string that can be used in a GUI for example
virtual std::string dump()
virtual void checkBasicConsistency() const
Check validity of output port. Nothing on base class.
Definition: PresetPorts.cxx:66
void setData(std::string data)
Definition: PresetPorts.cxx:59
OutputPort * clone(Node *newHelder) const
Definition: PresetPorts.cxx:54
Class for XML Output Ports.
Definition: XMLPorts.hxx:68
Base class for all ports.
Definition: Port.hxx:43
void modified()
Definition: Port.cxx:53
Base class for all type objects.
Definition: TypeCode.hxx:68
PyObject * convertXmlStrPyObject(const TypeCode *t, std::string data)
std::string convertPyObjectToString(PyObject *ob)