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