Salome HOME
Fix. Incorrect group of nodes representation
[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
243   myPickableActor = myBaseActor;
244
245   myHighlightProp = vtkProperty::New();
246   myHighlightProp->SetAmbient(1.0);
247   myHighlightProp->SetDiffuse(0.0);
248   myHighlightProp->SetSpecular(0.0);
249   anRGB[0] = SMESH::GetFloat("SMESH:SettingsSelectColorRed", 255)/255.;   // 1;
250   anRGB[1] = SMESH::GetFloat("SMESH:SettingsSelectColorGreen", 255)/255.; // 1;
251   anRGB[2] = SMESH::GetFloat("SMESH:SettingsSelectColorBlue", 255)/255.;  // 1;
252   myHighlightProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
253   myHighlightProp->SetPointSize(aPointSize);
254   myHighlightProp->SetRepresentation(1);
255  
256   myPreselectProp = vtkProperty::New();
257   myPreselectProp->SetAmbient(1.0);
258   myPreselectProp->SetDiffuse(0.0);
259   myPreselectProp->SetSpecular(0.0);
260   anRGB[0] = SMESH::GetFloat("SMESH:SettingsPreSelectColorRed", 0)/255.;     // 0;
261   anRGB[1] = SMESH::GetFloat("SMESH:SettingsPreSelectColorGreen", 255)/255.; // 1;
262   anRGB[2] = SMESH::GetFloat("SMESH:SettingsPreSelectColorBlue", 255)/255.;  // 1;
263   myPreselectProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
264   myPreselectProp->SetPointSize(aPointSize);
265   myPreselectProp->SetRepresentation(1);
266
267   myHighlitableActor = SMESH_DeviceActor::New();
268   myHighlitableActor->SetUserMatrix(aMatrix);
269   myHighlitableActor->SetStoreMapping(false);
270   myHighlitableActor->PickableOff();
271   myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
272
273   myNodeHighlitableActor = SMESH_DeviceActor::New();
274   myNodeHighlitableActor->SetUserMatrix(aMatrix);
275   myNodeHighlitableActor->SetStoreMapping(false);
276   myNodeHighlitableActor->PickableOff();
277   myNodeHighlitableActor->SetRepresentation(SMESH_DeviceActor::ePoint);
278   aFilter = myNodeHighlitableActor->GetExtractUnstructuredGrid();
279   aFilter->SetModeOfExtraction(SALOME_ExtractUnstructuredGrid::ePoints);
280
281
282   SetShrinkFactor(SMESH::GetFloat("SMESH:SettingsShrinkCoeff", 75)/100.);
283
284   myName = "";
285   myIO = NULL;
286
287   myControlMode = eNone;
288   myControlActor = my2DActor;
289
290   //Definition of myScalarBarActor
291   //------------------------------
292   myLookupTable = vtkLookupTable::New();
293   //Fix for Bug PAL5195 - SMESH764: 
294   //Controls - Aspect Ratio: incorrect colors of the best and worst values
295   myLookupTable->SetHueRange(0.667,0.0);
296
297   myScalarBarActor = vtkScalarBarActor::New();
298   myScalarBarActor->SetVisibility(false);
299   myScalarBarActor->SetLookupTable(myLookupTable);
300
301   vtkTextProperty* aScalarBarTitleProp = vtkTextProperty::New();
302
303   if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarTitleColor" ) ) {
304     QStringList aTColor = QStringList::split(  ":", QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleColor" ), false );
305     aScalarBarTitleProp->SetColor( ( aTColor.count() > 0 ? aTColor[0].toInt()/255. : 1.0 ),
306                                    ( aTColor.count() > 1 ? aTColor[1].toInt()/255. : 1.0 ), 
307                                    ( aTColor.count() > 2 ? aTColor[2].toInt()/255. : 1.0 ) );
308   }
309   else
310     aScalarBarTitleProp->SetColor( 1.0, 1.0, 1.0 );
311
312   aScalarBarTitleProp->SetFontFamilyToArial();
313   if( QAD_CONFIG->hasSetting( "SMESH:ScalarBarTitleFont" ) ){
314     if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleFont" ) == "Arial" )
315       aScalarBarTitleProp->SetFontFamilyToArial();
316     else if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleFont" ) == "Courier" )
317       aScalarBarTitleProp->SetFontFamilyToCourier();
318     else if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleFont" ) == "Times" )
319       aScalarBarTitleProp->SetFontFamilyToTimes();
320   }
321
322   if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleBold" ) == "true" )
323     aScalarBarTitleProp->BoldOn();
324   else
325     aScalarBarTitleProp->BoldOff();
326
327   if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleItalic" ) == "true" )
328     aScalarBarTitleProp->ItalicOn();
329   else
330     aScalarBarTitleProp->ItalicOff();
331
332   if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarTitleShadow" ) == "true" )
333     aScalarBarTitleProp->ShadowOn();
334   else
335     aScalarBarTitleProp->ShadowOff();
336
337   myScalarBarActor->SetTitleTextProperty( aScalarBarTitleProp );
338   aScalarBarTitleProp->Delete();
339
340   vtkTextProperty* aScalarBarLabelProp = vtkTextProperty::New();
341
342   if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarLabelColor" ) ) {
343     QStringList aTColor = QStringList::split(  ":", QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelColor" ), false );
344     aScalarBarLabelProp->SetColor( ( aTColor.count() > 0 ? aTColor[0].toInt()/255. : 1.0 ),
345                                    ( aTColor.count() > 1 ? aTColor[1].toInt()/255. : 1.0 ), 
346                                    ( aTColor.count() > 2 ? aTColor[2].toInt()/255. : 1.0 ) );
347   }
348   else
349     aScalarBarLabelProp->SetColor( 1.0, 1.0, 1.0 );
350
351   aScalarBarLabelProp->SetFontFamilyToArial();
352   if( QAD_CONFIG->hasSetting( "SMESH:ScalarBarLabelFont" ) ){
353     if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelFont" ) == "Arial" )
354       aScalarBarLabelProp->SetFontFamilyToArial();
355     else if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelFont" ) == "Courier" )
356       aScalarBarLabelProp->SetFontFamilyToCourier();
357     else if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelFont" ) == "Times" )
358       aScalarBarLabelProp->SetFontFamilyToTimes();
359   }
360
361   if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelBold" ) == "true" )
362     aScalarBarLabelProp->BoldOn();
363   else
364     aScalarBarLabelProp->BoldOff();
365
366   if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelItalic" ) == "true" )
367     aScalarBarLabelProp->ItalicOn();
368   else
369     aScalarBarLabelProp->ItalicOff();
370
371   if ( QAD_CONFIG->getSetting( "SMESH:ScalarBarLabelShadow" ) == "true" )
372     aScalarBarLabelProp->ShadowOn();
373   else
374     aScalarBarLabelProp->ShadowOff();
375
376   myScalarBarActor->SetLabelTextProperty( aScalarBarLabelProp );
377   aScalarBarLabelProp->Delete();
378
379   if ( QAD_CONFIG->getSetting("SMESH:ScalarBarOrientation") == "Horizontal" )
380     myScalarBarActor->SetOrientationToHorizontal();
381   else
382     myScalarBarActor->SetOrientationToVertical();
383
384   float aXVal = QAD_CONFIG->getSetting("SMESH:ScalarBarOrientation") == "Horizontal" ? 0.20 : 0.01;
385   if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarXPosition" ) )
386     aXVal = QAD_CONFIG->getSetting( "SMESH:ScalarBarXPosition" ).toFloat();
387   float aYVal = QAD_CONFIG->getSetting("SMESH:ScalarBarOrientation") == "Horizontal" ? 0.01 : 0.1;
388   if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarYPosition" ) )
389     aYVal = QAD_CONFIG->getSetting( "SMESH:ScalarBarYPosition" ).toFloat();
390   myScalarBarActor->SetPosition( aXVal, aYVal );
391
392   float aWVal = QAD_CONFIG->getSetting("SMESH:ScalarBarOrientation") == "Horizontal" ? 0.60 : 0.10;
393   if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarWidth" ) )
394     aWVal = QAD_CONFIG->getSetting( "SMESH:ScalarBarWidth" ).toFloat();
395   myScalarBarActor->SetWidth( aWVal );
396
397   float aHVal = QAD_CONFIG->getSetting("SMESH:ScalarBarOrientation") == "Horizontal" ? 0.12 : 0.80;
398   if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarHeight" ) )
399     aHVal = QAD_CONFIG->getSetting( "SMESH:ScalarBarHeight" ).toFloat();
400   myScalarBarActor->SetHeight( aHVal );
401
402   int anIntVal = 5;
403   if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarNbOfLabels" ) )
404     anIntVal = QAD_CONFIG->getSetting("SMESH:ScalarBarNbOfLabels").toInt();
405   myScalarBarActor->SetNumberOfLabels(anIntVal == 0? 5: anIntVal);
406
407   anIntVal = 64;
408   if ( QAD_CONFIG->hasSetting( "SMESH:ScalarBarNbOfColors" ) )
409     anIntVal = QAD_CONFIG->getSetting("SMESH:ScalarBarNbOfColors").toInt();
410   myScalarBarActor->SetMaximumNumberOfColors(anIntVal == 0? 64: anIntVal);
411
412
413   //Definition of points numbering pipeline
414   //---------------------------------------
415   myPointsNumDataSet = vtkUnstructuredGrid::New();
416
417   myPtsMaskPoints = vtkMaskPoints::New();
418   myPtsMaskPoints->SetInput(myPointsNumDataSet);
419   myPtsMaskPoints->SetOnRatio(1);
420     
421   myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
422   myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput());
423   myPtsSelectVisiblePoints->SelectInvisibleOff();
424   myPtsSelectVisiblePoints->SetTolerance(0.1);
425     
426   myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
427   myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
428   myPtsLabeledDataMapper->SetLabelFormat("%g");
429   myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
430     
431   vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
432   aPtsTextProp->SetFontFamilyToTimes();
433   static int aPointsFontSize = 10;
434   aPtsTextProp->SetFontSize(aPointsFontSize);
435   aPtsTextProp->SetBold(1);
436   aPtsTextProp->SetItalic(0);
437   aPtsTextProp->SetShadow(0);
438   myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
439   aPtsTextProp->Delete();
440   
441   myEntityMode = eAllEntity;
442
443   myIsPointsLabeled = false;
444
445   myPointLabels = vtkActor2D::New();
446   myPointLabels->SetMapper(myPtsLabeledDataMapper);
447   myPointLabels->GetProperty()->SetColor(1,1,1);
448   myPointLabels->SetVisibility(myIsPointsLabeled);
449
450
451   //Definition of cells numbering pipeline
452   //---------------------------------------
453   myCellsNumDataSet = vtkUnstructuredGrid::New();
454
455   myCellCenters = vtkCellCenters::New();
456   myCellCenters->SetInput(myCellsNumDataSet);
457
458   myClsMaskPoints = vtkMaskPoints::New();
459   myClsMaskPoints->SetInput(myCellCenters->GetOutput());
460   myClsMaskPoints->SetOnRatio(1);
461     
462   myClsSelectVisiblePoints = vtkSelectVisiblePoints::New();
463   myClsSelectVisiblePoints->SetInput(myClsMaskPoints->GetOutput());
464   myClsSelectVisiblePoints->SelectInvisibleOff();
465   myClsSelectVisiblePoints->SetTolerance(0.1);
466     
467   myClsLabeledDataMapper = vtkLabeledDataMapper::New();
468   myClsLabeledDataMapper->SetInput(myClsSelectVisiblePoints->GetOutput());
469   myClsLabeledDataMapper->SetLabelFormat("%g");
470   myClsLabeledDataMapper->SetLabelModeToLabelScalars();
471     
472   vtkTextProperty* aClsTextProp = vtkTextProperty::New();
473   aClsTextProp->SetFontFamilyToTimes();
474   static int aCellsFontSize = 12;
475   aClsTextProp->SetFontSize(aCellsFontSize);
476   aClsTextProp->SetBold(1);
477   aClsTextProp->SetItalic(0);
478   aClsTextProp->SetShadow(0);
479   myClsLabeledDataMapper->SetLabelTextProperty(aClsTextProp);
480   aClsTextProp->Delete();
481     
482   myIsCellsLabeled = false;
483
484   myCellsLabels = vtkActor2D::New();
485   myCellsLabels->SetMapper(myClsLabeledDataMapper);
486   myCellsLabels->GetProperty()->SetColor(0,1,0);
487   myCellsLabels->SetVisibility(myIsCellsLabeled);
488
489   // Clipping planes
490   myImplicitBoolean = vtkImplicitBoolean::New();
491   myImplicitBoolean->SetOperationTypeToIntersection();
492 }
493
494
495 SMESH_ActorDef::~SMESH_ActorDef(){
496   if(MYDEBUG) MESSAGE("~SMESH_ActorDef");
497
498   myScalarBarActor->Delete();
499   myLookupTable->Delete();
500
501   mySurfaceProp->Delete();
502   myBackSurfaceProp->Delete();
503
504   myEdgeProp->Delete();
505   myHighlightProp->Delete();
506   myPreselectProp->Delete();
507
508   myNodeProp->Delete();
509
510   my1DProp->Delete();
511   my1DActor->Delete();
512
513   my1DExtProp->Delete();
514   my1DExtActor->Delete();
515
516   my2DActor->Delete();
517   my3DActor->Delete();
518
519   myNodeActor->Delete();
520   myBaseActor->Delete();
521
522   myHighlitableActor->Delete();
523   myNodeHighlitableActor->Delete();
524
525
526   //Deleting of pints numbering pipeline
527   //---------------------------------------
528   myPointsNumDataSet->Delete();
529
530   myPtsLabeledDataMapper->RemoveAllInputs();
531   myPtsLabeledDataMapper->Delete();
532
533   myPtsSelectVisiblePoints->UnRegisterAllOutputs();
534   myPtsSelectVisiblePoints->Delete();
535
536   myPtsMaskPoints->UnRegisterAllOutputs();
537   myPtsMaskPoints->Delete();
538
539   myPointLabels->Delete();
540
541
542   //Deleting of cells numbering pipeline
543   //---------------------------------------
544   myCellsNumDataSet->Delete();
545
546   myClsLabeledDataMapper->RemoveAllInputs();
547   myClsLabeledDataMapper->Delete();
548
549   myClsSelectVisiblePoints->UnRegisterAllOutputs();
550   myClsSelectVisiblePoints->Delete();
551
552   myClsMaskPoints->UnRegisterAllOutputs();
553   myClsMaskPoints->Delete();
554
555   myCellCenters->UnRegisterAllOutputs();
556   myCellCenters->Delete();
557
558   myCellsLabels->Delete();
559
560   myImplicitBoolean->Delete();
561
562   myTimeStamp->Delete();
563 }
564
565
566 void SMESH_ActorDef::SetPointsLabeled( bool theIsPointsLabeled )
567 {
568   vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
569   myIsPointsLabeled = theIsPointsLabeled && aGrid->GetNumberOfPoints();
570
571   if ( myIsPointsLabeled )
572   {
573     myPointsNumDataSet->ShallowCopy(aGrid);
574     vtkDataSet *aDataSet = myPointsNumDataSet;
575     
576     int aNbElem = aDataSet->GetNumberOfPoints();
577     
578     vtkIntArray *anArray = vtkIntArray::New();
579     anArray->SetNumberOfValues( aNbElem );
580     
581     for ( int anId = 0; anId < aNbElem; anId++ )
582     {
583       int aSMDSId = myVisualObj->GetNodeObjId( anId );
584       anArray->SetValue( anId, aSMDSId );
585     }
586     
587     aDataSet->GetPointData()->SetScalars( anArray );
588     anArray->Delete();
589     myPtsMaskPoints->SetInput( aDataSet );
590     myPointLabels->SetVisibility( GetVisibility() );
591   }
592   else
593   {
594     myPointLabels->SetVisibility( false );
595   }
596   SetRepresentation(GetRepresentation());
597   myTimeStamp->Modified();
598 }
599
600
601 void SMESH_ActorDef::SetCellsLabeled(bool theIsCellsLabeled){
602   vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
603   myIsCellsLabeled = theIsCellsLabeled && aGrid->GetNumberOfPoints();
604   if(myIsCellsLabeled){
605     myCellsNumDataSet->ShallowCopy(aGrid);
606     vtkDataSet *aDataSet = myCellsNumDataSet;
607     int aNbElem = aDataSet->GetNumberOfCells();
608     vtkIntArray *anArray = vtkIntArray::New();
609     anArray->SetNumberOfValues(aNbElem);
610     for(int anId = 0; anId < aNbElem; anId++){
611       int aSMDSId = myVisualObj->GetElemObjId(anId);
612       anArray->SetValue(anId,aSMDSId);
613     }
614     aDataSet->GetCellData()->SetScalars(anArray);
615     myCellCenters->SetInput(aDataSet);
616     myCellsLabels->SetVisibility(GetVisibility());
617   }else{
618     myCellsLabels->SetVisibility(false);
619   }
620   myTimeStamp->Modified();
621 }
622
623
624 void SMESH_ActorDef::SetControlMode(eControl theMode){
625   myControlMode = eNone;
626
627   my1DActor->GetMapper()->SetScalarVisibility(false);
628   my2DActor->GetMapper()->SetScalarVisibility(false);
629   my3DActor->GetMapper()->SetScalarVisibility(false);
630   myScalarBarActor->SetVisibility(false);
631
632   bool anIsScalarVisible = theMode > eNone;
633
634   if(anIsScalarVisible){
635     SMESH::Controls::FunctorPtr aFunctor;
636     switch(theMode){
637     case eLength:
638     {
639       SMESH::Controls::Length* aControl = new SMESH::Controls::Length();
640       aControl->SetPrecision( myControlsPrecision );
641       aFunctor.reset( aControl );
642       myControlActor = my1DActor;
643       break;
644     }
645     case eLength2D:
646     {
647       aFunctor.reset(new SMESH::Controls::Length2D());
648       myControlActor = my2DActor;
649       break;
650     }
651     case eFreeBorders:
652       aFunctor.reset(new SMESH::Controls::FreeBorders());
653       myControlActor = my1DActor;
654       break;
655     case eFreeEdges:
656       aFunctor.reset(new SMESH::Controls::FreeEdges());
657       myControlActor = my2DActor;
658       break;
659     case eMultiConnection:
660       aFunctor.reset(new SMESH::Controls::MultiConnection());
661       myControlActor = my1DActor;
662       break;
663     case eMultiConnection2D:
664       aFunctor.reset(new SMESH::Controls::MultiConnection2D());
665       myControlActor = my2DActor;
666       break;
667     case eArea:
668     {
669       SMESH::Controls::Area* aControl = new SMESH::Controls::Area();
670       aControl->SetPrecision( myControlsPrecision );
671       aFunctor.reset( aControl );
672       myControlActor = my2DActor;
673       break;
674     }
675     case eTaper:
676     {
677       SMESH::Controls::Taper* aControl = new SMESH::Controls::Taper();
678       aControl->SetPrecision( myControlsPrecision );
679       aFunctor.reset( aControl );
680       myControlActor = my2DActor;
681       break;
682     }
683     case eAspectRatio:
684     {
685       SMESH::Controls::AspectRatio* aControl = new SMESH::Controls::AspectRatio();
686       aControl->SetPrecision( myControlsPrecision );
687       aFunctor.reset( aControl );
688       myControlActor = my2DActor;
689       break;
690     }
691     case eAspectRatio3D:
692     {
693       SMESH::Controls::AspectRatio3D* aControl = new SMESH::Controls::AspectRatio3D();
694       aControl->SetPrecision( myControlsPrecision );
695       aFunctor.reset( aControl );
696       myControlActor = my3DActor;
697       break;
698     }
699     case eMinimumAngle:
700     {
701       SMESH::Controls::MinimumAngle* aControl = new SMESH::Controls::MinimumAngle();
702       aControl->SetPrecision( myControlsPrecision );
703       aFunctor.reset( aControl );
704       myControlActor = my2DActor;
705       break;
706     }
707     case eWarping:
708     {
709       SMESH::Controls::Warping* aControl = new SMESH::Controls::Warping();
710       aControl->SetPrecision( myControlsPrecision );
711       aFunctor.reset( aControl );
712       myControlActor = my2DActor;
713       break;
714     }
715     case eSkew:
716     {
717       SMESH::Controls::Skew* aControl = new SMESH::Controls::Skew();
718       aControl->SetPrecision( myControlsPrecision );
719       aFunctor.reset( aControl );
720       myControlActor = my2DActor;
721       break;
722     }
723     default:
724       return;
725     }
726
727     vtkUnstructuredGrid* aGrid = myControlActor->GetUnstructuredGrid();
728     vtkIdType aNbCells = aGrid->GetNumberOfCells();
729     if(aNbCells){
730       myControlMode = theMode;
731       switch(myControlMode){
732       case eFreeEdges:
733       case eFreeBorders:
734         my1DExtActor->SetExtControlMode(aFunctor,myControlActor);
735         break;
736       case eLength2D:
737         my1DExtActor->SetExtControlMode(aFunctor,myControlActor,myScalarBarActor,myLookupTable);
738         break;
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
1070     if(myIsCellsLabeled) 
1071       myCellsLabels->VisibilityOn();
1072   }
1073
1074   Modified();
1075 }
1076
1077
1078 void SMESH_ActorDef::SetEntityMode(unsigned int theMode){
1079   if(!myVisualObj->GetNbEntities(SMDSAbs_Edge))
1080     theMode &= ~eEdges;
1081
1082   if(!myVisualObj->GetNbEntities(SMDSAbs_Face))
1083     theMode &= ~eFaces;
1084
1085   if(!myVisualObj->GetNbEntities(SMDSAbs_Volume))
1086     theMode &= ~eVolumes;
1087
1088   if(!theMode)
1089     return;
1090
1091   myEntityMode = theMode;
1092
1093   SetVisibility(GetVisibility(),false);
1094 }
1095
1096 void SMESH_ActorDef::SetRepresentation(int theMode){ 
1097   int aNbEdges = myVisualObj->GetNbEntities(SMDSAbs_Edge);
1098   int aNbFaces = myVisualObj->GetNbEntities(SMDSAbs_Face);
1099   int aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume);
1100   if(theMode < 0){
1101     myRepresentation = eSurface;
1102     if(!aNbFaces && !aNbVolumes && aNbEdges){
1103       myRepresentation = eEdge;
1104     }else if(!aNbFaces && !aNbVolumes && !aNbEdges){
1105       myRepresentation = ePoint;
1106     }
1107   }else{
1108     switch(theMode){
1109     case eEdge:
1110       if(!aNbFaces && !aNbVolumes && !aNbEdges) return;
1111       break;
1112     case eSurface:
1113       if(!aNbFaces && !aNbVolumes) return;
1114       break;
1115     }    
1116     myRepresentation = theMode;
1117   }
1118
1119   if(!GetUnstructuredGrid()->GetNumberOfCells())
1120     myRepresentation = ePoint;
1121
1122   if(myIsShrunk){
1123     if(myRepresentation == ePoint){
1124       UnShrink();
1125       myIsShrunk = true;
1126     }else{
1127       SetShrink();
1128     }      
1129   }
1130
1131   myPickableActor = myBaseActor;
1132   myNodeActor->SetVisibility(false);
1133   vtkProperty *aProp = NULL, *aBackProp = NULL;
1134   SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::EReperesent(-1);
1135   switch(myRepresentation){
1136   case ePoint:
1137     myPickableActor = myNodeActor;
1138     myNodeActor->SetVisibility(true);
1139
1140     aProp = aBackProp = myNodeProp;
1141     aReperesent = SMESH_DeviceActor::ePoint;
1142     break;
1143   case eEdge:
1144     aProp = aBackProp = myEdgeProp;
1145     aReperesent = SMESH_DeviceActor::eInsideframe;
1146     break;
1147   case eSurface:
1148     aProp = mySurfaceProp;
1149     aBackProp = myBackSurfaceProp;
1150     aReperesent = SMESH_DeviceActor::eSurface;
1151     break;
1152   }    
1153
1154   my2DActor->SetProperty(aProp);
1155   my2DActor->SetBackfaceProperty(aBackProp);
1156   my2DActor->SetRepresentation(aReperesent);
1157   
1158   my3DActor->SetProperty(aProp);
1159   my3DActor->SetBackfaceProperty(aBackProp);
1160   my3DActor->SetRepresentation(aReperesent);
1161
1162   my1DExtActor->SetVisibility(false);
1163
1164   switch(myControlMode){
1165   case eLength:
1166   case eMultiConnection:
1167     aProp = aBackProp = my1DProp;
1168     if(myRepresentation != ePoint)
1169       aReperesent = SMESH_DeviceActor::eInsideframe;
1170     break;
1171   }
1172   
1173   my1DActor->SetProperty(aProp);
1174   my1DActor->SetBackfaceProperty(aBackProp);
1175   my1DActor->SetRepresentation(aReperesent);
1176
1177   my1DExtActor->SetRepresentation(aReperesent);
1178   
1179   if(myIsPointsVisible)
1180     myPickableActor = myNodeActor;
1181   if(GetPointRepresentation())
1182     myNodeActor->SetVisibility(true);
1183
1184   SetMapper(myPickableActor->GetMapper());
1185
1186   SetVisibility(GetVisibility(),false);
1187
1188   Modified();
1189 }
1190
1191
1192 void SMESH_ActorDef::SetPointRepresentation(bool theIsPointsVisible){
1193   myIsPointsVisible = theIsPointsVisible;
1194   SetRepresentation(GetRepresentation());
1195 }
1196
1197 bool SMESH_ActorDef::GetPointRepresentation(){ 
1198   return myIsPointsVisible || myIsPointsLabeled;
1199 }
1200
1201
1202 void SMESH_ActorDef::UpdateHighlight(){
1203   myHighlitableActor->SetVisibility(false);
1204   myHighlitableActor->SetHighlited(false);
1205
1206   myNodeHighlitableActor->SetVisibility(false);
1207   myNodeHighlitableActor->SetHighlited(false);
1208
1209   if(myIsHighlighted){
1210     myHighlitableActor->SetProperty(myHighlightProp);
1211   }else if(myIsPreselected){
1212     myHighlitableActor->SetProperty(myPreselectProp);
1213   }
1214
1215   bool isVisible = GetVisibility();
1216
1217   if(myIsHighlighted || myIsPreselected){
1218     if(GetUnstructuredGrid()->GetNumberOfCells()){
1219       myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
1220       myHighlitableActor->SetVisibility(isVisible);
1221       myHighlitableActor->SetHighlited(isVisible);
1222     }
1223     if(myRepresentation == ePoint || GetPointRepresentation()){
1224       myNodeHighlitableActor->SetProperty(myHighlitableActor->GetProperty());
1225       myNodeHighlitableActor->SetVisibility(isVisible);
1226       myNodeHighlitableActor->SetHighlited(isVisible);
1227     }
1228   }
1229 }
1230
1231
1232 void SMESH_ActorDef::highlight(bool theHighlight){
1233   myIsHighlighted = theHighlight;
1234   UpdateHighlight();
1235 }
1236
1237
1238 void SMESH_ActorDef::SetPreSelected(bool thePreselect){ 
1239   myIsPreselected = thePreselect; 
1240   UpdateHighlight();
1241 }
1242
1243
1244 // From vtkFollower
1245 int SMESH_ActorDef::RenderOpaqueGeometry(vtkViewport *vp)
1246 {
1247   if (myPickableActor->GetIsOpaque())
1248     {
1249     vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1250     this->Render(ren);
1251     return 1;
1252     }
1253   return 0;
1254 }
1255
1256
1257 int SMESH_ActorDef::RenderTranslucentGeometry(vtkViewport *vp)
1258 {
1259   if (!myPickableActor->GetIsOpaque())
1260     {
1261     vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1262     this->Render(ren);
1263     return 1;
1264     }
1265   return 0;
1266 }
1267
1268
1269 void SMESH_ActorDef::Render(vtkRenderer *ren){
1270   unsigned long aTime = myTimeStamp->GetMTime();
1271   unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1272   unsigned long aClippingTime = myImplicitBoolean->GetMTime();
1273   if(anObjTime > aTime || aClippingTime > aTime)
1274     Update();
1275 }
1276
1277
1278 void SMESH_ActorDef::Update(){
1279   if(MYDEBUG) MESSAGE("SMESH_ActorDef::Update");
1280
1281   if(GetControlMode() != eNone) {
1282     unsigned long aTime = myTimeStamp->GetMTime();
1283     unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1284     if (anObjTime > aTime)
1285       SetControlMode(GetControlMode());
1286   }
1287   if(myIsPointsLabeled){
1288     SetPointsLabeled(myIsPointsLabeled);
1289   }
1290   if(myIsCellsLabeled){
1291     SetCellsLabeled(myIsCellsLabeled);
1292   }
1293   SetVisibility(GetVisibility());
1294   
1295   myTimeStamp->Modified();
1296   Modified();
1297 }
1298
1299
1300 void SMESH_ActorDef::ReleaseGraphicsResources(vtkWindow *renWin){
1301   SALOME_Actor::ReleaseGraphicsResources(renWin);
1302
1303   myPickableActor->ReleaseGraphicsResources(renWin);
1304 }
1305
1306
1307 static void GetColor(vtkProperty *theProperty, float& r,float& g,float& b){
1308   float* aColor = theProperty->GetColor();
1309   r = aColor[0];
1310   g = aColor[1];
1311   b = aColor[2];
1312 }
1313
1314
1315 void SMESH_ActorDef::SetOpacity(float theValue){
1316   mySurfaceProp->SetOpacity(theValue);
1317   myBackSurfaceProp->SetOpacity(theValue);
1318   myEdgeProp->SetOpacity(theValue);
1319   myNodeProp->SetOpacity(theValue);
1320
1321   my1DProp->SetOpacity(theValue);
1322 }
1323
1324
1325 float SMESH_ActorDef::GetOpacity(){
1326   return mySurfaceProp->GetOpacity();
1327 }
1328
1329
1330 void SMESH_ActorDef::SetSufaceColor(float r,float g,float b){
1331   mySurfaceProp->SetColor(r,g,b);
1332   Modified();
1333 }
1334
1335 void SMESH_ActorDef::GetSufaceColor(float& r,float& g,float& b){
1336   ::GetColor(mySurfaceProp,r,g,b);
1337 }
1338
1339 void SMESH_ActorDef::SetBackSufaceColor(float r,float g,float b){
1340   myBackSurfaceProp->SetColor(r,g,b);
1341   Modified();
1342 }
1343
1344 void SMESH_ActorDef::GetBackSufaceColor(float& r,float& g,float& b){
1345   ::GetColor(myBackSurfaceProp,r,g,b);
1346 }
1347
1348 void SMESH_ActorDef::SetEdgeColor(float r,float g,float b){
1349   myEdgeProp->SetColor(r,g,b);
1350   my1DProp->SetColor(r,g,b);
1351   my1DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1352   Modified();
1353 }
1354
1355 void SMESH_ActorDef::GetEdgeColor(float& r,float& g,float& b){
1356   ::GetColor(myEdgeProp,r,g,b);
1357 }
1358
1359 void SMESH_ActorDef::SetNodeColor(float r,float g,float b){ 
1360   myNodeProp->SetColor(r,g,b);
1361   Modified();
1362 }
1363
1364 void SMESH_ActorDef::GetNodeColor(float& r,float& g,float& b){ 
1365   ::GetColor(myNodeProp,r,g,b);
1366 }
1367
1368 void SMESH_ActorDef::SetHighlightColor(float r,float g,float b){ 
1369   myHighlightProp->SetColor(r,g,b);
1370   Modified();
1371 }
1372
1373 void SMESH_ActorDef::GetHighlightColor(float& r,float& g,float& b){ 
1374   ::GetColor(myHighlightProp,r,g,b);
1375 }
1376
1377 void SMESH_ActorDef::SetPreHighlightColor(float r,float g,float b){ 
1378   myPreselectProp->SetColor(r,g,b);
1379   Modified();
1380 }
1381
1382 void SMESH_ActorDef::GetPreHighlightColor(float& r,float& g,float& b){ 
1383   ::GetColor(myPreselectProp,r,g,b);
1384 }
1385
1386
1387 float SMESH_ActorDef::GetLineWidth(){
1388   return myEdgeProp->GetLineWidth();
1389 }
1390
1391
1392 void SMESH_ActorDef::SetLineWidth(float theVal){
1393   myEdgeProp->SetLineWidth(theVal);
1394
1395   my1DProp->SetLineWidth(theVal + aLineWidthInc);
1396   my1DExtProp->SetLineWidth(theVal + aLineWidthInc);
1397
1398   Modified();
1399 }
1400
1401
1402 void SMESH_ActorDef::SetNodeSize(float theVal){
1403   myNodeProp->SetPointSize(theVal);
1404   myHighlightProp->SetPointSize(theVal);
1405   myPreselectProp->SetPointSize(theVal);
1406
1407   my1DProp->SetPointSize(theVal + aPointSizeInc);
1408   my1DExtProp->SetPointSize(theVal + aPointSizeInc);
1409
1410   Modified();
1411 }
1412
1413 float SMESH_ActorDef::GetNodeSize(){
1414   return myNodeProp->GetPointSize();
1415 }
1416
1417 int SMESH_ActorDef::GetObjDimension( const int theObjId )
1418 {
1419   return myVisualObj->GetElemDimension( theObjId );
1420 }
1421
1422
1423 vtkImplicitBoolean* SMESH_ActorDef::GetPlaneContainer(){
1424   return myImplicitBoolean;
1425 }
1426
1427
1428 static void ComputeBoundsParam(vtkDataSet* theDataSet,
1429                                float theDirection[3], float theMinPnt[3],
1430                                float& theMaxBoundPrj, float& theMinBoundPrj)
1431 {
1432   float aBounds[6];
1433   theDataSet->GetBounds(aBounds);
1434
1435   //Enlarge bounds in order to avoid conflicts of precision
1436   for(int i = 0; i < 6; i += 2){
1437     static double EPS = 1.0E-3;
1438     float aDelta = (aBounds[i+1] - aBounds[i])*EPS;
1439     aBounds[i] -= aDelta;
1440     aBounds[i+1] += aDelta;
1441   }
1442
1443   float aBoundPoints[8][3] = { {aBounds[0],aBounds[2],aBounds[4]},
1444                                {aBounds[1],aBounds[2],aBounds[4]},
1445                                {aBounds[0],aBounds[3],aBounds[4]},
1446                                {aBounds[1],aBounds[3],aBounds[4]},
1447                                {aBounds[0],aBounds[2],aBounds[5]},
1448                                {aBounds[1],aBounds[2],aBounds[5]}, 
1449                                {aBounds[0],aBounds[3],aBounds[5]}, 
1450                                {aBounds[1],aBounds[3],aBounds[5]}};
1451
1452   int aMaxId = 0, aMinId = aMaxId;
1453   theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
1454   theMinBoundPrj = theMaxBoundPrj;
1455   for(int i = 1; i < 8; i++){
1456     float aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
1457     if(theMaxBoundPrj < aTmp){
1458       theMaxBoundPrj = aTmp;
1459       aMaxId = i;
1460     }
1461     if(theMinBoundPrj > aTmp){
1462       theMinBoundPrj = aTmp;
1463       aMinId = i;
1464     }
1465   }
1466   float *aMinPnt = aBoundPoints[aMaxId];
1467   theMinPnt[0] = aMinPnt[0];
1468   theMinPnt[1] = aMinPnt[1];
1469   theMinPnt[2] = aMinPnt[2];
1470 }
1471
1472
1473 static void DistanceToPosition(vtkDataSet* theDataSet,
1474                                float theDirection[3], float theDist, float thePos[3])
1475 {
1476   float aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1477   ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1478   float aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
1479   thePos[0] = aMinPnt[0]-theDirection[0]*aLength;
1480   thePos[1] = aMinPnt[1]-theDirection[1]*aLength;
1481   thePos[2] = aMinPnt[2]-theDirection[2]*aLength;
1482 }
1483
1484
1485 static void PositionToDistance(vtkDataSet* theDataSet, 
1486                                float theDirection[3], float thePos[3], float& theDist)
1487 {
1488   float aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1489   ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1490   float aPrj = vtkMath::Dot(theDirection,thePos);
1491   theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
1492 }
1493
1494
1495 void SMESH_ActorDef::SetPlaneParam(float theDir[3], float theDist, vtkPlane* thePlane)
1496 {
1497   thePlane->SetNormal(theDir);
1498   float anOrigin[3];
1499   ::DistanceToPosition(GetUnstructuredGrid(),theDir,theDist,anOrigin);
1500   thePlane->SetOrigin(anOrigin);
1501 }
1502
1503
1504 void SMESH_ActorDef::GetPlaneParam(float theDir[3], float& theDist, vtkPlane* thePlane)
1505 {
1506   thePlane->GetNormal(theDir);
1507
1508   float anOrigin[3];
1509   thePlane->GetOrigin(anOrigin);
1510   ::PositionToDistance(GetUnstructuredGrid(),theDir,anOrigin,theDist);
1511 }