Salome HOME
Fix for re-creation of old presentation of sketch circle on change radius in viewer...
[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   if (!aShape.get()) {
21     ResultPtr aResult = aSelectionAttribute->context();
22     if (aResult.get())
23       aShape = aResult->shape();
24   }
25
26   std::string aCurrentAttributeId = theAttribute->id();
27   // get all feature attributes
28   std::list<AttributePtr> anAttrs = 
29       aFeature->data()->attributes(ModelAPI_AttributeSelection::typeId());
30   if (anAttrs.size() > 0 && aShape.get() != NULL) {
31     std::list<AttributePtr>::iterator anAttr = anAttrs.begin();
32     for(; anAttr != anAttrs.end(); anAttr++) {
33       AttributePtr anAttribute = *anAttr;
34       // take into concideration only other attributes
35       if (anAttribute.get() != NULL && anAttribute->id() != aCurrentAttributeId) {
36         aSelectionAttribute = 
37           std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(anAttribute);
38         // the shape of the attribute should be not the same
39         if (aSelectionAttribute.get() != NULL) {
40           GeomShapePtr anAttrShape = aSelectionAttribute->value();
41           if (!anAttrShape.get()) {
42             ResultPtr aResult = aSelectionAttribute->context();
43             if (aResult.get())
44               anAttrShape = aResult->shape();
45             }
46             if (aShape->isEqual(anAttrShape)) {
47             return false;
48           }
49         }
50       }
51     }
52   }
53   return true;
54 }