Salome HOME
Issue #1158: To use parameters in integer attributes -- Data Model
[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 <ModelAPI_AttributeDouble.h>
10 #include <ModelAPI_AttributeInteger.h>
11
12 #include <GeomDataAPI_Point.h>
13 #include <GeomDataAPI_Point2D.h>
14
15 bool Model_AttributeValidator::isValid(const AttributePtr& theAttribute, 
16                                        const std::list<std::string>& theArguments, 
17                                        std::string& theError) const
18 {
19   if (theAttribute->attributeType() == ModelAPI_AttributeInteger::typeId()) {
20     AttributeIntegerPtr anAttribue =
21         std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(theAttribute);
22     if (!anAttribue->expressionError().empty()) {
23       theError = anAttribue->expressionError();
24       return false;
25     }
26   } else
27   if (theAttribute->attributeType() == ModelAPI_AttributeDouble::typeId()) {
28     AttributeDoublePtr anAttribue = 
29         std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
30     if (!anAttribue->expressionError().empty()) {
31       theError = anAttribue->expressionError();
32       return false;
33     }
34   } else
35   if (theAttribute->attributeType() == GeomDataAPI_Point::typeId()) {
36     AttributePointPtr anAttribue = 
37         std::dynamic_pointer_cast<GeomDataAPI_Point>(theAttribute);
38
39     const char* aComponent[] = {"X", "Y", "Z"};
40     std::string anErrorMessage;
41     for (int i = 0; i < 3; ++i) {
42       if (!anAttribue->expressionError(i).empty())
43         anErrorMessage.append("\n").append(aComponent[i]).append(": ").append(anAttribue->expressionError(i));
44     }
45     if (!anErrorMessage.empty()) {
46       theError = anErrorMessage;
47       return false;
48     }
49   } else
50   if (theAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
51     AttributePoint2DPtr anAttribue = 
52         std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theAttribute);
53
54     const char* aComponent[] = {"X", "Y"};
55     std::string anErrorMessage;
56     for (int i = 0; i < 2; ++i) {
57       if (!anAttribue->expressionError(i).empty())
58         anErrorMessage.append("\n").append(aComponent[i]).append(": ").append(anAttribue->expressionError(i));
59     }
60     if (!anErrorMessage.empty()) {
61       theError = anErrorMessage;
62       return false;
63     }
64   }
65   return true;
66 }
67