1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: Model_AttributeValidator.cpp
4 // Created: 29 July 2015
5 // Author: Sergey POKHODENKO
7 #include "Model_AttributeValidator.h"
9 #include <Events_InfoMessage.h>
11 #include <ModelAPI_AttributeDouble.h>
12 #include <ModelAPI_AttributeInteger.h>
14 #include <GeomDataAPI_Point.h>
15 #include <GeomDataAPI_Point2D.h>
17 bool Model_AttributeValidator::isValid(const AttributePtr& theAttribute,
18 const std::list<std::string>& theArguments,
19 Events_InfoMessage& theError) const
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();
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();
37 if (theAttribute->attributeType() == GeomDataAPI_Point::typeId()) {
38 AttributePointPtr anAttribue =
39 std::dynamic_pointer_cast<GeomDataAPI_Point>(theAttribute);
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));
47 if (!anErrorMessage.empty()) {
48 theError = anErrorMessage;
52 if (theAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
53 AttributePoint2DPtr anAttribue =
54 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theAttribute);
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));
62 if (!anErrorMessage.empty()) {
63 theError = anErrorMessage;