Salome HOME
VolumeTool has been partially adapted for PolyhedralVolumes processing
[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
72 #include "utilities.h"
73
74 #ifdef _DEBUG_
75 static int MYDEBUG = 0;
76 #else
77 static int MYDEBUG = 0;
78 #endif
79
80 static int aLineWidthInc = 2;
81 static int aPointSizeInc = 2;
82
83
84 SMESH_ActorDef* SMESH_ActorDef::New(){
85   return new SMESH_ActorDef();
86 }
87
88
89 SMESH_Actor* SMESH_Actor::New(TVisualObjPtr theVisualObj, 
90                               const char* theEntry, 
91                               const char* theName,
92                               int theIsClear)
93 {
94   SMESH_ActorDef* anActor = SMESH_ActorDef::New();
95   if(!anActor->Init(theVisualObj,theEntry,theName,theIsClear)){
96     anActor->Delete();
97     anActor = NULL;
98   }
99   return anActor;
100 }
101
102
103 SMESH_ActorDef::SMESH_ActorDef(){
104   if(MYDEBUG) MESSAGE("SMESH_ActorDef");
105
106   myTimeStamp = vtkTimeStamp::New();
107
108   myIsPointsVisible = false;
109
110   myIsShrinkable = false;
111   myIsShrunk = false;
112
113   myControlsPrecision = (long)SMESH::GetFloat( "SMESH:ControlsPrecision", -1 );
114
115   float aPointSize = SMESH::GetFloat("SMESH:SettingsNodesSize",3);
116   float aLineWidth = SMESH::GetFloat("SMESH:SettingsWidth",1);
117
118   vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
119   SALOME_ExtractUnstructuredGrid* aFilter = NULL;
120
121   //Definition 2D and 3D divices of the actor
122   //-----------------------------------------
123   float anRGB[3] = {1,1,1};
124   mySurfaceProp = vtkProperty::New();
125   anRGB[0] = SMESH::GetFloat("SMESH:SettingsFillColorRed", 0)/255.;
126   anRGB[1] = SMESH::GetFloat("SMESH:SettingsFillColorGreen", 170)/255.;
127   anRGB[2] = SMESH::GetFloat("SMESH:SettingsFillColorBlue", 255)/255.;
128   mySurfaceProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
129
130   myBackSurfaceProp = vtkProperty::New();
131   anRGB[0] = SMESH::GetFloat("SMESH:SettingsBackFaceColorRed", 0)/255.;
132   anRGB[1] = SMESH::GetFloat("SMESH:SettingsBackFaceColorGreen", 0)/255.;
133   anRGB[2] = SMESH::GetFloat("SMESH:SettingsBackFaceColorBlue", 255)/255.;
134   myBackSurfaceProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
135
136   my2DActor = SMESH_DeviceActor::New();
137   my2DActor->SetUserMatrix(aMatrix);
138   my2DActor->SetStoreMapping(true);
139   my2DActor->PickableOff();
140   my2DActor->SetProperty(mySurfaceProp);
141   my2DActor->SetBackfaceProperty(myBackSurfaceProp);
142   my2DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
143   aFilter = my2DActor->GetExtractUnstructuredGrid();
144   aFilter->SetModeOfChanging(SALOME_ExtractUnstructuredGrid::eAdding);
145   aFilter->RegisterCellsWithType(VTK_TRIANGLE);
146   aFilter->RegisterCellsWithType(VTK_POLYGON);
147   aFilter->RegisterCellsWithType(VTK_QUAD);
148
149   my3DActor = SMESH_DeviceActor::New();
150   my3DActor->SetUserMatrix(aMatrix);
151   my3DActor->SetStoreMapping(true);
152   my3DActor->PickableOff();
153   my3DActor->SetProperty(mySurfaceProp);
154   my3DActor->SetBackfaceProperty(myBackSurfaceProp);
155   my3DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
156   aFilter = my3DActor->GetExtractUnstructuredGrid();
157   aFilter->SetModeOfChanging(SALOME_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
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   vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
605   myIsCellsLabeled = theIsCellsLabeled && aGrid->GetNumberOfPoints();
606   if(myIsCellsLabeled){
607     myCellsNumDataSet->ShallowCopy(aGrid);
608     vtkDataSet *aDataSet = myCellsNumDataSet;
609     int aNbElem = aDataSet->GetNumberOfCells();
610     vtkIntArray *anArray = vtkIntArray::New();
611     anArray->SetNumberOfValues(aNbElem);
612     for(int anId = 0; anId < aNbElem; anId++){
613       int aSMDSId = myVisualObj->GetElemObjId(anId);
614       anArray->SetValue(anId,aSMDSId);
615     }
616     aDataSet->GetCellData()->SetScalars(anArray);
617     myCellCenters->SetInput(aDataSet);
618     myCellsLabels->SetVisibility(GetVisibility());
619   }else{
620     myCellsLabels->SetVisibility(false);
621   }
622   myTimeStamp->Modified();
623 }
624
625
626 void SMESH_ActorDef::SetControlMode(eControl theMode){
627   myControlMode = eNone;
628
629   my1DActor->GetMapper()->SetScalarVisibility(false);
630   my2DActor->GetMapper()->SetScalarVisibility(false);
631   my3DActor->GetMapper()->SetScalarVisibility(false);
632   myScalarBarActor->SetVisibility(false);
633
634   bool anIsScalarVisible = theMode > eNone;
635
636   if(anIsScalarVisible){
637     SMESH::Controls::FunctorPtr aFunctor;
638     switch(theMode){
639     case eLength:
640     {
641       SMESH::Controls::Length* aControl = new SMESH::Controls::Length();
642       aControl->SetPrecision( myControlsPrecision );
643       aFunctor.reset( aControl );
644       myControlActor = my1DActor;
645       break;
646     }
647     case eLength2D:
648     {
649       aFunctor.reset(new SMESH::Controls::Length2D());
650       myControlActor = my2DActor;
651       break;
652     }
653     case eFreeBorders:
654       aFunctor.reset(new SMESH::Controls::FreeBorders());
655       myControlActor = my1DActor;
656       break;
657     case eFreeEdges:
658       aFunctor.reset(new SMESH::Controls::FreeEdges());
659       myControlActor = my2DActor;
660       break;
661     case eMultiConnection:
662       aFunctor.reset(new SMESH::Controls::MultiConnection());
663       myControlActor = my1DActor;
664       break;
665     case eMultiConnection2D:
666       aFunctor.reset(new SMESH::Controls::MultiConnection2D());
667       myControlActor = my2DActor;
668       break;
669     case eArea:
670     {
671       SMESH::Controls::Area* aControl = new SMESH::Controls::Area();
672       aControl->SetPrecision( myControlsPrecision );
673       aFunctor.reset( aControl );
674       myControlActor = my2DActor;
675       break;
676     }
677     case eTaper:
678     {
679       SMESH::Controls::Taper* aControl = new SMESH::Controls::Taper();
680       aControl->SetPrecision( myControlsPrecision );
681       aFunctor.reset( aControl );
682       myControlActor = my2DActor;
683       break;
684     }
685     case eAspectRatio:
686     {
687       SMESH::Controls::AspectRatio* aControl = new SMESH::Controls::AspectRatio();
688       aControl->SetPrecision( myControlsPrecision );
689       aFunctor.reset( aControl );
690       myControlActor = my2DActor;
691       break;
692     }
693     case eAspectRatio3D:
694     {
695       SMESH::Controls::AspectRatio3D* aControl = new SMESH::Controls::AspectRatio3D();
696       aControl->SetPrecision( myControlsPrecision );
697       aFunctor.reset( aControl );
698       myControlActor = my3DActor;
699       break;
700     }
701     case eMinimumAngle:
702     {
703       SMESH::Controls::MinimumAngle* aControl = new SMESH::Controls::MinimumAngle();
704       aControl->SetPrecision( myControlsPrecision );
705       aFunctor.reset( aControl );
706       myControlActor = my2DActor;
707       break;
708     }
709     case eWarping:
710     {
711       SMESH::Controls::Warping* aControl = new SMESH::Controls::Warping();
712       aControl->SetPrecision( myControlsPrecision );
713       aFunctor.reset( aControl );
714       myControlActor = my2DActor;
715       break;
716     }
717     case eSkew:
718     {
719       SMESH::Controls::Skew* aControl = new SMESH::Controls::Skew();
720       aControl->SetPrecision( myControlsPrecision );
721       aFunctor.reset( aControl );
722       myControlActor = my2DActor;
723       break;
724     }
725     default:
726       return;
727     }
728
729     vtkUnstructuredGrid* aGrid = myControlActor->GetUnstructuredGrid();
730     vtkIdType aNbCells = aGrid->GetNumberOfCells();
731     if(aNbCells){
732       myControlMode = theMode;
733       switch(myControlMode){
734       case eFreeEdges:
735       case eFreeBorders:
736         my1DExtActor->SetExtControlMode(aFunctor,myControlActor);
737         break;
738       case eLength2D:
739       case eMultiConnection2D:
740         my1DExtActor->SetExtControlMode(aFunctor,myControlActor,myScalarBarActor,myLookupTable);
741         break;
742       default:
743         myControlActor->SetControlMode(aFunctor,myScalarBarActor,myLookupTable);
744       }
745     }
746
747     if(QAD_CONFIG->getSetting("SMESH:DispayEntity") == "true"){
748       if(myControlActor == my1DActor)
749         myEntityMode = eEdges;
750       else if(myControlActor == my2DActor)
751         myEntityMode = eFaces;
752       else if(myControlActor == my3DActor)
753         myEntityMode = eVolumes;
754     }
755
756   }else if(QAD_CONFIG->getSetting("SMESH:DispayEntity") == "true"){
757     myEntityMode = eAllEntity;
758   }
759
760   SetRepresentation(GetRepresentation());
761
762   myTimeStamp->Modified();
763   Modified();
764 }
765
766
767 void SMESH_ActorDef::AddToRender(vtkRenderer* theRenderer){
768   SALOME_Actor::AddToRender(theRenderer);
769
770   theRenderer->AddActor(myNodeActor);
771   theRenderer->AddActor(myBaseActor);
772
773   theRenderer->AddActor(my3DActor);
774   theRenderer->AddActor(my2DActor);
775
776   theRenderer->AddActor(my1DActor);
777   theRenderer->AddActor(my1DExtActor);
778
779   theRenderer->AddActor(myHighlitableActor);
780   theRenderer->AddActor(myNodeHighlitableActor);
781
782   theRenderer->AddActor2D(myScalarBarActor);
783
784   myPtsSelectVisiblePoints->SetRenderer(theRenderer);
785   myClsSelectVisiblePoints->SetRenderer(theRenderer);
786
787   theRenderer->AddActor2D(myPointLabels);
788   theRenderer->AddActor2D(myCellsLabels);
789 }
790
791 void SMESH_ActorDef::RemoveFromRender(vtkRenderer* theRenderer){
792   SALOME_Actor::RemoveFromRender(theRenderer);
793
794   theRenderer->RemoveActor(myNodeActor);
795   theRenderer->RemoveActor(myBaseActor);
796
797   theRenderer->RemoveActor(myHighlitableActor);
798   theRenderer->RemoveActor(myNodeHighlitableActor);
799
800   theRenderer->RemoveActor(my1DActor);
801   theRenderer->RemoveActor(my1DExtActor);
802
803   theRenderer->RemoveActor(my2DActor);
804   theRenderer->RemoveActor(my3DActor);
805
806   theRenderer->RemoveActor(myScalarBarActor);
807   theRenderer->RemoveActor(myPointLabels);
808   theRenderer->RemoveActor(myCellsLabels);
809 }
810
811
812 bool SMESH_ActorDef::Init(TVisualObjPtr theVisualObj, 
813                           const char* theEntry, 
814                           const char* theName,
815                           int theIsClear)
816 {
817   Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry,"SMESH",theName);
818   setIO(anIO);
819   setName(theName);
820
821   myVisualObj = theVisualObj;
822   myNodeActor->myVisualObj = myVisualObj;
823   myBaseActor->myVisualObj = myVisualObj;
824
825   myHighlitableActor->myVisualObj = myVisualObj;
826   myNodeHighlitableActor->myVisualObj = myVisualObj;
827
828   my1DActor->myVisualObj = myVisualObj;
829   my1DExtActor->myVisualObj = myVisualObj;
830
831   my2DActor->myVisualObj = myVisualObj;
832   my3DActor->myVisualObj = myVisualObj;
833
834   myVisualObj->Update(theIsClear);
835
836   myNodeActor->Init(myVisualObj,myImplicitBoolean);
837   myBaseActor->Init(myVisualObj,myImplicitBoolean);
838   
839   myHighlitableActor->Init(myVisualObj,myImplicitBoolean);
840   myNodeHighlitableActor->Init(myVisualObj,myImplicitBoolean);
841   
842   my1DActor->Init(myVisualObj,myImplicitBoolean);
843   my1DExtActor->Init(myVisualObj,myImplicitBoolean);
844   
845   my2DActor->Init(myVisualObj,myImplicitBoolean);
846   my3DActor->Init(myVisualObj,myImplicitBoolean);
847   
848   my1DActor->GetMapper()->SetLookupTable(myLookupTable);
849   my1DExtActor->GetMapper()->SetLookupTable(myLookupTable);
850
851   my2DActor->GetMapper()->SetLookupTable(myLookupTable);
852   my3DActor->GetMapper()->SetLookupTable(myLookupTable);
853     
854   float aFactor, aUnits;
855   my2DActor->GetPolygonOffsetParameters(aFactor,aUnits);
856   my2DActor->SetPolygonOffsetParameters(aFactor,aUnits*0.75);
857
858   //SetIsShrunkable(theGrid->GetNumberOfCells() > 10);
859   SetIsShrunkable(true);
860   
861   QString aMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
862   SetRepresentation(-1);
863   if(aMode.compare("Wireframe") == 0){
864     SetRepresentation(eEdge);
865   }else if(aMode.compare("Shading") == 0){
866     SetRepresentation(eSurface);
867   }else if(aMode.compare("Nodes") == 0){
868     SetRepresentation(ePoint);
869   }
870
871   aMode = QAD_CONFIG->getSetting("SMESH:Shrink");
872   if(aMode == "yes"){
873     SetShrink();
874   }
875
876   myTimeStamp->Modified();
877   Modified();
878   return true;
879 }
880
881
882 float* SMESH_ActorDef::GetBounds(){
883   return myNodeActor->GetBounds();
884 }
885
886
887 vtkDataSet* SMESH_ActorDef::GetInput(){
888   return GetUnstructuredGrid();
889 }
890
891
892 void SMESH_ActorDef::SetTransform(SALOME_Transform* theTransform){
893   myNodeActor->SetTransform(theTransform);
894   myBaseActor->SetTransform(theTransform);
895
896   myHighlitableActor->SetTransform(theTransform);
897   myNodeHighlitableActor->SetTransform(theTransform);
898
899   my1DActor->SetTransform(theTransform);
900   my1DExtActor->SetTransform(theTransform);
901
902   my2DActor->SetTransform(theTransform);
903   my3DActor->SetTransform(theTransform);
904
905   Modified();
906 }
907
908
909 void SMESH_ActorDef::SetMapper(vtkMapper* theMapper){
910   vtkLODActor::SetMapper(theMapper);
911 }
912
913
914 void SMESH_ActorDef::ShallowCopy(vtkProp *prop){
915   SALOME_Actor::ShallowCopy(prop);
916 }
917
918
919 vtkMapper* SMESH_ActorDef::GetMapper(){
920   return myPickableActor->GetMapper();
921 }
922
923
924 vtkUnstructuredGrid* SMESH_ActorDef::GetUnstructuredGrid(){ 
925   return myVisualObj->GetUnstructuredGrid();
926 }
927
928
929 bool SMESH_ActorDef::IsInfinitive(){
930   vtkDataSet *aDataSet = myPickableActor->GetUnstructuredGrid();
931   aDataSet->Update();
932   myIsInfinite = aDataSet->GetNumberOfCells() == 0 ||
933     aDataSet->GetNumberOfCells() == 1 && 
934     aDataSet->GetCell(0)->GetCellType() == VTK_VERTEX;
935   return SALOME_Actor::IsInfinitive();
936 }
937
938
939 void SMESH_ActorDef::SetIsShrunkable(bool theShrunkable){
940   myIsShrinkable = theShrunkable;
941   Modified();
942 }
943
944 float SMESH_ActorDef::GetShrinkFactor(){
945   return myBaseActor->GetShrinkFactor();
946 }
947
948 void SMESH_ActorDef::SetShrinkFactor(float theValue){
949   myBaseActor->SetShrinkFactor(theValue);
950
951   my1DActor->SetShrinkFactor(theValue);
952   my1DExtActor->SetShrinkFactor(theValue);
953
954   my2DActor->SetShrinkFactor(theValue);
955   my3DActor->SetShrinkFactor(theValue);
956
957   Modified();
958 }
959
960 void SMESH_ActorDef::SetShrink(){
961   if(!myIsShrinkable) return;
962
963   myBaseActor->SetShrink();
964
965   my1DActor->SetShrink();
966   my1DExtActor->SetShrink();
967
968   my2DActor->SetShrink();
969   my3DActor->SetShrink();
970
971   myIsShrunk = true;
972   Modified();
973 }
974
975 void SMESH_ActorDef::UnShrink(){
976   if(!myIsShrunk) return;
977
978   myBaseActor->UnShrink();
979
980   my1DActor->UnShrink();
981   my1DExtActor->UnShrink();
982
983   my2DActor->UnShrink();
984   my3DActor->UnShrink();
985
986   myIsShrunk = false;
987   Modified();
988 }
989
990
991 int SMESH_ActorDef::GetNodeObjId(int theVtkID){
992   return myPickableActor->GetNodeObjId(theVtkID);
993 }
994
995 float* SMESH_ActorDef::GetNodeCoord(int theObjID){
996   return myPickableActor->GetNodeCoord(theObjID);
997 }
998
999
1000 int SMESH_ActorDef::GetElemObjId(int theVtkID){
1001   return myPickableActor->GetElemObjId(theVtkID);
1002 }
1003
1004 vtkCell* SMESH_ActorDef::GetElemCell(int theObjID){
1005   return myPickableActor->GetElemCell(theObjID);
1006 }
1007
1008
1009 void SMESH_ActorDef::SetVisibility(int theMode){
1010   SetVisibility(theMode,true);
1011 }
1012
1013
1014 void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation){
1015   SALOME_Actor::SetVisibility(theMode);
1016
1017   myNodeActor->VisibilityOff();
1018   myBaseActor->VisibilityOff();
1019   
1020   my1DActor->VisibilityOff();
1021   my1DExtActor->VisibilityOff();
1022   
1023   my2DActor->VisibilityOff();
1024   my3DActor->VisibilityOff();
1025   
1026   myScalarBarActor->VisibilityOff();
1027   myPointLabels->VisibilityOff();
1028   myCellsLabels->VisibilityOff();
1029   
1030   if(GetVisibility()){
1031     if(theIsUpdateRepersentation)
1032       SetRepresentation(GetRepresentation());
1033
1034     if(myControlMode != eNone){
1035       switch(myControlMode){
1036       case eFreeEdges:
1037       case eFreeBorders:
1038         my1DExtActor->VisibilityOn();
1039         break;
1040       case eLength2D:
1041       case eMultiConnection2D:
1042         my1DExtActor->VisibilityOn();
1043       default:
1044         if(myControlActor->GetUnstructuredGrid()->GetNumberOfCells())
1045           myScalarBarActor->VisibilityOn();
1046       }
1047     }
1048
1049     if(myRepresentation != ePoint)
1050       myPickableActor->VisibilityOn();
1051     else {
1052       myNodeActor->VisibilityOn();
1053     }
1054
1055     if(myEntityMode & eEdges){
1056       my1DActor->VisibilityOn();
1057     }
1058     
1059     if(myEntityMode & eFaces){
1060       my2DActor->VisibilityOn();
1061     }
1062     
1063     if(myEntityMode & eVolumes){
1064       my3DActor->VisibilityOn();
1065     }
1066     
1067     if(myIsPointsLabeled){
1068       myPointLabels->VisibilityOn();
1069       myNodeActor->VisibilityOn();
1070     }
1071
1072     if(myIsCellsLabeled) 
1073       myCellsLabels->VisibilityOn();
1074   }
1075
1076   Modified();
1077 }
1078
1079
1080 void SMESH_ActorDef::SetEntityMode(unsigned int theMode){
1081   if(!myVisualObj->GetNbEntities(SMDSAbs_Edge))
1082     theMode &= ~eEdges;
1083
1084   if(!myVisualObj->GetNbEntities(SMDSAbs_Face))
1085     theMode &= ~eFaces;
1086
1087   if(!myVisualObj->GetNbEntities(SMDSAbs_Volume))
1088     theMode &= ~eVolumes;
1089
1090   if(!theMode){
1091     if(myVisualObj->GetNbEntities(SMDSAbs_Edge))
1092       theMode |= eEdges;
1093
1094     if(myVisualObj->GetNbEntities(SMDSAbs_Face))
1095       theMode |= eFaces;
1096
1097     if(myVisualObj->GetNbEntities(SMDSAbs_Volume))
1098       theMode |= eVolumes;
1099   }
1100
1101   myEntityMode = theMode;
1102   SALOME_ExtractUnstructuredGrid* aFilter = NULL;
1103   aFilter = myBaseActor->GetExtractUnstructuredGrid();
1104   aFilter->ClearRegisteredCellsWithType();
1105   aFilter->SetModeOfChanging(SALOME_ExtractUnstructuredGrid::eAdding);
1106   
1107   if(myEntityMode & eEdges){
1108     if (MYDEBUG) MESSAGE("EDGES");
1109     aFilter->RegisterCellsWithType(VTK_LINE);
1110   }
1111
1112   if(myEntityMode & eFaces){
1113     if (MYDEBUG) MESSAGE("FACES");
1114     aFilter->RegisterCellsWithType(VTK_TRIANGLE);
1115     aFilter->RegisterCellsWithType(VTK_POLYGON);
1116     aFilter->RegisterCellsWithType(VTK_QUAD);
1117   }
1118
1119   if(myEntityMode & eVolumes){
1120     if (MYDEBUG) MESSAGE("VOLUMES");
1121     aFilter->RegisterCellsWithType(VTK_TETRA);
1122     aFilter->RegisterCellsWithType(VTK_VOXEL);
1123     aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1124     aFilter->RegisterCellsWithType(VTK_WEDGE);
1125     aFilter->RegisterCellsWithType(VTK_PYRAMID);
1126     aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1127   }
1128   aFilter->Update();
1129   if (MYDEBUG) MESSAGE(aFilter->GetOutput()->GetNumberOfCells());
1130   SetVisibility(GetVisibility(),false);
1131 }
1132
1133 void SMESH_ActorDef::SetRepresentation(int theMode){ 
1134   int aNbEdges = myVisualObj->GetNbEntities(SMDSAbs_Edge);
1135   int aNbFaces = myVisualObj->GetNbEntities(SMDSAbs_Face);
1136   int aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume);
1137   if(theMode < 0){
1138     myRepresentation = eSurface;
1139     if(!aNbFaces && !aNbVolumes && aNbEdges){
1140       myRepresentation = eEdge;
1141     }else if(!aNbFaces && !aNbVolumes && !aNbEdges){
1142       myRepresentation = ePoint;
1143     }
1144   }else{
1145     switch(theMode){
1146     case eEdge:
1147       if(!aNbFaces && !aNbVolumes && !aNbEdges) return;
1148       break;
1149     case eSurface:
1150       if(!aNbFaces && !aNbVolumes) return;
1151       break;
1152     }    
1153     myRepresentation = theMode;
1154   }
1155
1156   if(!GetUnstructuredGrid()->GetNumberOfCells())
1157     myRepresentation = ePoint;
1158
1159   if(myIsShrunk){
1160     if(myRepresentation == ePoint){
1161       UnShrink();
1162       myIsShrunk = true;
1163     }else{
1164       SetShrink();
1165     }      
1166   }
1167
1168   myPickableActor = myBaseActor;
1169   myNodeActor->SetVisibility(false);
1170   vtkProperty *aProp = NULL, *aBackProp = NULL;
1171   SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::EReperesent(-1);
1172   switch(myRepresentation){
1173   case ePoint:
1174     myPickableActor = myNodeActor;
1175     myNodeActor->SetVisibility(true);
1176
1177     aProp = aBackProp = myNodeProp;
1178     aReperesent = SMESH_DeviceActor::ePoint;
1179     break;
1180   case eEdge:
1181     aProp = aBackProp = myEdgeProp;
1182     aReperesent = SMESH_DeviceActor::eInsideframe;
1183     break;
1184   case eSurface:
1185     aProp = mySurfaceProp;
1186     aBackProp = myBackSurfaceProp;
1187     aReperesent = SMESH_DeviceActor::eSurface;
1188     break;
1189   }    
1190
1191   my2DActor->SetProperty(aProp);
1192   my2DActor->SetBackfaceProperty(aBackProp);
1193   my2DActor->SetRepresentation(aReperesent);
1194   
1195   my3DActor->SetProperty(aProp);
1196   my3DActor->SetBackfaceProperty(aBackProp);
1197   my3DActor->SetRepresentation(aReperesent);
1198
1199   my1DExtActor->SetVisibility(false);
1200
1201   switch(myControlMode){
1202   case eLength:
1203   case eMultiConnection:
1204     aProp = aBackProp = my1DProp;
1205     if(myRepresentation != ePoint)
1206       aReperesent = SMESH_DeviceActor::eInsideframe;
1207     break;
1208   }
1209   
1210   my1DActor->SetProperty(aProp);
1211   my1DActor->SetBackfaceProperty(aBackProp);
1212   my1DActor->SetRepresentation(aReperesent);
1213
1214   my1DExtActor->SetRepresentation(aReperesent);
1215   
1216   if(myIsPointsVisible)
1217     myPickableActor = myNodeActor;
1218   if(GetPointRepresentation())
1219     myNodeActor->SetVisibility(true);
1220
1221   SetMapper(myPickableActor->GetMapper());
1222
1223   SetVisibility(GetVisibility(),false);
1224
1225   Modified();
1226 }
1227
1228
1229 void SMESH_ActorDef::SetPointRepresentation(bool theIsPointsVisible){
1230   myIsPointsVisible = theIsPointsVisible;
1231   SetRepresentation(GetRepresentation());
1232 }
1233
1234 bool SMESH_ActorDef::GetPointRepresentation(){ 
1235   return myIsPointsVisible || myIsPointsLabeled;
1236 }
1237
1238
1239 void SMESH_ActorDef::UpdateHighlight(){
1240   myHighlitableActor->SetVisibility(false);
1241   myHighlitableActor->SetHighlited(false);
1242
1243   myNodeHighlitableActor->SetVisibility(false);
1244   myNodeHighlitableActor->SetHighlited(false);
1245
1246   if(myIsHighlighted){
1247     myHighlitableActor->SetProperty(myHighlightProp);
1248   }else if(myIsPreselected){
1249     myHighlitableActor->SetProperty(myPreselectProp);
1250   }
1251
1252   bool isVisible = GetVisibility();
1253
1254   if(myIsHighlighted || myIsPreselected){
1255     if(GetUnstructuredGrid()->GetNumberOfCells()){
1256       myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
1257       myHighlitableActor->SetVisibility(isVisible);
1258       myHighlitableActor->SetHighlited(isVisible);
1259     }
1260     if(myRepresentation == ePoint || GetPointRepresentation()){
1261       myNodeHighlitableActor->SetProperty(myHighlitableActor->GetProperty());
1262       myNodeHighlitableActor->SetVisibility(isVisible);
1263       myNodeHighlitableActor->SetHighlited(isVisible);
1264     }
1265   }
1266 }
1267
1268
1269 void SMESH_ActorDef::highlight(bool theHighlight){
1270   myIsHighlighted = theHighlight;
1271   UpdateHighlight();
1272 }
1273
1274
1275 void SMESH_ActorDef::SetPreSelected(bool thePreselect){ 
1276   myIsPreselected = thePreselect; 
1277   UpdateHighlight();
1278 }
1279
1280
1281 // From vtkFollower
1282 int SMESH_ActorDef::RenderOpaqueGeometry(vtkViewport *vp)
1283 {
1284   if (myPickableActor->GetIsOpaque())
1285     {
1286     vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1287     this->Render(ren);
1288     return 1;
1289     }
1290   return 0;
1291 }
1292
1293
1294 int SMESH_ActorDef::RenderTranslucentGeometry(vtkViewport *vp)
1295 {
1296   if (!myPickableActor->GetIsOpaque())
1297     {
1298     vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1299     this->Render(ren);
1300     return 1;
1301     }
1302   return 0;
1303 }
1304
1305
1306 void SMESH_ActorDef::Render(vtkRenderer *ren){
1307   unsigned long aTime = myTimeStamp->GetMTime();
1308   unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1309   unsigned long aClippingTime = myImplicitBoolean->GetMTime();
1310   if(anObjTime > aTime || aClippingTime > aTime)
1311     Update();
1312 }
1313
1314
1315 void SMESH_ActorDef::Update(){
1316   if(MYDEBUG) MESSAGE("SMESH_ActorDef::Update");
1317
1318   if(GetControlMode() != eNone) {
1319     unsigned long aTime = myTimeStamp->GetMTime();
1320     unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1321     if (anObjTime > aTime)
1322       SetControlMode(GetControlMode());
1323   }
1324   if(myIsPointsLabeled){
1325     SetPointsLabeled(myIsPointsLabeled);
1326   }
1327   if(myIsCellsLabeled){
1328     SetCellsLabeled(myIsCellsLabeled);
1329   }
1330   SetEntityMode(GetEntityMode());
1331   SetVisibility(GetVisibility());
1332   
1333   myTimeStamp->Modified();
1334   Modified();
1335 }
1336
1337
1338 void SMESH_ActorDef::ReleaseGraphicsResources(vtkWindow *renWin){
1339   SALOME_Actor::ReleaseGraphicsResources(renWin);
1340
1341   myPickableActor->ReleaseGraphicsResources(renWin);
1342 }
1343
1344
1345 static void GetColor(vtkProperty *theProperty, float& r,float& g,float& b){
1346   float* aColor = theProperty->GetColor();
1347   r = aColor[0];
1348   g = aColor[1];
1349   b = aColor[2];
1350 }
1351
1352
1353 void SMESH_ActorDef::SetOpacity(float theValue){
1354   mySurfaceProp->SetOpacity(theValue);
1355   myBackSurfaceProp->SetOpacity(theValue);
1356   myEdgeProp->SetOpacity(theValue);
1357   myNodeProp->SetOpacity(theValue);
1358
1359   my1DProp->SetOpacity(theValue);
1360 }
1361
1362
1363 float SMESH_ActorDef::GetOpacity(){
1364   return mySurfaceProp->GetOpacity();
1365 }
1366
1367
1368 void SMESH_ActorDef::SetSufaceColor(float r,float g,float b){
1369   mySurfaceProp->SetColor(r,g,b);
1370   Modified();
1371 }
1372
1373 void SMESH_ActorDef::GetSufaceColor(float& r,float& g,float& b){
1374   ::GetColor(mySurfaceProp,r,g,b);
1375 }
1376
1377 void SMESH_ActorDef::SetBackSufaceColor(float r,float g,float b){
1378   myBackSurfaceProp->SetColor(r,g,b);
1379   Modified();
1380 }
1381
1382 void SMESH_ActorDef::GetBackSufaceColor(float& r,float& g,float& b){
1383   ::GetColor(myBackSurfaceProp,r,g,b);
1384 }
1385
1386 void SMESH_ActorDef::SetEdgeColor(float r,float g,float b){
1387   myEdgeProp->SetColor(r,g,b);
1388   my1DProp->SetColor(r,g,b);
1389   my1DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1390   Modified();
1391 }
1392
1393 void SMESH_ActorDef::GetEdgeColor(float& r,float& g,float& b){
1394   ::GetColor(myEdgeProp,r,g,b);
1395 }
1396
1397 void SMESH_ActorDef::SetNodeColor(float r,float g,float b){ 
1398   myNodeProp->SetColor(r,g,b);
1399   Modified();
1400 }
1401
1402 void SMESH_ActorDef::GetNodeColor(float& r,float& g,float& b){ 
1403   ::GetColor(myNodeProp,r,g,b);
1404 }
1405
1406 void SMESH_ActorDef::SetHighlightColor(float r,float g,float b){ 
1407   myHighlightProp->SetColor(r,g,b);
1408   Modified();
1409 }
1410
1411 void SMESH_ActorDef::GetHighlightColor(float& r,float& g,float& b){ 
1412   ::GetColor(myHighlightProp,r,g,b);
1413 }
1414
1415 void SMESH_ActorDef::SetPreHighlightColor(float r,float g,float b){ 
1416   myPreselectProp->SetColor(r,g,b);
1417   Modified();
1418 }
1419
1420 void SMESH_ActorDef::GetPreHighlightColor(float& r,float& g,float& b){ 
1421   ::GetColor(myPreselectProp,r,g,b);
1422 }
1423
1424
1425 float SMESH_ActorDef::GetLineWidth(){
1426   return myEdgeProp->GetLineWidth();
1427 }
1428
1429
1430 void SMESH_ActorDef::SetLineWidth(float theVal){
1431   myEdgeProp->SetLineWidth(theVal);
1432
1433   my1DProp->SetLineWidth(theVal + aLineWidthInc);
1434   my1DExtProp->SetLineWidth(theVal + aLineWidthInc);
1435
1436   Modified();
1437 }
1438
1439
1440 void SMESH_ActorDef::SetNodeSize(float theVal){
1441   myNodeProp->SetPointSize(theVal);
1442   myHighlightProp->SetPointSize(theVal);
1443   myPreselectProp->SetPointSize(theVal);
1444
1445   my1DProp->SetPointSize(theVal + aPointSizeInc);
1446   my1DExtProp->SetPointSize(theVal + aPointSizeInc);
1447
1448   Modified();
1449 }
1450
1451 float SMESH_ActorDef::GetNodeSize(){
1452   return myNodeProp->GetPointSize();
1453 }
1454
1455 int SMESH_ActorDef::GetObjDimension( const int theObjId )
1456 {
1457   return myVisualObj->GetElemDimension( theObjId );
1458 }
1459
1460
1461 vtkImplicitBoolean* SMESH_ActorDef::GetPlaneContainer(){
1462   return myImplicitBoolean;
1463 }
1464
1465
1466 static void ComputeBoundsParam(vtkDataSet* theDataSet,
1467                                float theDirection[3], float theMinPnt[3],
1468                                float& theMaxBoundPrj, float& theMinBoundPrj)
1469 {
1470   float aBounds[6];
1471   theDataSet->GetBounds(aBounds);
1472
1473   //Enlarge bounds in order to avoid conflicts of precision
1474   for(int i = 0; i < 6; i += 2){
1475     static double EPS = 1.0E-3;
1476     float aDelta = (aBounds[i+1] - aBounds[i])*EPS;
1477     aBounds[i] -= aDelta;
1478     aBounds[i+1] += aDelta;
1479   }
1480
1481   float aBoundPoints[8][3] = { {aBounds[0],aBounds[2],aBounds[4]},
1482                                {aBounds[1],aBounds[2],aBounds[4]},
1483                                {aBounds[0],aBounds[3],aBounds[4]},
1484                                {aBounds[1],aBounds[3],aBounds[4]},
1485                                {aBounds[0],aBounds[2],aBounds[5]},
1486                                {aBounds[1],aBounds[2],aBounds[5]}, 
1487                                {aBounds[0],aBounds[3],aBounds[5]}, 
1488                                {aBounds[1],aBounds[3],aBounds[5]}};
1489
1490   int aMaxId = 0, aMinId = aMaxId;
1491   theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
1492   theMinBoundPrj = theMaxBoundPrj;
1493   for(int i = 1; i < 8; i++){
1494     float aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
1495     if(theMaxBoundPrj < aTmp){
1496       theMaxBoundPrj = aTmp;
1497       aMaxId = i;
1498     }
1499     if(theMinBoundPrj > aTmp){
1500       theMinBoundPrj = aTmp;
1501       aMinId = i;
1502     }
1503   }
1504   float *aMinPnt = aBoundPoints[aMaxId];
1505   theMinPnt[0] = aMinPnt[0];
1506   theMinPnt[1] = aMinPnt[1];
1507   theMinPnt[2] = aMinPnt[2];
1508 }
1509
1510
1511 static void DistanceToPosition(vtkDataSet* theDataSet,
1512                                float theDirection[3], float theDist, float thePos[3])
1513 {
1514   float aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1515   ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1516   float aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
1517   thePos[0] = aMinPnt[0]-theDirection[0]*aLength;
1518   thePos[1] = aMinPnt[1]-theDirection[1]*aLength;
1519   thePos[2] = aMinPnt[2]-theDirection[2]*aLength;
1520 }
1521
1522
1523 static void PositionToDistance(vtkDataSet* theDataSet, 
1524                                float theDirection[3], float thePos[3], float& theDist)
1525 {
1526   float aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1527   ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1528   float aPrj = vtkMath::Dot(theDirection,thePos);
1529   theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
1530 }
1531
1532
1533 void SMESH_ActorDef::SetPlaneParam(float theDir[3], float theDist, vtkPlane* thePlane)
1534 {
1535   thePlane->SetNormal(theDir);
1536   float anOrigin[3];
1537   ::DistanceToPosition(GetUnstructuredGrid(),theDir,theDist,anOrigin);
1538   thePlane->SetOrigin(anOrigin);
1539 }
1540
1541
1542 void SMESH_ActorDef::GetPlaneParam(float theDir[3], float& theDist, vtkPlane* thePlane)
1543 {
1544   thePlane->GetNormal(theDir);
1545
1546   float anOrigin[3];
1547   thePlane->GetOrigin(anOrigin);
1548   ::PositionToDistance(GetUnstructuredGrid(),theDir,anOrigin,theDist);
1549 }