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