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