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