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