From 16144497273e116519cd26fa52da8bb877597fd1 Mon Sep 17 00:00:00 2001 From: marioalexis Date: Sat, 9 Mar 2024 15:30:11 -0300 Subject: [PATCH] Fem: Partial transparency fix in FemPostObject display modes --- src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp | 58 ++++++++++++------- src/Mod/Fem/Gui/ViewProviderFemPostObject.h | 5 ++ 2 files changed, 42 insertions(+), 21 deletions(-) diff --git a/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp b/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp index d1e8b0711e..1728d9c9ba 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp +++ b/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp @@ -33,6 +33,8 @@ #include #include #include +#include +#include #include #include @@ -159,6 +161,11 @@ ViewProviderFemPostObject::ViewProviderFemPostObject() sPixmap = "fem-femmesh-from-shape"; // create the subnodes which do the visualization work + m_transpType = new SoTransparencyType(); + m_transpType->ref(); + m_transpType->value = SoTransparencyType::BLEND; + m_depthBuffer = new SoDepthBuffer(); + m_depthBuffer->ref(); m_shapeHints = new SoShapeHints(); m_shapeHints->ref(); m_shapeHints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE; @@ -185,6 +192,8 @@ ViewProviderFemPostObject::ViewProviderFemPostObject() m_drawStyle->ref(); m_drawStyle->lineWidth.setValue(2); m_drawStyle->pointSize.setValue(3); + m_sepMarkerLine = new SoSeparator(); + m_sepMarkerLine->ref(); m_separator = new SoSeparator(); m_separator->ref(); @@ -221,6 +230,8 @@ ViewProviderFemPostObject::ViewProviderFemPostObject() ViewProviderFemPostObject::~ViewProviderFemPostObject() { FemPostObjectSelectionObserver::instance().unregisterFemPostObject(this); + m_transpType->unref(); + m_depthBuffer->unref(); m_shapeHints->unref(); m_coordinates->unref(); m_materialBinding->unref(); @@ -231,6 +242,7 @@ ViewProviderFemPostObject::~ViewProviderFemPostObject() m_triangleStrips->unref(); m_markers->unref(); m_lines->unref(); + m_sepMarkerLine->unref(); m_separator->unref(); m_material->unref(); m_colorBar->Detach(this); @@ -243,19 +255,27 @@ void ViewProviderFemPostObject::attach(App::DocumentObject* pcObj) { ViewProviderDocumentObject::attach(pcObj); + // marker and line nodes + m_sepMarkerLine->addChild(m_transpType); + m_sepMarkerLine->addChild(m_depthBuffer); + m_sepMarkerLine->addChild(m_drawStyle); + m_sepMarkerLine->addChild(m_materialBinding); + m_sepMarkerLine->addChild(m_material); + m_sepMarkerLine->addChild(m_coordinates); + m_sepMarkerLine->addChild(m_markers); + m_sepMarkerLine->addChild(m_lines); + // face nodes m_separator->addChild(m_shapeHints); - m_separator->addChild(m_drawStyle); m_separator->addChild(m_materialBinding); m_separator->addChild(m_material); m_separator->addChild(m_coordinates); - m_separator->addChild(m_markers); - m_separator->addChild(m_lines); m_separator->addChild(m_faces); + m_separator->addChild(m_sepMarkerLine); // Check for an already existing color bar Gui::SoFCColorBar* pcBar = - ((Gui::SoFCColorBar*)findFrontRootOfType(Gui::SoFCColorBar::getClassTypeId())); + static_cast(findFrontRootOfType(Gui::SoFCColorBar::getClassTypeId())); if (pcBar) { float fMin = m_colorBar->getMinValue(); float fMax = m_colorBar->getMaxValue(); @@ -318,7 +338,7 @@ std::vector ViewProviderFemPostObject::getDisplayModes() const std::vector StrList; StrList.emplace_back("Outline"); StrList.emplace_back("Nodes"); - // StrList.emplace_back("Nodes (surface only)"); somehow this filter does not work + StrList.emplace_back("Nodes (surface only)"); StrList.emplace_back("Surface"); StrList.emplace_back("Surface with Edges"); StrList.emplace_back("Wireframe"); @@ -441,7 +461,6 @@ void ViewProviderFemPostObject::update3D() // write out point data if any WritePointData(points, normals, tcoords); - WriteTransparency(); bool ResetColorBarRange = false; WriteColorData(ResetColorBarRange); @@ -656,9 +675,19 @@ void ViewProviderFemPostObject::WriteColorData(bool ResetColorBarRange) void ViewProviderFemPostObject::WriteTransparency() { - float trans = float(Transparency.getValue()) / 100.0; - m_material->transparency.setValue(trans); + float trans = static_cast(Transparency.getValue()) / 100.0; + float* value = m_material->transparency.startEditing(); + for (int i = 0; i < m_material->transparency.getNum(); ++i) { + value[i] = trans; + } + m_material->transparency.finishEditing(); + if (Transparency.getValue() > 99) { + m_depthBuffer->test.setValue(false); + } + else { + m_depthBuffer->test.setValue(true); + } // In order to apply the transparency changes the shape nodes must be touched m_faces->touch(); m_triangleStrips->touch(); @@ -817,11 +846,9 @@ void ViewProviderFemPostObject::onChanged(const App::Property* prop) if (prop == &Field && setupPipeline()) { updateProperties(); WriteColorData(ResetColorBarRange); - WriteTransparency(); } else if (prop == &VectorMode && setupPipeline()) { WriteColorData(ResetColorBarRange); - WriteTransparency(); } else if (prop == &Transparency) { WriteTransparency(); @@ -832,17 +859,6 @@ void ViewProviderFemPostObject::onChanged(const App::Property* prop) bool ViewProviderFemPostObject::doubleClicked() { - // work around for a problem in VTK implementation: - // https://forum.freecad.org/viewtopic.php?t=10587&start=130#p125688 - // check if backlight is enabled - ParameterGrp::handle hGrp = - App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View"); - bool isBackLightEnabled = hGrp->GetBool("EnableBacklight", false); - if (!isBackLightEnabled) { - Base::Console().Error("Backlight is not enabled. Due to a VTK implementation problem you " - "really should consider to enable backlight in FreeCAD display " - "preferences if you work with VTK post processing.\n"); - } // set edit Gui::Application::Instance->activeDocument()->setEdit(this, (int)ViewProvider::Default); return true; diff --git a/src/Mod/Fem/Gui/ViewProviderFemPostObject.h b/src/Mod/Fem/Gui/ViewProviderFemPostObject.h index 70b455ae7d..9c1322b4e5 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemPostObject.h +++ b/src/Mod/Fem/Gui/ViewProviderFemPostObject.h @@ -53,6 +53,8 @@ class SoDrawStyle; class SoIndexedFaceSet; class SoIndexedLineSet; class SoIndexedTriangleStripSet; +class SoTransparencyType; +class SoDepthBuffer; namespace Gui { @@ -143,6 +145,9 @@ protected: Gui::SoFCColorBar* m_colorBar; SoSeparator* m_colorRoot; SoDrawStyle* m_colorStyle; + SoTransparencyType* m_transpType; + SoSeparator* m_sepMarkerLine; + SoDepthBuffer* m_depthBuffer; vtkSmartPointer m_currentAlgorithm; vtkSmartPointer m_surface;