Salome HOME
Issue #1834: Fix length of lines
[modules/shaper.git] / src / GeomValidators / GeomValidators_BodyShapes.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomValidators_BodyShapes.cpp
4 // Created:     21 December 2015
5 // Author:      Dmitry Bobylev
6
7 #include "GeomValidators_BodyShapes.h"
8
9 #include <Events_InfoMessage.h>
10
11 #include <ModelAPI_AttributeSelectionList.h>
12 #include <ModelAPI_Object.h>
13 #include <ModelAPI_ResultConstruction.h>
14
15 bool GeomValidators_BodyShapes::isValid(const AttributePtr& theAttribute,
16                                         const std::list<std::string>& theArguments,
17                                         Events_InfoMessage& theError) const
18 {
19   std::string anAttributeType = theAttribute->attributeType();
20   if(anAttributeType == ModelAPI_AttributeSelection::typeId()) {
21     AttributeSelectionPtr anAttrSelection =
22       std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
23     ResultPtr aContext = anAttrSelection->context();
24     if(!aContext.get()) {
25       theError = "Error: Context is empty.";
26       return false;
27     }
28
29     ResultConstructionPtr aResultConstruction =
30       std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
31     if(aResultConstruction.get()) {
32       theError = "Error: Result construction selected.";
33       return false;
34     }
35   } else if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
36     AttributeSelectionListPtr anAttrSelectionList =
37       std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
38
39     // All objects should not be result constructions.
40     for(int anIndex = 0, aSize = anAttrSelectionList->size(); anIndex < aSize; ++anIndex) {
41       AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
42       if(!isValid(anAttrSelection, theArguments, theError)) {
43         return false;
44       }
45     }
46   } else {
47     theError = "Error: Attribute \"%1\" does not supported by this validator.";
48     theError.arg(anAttributeType);
49     return false;
50   }
51
52   return true;
53 }