Salome HOME
Issue #1860: fix end lines with spaces
[modules/shaper.git] / src / Model / Model_AttributeValidator.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        Model_AttributeValidator.cpp
4 // Created:     29 July 2015
5 // Author:      Sergey POKHODENKO
6
7 #include "Model_AttributeValidator.h"
8
9 #include <Events_InfoMessage.h>
10
11 #include <ModelAPI_AttributeDouble.h>
12 #include <ModelAPI_AttributeInteger.h>
13
14 #include <GeomDataAPI_Point.h>
15 #include <GeomDataAPI_Point2D.h>
16
17 bool Model_AttributeValidator::isValid(const AttributePtr& theAttribute,
18                                        const std::list<std::string>& theArguments,
19                                        Events_InfoMessage& theError) const
20 {
21   if (theAttribute->attributeType() == ModelAPI_AttributeInteger::typeId()) {
22     AttributeIntegerPtr anAttribue =
23         std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(theAttribute);
24     if (!anAttribue->expressionError().empty()) {
25       theError = "Expression error: %1";
26       theError.arg(anAttribue->expressionError());
27       return false;
28     }
29   } else
30   if (theAttribute->attributeType() == ModelAPI_AttributeDouble::typeId()) {
31     AttributeDoublePtr anAttribue =
32         std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
33     if (!anAttribue->expressionError().empty()) {
34       theError = "Expression error: %1";
35       theError.arg(anAttribue->expressionError());
36       return false;
37     }
38   } else
39   if (theAttribute->attributeType() == GeomDataAPI_Point::typeId()) {
40     AttributePointPtr anAttribue =
41         std::dynamic_pointer_cast<GeomDataAPI_Point>(theAttribute);
42
43     const char* aComponent[] = {"X", "Y", "Z"};
44     std::string anErrorMessage;
45     for (int i = 0; i < 3; ++i) {
46       if (!anAttribue->expressionError(i).empty())
47         anErrorMessage.append("\n").append(aComponent[i])
48           .append(": ").append(anAttribue->expressionError(i));
49     }
50     if (!anErrorMessage.empty()) {
51       theError = "Expression error: %1";
52       theError.arg(anErrorMessage);
53       return false;
54     }
55   } else
56   if (theAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
57     AttributePoint2DPtr anAttribue =
58         std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theAttribute);
59
60     const char* aComponent[] = {"X", "Y"};
61     std::string anErrorMessage;
62     for (int i = 0; i < 2; ++i) {
63       if (!anAttribue->expressionError(i).empty())
64         anErrorMessage.append("\n").append(aComponent[i])
65           .append(": ").append(anAttribue->expressionError(i));
66     }
67     if (!anErrorMessage.empty()) {
68       theError = "Expression error: %1";
69       theError.arg(anErrorMessage);
70       return false;
71     }
72   }
73   return true;
74 }