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