33
33
#include < Inventor/nodes/SoNormal.h>
34
34
#include < Inventor/nodes/SoSeparator.h>
35
35
#include < Inventor/nodes/SoShapeHints.h>
36
+ #include < Inventor/nodes/SoDepthBuffer.h>
37
+ #include < Inventor/nodes/SoTransparencyType.h>
36
38
#include < functional>
37
39
38
40
#include < vtkCellArray.h>
@@ -159,6 +161,11 @@ ViewProviderFemPostObject::ViewProviderFemPostObject()
159
161
sPixmap = " fem-femmesh-from-shape" ;
160
162
161
163
// 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 ();
162
169
m_shapeHints = new SoShapeHints ();
163
170
m_shapeHints->ref ();
164
171
m_shapeHints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE;
@@ -185,6 +192,8 @@ ViewProviderFemPostObject::ViewProviderFemPostObject()
185
192
m_drawStyle->ref ();
186
193
m_drawStyle->lineWidth .setValue (2 );
187
194
m_drawStyle->pointSize .setValue (3 );
195
+ m_sepMarkerLine = new SoSeparator ();
196
+ m_sepMarkerLine->ref ();
188
197
m_separator = new SoSeparator ();
189
198
m_separator->ref ();
190
199
@@ -221,6 +230,8 @@ ViewProviderFemPostObject::ViewProviderFemPostObject()
221
230
ViewProviderFemPostObject::~ViewProviderFemPostObject ()
222
231
{
223
232
FemPostObjectSelectionObserver::instance ().unregisterFemPostObject (this );
233
+ m_transpType->unref ();
234
+ m_depthBuffer->unref ();
224
235
m_shapeHints->unref ();
225
236
m_coordinates->unref ();
226
237
m_materialBinding->unref ();
@@ -231,6 +242,7 @@ ViewProviderFemPostObject::~ViewProviderFemPostObject()
231
242
m_triangleStrips->unref ();
232
243
m_markers->unref ();
233
244
m_lines->unref ();
245
+ m_sepMarkerLine->unref ();
234
246
m_separator->unref ();
235
247
m_material->unref ();
236
248
m_colorBar->Detach (this );
@@ -243,19 +255,27 @@ void ViewProviderFemPostObject::attach(App::DocumentObject* pcObj)
243
255
{
244
256
ViewProviderDocumentObject::attach (pcObj);
245
257
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
+
246
268
// face nodes
247
269
m_separator->addChild (m_shapeHints);
248
- m_separator->addChild (m_drawStyle);
249
270
m_separator->addChild (m_materialBinding);
250
271
m_separator->addChild (m_material);
251
272
m_separator->addChild (m_coordinates);
252
- m_separator->addChild (m_markers);
253
- m_separator->addChild (m_lines);
254
273
m_separator->addChild (m_faces);
274
+ m_separator->addChild (m_sepMarkerLine);
255
275
256
276
// Check for an already existing color bar
257
277
Gui::SoFCColorBar* pcBar =
258
- (( Gui::SoFCColorBar*) findFrontRootOfType (Gui::SoFCColorBar::getClassTypeId ()));
278
+ static_cast < Gui::SoFCColorBar*>( findFrontRootOfType (Gui::SoFCColorBar::getClassTypeId ()));
259
279
if (pcBar) {
260
280
float fMin = m_colorBar->getMinValue ();
261
281
float fMax = m_colorBar->getMaxValue ();
@@ -318,7 +338,7 @@ std::vector<std::string> ViewProviderFemPostObject::getDisplayModes() const
318
338
std::vector<std::string> StrList;
319
339
StrList.emplace_back (" Outline" );
320
340
StrList.emplace_back (" Nodes" );
321
- // StrList.emplace_back("Nodes (surface only)"); somehow this filter does not work
341
+ StrList.emplace_back (" Nodes (surface only)" );
322
342
StrList.emplace_back (" Surface" );
323
343
StrList.emplace_back (" Surface with Edges" );
324
344
StrList.emplace_back (" Wireframe" );
@@ -441,7 +461,6 @@ void ViewProviderFemPostObject::update3D()
441
461
442
462
// write out point data if any
443
463
WritePointData (points, normals, tcoords);
444
- WriteTransparency ();
445
464
bool ResetColorBarRange = false ;
446
465
WriteColorData (ResetColorBarRange);
447
466
@@ -656,9 +675,19 @@ void ViewProviderFemPostObject::WriteColorData(bool ResetColorBarRange)
656
675
657
676
void ViewProviderFemPostObject::WriteTransparency ()
658
677
{
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 ();
661
684
685
+ if (Transparency.getValue () > 99 ) {
686
+ m_depthBuffer->test .setValue (false );
687
+ }
688
+ else {
689
+ m_depthBuffer->test .setValue (true );
690
+ }
662
691
// In order to apply the transparency changes the shape nodes must be touched
663
692
m_faces->touch ();
664
693
m_triangleStrips->touch ();
@@ -817,11 +846,9 @@ void ViewProviderFemPostObject::onChanged(const App::Property* prop)
817
846
if (prop == &Field && setupPipeline ()) {
818
847
updateProperties ();
819
848
WriteColorData (ResetColorBarRange);
820
- WriteTransparency ();
821
849
}
822
850
else if (prop == &VectorMode && setupPipeline ()) {
823
851
WriteColorData (ResetColorBarRange);
824
- WriteTransparency ();
825
852
}
826
853
else if (prop == &Transparency) {
827
854
WriteTransparency ();
@@ -832,17 +859,6 @@ void ViewProviderFemPostObject::onChanged(const App::Property* prop)
832
859
833
860
bool ViewProviderFemPostObject::doubleClicked ()
834
861
{
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
- }
846
862
// set edit
847
863
Gui::Application::Instance->activeDocument ()->setEdit (this , (int )ViewProvider::Default);
848
864
return true ;
0 commit comments