Salome HOME
Error management -- Attribute validator returns an error.
[modules/shaper.git] / src / ModelAPI / ModelAPI_ShapeValidator.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModelAPI_ShapeValidator.cpp
4 // Created:     2 Feb 2015
5 // Author:      Natalia ERMOLAEVA
6
7 #include "ModelAPI_ShapeValidator.h"
8
9 #include <ModelAPI_AttributeSelection.h>
10 #include "ModelAPI_Object.h"
11
12 bool ModelAPI_ShapeValidator::isValid(const AttributePtr& theAttribute,
13                                       const std::list<std::string>& theArguments,
14                                       std::string& theError) const
15 {
16   FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
17   AttributeSelectionPtr aSelectionAttribute = 
18                      std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
19   GeomShapePtr aShape = aSelectionAttribute->value();
20
21   std::string aCurrentAttributeId = theAttribute->id();
22   // get all feature attributes
23   std::list<AttributePtr> anAttrs = 
24       aFeature->data()->attributes(ModelAPI_AttributeSelection::typeId());
25   if (anAttrs.size() > 0 && aShape.get() != NULL) {
26     std::list<AttributePtr>::iterator anAttr = anAttrs.begin();
27     for(; anAttr != anAttrs.end(); anAttr++) {
28       AttributePtr anAttribute = *anAttr;
29       // take into concideration only other attributes
30       if (anAttribute.get() != NULL && anAttribute->id() != aCurrentAttributeId) {
31         AttributeSelectionPtr aSelectionAttribute = 
32           std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(anAttribute);
33         // the shape of the attribute should be not the same
34         if (aSelectionAttribute.get() != NULL && aShape->isEqual(aSelectionAttribute->value())) {
35           return false;
36         }
37       }
38     }
39   }
40   return true;
41 }