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