diff --git a/src/Mod/Fem/Gui/ViewProviderAnalysis.cpp b/src/Mod/Fem/Gui/ViewProviderAnalysis.cpp index 5155235102..e865ab39f5 100644 --- a/src/Mod/Fem/Gui/ViewProviderAnalysis.cpp +++ b/src/Mod/Fem/Gui/ViewProviderAnalysis.cpp @@ -28,6 +28,7 @@ # include # include # include +# include #endif #include @@ -55,6 +56,33 @@ using namespace FemGui; +ViewProviderFemHighlighter::ViewProviderFemHighlighter() +{ + annotate = new SoAnnotation(); + annotate->ref(); +} + +ViewProviderFemHighlighter::~ViewProviderFemHighlighter() +{ + annotate->unref(); +} + +void ViewProviderFemHighlighter::attach(ViewProviderFemAnalysis* view) +{ + SoGroup* root = view->getRoot(); + root->addChild(annotate); +} + +void ViewProviderFemHighlighter::highlightView(Gui::ViewProviderDocumentObject* view) +{ + annotate->removeAllChildren(); + + if (view) { + annotate->addChild(view->getRoot()); + } +} + +// ---------------------------------------------------------------------------- /* TRANSLATOR FemGui::ViewProviderFemAnalysis */ @@ -71,6 +99,17 @@ ViewProviderFemAnalysis::~ViewProviderFemAnalysis() } +void ViewProviderFemAnalysis::attach(App::DocumentObject* obj) +{ + Gui::ViewProviderDocumentObjectGroup::attach(obj); + extension.attach(this); +} + +void ViewProviderFemAnalysis::highlightView(Gui::ViewProviderDocumentObject* view) +{ + extension.highlightView(view); +} + bool ViewProviderFemAnalysis::doubleClicked(void) { Gui::Command::assureWorkbench("FemWorkbench"); @@ -244,7 +283,7 @@ bool ViewProviderFemAnalysis::canDelete(App::DocumentObject* obj) const // thus we can pass this action // we can warn the user if necessary in the object's ViewProvider in the onDelete() function Q_UNUSED(obj) - return true; + return true; } // Python feature ----------------------------------------------------------------------- diff --git a/src/Mod/Fem/Gui/ViewProviderAnalysis.h b/src/Mod/Fem/Gui/ViewProviderAnalysis.h index 15f8c58924..fa50cf6e06 100644 --- a/src/Mod/Fem/Gui/ViewProviderAnalysis.h +++ b/src/Mod/Fem/Gui/ViewProviderAnalysis.h @@ -28,10 +28,26 @@ #include #include +class SoAnnotation; namespace FemGui { +class ViewProviderFemAnalysis; +class ViewProviderFemHighlighter +{ +public: + /// Constructor + ViewProviderFemHighlighter(); + ~ViewProviderFemHighlighter(); + + void attach(ViewProviderFemAnalysis*); + void highlightView(Gui::ViewProviderDocumentObject*); + +private: + SoAnnotation* annotate; +}; + class FemGuiExport ViewProviderFemAnalysis : public Gui::ViewProviderDocumentObjectGroup { Q_DECLARE_TR_FUNCTIONS(FemGui::ViewProviderFemAnalysis) @@ -44,6 +60,7 @@ public: /// destructor. virtual ~ViewProviderFemAnalysis(); + virtual void attach(App::DocumentObject*); virtual bool doubleClicked(void); virtual std::vector claimChildren(void)const; @@ -67,6 +84,8 @@ public: /// Show the object in the view virtual void show(void); + void highlightView(Gui::ViewProviderDocumentObject*); + /** @name Drag and drop */ //@{ /// Returns true if the view provider generally supports dragging objects @@ -87,6 +106,8 @@ protected: virtual bool setEdit(int ModNum); virtual void unsetEdit(int ModNum); +private: + ViewProviderFemHighlighter extension; }; typedef Gui::ViewProviderPythonFeatureT ViewProviderFemAnalysisPython; diff --git a/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp b/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp index b2141540b4..8a265ef388 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp +++ b/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp @@ -522,6 +522,11 @@ void ViewProviderFemPostObject::setRangeOfColorBar(double min, double max) } } +void ViewProviderFemPostObject::updateMaterial() +{ + WriteColorData(true); +} + void ViewProviderFemPostObject::WriteColorData(bool ResetColorBarRange) { if (!setupPipeline()) @@ -801,7 +806,7 @@ bool ViewProviderFemPostObject::canDelete(App::DocumentObject* obj) const // thus we can pass this action // we can warn the user if necessary in the object's ViewProvider in the onDelete() function Q_UNUSED(obj) - return true; + return true; } void ViewProviderFemPostObject::onSelectionChanged(const Gui::SelectionChanges &sel) @@ -810,8 +815,8 @@ void ViewProviderFemPostObject::onSelectionChanged(const Gui::SelectionChanges & // color bar. // But don't do this if the object is invisible because other objects with a // color bar might be visible and the color bar is then wrong. - if (sel.Type == sel.AddSelection) { + if (sel.Type == Gui::SelectionChanges::AddSelection) { if (this->getObject()->Visibility.getValue()) - WriteColorData(true); + updateMaterial(); } } diff --git a/src/Mod/Fem/Gui/ViewProviderFemPostObject.h b/src/Mod/Fem/Gui/ViewProviderFemPostObject.h index 772d15203f..fb4cf7843f 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemPostObject.h +++ b/src/Mod/Fem/Gui/ViewProviderFemPostObject.h @@ -123,6 +123,7 @@ protected: bool setupPipeline(); void updateVtk(); void setRangeOfColorBar(double min, double max); + void updateMaterial(); SoCoordinate3* m_coordinates; SoIndexedPointSet* m_markers; diff --git a/src/Mod/Fem/Gui/ViewProviderFemPostPipeline.cpp b/src/Mod/Fem/Gui/ViewProviderFemPostPipeline.cpp index 05dd0d0957..f3f5465442 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemPostPipeline.cpp +++ b/src/Mod/Fem/Gui/ViewProviderFemPostPipeline.cpp @@ -22,9 +22,17 @@ #include "PreCompiled.h" +#ifndef _PreComp_ +# include +#endif + +#include #include +#include +#include #include +#include "ViewProviderAnalysis.h" #include "ViewProviderFemPostPipeline.h" #include "ViewProviderFemPostFunction.h" @@ -36,6 +44,10 @@ PROPERTY_SOURCE(FemGui::ViewProviderFemPostPipeline, FemGui::ViewProviderFemPost ViewProviderFemPostPipeline::ViewProviderFemPostPipeline() { sPixmap = "FEM_PostPipelineFromResult"; + + // Fixes rendering issue with the annotation node + m_shapeHints->vertexOrdering = SoShapeHints::CLOCKWISE; + m_shapeHints->shapeType = SoShapeHints::SOLID; } ViewProviderFemPostPipeline::~ViewProviderFemPostPipeline() @@ -88,3 +100,31 @@ void ViewProviderFemPostPipeline::updateFunctionSize() { vp->SizeZ.setValue(box.GetLength(2) * 1.2); } } + +void ViewProviderFemPostPipeline::onSelectionChanged(const Gui::SelectionChanges &sel) +{ + auto getAnalyzeView = [](App::DocumentObject* obj) { + ViewProviderFemAnalysis* analyzeView = nullptr; + App::DocumentObject* grp = App::GroupExtension::getGroupOfObject(obj); + if (Fem::FemAnalysis* analyze = Base::freecad_dynamic_cast(grp)) { + analyzeView = Base::freecad_dynamic_cast + (Gui::Application::Instance->getViewProvider(analyze)); + } + return analyzeView; + }; + + // If a FemPostObject is selected in the document tree we must refresh its + // color bar. + // But don't do this if the object is invisible because other objects with a + // color bar might be visible and the color bar is then wrong. + if (sel.Type == Gui::SelectionChanges::AddSelection) { + if (this->getObject()->Visibility.getValue()) + updateMaterial(); + + // Access analysis object + ViewProviderFemAnalysis* analyzeView = getAnalyzeView(this->getObject()); + if (analyzeView) { + analyzeView->highlightView(this); + } + } +} diff --git a/src/Mod/Fem/Gui/ViewProviderFemPostPipeline.h b/src/Mod/Fem/Gui/ViewProviderFemPostPipeline.h index 9d7126a569..8bda582375 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemPostPipeline.h +++ b/src/Mod/Fem/Gui/ViewProviderFemPostPipeline.h @@ -41,6 +41,7 @@ public: virtual std::vector< App::DocumentObject* > claimChildren(void) const; virtual std::vector< App::DocumentObject* > claimChildren3D(void) const; virtual void updateData(const App::Property* prop); + virtual void onSelectionChanged(const Gui::SelectionChanges &sel); protected: void updateFunctionSize();