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