From 907740d70f2879c502146b8cfef3e95268ceb50a Mon Sep 17 00:00:00 2001 From: mpv Date: Fri, 26 Oct 2018 11:21:24 +0300 Subject: [PATCH] Update the context search after the restore by name basing on TestFillEdgeVertex.py case --- src/Model/Model_AttributeSelection.cpp | 118 +++++++++++++------------ src/Model/Model_AttributeSelection.h | 4 + 2 files changed, 67 insertions(+), 55 deletions(-) diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index 6b008ce7c..20bdc6284 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -188,8 +188,14 @@ bool Model_AttributeSelection::setValue(const ObjectPtr& theContext, if (aConstruction->isInfinite()) { // For correct naming selection, put the shape into the naming structure. // It seems sub-shapes are not needed: only this shape is (and can be) selected. + /* TNaming_Builder aBuilder(aSelLab); aBuilder.Generated(aConstruction->shape()->impl()); + std::string anInfinitiveName = contextName(aConstruction); + TDataStd_Name::Set(aSelLab, anInfinitiveName.c_str()); + std::dynamic_pointer_cast(owner()->document()) + ->addNamingName(aSelLab, anInfinitiveName.c_str()); + */ } } else if (theContext->groupName() == ModelAPI_ResultPart::group()) { aSelLab.ForgetAllAttributes(true); @@ -1022,8 +1028,11 @@ void Model_AttributeSelection::selectSubShape( if (aContext.get() && aContext->shape().get()) { TopoDS_Shape aContextShape = aContext->shape()->impl(); if (aSelector.solve(aContextShape)) { + TopoDS_Shape aSelectorShape = aSelector.value(); GeomShapePtr aShapeToBeSelected(new GeomAPI_Shape); - aShapeToBeSelected->setImpl(new TopoDS_Shape(aSelector.value())); + aShapeToBeSelected->setImpl(new TopoDS_Shape(aSelectorShape)); + // make the context result the latest existing + aContext = newestContext(aContext, aShapeToBeSelected); if (aCenterType != NOT_CENTER) { if (!aShapeToBeSelected->isEdge()) continue; @@ -1667,57 +1676,76 @@ bool Model_AttributeSelection::restoreContext(std::string theName, } } - /* to find the latest lower result that keeps given shape + if (aCont.get()) { + theContext = std::dynamic_pointer_cast(aCont->data())->label(); + } + return true; +} + +bool Model_AttributeSelection::isLater( + const TDF_Label theResult1, const TDF_Label theResult2) const +{ + std::shared_ptr aDoc = myRestoreDocument.get() ? myRestoreDocument : + std::dynamic_pointer_cast(owner()->document()); + FeaturePtr aFeat1 = aDoc->featureByLab(theResult1); + if (!aFeat1.get()) + return false; + FeaturePtr aFeat2 = aDoc->featureByLab(theResult2); + if (!aFeat2.get()) + return false; + return aDoc->isLaterByDep(aFeat1, aFeat2); +} + +ResultPtr Model_AttributeSelection::newestContext( + const ResultPtr theCurrent, const GeomShapePtr theValue) +{ + ResultPtr aResult = theCurrent; + GeomShapePtr aSelectedShape = theValue.get() ? theValue : theCurrent->shape(); + std::shared_ptr aDoc = + std::dynamic_pointer_cast(owner()->document()); bool aFindNewContext = true; - while(aFindNewContext && aCont.get()) { + while (aFindNewContext && aResult.get()) { aFindNewContext = false; // try to find the last context to find the up to date shape - TopoDS_Shape aConShape = aCont->shape()->impl(); + TopoDS_Shape aConShape = aResult->shape()->impl(); Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(aConShape, selectionLabel()); if (!aNS.IsNull()) { aNS = TNaming_Tool::CurrentNamedShape(aNS); - if (!aNS.IsNull() && isOlderThanMe(aNS->Label())) { // scope check is for 2228 + if (!aNS.IsNull() && isLater(selectionLabel(), aNS->Label()) && + isLater(aNS->Label(), std::dynamic_pointer_cast(aResult->data())->label())) { TDF_Label aLab = aNS->Label(); - if (aLab.Depth() % 2 == 0) - aLab = aLab.Father(); - ObjectPtr anObj = aDoc->objects()->object(aLab); - while (!anObj.get() && aLab.Depth() > 5) { - aLab = aLab.Father().Father(); - anObj = aDoc->objects()->object(aLab); - } - - if (anObj.get()) { - ResultPtr aRes = std::dynamic_pointer_cast(anObj); - if (aRes) { - aCont = aRes; + ResultPtr aRes = aDoc->resultByLab(aLab); + if (aRes.get()) { + if (aRes->shape()->isSubShape(aSelectedShape)) { + aResult = aRes; aFindNewContext = true; + continue; } } } - } else if (aCont->groupName() == ModelAPI_ResultBody::group()) { + } + if (aResult->groupName() == ModelAPI_ResultBody::group()) { // try to search newer context by the concealment references // take references to all results: root one, any sub std::list allRes; ResultPtr aCompContext; - if (aCont->groupName() == ModelAPI_ResultBody::group()) { - ResultBodyPtr aCompBody = ModelAPI_Tools::bodyOwner(aCont, true); - if (aCompBody.get()) { - ModelAPI_Tools::allSubs(aCompBody, allRes); - allRes.push_back(aCompBody); - aCompContext = aCompBody; - } + ResultBodyPtr aCompBody = ModelAPI_Tools::bodyOwner(aResult, true); + if (aCompBody.get()) { + ModelAPI_Tools::allSubs(aCompBody, allRes); + allRes.push_back(aCompBody); + aCompContext = aCompBody; } if (allRes.empty()) - allRes.push_back(aCont); + allRes.push_back(aResult); - for(std::list::iterator aSub = allRes.begin(); aSub != allRes.end(); aSub++) { + for (std::list::iterator aSub = allRes.begin(); aSub != allRes.end(); aSub++) { ResultPtr aResCont = *aSub; ResultBodyPtr aResBody = std::dynamic_pointer_cast(aResCont); if (aResBody.get() && aResBody->numberOfSubs() > 0 && aResBody != aCompContext) continue; // only lower and higher level subs are counted const std::set& aRefs = aResCont->data()->refsToMe(); std::set::const_iterator aRef = aRefs.begin(); - for(; !aFindNewContext && aRef != aRefs.end(); aRef++) { + for (; !aFindNewContext && aRef != aRefs.end(); aRef++) { if (!aRef->get() || !(*aRef)->owner().get()) continue; // concealed attribute only @@ -1732,20 +1760,18 @@ bool Model_AttributeSelection::restoreContext(std::string theName, std::list aRefFeatResults; ModelAPI_Tools::allResults(aRefFeat, aRefFeatResults); std::list::iterator aRefResIter = aRefFeatResults.begin(); - for(; aRefResIter != aRefFeatResults.end(); aRefResIter++) { + for (; aRefResIter != aRefFeatResults.end(); aRefResIter++) { ResultBodyPtr aBody = std::dynamic_pointer_cast(*aRefResIter); if (aBody.get() && aBody->numberOfSubs() == 0) // add only lower level subs aResults.push_back(aBody); } std::list >::iterator aResIter = aResults.begin(); - for(; aResIter != aResults.end(); aResIter++) { + for (; aResIter != aResults.end(); aResIter++) { if (!aResIter->get() || !(*aResIter)->data()->isValid() || (*aResIter)->isDisabled()) continue; GeomShapePtr aShape = (*aResIter)->shape(); - GeomShapePtr aSelectedShape = - aShapeToBeSelected.get() ? aShapeToBeSelected : aCont->shape(); if (aShape.get() && aShape->isSubShape(aSelectedShape, false)) { - aCont = *aResIter; // found new context (produced from this) with same subshape + aResult = *aResIter; // found new context (produced from this) with same subshape aFindNewContext = true; // continue searching futher break; } @@ -1755,7 +1781,7 @@ bool Model_AttributeSelection::restoreContext(std::string theName, } } // if compsolid is context, try to take sub-solid as context: like in GUI and scripts - ResultBodyPtr aComp = std::dynamic_pointer_cast(aCont); + ResultBodyPtr aComp = std::dynamic_pointer_cast(aResult); if (aComp && aComp->numberOfSubs()) { std::list allSubs; ModelAPI_Tools::allSubs(aComp, allSubs); @@ -1763,29 +1789,11 @@ bool Model_AttributeSelection::restoreContext(std::string theName, for (; aS != allSubs.end(); aS++) { ResultBodyPtr aSub = std::dynamic_pointer_cast(*aS); if (aSub && aSub->numberOfSubs() == 0 && aSub->shape().get() && - aSub->shape()->isSubShape(aShapeToBeSelected)) { - aCont = aSub; + aSub->shape()->isSubShape(aSelectedShape)) { + aResult = aSub; break; } } } - */ - if (aCont.get()) { - theContext = std::dynamic_pointer_cast(aCont->data())->label(); - } - return true; -} - -bool Model_AttributeSelection::isLater( - const TDF_Label theResult1, const TDF_Label theResult2) const -{ - std::shared_ptr aDoc = myRestoreDocument.get() ? myRestoreDocument : - std::dynamic_pointer_cast(owner()->document()); - FeaturePtr aFeat1 = aDoc->featureByLab(theResult1); - if (!aFeat1.get()) - return false; - FeaturePtr aFeat2 = aDoc->featureByLab(theResult2); - if (!aFeat2.get()) - return false; - return aDoc->isLaterByDep(aFeat1, aFeat2); + return aResult; } diff --git a/src/Model/Model_AttributeSelection.h b/src/Model/Model_AttributeSelection.h index 4c8f09f2a..8f692da98 100644 --- a/src/Model/Model_AttributeSelection.h +++ b/src/Model/Model_AttributeSelection.h @@ -188,6 +188,10 @@ protected: ResultPtr theContext, TopoDS_Shape theValShape, TDF_Label theAccessLabel, std::list& theResults, TopTools_ListOfShape& theValShapes); + /// Searches for the newest context, modification of the current, that contains theValue + ResultPtr newestContext(const ResultPtr theCurrent, + const std::shared_ptr theValue); + /// computes theShapes list - shapes that were generated/modified/deleted the theValShape /// during creation from new to old context void computeValues(ResultPtr theOldContext, ResultPtr theNewContext, TopoDS_Shape theValShape, -- 2.39.2