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