Salome HOME
Fix for the issue #930: update event of erased feature should not be processed
[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 #include <ModelAPI_AttributeDouble.h>
9 #include <GeomDataAPI_Point.h>
10 #include <GeomDataAPI_Point2D.h>
11
12 bool Model_AttributeValidator::isValid(const AttributePtr& theAttribute, 
13                                        const std::list<std::string>& theArguments, 
14                                        std::string& theError) const
15 {
16   if (theAttribute->attributeType() == ModelAPI_AttributeDouble::typeId()) {
17     AttributeDoublePtr anAttribue = 
18         std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
19     if (!anAttribue->expressionError().empty()) {
20       theError = anAttribue->expressionError();
21       return false;
22     }
23   } else
24   if (theAttribute->attributeType() == GeomDataAPI_Point::typeId()) {
25     AttributePointPtr anAttribue = 
26         std::dynamic_pointer_cast<GeomDataAPI_Point>(theAttribute);
27
28     const char* aComponent[] = {"X", "Y", "Z"};
29     std::string anErrorMessage;
30     for (int i = 0; i < 3; ++i) {
31       if (!anAttribue->expressionError(i).empty())
32         anErrorMessage.append("\n").append(aComponent[i]).append(": ").append(anAttribue->expressionError(i));
33     }
34     if (!anErrorMessage.empty()) {
35       theError = anErrorMessage;
36       return false;
37     }
38   } else
39   if (theAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
40     AttributePoint2DPtr anAttribue = 
41         std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theAttribute);
42
43     const char* aComponent[] = {"X", "Y"};
44     std::string anErrorMessage;
45     for (int i = 0; i < 2; ++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 = anErrorMessage;
51       return false;
52     }
53   }
54   return true;
55 }
56