Salome HOME
Issue #1366: Remove Sub-Shapes feature added.
[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 <ModelAPI_AttributeSelectionList.h>
10 #include <ModelAPI_Object.h>
11 #include <ModelAPI_ResultConstruction.h>
12
13 bool GeomValidators_BodyShapes::isValid(const AttributePtr& theAttribute,
14                                         const std::list<std::string>& theArguments,
15                                         std::string& theError) const
16 {
17   std::string anAttributeType = theAttribute->attributeType();
18   if(anAttributeType == ModelAPI_AttributeSelection::typeId()) {
19     AttributeSelectionPtr anAttrSelection =
20       std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
21     ResultPtr aContext = anAttrSelection->context();
22     if(!aContext.get()) {
23       theError = "Error: Context is empty.";
24       return false;
25     }
26
27     ResultConstructionPtr aResultConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
28     if(aResultConstruction.get()) {
29       theError = "Error: Result construction selected.";
30       return false;
31     }
32   } else if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
33     AttributeSelectionListPtr anAttrSelectionList =
34       std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
35
36     // All objects should not be result constructions.
37     for(int anIndex = 0, aSize = anAttrSelectionList->size(); anIndex < aSize; ++anIndex) {
38       AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
39       if(!isValid(anAttrSelection, theArguments, theError)) {
40         return false;
41       }
42     }
43   } else {
44     theError = "Error: Attribute \"" + anAttributeType + "\" does not supported by this validator.";
45     return false;
46   }
47
48   return true;
49 }