1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomValidators_DifferentShapes.cpp
5 // Author: Natalia ERMOLAEVA
7 #include "GeomValidators_DifferentShapes.h"
9 #include <ModelAPI_AttributeSelection.h>
10 #include "ModelAPI_Object.h"
12 bool GeomValidators_DifferentShapes::isValid(const AttributePtr& theAttribute,
13 const std::list<std::string>& theArguments,
14 std::string& theError) const
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();
21 ResultPtr aResult = aSelectionAttribute->context();
23 aShape = aResult->shape();
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) {
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();
44 anAttrShape = aResult->shape();
46 if (aShape->isEqual(anAttrShape)) {
47 theError = "The feature uses equal shapes.";