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