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