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