Salome HOME
ec2a7c949bc29db214b71bccf95f0b10343af4d1
[modules/smesh.git] / src / OBJECT / SMESH_Actor.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SMESH OBJECT : interactive object for SMESH visualization
24 //  File   : SMESH_Actor.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SMESH
27
28 #include "SMESH_ActorDef.h"
29 #include "SMESH_ActorUtils.h"
30 #include "SMESH_DeviceActor.h"
31 #include "SMESH_NodeLabelActor.h"
32 #include "SMESH_CellLabelActor.h"
33 #include "SMESH_ObjectDef.h"
34 #include "SMESH_ControlsDef.hxx"
35 #include "SMDS_UnstructuredGrid.hxx"
36 #include "SMESH_ScalarBarActor.h"
37 #include "VTKViewer_ExtractUnstructuredGrid.h"
38 #include "VTKViewer_FramedTextActor.h"
39 #include "SALOME_InteractiveObject.hxx"
40 #include "SMESH_SVTKActor.h"
41
42 #include "SUIT_Session.h"
43 #include "SUIT_ResourceMgr.h"
44
45 #include <Qtx.h>
46
47 #ifndef DISABLE_PLOT2DVIEWER
48 #include <SPlot2d_Histogram.h>
49 #endif
50
51 #include <vtkProperty.h>
52 #include <vtkTimeStamp.h>
53 #include <vtkObjectFactory.h>
54 #include <vtkShrinkPolyData.h>
55 #include <vtkMergeFilter.h>
56
57 #include <vtkMatrix4x4.h>
58 #include <vtkUnstructuredGrid.h>
59 #include <vtkPointData.h>
60 #include <vtkCellData.h>
61
62 #include <vtkMapper.h>
63 #include <vtkRenderer.h>
64
65 #include <vtkCell.h>
66 #include <vtkIdList.h>
67 #include <vtkIntArray.h>
68
69 #include <vtkActor2D.h>
70 #include <vtkProperty2D.h>
71 #include <vtkPolyData.h>
72 #include <vtkTextProperty.h>
73
74 #include <vtkLookupTable.h>
75
76 #include <vtkMath.h>
77 #include <vtkPlane.h>
78 #include <vtkImplicitBoolean.h>
79 #include <vtkImplicitFunctionCollection.h>
80
81 #include "utilities.h"
82
83 #ifdef _DEBUG_
84 static int MYDEBUG = 1;
85 #else
86 static int MYDEBUG = 1;
87 #endif
88
89 static int aLineWidthInc = 2;
90
91
92 SMESH_ActorDef* SMESH_ActorDef::New(){
93   return new SMESH_ActorDef();
94 }
95
96
97 SMESH_Actor* SMESH_Actor::New(TVisualObjPtr theVisualObj,
98                               const char* theEntry,
99                               const char* theName,
100                               int theIsClear)
101 {
102   SMESH_ActorDef* anActor = NULL;
103   if(theVisualObj->IsValid() ) {
104     anActor = SMESH_ActorDef::New();
105     if(!anActor->Init(theVisualObj,theEntry,theName,theIsClear)){
106       anActor->Delete();
107       anActor = NULL;
108     }
109     if( anActor )
110       anActor->UpdateScalarBar();
111   }
112   return anActor;
113 }
114
115
116 SMESH_ActorDef::SMESH_ActorDef()
117 {
118   if(MYDEBUG) MESSAGE("SMESH_ActorDef - "<<this);
119   myBaseActor = SMESH_DeviceActor::New();
120
121   myTimeStamp = vtkTimeStamp::New();
122
123   myIsPointsVisible = false;
124   myIsEntityModeCache = false;
125
126   myHighlightActor = SMESH_SVTKActor::New();
127   myHighlightActor->Delete(); // vtkSmartPointer!
128   myHighlightActor->Initialize();
129
130   myPreHighlightActor = SMESH_SVTKActor::New();
131   myPreHighlightActor->Delete();
132   myPreHighlightActor->Initialize();
133
134   myIsShrinkable = false;
135   myIsShrunk = false;
136
137   myIsFacesOriented = false;
138
139   myControlsPrecision = -1;
140   SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
141
142   if ( mgr && mgr->booleanValue( "SMESH", "use_precision", false ) )
143     myControlsPrecision = mgr->integerValue( "SMESH", "controls_precision", -1);
144
145   double aElem0DSize   = SMESH::GetFloat("SMESH:elem0d_size",5);
146   double aBallElemSize = SMESH::GetFloat("SMESH:ball_elem_size",10);
147   double aLineWidth    = SMESH::GetFloat("SMESH:element_width",1);
148   double aOutlineWidth = SMESH::GetFloat("SMESH:outline_width",1);
149
150   SMESH::LabelFont aFamilyNd = SMESH::FntTimes;
151   bool aBoldNd    = true;
152   bool anItalicNd = false;
153   bool aShadowNd  = false;
154   int  aSizeNd    = 10;
155   if ( mgr->hasValue( "SMESH", "numbering_node_font" ) ) {
156     QFont f = mgr->fontValue( "SMESH", "numbering_node_font" );
157     if ( f.family()      == "Arial" )   aFamilyNd = SMESH::FntArial;
158     else if ( f.family() == "Courier" ) aFamilyNd = SMESH::FntCourier;
159     else if ( f.family() == "Times" )   aFamilyNd = SMESH::FntTimes;
160     aBoldNd    = f.bold();
161     anItalicNd = f.italic();
162     aShadowNd  = f.overline();
163     aSizeNd    = f.pointSize();
164   }
165   double anRGBNd[3] = {1,1,1};
166   SMESH::GetColor( "SMESH", "numbering_node_color", anRGBNd[0], anRGBNd[1], anRGBNd[2], QColor( 255, 255, 255 ) );
167
168   SMESH::LabelFont aFamilyEl = SMESH::FntTimes;
169   bool aBoldEl    = true;
170   bool anItalicEl = false;
171   bool aShadowEl  = false;
172   int  aSizeEl    = 12;
173   if ( mgr->hasValue( "SMESH", "numbering_elem_font" ) ) {
174     QFont f = mgr->fontValue( "SMESH", "numbering_elem_font" );
175     if ( f.family()      == "Arial" )   aFamilyEl = SMESH::FntArial;
176     else if ( f.family() == "Courier" ) aFamilyEl = SMESH::FntCourier;
177     else if ( f.family() == "Times" )   aFamilyEl = SMESH::FntTimes;
178     aBoldEl    = f.bold();
179     anItalicEl = f.italic();
180     aShadowEl  = f.overline();
181     aSizeEl    = f.pointSize();
182   }
183   double anRGBEl[3] = {0,1,0};
184   SMESH::GetColor( "SMESH", "numbering_elem_color", anRGBEl[0], anRGBEl[1], anRGBEl[2], QColor( 0, 255, 0 ) );
185
186   vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
187   VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
188
189   //Definition 2D and 3D devices of the actor
190   //-----------------------------------------
191   double anRGB[3] = {1,1,1};
192   mySurfaceProp = vtkProperty::New();
193   QColor ffc, bfc;
194   int delta;
195   SMESH::GetColor( "SMESH", "fill_color", ffc, delta, "0,170,255|-100" ) ;
196   mySurfaceProp->SetColor( ffc.red() / 255. , ffc.green() / 255. , ffc.blue() / 255. );
197   myDeltaBrightness = delta;
198
199   myBackSurfaceProp = vtkProperty::New();
200   bfc = Qtx::mainColorToSecondary(ffc, delta);
201   myBackSurfaceProp->SetColor( bfc.red() / 255. , bfc.green() / 255. , bfc.blue() / 255. );
202
203   myNormalVProp = vtkProperty::New();
204   SMESH::GetColor( "SMESH", "volume_color", ffc, delta, "255,0,170|-100" );
205   myNormalVProp->SetColor( ffc.redF(), ffc.greenF(), ffc.blueF() );
206   myDeltaVBrightness = delta;
207
208   myReversedVProp = vtkProperty::New();
209   bfc = Qtx::mainColorToSecondary(ffc, delta);
210   myReversedVProp->SetColor( bfc.red() / 255. , bfc.green() / 255. , bfc.blue() / 255. );
211
212   my2DActor = SMESH_CellLabelActor::New();
213   my2DActor->SetStoreGemetryMapping(true);
214   my2DActor->SetUserMatrix(aMatrix);
215   my2DActor->PickableOff();
216   my2DActor->SetFontProperties( aFamilyEl, aSizeEl, aBoldEl, anItalicEl, aShadowEl, anRGBEl[0], anRGBEl[1], anRGBEl[2] );
217   my2DActor->SetProperty(mySurfaceProp);
218   my2DActor->SetBackfaceProperty(myBackSurfaceProp);
219   my2DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
220   aFilter = my2DActor->GetExtractUnstructuredGrid();
221   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
222   aFilter->RegisterCellsWithType(VTK_TRIANGLE);
223   aFilter->RegisterCellsWithType(VTK_POLYGON);
224   aFilter->RegisterCellsWithType(VTK_QUAD);
225   aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
226   aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
227   aFilter->RegisterCellsWithType(VTK_BIQUADRATIC_QUAD);
228   aFilter->RegisterCellsWithType(VTK_BIQUADRATIC_TRIANGLE);
229
230   my2DExtProp = vtkProperty::New();
231   my2DExtProp->DeepCopy(mySurfaceProp);
232   SMESH::GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
233   anRGB[0] = 1 - anRGB[0];
234   anRGB[1] = 1 - anRGB[1];
235   anRGB[2] = 1 - anRGB[2];
236   my2DExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
237
238   my2DExtActor = SMESH_DeviceActor::New();
239   my2DExtActor->SetUserMatrix(aMatrix);
240   my2DExtActor->PickableOff();
241   my2DExtActor->SetProperty(my2DExtProp);
242   my2DExtActor->SetBackfaceProperty(my2DExtProp);
243   my2DExtActor->SetRepresentation(SMESH_DeviceActor::eInsideframe);
244   aFilter = my2DExtActor->GetExtractUnstructuredGrid();
245   aFilter->RegisterCellsWithType(VTK_TRIANGLE);
246   aFilter->RegisterCellsWithType(VTK_POLYGON);
247   aFilter->RegisterCellsWithType(VTK_QUAD);
248   aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
249   aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
250   aFilter->RegisterCellsWithType(VTK_BIQUADRATIC_QUAD);
251   aFilter->RegisterCellsWithType(VTK_BIQUADRATIC_TRIANGLE);
252
253   my3DActor = SMESH_CellLabelActor::New();
254   my3DActor->SetStoreGemetryMapping(true);
255   my3DActor->SetUserMatrix(aMatrix);
256   my3DActor->PickableOff();
257   my3DActor->SetFontProperties( aFamilyEl, aSizeEl, aBoldEl, anItalicEl, aShadowEl, anRGBEl[0], anRGBEl[1], anRGBEl[2] );
258   my3DActor->SetProperty(myNormalVProp);
259   my3DActor->SetBackfaceProperty(myReversedVProp);
260   my3DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
261   my3DActor->SetCoincident3DAllowed(true);
262   aFilter = my3DActor->GetExtractUnstructuredGrid();
263   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
264   aFilter->RegisterCellsWithType(VTK_TETRA);
265   aFilter->RegisterCellsWithType(VTK_VOXEL);
266   aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
267   aFilter->RegisterCellsWithType(VTK_WEDGE);
268   aFilter->RegisterCellsWithType(VTK_PYRAMID);
269   aFilter->RegisterCellsWithType(VTK_HEXAGONAL_PRISM);
270   aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
271   aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
272   aFilter->RegisterCellsWithType(VTK_TRIQUADRATIC_HEXAHEDRON);
273   aFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
274   aFilter->RegisterCellsWithType(VTK_QUADRATIC_PYRAMID);
275   aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
276 //#ifdef VTK_HAVE_POLYHEDRON
277   MESSAGE("RegisterCellsWithType(VTK_POLYHEDRON)");
278   aFilter->RegisterCellsWithType(VTK_POLYHEDRON);
279 //#endif
280
281   my3DExtProp = vtkProperty::New();
282   my3DExtProp->DeepCopy(myNormalVProp);
283   SMESH::GetColor( "SMESH", "volume_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 0, 170 ) );
284   anRGB[0] = 1 - anRGB[0];
285   anRGB[1] = 1 - anRGB[1];
286   anRGB[2] = 1 - anRGB[2];
287   my3DExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
288
289   my3DExtActor = SMESH_DeviceActor::New();
290   my3DExtActor->SetUserMatrix(aMatrix);
291   my3DExtActor->PickableOff();
292   my3DExtActor->SetProperty(my3DExtProp);
293   my3DExtActor->SetBackfaceProperty(my3DExtProp);
294   my3DExtActor->SetRepresentation(SMESH_DeviceActor::eSurface);
295   my3DExtActor->SetCoincident3DAllowed(true);
296   aFilter = my3DExtActor->GetExtractUnstructuredGrid();
297   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
298   aFilter->RegisterCellsWithType(VTK_TETRA);
299   aFilter->RegisterCellsWithType(VTK_VOXEL);
300   aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
301   aFilter->RegisterCellsWithType(VTK_WEDGE);
302   aFilter->RegisterCellsWithType(VTK_PYRAMID);
303   aFilter->RegisterCellsWithType(VTK_HEXAGONAL_PRISM);
304   aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
305   aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
306   aFilter->RegisterCellsWithType(VTK_TRIQUADRATIC_HEXAHEDRON);
307   aFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
308   aFilter->RegisterCellsWithType(VTK_QUADRATIC_PYRAMID);
309   aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
310   aFilter->RegisterCellsWithType(VTK_POLYHEDRON);
311
312   //Definition 1D device of the actor
313   //---------------------------------
314   myEdgeProp = vtkProperty::New();
315   myEdgeProp->SetAmbient(1.0);
316   myEdgeProp->SetDiffuse(0.0);
317   myEdgeProp->SetSpecular(0.0);
318   SMESH::GetColor( "SMESH", "wireframe_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
319   myEdgeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
320   myEdgeProp->SetLineWidth(aLineWidth);
321
322   my1DActor = SMESH_CellLabelActor::New();
323   my1DActor->SetStoreGemetryMapping(true);
324   my1DActor->SetUserMatrix(aMatrix);
325   my1DActor->PickableOff();
326   my1DActor->SetHighlited(true);
327   my1DActor->SetFontProperties( aFamilyEl, aSizeEl, aBoldEl, anItalicEl, aShadowEl, anRGBEl[0], anRGBEl[1], anRGBEl[2] );
328   my1DActor->SetProperty(myEdgeProp);
329   my1DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
330   aFilter = my1DActor->GetExtractUnstructuredGrid();
331   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
332   aFilter->RegisterCellsWithType(VTK_LINE);
333   aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
334
335   my1DProp = vtkProperty::New();
336   my1DProp->DeepCopy(myEdgeProp);
337   my1DProp->SetLineWidth(aLineWidth + aLineWidthInc);
338   my1DProp->SetPointSize(aElem0DSize);
339
340   my1DExtProp = vtkProperty::New();
341   my1DExtProp->DeepCopy(myEdgeProp);
342   anRGB[0] = 1 - anRGB[0];
343   anRGB[1] = 1 - anRGB[1];
344   anRGB[2] = 1 - anRGB[2];
345   my1DExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
346   my1DExtProp->SetLineWidth(aLineWidth + aLineWidthInc);
347   my1DExtProp->SetPointSize(aElem0DSize);
348
349   my1DExtActor = SMESH_DeviceActor::New();
350   my1DExtActor->SetUserMatrix(aMatrix);
351   my1DExtActor->PickableOff();
352   my1DExtActor->SetHighlited(true);
353   my1DExtActor->SetVisibility(false);
354   my1DExtActor->SetProperty(my1DExtProp);
355   my1DExtActor->SetRepresentation(SMESH_DeviceActor::eInsideframe);
356   aFilter = my1DExtActor->GetExtractUnstructuredGrid();
357   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
358   aFilter->RegisterCellsWithType(VTK_LINE);
359   aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
360
361
362   //Definition 0D device of the actor (0d elements)
363   //-----------------------------------------------
364   my0DProp = vtkProperty::New();
365   SMESH::GetColor( "SMESH", "elem0d_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 255, 0 ) );
366   my0DProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
367   my0DProp->SetPointSize(aElem0DSize);
368
369   my0DActor = SMESH_CellLabelActor::New();
370   my0DActor->SetUserMatrix(aMatrix);
371   my0DActor->SetStoreGemetryMapping(true);
372   my0DActor->PickableOff();
373   my0DActor->SetFontProperties( aFamilyEl, aSizeEl, aBoldEl, anItalicEl, aShadowEl, anRGBEl[0], anRGBEl[1], anRGBEl[2] );
374   my0DActor->SetVisibility(false);
375   my0DActor->SetProperty(my0DProp);
376   my0DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
377   aFilter = my0DActor->GetExtractUnstructuredGrid();
378   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
379   aFilter->RegisterCellsWithType(VTK_VERTEX);
380
381   //Definition 0D device of the actor (ball elements)
382   //-----------------------------------------------
383   myBallProp = vtkProperty::New();
384   SMESH::GetColor( "SMESH", "ball_elem_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 85, 255 ) );
385   myBallProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
386   myBallProp->SetPointSize(aBallElemSize);
387
388   myBallActor = SMESH_CellLabelActor::New();
389   myBallActor->SetUserMatrix(aMatrix);
390   myBallActor->SetStoreGemetryMapping(true);
391   myBallActor->PickableOff();
392   myBallActor->SetFontProperties( aFamilyEl, aSizeEl, aBoldEl, anItalicEl, aShadowEl, anRGBEl[0], anRGBEl[1], anRGBEl[2] );
393   myBallActor->SetVisibility(false);
394   myBallActor->SetProperty(myBallProp);
395   myBallActor->SetRepresentation(SMESH_DeviceActor::eSurface);
396   myBallActor->SetBallEnabled(true);
397   aFilter = myBallActor->GetExtractUnstructuredGrid();
398   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
399   aFilter->RegisterCellsWithType(VTK_POLY_VERTEX);
400
401   //my0DExtProp = vtkProperty::New();
402   //my0DExtProp->DeepCopy(my0DProp);
403   //anRGB[0] = 1 - anRGB[0];
404   //anRGB[1] = 1 - anRGB[1];
405   //anRGB[2] = 1 - anRGB[2];
406   //my0DExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
407   //my0DExtProp->SetPointSize(aElem0DSize);
408   //
409   //my0DExtActor = SMESH_DeviceActor::New();
410   //my0DExtActor->SetUserMatrix(aMatrix);
411   //my0DExtActor->SetStoreClippingMapping(true);
412   //my0DExtActor->PickableOff();
413   //my0DExtActor->SetHighlited(true);
414   //my0DExtActor->SetVisibility(false);
415   //my0DExtActor->SetProperty(my0DExtProp);
416   //my0DExtActor->SetRepresentation(SMESH_DeviceActor::eInsideframe);
417   //aFilter = my0DExtActor->GetExtractUnstructuredGrid();
418   ////aFilter->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
419   //aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
420   //aFilter->RegisterCellsWithType(VTK_VERTEX);
421
422
423   //Definition 0D device of the actor (nodes)
424   //-----------------------------------------
425   myNodeProp = vtkProperty::New();
426   SMESH::GetColor( "SMESH", "node_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 0, 0 ) );
427   myNodeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
428
429   myNodeActor = SMESH_NodeLabelActor::New();
430   myNodeActor->SetUserMatrix(aMatrix);
431   myNodeActor->SetStoreClippingMapping(true);
432   myNodeActor->PickableOff();
433   myNodeActor->SetVisibility(false);
434   myNodeActor->SetFontProperties( aFamilyNd, aSizeNd, aBoldNd, anItalicNd, aShadowNd, anRGBNd[0], anRGBNd[1], anRGBNd[2] );
435   myNodeActor->SetProperty(myNodeProp);
436   myNodeActor->SetRepresentation(SMESH_DeviceActor::ePoint);
437   aFilter = myNodeActor->GetExtractUnstructuredGrid();
438   aFilter->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
439
440   myNodeExtProp = vtkProperty::New();
441   myNodeExtProp->DeepCopy(myNodeProp);
442   anRGB[0] = 1 - anRGB[0];
443   anRGB[1] = 1 - anRGB[1];
444   anRGB[2] = 1 - anRGB[2];
445   myNodeExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
446
447   myNodeExtActor = SMESH_DeviceActor::New();
448   myNodeExtActor->SetUserMatrix(aMatrix);
449   myNodeExtActor->SetStoreClippingMapping(true);
450   myNodeExtActor->PickableOff();
451   myNodeExtActor->SetHighlited(true);
452   myNodeExtActor->SetVisibility(false);
453   myNodeExtActor->SetProperty(myNodeExtProp);
454   myNodeExtActor->SetRepresentation(SMESH_DeviceActor::ePoint);
455   aFilter = myNodeExtActor->GetExtractUnstructuredGrid();
456   aFilter->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
457   aFilter->RegisterCellsWithType(VTK_VERTEX);
458
459   //Definition of Pickable and Highlitable engines
460   //----------------------------------------------
461
462   myBaseActor->SetUserMatrix(aMatrix);
463   myBaseActor->SetStoreGemetryMapping(true);
464   myBaseActor->GetProperty()->SetOpacity(0.0);
465   myPickableActor = myBaseActor;
466
467   myHighlightProp = vtkProperty::New();
468   myHighlightProp->SetAmbient(1.0);
469   myHighlightProp->SetDiffuse(0.0);
470   myHighlightProp->SetSpecular(0.0);
471   SMESH::GetColor( "SMESH", "selection_object_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
472   myHighlightProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
473   myHighlightProp->SetPointSize(aElem0DSize); // ??
474   myHighlightProp->SetLineWidth(aLineWidth);
475   myHighlightProp->SetRepresentation(1);
476
477   myOutLineProp = vtkProperty::New();
478   myOutLineProp->SetAmbient(1.0);
479   myOutLineProp->SetDiffuse(0.0);
480   myOutLineProp->SetSpecular(0.0);
481   SMESH::GetColor( "SMESH", "outline_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 70, 0 ) );
482   myOutLineProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
483   myOutLineProp->SetLineWidth(aOutlineWidth);
484   myOutLineProp->SetRepresentation(1);
485
486   myPreselectProp = vtkProperty::New();
487   myPreselectProp->SetAmbient(1.0);
488   myPreselectProp->SetDiffuse(0.0);
489   myPreselectProp->SetSpecular(0.0);
490   SMESH::GetColor( "SMESH", "highlight_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 255, 255 ) );
491   myPreselectProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
492   myPreselectProp->SetPointSize(aElem0DSize); // ??
493   myPreselectProp->SetLineWidth(aLineWidth);
494   myPreselectProp->SetRepresentation(1);
495
496   myHighlitableActor = SMESH_DeviceActor::New();
497   myHighlitableActor->SetUserMatrix(aMatrix);
498   myHighlitableActor->PickableOff();
499   myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
500   myHighlitableActor->SetCoincident3DAllowed(true);
501
502   aMatrix->Delete();
503
504   myName = "";
505   myIO = NULL;
506
507   myControlMode = eNone;
508   myControlActor = my2DActor;
509
510   //Definition of myScalarBarActor
511   //------------------------------
512   myLookupTable = vtkLookupTable::New();
513   //Fix for Bug PAL5195 - SMESH764:
514   //Controls - Aspect Ratio: incorrect colors of the best and worst values
515   myLookupTable->SetHueRange(0.667,0.0);
516
517   myScalarBarActor = SMESH_ScalarBarActor::New();
518   myScalarBarActor->SetVisibility(false);
519   myScalarBarActor->SetLookupTable(myLookupTable);
520
521   //Fix for Bug 13314:
522   //Incorrect "Min value" in Scalar Bar in Mesh:
523   //  myScalarBarActor->SetLabelFormat("%.4g");
524   // changes was commented because of regression bug IPAL 19981
525
526   mgr = SUIT_Session::session()->resourceMgr();
527   if( !mgr )
528     return;
529
530   myEntityMode = eAllEntity;
531   myEntityModeCache = eAllEntity;
532
533   // Clipping planes
534   myImplicitBoolean = vtkImplicitBoolean::New();
535   myImplicitBoolean->SetOperationTypeToIntersection();
536
537   //Quadratic 2D elements representation
538   //-----------------------------------------------------------------------------
539   int aQuadratic2DMode = mgr->integerValue( "SMESH", "quadratic_mode", 0);
540   if(aQuadratic2DMode == 0){
541     myHighlitableActor->SetQuadraticArcMode(false);
542     my2DActor->SetQuadraticArcMode(false);
543     my1DActor->SetQuadraticArcMode(false);
544   }
545   else if(aQuadratic2DMode == 1){
546     myHighlitableActor->SetQuadraticArcMode(true);
547     my2DActor->SetQuadraticArcMode(true);
548     my1DActor->SetQuadraticArcMode(true);
549   }
550
551   int aQuadraticAngle = mgr->integerValue( "SMESH", "max_angle", 2);
552   myHighlitableActor->SetQuadraticArcAngle(aQuadraticAngle);
553   my2DActor->SetQuadraticArcAngle(aQuadraticAngle);
554
555   // Set colors of the name actor
556   SMESH::GetColor( "SMESH", "default_grp_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
557   myNameActor->SetBackgroundColor(anRGB[0], anRGB[1], anRGB[2]);
558   SMESH::GetColor( "SMESH", "group_name_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
559   myNameActor->SetForegroundColor(anRGB[0], anRGB[1], anRGB[2]);
560
561 #ifndef DISABLE_PLOT2DVIEWER
562   my2dHistogram = 0;
563 #endif
564
565   SetBallSize(aBallElemSize);
566   Set0DSize(aElem0DSize);
567 }
568
569
570 SMESH_ActorDef::~SMESH_ActorDef()
571 {
572   if(MYDEBUG) MESSAGE("~SMESH_ActorDef - "<<this);
573
574   // Please keep the order same as one in the header file
575
576   myTimeStamp->Delete();
577
578   myScalarBarActor->Delete();
579   myLookupTable->Delete();
580
581   mySurfaceProp->Delete();
582   myBackSurfaceProp->Delete();
583   myNormalVProp->Delete();
584   myReversedVProp->Delete();
585   myEdgeProp->Delete();
586   myNodeProp->Delete();
587
588   myNodeActor->Delete();
589   myBaseActor->Delete();
590   //myPickableActor->Delete(); myPickableActor == myBaseActor
591
592   myHighlightProp->Delete();
593   myOutLineProp->Delete();
594   myPreselectProp->Delete();
595
596   myHighlitableActor->Delete();
597
598   my2DExtProp->Delete();
599   my3DExtProp->Delete();
600   my2DActor->Delete();
601   my2DExtActor->Delete();
602   my3DActor->Delete();
603   my3DExtActor->Delete();
604   // myControlActor->Delete(); myControlActor == my2DActor
605
606   myNodeExtProp->Delete();
607   myNodeExtActor->Delete();
608
609   my1DProp->Delete();
610   my1DActor->Delete();
611   my1DExtProp->Delete();
612   my1DExtActor->Delete();
613
614   my0DProp->Delete();
615   my0DActor->Delete();
616   myBallProp->Delete();
617   myBallActor->Delete();
618   //my0DExtProp->Delete();
619   //my0DExtActor->Delete();
620
621   myImplicitBoolean->Delete();
622
623 #ifndef DISABLE_PLOT2DVIEWER
624   if(my2dHistogram) {
625     SMESH::ProcessIn2DViewers(this,SMESH::RemoveFrom2dViewer);
626     delete my2dHistogram;
627   }
628 #endif
629 }
630
631 void SMESH_ActorDef::Delete()
632 {
633   // This is just to guarantee that the DeleteActorEvent (which was previously invoked
634   // from the actor's destructor) will be thrown before removing the actor's observers,
635   // that is done inside the Superclass::Delete() method but before the destructor itself
636   // (see the issue 0021562: EDF SMESH: clipping and delete mesh clipped leads to crash).
637   // The event is caught by SMESHGUI::ProcessEvents() static method.
638   this->InvokeEvent( SMESH::DeleteActorEvent, NULL );
639
640   Superclass::Delete();
641 }
642
643 void SMESH_ActorDef::SetPointsLabeled( bool theIsPointsLabeled )
644 {
645   if(myNodeActor) {
646     myNodeActor->SetPointsLabeled(theIsPointsLabeled);
647     SetRepresentation(GetRepresentation());
648     myTimeStamp->Modified();
649   }
650 }
651
652 void SMESH_ActorDef::SetPointsFontProperties( SMESH::LabelFont theFamily, int theSize,
653                                               bool theBold, bool theItalic, bool theShadow,
654                                               double r, double g, double b )
655 {    
656   if(myNodeActor) {
657     myNodeActor->SetFontProperties( theFamily, theSize, theBold, theItalic, theShadow, r, g, b );
658     SetRepresentation( GetRepresentation() );
659     myTimeStamp->Modified();
660   }
661 }
662
663 void SMESH_ActorDef::SetCellsFontProperties( SMESH::LabelFont theFamily, int theSize,
664                                              bool theBold, bool theItalic, bool theShadow,
665                                              double r, double g, double b )
666 {    
667   if(my3DActor) {
668     my3DActor->SetFontProperties( theFamily, theSize, theBold, theItalic, theShadow, r, g, b );
669   }
670   if(my2DActor) {
671     my2DActor->SetFontProperties( theFamily, theSize, theBold, theItalic, theShadow, r, g, b );
672     SetRepresentation( GetRepresentation() );
673     myTimeStamp->Modified();
674   }
675   if(my1DActor) {
676     my1DActor->SetFontProperties( theFamily, theSize, theBold, theItalic, theShadow, r, g, b );
677     SetRepresentation( GetRepresentation() );
678     myTimeStamp->Modified();
679   }
680   if(my0DActor) {
681     my0DActor->SetFontProperties( theFamily, theSize, theBold, theItalic, theShadow, r, g, b );
682     SetRepresentation( GetRepresentation() );
683     myTimeStamp->Modified();
684   }
685   if(myBallActor) {
686     myBallActor->SetFontProperties( theFamily, theSize, theBold, theItalic, theShadow, r, g, b );
687     SetRepresentation( GetRepresentation() );
688     myTimeStamp->Modified();
689   }
690 }
691
692 bool SMESH_ActorDef::GetPointsLabeled() {
693   return myNodeActor && myNodeActor->GetPointsLabeled();
694 }
695
696 void SMESH_ActorDef::SetCellsLabeled(bool theIsCellsLabeled)
697 {
698   if(my3DActor)
699     my3DActor->SetCellsLabeled(theIsCellsLabeled);
700
701   if(my2DActor)
702     my2DActor->SetCellsLabeled(theIsCellsLabeled);
703
704   if(my1DActor)
705     my1DActor->SetCellsLabeled(theIsCellsLabeled);
706
707   if(my0DActor)
708     my0DActor->SetCellsLabeled(theIsCellsLabeled);
709
710   if(myBallActor)
711     myBallActor->SetCellsLabeled(theIsCellsLabeled);
712
713   myTimeStamp->Modified();
714 }
715
716
717 bool SMESH_ActorDef::GetCellsLabeled() {
718   bool result = false;
719   if(my3DActor)
720     result = result || my3DActor->GetCellsLabeled();
721
722   if(my2DActor)
723     result = result || my2DActor->GetCellsLabeled();
724
725   if(my1DActor)
726     result = result || my1DActor->GetCellsLabeled();
727
728   if(my0DActor)
729     result = result || my0DActor->GetCellsLabeled();
730
731   if(myBallActor)
732     result = result || myBallActor->GetCellsLabeled();
733
734   return result;
735 }
736
737
738 void SMESH_ActorDef::SetFacesOriented(bool theIsFacesOriented)
739 {
740   myIsFacesOriented = theIsFacesOriented;
741
742   my2DActor->SetFacesOriented(theIsFacesOriented);
743   my3DActor->SetFacesOriented(theIsFacesOriented);
744
745   myTimeStamp->Modified();
746 }
747
748 bool SMESH_ActorDef::GetFacesOriented()
749 {
750   return myIsFacesOriented;
751 }
752
753 void SMESH_ActorDef::SetFacesOrientationColor(double r,double g,double b)
754 {
755   my2DActor->SetFacesOrientationColor( r, g, b );
756   my3DActor->SetFacesOrientationColor( r, g, b );
757 }
758
759 void SMESH_ActorDef::GetFacesOrientationColor(double& r,double& g,double& b)
760 {
761   my3DActor->GetFacesOrientationColor( r, g, b );
762 }
763
764 void SMESH_ActorDef::SetFacesOrientationScale(double theScale)
765 {
766   my2DActor->SetFacesOrientationScale( theScale );
767   my3DActor->SetFacesOrientationScale( theScale );
768 }
769
770 double SMESH_ActorDef::GetFacesOrientationScale()
771 {
772   return my3DActor->GetFacesOrientationScale();
773 }
774
775 void SMESH_ActorDef::SetFacesOrientation3DVectors(bool theState)
776 {
777   my2DActor->SetFacesOrientation3DVectors( theState );
778   my3DActor->SetFacesOrientation3DVectors( theState );
779 }
780
781 bool SMESH_ActorDef::GetFacesOrientation3DVectors()
782 {
783   return my3DActor->GetFacesOrientation3DVectors();
784 }
785
786
787 void
788 SMESH_ActorDef::
789 SetControlMode(eControl theMode)
790 {
791   SetControlMode(theMode,true);
792 }
793
794
795 void
796 SMESH_ActorDef::
797 SetControlMode(eControl theMode,
798                bool theCheckEntityMode)
799 {
800   vtkLookupTable* lookupTable = static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
801   bool isLogarithmic = lookupTable->GetScale() == VTK_SCALE_LOG10;
802   lookupTable->SetScale(VTK_SCALE_LINEAR);
803
804   SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
805   if( !mgr )
806     return;
807
808   myControlMode = eNone;
809   theCheckEntityMode &= mgr->booleanValue( "SMESH", "display_entity", false );
810
811   my0DActor->GetMapper()->SetScalarVisibility(false);
812   my1DActor->GetMapper()->SetScalarVisibility(false);
813   my2DActor->GetMapper()->SetScalarVisibility(false);
814   my3DActor->GetMapper()->SetScalarVisibility(false);
815   myBallActor->GetMapper()->SetScalarVisibility(false);
816   myScalarBarActor->SetVisibility(false);
817
818   bool anIsScalarVisible = theMode > eNone;
819
820   if(anIsScalarVisible) {
821     switch(theMode) {
822     case eLength:
823     {
824       SMESH::Controls::Length* aControl = new SMESH::Controls::Length();
825       aControl->SetPrecision( myControlsPrecision );
826       myFunctor.reset( aControl );
827       myControlActor = my1DActor;
828       break;
829     }
830     case eLength2D:
831     {
832       myFunctor.reset(new SMESH::Controls::Length2D());
833       myControlActor = my2DActor;
834       break;
835     }
836     case eFreeBorders:
837       myFunctor.reset(new SMESH::Controls::FreeBorders());
838       myControlActor = my1DActor;
839       break;
840     case eFreeEdges:
841       myFunctor.reset(new SMESH::Controls::FreeEdges());
842       myControlActor = my2DActor;
843       break;
844     case eFreeNodes:
845       myFunctor.reset(new SMESH::Controls::FreeNodes());
846       myControlActor = myNodeActor;
847       break;
848     case eFreeFaces:
849       myFunctor.reset(new SMESH::Controls::FreeFaces());
850       myControlActor = my2DActor;
851       break;
852     case eCoincidentNodes:
853       {
854         SMESH::Controls::CoincidentNodes* cn = new SMESH::Controls::CoincidentNodes();
855         double tol = mgr->doubleValue( "SMESH", "equal_nodes_tolerance", 1e-7 );
856         cn->SetTolerance( tol );
857         myFunctor.reset(cn);
858         myControlActor = myNodeActor;
859         break;
860       }
861     case eCoincidentElems1D:
862       myFunctor.reset(new SMESH::Controls::CoincidentElements1D());
863       myControlActor = my1DActor;
864       break;
865     case eCoincidentElems2D:
866       myFunctor.reset(new SMESH::Controls::CoincidentElements2D());
867       myControlActor = my2DActor;
868       break;
869     case eCoincidentElems3D:
870       myFunctor.reset(new SMESH::Controls::CoincidentElements3D());
871       myControlActor = my3DActor;
872       break;
873     case eBareBorderFace:
874       myFunctor.reset(new SMESH::Controls::BareBorderFace());
875       myControlActor = my2DActor;
876       break;
877     case eOverConstrainedFace:
878       myFunctor.reset(new SMESH::Controls::OverConstrainedFace());
879       myControlActor = my2DActor;
880       break;
881     case eMultiConnection:
882       myFunctor.reset(new SMESH::Controls::MultiConnection());
883       myControlActor = my1DActor;
884       break;
885     case eMultiConnection2D:
886       myFunctor.reset(new SMESH::Controls::MultiConnection2D());
887       myControlActor = my2DActor;
888       break;
889     case eArea:
890     {
891       SMESH::Controls::Area* aControl = new SMESH::Controls::Area();
892       aControl->SetPrecision( myControlsPrecision );
893       myFunctor.reset( aControl );
894       myControlActor = my2DActor;
895       break;
896     }
897     case eTaper:
898     {
899       SMESH::Controls::Taper* aControl = new SMESH::Controls::Taper();
900       aControl->SetPrecision( myControlsPrecision );
901       myFunctor.reset( aControl );
902       myControlActor = my2DActor;
903       break;
904     }
905     case eAspectRatio:
906     {
907       SMESH::Controls::AspectRatio* aControl = new SMESH::Controls::AspectRatio();
908       aControl->SetPrecision( myControlsPrecision );
909       myFunctor.reset( aControl );
910       myControlActor = my2DActor;
911       break;
912     }
913     case eAspectRatio3D:
914     {
915       SMESH::Controls::AspectRatio3D* aControl = new SMESH::Controls::AspectRatio3D();
916       aControl->SetPrecision( myControlsPrecision );
917       myFunctor.reset( aControl );
918       myControlActor = my3DActor;
919       break;
920     }
921     case eVolume3D:
922     {
923       SMESH::Controls::Volume* aControl = new SMESH::Controls::Volume();
924       aControl->SetPrecision( myControlsPrecision );
925       myFunctor.reset( aControl );
926       myControlActor = my3DActor;
927       break;
928     }
929     case eMaxElementLength2D:
930     {
931       SMESH::Controls::MaxElementLength2D* aControl = new SMESH::Controls::MaxElementLength2D();
932       aControl->SetPrecision( myControlsPrecision );
933       myFunctor.reset( aControl );
934       myControlActor = my2DActor;
935       break;
936     }
937     case eMaxElementLength3D:
938     {
939       SMESH::Controls::MaxElementLength3D* aControl = new SMESH::Controls::MaxElementLength3D();
940       aControl->SetPrecision( myControlsPrecision );
941       myFunctor.reset( aControl );
942       myControlActor = my3DActor;
943       break;
944     }
945     case eBareBorderVolume:
946     {
947       myFunctor.reset(new SMESH::Controls::BareBorderVolume());
948       myControlActor = my3DActor;
949       break;
950     }
951     case eOverConstrainedVolume:
952     {
953       myFunctor.reset(new SMESH::Controls::OverConstrainedVolume());
954       myControlActor = my3DActor;
955       break;
956     }
957     case eMinimumAngle:
958     {
959       SMESH::Controls::MinimumAngle* aControl = new SMESH::Controls::MinimumAngle();
960       aControl->SetPrecision( myControlsPrecision );
961       myFunctor.reset( aControl );
962       myControlActor = my2DActor;
963       break;
964     }
965     case eWarping:
966     {
967       SMESH::Controls::Warping* aControl = new SMESH::Controls::Warping();
968       aControl->SetPrecision( myControlsPrecision );
969       myFunctor.reset( aControl );
970       myControlActor = my2DActor;
971       break;
972     }
973     case eSkew:
974     {
975       SMESH::Controls::Skew* aControl = new SMESH::Controls::Skew();
976       aControl->SetPrecision( myControlsPrecision );
977       myFunctor.reset( aControl );
978       myControlActor = my2DActor;
979       break;
980     }
981     default:
982       return;
983     }
984
985     vtkUnstructuredGrid* aGrid = myControlActor->GetUnstructuredGrid();
986     vtkIdType aNbCells = aGrid->GetNumberOfCells();
987     if(aNbCells){
988       myControlMode = theMode;
989       switch(myControlMode){
990       case eFreeNodes:
991       case eCoincidentNodes:
992         myNodeExtActor->SetExtControlMode(myFunctor);
993         break;
994       case eFreeEdges:
995       case eFreeBorders:
996       case eCoincidentElems1D:
997         my1DExtActor->SetExtControlMode(myFunctor);
998         break;
999       case eFreeFaces:
1000       case eBareBorderFace:
1001       case eOverConstrainedFace:
1002       case eCoincidentElems2D:
1003         my2DExtActor->SetExtControlMode(myFunctor);
1004         break;
1005       case eBareBorderVolume:
1006       case eOverConstrainedVolume:
1007       case eCoincidentElems3D:
1008         my3DExtActor->SetExtControlMode(myFunctor);
1009         break;
1010       case eLength2D:
1011       case eMultiConnection2D:
1012         my1DExtActor->SetExtControlMode(myFunctor,myScalarBarActor,myLookupTable);
1013         UpdateDistribution();
1014         break;
1015       default:
1016         myControlActor->SetControlMode(myFunctor,myScalarBarActor,myLookupTable);
1017         UpdateDistribution();
1018       }
1019     }
1020
1021     if(theCheckEntityMode) {
1022       if(myControlActor == my1DActor) {
1023         if (!myIsEntityModeCache){
1024           myEntityModeCache = GetEntityMode();
1025           myIsEntityModeCache=true;
1026         }
1027         SetEntityMode(eEdges);
1028       }
1029       else if(myControlActor == my2DActor) {
1030         switch(myControlMode) {
1031         case eLength2D:
1032         case eFreeEdges:
1033         case eFreeFaces:
1034         case eMultiConnection2D:
1035           if (!myIsEntityModeCache){
1036             myEntityModeCache = GetEntityMode();
1037             myIsEntityModeCache=true;
1038           }
1039           SetEntityMode(eFaces);
1040           break;
1041         default:
1042           if (!myIsEntityModeCache){
1043             myEntityModeCache = GetEntityMode();
1044             myIsEntityModeCache=true;
1045           }
1046           SetEntityMode(eFaces);
1047         }
1048       }else if(myControlActor == my3DActor) {
1049         if (!myIsEntityModeCache){
1050             myEntityModeCache = GetEntityMode();
1051             myIsEntityModeCache=true;
1052         }
1053         SetEntityMode(eVolumes);
1054     }
1055     }
1056
1057   }
1058   else {
1059     if(theCheckEntityMode){
1060       myEntityMode = myEntityModeCache;
1061       myIsEntityModeCache = false;
1062     }
1063     myFunctor.reset();
1064   }
1065
1066   SetRepresentation(GetRepresentation());
1067
1068   myTimeStamp->Modified();
1069   Modified();
1070
1071   lookupTable = static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
1072   double * range = lookupTable->GetRange();
1073
1074   if (isLogarithmic && range[0] > 1e-07 && range[1] > 1e-07)
1075     lookupTable->SetScale(VTK_SCALE_LOG10);
1076
1077   Update();
1078 }
1079
1080
1081 void SMESH_ActorDef::AddToRender(vtkRenderer* theRenderer){
1082
1083   theRenderer->AddActor(myBaseActor);
1084   theRenderer->AddActor(myNodeExtActor);
1085   theRenderer->AddActor(my1DExtActor);
1086
1087   my3DActor   ->AddToRender(theRenderer);
1088   my3DExtActor->AddToRender(theRenderer);
1089   my2DActor   ->AddToRender(theRenderer);
1090   my2DExtActor->AddToRender(theRenderer);
1091   myNodeActor ->AddToRender(theRenderer);
1092   my1DActor   ->AddToRender(theRenderer);
1093   my0DActor   ->AddToRender(theRenderer);
1094   myBallActor ->AddToRender(theRenderer);
1095
1096   theRenderer->AddActor(myHighlitableActor);
1097
1098   theRenderer->AddActor2D(myScalarBarActor);
1099
1100   // the superclass' method should be called at the end
1101   // (in particular, for correct work of selection)
1102   SALOME_Actor::AddToRender(theRenderer);
1103 }
1104
1105 void SMESH_ActorDef::RemoveFromRender(vtkRenderer* theRenderer){
1106   SALOME_Actor::RemoveFromRender(theRenderer);
1107
1108   theRenderer->RemoveActor(myBaseActor);
1109
1110   theRenderer->RemoveActor(myNodeExtActor);
1111
1112   theRenderer->RemoveActor(myHighlitableActor);
1113
1114   //theRenderer->RemoveActor(my0DExtActor);
1115
1116   theRenderer->RemoveActor(my1DExtActor);
1117
1118   my2DActor->RemoveFromRender(theRenderer);
1119   my2DExtActor->RemoveFromRender(theRenderer);
1120   my3DActor->RemoveFromRender(theRenderer);
1121   my3DExtActor->RemoveFromRender(theRenderer);
1122   myNodeActor->RemoveFromRender(theRenderer);
1123   my0DActor->RemoveFromRender(theRenderer);
1124   myBallActor->RemoveFromRender(theRenderer);
1125   my1DActor->RemoveFromRender(theRenderer);
1126
1127   theRenderer->RemoveActor(myScalarBarActor);
1128 }
1129
1130
1131 bool SMESH_ActorDef::Init(TVisualObjPtr theVisualObj,
1132                           const char* theEntry,
1133                           const char* theName,
1134                           int theIsClear)
1135 {
1136   Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry,"SMESH",theName);
1137   setIO(anIO);
1138   setName(theName);
1139
1140   myVisualObj = theVisualObj;
1141   myVisualObj->Update(theIsClear);
1142
1143   SMESH_SVTKActor::SafeDownCast(myHighlightActor)->SetVisualObject(myVisualObj);
1144   SMESH_SVTKActor::SafeDownCast(myPreHighlightActor)->SetVisualObject(myVisualObj);
1145
1146   myNodeActor->Init(myVisualObj,myImplicitBoolean);
1147   myBaseActor->Init(myVisualObj,myImplicitBoolean);
1148
1149   myHighlitableActor->Init(myVisualObj,myImplicitBoolean);
1150
1151   myNodeExtActor->Init(myVisualObj,myImplicitBoolean);
1152
1153   my0DActor->Init(myVisualObj,myImplicitBoolean);
1154   myBallActor->Init(myVisualObj,myImplicitBoolean);
1155   //my0DExtActor->Init(myVisualObj,myImplicitBoolean);
1156
1157   my1DActor->Init(myVisualObj,myImplicitBoolean);
1158   my1DExtActor->Init(myVisualObj,myImplicitBoolean);
1159
1160   my2DActor->Init(myVisualObj,myImplicitBoolean);
1161   my2DExtActor->Init(myVisualObj,myImplicitBoolean);
1162   my3DActor->Init(myVisualObj,myImplicitBoolean);
1163   my3DExtActor->Init(myVisualObj,myImplicitBoolean);
1164
1165   my0DActor->GetMapper()->SetLookupTable(myLookupTable);
1166   myBallActor->GetMapper()->SetLookupTable(myLookupTable);
1167   //my0DExtActor->GetMapper()->SetLookupTable(myLookupTable);
1168
1169   my1DActor->GetMapper()->SetLookupTable(myLookupTable);
1170   my1DExtActor->GetMapper()->SetLookupTable(myLookupTable);
1171
1172   my2DActor->GetMapper()->SetLookupTable(myLookupTable);
1173   my2DExtActor->GetMapper()->SetLookupTable(myLookupTable);
1174   my3DActor->GetMapper()->SetLookupTable(myLookupTable);
1175   my3DExtActor->GetMapper()->SetLookupTable(myLookupTable);
1176     
1177   double aFactor, aUnits;
1178   my2DActor->GetPolygonOffsetParameters(aFactor,aUnits);
1179   my2DActor->SetPolygonOffsetParameters(aFactor,aUnits*0.75);
1180   my2DExtActor->SetPolygonOffsetParameters(aFactor,aUnits*0.5);
1181   my3DActor->SetPolygonOffsetParameters(2*aFactor,aUnits);
1182
1183   SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
1184   if( !mgr )
1185     return false;
1186
1187   //SetIsShrunkable(theGrid->GetNumberOfCells() > 10);
1188   SetIsShrunkable(true);
1189
1190   SetShrinkFactor( SMESH::GetFloat( "SMESH:shrink_coeff", 75 ) / 100. );
1191
1192   int aMode = mgr->integerValue( "SMESH", "display_mode" );
1193   SetRepresentation(-1);
1194
1195   if(aMode == 0){
1196     SetRepresentation(eEdge);
1197   }else if(aMode == 1){
1198     SetRepresentation(eSurface);
1199   }else if(aMode == 2){
1200     SetRepresentation(ePoint);
1201   }
1202
1203   if(aMode == 3){
1204     SetShrink();
1205   }
1206
1207   if( dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
1208     SetIsDisplayNameActor( true );
1209
1210   int aMarkerType = mgr->integerValue( "SMESH", "type_of_marker", 1 ); // dot
1211   int aMarkerScale = mgr->integerValue( "SMESH", "marker_scale", 9 );  // 5 pixels
1212   SetMarkerStd( (VTK::MarkerType)aMarkerType, (VTK::MarkerScale)aMarkerScale );
1213
1214   myTimeStamp->Modified();
1215   Modified();
1216   return true;
1217 }
1218
1219
1220 double* SMESH_ActorDef::GetBounds(){
1221   return myNodeActor->GetBounds();
1222 }
1223
1224
1225 vtkDataSet* SMESH_ActorDef::GetInput(){
1226   return GetUnstructuredGrid();
1227 }
1228
1229
1230 void SMESH_ActorDef::SetTransform(VTKViewer_Transform* theTransform){
1231   Superclass::SetTransform(theTransform);
1232
1233   myNodeActor->SetTransform(theTransform);
1234   myBaseActor->SetTransform(theTransform);
1235
1236   myHighlitableActor->SetTransform(theTransform);
1237
1238   myNodeExtActor->SetTransform(theTransform);
1239
1240   my0DActor->SetTransform(theTransform);
1241   myBallActor->SetTransform(theTransform);
1242   //my0DExtActor->SetTransform(theTransform);
1243
1244   my1DActor->SetTransform(theTransform);
1245   my1DExtActor->SetTransform(theTransform);
1246
1247   my2DActor->SetTransform(theTransform);
1248   my2DExtActor->SetTransform(theTransform);
1249   my3DActor->SetTransform(theTransform);
1250   my3DExtActor->SetTransform(theTransform);
1251
1252   Modified();
1253 }
1254
1255
1256 void SMESH_ActorDef::SetMapper(vtkMapper* theMapper){
1257   vtkLODActor::SetMapper(theMapper);
1258 }
1259
1260
1261 void SMESH_ActorDef::ShallowCopy(vtkProp *prop){
1262   SALOME_Actor::ShallowCopy(prop);
1263 }
1264
1265
1266 vtkMapper* SMESH_ActorDef::GetMapper(){
1267   return myPickableActor->GetMapper();
1268 }
1269
1270
1271 vtkUnstructuredGrid* SMESH_ActorDef::GetUnstructuredGrid(){
1272   return myVisualObj->GetUnstructuredGrid();
1273 }
1274
1275
1276 bool SMESH_ActorDef::IsInfinitive(){
1277   vtkDataSet *aDataSet = myPickableActor->GetUnstructuredGrid();
1278   myIsInfinite = aDataSet->GetNumberOfCells() == 0 ||
1279     ( aDataSet->GetNumberOfCells() == 1 &&
1280     aDataSet->GetCell(0)->GetCellType() == VTK_VERTEX );
1281   return SALOME_Actor::IsInfinitive();
1282 }
1283
1284
1285 void SMESH_ActorDef::SetIsShrunkable(bool theShrunkable){
1286   if ( myIsShrinkable == theShrunkable )
1287     return;
1288   myIsShrinkable = theShrunkable;
1289   Modified();
1290 }
1291
1292 double SMESH_ActorDef::GetShrinkFactor(){
1293   return myBaseActor->GetShrinkFactor();
1294 }
1295
1296 void SMESH_ActorDef::SetShrinkFactor(double theValue){
1297   myBaseActor->SetShrinkFactor(theValue);
1298
1299   my1DActor->SetShrinkFactor(theValue);
1300   my1DExtActor->SetShrinkFactor(theValue);
1301
1302   my2DActor->SetShrinkFactor(theValue);
1303   my2DExtActor->SetShrinkFactor(theValue);
1304   my3DActor->SetShrinkFactor(theValue);
1305   my3DExtActor->SetShrinkFactor(theValue);
1306   my3DExtActor->SetShrinkFactor(theValue);
1307   myHighlitableActor->SetShrinkFactor(theValue);
1308
1309   Modified();
1310 }
1311
1312 void SMESH_ActorDef::SetShrink(){
1313   if(!myIsShrinkable) return;
1314
1315   myBaseActor->SetShrink();
1316
1317   my1DActor->SetShrink();
1318   my1DExtActor->SetShrink();
1319
1320   my2DActor->SetShrink();
1321   my2DExtActor->SetShrink();
1322   my3DActor->SetShrink();
1323   my3DExtActor->SetShrink();
1324   myHighlitableActor->SetShrink();
1325
1326   myIsShrunk = true;
1327   Modified();
1328 }
1329
1330 void SMESH_ActorDef::UnShrink(){
1331   if(!myIsShrunk) return;
1332
1333   myBaseActor->UnShrink();
1334
1335   my1DActor->UnShrink();
1336   my1DExtActor->UnShrink();
1337
1338   my2DActor->UnShrink();
1339   my2DExtActor->UnShrink();
1340   my3DActor->UnShrink();
1341   my3DExtActor->UnShrink();
1342   myHighlitableActor->UnShrink();
1343
1344   myIsShrunk = false;
1345   Modified();
1346 }
1347
1348
1349 int SMESH_ActorDef::GetNodeObjId(int theVtkID){
1350   return myPickableActor->GetNodeObjId(theVtkID);
1351 }
1352
1353 double* SMESH_ActorDef::GetNodeCoord(int theObjID){
1354   return myPickableActor->GetNodeCoord(theObjID);
1355 }
1356
1357
1358 int SMESH_ActorDef::GetElemObjId(int theVtkID){
1359   return myPickableActor->GetElemObjId(theVtkID);
1360 }
1361
1362 vtkCell* SMESH_ActorDef::GetElemCell(int theObjID){
1363   return myPickableActor->GetElemCell(theObjID);
1364 }
1365
1366
1367 void SMESH_ActorDef::SetVisibility(int theMode){
1368   SetVisibility(theMode,true);
1369 }
1370
1371
1372 void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation){
1373   SALOME_Actor::SetVisibility(theMode);
1374
1375   myNodeActor->VisibilityOff();
1376   myBaseActor->VisibilityOff();
1377
1378   myNodeExtActor->VisibilityOff();
1379
1380   my0DActor->VisibilityOff();
1381   myBallActor->VisibilityOff();
1382   //my0DExtActor->VisibilityOff();
1383
1384   my1DActor->VisibilityOff();
1385   my1DExtActor->VisibilityOff();
1386
1387   my2DActor->VisibilityOff();
1388   my2DExtActor->VisibilityOff();
1389   my3DActor->VisibilityOff();
1390   my3DExtActor->VisibilityOff();
1391
1392   myScalarBarActor->VisibilityOff();
1393
1394   if(GetVisibility()){
1395     if(theIsUpdateRepersentation)
1396       SetRepresentation(GetRepresentation());
1397
1398     if(myControlMode != eNone){
1399       switch(myControlMode){
1400       case eFreeNodes:
1401       case eCoincidentNodes:
1402         myNodeExtActor->VisibilityOn();
1403         break;
1404       case eFreeEdges:
1405       case eFreeBorders:
1406       case eCoincidentElems1D:
1407         my1DExtActor->VisibilityOn();
1408         break;
1409       case eFreeFaces:
1410       case eBareBorderFace:
1411       case eOverConstrainedFace:
1412       case eCoincidentElems2D:
1413         my2DExtActor->VisibilityOn();
1414         break;
1415       case eBareBorderVolume:
1416       case eOverConstrainedVolume:
1417       case eCoincidentElems3D:
1418         my3DExtActor->VisibilityOn();
1419         break;
1420       case eLength2D:
1421       case eMultiConnection2D:
1422         my1DExtActor->VisibilityOn();
1423       default:
1424         if(myControlActor->GetUnstructuredGrid()->GetNumberOfCells())
1425           myScalarBarActor->VisibilityOn();
1426       }
1427     }
1428
1429     if(myRepresentation != ePoint)
1430       myPickableActor->VisibilityOn();
1431     else {
1432       myNodeActor->VisibilityOn();
1433     }
1434
1435     if(myEntityMode & e0DElements && GetRepresentation() != ePoint ){
1436       my0DActor->VisibilityOn();
1437     }
1438     if(myEntityMode & eBallElem && GetRepresentation() != ePoint ){
1439       myBallActor->VisibilityOn();
1440     }
1441
1442     if(myEntityMode & eEdges && GetRepresentation() != ePoint){
1443       my1DActor->VisibilityOn();
1444     }
1445
1446     if(myEntityMode & eFaces && GetRepresentation() != ePoint){
1447       my2DActor->VisibilityOn();
1448     }
1449
1450     if(myEntityMode & eVolumes && GetRepresentation() != ePoint){
1451       my3DActor->VisibilityOn();
1452     }
1453
1454     if(myNodeActor->GetPointsLabeled()){
1455       myNodeActor->VisibilityOn();
1456     }
1457
1458     if(my0DActor)
1459       my0DActor->UpdateLabels();
1460
1461     if(myBallActor)
1462       myBallActor->UpdateLabels();
1463
1464     if(my1DActor)
1465       my1DActor->UpdateLabels();
1466
1467     if(my2DActor)
1468       my2DActor->UpdateLabels();
1469
1470     if(my3DActor)
1471       my3DActor->UpdateLabels();
1472   }
1473 #ifndef DISABLE_PLOT2DVIEWER
1474   else
1475     SMESH::ProcessIn2DViewers(this,SMESH::RemoveFrom2dViewer);
1476 #endif
1477   UpdateHighlight();
1478   Modified();
1479 }
1480
1481
1482 void SMESH_ActorDef::SetEntityMode(unsigned int theMode)
1483 {
1484   myEntityState = eAllEntity;
1485
1486   if(!myVisualObj->GetNbEntities(SMDSAbs_0DElement)) {
1487     myEntityState &= ~e0DElements;
1488     theMode &= ~e0DElements;
1489   }
1490
1491   if(!myVisualObj->GetNbEntities(SMDSAbs_Ball)) {
1492     myEntityState &= ~eBallElem;
1493     theMode &= ~eBallElem;
1494   }
1495
1496   if(!myVisualObj->GetNbEntities(SMDSAbs_Edge)) {
1497     myEntityState &= ~eEdges;
1498     theMode &= ~eEdges;
1499   }
1500
1501   if(!myVisualObj->GetNbEntities(SMDSAbs_Face)) {
1502     myEntityState &= ~eFaces;
1503     theMode &= ~eFaces;
1504   }
1505
1506   if(!myVisualObj->GetNbEntities(SMDSAbs_Volume)) {
1507     myEntityState &= ~eVolumes;
1508     theMode &= ~eVolumes;
1509   }
1510
1511   if (!theMode) {
1512     if(myVisualObj->GetNbEntities(SMDSAbs_0DElement))
1513       theMode |= e0DElements;
1514
1515     if(myVisualObj->GetNbEntities(SMDSAbs_Ball))
1516       theMode |= eBallElem;
1517
1518     if(myVisualObj->GetNbEntities(SMDSAbs_Edge))
1519       theMode |= eEdges;
1520
1521     if(myVisualObj->GetNbEntities(SMDSAbs_Face))
1522       theMode |= eFaces;
1523
1524     if(myVisualObj->GetNbEntities(SMDSAbs_Volume))
1525       theMode |= eVolumes;
1526   }
1527
1528   myBaseActor->myGeomFilter->SetInside(myEntityMode != myEntityState);
1529
1530   myEntityMode = theMode;
1531   VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
1532   aFilter = myBaseActor->GetExtractUnstructuredGrid();
1533   aFilter->ClearRegisteredCellsWithType();
1534   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
1535
1536   VTKViewer_ExtractUnstructuredGrid* aHightFilter = myHighlitableActor->GetExtractUnstructuredGrid();
1537   aHightFilter->ClearRegisteredCellsWithType();
1538   aHightFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
1539
1540   if (myEntityMode & e0DElements) {
1541     if (MYDEBUG) MESSAGE("0D ELEMENTS");
1542     aFilter->RegisterCellsWithType(VTK_VERTEX);
1543     aHightFilter->RegisterCellsWithType(VTK_VERTEX);
1544   }
1545
1546   if (myEntityMode & eBallElem) {
1547     aFilter->RegisterCellsWithType(VTK_POLY_VERTEX);
1548   }
1549
1550   if (myEntityMode & eEdges) {
1551     if (MYDEBUG) MESSAGE("EDGES");
1552     aFilter->RegisterCellsWithType(VTK_LINE);
1553     aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
1554
1555     aHightFilter->RegisterCellsWithType(VTK_LINE);
1556     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
1557   }
1558
1559   if (myEntityMode & eFaces) {
1560     if (MYDEBUG) MESSAGE("FACES");
1561     aFilter->RegisterCellsWithType(VTK_TRIANGLE);
1562     aFilter->RegisterCellsWithType(VTK_POLYGON);
1563     aFilter->RegisterCellsWithType(VTK_QUAD);
1564     aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
1565     aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
1566     aFilter->RegisterCellsWithType(VTK_BIQUADRATIC_QUAD);
1567     aFilter->RegisterCellsWithType(VTK_BIQUADRATIC_TRIANGLE);
1568
1569     aHightFilter->RegisterCellsWithType(VTK_TRIANGLE);
1570     aHightFilter->RegisterCellsWithType(VTK_POLYGON);
1571     aHightFilter->RegisterCellsWithType(VTK_QUAD);
1572     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
1573     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
1574     aHightFilter->RegisterCellsWithType(VTK_BIQUADRATIC_QUAD);
1575     aHightFilter->RegisterCellsWithType(VTK_BIQUADRATIC_TRIANGLE);
1576   }
1577
1578   if (myEntityMode & eVolumes) {
1579     if (MYDEBUG) MESSAGE("VOLUMES");
1580     aFilter->RegisterCellsWithType(VTK_TETRA);
1581     aFilter->RegisterCellsWithType(VTK_VOXEL);
1582     aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1583     aFilter->RegisterCellsWithType(VTK_WEDGE);
1584     aFilter->RegisterCellsWithType(VTK_PYRAMID);
1585     aFilter->RegisterCellsWithType(VTK_HEXAGONAL_PRISM);
1586     aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
1587     aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
1588     aFilter->RegisterCellsWithType(VTK_TRIQUADRATIC_HEXAHEDRON);
1589     aFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
1590     aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1591 //#ifdef VTK_HAVE_POLYHEDRON
1592     aFilter->RegisterCellsWithType(VTK_POLYHEDRON);
1593 //#endif
1594
1595     aHightFilter->RegisterCellsWithType(VTK_TETRA);
1596     aHightFilter->RegisterCellsWithType(VTK_VOXEL);
1597     aHightFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1598     aHightFilter->RegisterCellsWithType(VTK_WEDGE);
1599     aHightFilter->RegisterCellsWithType(VTK_PYRAMID);
1600     aHightFilter->RegisterCellsWithType(VTK_HEXAGONAL_PRISM);
1601     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
1602     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
1603     aHightFilter->RegisterCellsWithType(VTK_TRIQUADRATIC_HEXAHEDRON);
1604     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
1605     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_PYRAMID);
1606     aHightFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1607 //#ifdef VTK_HAVE_POLYHEDRON
1608     aHightFilter->RegisterCellsWithType(VTK_POLYHEDRON);
1609 //#endif
1610   }
1611   aFilter->Update();
1612   if (MYDEBUG) MESSAGE(aFilter->GetOutput()->GetNumberOfCells());
1613   SetVisibility(GetVisibility(),false);
1614 }
1615
1616 void SMESH_ActorDef::SetRepresentation (int theMode)
1617 {
1618   int aNbEdges = myVisualObj->GetNbEntities(SMDSAbs_Edge);
1619   int aNbFaces = myVisualObj->GetNbEntities(SMDSAbs_Face);
1620   int aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume);
1621   int aNb0Ds       = myVisualObj->GetNbEntities(SMDSAbs_0DElement);
1622   int aNbBalls       = myVisualObj->GetNbEntities(SMDSAbs_Ball);
1623
1624   if (theMode < 0) {
1625     myRepresentation = eSurface;
1626     if (!aNbFaces && !aNbVolumes && !aNbBalls && aNbEdges) {
1627       myRepresentation = eEdge;
1628     } else if (!aNbFaces && !aNbVolumes && !aNbEdges && !aNbBalls) {
1629       myRepresentation = ePoint;
1630     }
1631   } else {
1632     switch (theMode) {
1633     case eEdge:
1634       if (!aNbFaces && !aNbVolumes && !aNbEdges && !aNb0Ds && !aNbBalls) return;
1635       break;
1636     case eSurface:
1637       if (!aNbFaces && !aNbVolumes && !aNb0Ds && !aNbBalls) return;
1638       break;
1639     }
1640     myRepresentation = theMode;
1641   }
1642
1643   if (!GetUnstructuredGrid()->GetNumberOfCells())
1644     myRepresentation = ePoint;
1645
1646   if (myIsShrunk) {
1647     if (myRepresentation == ePoint) {
1648       UnShrink();
1649       myIsShrunk = true;
1650     } else {
1651       SetShrink();
1652     }
1653   }
1654
1655   myPickableActor = myBaseActor;
1656   myNodeActor->SetVisibility(false);
1657   myNodeExtActor->SetVisibility(false);
1658   vtkProperty *aProp = NULL, *aBackProp = NULL;
1659   vtkProperty *aPropVN = NULL, *aPropVR = NULL;
1660   SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::EReperesent(-1);
1661   SMESH_Actor::EQuadratic2DRepresentation aQuadraticMode = GetQuadratic2DRepresentation();
1662   switch (myRepresentation) {
1663   case ePoint:
1664     myPickableActor = myNodeActor;
1665     myNodeActor->SetVisibility(true);
1666     aQuadraticMode = SMESH_Actor::eLines;
1667     aProp = aBackProp = aPropVN = aPropVR = myNodeProp;
1668     aReperesent = SMESH_DeviceActor::ePoint;
1669     break;
1670   case eEdge:
1671     aProp = aBackProp = aPropVN = aPropVR = myEdgeProp;
1672     aReperesent = SMESH_DeviceActor::eInsideframe;
1673     break;
1674   case eSurface:
1675     aProp = mySurfaceProp;
1676     aBackProp = myBackSurfaceProp;
1677     aPropVN = myNormalVProp;
1678     aPropVR = myReversedVProp;
1679     aReperesent = SMESH_DeviceActor::eSurface;
1680     break;
1681   }
1682
1683   my2DActor->SetProperty(aProp);
1684   my2DActor->SetBackfaceProperty(aBackProp);
1685   my2DActor->SetRepresentation(aReperesent);
1686
1687   if(aQuadraticMode == SMESH_Actor::eLines)
1688     my2DActor->SetQuadraticArcMode(false);
1689   else if(aQuadraticMode == SMESH_Actor::eArcs)
1690     my2DActor->SetQuadraticArcMode(true);
1691
1692   my2DExtActor->SetRepresentation(aReperesent);
1693
1694   my3DActor->SetProperty(aPropVN);
1695   my3DActor->SetBackfaceProperty(aPropVR);
1696   my3DActor->SetRepresentation(aReperesent);
1697
1698
1699   my1DExtActor->SetVisibility(false);
1700   my2DExtActor->SetVisibility(false);
1701   my3DExtActor->SetVisibility(false);
1702
1703   my0DActor->SetRepresentation(aReperesent);
1704   myBallActor->SetRepresentation(aReperesent);
1705
1706   switch(myControlMode){
1707   case eLength:
1708   case eMultiConnection:
1709     aProp = aBackProp = my1DProp;
1710     if(myRepresentation != ePoint)
1711       aReperesent = SMESH_DeviceActor::eInsideframe;
1712     break;
1713   }
1714
1715   if(aQuadraticMode == SMESH_Actor::eLines)
1716     my1DActor->SetQuadraticArcMode(false);
1717   else if(aQuadraticMode == SMESH_Actor::eArcs)
1718     my1DActor->SetQuadraticArcMode(true);
1719
1720   my1DActor->SetProperty(aProp);
1721   my1DActor->SetBackfaceProperty(aBackProp);
1722   my1DActor->SetRepresentation(aReperesent);
1723
1724   my1DExtActor->SetRepresentation(aReperesent);
1725
1726   if(myIsPointsVisible)
1727     myPickableActor = myNodeActor;
1728   if(GetPointRepresentation())
1729     myNodeActor->SetVisibility(true);
1730
1731   SetMapper(myPickableActor->GetMapper());
1732
1733   SetVisibility(GetVisibility(),false);
1734
1735   Modified();
1736 }
1737
1738
1739 void SMESH_ActorDef::SetPointRepresentation(bool theIsPointsVisible){
1740   if ( myIsPointsVisible == theIsPointsVisible )
1741     return;
1742   myIsPointsVisible = theIsPointsVisible;
1743   SetRepresentation(GetRepresentation());
1744 }
1745
1746 bool SMESH_ActorDef::GetPointRepresentation(){
1747   return myIsPointsVisible || myNodeActor->GetPointsLabeled();
1748 }
1749
1750
1751 void SMESH_ActorDef::UpdateHighlight(){
1752   myHighlitableActor->SetHighlited(false);
1753   myHighlitableActor->SetVisibility(false);
1754   bool anIsVisible = GetVisibility();
1755
1756   switch(myRepresentation){
1757   case SMESH_DeviceActor::eSurface:
1758   case SMESH_DeviceActor::eWireframe:
1759     {
1760       if(myIsHighlighted) {
1761         myHighlitableActor->SetProperty(myHighlightProp);
1762       }else if(myIsPreselected){
1763         myHighlitableActor->SetProperty(myPreselectProp);
1764       } else if(anIsVisible){
1765         (myRepresentation == eSurface) ?
1766           myHighlitableActor->SetProperty(myOutLineProp) : myHighlitableActor->SetProperty(myEdgeProp);
1767       }
1768       if(GetUnstructuredGrid()->GetNumberOfCells()) {
1769         myHighlitableActor->SetHighlited(anIsVisible);
1770         myHighlitableActor->GetExtractUnstructuredGrid()->
1771           SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::eCells);
1772         myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
1773       }
1774       myHighlitableActor->SetVisibility(anIsVisible);
1775       break;
1776     }
1777   case SMESH_DeviceActor::ePoint:
1778     {
1779       if(myIsHighlighted) {
1780         myNodeActor->SetProperty(myHighlightProp);
1781       }else if(myIsPreselected) {
1782         myNodeActor->SetProperty(myPreselectProp);
1783       } else if(anIsVisible) {
1784         myNodeActor->SetProperty(myNodeProp);
1785       }
1786       myNodeActor->SetRepresentation(SMESH_DeviceActor::ePoint);
1787       myNodeActor->GetExtractUnstructuredGrid()->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
1788       break;
1789     }
1790   }
1791 }
1792
1793
1794 void SMESH_ActorDef::highlight(bool theHighlight){
1795   if ( myIsHighlighted == theHighlight )
1796     return;
1797   myIsHighlighted = theHighlight;
1798   UpdateHighlight();
1799 }
1800
1801
1802 void SMESH_ActorDef::SetPreSelected(bool thePreselect){
1803   if ( myIsPreselected == thePreselect )
1804     return;
1805   myIsPreselected = thePreselect;
1806   UpdateHighlight();
1807 }
1808
1809
1810 // From vtkFollower
1811 int SMESH_ActorDef::RenderOpaqueGeometry(vtkViewport *vp)
1812 {
1813   if (myPickableActor->GetIsOpaque())
1814     {
1815     vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1816     this->Render(ren);
1817     return 1;
1818     }
1819   return 0;
1820 }
1821
1822
1823 int SMESH_ActorDef::RenderTranslucentGeometry(vtkViewport *vp)
1824 {
1825   if (!myPickableActor->GetIsOpaque())
1826     {
1827     vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1828     this->Render(ren);
1829     return 1;
1830     }
1831   return 0;
1832 }
1833
1834
1835 void SMESH_ActorDef::Render(vtkRenderer *ren){
1836   unsigned long aTime = myTimeStamp->GetMTime();
1837   unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1838   unsigned long aClippingTime = myImplicitBoolean->GetMTime();
1839   if(anObjTime > aTime || aClippingTime > aTime)
1840     Update();
1841 }
1842
1843
1844 void SMESH_ActorDef::Update(){
1845   if(MYDEBUG) MESSAGE("SMESH_ActorDef::Update");
1846
1847   if(GetControlMode() != eNone) {
1848     unsigned long aTime = myTimeStamp->GetMTime();
1849     unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1850     if (anObjTime > aTime)
1851       SetControlMode(GetControlMode(),false);
1852   }
1853
1854   if(myNodeActor)
1855     myNodeActor->UpdateLabels();
1856
1857   if(my0DActor)
1858     my0DActor->UpdateLabels();
1859
1860   if(myBallActor)
1861     myBallActor->UpdateLabels();
1862
1863   if(my1DActor)
1864     my1DActor->UpdateLabels();
1865
1866   if(my2DActor)
1867     my2DActor->UpdateLabels();
1868
1869   if(my3DActor)
1870     my3DActor->UpdateLabels();
1871
1872   if(myIsFacesOriented){
1873     SetFacesOriented(myIsFacesOriented);
1874   }
1875
1876   if(myVisualObj->GetEntitiesFlag()) {
1877     myEntityMode |= myVisualObj->GetEntitiesState();
1878   }
1879
1880   SetEntityMode(GetEntityMode());
1881   SetVisibility(GetVisibility());
1882
1883   myTimeStamp->Modified();
1884   Modified();
1885 }
1886
1887
1888 void SMESH_ActorDef::ReleaseGraphicsResources(vtkWindow *renWin){
1889   SALOME_Actor::ReleaseGraphicsResources(renWin);
1890
1891   myPickableActor->ReleaseGraphicsResources(renWin);
1892 }
1893
1894
1895 static void GetColor(vtkProperty *theProperty, double& r,double& g,double& b){
1896   double* aColor = theProperty->GetColor();
1897   r = aColor[0];
1898   g = aColor[1];
1899   b = aColor[2];
1900 }
1901
1902
1903 void SMESH_ActorDef::SetOpacity(double theValue){
1904   mySurfaceProp->SetOpacity(theValue);
1905   myBackSurfaceProp->SetOpacity(theValue);
1906   myNormalVProp->SetOpacity(theValue);
1907   myReversedVProp->SetOpacity(theValue);
1908   myEdgeProp->SetOpacity(theValue);
1909   myOutLineProp->SetOpacity(theValue);
1910   myNodeProp->SetOpacity(theValue);
1911
1912   my1DProp->SetOpacity(theValue);
1913   my0DProp->SetOpacity(theValue);
1914   myBallProp->SetOpacity(theValue);
1915 }
1916
1917
1918 double SMESH_ActorDef::GetOpacity(){
1919   return mySurfaceProp->GetOpacity();
1920 }
1921
1922
1923 void SMESH_ActorDef::SetSufaceColor(double r,double g,double b, int delta){
1924   mySurfaceProp->SetColor(r,g,b);
1925   my2DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1926   if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
1927     if( aGroupObj->GetElementType() == SMDSAbs_Face )
1928       myNameActor->SetBackgroundColor(r,g,b);
1929
1930   myDeltaBrightness = delta;
1931   QColor bfc = Qtx::mainColorToSecondary(QColor(int(r*255),int(g*255),int(b*255)), delta);
1932   myBackSurfaceProp->SetColor( bfc.red() / 255. , bfc.green() / 255. , bfc.blue() / 255. );
1933   Modified();
1934 }
1935
1936 void SMESH_ActorDef::GetSufaceColor(double& r,double& g,double& b, int& delta){
1937   ::GetColor(mySurfaceProp,r,g,b);
1938   delta = myDeltaBrightness;
1939 }
1940
1941 void SMESH_ActorDef::SetVolumeColor(double r,double g,double b, int delta){
1942   myNormalVProp->SetColor(r,g,b);
1943   my3DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1944   if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
1945     if( aGroupObj->GetElementType() == SMDSAbs_Volume )
1946       myNameActor->SetBackgroundColor(r,g,b);
1947
1948   myDeltaVBrightness = delta;
1949   QColor bfc = Qtx::mainColorToSecondary(QColor(int(r*255),int(g*255),int(b*255)), delta);
1950   myReversedVProp->SetColor( bfc.red() / 255. , bfc.green() / 255. , bfc.blue() / 255. );
1951   Modified();
1952 }
1953
1954 void SMESH_ActorDef::GetVolumeColor(double& r,double& g,double& b, int& delta){
1955   ::GetColor(myNormalVProp,r,g,b);
1956   delta = myDeltaVBrightness;
1957 }
1958
1959 void SMESH_ActorDef::SetEdgeColor(double r,double g,double b){
1960   myEdgeProp->SetColor(r,g,b);
1961   my1DProp->SetColor(r,g,b);
1962   my1DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1963   if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
1964     if( aGroupObj->GetElementType() == SMDSAbs_Edge )
1965       myNameActor->SetBackgroundColor(r,g,b);
1966   Modified();
1967 }
1968
1969 void SMESH_ActorDef::GetEdgeColor(double& r,double& g,double& b){
1970   ::GetColor(myEdgeProp,r,g,b);
1971 }
1972
1973 void SMESH_ActorDef::SetOutlineColor(double r,double g,double b){
1974   myOutLineProp->SetColor(r,g,b);
1975   Modified();
1976 }
1977
1978 void SMESH_ActorDef::GetOutlineColor(double& r,double& g,double& b){
1979   ::GetColor(myOutLineProp,r,g,b);
1980 }
1981
1982
1983 void SMESH_ActorDef::SetNodeColor(double r,double g,double b){ 
1984   myNodeProp->SetColor(r,g,b);
1985   myNodeExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1986   if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
1987     if( aGroupObj->GetElementType() == SMDSAbs_Node )
1988       myNameActor->SetBackgroundColor(r,g,b);
1989   Modified();
1990 }
1991
1992 void SMESH_ActorDef::GetNodeColor(double& r,double& g,double& b){ 
1993   ::GetColor(myNodeProp,r,g,b);
1994 }
1995
1996 void SMESH_ActorDef::Set0DColor(double r,double g,double b){ 
1997   my0DProp->SetColor(r,g,b);
1998   if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
1999     if( aGroupObj->GetElementType() == SMDSAbs_0DElement )
2000       myNameActor->SetBackgroundColor(r,g,b);
2001   Modified();
2002 }
2003
2004 void SMESH_ActorDef::Get0DColor(double& r,double& g,double& b){ 
2005   ::GetColor(my0DProp,r,g,b);
2006 }
2007
2008 void SMESH_ActorDef::SetBallColor(double r,double g,double b){ 
2009   myBallProp->SetColor(r,g,b);
2010   if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
2011     if( aGroupObj->GetElementType() == SMDSAbs_Ball )
2012       myNameActor->SetBackgroundColor(r,g,b);
2013   Modified();
2014 }
2015
2016 void SMESH_ActorDef::GetBallColor(double& r,double& g,double& b){ 
2017   ::GetColor(myBallProp,r,g,b);
2018 }
2019
2020 void SMESH_ActorDef::SetHighlightColor(double r,double g,double b){ 
2021   myHighlightProp->SetColor(r,g,b);
2022   Modified();
2023 }
2024
2025 void SMESH_ActorDef::GetHighlightColor(double& r,double& g,double& b){ 
2026   ::GetColor(myHighlightProp,r,g,b);
2027 }
2028
2029 void SMESH_ActorDef::SetPreHighlightColor(double r,double g,double b){ 
2030   myPreselectProp->SetColor(r,g,b);
2031   Modified();
2032 }
2033
2034 void SMESH_ActorDef::GetPreHighlightColor(double& r,double& g,double& b){ 
2035   ::GetColor(myPreselectProp,r,g,b);
2036 }
2037
2038
2039 double SMESH_ActorDef::GetLineWidth(){
2040   return myEdgeProp->GetLineWidth();
2041 }
2042
2043
2044 void SMESH_ActorDef::SetLineWidth(double theVal){
2045   myEdgeProp->SetLineWidth(theVal);
2046
2047   my1DProp->SetLineWidth(theVal + aLineWidthInc);
2048   my1DExtProp->SetLineWidth(theVal + aLineWidthInc);
2049   my2DExtProp->SetLineWidth(theVal + aLineWidthInc);
2050   my3DExtProp->SetLineWidth(theVal + aLineWidthInc);
2051   myOutLineProp->SetLineWidth(theVal);
2052   myHighlightProp->SetLineWidth(theVal);
2053   myPreselectProp->SetLineWidth(theVal);
2054   Modified();
2055 }
2056
2057 double SMESH_ActorDef::GetOutlineWidth()
2058 {
2059   return myOutLineProp->GetLineWidth();
2060 }
2061
2062 void SMESH_ActorDef::SetOutlineWidth(double theVal)
2063 {
2064   myOutLineProp->SetLineWidth(theVal);
2065   Modified();
2066 }
2067
2068 void SMESH_ActorDef::Set0DSize(double theVal){
2069   my0DProp->SetPointSize(theVal);
2070   myHighlightProp->SetPointSize(theVal);
2071   myPreselectProp->SetPointSize(theVal);
2072
2073   if(SMESH_SVTKActor* aCustom = SMESH_SVTKActor::SafeDownCast( myHighlightActor )) {
2074     aCustom->Set0DSize(theVal);
2075   }
2076   if(SMESH_SVTKActor* aCustom = SMESH_SVTKActor::SafeDownCast( myPreHighlightActor )) {
2077     aCustom->Set0DSize(theVal);
2078   }
2079
2080   Modified();
2081 }
2082
2083 double SMESH_ActorDef::Get0DSize(){
2084   return my0DProp->GetPointSize();
2085 }
2086
2087 void SMESH_ActorDef::SetBallSize(double theVal){
2088   myBallProp->SetPointSize(theVal);
2089
2090   if(SMESH_SVTKActor* aCustom = SMESH_SVTKActor::SafeDownCast( myHighlightActor )) {
2091     aCustom->SetBallSize(theVal);
2092   }
2093   if(SMESH_SVTKActor* aCustom = SMESH_SVTKActor::SafeDownCast( myPreHighlightActor )) {
2094     aCustom->SetBallSize(theVal);
2095   }
2096
2097   Modified();
2098 }
2099
2100 double SMESH_ActorDef::GetBallSize(){
2101   return myBallProp->GetPointSize();
2102 }
2103
2104 int SMESH_ActorDef::GetObjDimension( const int theObjId )
2105 {
2106   return myVisualObj->GetElemDimension( theObjId );
2107 }
2108
2109 bool
2110 SMESH_ActorDef::
2111 IsImplicitFunctionUsed() const
2112 {
2113   return myBaseActor->IsImplicitFunctionUsed();
2114 }
2115
2116 void
2117 SMESH_ActorDef::SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed)
2118 {
2119   myNodeActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
2120   myBaseActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
2121
2122   myHighlitableActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
2123
2124   myNodeExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
2125
2126   my0DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
2127   myBallActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
2128   //my0DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
2129
2130   my1DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
2131   my1DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
2132
2133   my2DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
2134   my2DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
2135   my3DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
2136   my3DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
2137 }
2138
2139 vtkIdType
2140 SMESH_ActorDef::AddClippingPlane(vtkPlane* thePlane)
2141 {
2142   if(thePlane){
2143     myImplicitBoolean->GetFunction()->AddItem(thePlane);
2144     myCippingPlaneCont.push_back(thePlane);
2145     if(!IsImplicitFunctionUsed())
2146       SetImplicitFunctionUsed(true);
2147     myNodeActor->UpdateLabels();
2148   }
2149   return myCippingPlaneCont.size();
2150 }
2151
2152 void
2153 SMESH_ActorDef::
2154 RemoveAllClippingPlanes()
2155 {
2156   myImplicitBoolean->GetFunction()->RemoveAllItems();
2157   myImplicitBoolean->GetFunction()->Modified(); // VTK bug
2158   myCippingPlaneCont.clear();
2159   SetImplicitFunctionUsed(false);
2160   myNodeActor->UpdateLabels();
2161 }
2162
2163 vtkIdType
2164 SMESH_ActorDef::
2165 GetNumberOfClippingPlanes()
2166 {
2167   return myCippingPlaneCont.size();
2168 }
2169
2170 vtkPlane*
2171 SMESH_ActorDef::
2172 GetClippingPlane(vtkIdType theID)
2173 {
2174   if(theID >= myCippingPlaneCont.size())
2175     return NULL;
2176   return myCippingPlaneCont[theID].Get();
2177 }
2178
2179 void SMESH_ActorDef::UpdateScalarBar()
2180 {
2181   SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
2182   if( !mgr )
2183     return;
2184
2185   vtkTextProperty* aScalarBarTitleProp = vtkTextProperty::New();
2186
2187   QColor aTColor = mgr->colorValue( "SMESH", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
2188   aScalarBarTitleProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
2189
2190   aScalarBarTitleProp->SetFontFamilyToArial();
2191
2192   if ( mgr->hasValue( "SMESH", "scalar_bar_title_font" ) )
2193   {
2194     QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
2195     if ( f.family() == "Arial" )
2196       aScalarBarTitleProp->SetFontFamilyToArial();
2197     else if ( f.family() == "Courier" )
2198       aScalarBarTitleProp->SetFontFamilyToCourier();
2199     else if ( f.family() == "Times" )
2200       aScalarBarTitleProp->SetFontFamilyToTimes();
2201
2202     if ( f.bold() )
2203       aScalarBarTitleProp->BoldOn();
2204     else
2205       aScalarBarTitleProp->BoldOff();
2206
2207     if ( f.italic() )
2208       aScalarBarTitleProp->ItalicOn();
2209     else
2210      aScalarBarTitleProp->ItalicOff();
2211
2212     if ( f.overline() )
2213       aScalarBarTitleProp->ShadowOn();
2214     else
2215       aScalarBarTitleProp->ShadowOff();
2216   }
2217
2218   myScalarBarActor->SetTitleTextProperty( aScalarBarTitleProp );
2219   aScalarBarTitleProp->Delete();
2220
2221   vtkTextProperty* aScalarBarLabelProp = vtkTextProperty::New();
2222
2223   aTColor = mgr->colorValue( "SMESH", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
2224   aScalarBarLabelProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
2225
2226   aScalarBarLabelProp->SetFontFamilyToArial();
2227   if( mgr->hasValue( "SMESH", "scalar_bar_label_font" ) )
2228   {
2229     QFont f = mgr->fontValue( "SMESH", "scalar_bar_label_font" );
2230     if( f.family() == "Arial" )
2231       aScalarBarLabelProp->SetFontFamilyToArial();
2232     else if( f.family() == "Courier" )
2233       aScalarBarLabelProp->SetFontFamilyToCourier();
2234     else if( f.family() == "Times" )
2235       aScalarBarLabelProp->SetFontFamilyToTimes();
2236
2237     if ( f.bold() )
2238       aScalarBarLabelProp->BoldOn();
2239     else
2240       aScalarBarLabelProp->BoldOff();
2241
2242     if ( f.italic() )
2243       aScalarBarLabelProp->ItalicOn();
2244     else
2245       aScalarBarLabelProp->ItalicOff();
2246
2247     if( f.overline() )
2248       aScalarBarLabelProp->ShadowOn();
2249     else
2250       aScalarBarLabelProp->ShadowOff();
2251   }
2252
2253   myScalarBarActor->SetLabelTextProperty( aScalarBarLabelProp );
2254   aScalarBarLabelProp->Delete();
2255
2256   bool horiz = ( mgr->integerValue( "SMESH", "scalar_bar_orientation" ) == 1 );
2257   QString name = QString( "scalar_bar_%1_" ).arg( horiz ? "horizontal" : "vertical" );
2258   if( horiz )
2259     myScalarBarActor->SetOrientationToHorizontal();
2260   else
2261     myScalarBarActor->SetOrientationToVertical();
2262
2263
2264   double aXVal = horiz ? 0.20 : 0.01;
2265   if( mgr->hasValue( "SMESH", name + "x" ) )
2266     aXVal = mgr->doubleValue( "SMESH", name + "x", aXVal );
2267
2268   double aYVal = horiz ? 0.01 : 0.1;
2269   if( mgr->hasValue( "SMESH", name + "y" ) )
2270     aYVal = mgr->doubleValue( "SMESH", name + "y", aYVal );
2271   myScalarBarActor->SetPosition( aXVal, aYVal );
2272
2273   double aWVal = horiz ? 0.60 : 0.10;
2274   if( mgr->hasValue( "SMESH", name + "width" ) )
2275     aWVal = mgr->doubleValue( "SMESH", name + "width", aWVal );
2276   myScalarBarActor->SetWidth( aWVal );
2277
2278   double aHVal = horiz ? 0.12 : 0.80;
2279   if( mgr->hasValue( "SMESH", name + "height" ) )
2280     aHVal = mgr->doubleValue( "SMESH", name + "height", aHVal );
2281   myScalarBarActor->SetHeight( aHVal );
2282
2283   int anIntVal = 5;
2284   if( mgr->hasValue( "SMESH", "scalar_bar_num_labels" ) )
2285     anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_labels", anIntVal );
2286   myScalarBarActor->SetNumberOfLabels( anIntVal == 0 ? 5: anIntVal );
2287
2288   anIntVal = 64;
2289   if( mgr->hasValue( "SMESH", "scalar_bar_num_colors" ) )
2290     anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_colors", anIntVal );
2291   myScalarBarActor->SetMaximumNumberOfColors( anIntVal == 0 ? 64 : anIntVal );
2292
2293   bool distributionVisibility = mgr->booleanValue("SMESH","distribution_visibility");
2294   myScalarBarActor->SetDistributionVisibility(distributionVisibility);
2295
2296   int coloringType = mgr->integerValue("SMESH", "distribution_coloring_type", 0);
2297   myScalarBarActor->SetDistributionColoringType(coloringType);
2298
2299   QColor distributionColor = mgr->colorValue("SMESH", "distribution_color",
2300                                              QColor(255, 255, 255));
2301   double rgb[3];
2302   rgb[0]= distributionColor.red()/255.;
2303   rgb[1]= distributionColor.green()/255.;
2304   rgb[2]= distributionColor.blue()/255.;
2305   myScalarBarActor->SetDistributionColor(rgb);
2306
2307
2308 }
2309
2310 void SMESH_ActorDef::UpdateDistribution()
2311 {
2312   if(SMESH::Controls::NumericalFunctor* fun =
2313      dynamic_cast<SMESH::Controls::NumericalFunctor*>(myFunctor.get()))
2314   {
2315     int nbIntervals = myScalarBarActor->GetMaximumNumberOfColors();
2316     std::vector<int> nbEvents;
2317     std::vector<double> funValues;
2318     SMESH_VisualObjDef::TEntityList elems;
2319     if ( ! dynamic_cast<SMESH_MeshObj*>(myVisualObj.get()))
2320       dynamic_cast<SMESH_VisualObjDef*>(myVisualObj.get())->GetEntities( fun->GetType(), elems );
2321     std::vector<int> elemIds;
2322     for ( SMESH_VisualObjDef::TEntityList::iterator e = elems.begin(); e != elems.end(); ++e)
2323       elemIds.push_back( (*e)->GetID());
2324     vtkLookupTable* lookupTable = static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
2325     double * range = lookupTable->GetRange();
2326     bool isLogarithmic = lookupTable->GetScale() == VTK_SCALE_LOG10;
2327     fun->GetHistogram(nbIntervals, nbEvents, funValues, elemIds, range, isLogarithmic);
2328     myScalarBarActor->SetDistribution(nbEvents);
2329   }
2330 }
2331
2332 void SMESH_ActorDef::SetQuadratic2DRepresentation(EQuadratic2DRepresentation theMode)
2333 {
2334   switch(theMode) {
2335   case SMESH_Actor::eLines :
2336     myHighlitableActor->SetQuadraticArcMode(false);
2337     my2DActor->SetQuadraticArcMode(false);
2338     my1DActor->SetQuadraticArcMode(false);
2339     break;
2340   case SMESH_Actor::eArcs :
2341     myHighlitableActor->SetQuadraticArcMode(true);
2342     if(GetRepresentation() != SMESH_Actor::ePoint) {
2343       my2DActor->SetQuadraticArcMode(true);
2344       my1DActor->SetQuadraticArcMode(true);
2345     }
2346     break;
2347   default:
2348     break;
2349   }
2350 }
2351
2352
2353 SMESH_Actor::EQuadratic2DRepresentation SMESH_ActorDef::GetQuadratic2DRepresentation()
2354 {
2355   if(myHighlitableActor->GetQuadraticArcMode())
2356     return SMESH_Actor::eArcs;
2357   else
2358     return SMESH_Actor::eLines;
2359 }
2360
2361 void SMESH_ActorDef::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale )
2362 {
2363   SALOME_Actor::SetMarkerStd( theMarkerType, theMarkerScale );
2364   myNodeActor->SetMarkerStd( theMarkerType, theMarkerScale );
2365   myNodeExtActor->SetMarkerStd( theMarkerType, theMarkerScale );
2366 }
2367
2368 void SMESH_ActorDef::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
2369 {
2370   SALOME_Actor::SetMarkerTexture( theMarkerId, theMarkerTexture );
2371   myNodeActor->SetMarkerTexture( theMarkerId, theMarkerTexture );
2372   myNodeExtActor->SetMarkerTexture( theMarkerId, theMarkerTexture );
2373   myMarkerTexture = theMarkerTexture; // for deferred update of myHighlightActor
2374 }
2375
2376 #ifndef DISABLE_PLOT2DVIEWER
2377 SPlot2d_Histogram* SMESH_ActorDef::UpdatePlot2Histogram() {
2378
2379   if(my2dHistogram)
2380     my2dHistogram->clearAllPoints();
2381
2382   if(SMESH::Controls::NumericalFunctor* fun =
2383      dynamic_cast<SMESH::Controls::NumericalFunctor*>(myFunctor.get()))
2384   {
2385
2386     if(!my2dHistogram) {
2387       my2dHistogram = new SPlot2d_Histogram();
2388       Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(getIO()->getEntry(),"SMESH",getName());
2389       my2dHistogram->setIO(anIO);
2390     }
2391
2392     int nbIntervals = myScalarBarActor->GetMaximumNumberOfColors();
2393     std::vector<int> nbEvents;
2394     std::vector<double> funValues;
2395     SMESH_VisualObjDef::TEntityList elems;
2396     if ( ! dynamic_cast<SMESH_MeshObj*>(myVisualObj.get()))
2397       dynamic_cast<SMESH_VisualObjDef*>(myVisualObj.get())->GetEntities( fun->GetType(), elems );
2398     std::vector<int> elemIds;
2399
2400     for ( SMESH_VisualObjDef::TEntityList::iterator e = elems.begin(); e != elems.end(); ++e)
2401       elemIds.push_back( (*e)->GetID());
2402
2403     vtkLookupTable* lookupTable = static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
2404     double * range = lookupTable->GetRange();
2405     bool isLogarithmic = lookupTable->GetScale() == VTK_SCALE_LOG10;
2406     fun->GetHistogram(nbIntervals, nbEvents, funValues, elemIds, range, isLogarithmic);
2407
2408     for ( int i = 0; i < std::min( nbEvents.size(), funValues.size() -1 ); i++ )
2409       my2dHistogram->addPoint(funValues[i] + (funValues[i+1] - funValues[i])/2.0, static_cast<double>(nbEvents[i]));
2410
2411     if(funValues.size() >= 2)
2412       my2dHistogram->setWidth((funValues[1] - funValues[0]) * 0.8) ;
2413
2414   }
2415
2416   //Color of the histogram
2417   if(myScalarBarActor->GetDistributionColoringType() == SMESH_MULTICOLOR_TYPE)
2418     my2dHistogram->setAutoAssign(true);
2419   else {
2420     double rgb[3];
2421     myScalarBarActor->GetDistributionColor(rgb);
2422     QColor aColor = QColor( (int)( rgb[0]*255 ), (int)( rgb[1]*255 ), (int)( rgb[2]*255 ) );
2423     my2dHistogram->setColor(aColor);
2424
2425   }
2426
2427   return my2dHistogram;
2428 }
2429 #endif