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