Salome HOME
Validators return InfoMessage instead of string as an error
[modules/shaper.git] / src / GeomValidators / GeomValidators_Finite.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomValidators_Finite.cpp
4 // Created:     27 Aug 2015
5 // Author:      Natalia ERMOLAEVA
6
7 #include <GeomValidators_Finite.h>
8
9 #include <Events_InfoMessage.h>
10
11 #include <ModelAPI_AttributeSelectionList.h>
12 #include <ModelAPI_ResultConstruction.h>
13
14 bool GeomValidators_Finite::isValid(const AttributePtr& theAttribute,
15                                    const std::list<std::string>& theArguments,
16                                    Events_InfoMessage& theError) const
17 {
18   bool aValid = true;
19
20   if (theAttribute->attributeType() == ModelAPI_AttributeSelectionList::typeId()) {
21     AttributeSelectionListPtr aSelectionListAttr = 
22                       std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
23     for (int i = 0, aSize = aSelectionListAttr->size(); i < aSize; i++) {
24       AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
25       ResultPtr aResult = aSelectAttr->context();
26       if (aResult.get() && aResult->groupName() == ModelAPI_ResultConstruction::group()) {
27         ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aResult);
28         if (aConstruction.get() && aConstruction->isInfinite()) {
29           aValid = false;
30           theError = "Infinite result is selected.";
31         }
32       }
33     }
34   }
35   return aValid;
36 }
37