- return !featureHasReferences(theAttribute);
-}
-
-bool PartSet_DifferentObjectsValidator::featureHasReferences(const AttributePtr& theAttribute) const
-{
- std::list<std::pair<std::string, std::list<ObjectPtr> > > allRefs;
- if (theAttribute->owner().get() && theAttribute->owner()->data().get())
- theAttribute->owner()->data()->referencesToObjects(allRefs);
- // collect object referenced by theAttribute
- std::list<ObjectPtr>* anAttrObjs = 0;
- std::list<std::pair<std::string, std::list<ObjectPtr> > >::iterator aRefIter = allRefs.begin();
- for(; aRefIter != allRefs.end(); aRefIter++) {
- if (theAttribute->id() == aRefIter->first)
- anAttrObjs = &(aRefIter->second);
+ else if(anAttrType == ModelAPI_AttributeSelectionList::typeId()) {
+ std::shared_ptr<ModelAPI_AttributeSelectionList> aCurSelList =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+ anAttrs = aFeature->data()->attributes(ModelAPI_AttributeSelectionList::typeId());
+ if(anAttrs.size() > 0) {
+ std::list<std::shared_ptr<ModelAPI_Attribute>>::iterator anAttrItr = anAttrs.begin();
+ for(; anAttrItr != anAttrs.end(); anAttrItr++){
+ if ((*anAttrItr).get() && (*anAttrItr)->id() != theAttribute->id()){
+ std::shared_ptr<ModelAPI_AttributeSelectionList> aRefSelList =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(*anAttrItr);
+ for(int i = 0; i < aCurSelList->size(); i++) {
+ std::shared_ptr<ModelAPI_AttributeSelection> aCurSel = aCurSelList->value(i);
+ ResultPtr aCurSelContext = aCurSel->context();
+ FeaturePtr aCurSelFeature = aCurSel->contextFeature();
+ ResultBodyPtr aCurSelCompSolidPtr = ModelAPI_Tools::bodyOwner(aCurSelContext);
+ std::shared_ptr<GeomAPI_Shape> aCurSelCompSolid;
+ if(aCurSelCompSolidPtr.get()) {
+ aCurSelCompSolid = aCurSelCompSolidPtr->shape();
+ }
+ for(int j = 0; j < aRefSelList->size(); j++) {
+ std::shared_ptr<ModelAPI_AttributeSelection> aRefSel = aRefSelList->value(j);
+ ResultPtr aRefSelContext = aRefSel->context();
+ FeaturePtr aRefSelFeature = aRefSel->contextFeature();
+ ResultBodyPtr aRefSelCompSolidPtr =
+ ModelAPI_Tools::bodyOwner(aRefSelContext);
+ std::shared_ptr<GeomAPI_Shape> aRefSelCompSolid;
+ if (aRefSelCompSolidPtr.get()) {
+ aRefSelCompSolid = aRefSelCompSolidPtr->shape();
+ }
+ if ((aCurSelCompSolid.get() && aCurSelCompSolid->isEqual(aRefSel->value()))
+ || (aRefSelCompSolid.get() && aRefSelCompSolid->isEqual(aCurSel->value()))) {
+ theError = errorMessage(EqualShapes, "", theAttribute->id(),
+ aRefSel->id());
+ return false;
+ }
+ if (aCurSelContext == aRefSelContext) {
+ if (aCurSel->value().get() == NULL || aRefSel->value().get() == NULL) {
+ theError = errorMessage(EmptyShapes, "", theAttribute->id(), aRefSel->id());
+ return false;
+ }
+ if (aCurSel->value()->isEqual(aRefSel->value())) {
+ theError = errorMessage(EqualShapes, "", theAttribute->id(), aRefSel->id());
+ return false;
+ }
+ }
+
+ // check the whole selected feature contains the result
+ if (aCurSelFeature.get()) {
+ if (aRefSelFeature.get()) {
+ if (aCurSelFeature == aRefSelFeature) {
+ theError = errorMessage(EqualShapes, "", theAttribute->id(), aRefSel->id());
+ return false;
+ }
+ }
+ else if (aRefSelContext.get() &&
+ aRefSelContext->document()->feature(aRefSelContext) == aCurSelFeature) {
+ theError = errorMessage(EqualShapes, "", theAttribute->id(), aRefSel->id());
+ return false;
+ }
+ }
+ else if (aRefSelFeature.get() && aCurSelContext.get()) {
+ if (aCurSelContext->document()->feature(aCurSelContext) == aRefSelFeature) {
+ theError = errorMessage(EqualShapes, "", theAttribute->id(), aRefSel->id());
+ return false;
+ }
+ }
+ }
+ }
+ }
+ }
+ }