Salome HOME
Add translations
[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]).append(": ").append(anAttribue->expressionError(i));
48     }
49     if (!anErrorMessage.empty()) {
50       theError = "Expression error: %1";
51       theError.arg(anErrorMessage);
52       return false;
53     }
54   } else
55   if (theAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
56     AttributePoint2DPtr anAttribue = 
57         std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theAttribute);
58
59     const char* aComponent[] = {"X", "Y"};
60     std::string anErrorMessage;
61     for (int i = 0; i < 2; ++i) {
62       if (!anAttribue->expressionError(i).empty())
63         anErrorMessage.append("\n").append(aComponent[i]).append(": ").append(anAttribue->expressionError(i));
64     }
65     if (!anErrorMessage.empty()) {
66       theError = "Expression error: %1";
67       theError.arg(anErrorMessage);
68       return false;
69     }
70   }
71   return true;
72 }
73