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