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 <ModelAPI_AttributeDouble.h>
10 #include <ModelAPI_AttributeInteger.h>
12 #include <GeomDataAPI_Point.h>
13 #include <GeomDataAPI_Point2D.h>
15 bool Model_AttributeValidator::isValid(const AttributePtr& theAttribute,
16 const std::list<std::string>& theArguments,
17 std::string& theError) const
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();
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();
35 if (theAttribute->attributeType() == GeomDataAPI_Point::typeId()) {
36 AttributePointPtr anAttribue =
37 std::dynamic_pointer_cast<GeomDataAPI_Point>(theAttribute);
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));
45 if (!anErrorMessage.empty()) {
46 theError = anErrorMessage;
50 if (theAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
51 AttributePoint2DPtr anAttribue =
52 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theAttribute);
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));
60 if (!anErrorMessage.empty()) {
61 theError = anErrorMessage;