Salome HOME
Multi-selection widget to be used in the extrusion feature.
[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) const
14 {
15   FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
16   AttributeSelectionPtr aSelectionAttribute = 
17                      std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
18   GeomShapePtr aShape = aSelectionAttribute->value();
19
20   std::string aCurrentAttributeId = theAttribute->id();
21   // get all feature attributes
22   std::list<AttributePtr> anAttrs = 
23                    aFeature->data()->attributes(ModelAPI_AttributeSelection::type());
24   if (anAttrs.size() > 0 && aShape.get() != NULL) {
25     std::list<AttributePtr>::iterator anAttr = anAttrs.begin();
26     for(; anAttr != anAttrs.end(); anAttr++) {
27       AttributePtr anAttribute = *anAttr;
28       // take into concideration only other attributes
29       if (anAttribute.get() != NULL && anAttribute->id() != aCurrentAttributeId) {
30         AttributeSelectionPtr aSelectionAttribute = 
31           std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(anAttribute);
32         // the shape of the attribute should be not the same
33         if (aSelectionAttribute.get() != NULL && aShape->isEqual(aSelectionAttribute->value())) {
34           return false;
35         }
36       }
37     }
38   }
39   return true;
40 }