From 0caf01acad9c0f9ad5f5a0dc235ff5be21272f7d Mon Sep 17 00:00:00 2001 From: mpv Date: Thu, 22 Jan 2015 11:29:57 +0300 Subject: [PATCH] Fix for Issue #359 : implement the method of validator --- src/Model/Model_Data.h | 8 +++++--- src/ModelAPI/ModelAPI_Data.h | 5 +++++ src/PartSet/PartSet_Validators.cpp | 27 ++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/Model/Model_Data.h b/src/Model/Model_Data.h index 01b669780..64479abe1 100644 --- a/src/Model/Model_Data.h +++ b/src/Model/Model_Data.h @@ -160,14 +160,16 @@ class Model_Data : public ModelAPI_Data // returns all objects referenced to this MODEL_EXPORT virtual const std::set& refsToMe() {return myRefsToMe;} + // returns all references by attributes of this data + // \param theRefs returned list of pairs: id of referenced attribute and list of referenced objects + MODEL_EXPORT virtual void referencesToObjects( + std::list > >& theRefs); + private: // removes all information about back references void eraseBackReferences(); // adds a back reference (with identifier which attribute references to this object void addBackReference(FeaturePtr theFeature, std::string theAttrID); - // returns all references by attributes of this data - // \param the returned list of pairs: id of referenced attribute and list of referenced objects - void referencesToObjects(std::list > >& theRefs); }; #endif diff --git a/src/ModelAPI/ModelAPI_Data.h b/src/ModelAPI/ModelAPI_Data.h index 14d191b08..03e21b36f 100644 --- a/src/ModelAPI/ModelAPI_Data.h +++ b/src/ModelAPI/ModelAPI_Data.h @@ -26,6 +26,7 @@ class ModelAPI_Attribute; class ModelAPI_Feature; class ModelAPI_AttributeSelection; class ModelAPI_AttributeSelectionList; +class ModelAPI_Object; class GeomAPI_Shape; /// Enumeration that contains the execution status of the Object @@ -126,6 +127,10 @@ class MODELAPI_EXPORT ModelAPI_Data // returns all objects referenced to this virtual const std::set >& refsToMe() = 0; + // returns all references by attributes of this data + // \param theRefs returned list of pairs: id of referenced attribute and list of referenced objects + virtual void referencesToObjects( + std::list > > >& theRefs) = 0; protected: /// Objects are created for features automatically ModelAPI_Data() diff --git a/src/PartSet/PartSet_Validators.cpp b/src/PartSet/PartSet_Validators.cpp index 69c488639..c4e441767 100644 --- a/src/PartSet/PartSet_Validators.cpp +++ b/src/PartSet/PartSet_Validators.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include @@ -170,7 +171,31 @@ bool PartSet_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature, bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute, const std::list& theArguments) const { - // not implemented + std::list > > allRefs; + if (theAttribute->owner().get() && theAttribute->owner()->data().get()) + theAttribute->owner()->data()->referencesToObjects(allRefs); + // collect object referenced by theAttribute + std::list* anAttrObjs = 0; + std::list > >::iterator aRefIter = allRefs.begin(); + for(; aRefIter != allRefs.end(); aRefIter++) { + if (theAttribute->id() == aRefIter->first) + anAttrObjs = &(aRefIter->second); + } + if (!anAttrObjs || anAttrObjs->empty()) + return true; // theAttribute does not references to anything + // check with all others + for(aRefIter = allRefs.begin(); aRefIter != allRefs.end(); aRefIter++) { + if (theAttribute->id() == aRefIter->first) + continue; // do not check with myself + std::list::iterator aReferenced = aRefIter->second.begin(); + for(; aReferenced != aRefIter->second.end(); aReferenced++) { + std::list::iterator aReferencedByMe = anAttrObjs->begin(); + for(; aReferencedByMe != anAttrObjs->end(); aReferencedByMe++) { + if (*aReferenced == *aReferencedByMe) // found same objects! + return false; + } + } + } return true; } -- 2.39.2