From: mpv Date: Fri, 24 Aug 2018 07:22:43 +0000 (+0300) Subject: Update validation and filtration of the same shapes taking into account selection... X-Git-Tag: SHAPER_V9_1_0RC1~28 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6eda8832857ed1cdf4ed2c281faef0daccfb67a6;p=modules%2Fshaper.git Update validation and filtration of the same shapes taking into account selection of whole features --- diff --git a/src/GeomValidators/GeomValidators_DifferentShapes.cpp b/src/GeomValidators/GeomValidators_DifferentShapes.cpp index 985f7acf0..69a981be6 100644 --- a/src/GeomValidators/GeomValidators_DifferentShapes.cpp +++ b/src/GeomValidators/GeomValidators_DifferentShapes.cpp @@ -94,11 +94,13 @@ bool GeomValidators_DifferentShapes::checkEqualToCurrent(std::list std::dynamic_pointer_cast(theCurrentAttribute); GeomShapePtr aShape = aSelectionAttribute->value(); + ResultPtr aResultContext = aSelectionAttribute->context(); if (!aShape.get()) { - ResultPtr aResult = aSelectionAttribute->context(); - if (aResult.get()) - aShape = aResult->shape(); + if (aResultContext.get()) + aShape = aResultContext->shape(); } + // whole feature selection + FeaturePtr aFeature = aSelectionAttribute->contextFeature(); std::string aCurrentAttributeId = theCurrentAttribute->id(); if (theAttributes.size() > 0 && aShape.get() != NULL) { @@ -112,14 +114,31 @@ bool GeomValidators_DifferentShapes::checkEqualToCurrent(std::list // the shape of the attribute should be not the same if (aSelectionAttribute.get() != NULL) { GeomShapePtr anAttrShape = aSelectionAttribute->value(); + ResultPtr aResult = aSelectionAttribute->context(); if (!anAttrShape.get()) { - ResultPtr aResult = aSelectionAttribute->context(); if (aResult.get()) anAttrShape = aResult->shape(); } if (aShape->isEqual(anAttrShape)) { return false; } + if (aFeature.get()) { + if (aResult.get()) { // check result is in feature + if (aResult->document()->feature(aResult) == aFeature) + return false; + } + else { // check selection of the same features + if (aFeature == aSelectionAttribute->contextFeature()) + return false; + } + } + else { + if (!aResult.get() && aResultContext.get()) { + FeaturePtr aSelectedFeature = aSelectionAttribute->contextFeature(); + if (aResultContext->document()->feature(aResultContext) == aSelectedFeature) + return false; + } + } } } } diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.cpp b/src/ModuleBase/ModuleBase_WidgetValidated.cpp index 91713b65b..76dfc2909 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.cpp +++ b/src/ModuleBase/ModuleBase_WidgetValidated.cpp @@ -421,31 +421,42 @@ void ModuleBase_WidgetValidated::filterPresentations(QList& theValues) { - std::set aCompSolids; + std::set aFilterOut; // all objects that must be filtered out with their children QList aValidatedValues; // Collect compsolids. QList::const_iterator anIt = theValues.begin(), aLast = theValues.end(); - for (; anIt != aLast; anIt++) { + for(; anIt != aLast; anIt++) { const ModuleBase_ViewerPrsPtr& aViewerPrs = *anIt; ObjectPtr anObject = aViewerPrs->object(); ResultBodyPtr aResultCompSolid = std::dynamic_pointer_cast(anObject); - if(aResultCompSolid.get() && aResultCompSolid->numberOfSubs() > 0) { - aCompSolids.insert(aResultCompSolid); + if (aResultCompSolid.get()) { + for(int aSubIndex = 0; aSubIndex < aResultCompSolid->numberOfSubs(); aSubIndex++) + aFilterOut.insert(aResultCompSolid->subResult(aSubIndex)); + } else { // it could be a whole feature selected, so, add all results of this feature + FeaturePtr aFeature = std::dynamic_pointer_cast(anObject); + if (aFeature.get()) { + std::list::const_iterator aRes = aFeature->results().cbegin(); + for(; aRes != aFeature->results().cend(); aRes++) + aFilterOut.insert(*aRes); + } } } // Filter sub-solids of compsolids. anIt = theValues.begin(); - for (; anIt != aLast; anIt++) { + for(; anIt != aLast; anIt++) { const ModuleBase_ViewerPrsPtr& aViewerPrs = *anIt; ObjectPtr anObject = aViewerPrs->object(); ResultPtr aResult = std::dynamic_pointer_cast(anObject); - ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aResult); - if(aResCompSolidPtr.get() && (aCompSolids.find(aResCompSolidPtr) != aCompSolids.end())) { - // Skip sub-solid of compsolid. - continue; + while(aResult.get()) { + if (aFilterOut.find(aResult) != aFilterOut.end()) // skip if parent is filtered out + break; + aResult = ModelAPI_Tools::bodyOwner(aResult); // iterate all parents + } + if (aResult.get()) { + continue; // skip } else { aValidatedValues.append(*anIt); } diff --git a/src/PartSet/PartSet_Validators.cpp b/src/PartSet/PartSet_Validators.cpp index 32fea8398..f1cef7447 100755 --- a/src/PartSet/PartSet_Validators.cpp +++ b/src/PartSet/PartSet_Validators.cpp @@ -500,6 +500,7 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute AttributeSelectionPtr anAttr = std::dynamic_pointer_cast(theAttribute); ResultPtr aContext = anAttr->context(); + FeaturePtr aContextFeature = anAttr->contextFeature(); GeomShapePtr aShape = anAttr->value(); // Check selection attributes @@ -518,6 +519,24 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute return false; } } + // check the whole selected feature contains the result + if (aContextFeature.get()) { + if (aRef->contextFeature().get()) { + if (aContextFeature == aRef->contextFeature()) { + theError = errorMessage(EqualShapes, "", theAttribute->id(), aRef->id()); + return false; + } + } else if (aRef->context().get() && + aRef->context()->document()->feature(aRef->context()) == aContextFeature) { + theError = errorMessage(EqualShapes, "", theAttribute->id(), aRef->id()); + return false; + } + } else if (aRef->contextFeature().get() && aContext.get()) { + if (aContext->document()->feature(aContext) == aRef->contextFeature()) { + theError = errorMessage(EqualShapes, "", theAttribute->id(), aRef->id()); + return false; + } + } } } } @@ -558,6 +577,7 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute for(int i = 0; i < aCurSelList->size(); i++) { std::shared_ptr aCurSel = aCurSelList->value(i); ResultPtr aCurSelContext = aCurSel->context(); + FeaturePtr aCurSelFeature = aCurSel->contextFeature(); ResultBodyPtr aCurSelCompSolidPtr = ModelAPI_Tools::bodyOwner(aCurSelContext); std::shared_ptr aCurSelCompSolid; if(aCurSelCompSolidPtr.get()) { @@ -566,27 +586,47 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute for(int j = 0; j < aRefSelList->size(); j++) { std::shared_ptr aRefSel = aRefSelList->value(j); ResultPtr aRefSelContext = aRefSel->context(); + FeaturePtr aRefSelFeature = aRefSel->contextFeature(); ResultBodyPtr aRefSelCompSolidPtr = ModelAPI_Tools::bodyOwner(aRefSelContext); std::shared_ptr aRefSelCompSolid; - if(aRefSelCompSolidPtr.get()) { + 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; + theError = errorMessage(EqualShapes, "", theAttribute->id(), + aRefSel->id()); + return false; } - if(aCurSelContext == aRefSelContext) { + if (aCurSelContext == aRefSelContext) { if (aCurSel->value().get() == NULL || aRefSel->value().get() == NULL) { - theError = errorMessage(EmptyShapes, "", theAttribute->id(), - aRefSel->id()); + theError = errorMessage(EmptyShapes, "", theAttribute->id(), aRefSel->id()); return false; } if (aCurSel->value()->isEqual(aRefSel->value())) { - theError = errorMessage(EqualShapes, "", theAttribute->id(), - aRefSel->id()); + 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; } }