Skip to content

Commit 33ed466

Browse files
committed
Fem: Partial transparency fix in FemPostObject display modes
1 parent 1ab6287 commit 33ed466

File tree

2 files changed

+42
-21
lines changed

2 files changed

+42
-21
lines changed

src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp

+37-21
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#include <Inventor/nodes/SoNormal.h>
3434
#include <Inventor/nodes/SoSeparator.h>
3535
#include <Inventor/nodes/SoShapeHints.h>
36+
#include <Inventor/nodes/SoDepthBuffer.h>
37+
#include <Inventor/nodes/SoTransparencyType.h>
3638
#include <functional>
3739

3840
#include <vtkCellArray.h>
@@ -159,6 +161,11 @@ ViewProviderFemPostObject::ViewProviderFemPostObject()
159161
sPixmap = "fem-femmesh-from-shape";
160162

161163
// create the subnodes which do the visualization work
164+
m_transpType = new SoTransparencyType();
165+
m_transpType->ref();
166+
m_transpType->value = SoTransparencyType::BLEND;
167+
m_depthBuffer = new SoDepthBuffer();
168+
m_depthBuffer->ref();
162169
m_shapeHints = new SoShapeHints();
163170
m_shapeHints->ref();
164171
m_shapeHints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE;
@@ -185,6 +192,8 @@ ViewProviderFemPostObject::ViewProviderFemPostObject()
185192
m_drawStyle->ref();
186193
m_drawStyle->lineWidth.setValue(2);
187194
m_drawStyle->pointSize.setValue(3);
195+
m_sepMarkerLine = new SoSeparator();
196+
m_sepMarkerLine->ref();
188197
m_separator = new SoSeparator();
189198
m_separator->ref();
190199

@@ -221,6 +230,8 @@ ViewProviderFemPostObject::ViewProviderFemPostObject()
221230
ViewProviderFemPostObject::~ViewProviderFemPostObject()
222231
{
223232
FemPostObjectSelectionObserver::instance().unregisterFemPostObject(this);
233+
m_transpType->unref();
234+
m_depthBuffer->unref();
224235
m_shapeHints->unref();
225236
m_coordinates->unref();
226237
m_materialBinding->unref();
@@ -231,6 +242,7 @@ ViewProviderFemPostObject::~ViewProviderFemPostObject()
231242
m_triangleStrips->unref();
232243
m_markers->unref();
233244
m_lines->unref();
245+
m_sepMarkerLine->unref();
234246
m_separator->unref();
235247
m_material->unref();
236248
m_colorBar->Detach(this);
@@ -243,19 +255,27 @@ void ViewProviderFemPostObject::attach(App::DocumentObject* pcObj)
243255
{
244256
ViewProviderDocumentObject::attach(pcObj);
245257

258+
// marker and line nodes
259+
m_sepMarkerLine->addChild(m_transpType);
260+
m_sepMarkerLine->addChild(m_depthBuffer);
261+
m_sepMarkerLine->addChild(m_drawStyle);
262+
m_sepMarkerLine->addChild(m_materialBinding);
263+
m_sepMarkerLine->addChild(m_material);
264+
m_sepMarkerLine->addChild(m_coordinates);
265+
m_sepMarkerLine->addChild(m_markers);
266+
m_sepMarkerLine->addChild(m_lines);
267+
246268
// face nodes
247269
m_separator->addChild(m_shapeHints);
248-
m_separator->addChild(m_drawStyle);
249270
m_separator->addChild(m_materialBinding);
250271
m_separator->addChild(m_material);
251272
m_separator->addChild(m_coordinates);
252-
m_separator->addChild(m_markers);
253-
m_separator->addChild(m_lines);
254273
m_separator->addChild(m_faces);
274+
m_separator->addChild(m_sepMarkerLine);
255275

256276
// Check for an already existing color bar
257277
Gui::SoFCColorBar* pcBar =
258-
((Gui::SoFCColorBar*)findFrontRootOfType(Gui::SoFCColorBar::getClassTypeId()));
278+
static_cast<Gui::SoFCColorBar*>(findFrontRootOfType(Gui::SoFCColorBar::getClassTypeId()));
259279
if (pcBar) {
260280
float fMin = m_colorBar->getMinValue();
261281
float fMax = m_colorBar->getMaxValue();
@@ -318,7 +338,7 @@ std::vector<std::string> ViewProviderFemPostObject::getDisplayModes() const
318338
std::vector<std::string> StrList;
319339
StrList.emplace_back("Outline");
320340
StrList.emplace_back("Nodes");
321-
// StrList.emplace_back("Nodes (surface only)"); somehow this filter does not work
341+
StrList.emplace_back("Nodes (surface only)");
322342
StrList.emplace_back("Surface");
323343
StrList.emplace_back("Surface with Edges");
324344
StrList.emplace_back("Wireframe");
@@ -441,7 +461,6 @@ void ViewProviderFemPostObject::update3D()
441461

442462
// write out point data if any
443463
WritePointData(points, normals, tcoords);
444-
WriteTransparency();
445464
bool ResetColorBarRange = false;
446465
WriteColorData(ResetColorBarRange);
447466

@@ -656,9 +675,19 @@ void ViewProviderFemPostObject::WriteColorData(bool ResetColorBarRange)
656675

657676
void ViewProviderFemPostObject::WriteTransparency()
658677
{
659-
float trans = float(Transparency.getValue()) / 100.0;
660-
m_material->transparency.setValue(trans);
678+
float trans = static_cast<float>(Transparency.getValue()) / 100.0;
679+
float* value = m_material->transparency.startEditing();
680+
for (int i = 0; i < m_material->transparency.getNum(); ++i) {
681+
value[i] = trans;
682+
}
683+
m_material->transparency.finishEditing();
661684

685+
if (Transparency.getValue() > 99) {
686+
m_depthBuffer->test.setValue(false);
687+
}
688+
else {
689+
m_depthBuffer->test.setValue(true);
690+
}
662691
// In order to apply the transparency changes the shape nodes must be touched
663692
m_faces->touch();
664693
m_triangleStrips->touch();
@@ -817,11 +846,9 @@ void ViewProviderFemPostObject::onChanged(const App::Property* prop)
817846
if (prop == &Field && setupPipeline()) {
818847
updateProperties();
819848
WriteColorData(ResetColorBarRange);
820-
WriteTransparency();
821849
}
822850
else if (prop == &VectorMode && setupPipeline()) {
823851
WriteColorData(ResetColorBarRange);
824-
WriteTransparency();
825852
}
826853
else if (prop == &Transparency) {
827854
WriteTransparency();
@@ -832,17 +859,6 @@ void ViewProviderFemPostObject::onChanged(const App::Property* prop)
832859

833860
bool ViewProviderFemPostObject::doubleClicked()
834861
{
835-
// work around for a problem in VTK implementation:
836-
// https://forum.freecad.org/viewtopic.php?t=10587&start=130#p125688
837-
// check if backlight is enabled
838-
ParameterGrp::handle hGrp =
839-
App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View");
840-
bool isBackLightEnabled = hGrp->GetBool("EnableBacklight", false);
841-
if (!isBackLightEnabled) {
842-
Base::Console().Error("Backlight is not enabled. Due to a VTK implementation problem you "
843-
"really should consider to enable backlight in FreeCAD display "
844-
"preferences if you work with VTK post processing.\n");
845-
}
846862
// set edit
847863
Gui::Application::Instance->activeDocument()->setEdit(this, (int)ViewProvider::Default);
848864
return true;

src/Mod/Fem/Gui/ViewProviderFemPostObject.h

+5
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class SoDrawStyle;
5353
class SoIndexedFaceSet;
5454
class SoIndexedLineSet;
5555
class SoIndexedTriangleStripSet;
56+
class SoTransparencyType;
57+
class SoDepthBuffer;
5658

5759
namespace Gui
5860
{
@@ -143,6 +145,9 @@ class FemGuiExport ViewProviderFemPostObject: public Gui::ViewProviderDocumentOb
143145
Gui::SoFCColorBar* m_colorBar;
144146
SoSeparator* m_colorRoot;
145147
SoDrawStyle* m_colorStyle;
148+
SoTransparencyType* m_transpType;
149+
SoSeparator* m_sepMarkerLine;
150+
SoDepthBuffer* m_depthBuffer;
146151

147152
vtkSmartPointer<vtkPolyDataAlgorithm> m_currentAlgorithm;
148153
vtkSmartPointer<vtkGeometryFilter> m_surface;

0 commit comments

Comments
 (0)