From d012b8d012b78abe1ac005f2727e34af6115b5cd Mon Sep 17 00:00:00 2001 From: Uwe Date: Sun, 24 Jul 2022 19:17:24 +0200 Subject: [PATCH] [FEM] fix color bar handling on hiding post objects - fixed the remaining part of #7230: on hiding an object, refresh the color bar of the new visible object (if there is any) --- src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp b/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp index 74e3eea236..3496b2a283 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp +++ b/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp @@ -44,6 +44,7 @@ # include #endif +#include #include #include #include @@ -664,13 +665,33 @@ void ViewProviderFemPostObject::unsetEdit(int ModNum) { void ViewProviderFemPostObject::hide(void) { Gui::ViewProviderDocumentObject::hide(); m_colorStyle->style = SoDrawStyle::INVISIBLE; - // TODO: the object is now hidden but the color bar is wrong - // if there are other FemPostObjects visible - // one must first search if there are other FemPostObjects visible - // in the tree view above this one and refresh ist color bar by updating - // its Field property - // if this is not the case, the colorbar of the next visible FemPostObjects - // has t be refreshed + // The object is now hidden but the color bar is wrong + // if there are other FemPostObjects visible. + // We must therefore search for the first visible FemPostObjects + // in the document and refresh ist color bar + + // get all objects in the document + auto docGui = Gui::Application::Instance->activeDocument(); + if (!docGui) + return; + auto doc = docGui->getDocument(); + std::vector ObjectsList = doc->getObjects(); + App::DocumentObject *firstVisiblePostObject = nullptr; + // step through the objects + for (auto it = ObjectsList.begin(); it != ObjectsList.end(); ++it) { + if ((*it)->getTypeId().isDerivedFrom(Fem::FemPostObject::getClassTypeId())) { + if (!firstVisiblePostObject && (*it)->Visibility.getValue()) { + firstVisiblePostObject = *it; + break; + } + } + // refesh found object + if (firstVisiblePostObject) { + auto viewProvider = docGui->getViewProvider(firstVisiblePostObject); + auto FEMviewProvider = static_cast(viewProvider); + if (FEMviewProvider) + FEMviewProvider->WriteColorData(true); + } } void ViewProviderFemPostObject::show(void) {