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