]> SALOME platform Git repositories - modules/shaper.git/blob - src/Model/Model_AttributeValidator.cpp
Salome HOME
Validators return InfoMessage instead of string as an error
[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 = anAttribue->expressionError();
26       return false;
27     }
28   } else
29   if (theAttribute->attributeType() == ModelAPI_AttributeDouble::typeId()) {
30     AttributeDoublePtr anAttribue = 
31         std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
32     if (!anAttribue->expressionError().empty()) {
33       theError = anAttribue->expressionError();
34       return false;
35     }
36   } else
37   if (theAttribute->attributeType() == GeomDataAPI_Point::typeId()) {
38     AttributePointPtr anAttribue = 
39         std::dynamic_pointer_cast<GeomDataAPI_Point>(theAttribute);
40
41     const char* aComponent[] = {"X", "Y", "Z"};
42     std::string anErrorMessage;
43     for (int i = 0; i < 3; ++i) {
44       if (!anAttribue->expressionError(i).empty())
45         anErrorMessage.append("\n").append(aComponent[i]).append(": ").append(anAttribue->expressionError(i));
46     }
47     if (!anErrorMessage.empty()) {
48       theError = anErrorMessage;
49       return false;
50     }
51   } else
52   if (theAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
53     AttributePoint2DPtr anAttribue = 
54         std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theAttribute);
55
56     const char* aComponent[] = {"X", "Y"};
57     std::string anErrorMessage;
58     for (int i = 0; i < 2; ++i) {
59       if (!anAttribue->expressionError(i).empty())
60         anErrorMessage.append("\n").append(aComponent[i]).append(": ").append(anAttribue->expressionError(i));
61     }
62     if (!anErrorMessage.empty()) {
63       theError = anErrorMessage;
64       return false;
65     }
66   }
67   return true;
68 }
69