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