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