]> SALOME platform Git repositories - modules/shaper.git/blob - src/Model/Model_AttributeValidator.cpp
Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / Model / Model_AttributeValidator.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
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<mailto:webmaster.salome@opencascade.com>
18 //
19
20 #include "Model_AttributeValidator.h"
21
22 #include <Events_InfoMessage.h>
23
24 #include <ModelAPI_AttributeDouble.h>
25 #include <ModelAPI_AttributeInteger.h>
26
27 #include <GeomDataAPI_Point.h>
28 #include <GeomDataAPI_Point2D.h>
29
30 bool Model_AttributeValidator::isValid(const AttributePtr& theAttribute,
31                                        const std::list<std::string>& theArguments,
32                                        Events_InfoMessage& theError) const
33 {
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());
40       return false;
41     }
42   } else
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());
49       return false;
50     }
51   } else
52   if (theAttribute->attributeType() == GeomDataAPI_Point::typeId()) {
53     AttributePointPtr anAttribue =
54         std::dynamic_pointer_cast<GeomDataAPI_Point>(theAttribute);
55
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));
62     }
63     if (!anErrorMessage.empty()) {
64       theError = "Expression error: %1";
65       theError.arg(anErrorMessage);
66       return false;
67     }
68   } else
69   if (theAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
70     AttributePoint2DPtr anAttribue =
71         std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theAttribute);
72
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));
79     }
80     if (!anErrorMessage.empty()) {
81       theError = "Expression error: %1";
82       theError.arg(anErrorMessage);
83       return false;
84     }
85   }
86   return true;
87 }