- // 1. check whether the object of the attribute is not among the feature attributes
- // find the attribute's object
- ObjectPtr anObject = GeomValidators_Tools::getObject(theAttribute);
-
- // check whether the object is not among other feature attributes
- if (anObject.get() != NULL) {
- // Check RefAttr attributes
- std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs = aFeature->data()->attributes("");
- //if (anAttrs.size() > 0) {
- std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anIt = anAttrs.begin();
- for(; anIt != anAttrs.end(); anIt++) {
- AttributePtr anAttr = *anIt;
- // the function parameter attribute should be skipped
- if (anAttr.get() == NULL || anAttr->id() == theAttribute->id())
- continue;
- ObjectPtr aCurObject = GeomValidators_Tools::getObject(anAttr);
- if (aCurObject && aCurObject == anObject)
- return false;
+ // the type of validated attributes should be equal, attributes with different types are not validated
+ // Check RefAttr attributes
+ std::string anAttrType = theAttribute->attributeType();
+ std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs;
+
+ if (anAttrType == ModelAPI_AttributeRefAttr::typeId()) {
+ AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+ bool isObject = anAttr->isObject();
+ ObjectPtr anObject = anAttr->object();
+ AttributePtr anAttributeAttr = anAttr->attr();
+
+ anAttrs = aFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
+ if (anAttrs.size() > 0) {
+ std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
+ for(; anAttr != anAttrs.end(); anAttr++) {
+ if ((*anAttr).get() && (*anAttr)->id() != theAttribute->id()) {
+ std::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
+ if (aRef->isObject() != isObject)
+ continue;
+ if (isObject) {
+ if (aRef->object() == anObject)
+ return false;
+ }
+ else { // the attribute reference
+ if (aRef->attr() == theAttribute)
+ return false;
+ }
+ }
+ }
+ }
+ }
+ else if (anAttrType == ModelAPI_AttributeRefAttr::typeId()) {
+ AttributeSelectionPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+ ResultPtr aContext = anAttr->context();
+ GeomShapePtr aShape = anAttr->value();
+
+ // Check selection attributes
+ anAttrs = aFeature->data()->attributes(ModelAPI_AttributeSelection::typeId());
+ if (anAttrs.size() > 0) {
+ std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
+ for(; anAttr != anAttrs.end(); anAttr++) {
+ if ((*anAttr).get() && (*anAttr)->id() != theAttribute->id()) {
+ std::shared_ptr<ModelAPI_AttributeSelection> aRef =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(*anAttr);
+ // check the object is already presented
+ if (aRef->context() == aContext) {
+ bool aHasShape = aShape.get() != NULL;
+ if (!aHasShape || aRef->value()->isEqual(aShape))
+ return false;
+ }
+ }
+ }