Salome HOME
Merge with version on tag OCC-V2_1_0d
[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_Actor.h"
31 #include "SMESH_ActorUtils.h"
32 #include "SMESH_DeviceActor.h"
33 #include "SALOME_ExtractUnstructuredGrid.h"
34
35 #include "QAD_Config.h"
36 #include "utilities.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 #ifdef _DEBUG_
73 static int MYDEBUG = 0;
74 static int MYDEBUGWITHFILES = 0;
75 #else
76 static int MYDEBUG = 0;
77 static int MYDEBUGWITHFILES = 0;
78 #endif
79
80 static int aLineWidthInc = 2;
81 static int aPointSizeInc = 2;
82
83
84 SMESH_Actor* SMESH_Actor::New(){
85   return new SMESH_Actor();
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_Actor* anActor = SMESH_Actor::New();
95   if(!anActor->Init(theVisualObj,theEntry,theName,theIsClear)){
96     anActor->Delete();
97     anActor = NULL;
98   }
99   return anActor;
100 }
101
102
103 SMESH_Actor::SMESH_Actor(){
104   if(MYDEBUG) MESSAGE("SMESH_Actor");
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   myColorMode = eNone;
288   my1DColorMode = e1DNone;
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   myIsPointsLabeled = false;
443
444   myPointLabels = vtkActor2D::New();
445   myPointLabels->SetMapper(myPtsLabeledDataMapper);
446   myPointLabels->GetProperty()->SetColor(1,1,1);
447   myPointLabels->SetVisibility(myIsPointsLabeled);
448
449
450   //Definition of cells numbering pipeline
451   //---------------------------------------
452   myCellsNumDataSet = vtkUnstructuredGrid::New();
453
454   myCellCenters = vtkCellCenters::New();
455   myCellCenters->SetInput(myCellsNumDataSet);
456
457   myClsMaskPoints = vtkMaskPoints::New();
458   myClsMaskPoints->SetInput(myCellCenters->GetOutput());
459   myClsMaskPoints->SetOnRatio(1);
460     
461   myClsSelectVisiblePoints = vtkSelectVisiblePoints::New();
462   myClsSelectVisiblePoints->SetInput(myClsMaskPoints->GetOutput());
463   myClsSelectVisiblePoints->SelectInvisibleOff();
464   myClsSelectVisiblePoints->SetTolerance(0.1);
465     
466   myClsLabeledDataMapper = vtkLabeledDataMapper::New();
467   myClsLabeledDataMapper->SetInput(myClsSelectVisiblePoints->GetOutput());
468   myClsLabeledDataMapper->SetLabelFormat("%g");
469   myClsLabeledDataMapper->SetLabelModeToLabelScalars();
470     
471   vtkTextProperty* aClsTextProp = vtkTextProperty::New();
472   aClsTextProp->SetFontFamilyToTimes();
473   static int aCellsFontSize = 12;
474   aClsTextProp->SetFontSize(aCellsFontSize);
475   aClsTextProp->SetBold(1);
476   aClsTextProp->SetItalic(0);
477   aClsTextProp->SetShadow(0);
478   myClsLabeledDataMapper->SetLabelTextProperty(aClsTextProp);
479   aClsTextProp->Delete();
480     
481   myIsCellsLabeled = false;
482
483   myCellsLabels = vtkActor2D::New();
484   myCellsLabels->SetMapper(myClsLabeledDataMapper);
485   myCellsLabels->GetProperty()->SetColor(0,1,0);
486   myCellsLabels->SetVisibility(myIsCellsLabeled);
487
488   // Clipping planes
489   myImplicitBoolean = vtkImplicitBoolean::New();
490   myImplicitBoolean->SetOperationTypeToIntersection();
491 }
492
493
494 SMESH_Actor::~SMESH_Actor(){
495   if(MYDEBUG) MESSAGE("~SMESH_Actor");
496
497   myScalarBarActor->Delete();
498   myLookupTable->Delete();
499
500   mySurfaceProp->Delete();
501   myBackSurfaceProp->Delete();
502
503   myEdgeProp->Delete();
504   myHighlightProp->Delete();
505   myPreselectProp->Delete();
506
507   myNodeProp->Delete();
508
509   my1DProp->Delete();
510   my1DActor->Delete();
511
512   my1DExtProp->Delete();
513   my1DExtActor->Delete();
514
515   my2DActor->Delete();
516   my3DActor->Delete();
517
518   myNodeActor->Delete();
519   myBaseActor->Delete();
520
521   myHighlitableActor->Delete();
522   myNodeHighlitableActor->Delete();
523
524
525   //Deleting of pints numbering pipeline
526   //---------------------------------------
527   myPointsNumDataSet->Delete();
528
529   myPtsLabeledDataMapper->RemoveAllInputs();
530   myPtsLabeledDataMapper->Delete();
531
532   myPtsSelectVisiblePoints->UnRegisterAllOutputs();
533   myPtsSelectVisiblePoints->Delete();
534
535   myPtsMaskPoints->UnRegisterAllOutputs();
536   myPtsMaskPoints->Delete();
537
538   myPointLabels->Delete();
539
540
541   //Deleting of cells numbering pipeline
542   //---------------------------------------
543   myCellsNumDataSet->Delete();
544
545   myClsLabeledDataMapper->RemoveAllInputs();
546   myClsLabeledDataMapper->Delete();
547
548   myClsSelectVisiblePoints->UnRegisterAllOutputs();
549   myClsSelectVisiblePoints->Delete();
550
551   myClsMaskPoints->UnRegisterAllOutputs();
552   myClsMaskPoints->Delete();
553
554   myCellCenters->UnRegisterAllOutputs();
555   myCellCenters->Delete();
556
557   myCellsLabels->Delete();
558
559   myImplicitBoolean->Delete();
560
561   myTimeStamp->Delete();
562 }
563
564
565 void SMESH_Actor::SetPointsLabeled( bool theIsPointsLabeled )
566 {
567   vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
568   myIsPointsLabeled = theIsPointsLabeled && aGrid->GetNumberOfPoints();
569
570   if ( myIsPointsLabeled )
571   {
572     myPointsNumDataSet->ShallowCopy(aGrid);
573     vtkDataSet *aDataSet = myPointsNumDataSet;
574     
575     int aNbElem = aDataSet->GetNumberOfPoints();
576     
577     vtkIntArray *anArray = vtkIntArray::New();
578     anArray->SetNumberOfValues( aNbElem );
579     
580     for ( int anId = 0; anId < aNbElem; anId++ )
581     {
582       int aSMDSId = myVisualObj->GetNodeObjId( anId );
583       anArray->SetValue( anId, aSMDSId );
584     }
585     
586     aDataSet->GetPointData()->SetScalars( anArray );
587     anArray->Delete();
588     myPtsMaskPoints->SetInput( aDataSet );
589     myPointLabels->SetVisibility( GetVisibility() );
590   }
591   else
592   {
593     myPointLabels->SetVisibility( false );
594   }
595   SetRepresentation(GetRepresentation());
596   myTimeStamp->Modified();
597 }
598
599
600 void SMESH_Actor::SetCellsLabeled(bool theIsCellsLabeled){
601   vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
602   myIsCellsLabeled = theIsCellsLabeled && aGrid->GetNumberOfPoints();
603   if(myIsCellsLabeled){
604     myCellsNumDataSet->ShallowCopy(aGrid);
605     vtkDataSet *aDataSet = myCellsNumDataSet;
606     int aNbElem = aDataSet->GetNumberOfCells();
607     vtkIntArray *anArray = vtkIntArray::New();
608     anArray->SetNumberOfValues(aNbElem);
609     for(int anId = 0; anId < aNbElem; anId++){
610       int aSMDSId = myVisualObj->GetElemObjId(anId);
611       anArray->SetValue(anId,aSMDSId);
612     }
613     aDataSet->GetCellData()->SetScalars(anArray);
614     myCellCenters->SetInput(aDataSet);
615     myCellsLabels->SetVisibility(GetVisibility());
616   }else{
617     myCellsLabels->SetVisibility(false);
618   }
619   myTimeStamp->Modified();
620 }
621
622
623 void SMESH_Actor::SetControlMode(eControl theMode){
624   myColorMode = eNone;
625   my1DColorMode = e1DNone;
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 eLengthEdges:
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 eFreeBorders:
646       aFunctor.reset(new SMESH::Controls::FreeBorders());
647       myControlActor = my1DActor;
648       break;
649     case eFreeEdges:
650       aFunctor.reset(new SMESH::Controls::FreeEdges());
651       myControlActor = my2DActor;
652       break;
653     case eMultiConnection:
654       aFunctor.reset(new SMESH::Controls::MultiConnection());
655       myControlActor = my1DActor;
656       break;
657     case eArea:
658     {
659       SMESH::Controls::Area* aControl = new SMESH::Controls::Area();
660       aControl->SetPrecision( myControlsPrecision );
661       aFunctor.reset( aControl );
662       myControlActor = my2DActor;
663       break;
664     }
665     case eTaper:
666     {
667       SMESH::Controls::Taper* aControl = new SMESH::Controls::Taper();
668       aControl->SetPrecision( myControlsPrecision );
669       aFunctor.reset( aControl );
670       myControlActor = my2DActor;
671       break;
672     }
673     case eAspectRatio:
674     {
675       SMESH::Controls::AspectRatio* aControl = new SMESH::Controls::AspectRatio();
676       aControl->SetPrecision( myControlsPrecision );
677       aFunctor.reset( aControl );
678       myControlActor = my2DActor;
679       break;
680     }
681     case eMinimumAngle:
682     {
683       SMESH::Controls::MinimumAngle* aControl = new SMESH::Controls::MinimumAngle();
684       aControl->SetPrecision( myControlsPrecision );
685       aFunctor.reset( aControl );
686       myControlActor = my2DActor;
687       break;
688     }
689     case eWarping:
690     {
691       SMESH::Controls::Warping* aControl = new SMESH::Controls::Warping();
692       aControl->SetPrecision( myControlsPrecision );
693       aFunctor.reset( aControl );
694       myControlActor = my2DActor;
695       break;
696     }
697     case eSkew:
698     {
699       SMESH::Controls::Skew* aControl = new SMESH::Controls::Skew();
700       aControl->SetPrecision( myControlsPrecision );
701       aFunctor.reset( aControl );
702       myControlActor = my2DActor;
703       break;
704     }
705     default:
706       return;
707     }
708
709     vtkUnstructuredGrid* aGrid = myControlActor->GetUnstructuredGrid();
710     vtkIdType aNbCells = aGrid->GetNumberOfCells();
711     if(aNbCells){
712       myColorMode = theMode;
713       if(theMode == eFreeBorders || theMode == eFreeEdges){
714         my1DColorMode = e1DHighlited;
715         my1DExtActor->SetExtControlMode(aFunctor,myControlActor);
716       }else{
717         if(myControlActor == my1DActor)
718           my1DColorMode = e1DColored;
719         myControlActor->SetControlMode(aFunctor,myScalarBarActor,myLookupTable);
720       }
721     }
722   }
723   SetRepresentation(GetRepresentation());
724
725   myTimeStamp->Modified();
726   Modified();
727 }
728
729
730 void SMESH_Actor::AddToRender(vtkRenderer* theRenderer){
731   SALOME_Actor::AddToRender(theRenderer);
732
733   theRenderer->AddActor(myNodeActor);
734   theRenderer->AddActor(myBaseActor);
735
736   theRenderer->AddActor(my3DActor);
737   theRenderer->AddActor(my2DActor);
738
739   theRenderer->AddActor(my1DActor);
740   theRenderer->AddActor(my1DExtActor);
741
742   theRenderer->AddActor(myHighlitableActor);
743   theRenderer->AddActor(myNodeHighlitableActor);
744
745   theRenderer->AddActor2D(myScalarBarActor);
746
747   myPtsSelectVisiblePoints->SetRenderer(theRenderer);
748   myClsSelectVisiblePoints->SetRenderer(theRenderer);
749
750   theRenderer->AddActor2D(myPointLabels);
751   theRenderer->AddActor2D(myCellsLabels);
752 }
753
754 void SMESH_Actor::RemoveFromRender(vtkRenderer* theRenderer){
755   SALOME_Actor::RemoveFromRender(theRenderer);
756
757   theRenderer->RemoveActor(myNodeActor);
758   theRenderer->RemoveActor(myBaseActor);
759
760   theRenderer->RemoveActor(myHighlitableActor);
761   theRenderer->RemoveActor(myNodeHighlitableActor);
762
763   theRenderer->RemoveActor(my1DActor);
764   theRenderer->RemoveActor(my1DExtActor);
765
766   theRenderer->RemoveActor(my2DActor);
767   theRenderer->RemoveActor(my3DActor);
768
769   theRenderer->RemoveActor(myScalarBarActor);
770   theRenderer->RemoveActor(myPointLabels);
771   theRenderer->RemoveActor(myCellsLabels);
772 }
773
774
775 bool SMESH_Actor::Init(TVisualObjPtr theVisualObj, 
776                        const char* theEntry, 
777                        const char* theName,
778                        int theIsClear)
779 {
780   Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry,"SMESH",theName);
781   setIO(anIO);
782   setName(theName);
783
784   myVisualObj = theVisualObj;
785   myNodeActor->myVisualObj = myVisualObj;
786   myBaseActor->myVisualObj = myVisualObj;
787
788   myHighlitableActor->myVisualObj = myVisualObj;
789   myNodeHighlitableActor->myVisualObj = myVisualObj;
790
791   my1DActor->myVisualObj = myVisualObj;
792   my1DExtActor->myVisualObj = myVisualObj;
793
794   my2DActor->myVisualObj = myVisualObj;
795   my3DActor->myVisualObj = myVisualObj;
796
797   myVisualObj->Update(theIsClear);
798
799   myNodeActor->Init(myVisualObj,myImplicitBoolean);
800   myBaseActor->Init(myVisualObj,myImplicitBoolean);
801   
802   myHighlitableActor->Init(myVisualObj,myImplicitBoolean);
803   myNodeHighlitableActor->Init(myVisualObj,myImplicitBoolean);
804   
805   my1DActor->Init(myVisualObj,myImplicitBoolean);
806   my1DExtActor->Init(myVisualObj,myImplicitBoolean);
807   
808   my2DActor->Init(myVisualObj,myImplicitBoolean);
809   my3DActor->Init(myVisualObj,myImplicitBoolean);
810   
811   my1DActor->GetMapper()->SetLookupTable(myLookupTable);
812   my2DActor->GetMapper()->SetLookupTable(myLookupTable);
813   my3DActor->GetMapper()->SetLookupTable(myLookupTable);
814     
815   float aFactor, aUnits;
816   my2DActor->GetPolygonOffsetParameters(aFactor,aUnits);
817   my2DActor->SetPolygonOffsetParameters(aFactor,aUnits*0.75);
818
819   //SetIsShrunkable(theGrid->GetNumberOfCells() > 10);
820   SetIsShrunkable(true);
821   
822   QString aMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
823   SetRepresentation(-1);
824   if(aMode.compare("Wireframe") == 0){
825     SetRepresentation(eEdge);
826   }else if(aMode.compare("Shading") == 0){
827     SetRepresentation(eSurface);
828   }else if(aMode.compare("Nodes") == 0){
829     SetRepresentation(ePoint);
830   }
831
832   aMode = QAD_CONFIG->getSetting("SMESH:Shrink");
833   if(aMode == "yes"){
834     SetShrink();
835   }
836
837   myTimeStamp->Modified();
838   Modified();
839   return true;
840 }
841
842
843 float* SMESH_Actor::GetBounds(){
844   return myNodeActor->GetBounds();
845 }
846
847
848 vtkDataSet* SMESH_Actor::GetInput(){
849   return GetUnstructuredGrid();
850 }
851
852
853 void SMESH_Actor::SetTransform(SALOME_Transform* theTransform){
854   myNodeActor->SetTransform(theTransform);
855   myBaseActor->SetTransform(theTransform);
856
857   myHighlitableActor->SetTransform(theTransform);
858   myNodeHighlitableActor->SetTransform(theTransform);
859
860   my1DActor->SetTransform(theTransform);
861   my1DExtActor->SetTransform(theTransform);
862
863   my2DActor->SetTransform(theTransform);
864   my3DActor->SetTransform(theTransform);
865
866   Modified();
867 }
868
869
870 void SMESH_Actor::SetMapper(vtkMapper* theMapper){
871   vtkLODActor::SetMapper(theMapper);
872 }
873
874
875 void SMESH_Actor::ShallowCopy(vtkProp *prop){
876   SALOME_Actor::ShallowCopy(prop);
877 }
878
879
880 vtkMapper* SMESH_Actor::GetMapper(){
881   return myPickableActor->GetMapper();
882 }
883
884
885 vtkUnstructuredGrid* SMESH_Actor::GetUnstructuredGrid(){ 
886   return myVisualObj->GetUnstructuredGrid();
887 }
888
889
890 bool SMESH_Actor::IsInfinitive(){
891   vtkDataSet *aDataSet = myPickableActor->GetUnstructuredGrid();
892   aDataSet->Update();
893   myIsInfinite = aDataSet->GetNumberOfCells() == 0 ||
894     aDataSet->GetNumberOfCells() == 1 && 
895     aDataSet->GetCell(0)->GetCellType() == VTK_VERTEX;
896   return SALOME_Actor::IsInfinitive();
897 }
898
899
900 void SMESH_Actor::SetIsShrunkable(bool theShrunkable){
901   myIsShrinkable = theShrunkable;
902   Modified();
903 }
904
905 float SMESH_Actor::GetShrinkFactor(){
906   return myBaseActor->GetShrinkFactor();
907 }
908
909 void SMESH_Actor::SetShrinkFactor(float theValue){
910   myBaseActor->SetShrinkFactor(theValue);
911
912   my1DActor->SetShrinkFactor(theValue);
913   my1DExtActor->SetShrinkFactor(theValue);
914
915   my2DActor->SetShrinkFactor(theValue);
916   my3DActor->SetShrinkFactor(theValue);
917
918   Modified();
919 }
920
921 void SMESH_Actor::SetShrink(){
922   if(!myIsShrinkable) return;
923
924   myBaseActor->SetShrink();
925
926   my1DActor->SetShrink();
927   my1DExtActor->SetShrink();
928
929   my2DActor->SetShrink();
930   my3DActor->SetShrink();
931
932   myIsShrunk = true;
933   Modified();
934 }
935
936 void SMESH_Actor::UnShrink(){
937   if(!myIsShrunk) return;
938
939   myBaseActor->UnShrink();
940
941   my1DActor->UnShrink();
942   my1DExtActor->UnShrink();
943
944   my2DActor->UnShrink();
945   my3DActor->UnShrink();
946
947   myIsShrunk = false;
948   Modified();
949 }
950
951
952 int SMESH_Actor::GetNodeObjId(int theVtkID){
953   return myPickableActor->GetNodeObjId(theVtkID);
954 }
955
956 float* SMESH_Actor::GetNodeCoord(int theObjID){
957   return myPickableActor->GetNodeCoord(theObjID);
958 }
959
960
961 int SMESH_Actor::GetElemObjId(int theVtkID){
962   return myPickableActor->GetElemObjId(theVtkID);
963 }
964
965 vtkCell* SMESH_Actor::GetElemCell(int theObjID){
966   return myPickableActor->GetElemCell(theObjID);
967 }
968
969
970 void SMESH_Actor::SetVisibility(int theMode){
971   SetVisibility(theMode,true);
972 }
973
974
975 void SMESH_Actor::SetVisibility(int theMode, bool theIsUpdateRepersentation){
976   SALOME_Actor::SetVisibility(theMode);
977   if(GetVisibility()){
978     if(theIsUpdateRepersentation)
979       SetRepresentation(GetRepresentation());
980
981     if(myColorMode != eNone){
982       if(my1DColorMode == e1DHighlited)
983         my1DExtActor->VisibilityOn();
984       else if(myControlActor->GetUnstructuredGrid()->GetNumberOfCells())
985         myScalarBarActor->VisibilityOn();
986     }
987
988     if(myRepresentation != ePoint)
989       myPickableActor->VisibilityOn();
990
991     my1DActor->VisibilityOn();
992
993     my2DActor->VisibilityOn();
994     my3DActor->VisibilityOn();
995
996     if(myIsPointsLabeled) myPointLabels->VisibilityOn();
997     if(myIsCellsLabeled) myCellsLabels->VisibilityOn();
998   }else{
999     myNodeActor->VisibilityOff();
1000     myBaseActor->VisibilityOff();
1001
1002     my1DActor->VisibilityOff();
1003     my1DExtActor->VisibilityOff();
1004
1005     my2DActor->VisibilityOff();
1006     my3DActor->VisibilityOff();
1007
1008     myScalarBarActor->VisibilityOff();
1009     myPointLabels->VisibilityOff();
1010     myCellsLabels->VisibilityOff();
1011   }
1012   Modified();
1013 }
1014
1015
1016 void SMESH_Actor::SetRepresentation(int theMode){ 
1017   int aNbEdges = myVisualObj->GetNbEntities(SMESH::EDGE);
1018   int aNbFaces = myVisualObj->GetNbEntities(SMESH::FACE);
1019   int aNbVolumes = myVisualObj->GetNbEntities(SMESH::VOLUME);
1020   if(theMode < 0){
1021     myRepresentation = eSurface;
1022     if(!aNbFaces && !aNbVolumes && aNbEdges){
1023       myRepresentation = eEdge;
1024     }else if(!aNbFaces && !aNbVolumes && !aNbEdges){
1025       myRepresentation = ePoint;
1026     }
1027   }else{
1028     switch(theMode){
1029     case eEdge:
1030       if(!aNbFaces && !aNbVolumes && !aNbEdges) return;
1031       break;
1032     case eSurface:
1033       if(!aNbFaces && !aNbVolumes) return;
1034       break;
1035     }    
1036     myRepresentation = theMode;
1037   }
1038
1039   if(!GetUnstructuredGrid()->GetNumberOfCells())
1040     myRepresentation = ePoint;
1041
1042   if(myIsShrunk){
1043     if(myRepresentation == ePoint){
1044       UnShrink();
1045       myIsShrunk = true;
1046     }else{
1047       SetShrink();
1048     }      
1049   }
1050
1051   myPickableActor = myBaseActor;
1052   myNodeActor->SetVisibility(false);
1053   vtkProperty *aProp = NULL, *aBackProp = NULL;
1054   SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::EReperesent(-1);
1055   switch(myRepresentation){
1056   case ePoint: 
1057     myPickableActor = myNodeActor;
1058     myNodeActor->SetVisibility(true);
1059
1060     aProp = aBackProp = myNodeProp;
1061     aReperesent = SMESH_DeviceActor::ePoint;
1062     break;
1063   case eEdge:
1064     aProp = aBackProp = myEdgeProp;
1065     aReperesent = SMESH_DeviceActor::eInsideframe;
1066     break;
1067   case eSurface:
1068     aProp = mySurfaceProp;
1069     aBackProp = myBackSurfaceProp;
1070     aReperesent = SMESH_DeviceActor::eSurface;
1071     break;
1072   }    
1073
1074   my2DActor->SetProperty(aProp);
1075   my2DActor->SetBackfaceProperty(aBackProp);
1076   my2DActor->SetRepresentation(aReperesent);
1077   
1078   my3DActor->SetProperty(aProp);
1079   my3DActor->SetBackfaceProperty(aBackProp);
1080   my3DActor->SetRepresentation(aReperesent);
1081
1082   my1DExtActor->SetVisibility(false);
1083   switch(my1DColorMode){
1084   case e1DColored: 
1085     aProp = aBackProp = my1DProp;
1086     if(myRepresentation != ePoint)
1087       aReperesent = SMESH_DeviceActor::eInsideframe;
1088     break;
1089   case e1DHighlited: 
1090     my1DExtActor->SetVisibility(true);
1091     break;
1092   }
1093   
1094   my1DActor->SetProperty(aProp);
1095   my1DActor->SetBackfaceProperty(aBackProp);
1096   my1DActor->SetRepresentation(aReperesent);
1097
1098   my1DExtActor->SetRepresentation(aReperesent);
1099   
1100   if(myIsPointsVisible)
1101     myPickableActor = myNodeActor;
1102
1103   if(GetPointRepresentation())
1104     myNodeActor->SetVisibility(true);
1105
1106   SetMapper(myPickableActor->GetMapper());
1107
1108   SetVisibility(GetVisibility(),false);
1109
1110   Modified();
1111 }
1112
1113
1114 void SMESH_Actor::SetPointRepresentation(bool theIsPointsVisible){
1115   myIsPointsVisible = theIsPointsVisible;
1116   SetRepresentation(GetRepresentation());
1117 }
1118
1119 bool SMESH_Actor::GetPointRepresentation(){ 
1120   return myIsPointsVisible || myIsPointsLabeled;
1121 }
1122
1123
1124 void SMESH_Actor::UpdateHighlight(){
1125   myHighlitableActor->SetVisibility(false);
1126   myHighlitableActor->SetHighlited(false);
1127
1128   myNodeHighlitableActor->SetVisibility(false);
1129   myNodeHighlitableActor->SetHighlited(false);
1130
1131   if(myIsHighlighted){
1132     myHighlitableActor->SetProperty(myHighlightProp);
1133   }else if(myIsPreselected){
1134     myHighlitableActor->SetProperty(myPreselectProp);
1135   }
1136
1137   bool isVisible = GetVisibility();
1138
1139   if(myIsHighlighted || myIsPreselected){
1140     if(GetUnstructuredGrid()->GetNumberOfCells()){
1141       myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
1142       myHighlitableActor->SetVisibility(isVisible);
1143       myHighlitableActor->SetHighlited(isVisible);
1144     }
1145     if(myRepresentation == ePoint || GetPointRepresentation()){
1146       myNodeHighlitableActor->SetProperty(myHighlitableActor->GetProperty());
1147       myNodeHighlitableActor->SetVisibility(isVisible);
1148       myNodeHighlitableActor->SetHighlited(isVisible);
1149     }
1150   }
1151 }
1152
1153
1154 void SMESH_Actor::highlight(bool theHighlight){
1155   myIsHighlighted = theHighlight;
1156   UpdateHighlight();
1157 }
1158
1159
1160 void SMESH_Actor::SetPreSelected(bool thePreselect){ 
1161   myIsPreselected = thePreselect; 
1162   UpdateHighlight();
1163 }
1164
1165
1166 // From vtkFollower
1167 int SMESH_Actor::RenderOpaqueGeometry(vtkViewport *vp)
1168 {
1169   if (myPickableActor->GetIsOpaque())
1170     {
1171     vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1172     this->Render(ren);
1173     return 1;
1174     }
1175   return 0;
1176 }
1177
1178
1179 int SMESH_Actor::RenderTranslucentGeometry(vtkViewport *vp)
1180 {
1181   if (!myPickableActor->GetIsOpaque())
1182     {
1183     vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1184     this->Render(ren);
1185     return 1;
1186     }
1187   return 0;
1188 }
1189
1190
1191 void SMESH_Actor::Render(vtkRenderer *ren){
1192   unsigned long mTime = myTimeStamp->GetMTime();
1193   unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1194   if(anObjTime > mTime)
1195     Update();
1196 }
1197
1198
1199 void SMESH_Actor::Update(){
1200   SetVisibility(GetVisibility());
1201   unsigned long int anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1202   unsigned long int aClippingTime = myImplicitBoolean->GetMTime();
1203   unsigned long int aTime = myTimeStamp->GetMTime();
1204   if(MYDEBUG) MESSAGE("SMESH_Actor::Update");
1205
1206   if(GetControlMode() != eNone) {
1207     if(anObjTime > aTime || aClippingTime > aTime){
1208       SetControlMode(GetControlMode());
1209       SetVisibility(GetVisibility());
1210     }
1211   }
1212   if(myIsPointsLabeled){
1213     if(anObjTime > aTime || aClippingTime > aTime)
1214       SetPointsLabeled(myIsPointsLabeled);
1215   }
1216   if(myIsCellsLabeled){
1217     if(anObjTime > aTime || aClippingTime > aTime)
1218       SetCellsLabeled(myIsCellsLabeled);
1219   }
1220
1221   myTimeStamp->Modified();
1222   Modified();
1223 }
1224
1225
1226 void SMESH_Actor::ReleaseGraphicsResources(vtkWindow *renWin){
1227   SALOME_Actor::ReleaseGraphicsResources(renWin);
1228
1229   myPickableActor->ReleaseGraphicsResources(renWin);
1230 }
1231
1232
1233 static void GetColor(vtkProperty *theProperty, float& r,float& g,float& b){
1234   float* aColor = theProperty->GetColor();
1235   r = aColor[0];
1236   g = aColor[1];
1237   b = aColor[2];
1238 }
1239
1240
1241 void SMESH_Actor::SetOpacity(float theValue){
1242   mySurfaceProp->SetOpacity(theValue);
1243   myBackSurfaceProp->SetOpacity(theValue);
1244   myEdgeProp->SetOpacity(theValue);
1245   myNodeProp->SetOpacity(theValue);
1246
1247   my1DProp->SetOpacity(theValue);
1248 }
1249
1250
1251 float SMESH_Actor::GetOpacity(){
1252   return mySurfaceProp->GetOpacity();
1253 }
1254
1255
1256 void SMESH_Actor::SetSufaceColor(float r,float g,float b){
1257   mySurfaceProp->SetColor(r,g,b);
1258   Modified();
1259 }
1260
1261 void SMESH_Actor::GetSufaceColor(float& r,float& g,float& b){
1262   ::GetColor(mySurfaceProp,r,g,b);
1263 }
1264
1265 void SMESH_Actor::SetBackSufaceColor(float r,float g,float b){
1266   myBackSurfaceProp->SetColor(r,g,b);
1267   Modified();
1268 }
1269
1270 void SMESH_Actor::GetBackSufaceColor(float& r,float& g,float& b){
1271   ::GetColor(myBackSurfaceProp,r,g,b);
1272 }
1273
1274 void SMESH_Actor::SetEdgeColor(float r,float g,float b){
1275   myEdgeProp->SetColor(r,g,b);
1276   my1DProp->SetColor(r,g,b);
1277   my1DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1278   Modified();
1279 }
1280
1281 void SMESH_Actor::GetEdgeColor(float& r,float& g,float& b){
1282   ::GetColor(myEdgeProp,r,g,b);
1283 }
1284
1285 void SMESH_Actor::SetNodeColor(float r,float g,float b){ 
1286   myNodeProp->SetColor(r,g,b);
1287   Modified();
1288 }
1289
1290 void SMESH_Actor::GetNodeColor(float& r,float& g,float& b){ 
1291   ::GetColor(myNodeProp,r,g,b);
1292 }
1293
1294 void SMESH_Actor::SetHighlightColor(float r,float g,float b){ 
1295   myHighlightProp->SetColor(r,g,b);
1296   Modified();
1297 }
1298
1299 void SMESH_Actor::GetHighlightColor(float& r,float& g,float& b){ 
1300   ::GetColor(myHighlightProp,r,g,b);
1301 }
1302
1303 void SMESH_Actor::SetPreHighlightColor(float r,float g,float b){ 
1304   myPreselectProp->SetColor(r,g,b);
1305   Modified();
1306 }
1307
1308 void SMESH_Actor::GetPreHighlightColor(float& r,float& g,float& b){ 
1309   ::GetColor(myPreselectProp,r,g,b);
1310 }
1311
1312
1313 float SMESH_Actor::GetLineWidth(){
1314   return myEdgeProp->GetLineWidth();
1315 }
1316
1317
1318 void SMESH_Actor::SetLineWidth(float theVal){
1319   myEdgeProp->SetLineWidth(theVal);
1320
1321   my1DProp->SetLineWidth(theVal + aLineWidthInc);
1322   my1DExtProp->SetLineWidth(theVal + aLineWidthInc);
1323
1324   Modified();
1325 }
1326
1327
1328 void SMESH_Actor::SetNodeSize(float theVal){
1329   myNodeProp->SetPointSize(theVal);
1330   myHighlightProp->SetPointSize(theVal);
1331   myPreselectProp->SetPointSize(theVal);
1332
1333   my1DProp->SetPointSize(theVal + aPointSizeInc);
1334   my1DExtProp->SetPointSize(theVal + aPointSizeInc);
1335
1336   Modified();
1337 }
1338
1339 float SMESH_Actor::GetNodeSize(){
1340   return myNodeProp->GetPointSize();
1341 }
1342
1343 int SMESH_Actor::GetObjDimension( const int theObjId )
1344 {
1345   return myVisualObj->GetElemDimension( theObjId );
1346 }
1347
1348
1349 vtkImplicitBoolean* SMESH_Actor::GetPlaneContainer(){
1350   return myImplicitBoolean;
1351 }
1352
1353
1354 static void ComputeBoundsParam(vtkDataSet* theDataSet,
1355                                float theDirection[3], float theMinPnt[3],
1356                                float& theMaxBoundPrj, float& theMinBoundPrj)
1357 {
1358   float aBounds[6];
1359   theDataSet->GetBounds(aBounds);
1360
1361   //Enlarge bounds in order to avoid conflicts of precision
1362   for(int i = 0; i < 6; i += 2){
1363     static double EPS = 1.0E-3;
1364     float aDelta = (aBounds[i+1] - aBounds[i])*EPS;
1365     aBounds[i] -= aDelta;
1366     aBounds[i+1] += aDelta;
1367   }
1368
1369   float aBoundPoints[8][3] = { {aBounds[0],aBounds[2],aBounds[4]},
1370                                {aBounds[1],aBounds[2],aBounds[4]},
1371                                {aBounds[0],aBounds[3],aBounds[4]},
1372                                {aBounds[1],aBounds[3],aBounds[4]},
1373                                {aBounds[0],aBounds[2],aBounds[5]},
1374                                {aBounds[1],aBounds[2],aBounds[5]}, 
1375                                {aBounds[0],aBounds[3],aBounds[5]}, 
1376                                {aBounds[1],aBounds[3],aBounds[5]}};
1377
1378   int aMaxId = 0, aMinId = aMaxId;
1379   theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
1380   theMinBoundPrj = theMaxBoundPrj;
1381   for(int i = 1; i < 8; i++){
1382     float aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
1383     if(theMaxBoundPrj < aTmp){
1384       theMaxBoundPrj = aTmp;
1385       aMaxId = i;
1386     }
1387     if(theMinBoundPrj > aTmp){
1388       theMinBoundPrj = aTmp;
1389       aMinId = i;
1390     }
1391   }
1392   float *aMinPnt = aBoundPoints[aMaxId];
1393   theMinPnt[0] = aMinPnt[0];
1394   theMinPnt[1] = aMinPnt[1];
1395   theMinPnt[2] = aMinPnt[2];
1396 }
1397
1398
1399 static void DistanceToPosition(vtkDataSet* theDataSet,
1400                                float theDirection[3], float theDist, float thePos[3])
1401 {
1402   float aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1403   ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1404   float aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
1405   thePos[0] = aMinPnt[0]-theDirection[0]*aLength;
1406   thePos[1] = aMinPnt[1]-theDirection[1]*aLength;
1407   thePos[2] = aMinPnt[2]-theDirection[2]*aLength;
1408 }
1409
1410
1411 static void PositionToDistance(vtkDataSet* theDataSet, 
1412                                float theDirection[3], float thePos[3], float& theDist)
1413 {
1414   float aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1415   ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1416   float aPrj = vtkMath::Dot(theDirection,thePos);
1417   theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
1418 }
1419
1420
1421 void SMESH_Actor::SetPlaneParam(float theDir[3], float theDist, vtkPlane* thePlane)
1422 {
1423   thePlane->SetNormal(theDir);
1424   float anOrigin[3];
1425   ::DistanceToPosition(GetUnstructuredGrid(),theDir,theDist,anOrigin);
1426   thePlane->SetOrigin(anOrigin);
1427   Update();
1428 }
1429
1430
1431 void SMESH_Actor::GetPlaneParam(float theDir[3], float& theDist, vtkPlane* thePlane)
1432 {
1433   thePlane->GetNormal(theDir);
1434
1435   float anOrigin[3];
1436   thePlane->GetOrigin(anOrigin);
1437   ::PositionToDistance(GetUnstructuredGrid(),theDir,anOrigin,theDist);
1438 }