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