1 // Copyright (C) 2016-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
19 // Author : Anthony Geay (EDF R&D)
21 #include "YDFXGUIPortsValidator.hxx"
23 #include <QIntValidator>
24 #include <QDoubleValidator>
26 #include "YACSEvalPort.hxx"
27 #include "YACSEvalSeqAny.hxx"
29 QValidator *BuildValidatorFromPort(QObject *parent, YACSEvalPort *port)
33 std::string tod(port->getTypeOfData());
34 if(tod==YACSEvalAnyDouble::TYPE_REPR)
35 return new QDoubleValidator(parent);
36 if(tod==YACSEvalAnyInt::TYPE_REPR)
37 return new QIntValidator(parent);
41 YACSEvalAny *BuildAnyFromString(const QString& text, YACSEvalPort *port)
45 std::string tod(port->getTypeOfData());
46 if(tod==YACSEvalAnyDouble::TYPE_REPR)
49 double val(text.toDouble(&isok));
52 return new YACSEvalAnyDouble(val);
54 if(tod==YACSEvalAnyInt::TYPE_REPR)
57 int val(text.toInt(&isok));
60 return new YACSEvalAnyInt(val);
65 QString BuidStringFromAny(YACSEvalAny *val)
69 if(val->getTypeOfData()==YACSEvalAnyDouble::TYPE_REPR)
71 YACSEvalAnyDouble *valc(static_cast<YACSEvalAnyDouble *>(val));
72 return QString::number(valc->toDouble(),'g',16);
74 if(val->getTypeOfData()==YACSEvalAnyInt::TYPE_REPR)
76 YACSEvalAnyInt *valc(static_cast<YACSEvalAnyInt *>(val));
77 return QString::number(valc->toInt());
82 YACSEvalSeqAny *BuildEmptySeqFromPort(YACSEvalPort *port)
84 std::string tod(port->getTypeOfData());
85 if(tod==YACSEvalAnyDouble::TYPE_REPR)
87 std::vector<double> v;
88 return new YACSEvalSeqAnyDouble(v);
90 if(tod==YACSEvalAnyInt::TYPE_REPR)
93 return new YACSEvalSeqAnyInt(v);