From ccc971b2f615b36eda675e69c0cf6f596d3074e5 Mon Sep 17 00:00:00 2001 From: mpv Date: Fri, 26 Oct 2018 17:23:58 +0300 Subject: [PATCH] Fix for TestFillWireVertex.py : take the latest context for the filter by neighbors --- src/Model/Model_AttributeSelection.cpp | 118 ++++++++++++++----------- src/Model/Model_AttributeSelection.h | 5 +- src/Model/Model_Document.cpp | 6 +- src/Selector/Selector_NameGenerator.h | 3 + src/Selector/Selector_Selector.cpp | 3 + 5 files changed, 81 insertions(+), 54 deletions(-) diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index 20bdc6284..b3357626f 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -1682,6 +1682,18 @@ bool Model_AttributeSelection::restoreContext(std::string theName, return true; } +TDF_Label Model_AttributeSelection::newestContext(const TDF_Label theCurrentContext) { + std::shared_ptr aDoc = myRestoreDocument.get() ? myRestoreDocument : + std::dynamic_pointer_cast(owner()->document()); + ResultPtr aContext = aDoc->resultByLab(theCurrentContext); + if (aContext.get()) { + aContext = newestContext(aContext, GeomShapePtr(), true); + if (aContext.get()) + return std::dynamic_pointer_cast(aContext->data())->label(); + } + return theCurrentContext; // nothing is changed +} + bool Model_AttributeSelection::isLater( const TDF_Label theResult1, const TDF_Label theResult2) const { @@ -1697,7 +1709,7 @@ bool Model_AttributeSelection::isLater( } ResultPtr Model_AttributeSelection::newestContext( - const ResultPtr theCurrent, const GeomShapePtr theValue) + const ResultPtr theCurrent, const GeomShapePtr theValue, const bool theAnyValue) { ResultPtr aResult = theCurrent; GeomShapePtr aSelectedShape = theValue.get() ? theValue : theCurrent->shape(); @@ -1716,7 +1728,7 @@ ResultPtr Model_AttributeSelection::newestContext( TDF_Label aLab = aNS->Label(); ResultPtr aRes = aDoc->resultByLab(aLab); if (aRes.get()) { - if (aRes->shape()->isSubShape(aSelectedShape)) { + if (theAnyValue || aRes->shape()->isSubShape(aSelectedShape)) { aResult = aRes; aFindNewContext = true; continue; @@ -1724,57 +1736,57 @@ ResultPtr Model_AttributeSelection::newestContext( } } } - if (aResult->groupName() == ModelAPI_ResultBody::group()) { + // TestFillWireVertex.py - sketch constructions for wire may participate too + //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; - 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(aResult); - - 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++) { - if (!aRef->get() || !(*aRef)->owner().get()) - continue; - // concealed attribute only - FeaturePtr aRefFeat = std::dynamic_pointer_cast((*aRef)->owner()); - if (!ModelAPI_Session::get()->validators()->isConcealed( - aRefFeat->getKind(), (*aRef)->id())) + std::list allRes; + ResultPtr aCompContext; + 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(aResult); + + 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++) { + if (!aRef->get() || !(*aRef)->owner().get()) + continue; + // concealed attribute only + FeaturePtr aRefFeat = std::dynamic_pointer_cast((*aRef)->owner()); + if (!ModelAPI_Session::get()->validators()->isConcealed( + aRefFeat->getKind(), (*aRef)->id())) + continue; + // search the feature result that contains sub-shape selected + std::list > aResults; + + // take all sub-results or one result + std::list aRefFeatResults; + ModelAPI_Tools::allResults(aRefFeat, aRefFeatResults); + std::list::iterator aRefResIter = aRefFeatResults.begin(); + 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++) { + if (!aResIter->get() || !(*aResIter)->data()->isValid() || (*aResIter)->isDisabled()) continue; - // search the feature result that contains sub-shape selected - std::list > aResults; - - // take all sub-results or one result - std::list aRefFeatResults; - ModelAPI_Tools::allResults(aRefFeat, aRefFeatResults); - std::list::iterator aRefResIter = aRefFeatResults.begin(); - 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++) { - if (!aResIter->get() || !(*aResIter)->data()->isValid() || (*aResIter)->isDisabled()) - continue; - GeomShapePtr aShape = (*aResIter)->shape(); - if (aShape.get() && aShape->isSubShape(aSelectedShape, false)) { - aResult = *aResIter; // found new context (produced from this) with same subshape - aFindNewContext = true; // continue searching futher - break; - } + GeomShapePtr aShape = (*aResIter)->shape(); + if (aShape.get() && (theAnyValue || aShape->isSubShape(aSelectedShape, false))) { + aResult = *aResIter; // found new context (produced from this) with same subshape + aFindNewContext = true; // continue searching futher + break; } } } @@ -1789,11 +1801,15 @@ ResultPtr Model_AttributeSelection::newestContext( for (; aS != allSubs.end(); aS++) { ResultBodyPtr aSub = std::dynamic_pointer_cast(*aS); if (aSub && aSub->numberOfSubs() == 0 && aSub->shape().get() && - aSub->shape()->isSubShape(aSelectedShape)) { + (theAnyValue || aSub->shape()->isSubShape(aSelectedShape))) { aResult = aSub; break; } } } + // in case sketch line was selected for wire, but wire was concealed and not such line anymore, + // so, actually, the sketch element was selected (which is never concealed) + if (aResult != theCurrent && aResult->isConcealed()) + aResult = theCurrent; return aResult; } diff --git a/src/Model/Model_AttributeSelection.h b/src/Model/Model_AttributeSelection.h index 8f692da98..62a3e09af 100644 --- a/src/Model/Model_AttributeSelection.h +++ b/src/Model/Model_AttributeSelection.h @@ -137,6 +137,9 @@ public: MODEL_EXPORT virtual bool restoreContext(std::string theName, TDF_Label& theContext, TDF_Label& theValue) override; + /// Returns the label of the newest context presented by the current one + MODEL_EXPORT virtual TDF_Label newestContext(const TDF_Label theCurrentContext) override; + /// Returns true if the first result is newer than the second one in the tree of features MODEL_EXPORT virtual bool isLater(const TDF_Label theResult1, const TDF_Label theResult2) const override; @@ -190,7 +193,7 @@ protected: /// Searches for the newest context, modification of the current, that contains theValue ResultPtr newestContext(const ResultPtr theCurrent, - const std::shared_ptr theValue); + const std::shared_ptr theValue, const bool theAnyValue = false); /// computes theShapes list - shapes that were generated/modified/deleted the theValShape /// during creation from new to old context diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index 6fc16f5cf..4d4207648 100755 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -1000,12 +1000,14 @@ void Model_Document::moveFeature(FeaturePtr theMoved, FeaturePtr theAfterThis) void Model_Document::updateHistory(const std::shared_ptr theObject) { - myObjs->updateHistory(theObject); + if (myObjs) + myObjs->updateHistory(theObject); } void Model_Document::updateHistory(const std::string theGroup) { - myObjs->updateHistory(theGroup); + if (myObjs) + myObjs->updateHistory(theGroup); } const std::set Model_Document::subDocuments() const diff --git a/src/Selector/Selector_NameGenerator.h b/src/Selector/Selector_NameGenerator.h index 4a06abc07..6ac0f4ce4 100644 --- a/src/Selector/Selector_NameGenerator.h +++ b/src/Selector/Selector_NameGenerator.h @@ -47,6 +47,9 @@ public: /// Returns true if the first result is older than the second one in the tree of features virtual bool isLater(const TDF_Label theResult1, const TDF_Label theResult2) const = 0; + + /// Returns the label of the newest context presented by the current one + virtual TDF_Label newestContext(const TDF_Label theCurrentContext) = 0; }; #endif diff --git a/src/Selector/Selector_Selector.cpp b/src/Selector/Selector_Selector.cpp index 8fe3532ef..0347c1360 100644 --- a/src/Selector/Selector_Selector.cpp +++ b/src/Selector/Selector_Selector.cpp @@ -1032,6 +1032,9 @@ TDF_Label Selector_Selector::restoreByName( } else { aContext = aSubContext; } + if (!aContext.IsNull()) // for filters by neighbour the latest context shape is vital + aContext = theNameGenerator->newestContext(aContext); + // searching for the level index std::string aLevel; for(anEndPos++; anEndPos != std::string::npos && -- 2.39.2