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