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