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