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 email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #include "Model_AttributeValidator.h"
22 #include <Events_InfoMessage.h>
24 #include <ModelAPI_AttributeDouble.h>
25 #include <ModelAPI_AttributeInteger.h>
27 #include <GeomDataAPI_Point.h>
28 #include <GeomDataAPI_Point2D.h>
30 bool Model_AttributeValidator::isValid(const AttributePtr& theAttribute,
31 const std::list<std::string>& theArguments,
32 Events_InfoMessage& theError) const
34 if (theAttribute->attributeType() == ModelAPI_AttributeInteger::typeId()) {
35 AttributeIntegerPtr anAttribue =
36 std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(theAttribute);
37 if (!anAttribue->expressionError().empty()) {
38 theError = "Expression error: %1";
39 theError.arg(anAttribue->expressionError());
43 if (theAttribute->attributeType() == ModelAPI_AttributeDouble::typeId()) {
44 AttributeDoublePtr anAttribue =
45 std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
46 if (!anAttribue->expressionError().empty()) {
47 theError = "Expression error: %1";
48 theError.arg(anAttribue->expressionError());
52 if (theAttribute->attributeType() == GeomDataAPI_Point::typeId()) {
53 AttributePointPtr anAttribue =
54 std::dynamic_pointer_cast<GeomDataAPI_Point>(theAttribute);
56 const char* aComponent[] = {"X", "Y", "Z"};
57 std::string anErrorMessage;
58 for (int i = 0; i < 3; ++i) {
59 if (!anAttribue->expressionError(i).empty())
60 anErrorMessage.append("\n").append(aComponent[i])
61 .append(": ").append(anAttribue->expressionError(i));
63 if (!anErrorMessage.empty()) {
64 theError = "Expression error: %1";
65 theError.arg(anErrorMessage);
69 if (theAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
70 AttributePoint2DPtr anAttribue =
71 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theAttribute);
73 const char* aComponent[] = {"X", "Y"};
74 std::string anErrorMessage;
75 for (int i = 0; i < 2; ++i) {
76 if (!anAttribue->expressionError(i).empty())
77 anErrorMessage.append("\n").append(aComponent[i])
78 .append(": ").append(anAttribue->expressionError(i));
80 if (!anErrorMessage.empty()) {
81 theError = "Expression error: %1";
82 theError.arg(anErrorMessage);