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