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