24
24
25
25
#ifndef _PreComp_
26
26
#include < Inventor/nodes/SoCoordinate3.h>
27
+ #include < Inventor/nodes/SoDepthBuffer.h>
27
28
#include < Inventor/nodes/SoDrawStyle.h>
28
29
#include < Inventor/nodes/SoIndexedFaceSet.h>
29
30
#include < Inventor/nodes/SoIndexedLineSet.h>
33
34
#include < Inventor/nodes/SoNormal.h>
34
35
#include < Inventor/nodes/SoSeparator.h>
35
36
#include < Inventor/nodes/SoShapeHints.h>
36
- #include < Inventor/nodes/SoDepthBuffer .h>
37
+ #include < Inventor/nodes/SoSwitch .h>
37
38
#include < Inventor/nodes/SoTransparencyType.h>
38
39
#include < functional>
39
40
@@ -141,6 +142,8 @@ class FemPostObjectSelectionObserver
141
142
142
143
// ----------------------------------------------------------------------------
143
144
145
+ App::PropertyFloatConstraint::Constraints ViewProviderFemPostObject::sizeRange = {1.0 , 64.0 , 1.0 };
146
+
144
147
PROPERTY_SOURCE (FemGui::ViewProviderFemPostObject, Gui::ViewProviderDocumentObject)
145
148
146
149
ViewProviderFemPostObject::ViewProviderFemPostObject()
@@ -156,7 +159,27 @@ ViewProviderFemPostObject::ViewProviderFemPostObject()
156
159
" Coloring" ,
157
160
App::Prop_None,
158
161
" Select what to show for a vector field" );
159
- ADD_PROPERTY (Transparency, (0 ));
162
+ ADD_PROPERTY_TYPE (Transparency,
163
+ (0 ),
164
+ " Object Style" ,
165
+ App::Prop_None,
166
+ " Set object transparency." );
167
+ ADD_PROPERTY_TYPE (EdgeColor,
168
+ (0 .0f , 0 .0f , 0 .0f ),
169
+ " Object Style" ,
170
+ App::Prop_None,
171
+ " Set wireframe line color." );
172
+ ADD_PROPERTY_TYPE (PlainColorEdgeOnSurface,
173
+ (false ),
174
+ " Object Style" ,
175
+ App::Prop_None,
176
+ " Use plain color for edges on surface." );
177
+ ADD_PROPERTY_TYPE (LineWidth, (2 ), " Object Style" , App::Prop_None, " Set wireframe line width." );
178
+ ADD_PROPERTY_TYPE (PointSize, (3 ), " Object Style" , App::Prop_None, " Set node point size." );
179
+
180
+
181
+ LineWidth.setConstraints (&sizeRange);
182
+ PointSize.setConstraints (&sizeRange);
160
183
161
184
sPixmap = " fem-femmesh-from-shape" ;
162
185
@@ -174,8 +197,12 @@ ViewProviderFemPostObject::ViewProviderFemPostObject()
174
197
m_coordinates->ref ();
175
198
m_materialBinding = new SoMaterialBinding ();
176
199
m_materialBinding->ref ();
200
+ m_switchMatEdges = new SoSwitch ();
201
+ m_switchMatEdges->ref ();
177
202
m_material = new SoMaterial ();
178
203
m_material->ref ();
204
+ m_matPlainEdges = new SoMaterial ();
205
+ m_matPlainEdges->ref ();
179
206
m_normalBinding = new SoNormalBinding ();
180
207
m_normalBinding->ref ();
181
208
m_normals = new SoNormal ();
@@ -190,8 +217,8 @@ ViewProviderFemPostObject::ViewProviderFemPostObject()
190
217
m_lines->ref ();
191
218
m_drawStyle = new SoDrawStyle ();
192
219
m_drawStyle->ref ();
193
- m_drawStyle->lineWidth .setValue (2 );
194
- m_drawStyle->pointSize .setValue (3 );
220
+ m_drawStyle->lineWidth .setValue (LineWidth. getValue () );
221
+ m_drawStyle->pointSize .setValue (PointSize. getValue () );
195
222
m_sepMarkerLine = new SoSeparator ();
196
223
m_sepMarkerLine->ref ();
197
224
m_separator = new SoSeparator ();
@@ -245,6 +272,8 @@ ViewProviderFemPostObject::~ViewProviderFemPostObject()
245
272
m_sepMarkerLine->unref ();
246
273
m_separator->unref ();
247
274
m_material->unref ();
275
+ m_matPlainEdges->unref ();
276
+ m_switchMatEdges->unref ();
248
277
m_colorBar->Detach (this );
249
278
m_colorBar->unref ();
250
279
m_colorStyle->unref ();
@@ -255,12 +284,14 @@ void ViewProviderFemPostObject::attach(App::DocumentObject* pcObj)
255
284
{
256
285
ViewProviderDocumentObject::attach (pcObj);
257
286
287
+ m_switchMatEdges->addChild (m_material);
288
+ m_switchMatEdges->addChild (m_matPlainEdges);
258
289
// marker and line nodes
259
290
m_sepMarkerLine->addChild (m_transpType);
260
291
m_sepMarkerLine->addChild (m_depthBuffer);
261
292
m_sepMarkerLine->addChild (m_drawStyle);
262
293
m_sepMarkerLine->addChild (m_materialBinding);
263
- m_sepMarkerLine->addChild (m_material );
294
+ m_sepMarkerLine->addChild (m_switchMatEdges );
264
295
m_sepMarkerLine->addChild (m_coordinates);
265
296
m_sepMarkerLine->addChild (m_markers);
266
297
m_sepMarkerLine->addChild (m_lines);
@@ -638,14 +669,21 @@ void ViewProviderFemPostObject::WriteColorData(bool ResetColorBarRange)
638
669
setRangeOfColorBar (range[0 ], range[1 ]);
639
670
}
640
671
641
- m_material->diffuseColor .setNum (pd->GetNumberOfPoints ());
672
+ vtkIdType numPts = pd->GetNumberOfPoints ();
673
+ m_material->diffuseColor .setNum (numPts);
674
+ m_matPlainEdges->diffuseColor .setNum (numPts);
642
675
SbColor* diffcol = m_material->diffuseColor .startEditing ();
676
+ SbColor* edgeDiffcol = m_matPlainEdges->diffuseColor .startEditing ();
643
677
644
678
float overallTransp = Transparency.getValue () / 100 .0f ;
645
- m_material->transparency .setNum (pd->GetNumberOfPoints ());
679
+ m_material->transparency .setNum (numPts);
680
+ m_matPlainEdges->transparency .setNum (numPts);
646
681
float * transp = m_material->transparency .startEditing ();
682
+ float * edgeTransp = m_matPlainEdges->transparency .startEditing ();
647
683
648
- for (int i = 0 ; i < pd->GetNumberOfPoints (); i++) {
684
+ App::Color c;
685
+ App::Color cEdge = EdgeColor.getValue ();
686
+ for (int i = 0 ; i < numPts; i++) {
649
687
650
688
double value = 0 ;
651
689
if (component >= 0 ) {
@@ -659,13 +697,17 @@ void ViewProviderFemPostObject::WriteColorData(bool ResetColorBarRange)
659
697
value = std::sqrt (value);
660
698
}
661
699
662
- App::Color c = m_colorBar->getColor (value);
700
+ c = m_colorBar->getColor (value);
663
701
diffcol[i].setValue (c.r , c.g , c.b );
664
702
transp[i] = std::max (c.a , overallTransp);
703
+ edgeDiffcol[i].setValue (cEdge.r , cEdge.g , cEdge.b );
704
+ edgeTransp[i] = std::max (cEdge.a , overallTransp);
665
705
}
666
706
667
707
m_material->diffuseColor .finishEditing ();
668
708
m_material->transparency .finishEditing ();
709
+ m_matPlainEdges->diffuseColor .finishEditing ();
710
+ m_matPlainEdges->transparency .finishEditing ();
669
711
m_materialBinding->value = SoMaterialBinding::PER_VERTEX_INDEXED;
670
712
671
713
// In order to apply the transparency changes the shape nodes must be touched
@@ -677,10 +719,14 @@ void ViewProviderFemPostObject::WriteTransparency()
677
719
{
678
720
float trans = static_cast <float >(Transparency.getValue ()) / 100.0 ;
679
721
float * value = m_material->transparency .startEditing ();
722
+ float * edgeValue = m_matPlainEdges->transparency .startEditing ();
723
+ // m_material and m_matPlainEdges field containers have same size
680
724
for (int i = 0 ; i < m_material->transparency .getNum (); ++i) {
681
725
value[i] = trans;
726
+ edgeValue[i] = trans;
682
727
}
683
728
m_material->transparency .finishEditing ();
729
+ m_matPlainEdges->transparency .finishEditing ();
684
730
685
731
if (Transparency.getValue () > 99 ) {
686
732
m_depthBuffer->test .setValue (false );
@@ -853,6 +899,26 @@ void ViewProviderFemPostObject::onChanged(const App::Property* prop)
853
899
else if (prop == &Transparency) {
854
900
WriteTransparency ();
855
901
}
902
+ else if (prop == &LineWidth) {
903
+ m_drawStyle->lineWidth .setValue (LineWidth.getValue ());
904
+ }
905
+ else if (prop == &PointSize) {
906
+ m_drawStyle->pointSize .setValue (PointSize.getValue ());
907
+ }
908
+ else if (prop == &EdgeColor && setupPipeline ()) {
909
+ App::Color c = EdgeColor.getValue ();
910
+ SbColor* edgeColor = m_matPlainEdges->diffuseColor .startEditing ();
911
+ for (int i = 0 ; i < m_matPlainEdges->diffuseColor .getNum (); ++i) {
912
+ edgeColor[i].setValue (c.r , c.g , c.b );
913
+ }
914
+ m_matPlainEdges->diffuseColor .finishEditing ();
915
+ }
916
+ else if (prop == &PlainColorEdgeOnSurface || prop == &DisplayMode) {
917
+ bool plainColor = PlainColorEdgeOnSurface.getValue ()
918
+ && (strcmp (" Surface with Edges" , DisplayMode.getValueAsString ()) == 0 );
919
+ int child = plainColor ? 1 : 0 ;
920
+ m_switchMatEdges->whichChild .setValue (child);
921
+ }
856
922
857
923
ViewProviderDocumentObject::onChanged (prop);
858
924
}
0 commit comments