Fem: use SoAnnotation to highlight result pipeline objects

This commit is contained in:
wmayer
2022-07-31 17:51:31 +02:00
parent 47c2e77ebf
commit 8bb85d2b7c
6 changed files with 111 additions and 4 deletions

View File

@@ -28,6 +28,7 @@
# include <QMenu>
# include <QMessageBox>
# include <QTextStream>
# include <Inventor/nodes/SoAnnotation.h>
#endif
#include <App/MaterialObject.h>
@@ -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 -----------------------------------------------------------------------

View File

@@ -28,10 +28,26 @@
#include <Mod/Fem/FemGlobal.h>
#include <QCoreApplication>
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<App::DocumentObject*> 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<ViewProviderFemAnalysis> ViewProviderFemAnalysisPython;

View File

@@ -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();
}
}

View File

@@ -123,6 +123,7 @@ protected:
bool setupPipeline();
void updateVtk();
void setRangeOfColorBar(double min, double max);
void updateMaterial();
SoCoordinate3* m_coordinates;
SoIndexedPointSet* m_markers;

View File

@@ -22,9 +22,17 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <Inventor/nodes/SoShapeHints.h>
#endif
#include <App/GroupExtension.h>
#include <Gui/Application.h>
#include <Gui/Selection.h>
#include <Mod/Fem/App/FemAnalysis.h>
#include <Mod/Fem/App/FemPostPipeline.h>
#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<Fem::FemAnalysis>(grp)) {
analyzeView = Base::freecad_dynamic_cast<ViewProviderFemAnalysis>
(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);
}
}
}

View File

@@ -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();