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