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