Salome HOME
Issue #1664 In the Sketcher, add the function Split a segment - correction for arc...
[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   const std::string anAttributeType = theAttribute->attributeType();
21
22   if(anAttributeType == ModelAPI_AttributeSelection::typeId()) {
23     AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
24     ResultPtr aResult = aSelectionAttr->context();
25     ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aResult);
26     if (aConstruction.get() && aConstruction->isInfinite()) {
27       aValid = false;
28       theError = "Infinite result is selected.";
29     }
30   } else if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
31     AttributeSelectionListPtr aSelectionListAttr = 
32                       std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
33     for (int i = 0, aSize = aSelectionListAttr->size(); i < aSize; i++) {
34       AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
35       ResultPtr aResult = aSelectAttr->context();
36       if (aResult.get() && aResult->groupName() == ModelAPI_ResultConstruction::group()) {
37         ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aResult);
38         if (aConstruction.get() && aConstruction->isInfinite()) {
39           aValid = false;
40           theError = "Infinite result is selected.";
41         }
42       }
43     }
44   }
45   return aValid;
46 }
47