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