// returns all objects referenced to this
MODEL_EXPORT virtual const std::set<AttributePtr>& 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<std::pair<std::string, std::list<ObjectPtr> > >& 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<std::pair<std::string, std::list<ObjectPtr> > >& theRefs);
};
#endif
class ModelAPI_Feature;
class ModelAPI_AttributeSelection;
class ModelAPI_AttributeSelectionList;
+class ModelAPI_Object;
class GeomAPI_Shape;
/// Enumeration that contains the execution status of the Object
// returns all objects referenced to this
virtual const std::set<std::shared_ptr<ModelAPI_Attribute> >& 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<std::pair<std::string, std::list<std::shared_ptr<ModelAPI_Object> > > >& theRefs) = 0;
protected:
/// Objects are created for features automatically
ModelAPI_Data()
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_AttributeSelection.h>
#include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_Object.h>
#include <SketchPlugin_Sketch.h>
bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute,
const std::list<std::string>& theArguments) const
{
- // not implemented
+ 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);
+ }
+ 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<ObjectPtr>::iterator aReferenced = aRefIter->second.begin();
+ for(; aReferenced != aRefIter->second.end(); aReferenced++) {
+ std::list<ObjectPtr>::iterator aReferencedByMe = anAttrObjs->begin();
+ for(; aReferencedByMe != anAttrObjs->end(); aReferencedByMe++) {
+ if (*aReferenced == *aReferencedByMe) // found same objects!
+ return false;
+ }
+ }
+ }
return true;
}