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