diff --git a/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp b/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp index 2ddfb1a247..15b3efe31e 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp +++ b/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp @@ -23,6 +23,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ +# include # include # include # include @@ -48,6 +49,8 @@ #include #include #include +#include +#include #include #include @@ -56,6 +59,7 @@ using namespace FemGui; +namespace sp = std::placeholders; #ifdef VTK_CELL_ARRAY_V2 typedef const vtkIdType* vtkIdTypePtr; @@ -130,6 +134,9 @@ ViewProviderFemPostObject::ViewProviderFemPostObject() : m_blockPropertyChanges( m_currentAlgorithm = m_outline; updateProperties(); // initialize the enums + + this->connectSelection = Gui::Selection().signalSelectionChanged.connect( + std::bind(&ViewProviderFemPostObject::selectionChanged, this, sp::_1)); } ViewProviderFemPostObject::~ViewProviderFemPostObject() @@ -708,3 +715,23 @@ bool ViewProviderFemPostObject::canDelete(App::DocumentObject* obj) const Q_UNUSED(obj) return true; } + +void ViewProviderFemPostObject::selectionChanged(const Gui::SelectionChanges &sel) +{ + // If a FemPostObject is selected in the document tree we must refresh its + // Field property to update the color bar. + // But don't do this if the object is invisible because otherobjects with a + // color bar might be visible and the color bar is then wrong. + if (sel.Type == sel.AddSelection) { + Gui::SelectionObject obj(sel); + if (obj.getObject() == this->getObject()) { + if (!this->getObject()->Visibility.getValue()) + return; + auto propField = Base::freecad_dynamic_cast( + getPropertyByName("Field")); + if (propField) + propField->touch(); + } + } +} + diff --git a/src/Mod/Fem/Gui/ViewProviderFemPostObject.h b/src/Mod/Fem/Gui/ViewProviderFemPostObject.h index e4e12cd61a..399fe96340 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemPostObject.h +++ b/src/Mod/Fem/Gui/ViewProviderFemPostObject.h @@ -54,6 +54,7 @@ class SoIndexedLineSet; class SoIndexedTriangleStripSet; namespace Gui { + class SelectionChanges; class SoFCColorBar; } @@ -145,6 +146,10 @@ protected: vtkSmartPointer m_wireframe, m_wireframeSurface; vtkSmartPointer m_points, m_pointsSurface; + void selectionChanged(const Gui::SelectionChanges &); + typedef boost::signals2::scoped_connection Connection; + Connection connectSelection; + private: void updateProperties(); void update3D();