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