From 000ef1517ff2fd6377e7e2d564ba0d250ab442bd Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Fri, 4 Oct 2019 12:17:06 +0800 Subject: [PATCH] Gui: avoid unecessary visibility change when update view provider This patch prevents syncing DocumentObject::Visibility when view provider hides itself before updating. Some object may have additional logic based on object visibility change. For example, GroupExtension monitors its children visibility for exporting, and propgate changes to upper hierarchy. --- src/Gui/ViewProviderDocumentObject.cpp | 15 +++++++++++++-- src/Gui/ViewProviderGroupExtension.cpp | 7 ++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Gui/ViewProviderDocumentObject.cpp b/src/Gui/ViewProviderDocumentObject.cpp index 921f09ff6f..08af98ee77 100644 --- a/src/Gui/ViewProviderDocumentObject.cpp +++ b/src/Gui/ViewProviderDocumentObject.cpp @@ -183,8 +183,12 @@ void ViewProviderDocumentObject::onChanged(const App::Property* prop) Visibility.getValue() ? show() : hide(); Visibility.setStatus(App::Property::User2, false); } - if(getObject() && getObject()->Visibility.getValue()!=Visibility.getValue()) + if (!Visibility.testStatus(App::Property::User1) + && getObject() + && getObject()->Visibility.getValue()!=Visibility.getValue()) + { getObject()->Visibility.setValue(Visibility.getValue()); + } } else if (prop == &SelectionStyle) { if(getRoot()->isOfType(SoFCSelectionRoot::getClassTypeId())) { @@ -239,6 +243,9 @@ void ViewProviderDocumentObject::updateView() Base::ObjectStatusLocker lock(ViewStatus::UpdatingView,this); + // Disable object visibility syncing + Base::ObjectStatusLocker lock2(App::Property::User1, &Visibility); + std::map Map; pcObject->getPropertyMap(Map); @@ -298,8 +305,12 @@ void ViewProviderDocumentObject::update(const App::Property* prop) if(prop == &getObject()->Visibility) { if(!isRestoring() && Visibility.getValue()!=getObject()->Visibility.getValue()) Visibility.setValue(!Visibility.getValue()); - }else + } else { + // Disable object visibility syncing + Base::ObjectStatusLocker + guard(App::Property::User1, &Visibility); ViewProvider::update(prop); + } } Gui::Document* ViewProviderDocumentObject::getDocument() const diff --git a/src/Gui/ViewProviderGroupExtension.cpp b/src/Gui/ViewProviderGroupExtension.cpp index 81f043e89d..29ca221742 100644 --- a/src/Gui/ViewProviderGroupExtension.cpp +++ b/src/Gui/ViewProviderGroupExtension.cpp @@ -145,7 +145,12 @@ void ViewProviderGroupExtension::extensionHide(void) { // when reading the Visibility property from file then do not hide the // objects of this group because they have stored their visibility status, too - if (!getExtendedViewProvider()->isRestoring()) { + // + // Property::User1 is used by ViewProviderDocumentObject to mark for + // temporary visibility changes. Do not propagate the change to children. + if (!getExtendedViewProvider()->isRestoring() + && !getExtendedViewProvider()->Visibility.testStatus(App::Property::User1)) + { auto* group = getExtendedViewProvider()->getObject()->getExtensionByType(); for(auto obj : group->Group.getValues()) { if(obj && obj->Visibility.getValue())