X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_Validators.cpp;h=b246046d509408010fc3d474693d38225ed23082;hb=0b503091623876eda1ae9214e32f8831ef03778b;hp=278c3e637906497337b4230cf972e978c90ed773;hpb=df6afd662c4fdbc0744c45eb7f54010930e8c9f1;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_Validators.cpp b/src/PartSet/PartSet_Validators.cpp index 278c3e637..b246046d5 100644 --- a/src/PartSet/PartSet_Validators.cpp +++ b/src/PartSet/PartSet_Validators.cpp @@ -12,10 +12,12 @@ #include #include #include +#include #include #include #include +#include #include #include @@ -110,65 +112,54 @@ bool PartSet_RigidValidator::isValid(const ModuleBase_ISelection* theSelection) return (aCount > 0) && (aCount < 2); } -bool PartSet_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature, - const std::list& theArguments, - const ObjectPtr& theObject) const +bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute, + const std::list& theArguments) const { - // Check RefAttr attributes - std::list > anAttrs = - theFeature->data()->attributes(ModelAPI_AttributeRefAttr::type()); - if (anAttrs.size() > 0) { - std::list >::iterator anAttr = anAttrs.begin(); - for(; anAttr != anAttrs.end(); anAttr++) { - if (*anAttr) { - std::shared_ptr aRef = - std::dynamic_pointer_cast(*anAttr); - // check the object is already presented - if (aRef->isObject() && aRef->object() == theObject) - return false; - } + FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); + + // 1. check whether the object of the attribute is not among the feature attributes + // find the attribute's object + ObjectPtr anObject = ModuleBase_WidgetShapeSelector::getObject(theAttribute); + + // check whether the object is not among other feature attributes + if (anObject.get() != NULL) { + // Check RefAttr attributes + std::list > anAttrs = aFeature->data()->attributes(""); + //if (anAttrs.size() > 0) { + std::list >::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 = ModuleBase_WidgetShapeSelector::getObject(anAttr); + if (aCurObject && aCurObject == anObject) + return false; } } - // Check selection attributes - anAttrs = theFeature->data()->attributes(ModelAPI_AttributeSelection::type()); - if (anAttrs.size() > 0) { - std::list >::iterator anAttr = anAttrs.begin(); - for(; anAttr != anAttrs.end(); anAttr++) { - if (*anAttr) { - std::shared_ptr aRef = - std::dynamic_pointer_cast(*anAttr); - // check the object is already presented - if (aRef->isInitialized() && aRef->context() == theObject) - return false; - } - } - } - // Check selection attributes - anAttrs = theFeature->data()->attributes(ModelAPI_AttributeReference::type()); - if (anAttrs.size() > 0) { - std::list >::iterator anAttr = anAttrs.begin(); - for(; anAttr != anAttrs.end(); anAttr++) { - if (*anAttr) { - std::shared_ptr aRef = - std::dynamic_pointer_cast(*anAttr); - // check the object is already presented - if (aRef->isInitialized() && aRef->value() == theObject) - return false; + else { + // 2. collect object referenced by theAttribute and ... + if (featureHasReferences(theAttribute)) { + // 3. check whether the attribute value is not among other feature attributes + std::list > anAttrs = + aFeature->data()->attributes(ModelAPI_AttributeRefAttr::type()); + std::list >::iterator anAttr = anAttrs.begin(); + for(; anAttr != anAttrs.end(); anAttr++) { + if (*anAttr) { + std::shared_ptr aRef = + std::dynamic_pointer_cast(*anAttr); + // check the object is already presented + if (!aRef->isObject() && aRef->attr() == theAttribute) + return false; + } } + return true; } } return true; } -bool PartSet_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature, - const std::list& theArguments, - const AttributePtr& theAttribute) const -{ - return PartSet_DifferentObjectsValidator::isValid(theAttribute, theArguments); -} - -bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute, - const std::list& theArguments) const +bool PartSet_DifferentObjectsValidator::featureHasReferences(const AttributePtr& theAttribute) const { std::list > > allRefs; if (theAttribute->owner().get() && theAttribute->owner()->data().get()) @@ -198,8 +189,44 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute return true; } -bool PartSet_SketchValidator::isValid(const ObjectPtr theObject) const +bool PartSet_SketchEntityValidator::isValid(const AttributePtr& theAttribute, + const std::list& theArguments) const { - FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); - return aFeature->getKind() == SketchPlugin_Sketch::ID(); + bool isSketchEntities = true; + std::set anEntityKinds; + std::list::const_iterator anIt = theArguments.begin(), aLast = theArguments.end(); + for (; anIt != aLast; anIt++) { + anEntityKinds.insert(*anIt); + } + + std::string anAttributeType = theAttribute->attributeType(); + if (anAttributeType == ModelAPI_AttributeSelectionList::type()) { + AttributeSelectionListPtr aSelectionListAttr = + std::dynamic_pointer_cast(theAttribute); + // it filters only selection list attributes + std::string aType = aSelectionListAttr->selectionType().c_str(); + // all context objects should be sketch entities + int aSize = aSelectionListAttr->size(); + for (int i = 0; i < aSelectionListAttr->size() && isSketchEntities; i++) { + AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i); + ObjectPtr anObject = aSelectAttr->context(); + FeaturePtr aFeature = ModelAPI_Feature::feature(anObject); + isSketchEntities = anEntityKinds.find(aFeature->getKind()) != anEntityKinds.end(); + } + } + if (anAttributeType == ModelAPI_AttributeRefAttr::type()) { + std::shared_ptr aRef = + std::dynamic_pointer_cast(theAttribute); + isSketchEntities = false; + if (aRef->isObject()) { + ObjectPtr anObject = aRef->object(); + if (anObject.get() != NULL) { + FeaturePtr aFeature = ModelAPI_Feature::feature(anObject); + if (aFeature.get() != NULL) + isSketchEntities = anEntityKinds.find(aFeature->getKind()) != anEntityKinds.end(); + } + } + } + + return isSketchEntities; }