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 = "Expression error: %1";
26 theError.arg(anAttribue->expressionError());
30 if (theAttribute->attributeType() == ModelAPI_AttributeDouble::typeId()) {
31 AttributeDoublePtr anAttribue =
32 std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
33 if (!anAttribue->expressionError().empty()) {
34 theError = "Expression error: %1";
35 theError.arg(anAttribue->expressionError());
39 if (theAttribute->attributeType() == GeomDataAPI_Point::typeId()) {
40 AttributePointPtr anAttribue =
41 std::dynamic_pointer_cast<GeomDataAPI_Point>(theAttribute);
43 const char* aComponent[] = {"X", "Y", "Z"};
44 std::string anErrorMessage;
45 for (int i = 0; i < 3; ++i) {
46 if (!anAttribue->expressionError(i).empty())
47 anErrorMessage.append("\n").append(aComponent[i])
48 .append(": ").append(anAttribue->expressionError(i));
50 if (!anErrorMessage.empty()) {
51 theError = "Expression error: %1";
52 theError.arg(anErrorMessage);
56 if (theAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
57 AttributePoint2DPtr anAttribue =
58 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theAttribute);
60 const char* aComponent[] = {"X", "Y"};
61 std::string anErrorMessage;
62 for (int i = 0; i < 2; ++i) {
63 if (!anAttribue->expressionError(i).empty())
64 anErrorMessage.append("\n").append(aComponent[i])
65 .append(": ").append(anAttribue->expressionError(i));
67 if (!anErrorMessage.empty()) {
68 theError = "Expression error: %1";
69 theError.arg(anErrorMessage);