From 945aee1d1ccbba52c87b3728e9f06ef131fafb0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Tr=C3=B6ger?= Date: Sun, 20 Mar 2016 08:17:54 +0100 Subject: [PATCH] FEM Post: integrate FreeCAD color system --- src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp | 66 ++++++++++++++++--- src/Mod/Fem/Gui/ViewProviderFemPostObject.h | 19 +++++- 2 files changed, 74 insertions(+), 11 deletions(-) diff --git a/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp b/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp index 46f9eefb1..8cb455380 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp +++ b/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include #include @@ -96,6 +97,16 @@ ViewProviderFemPostObject::ViewProviderFemPostObject() : m_blockPropertyChanges( m_seperator = new SoSeparator(); m_seperator->ref(); + // simple color bar + m_colorRoot = new SoSeparator(); + m_colorRoot->ref(); + m_colorStyle = new SoDrawStyle(); + m_colorStyle->ref(); + m_colorRoot->addChild(m_colorStyle); + m_colorBar = new Gui::SoFCColorBar; + m_colorBar->Attach(this); + m_colorBar->ref(); + //create the vtk algorithms we use for visualisation m_outline = vtkSmartPointer::New(); m_points = vtkSmartPointer::New(); @@ -104,9 +115,6 @@ ViewProviderFemPostObject::ViewProviderFemPostObject() : m_blockPropertyChanges( m_surfaceEdges = vtkSmartPointer::New(); m_surfaceEdges->AddInputConnection(m_surface->GetOutputPort()); m_surfaceEdges->AddInputConnection(m_wireframe->GetOutputPort()); - - m_lookup = vtkSmartPointer::New(); - m_lookup->SetRampToLinear(); m_currentAlgorithm = m_outline; } @@ -125,6 +133,10 @@ ViewProviderFemPostObject::~ViewProviderFemPostObject() m_lines->unref(); m_seperator->unref(); m_material->unref(); + m_colorBar->Detach(this); + m_colorBar->unref(); + m_colorStyle->unref(); + m_colorRoot->unref(); } void ViewProviderFemPostObject::attach(App::DocumentObject *pcObj) @@ -140,6 +152,24 @@ void ViewProviderFemPostObject::attach(App::DocumentObject *pcObj) m_seperator->addChild(m_markers); m_seperator->addChild(m_lines); m_seperator->addChild(m_faces); + + // Check for an already existing color bar + Gui::SoFCColorBar* pcBar = ((Gui::SoFCColorBar*)findFrontRootOfType( Gui::SoFCColorBar::getClassTypeId() )); + if ( pcBar ) { + float fMin = m_colorBar->getMinValue(); + float fMax = m_colorBar->getMaxValue(); + + // Attach to the foreign color bar and delete our own bar + pcBar->Attach(this); + pcBar->ref(); + pcBar->setRange(fMin, fMax, 3); + pcBar->Notify(0); + m_colorBar->Detach(this); + m_colorBar->unref(); + m_colorBar = pcBar; + } + + m_colorRoot->addChild(m_colorBar); //all addDisplayMaskMode(m_seperator, "Default"); @@ -148,6 +178,12 @@ void ViewProviderFemPostObject::attach(App::DocumentObject *pcObj) setupPipeline(); } +SoSeparator* ViewProviderFemPostObject::getFrontRoot(void) const { + + return m_colorRoot; +} + + void ViewProviderFemPostObject::setDisplayMode(const char* ModeName) { if (strcmp("Outline",ModeName)==0) @@ -416,9 +452,7 @@ void ViewProviderFemPostObject::WriteColorData() { //build the lookuptable double range[2]; data->GetRange(range, component); - m_lookup->SetTableRange(range[0], range[1]); - m_lookup->SetScaleToLinear(); - m_lookup->Build(); + m_colorBar->setRange(range[0], range[1]); m_material->diffuseColor.startEditing(); @@ -433,9 +467,8 @@ void ViewProviderFemPostObject::WriteColorData() { value = std::sqrt(value); } - double c[3]; - m_lookup->GetColor(value, c); - m_material->diffuseColor.set1Value(i, c[0], c[1], c[2]); + App::Color c = m_colorBar->getColor(value); + m_material->diffuseColor.set1Value(i, c.r, c.g, c.b); } m_material->diffuseColor.finishEditing(); m_materialBinding->value = SoMaterialBinding::PER_VERTEX_INDEXED; @@ -557,3 +590,18 @@ void ViewProviderFemPostObject::unsetEdit(int ModNum) { } } +void ViewProviderFemPostObject::hide(void) { + Gui::ViewProviderDocumentObject::hide(); + m_colorStyle->style = SoDrawStyle::INVISIBLE; +} + +void ViewProviderFemPostObject::show(void) { + Gui::ViewProviderDocumentObject::show(); + m_colorStyle->style = SoDrawStyle::FILLED; +} + + +void ViewProviderFemPostObject::OnChange(Base::Subject< int >& rCaller, int rcReason) { + + WriteColorData(); +} diff --git a/src/Mod/Fem/Gui/ViewProviderFemPostObject.h b/src/Mod/Fem/Gui/ViewProviderFemPostObject.h index 5883a96c2..f9587f9bd 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemPostObject.h +++ b/src/Mod/Fem/Gui/ViewProviderFemPostObject.h @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -56,13 +57,17 @@ class SoIndexedFaceSet; class SoIndexedLineSet; class SoIndexedTriangleStripSet; +namespace Gui { + class SoFCColorBar; +} namespace FemGui { class TaskDlgPost; -class FemGuiExport ViewProviderFemPostObject : public Gui::ViewProviderDocumentObject +class FemGuiExport ViewProviderFemPostObject : public Gui::ViewProviderDocumentObject, + public Base::Observer { PROPERTY_HEADER(FemGui::ViewProviderFemPostObject); @@ -88,6 +93,14 @@ public: virtual bool setEdit(int ModNum); virtual void unsetEdit(int ModNum); + virtual void hide(void); + virtual void show(void); + + virtual SoSeparator* getFrontRoot(void) const; + + //observer for the color bar + virtual void OnChange(Base::Subject< int >& rCaller, int rcReason); + /** @name Selection handling * This group of methodes do the selection handling. * Here you can define how the selection for your ViewProvider @@ -120,6 +133,9 @@ protected: SoNormal* m_normals; SoDrawStyle* m_drawStyle; SoSeparator* m_seperator; + Gui::SoFCColorBar* m_colorBar; + SoSeparator* m_colorRoot; + SoDrawStyle* m_colorStyle; vtkSmartPointer m_currentAlgorithm; vtkSmartPointer m_surface; @@ -127,7 +143,6 @@ protected: vtkSmartPointer m_outline; vtkSmartPointer m_wireframe; vtkSmartPointer m_points; - vtkSmartPointer m_lookup; private: void updateProperties();