1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "Model_AttributeValidator.h"
23 #include <Events_InfoMessage.h>
25 #include <ModelAPI_AttributeDouble.h>
26 #include <ModelAPI_AttributeInteger.h>
28 #include <GeomDataAPI_Point.h>
29 #include <GeomDataAPI_Point2D.h>
31 bool Model_AttributeValidator::isValid(const AttributePtr& theAttribute,
32 const std::list<std::string>& theArguments,
33 Events_InfoMessage& theError) const
35 if (theAttribute->attributeType() == ModelAPI_AttributeInteger::typeId()) {
36 AttributeIntegerPtr anAttribue =
37 std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(theAttribute);
38 if (!anAttribue->expressionError().empty()) {
39 theError = "Expression error: %1";
40 theError.arg(anAttribue->expressionError());
44 if (theAttribute->attributeType() == ModelAPI_AttributeDouble::typeId()) {
45 AttributeDoublePtr anAttribue =
46 std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
47 if (!anAttribue->expressionError().empty()) {
48 theError = "Expression error: %1";
49 theError.arg(anAttribue->expressionError());
53 if (theAttribute->attributeType() == GeomDataAPI_Point::typeId()) {
54 AttributePointPtr anAttribue =
55 std::dynamic_pointer_cast<GeomDataAPI_Point>(theAttribute);
57 const char* aComponent[] = {"X", "Y", "Z"};
58 std::string anErrorMessage;
59 for (int i = 0; i < 3; ++i) {
60 if (!anAttribue->expressionError(i).empty())
61 anErrorMessage.append("\n").append(aComponent[i])
62 .append(": ").append(anAttribue->expressionError(i));
64 if (!anErrorMessage.empty()) {
65 theError = "Expression error: %1";
66 theError.arg(anErrorMessage);
70 if (theAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
71 AttributePoint2DPtr anAttribue =
72 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theAttribute);
74 const char* aComponent[] = {"X", "Y"};
75 std::string anErrorMessage;
76 for (int i = 0; i < 2; ++i) {
77 if (!anAttribue->expressionError(i).empty())
78 anErrorMessage.append("\n").append(aComponent[i])
79 .append(": ").append(anAttribue->expressionError(i));
81 if (!anErrorMessage.empty()) {
82 theError = "Expression error: %1";
83 theError.arg(anErrorMessage);