]> SALOME platform Git repositories - modules/smesh.git/blob - src/OBJECT/SMESH_Actor.cxx
Salome HOME
0021562: EDF SMESH: clipping and delete mesh clipped leads to crash
[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       case eLength2D:
1248       case eMultiConnection2D:
1249         my1DExtActor->VisibilityOn();
1250         break;
1251       case eFreeFaces:
1252       case eBareBorderFace:
1253       case eOverConstrainedFace:
1254       case eCoincidentElems2D:
1255         my2DExtActor->VisibilityOn();
1256         break;
1257       case eBareBorderVolume:
1258       case eOverConstrainedVolume:
1259       case eCoincidentElems3D:
1260         my3DExtActor->VisibilityOn();
1261         break;
1262       default:
1263         if(myControlActor->GetUnstructuredGrid()->GetNumberOfCells())
1264           myScalarBarActor->VisibilityOn();
1265       }
1266     }
1267
1268     if(myRepresentation != ePoint)
1269       myPickableActor->VisibilityOn();
1270     else {
1271       myNodeActor->VisibilityOn();
1272     }
1273
1274     if(myEntityMode & e0DElements){
1275       my0DActor->VisibilityOn();
1276     }
1277
1278     if(myEntityMode & eEdges && GetRepresentation() != ePoint){
1279       my1DActor->VisibilityOn();
1280     }
1281     
1282     if(myEntityMode & eFaces && GetRepresentation() != ePoint){
1283       my2DActor->VisibilityOn();
1284     }
1285     
1286     if(myEntityMode & eVolumes && GetRepresentation() != ePoint){
1287       my3DActor->VisibilityOn();
1288     }
1289     
1290     if(myNodeActor->GetPointsLabeled()){ 
1291       myNodeActor->VisibilityOn();
1292     }
1293
1294     if(my0DActor)
1295       my0DActor->UpdateLabels();
1296     
1297     if(my1DActor)
1298       my1DActor->UpdateLabels();
1299     
1300     if(my2DActor)
1301       my2DActor->UpdateLabels();
1302     
1303     if(my3DActor)
1304       my3DActor->UpdateLabels();    
1305   } 
1306 #ifndef DISABLE_PLOT2DVIEWER
1307   else
1308     SMESH::ProcessIn2DViewers(this,SMESH::RemoveFrom2dViewer);
1309 #endif
1310   UpdateHighlight();
1311   Modified();
1312 }
1313
1314
1315 void SMESH_ActorDef::SetEntityMode(unsigned int theMode)
1316 {
1317   myEntityState = eAllEntity;
1318
1319   if(!myVisualObj->GetNbEntities(SMDSAbs_0DElement)) {
1320     myEntityState &= ~e0DElements;
1321     theMode &= ~e0DElements;
1322   }
1323
1324   if(!myVisualObj->GetNbEntities(SMDSAbs_Edge)) {
1325     myEntityState &= ~eEdges;
1326     theMode &= ~eEdges;
1327   }
1328
1329   if(!myVisualObj->GetNbEntities(SMDSAbs_Face)) {
1330     myEntityState &= ~eFaces;
1331     theMode &= ~eFaces;
1332   }
1333
1334   if(!myVisualObj->GetNbEntities(SMDSAbs_Volume)) {
1335     myEntityState &= ~eVolumes;
1336     theMode &= ~eVolumes;
1337   }
1338
1339   if (!theMode) {
1340     if(myVisualObj->GetNbEntities(SMDSAbs_0DElement))
1341       theMode |= e0DElements;
1342
1343     if(myVisualObj->GetNbEntities(SMDSAbs_Edge))
1344       theMode |= eEdges;
1345
1346     if(myVisualObj->GetNbEntities(SMDSAbs_Face))
1347       theMode |= eFaces;
1348
1349     if(myVisualObj->GetNbEntities(SMDSAbs_Volume))
1350       theMode |= eVolumes;
1351   }
1352
1353   myBaseActor->myGeomFilter->SetInside(myEntityMode != myEntityState);
1354
1355   myEntityMode = theMode;
1356   VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
1357   aFilter = myBaseActor->GetExtractUnstructuredGrid();
1358   aFilter->ClearRegisteredCellsWithType();
1359   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
1360
1361   VTKViewer_ExtractUnstructuredGrid* aHightFilter = myHighlitableActor->GetExtractUnstructuredGrid();
1362   aHightFilter->ClearRegisteredCellsWithType();
1363   aHightFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
1364
1365   if (myEntityMode & e0DElements) {
1366     if (MYDEBUG) MESSAGE("0D ELEMENTS");
1367     aFilter->RegisterCellsWithType(VTK_VERTEX);
1368     aHightFilter->RegisterCellsWithType(VTK_VERTEX);
1369   }
1370
1371   if (myEntityMode & eEdges) {
1372     if (MYDEBUG) MESSAGE("EDGES");
1373     aFilter->RegisterCellsWithType(VTK_LINE);
1374     aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
1375
1376     aHightFilter->RegisterCellsWithType(VTK_LINE);
1377     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
1378   }
1379
1380   if (myEntityMode & eFaces) {
1381     if (MYDEBUG) MESSAGE("FACES");
1382     aFilter->RegisterCellsWithType(VTK_TRIANGLE);
1383     aFilter->RegisterCellsWithType(VTK_POLYGON);
1384     aFilter->RegisterCellsWithType(VTK_QUAD);
1385     aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
1386     aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
1387     aFilter->RegisterCellsWithType(VTK_BIQUADRATIC_QUAD);
1388
1389     aHightFilter->RegisterCellsWithType(VTK_TRIANGLE);
1390     aHightFilter->RegisterCellsWithType(VTK_POLYGON);
1391     aHightFilter->RegisterCellsWithType(VTK_QUAD);
1392     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
1393     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
1394     aHightFilter->RegisterCellsWithType(VTK_BIQUADRATIC_QUAD);
1395   }
1396
1397   if (myEntityMode & eVolumes) {
1398     if (MYDEBUG) MESSAGE("VOLUMES");
1399     aFilter->RegisterCellsWithType(VTK_TETRA);
1400     aFilter->RegisterCellsWithType(VTK_VOXEL);
1401     aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1402     aFilter->RegisterCellsWithType(VTK_WEDGE);
1403     aFilter->RegisterCellsWithType(VTK_PYRAMID);
1404     aFilter->RegisterCellsWithType(VTK_HEXAGONAL_PRISM);
1405     aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
1406     aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
1407     aFilter->RegisterCellsWithType(VTK_TRIQUADRATIC_HEXAHEDRON);
1408     aFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
1409     aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1410 //#ifdef VTK_HAVE_POLYHEDRON
1411     aFilter->RegisterCellsWithType(VTK_POLYHEDRON);
1412 //#endif
1413     
1414     aHightFilter->RegisterCellsWithType(VTK_TETRA);
1415     aHightFilter->RegisterCellsWithType(VTK_VOXEL);
1416     aHightFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1417     aHightFilter->RegisterCellsWithType(VTK_WEDGE);
1418     aHightFilter->RegisterCellsWithType(VTK_PYRAMID);
1419     aHightFilter->RegisterCellsWithType(VTK_HEXAGONAL_PRISM);
1420     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
1421     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
1422     aHightFilter->RegisterCellsWithType(VTK_TRIQUADRATIC_HEXAHEDRON);
1423     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
1424     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_PYRAMID);
1425     aHightFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1426 //#ifdef VTK_HAVE_POLYHEDRON
1427     aHightFilter->RegisterCellsWithType(VTK_POLYHEDRON);
1428 //#endif
1429   }
1430   aFilter->Update();
1431   if (MYDEBUG) MESSAGE(aFilter->GetOutput()->GetNumberOfCells());
1432   SetVisibility(GetVisibility(),false);
1433 }
1434
1435 void SMESH_ActorDef::SetRepresentation (int theMode)
1436
1437   int aNbEdges = myVisualObj->GetNbEntities(SMDSAbs_Edge);
1438   int aNbFaces = myVisualObj->GetNbEntities(SMDSAbs_Face);
1439   int aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume);
1440
1441   if (theMode < 0) {
1442     myRepresentation = eSurface;
1443     if (!aNbFaces && !aNbVolumes && aNbEdges) {
1444       myRepresentation = eEdge;
1445     } else if (!aNbFaces && !aNbVolumes && !aNbEdges) {
1446       myRepresentation = ePoint;
1447     }
1448   } else {
1449     switch (theMode) {
1450     case eEdge:
1451       if (!aNbFaces && !aNbVolumes && !aNbEdges) return;
1452       break;
1453     case eSurface:
1454       if (!aNbFaces && !aNbVolumes) return;
1455       break;
1456     }    
1457     myRepresentation = theMode;
1458   }
1459
1460   if (!GetUnstructuredGrid()->GetNumberOfCells())
1461     myRepresentation = ePoint;
1462
1463   if (myIsShrunk) {
1464     if (myRepresentation == ePoint) {
1465       UnShrink();
1466       myIsShrunk = true;
1467     } else {
1468       SetShrink();
1469     }      
1470   }
1471
1472   myPickableActor = myBaseActor;
1473   myNodeActor->SetVisibility(false);
1474   myNodeExtActor->SetVisibility(false);
1475   vtkProperty *aProp = NULL, *aBackProp = NULL;
1476   SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::EReperesent(-1);
1477   SMESH_Actor::EQuadratic2DRepresentation aQuadraticMode = GetQuadratic2DRepresentation();
1478   switch (myRepresentation) {
1479   case ePoint:
1480     myPickableActor = myNodeActor;
1481     myNodeActor->SetVisibility(true);
1482     aQuadraticMode = SMESH_Actor::eLines;
1483     aProp = aBackProp = myNodeProp;
1484     aReperesent = SMESH_DeviceActor::ePoint;
1485     break;
1486   case eEdge:
1487     aProp = aBackProp = myEdgeProp;
1488     aReperesent = SMESH_DeviceActor::eInsideframe;
1489     break;
1490   case eSurface:
1491     aProp = mySurfaceProp;
1492     aBackProp = myBackSurfaceProp;
1493     aReperesent = SMESH_DeviceActor::eSurface;
1494     break;
1495   }
1496
1497   my2DActor->SetProperty(aProp);
1498   my2DActor->SetBackfaceProperty(aBackProp);
1499   my2DActor->SetRepresentation(aReperesent);
1500
1501   if(aQuadraticMode == SMESH_Actor::eLines)
1502     my2DActor->SetQuadraticArcMode(false);
1503   else if(aQuadraticMode == SMESH_Actor::eArcs)
1504     my2DActor->SetQuadraticArcMode(true);
1505
1506   my2DExtActor->SetRepresentation(aReperesent);
1507   
1508   my3DActor->SetProperty(aProp);
1509   my3DActor->SetBackfaceProperty(aBackProp);
1510   my3DActor->SetRepresentation(aReperesent);
1511
1512   //my0DExtActor->SetVisibility(false);
1513   my1DExtActor->SetVisibility(false);
1514   my2DExtActor->SetVisibility(false);
1515   my3DExtActor->SetVisibility(false);
1516
1517   // ???
1518   //my0DActor->SetProperty(aProp);
1519   //my0DActor->SetBackfaceProperty(aBackProp);
1520   my0DActor->SetRepresentation(aReperesent);
1521   //my0DExtActor->SetRepresentation(aReperesent);
1522
1523   switch(myControlMode){
1524   case eLength:
1525   case eMultiConnection:
1526     aProp = aBackProp = my1DProp;
1527     if(myRepresentation != ePoint)
1528       aReperesent = SMESH_DeviceActor::eInsideframe;
1529     break;
1530   }
1531   
1532   if(aQuadraticMode == SMESH_Actor::eLines)
1533     my1DActor->SetQuadraticArcMode(false);
1534   else if(aQuadraticMode == SMESH_Actor::eArcs)
1535     my1DActor->SetQuadraticArcMode(true);
1536
1537   my1DActor->SetProperty(aProp);
1538   my1DActor->SetBackfaceProperty(aBackProp);
1539   my1DActor->SetRepresentation(aReperesent);
1540
1541   my1DExtActor->SetRepresentation(aReperesent);
1542
1543   if(myIsPointsVisible)
1544     myPickableActor = myNodeActor;
1545   if(GetPointRepresentation())
1546     myNodeActor->SetVisibility(true);
1547
1548   SetMapper(myPickableActor->GetMapper());
1549
1550   SetVisibility(GetVisibility(),false);
1551
1552   Modified();
1553 }
1554
1555
1556 void SMESH_ActorDef::SetPointRepresentation(bool theIsPointsVisible){
1557   if ( myIsPointsVisible == theIsPointsVisible )
1558     return;
1559   myIsPointsVisible = theIsPointsVisible;
1560   SetRepresentation(GetRepresentation());
1561 }
1562
1563 bool SMESH_ActorDef::GetPointRepresentation(){ 
1564   return myIsPointsVisible || myNodeActor->GetPointsLabeled();
1565 }
1566
1567
1568 void SMESH_ActorDef::UpdateHighlight(){
1569   myHighlitableActor->SetHighlited(false);
1570   myHighlitableActor->SetVisibility(false);
1571
1572   bool anIsVisible = GetVisibility();
1573
1574   switch(myRepresentation){
1575   case SMESH_DeviceActor::eSurface:
1576   case SMESH_DeviceActor::eWireframe:
1577     {
1578       if(myIsHighlighted) {
1579         myHighlitableActor->SetProperty(myHighlightProp);
1580       }else if(myIsPreselected){
1581         myHighlitableActor->SetProperty(myPreselectProp);
1582       } else if(anIsVisible){
1583         (myRepresentation == eSurface) ? 
1584           myHighlitableActor->SetProperty(myOutLineProp) : myHighlitableActor->SetProperty(myEdgeProp);
1585       }
1586       if(GetUnstructuredGrid()->GetNumberOfCells()) {
1587         myHighlitableActor->SetHighlited(anIsVisible);
1588         myHighlitableActor->GetExtractUnstructuredGrid()->
1589           SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::eCells);
1590         myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
1591       }
1592       myHighlitableActor->SetVisibility(anIsVisible);
1593       break;
1594     }
1595   case SMESH_DeviceActor::ePoint:
1596     {
1597       if(myIsHighlighted) {
1598         myNodeActor->SetProperty(myHighlightProp);
1599       }else if(myIsPreselected) {
1600         myNodeActor->SetProperty(myPreselectProp);
1601       } else if(anIsVisible) {
1602         myNodeActor->SetProperty(myNodeProp);
1603       }
1604       myNodeActor->SetRepresentation(SMESH_DeviceActor::ePoint);
1605       myNodeActor->GetExtractUnstructuredGrid()->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
1606       break;
1607     }
1608   }
1609 }
1610
1611
1612 void SMESH_ActorDef::highlight(bool theHighlight){
1613   if ( myIsHighlighted == theHighlight )
1614     return;
1615   myIsHighlighted = theHighlight;
1616   UpdateHighlight();
1617 }
1618
1619
1620 void SMESH_ActorDef::SetPreSelected(bool thePreselect){ 
1621   if ( myIsPreselected == thePreselect )
1622     return;
1623   myIsPreselected = thePreselect; 
1624   UpdateHighlight();
1625 }
1626
1627
1628 // From vtkFollower
1629 int SMESH_ActorDef::RenderOpaqueGeometry(vtkViewport *vp)
1630 {
1631   if (myPickableActor->GetIsOpaque())
1632     {
1633     vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1634     this->Render(ren);
1635     return 1;
1636     }
1637   return 0;
1638 }
1639
1640
1641 int SMESH_ActorDef::RenderTranslucentGeometry(vtkViewport *vp)
1642 {
1643   if (!myPickableActor->GetIsOpaque())
1644     {
1645     vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1646     this->Render(ren);
1647     return 1;
1648     }
1649   return 0;
1650 }
1651
1652
1653 void SMESH_ActorDef::Render(vtkRenderer *ren){
1654   unsigned long aTime = myTimeStamp->GetMTime();
1655   unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1656   unsigned long aClippingTime = myImplicitBoolean->GetMTime();
1657   if(anObjTime > aTime || aClippingTime > aTime)
1658     Update();
1659 }
1660
1661
1662 void SMESH_ActorDef::Update(){
1663   if(MYDEBUG) MESSAGE("SMESH_ActorDef::Update");
1664
1665   if(GetControlMode() != eNone) {
1666     unsigned long aTime = myTimeStamp->GetMTime();
1667     unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1668     if (anObjTime > aTime)
1669       SetControlMode(GetControlMode(),false);
1670   }
1671
1672   if(myNodeActor)
1673     myNodeActor->UpdateLabels();
1674
1675   if(my0DActor)
1676     my0DActor->UpdateLabels();
1677   
1678   if(my1DActor)
1679     my1DActor->UpdateLabels();
1680   
1681   if(my2DActor)
1682     my2DActor->UpdateLabels();
1683
1684   if(my3DActor)
1685     my3DActor->UpdateLabels();
1686   
1687   if(myIsFacesOriented){
1688     SetFacesOriented(myIsFacesOriented);
1689   }
1690     
1691   if(myVisualObj->GetEntitiesFlag()) {
1692     myEntityMode |= myVisualObj->GetEntitiesState();
1693   }
1694   
1695   SetEntityMode(GetEntityMode());
1696   SetVisibility(GetVisibility());
1697   
1698   myTimeStamp->Modified();
1699   Modified();
1700 }
1701
1702
1703 void SMESH_ActorDef::ReleaseGraphicsResources(vtkWindow *renWin){
1704   SALOME_Actor::ReleaseGraphicsResources(renWin);
1705
1706   myPickableActor->ReleaseGraphicsResources(renWin);
1707 }
1708
1709
1710 static void GetColor(vtkProperty *theProperty, vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1711   vtkFloatingPointType* aColor = theProperty->GetColor();
1712   r = aColor[0];
1713   g = aColor[1];
1714   b = aColor[2];
1715 }
1716
1717
1718 void SMESH_ActorDef::SetOpacity(vtkFloatingPointType theValue){
1719   mySurfaceProp->SetOpacity(theValue);
1720   myBackSurfaceProp->SetOpacity(theValue);
1721   myEdgeProp->SetOpacity(theValue);
1722   myNodeProp->SetOpacity(theValue);
1723
1724   my1DProp->SetOpacity(theValue);
1725 }
1726
1727
1728 vtkFloatingPointType SMESH_ActorDef::GetOpacity(){
1729   return mySurfaceProp->GetOpacity();
1730 }
1731
1732
1733 void SMESH_ActorDef::SetSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b, int delta){
1734   mySurfaceProp->SetColor(r,g,b);
1735   if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
1736     if( aGroupObj->GetElementType() == SMDSAbs_Face ||
1737         aGroupObj->GetElementType() == SMDSAbs_Volume )
1738       myNameActor->SetBackgroundColor(r,g,b);
1739   
1740   myDeltaBrightness = delta;
1741   QColor bfc = Qtx::mainColorToSecondary(QColor(int(r*255),int(g*255),int(b*255)), delta);
1742   myBackSurfaceProp->SetColor( bfc.red() / 255. , bfc.green() / 255. , bfc.blue() / 255. );
1743   Modified();
1744 }
1745
1746 void SMESH_ActorDef::GetSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b, int& delta){
1747   ::GetColor(mySurfaceProp,r,g,b);
1748   my2DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1749   delta = myDeltaBrightness;
1750 }
1751
1752 void SMESH_ActorDef::SetEdgeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1753   myEdgeProp->SetColor(r,g,b);
1754   my1DProp->SetColor(r,g,b);
1755   my1DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1756   if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
1757     if( aGroupObj->GetElementType() == SMDSAbs_Edge )
1758       myNameActor->SetBackgroundColor(r,g,b);
1759   Modified();
1760 }
1761
1762 void SMESH_ActorDef::GetEdgeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1763   ::GetColor(myEdgeProp,r,g,b);
1764 }
1765
1766 void SMESH_ActorDef::SetOutlineColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1767   myOutLineProp->SetColor(r,g,b);
1768   Modified();
1769 }
1770
1771 void SMESH_ActorDef::GetOutlineColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1772   ::GetColor(myOutLineProp,r,g,b);
1773 }
1774
1775
1776 void SMESH_ActorDef::SetNodeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){ 
1777   myNodeProp->SetColor(r,g,b);
1778   myNodeExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1779   if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
1780     if( aGroupObj->GetElementType() == SMDSAbs_Node )
1781       myNameActor->SetBackgroundColor(r,g,b);
1782   Modified();
1783 }
1784
1785 void SMESH_ActorDef::GetNodeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){ 
1786   ::GetColor(myNodeProp,r,g,b);
1787 }
1788
1789 void SMESH_ActorDef::Set0DColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){ 
1790   my0DProp->SetColor(r,g,b);
1791   if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
1792     if( aGroupObj->GetElementType() == SMDSAbs_0DElement )
1793       myNameActor->SetBackgroundColor(r,g,b);
1794   Modified();
1795 }
1796
1797 void SMESH_ActorDef::Get0DColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){ 
1798   ::GetColor(my0DProp,r,g,b);
1799 }
1800
1801 void SMESH_ActorDef::SetHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){ 
1802   myHighlightProp->SetColor(r,g,b);
1803   Modified();
1804 }
1805
1806 void SMESH_ActorDef::GetHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){ 
1807   ::GetColor(myHighlightProp,r,g,b);
1808 }
1809
1810 void SMESH_ActorDef::SetPreHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){ 
1811   myPreselectProp->SetColor(r,g,b);
1812   Modified();
1813 }
1814
1815 void SMESH_ActorDef::GetPreHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){ 
1816   ::GetColor(myPreselectProp,r,g,b);
1817 }
1818
1819
1820 vtkFloatingPointType SMESH_ActorDef::GetLineWidth(){
1821   return myEdgeProp->GetLineWidth();
1822 }
1823
1824
1825 void SMESH_ActorDef::SetLineWidth(vtkFloatingPointType theVal){
1826   myEdgeProp->SetLineWidth(theVal);
1827
1828   my1DProp->SetLineWidth(theVal + aLineWidthInc);
1829   my1DExtProp->SetLineWidth(theVal + aLineWidthInc);    
1830   my2DExtProp->SetLineWidth(theVal + aLineWidthInc);
1831   myOutLineProp->SetLineWidth(theVal);
1832   myHighlightProp->SetLineWidth(theVal);
1833   myPreselectProp->SetLineWidth(theVal);
1834   Modified();
1835 }
1836
1837
1838 void SMESH_ActorDef::Set0DSize(vtkFloatingPointType theVal){
1839   my0DProp->SetPointSize(theVal);
1840   Modified();
1841 }
1842
1843 vtkFloatingPointType SMESH_ActorDef::Get0DSize(){
1844   return my0DProp->GetPointSize();
1845 }
1846
1847 int SMESH_ActorDef::GetObjDimension( const int theObjId )
1848 {
1849   return myVisualObj->GetElemDimension( theObjId );
1850 }
1851
1852 bool
1853 SMESH_ActorDef::
1854 IsImplicitFunctionUsed() const
1855 {
1856   return myBaseActor->IsImplicitFunctionUsed();
1857 }
1858
1859 void
1860 SMESH_ActorDef::SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed)
1861 {
1862   myNodeActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1863   myBaseActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1864
1865   myHighlitableActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1866
1867   myNodeExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1868
1869   my0DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1870   //my0DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1871
1872   my1DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1873   my1DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1874
1875   my2DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1876   my2DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1877   my3DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1878   my3DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1879 }
1880
1881 vtkIdType 
1882 SMESH_ActorDef::AddClippingPlane(vtkPlane* thePlane)
1883 {
1884   if(thePlane){
1885     myImplicitBoolean->GetFunction()->AddItem(thePlane);
1886     myCippingPlaneCont.push_back(thePlane);
1887     if(!IsImplicitFunctionUsed())
1888       SetImplicitFunctionUsed(true);
1889     myNodeActor->UpdateLabels();
1890   }
1891   return myCippingPlaneCont.size();
1892 }
1893
1894 void
1895 SMESH_ActorDef::
1896 RemoveAllClippingPlanes()
1897 {
1898   myImplicitBoolean->GetFunction()->RemoveAllItems();
1899   myImplicitBoolean->GetFunction()->Modified(); // VTK bug
1900   myCippingPlaneCont.clear();
1901   SetImplicitFunctionUsed(false);
1902   myNodeActor->UpdateLabels();
1903 }
1904
1905 vtkIdType
1906 SMESH_ActorDef::
1907 GetNumberOfClippingPlanes()
1908 {
1909   return myCippingPlaneCont.size();
1910 }
1911
1912 vtkPlane* 
1913 SMESH_ActorDef::
1914 GetClippingPlane(vtkIdType theID)
1915 {
1916   if(theID >= myCippingPlaneCont.size())
1917     return NULL;
1918   return myCippingPlaneCont[theID].Get();
1919 }
1920
1921 void SMESH_ActorDef::UpdateScalarBar()
1922 {
1923   SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
1924   if( !mgr )
1925     return;
1926
1927   vtkTextProperty* aScalarBarTitleProp = vtkTextProperty::New();
1928
1929   QColor aTColor = mgr->colorValue( "SMESH", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
1930   aScalarBarTitleProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1931
1932   aScalarBarTitleProp->SetFontFamilyToArial();
1933
1934   if ( mgr->hasValue( "SMESH", "scalar_bar_title_font" ) )
1935   {
1936     QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
1937     if ( f.family() == "Arial" )
1938       aScalarBarTitleProp->SetFontFamilyToArial();
1939     else if ( f.family() == "Courier" )
1940       aScalarBarTitleProp->SetFontFamilyToCourier();
1941     else if ( f.family() == "Times" )
1942       aScalarBarTitleProp->SetFontFamilyToTimes();
1943
1944     if ( f.bold() )
1945       aScalarBarTitleProp->BoldOn();
1946     else
1947       aScalarBarTitleProp->BoldOff();
1948
1949     if ( f.italic() )
1950       aScalarBarTitleProp->ItalicOn();
1951     else
1952      aScalarBarTitleProp->ItalicOff();
1953
1954     if ( f.overline() )
1955       aScalarBarTitleProp->ShadowOn();
1956     else
1957       aScalarBarTitleProp->ShadowOff();
1958   }
1959
1960   myScalarBarActor->SetTitleTextProperty( aScalarBarTitleProp );
1961   aScalarBarTitleProp->Delete();
1962
1963   vtkTextProperty* aScalarBarLabelProp = vtkTextProperty::New();
1964
1965   aTColor = mgr->colorValue( "SMESH", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
1966   aScalarBarLabelProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1967
1968   aScalarBarLabelProp->SetFontFamilyToArial();
1969   if( mgr->hasValue( "SMESH", "scalar_bar_label_font" ) )
1970   {
1971     QFont f = mgr->fontValue( "SMESH", "scalar_bar_label_font" );
1972     if( f.family() == "Arial" )
1973       aScalarBarLabelProp->SetFontFamilyToArial();
1974     else if( f.family() == "Courier" )
1975       aScalarBarLabelProp->SetFontFamilyToCourier();
1976     else if( f.family() == "Times" )
1977       aScalarBarLabelProp->SetFontFamilyToTimes();
1978
1979     if ( f.bold() )
1980       aScalarBarLabelProp->BoldOn();
1981     else
1982       aScalarBarLabelProp->BoldOff();
1983
1984     if ( f.italic() )
1985       aScalarBarLabelProp->ItalicOn();
1986     else
1987       aScalarBarLabelProp->ItalicOff();
1988
1989     if( f.overline() )
1990       aScalarBarLabelProp->ShadowOn();
1991     else
1992       aScalarBarLabelProp->ShadowOff();
1993   }
1994
1995   myScalarBarActor->SetLabelTextProperty( aScalarBarLabelProp );
1996   aScalarBarLabelProp->Delete();
1997
1998   bool horiz = ( mgr->integerValue( "SMESH", "scalar_bar_orientation" ) == 1 );
1999   QString name = QString( "scalar_bar_%1_" ).arg( horiz ? "horizontal" : "vertical" );
2000   if( horiz )
2001     myScalarBarActor->SetOrientationToHorizontal();
2002   else
2003     myScalarBarActor->SetOrientationToVertical();
2004
2005
2006   vtkFloatingPointType aXVal = horiz ? 0.20 : 0.01;
2007   if( mgr->hasValue( "SMESH", name + "x" ) )
2008     aXVal = mgr->doubleValue( "SMESH", name + "x", aXVal );
2009
2010   vtkFloatingPointType aYVal = horiz ? 0.01 : 0.1;
2011   if( mgr->hasValue( "SMESH", name + "y" ) )
2012     aYVal = mgr->doubleValue( "SMESH", name + "y", aYVal );
2013   myScalarBarActor->SetPosition( aXVal, aYVal );
2014
2015   vtkFloatingPointType aWVal = horiz ? 0.60 : 0.10;
2016   if( mgr->hasValue( "SMESH", name + "width" ) )
2017     aWVal = mgr->doubleValue( "SMESH", name + "width", aWVal );
2018   myScalarBarActor->SetWidth( aWVal );
2019
2020   vtkFloatingPointType aHVal = horiz ? 0.12 : 0.80;
2021   if( mgr->hasValue( "SMESH", name + "height" ) )
2022     aHVal = mgr->doubleValue( "SMESH", name + "height", aHVal );
2023   myScalarBarActor->SetHeight( aHVal );
2024
2025   int anIntVal = 5;
2026   if( mgr->hasValue( "SMESH", "scalar_bar_num_labels" ) )
2027     anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_labels", anIntVal );
2028   myScalarBarActor->SetNumberOfLabels( anIntVal == 0 ? 5: anIntVal );
2029
2030   anIntVal = 64;
2031   if( mgr->hasValue( "SMESH", "scalar_bar_num_colors" ) )
2032     anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_colors", anIntVal );
2033   myScalarBarActor->SetMaximumNumberOfColors( anIntVal == 0 ? 64 : anIntVal );
2034
2035   bool distributionVisibility = mgr->booleanValue("SMESH","distribution_visibility");
2036   myScalarBarActor->SetDistributionVisibility(distributionVisibility);
2037
2038   int coloringType = mgr->integerValue("SMESH", "distribution_coloring_type", 0);
2039   myScalarBarActor->SetDistributionColoringType(coloringType);
2040   
2041   QColor distributionColor = mgr->colorValue("SMESH", "distribution_color",
2042                                              QColor(255, 255, 255));
2043   double rgb[3];
2044   rgb[0]= distributionColor.red()/255.;
2045   rgb[1]= distributionColor.green()/255.;
2046   rgb[2]= distributionColor.blue()/255.;
2047   myScalarBarActor->SetDistributionColor(rgb);
2048
2049   
2050 }
2051
2052 void SMESH_ActorDef::UpdateDistribution()
2053 {
2054   if(SMESH::Controls::NumericalFunctor* fun =
2055      dynamic_cast<SMESH::Controls::NumericalFunctor*>(myFunctor.get()))
2056   {
2057     int nbIntervals = myScalarBarActor->GetMaximumNumberOfColors();
2058     std::vector<int> nbEvents;
2059     std::vector<double> funValues;
2060     SMESH_VisualObjDef::TEntityList elems;
2061     if ( ! dynamic_cast<SMESH_MeshObj*>(myVisualObj.get()))
2062       dynamic_cast<SMESH_VisualObjDef*>(myVisualObj.get())->GetEntities( fun->GetType(), elems );
2063     std::vector<int> elemIds;
2064     for ( SMESH_VisualObjDef::TEntityList::iterator e = elems.begin(); e != elems.end(); ++e)
2065       elemIds.push_back( (*e)->GetID());
2066     vtkLookupTable* lookupTable = static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
2067     double * range = lookupTable->GetRange();
2068     fun->GetHistogram(nbIntervals, nbEvents, funValues, elemIds, range);
2069     myScalarBarActor->SetDistribution(nbEvents);
2070   }
2071 }
2072
2073 void SMESH_ActorDef::SetQuadratic2DRepresentation(EQuadratic2DRepresentation theMode)
2074 {
2075   switch(theMode) {
2076   case SMESH_Actor::eLines :
2077     myHighlitableActor->SetQuadraticArcMode(false);
2078     my2DActor->SetQuadraticArcMode(false);
2079     my1DActor->SetQuadraticArcMode(false);
2080     break;
2081   case SMESH_Actor::eArcs :
2082     myHighlitableActor->SetQuadraticArcMode(true);
2083     if(GetRepresentation() != SMESH_Actor::ePoint) {
2084       my2DActor->SetQuadraticArcMode(true);
2085       my1DActor->SetQuadraticArcMode(true);
2086     }
2087     break;
2088   default:
2089     break;
2090   }
2091 }
2092
2093
2094 SMESH_Actor::EQuadratic2DRepresentation SMESH_ActorDef::GetQuadratic2DRepresentation()
2095 {
2096   if(myHighlitableActor->GetQuadraticArcMode())
2097     return SMESH_Actor::eArcs;
2098   else
2099     return SMESH_Actor::eLines;
2100 }
2101
2102 void SMESH_ActorDef::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale )
2103 {
2104   SALOME_Actor::SetMarkerStd( theMarkerType, theMarkerScale );
2105   myNodeActor->SetMarkerStd( theMarkerType, theMarkerScale );
2106   myNodeExtActor->SetMarkerStd( theMarkerType, theMarkerScale );
2107 }
2108
2109 void SMESH_ActorDef::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
2110 {
2111   SALOME_Actor::SetMarkerTexture( theMarkerId, theMarkerTexture );
2112   myNodeActor->SetMarkerTexture( theMarkerId, theMarkerTexture );
2113   myNodeExtActor->SetMarkerTexture( theMarkerId, theMarkerTexture );
2114   myMarkerTexture = theMarkerTexture; // for deferred update of myHighlightActor
2115 }
2116
2117 #ifndef DISABLE_PLOT2DVIEWER
2118 SPlot2d_Histogram* SMESH_ActorDef::UpdatePlot2Histogram() {
2119
2120   if(my2dHistogram)
2121     my2dHistogram->clearAllPoints();
2122   
2123   if(SMESH::Controls::NumericalFunctor* fun =
2124      dynamic_cast<SMESH::Controls::NumericalFunctor*>(myFunctor.get()))
2125   {
2126     
2127     if(!my2dHistogram) {
2128       my2dHistogram = new SPlot2d_Histogram();
2129       Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(getIO()->getEntry(),"SMESH",getName());
2130       my2dHistogram->setIO(anIO);
2131     }
2132     
2133     int nbIntervals = myScalarBarActor->GetMaximumNumberOfColors();
2134     std::vector<int> nbEvents;
2135     std::vector<double> funValues;
2136     SMESH_VisualObjDef::TEntityList elems;
2137     if ( ! dynamic_cast<SMESH_MeshObj*>(myVisualObj.get()))
2138       dynamic_cast<SMESH_VisualObjDef*>(myVisualObj.get())->GetEntities( fun->GetType(), elems );
2139     std::vector<int> elemIds;
2140     
2141     for ( SMESH_VisualObjDef::TEntityList::iterator e = elems.begin(); e != elems.end(); ++e)
2142       elemIds.push_back( (*e)->GetID());
2143
2144     vtkLookupTable* lookupTable = static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
2145     double * range = lookupTable->GetRange();
2146     fun->GetHistogram(nbIntervals, nbEvents, funValues, elemIds, range);
2147
2148     for ( int i = 0; i < std::min( nbEvents.size(), funValues.size() -1 ); i++ ) 
2149       my2dHistogram->addPoint(funValues[i] + (funValues[i+1] - funValues[i])/2.0, static_cast<double>(nbEvents[i]));
2150
2151     if(funValues.size() >= 2)
2152       my2dHistogram->setWidth((funValues[1] - funValues[0]) * 0.8) ;
2153
2154   }
2155   
2156   //Color of the histogram
2157   if(myScalarBarActor->GetDistributionColoringType() == SMESH_MULTICOLOR_TYPE)
2158     my2dHistogram->setAutoAssign(true);
2159   else {
2160     double rgb[3];
2161     myScalarBarActor->GetDistributionColor(rgb);
2162     QColor aColor = QColor( (int)( rgb[0]*255 ), (int)( rgb[1]*255 ), (int)( rgb[2]*255 ) );
2163     my2dHistogram->setColor(aColor);
2164
2165   }
2166       
2167   return my2dHistogram;
2168 }
2169 #endif