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 <Events_InfoMessage.h>
11 #include <ModelAPI_AttributeSelection.h>
12 #include "ModelAPI_Object.h"
14 bool GeomValidators_DifferentShapes::isValid(const AttributePtr& theAttribute,
15 const std::list<std::string>& theArguments,
16 Events_InfoMessage& theError) const
18 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
19 AttributeSelectionPtr aSelectionAttribute =
20 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
21 GeomShapePtr aShape = aSelectionAttribute->value();
23 ResultPtr aResult = aSelectionAttribute->context();
25 aShape = aResult->shape();
28 std::string aCurrentAttributeId = theAttribute->id();
29 // get all feature attributes
30 std::list<AttributePtr> anAttrs =
31 aFeature->data()->attributes(ModelAPI_AttributeSelection::typeId());
32 if (anAttrs.size() > 0 && aShape.get() != NULL) {
33 std::list<AttributePtr>::iterator anAttr = anAttrs.begin();
34 for(; anAttr != anAttrs.end(); anAttr++) {
35 AttributePtr anAttribute = *anAttr;
36 // take into concideration only other attributes
37 if (anAttribute.get() != NULL && anAttribute->id() != aCurrentAttributeId) {
39 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(anAttribute);
40 // the shape of the attribute should be not the same
41 if (aSelectionAttribute.get() != NULL) {
42 GeomShapePtr anAttrShape = aSelectionAttribute->value();
43 if (!anAttrShape.get()) {
44 ResultPtr aResult = aSelectionAttribute->context();
46 anAttrShape = aResult->shape();
48 if (aShape->isEqual(anAttrShape)) {
49 theError = "The feature uses equal shapes.";