Salome HOME
Fix regressions 0021322, 0021323
[modules/smesh.git] / src / OBJECT / SMESH_Actor.cxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SMESH OBJECT : interactive object for SMESH visualization
24 //  File   : SMESH_Actor.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SMESH
27 //
28 #include "SMESH_ActorDef.h"
29 #include "SMESH_ActorUtils.h"
30 #include "SMESH_DeviceActor.h"
31 #include "SMESH_ObjectDef.h"
32 #include "SMESH_ControlsDef.hxx"
33 #include "SMDS_UnstructuredGrid.hxx"
34 #include "SMESH_ScalarBarActor.h"
35 #include "VTKViewer_CellCenters.h"
36 #include "VTKViewer_DataSetMapper.h"
37 #include "VTKViewer_ExtractUnstructuredGrid.h"
38 #include "VTKViewer_FramedTextActor.h"
39 #include "SALOME_InteractiveObject.hxx"
40
41 #include "SUIT_Session.h"
42 #include "SUIT_ResourceMgr.h"
43
44 #ifndef DISABLE_PLOT2DVIEWER
45 #include <SPlot2d_Histogram.h>
46 #endif
47
48 #include <vtkProperty.h>
49 #include <vtkTimeStamp.h>
50 #include <vtkObjectFactory.h>
51 #include <vtkShrinkPolyData.h>
52 #include <vtkMergeFilter.h>
53
54 #include <vtkMatrix4x4.h>
55 #include <vtkUnstructuredGrid.h>
56 #include <vtkPointData.h>
57 #include <vtkCellData.h>
58
59 #include <vtkMapper.h>
60 #include <vtkRenderer.h>
61
62 #include <vtkCell.h>
63 #include <vtkIdList.h>
64 #include <vtkIntArray.h>
65
66 #include <vtkActor2D.h>
67 #include <vtkProperty2D.h>
68 #include <vtkPolyData.h>
69 #include <vtkMaskPoints.h>
70 #include <vtkTextProperty.h>
71 #include <vtkLabeledDataMapper.h>
72 #include <vtkSelectVisiblePoints.h>
73
74 #include <vtkLookupTable.h>
75
76 #include <vtkMath.h>
77 #include <vtkPlane.h>
78 #include <vtkImplicitBoolean.h>
79 #include <vtkImplicitFunctionCollection.h>
80
81 #include <vtkConfigure.h>
82 #if !defined(VTK_XVERSION)
83 #define VTK_XVERSION (VTK_MAJOR_VERSION<<16)+(VTK_MINOR_VERSION<<8)+(VTK_BUILD_VERSION)
84 #endif
85
86 #include "utilities.h"
87
88 #ifdef _DEBUG_
89 static int MYDEBUG = 1;
90 #else
91 static int MYDEBUG = 1;
92 #endif
93
94 static int aLineWidthInc = 2;
95
96
97 SMESH_ActorDef* SMESH_ActorDef::New(){
98   return new SMESH_ActorDef();
99 }
100
101
102 SMESH_Actor* SMESH_Actor::New(TVisualObjPtr theVisualObj, 
103                               const char* theEntry, 
104                               const char* theName,
105                               int theIsClear)
106 {
107   SMESH_ActorDef* anActor = NULL;
108   if(theVisualObj->IsValid() ) {
109     anActor = SMESH_ActorDef::New();
110     if(!anActor->Init(theVisualObj,theEntry,theName,theIsClear)){
111       anActor->Delete();
112       anActor = NULL;
113     }
114     if( anActor )
115       anActor->UpdateScalarBar();
116   }
117   return anActor;
118 }
119
120
121 SMESH_ActorDef::SMESH_ActorDef()
122 {
123   if(MYDEBUG) MESSAGE("SMESH_ActorDef - "<<this);
124
125   myTimeStamp = vtkTimeStamp::New();
126
127   myIsPointsVisible = false;
128
129   myIsShrinkable = false;
130   myIsShrunk = false;
131
132   myIsFacesOriented = false;
133
134   myControlsPrecision = -1;
135   SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
136
137   if ( mgr && mgr->booleanValue( "SMESH", "use_precision", false ) )
138     myControlsPrecision = mgr->integerValue( "SMESH", "controls_precision", -1);
139
140   vtkFloatingPointType aElem0DSize = SMESH::GetFloat("SMESH:elem0d_size",5);
141   vtkFloatingPointType aLineWidth  = SMESH::GetFloat("SMESH:element_width",1);
142
143   vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
144   VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
145
146   //Definition 2D and 3D devices of the actor
147   //-----------------------------------------
148   vtkFloatingPointType anRGB[3] = {1,1,1};
149   mySurfaceProp = vtkProperty::New();
150   SMESH::GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
151   mySurfaceProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
152
153   myBackSurfaceProp = vtkProperty::New();
154   SMESH::GetColor( "SMESH", "backface_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 0, 255 ) );
155   myBackSurfaceProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
156
157   my2DActor = SMESH_DeviceActor::New();
158   my2DActor->SetUserMatrix(aMatrix);
159   my2DActor->PickableOff();
160   my2DActor->SetProperty(mySurfaceProp);
161   my2DActor->SetBackfaceProperty(myBackSurfaceProp);
162   my2DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
163   aFilter = my2DActor->GetExtractUnstructuredGrid();
164   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
165   aFilter->RegisterCellsWithType(VTK_TRIANGLE);
166   aFilter->RegisterCellsWithType(VTK_POLYGON);
167   aFilter->RegisterCellsWithType(VTK_QUAD);
168   aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
169   aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
170
171   my2DExtProp = vtkProperty::New();
172   my2DExtProp->DeepCopy(mySurfaceProp);
173   SMESH::GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
174   anRGB[0] = 1 - anRGB[0];
175   anRGB[1] = 1 - anRGB[1];
176   anRGB[2] = 1 - anRGB[2];
177   my2DExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
178
179   my2DExtActor = SMESH_DeviceActor::New();
180   my2DExtActor->SetUserMatrix(aMatrix);
181   my2DExtActor->PickableOff();
182   my2DExtActor->SetProperty(my2DExtProp);
183   my2DExtActor->SetBackfaceProperty(my2DExtProp);
184   my2DExtActor->SetRepresentation(SMESH_DeviceActor::eInsideframe);
185   aFilter = my2DExtActor->GetExtractUnstructuredGrid();
186   aFilter->RegisterCellsWithType(VTK_TRIANGLE);
187   aFilter->RegisterCellsWithType(VTK_POLYGON);
188   aFilter->RegisterCellsWithType(VTK_QUAD);
189   aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
190   aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
191
192   my3DActor = SMESH_DeviceActor::New();
193   my3DActor->SetUserMatrix(aMatrix);
194   my3DActor->PickableOff();
195   my3DActor->SetProperty(mySurfaceProp);
196   my3DActor->SetBackfaceProperty(myBackSurfaceProp);
197   my3DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
198   aFilter = my3DActor->GetExtractUnstructuredGrid();
199   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
200   aFilter->RegisterCellsWithType(VTK_TETRA);
201   aFilter->RegisterCellsWithType(VTK_VOXEL);
202   aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
203   aFilter->RegisterCellsWithType(VTK_WEDGE);
204   aFilter->RegisterCellsWithType(VTK_PYRAMID);
205   aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
206   aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
207   aFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
208   aFilter->RegisterCellsWithType(VTK_QUADRATIC_PYRAMID);
209   aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
210 //#ifdef VTK_HAVE_POLYHEDRON
211   MESSAGE("RegisterCellsWithType(VTK_POLYHEDRON)");
212   aFilter->RegisterCellsWithType(VTK_POLYHEDRON);
213 //#endif
214
215   my3DExtActor = SMESH_DeviceActor::New();
216   my3DExtActor->SetUserMatrix(aMatrix);
217   my3DExtActor->PickableOff();
218   my3DExtActor->SetProperty(my2DExtProp);
219   my3DExtActor->SetBackfaceProperty(my2DExtProp);
220   my3DExtActor->SetRepresentation(SMESH_DeviceActor::eSurface);
221   aFilter = my3DExtActor->GetExtractUnstructuredGrid();
222   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
223   aFilter->RegisterCellsWithType(VTK_TETRA);
224   aFilter->RegisterCellsWithType(VTK_VOXEL);
225   aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
226   aFilter->RegisterCellsWithType(VTK_WEDGE);
227   aFilter->RegisterCellsWithType(VTK_PYRAMID);
228   aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
229   aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
230   aFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
231   aFilter->RegisterCellsWithType(VTK_QUADRATIC_PYRAMID);
232   aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
233   aFilter->RegisterCellsWithType(VTK_POLYHEDRON);
234
235   //Definition 1D device of the actor
236   //---------------------------------
237   myEdgeProp = vtkProperty::New();
238   myEdgeProp->SetAmbient(1.0);
239   myEdgeProp->SetDiffuse(0.0);
240   myEdgeProp->SetSpecular(0.0);
241   SMESH::GetColor( "SMESH", "outline_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
242   myEdgeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
243   myEdgeProp->SetLineWidth(aLineWidth);
244
245   my1DActor = SMESH_DeviceActor::New();
246   my1DActor->SetUserMatrix(aMatrix);
247   my1DActor->PickableOff();
248   my1DActor->SetHighlited(true);
249   my1DActor->SetProperty(myEdgeProp);
250   my1DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
251   aFilter = my1DActor->GetExtractUnstructuredGrid();
252   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
253   aFilter->RegisterCellsWithType(VTK_LINE);
254   aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
255
256   my1DProp = vtkProperty::New();
257   my1DProp->DeepCopy(myEdgeProp);
258   my1DProp->SetLineWidth(aLineWidth + aLineWidthInc);
259   my1DProp->SetPointSize(aElem0DSize);
260   
261   my1DExtProp = vtkProperty::New();
262   my1DExtProp->DeepCopy(myEdgeProp);
263   anRGB[0] = 1 - anRGB[0];
264   anRGB[1] = 1 - anRGB[1];
265   anRGB[2] = 1 - anRGB[2];
266   my1DExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
267   my1DExtProp->SetLineWidth(aLineWidth + aLineWidthInc);
268   my1DExtProp->SetPointSize(aElem0DSize);
269
270   my1DExtActor = SMESH_DeviceActor::New();
271   my1DExtActor->SetUserMatrix(aMatrix);
272   my1DExtActor->PickableOff();
273   my1DExtActor->SetHighlited(true);
274   my1DExtActor->SetVisibility(false);
275   my1DExtActor->SetProperty(my1DExtProp);
276   my1DExtActor->SetRepresentation(SMESH_DeviceActor::eInsideframe);
277   aFilter = my1DExtActor->GetExtractUnstructuredGrid();
278   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
279   aFilter->RegisterCellsWithType(VTK_LINE);
280   aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
281
282
283   //Definition 0D device of the actor (0d elements)
284   //-----------------------------------------------
285   my0DProp = vtkProperty::New();
286   SMESH::GetColor( "SMESH", "elem0d_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 255, 0 ) );
287   my0DProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
288   my0DProp->SetPointSize(aElem0DSize);
289
290   my0DActor = SMESH_DeviceActor::New();
291   my0DActor->SetUserMatrix(aMatrix);
292   my0DActor->SetStoreClippingMapping(true);
293   my0DActor->PickableOff();
294   my0DActor->SetVisibility(false);
295   my0DActor->SetProperty(my0DProp);
296   my0DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
297   aFilter = my0DActor->GetExtractUnstructuredGrid();
298   //aFilter->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
299   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
300   aFilter->RegisterCellsWithType(VTK_VERTEX);
301   
302   //my0DExtProp = vtkProperty::New();
303   //my0DExtProp->DeepCopy(my0DProp);
304   //anRGB[0] = 1 - anRGB[0];
305   //anRGB[1] = 1 - anRGB[1];
306   //anRGB[2] = 1 - anRGB[2];
307   //my0DExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
308   //my0DExtProp->SetPointSize(aElem0DSize);
309   //
310   //my0DExtActor = SMESH_DeviceActor::New();
311   //my0DExtActor->SetUserMatrix(aMatrix);
312   //my0DExtActor->SetStoreClippingMapping(true);
313   //my0DExtActor->PickableOff();
314   //my0DExtActor->SetHighlited(true);
315   //my0DExtActor->SetVisibility(false);
316   //my0DExtActor->SetProperty(my0DExtProp);
317   //my0DExtActor->SetRepresentation(SMESH_DeviceActor::eInsideframe);
318   //aFilter = my0DExtActor->GetExtractUnstructuredGrid();
319   ////aFilter->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
320   //aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
321   //aFilter->RegisterCellsWithType(VTK_VERTEX);
322
323
324   //Definition 0D device of the actor (nodes)
325   //-----------------------------------------
326   myNodeProp = vtkProperty::New();
327   SMESH::GetColor( "SMESH", "node_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 0, 0 ) );
328   myNodeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
329
330   myNodeActor = SMESH_DeviceActor::New();
331   myNodeActor->SetUserMatrix(aMatrix);
332   myNodeActor->SetStoreClippingMapping(true);
333   myNodeActor->PickableOff();
334   myNodeActor->SetVisibility(false);
335   myNodeActor->SetProperty(myNodeProp);
336   myNodeActor->SetRepresentation(SMESH_DeviceActor::ePoint);
337   aFilter = myNodeActor->GetExtractUnstructuredGrid();
338   aFilter->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
339   
340   myNodeExtProp = vtkProperty::New();
341   myNodeExtProp->DeepCopy(myNodeProp);
342   anRGB[0] = 1 - anRGB[0];
343   anRGB[1] = 1 - anRGB[1];
344   anRGB[2] = 1 - anRGB[2];
345   myNodeExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
346
347   myNodeExtActor = SMESH_DeviceActor::New();
348   myNodeExtActor->SetUserMatrix(aMatrix);
349   myNodeExtActor->SetStoreClippingMapping(true);
350   myNodeExtActor->PickableOff();
351   myNodeExtActor->SetHighlited(true);
352   myNodeExtActor->SetVisibility(false);
353   myNodeExtActor->SetProperty(myNodeExtProp);
354   myNodeExtActor->SetRepresentation(SMESH_DeviceActor::ePoint);
355   aFilter = myNodeExtActor->GetExtractUnstructuredGrid();
356   aFilter->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
357   aFilter->RegisterCellsWithType(VTK_VERTEX);
358
359   //Definition of Pickable and Highlitable engines
360   //----------------------------------------------
361
362   myBaseActor = SMESH_DeviceActor::New();
363   myBaseActor->SetUserMatrix(aMatrix);
364   myBaseActor->SetStoreGemetryMapping(true);
365   myBaseActor->GetProperty()->SetOpacity(0.0);
366
367   myPickableActor = myBaseActor;
368
369   // VSR 13/07/2011: Revert back previous fix for issue 0020749 since it causes regressions, see issues 0021322, 0021323
370   // To be removed later or fix to be improved
371   //myMapper = VTKViewer_DataSetMapper::New();
372   //myMapper->SetInput( myPickableActor->GetUnstructuredGrid() );
373
374   myHighlightProp = vtkProperty::New();
375   myHighlightProp->SetAmbient(1.0);
376   myHighlightProp->SetDiffuse(0.0);
377   myHighlightProp->SetSpecular(0.0);
378   SMESH::GetColor( "SMESH", "selection_object_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
379   myHighlightProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
380   myHighlightProp->SetPointSize(aElem0DSize); // ??
381   myHighlightProp->SetRepresentation(1);
382
383   myPreselectProp = vtkProperty::New();
384   myPreselectProp->SetAmbient(1.0);
385   myPreselectProp->SetDiffuse(0.0);
386   myPreselectProp->SetSpecular(0.0);
387   SMESH::GetColor( "SMESH", "highlight_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 255, 255 ) );
388   myPreselectProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
389   myPreselectProp->SetPointSize(aElem0DSize); // ??
390   myPreselectProp->SetRepresentation(1);
391
392   myHighlitableActor = SMESH_DeviceActor::New();
393   myHighlitableActor->SetUserMatrix(aMatrix);
394   myHighlitableActor->PickableOff();
395   myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
396
397   aMatrix->Delete();
398
399   myName = "";
400   myIO = NULL;
401
402   myControlMode = eNone;
403   myControlActor = my2DActor;
404
405   //Definition of myScalarBarActor
406   //------------------------------
407   myLookupTable = vtkLookupTable::New();
408   //Fix for Bug PAL5195 - SMESH764: 
409   //Controls - Aspect Ratio: incorrect colors of the best and worst values
410   myLookupTable->SetHueRange(0.667,0.0);
411
412   myScalarBarActor = SMESH_ScalarBarActor::New();
413   myScalarBarActor->SetVisibility(false);
414   myScalarBarActor->SetLookupTable(myLookupTable);
415
416   //Fix for Bug 13314:
417   //Incorrect "Min value" in Scalar Bar in Mesh:
418   //  myScalarBarActor->SetLabelFormat("%.4g");
419   // changes was commented because of regression bug IPAL 19981
420
421   mgr = SUIT_Session::session()->resourceMgr();
422   if( !mgr )
423     return;
424
425   //Definition of points numbering pipeline
426   //---------------------------------------
427   myPointsNumDataSet = vtkUnstructuredGrid::New();
428
429   myPtsMaskPoints = vtkMaskPoints::New();
430   myPtsMaskPoints->SetInput(myPointsNumDataSet);
431   myPtsMaskPoints->SetOnRatio(1);
432
433   myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
434   myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput());
435   myPtsSelectVisiblePoints->SelectInvisibleOff();
436   myPtsSelectVisiblePoints->SetTolerance(0.1);
437     
438   myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
439   myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
440 #if (VTK_XVERSION < 0x050200)
441   myPtsLabeledDataMapper->SetLabelFormat("%g");
442 #endif
443   myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
444     
445   vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
446   aPtsTextProp->SetFontFamilyToTimes();
447   static int aPointsFontSize = 10;
448   aPtsTextProp->SetFontSize(aPointsFontSize);
449   aPtsTextProp->SetBold(1);
450   aPtsTextProp->SetItalic(0);
451   aPtsTextProp->SetShadow(0);
452   myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
453   aPtsTextProp->Delete();
454   
455   myEntityMode = eAllEntity;
456
457   myIsPointsLabeled = false;
458
459   myPointLabels = vtkActor2D::New();
460   myPointLabels->SetMapper(myPtsLabeledDataMapper);
461   myPointLabels->GetProperty()->SetColor(1,1,1);
462   myPointLabels->SetVisibility(myIsPointsLabeled);
463
464
465   //Definition of cells numbering pipeline
466   //---------------------------------------
467   myCellsNumDataSet = vtkUnstructuredGrid::New();
468
469   myCellCenters = VTKViewer_CellCenters::New();
470   myCellCenters->SetInput(myCellsNumDataSet);
471
472   myClsMaskPoints = vtkMaskPoints::New();
473   myClsMaskPoints->SetInput(myCellCenters->GetOutput());
474   myClsMaskPoints->SetOnRatio(1);
475     
476   myClsSelectVisiblePoints = vtkSelectVisiblePoints::New();
477   myClsSelectVisiblePoints->SetInput(myClsMaskPoints->GetOutput());
478   myClsSelectVisiblePoints->SelectInvisibleOff();
479   myClsSelectVisiblePoints->SetTolerance(0.1);
480     
481   myClsLabeledDataMapper = vtkLabeledDataMapper::New();
482   myClsLabeledDataMapper->SetInput(myClsSelectVisiblePoints->GetOutput());
483 #if (VTK_XVERSION < 0x050200)
484   myClsLabeledDataMapper->SetLabelFormat("%g");
485 #endif
486   myClsLabeledDataMapper->SetLabelModeToLabelScalars();
487     
488   vtkTextProperty* aClsTextProp = vtkTextProperty::New();
489   aClsTextProp->SetFontFamilyToTimes();
490   static int aCellsFontSize = 12;
491   aClsTextProp->SetFontSize(aCellsFontSize);
492   aClsTextProp->SetBold(1);
493   aClsTextProp->SetItalic(0);
494   aClsTextProp->SetShadow(0);
495   myClsLabeledDataMapper->SetLabelTextProperty(aClsTextProp);
496   aClsTextProp->Delete();
497     
498   myIsCellsLabeled = false;
499
500   myCellsLabels = vtkActor2D::New();
501   myCellsLabels->SetMapper(myClsLabeledDataMapper);
502   myCellsLabels->GetProperty()->SetColor(0,1,0);
503   myCellsLabels->SetVisibility(myIsCellsLabeled);
504
505   // Clipping planes
506   myImplicitBoolean = vtkImplicitBoolean::New();
507   myImplicitBoolean->SetOperationTypeToIntersection();
508   
509
510
511   //Quadratic 2D elements representation
512   //-----------------------------------------------------------------------------
513   int aQuadratic2DMode = mgr->integerValue( "SMESH", "quadratic_mode", 0);
514   if(aQuadratic2DMode == 0){
515     myHighlitableActor->SetQuadraticArcMode(false);
516     my2DActor->SetQuadraticArcMode(false);
517     my1DActor->SetQuadraticArcMode(false);
518   }
519   else if(aQuadratic2DMode == 1){
520     myHighlitableActor->SetQuadraticArcMode(true);
521     my2DActor->SetQuadraticArcMode(true);
522     my1DActor->SetQuadraticArcMode(true);
523   }
524   
525   int aQuadraticAngle = mgr->integerValue( "SMESH", "max_angle", 2);
526   myHighlitableActor->SetQuadraticArcAngle(aQuadraticAngle);
527   my2DActor->SetQuadraticArcAngle(aQuadraticAngle);
528   
529   // Set colors of the name actor
530   SMESH::GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
531   myNameActor->SetBackgroundColor(anRGB[0], anRGB[1], anRGB[2]);
532   SMESH::GetColor( "SMESH", "group_name_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
533   myNameActor->SetForegroundColor(anRGB[0], anRGB[1], anRGB[2]);
534
535 #ifndef DISABLE_PLOT2DVIEWER
536   my2dHistogram = 0;
537 #endif
538
539 }
540
541
542 SMESH_ActorDef::~SMESH_ActorDef()
543 {
544   if(MYDEBUG) MESSAGE("~SMESH_ActorDef - "<<this);
545
546 #ifndef DISABLE_PLOT2DVIEWER
547   if(my2dHistogram) {
548     SMESH::ProcessIn2DViewers(this,SMESH::RemoveFrom2dViewer);
549     delete my2dHistogram;
550   }
551 #endif
552
553   // caught by SMESHGUI::ProcessEvents() static method
554   this->InvokeEvent( SMESH::DeleteActorEvent, NULL );
555
556   myScalarBarActor->Delete();
557   myLookupTable->Delete();
558
559   mySurfaceProp->Delete();
560   myBackSurfaceProp->Delete();
561
562   myEdgeProp->Delete();
563   myHighlightProp->Delete();
564   myPreselectProp->Delete();
565
566   myNodeProp->Delete();
567   myNodeExtProp->Delete();
568  
569   my0DProp->Delete();
570   my0DActor->Delete();
571
572   //my0DExtProp->Delete();
573   //my0DExtActor->Delete();
574  
575   my1DProp->Delete();
576   my1DActor->Delete();
577
578   my1DExtProp->Delete();
579   my1DExtActor->Delete();
580
581   my2DActor->Delete();
582   my2DExtProp->Delete();
583   my2DExtActor->Delete();
584   my3DActor->Delete();
585   my3DExtActor->Delete();
586
587   myNodeActor->Delete();
588   myBaseActor->Delete();
589
590   myNodeExtActor->Delete();
591   
592   myHighlitableActor->Delete();
593
594   //Deleting of points numbering pipeline
595   //---------------------------------------
596   myPointsNumDataSet->Delete();
597
598   // commented: porting to vtk 5.0
599   //  myPtsLabeledDataMapper->RemoveAllInputs();
600   myPtsLabeledDataMapper->Delete();
601
602   // commented: porting to vtk 5.0
603   //  myPtsSelectVisiblePoints->UnRegisterAllOutputs();
604   myPtsSelectVisiblePoints->Delete();
605
606   // commented: porting to vtk 5.0
607   //  myPtsMaskPoints->UnRegisterAllOutputs();
608   myPtsMaskPoints->Delete();
609
610   myPointLabels->Delete();
611
612
613   //Deleting of cells numbering pipeline
614   //---------------------------------------
615   myCellsNumDataSet->Delete();
616
617   myClsLabeledDataMapper->RemoveAllInputs();
618   myClsLabeledDataMapper->Delete();
619
620   // commented: porting to vtk 5.0
621   //  myClsSelectVisiblePoints->UnRegisterAllOutputs();
622   myClsSelectVisiblePoints->Delete();
623
624   // commented: porting to vtk 5.0
625   //  myClsMaskPoints->UnRegisterAllOutputs();
626   myClsMaskPoints->Delete();
627
628   // commented: porting to vtk 5.0
629   //  myCellCenters->UnRegisterAllOutputs();
630   myCellCenters->Delete();
631
632   myCellsLabels->Delete();
633
634   myImplicitBoolean->Delete();
635
636   // VSR 13/07/2011: Revert back previous fix for issue 0020749 since it causes regressions, see issues 0021322, 0021323
637   // To be removed later or fix to be improved
638   //myMapper->Delete();
639
640   myTimeStamp->Delete();
641 }
642
643
644 void SMESH_ActorDef::SetPointsLabeled( bool theIsPointsLabeled )
645 {    
646   vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
647     
648   myIsPointsLabeled = theIsPointsLabeled && aGrid->GetNumberOfPoints();
649
650   if ( myIsPointsLabeled )
651   {
652     myPointsNumDataSet->ShallowCopy(aGrid);
653     vtkDataSet *aDataSet = myPointsNumDataSet;
654     
655     int aNbElem = aDataSet->GetNumberOfPoints();
656     
657     vtkIntArray *anArray = vtkIntArray::New();
658     anArray->SetNumberOfValues( aNbElem );
659     
660     for ( vtkIdType anId = 0; anId < aNbElem; anId++ )
661     {
662       int aSMDSId = myVisualObj->GetNodeObjId( anId );
663       anArray->SetValue( anId, aSMDSId );
664     }
665     
666     aDataSet->GetPointData()->SetScalars( anArray );
667     anArray->Delete();
668     myPtsMaskPoints->SetInput( aDataSet );
669     myPointLabels->SetVisibility( GetVisibility() );
670   }
671   else
672   {
673     myPointLabels->SetVisibility( false );
674   }
675   SetRepresentation(GetRepresentation());
676   myTimeStamp->Modified();
677 }
678
679
680 void SMESH_ActorDef::SetCellsLabeled(bool theIsCellsLabeled)
681 {
682   vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
683   myIsCellsLabeled = theIsCellsLabeled && aGrid->GetNumberOfPoints();
684   if(myIsCellsLabeled){
685     myCellsNumDataSet->ShallowCopy(aGrid);
686     vtkDataSet *aDataSet = myCellsNumDataSet;
687     int aNbElem = aDataSet->GetNumberOfCells();
688     vtkIntArray *anArray = vtkIntArray::New();
689     anArray->SetNumberOfValues(aNbElem);
690     for(int anId = 0; anId < aNbElem; anId++){
691       int aSMDSId = myVisualObj->GetElemObjId(anId);
692       anArray->SetValue(anId,aSMDSId);
693     }
694     aDataSet->GetCellData()->SetScalars(anArray);
695     myCellCenters->SetInput(aDataSet);
696     myCellsLabels->SetVisibility(GetVisibility());
697   }else{
698     myCellsLabels->SetVisibility(false);
699   }
700   myTimeStamp->Modified();
701 }
702
703
704 void SMESH_ActorDef::SetFacesOriented(bool theIsFacesOriented)
705 {
706   myIsFacesOriented = theIsFacesOriented;
707
708   my2DActor->SetFacesOriented(theIsFacesOriented);
709   my3DActor->SetFacesOriented(theIsFacesOriented);
710
711   myTimeStamp->Modified();
712 }
713
714 bool SMESH_ActorDef::GetFacesOriented()
715 {
716   return myIsFacesOriented;
717 }
718
719 void SMESH_ActorDef::SetFacesOrientationColor(vtkFloatingPointType theColor[3])
720 {
721   my2DActor->SetFacesOrientationColor( theColor );
722   my3DActor->SetFacesOrientationColor( theColor );
723 }
724
725 void SMESH_ActorDef::GetFacesOrientationColor(vtkFloatingPointType theColor[3])
726 {
727   my3DActor->GetFacesOrientationColor( theColor );
728 }
729
730 void SMESH_ActorDef::SetFacesOrientationScale(vtkFloatingPointType theScale)
731 {
732   my2DActor->SetFacesOrientationScale( theScale );
733   my3DActor->SetFacesOrientationScale( theScale );
734 }
735
736 vtkFloatingPointType SMESH_ActorDef::GetFacesOrientationScale()
737 {
738   return my3DActor->GetFacesOrientationScale();
739 }
740
741 void SMESH_ActorDef::SetFacesOrientation3DVectors(bool theState)
742 {
743   my2DActor->SetFacesOrientation3DVectors( theState );
744   my3DActor->SetFacesOrientation3DVectors( theState );
745 }
746
747 bool SMESH_ActorDef::GetFacesOrientation3DVectors()
748 {
749   return my3DActor->GetFacesOrientation3DVectors();
750 }
751
752
753 void 
754 SMESH_ActorDef::
755 SetControlMode(eControl theMode)
756 {
757   SetControlMode(theMode,true);
758 }
759
760
761 void 
762 SMESH_ActorDef::
763 SetControlMode(eControl theMode,
764                bool theCheckEntityMode)
765 {
766   SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();  
767   if( !mgr )
768     return;
769
770   myControlMode = eNone;
771   theCheckEntityMode &= mgr->booleanValue( "SMESH", "display_entity", false );
772
773   my0DActor->GetMapper()->SetScalarVisibility(false);
774   my1DActor->GetMapper()->SetScalarVisibility(false);
775   my2DActor->GetMapper()->SetScalarVisibility(false);
776   my3DActor->GetMapper()->SetScalarVisibility(false);
777   myScalarBarActor->SetVisibility(false);
778
779   bool anIsScalarVisible = theMode > eNone;
780
781   if(anIsScalarVisible) {
782     switch(theMode) {
783     case eLength:
784     {
785       SMESH::Controls::Length* aControl = new SMESH::Controls::Length();
786       aControl->SetPrecision( myControlsPrecision );
787       myFunctor.reset( aControl );
788       myControlActor = my1DActor;
789       break;
790     }
791     case eLength2D:
792     {
793       myFunctor.reset(new SMESH::Controls::Length2D());
794       myControlActor = my2DActor;
795       break;
796     }
797     case eFreeBorders:
798       myFunctor.reset(new SMESH::Controls::FreeBorders());
799       myControlActor = my1DActor;
800       break;
801     case eFreeEdges:
802       myFunctor.reset(new SMESH::Controls::FreeEdges());
803       myControlActor = my2DActor;
804       break;
805     case eFreeNodes:
806       myFunctor.reset(new SMESH::Controls::FreeNodes());
807       myControlActor = myNodeActor;
808       break;
809     case eFreeFaces:
810       myFunctor.reset(new SMESH::Controls::FreeFaces());
811       myControlActor = my2DActor;
812       break;
813     case eBareBorderFace:
814       myFunctor.reset(new SMESH::Controls::BareBorderFace());
815       myControlActor = my2DActor;
816       break;
817     case eOverConstrainedFace:
818       myFunctor.reset(new SMESH::Controls::OverConstrainedFace());
819       myControlActor = my2DActor;
820       break;
821     case eMultiConnection:
822       myFunctor.reset(new SMESH::Controls::MultiConnection());
823       myControlActor = my1DActor;
824       break;
825     case eMultiConnection2D:
826       myFunctor.reset(new SMESH::Controls::MultiConnection2D());
827       myControlActor = my2DActor;
828       break;
829     case eArea:
830     {
831       SMESH::Controls::Area* aControl = new SMESH::Controls::Area();
832       aControl->SetPrecision( myControlsPrecision );
833       myFunctor.reset( aControl );
834       myControlActor = my2DActor;
835       break;
836     }
837     case eTaper:
838     {
839       SMESH::Controls::Taper* aControl = new SMESH::Controls::Taper();
840       aControl->SetPrecision( myControlsPrecision );
841       myFunctor.reset( aControl );
842       myControlActor = my2DActor;
843       break;
844     }
845     case eAspectRatio:
846     {
847       SMESH::Controls::AspectRatio* aControl = new SMESH::Controls::AspectRatio();
848       aControl->SetPrecision( myControlsPrecision );
849       myFunctor.reset( aControl );
850       myControlActor = my2DActor;
851       break;
852     }
853     case eAspectRatio3D:
854     {
855       SMESH::Controls::AspectRatio3D* aControl = new SMESH::Controls::AspectRatio3D();
856       aControl->SetPrecision( myControlsPrecision );
857       myFunctor.reset( aControl );
858       myControlActor = my3DActor;
859       break;
860     }
861     case eVolume3D:
862     {
863       SMESH::Controls::Volume* aControl = new SMESH::Controls::Volume();
864       aControl->SetPrecision( myControlsPrecision );
865       myFunctor.reset( aControl );
866       myControlActor = my3DActor;
867       break;
868     }
869     case eMaxElementLength2D:
870     {
871       SMESH::Controls::MaxElementLength2D* aControl = new SMESH::Controls::MaxElementLength2D();
872       aControl->SetPrecision( myControlsPrecision );
873       myFunctor.reset( aControl );
874       myControlActor = my2DActor;
875       break;
876     }
877     case eMaxElementLength3D:
878     {
879       SMESH::Controls::MaxElementLength3D* aControl = new SMESH::Controls::MaxElementLength3D();
880       aControl->SetPrecision( myControlsPrecision );
881       myFunctor.reset( aControl );
882       myControlActor = my3DActor;
883       break;
884     }
885     case eBareBorderVolume:
886     {
887       myFunctor.reset(new SMESH::Controls::BareBorderVolume());
888       myControlActor = my3DActor;
889       break;
890     }
891     case eOverConstrainedVolume:
892     {
893       myFunctor.reset(new SMESH::Controls::OverConstrainedVolume());
894       myControlActor = my3DActor;
895       break;
896     }
897     case eMinimumAngle:
898     {
899       SMESH::Controls::MinimumAngle* aControl = new SMESH::Controls::MinimumAngle();
900       aControl->SetPrecision( myControlsPrecision );
901       myFunctor.reset( aControl );
902       myControlActor = my2DActor;
903       break;
904     }
905     case eWarping:
906     {
907       SMESH::Controls::Warping* aControl = new SMESH::Controls::Warping();
908       aControl->SetPrecision( myControlsPrecision );
909       myFunctor.reset( aControl );
910       myControlActor = my2DActor;
911       break;
912     }
913     case eSkew:
914     {
915       SMESH::Controls::Skew* aControl = new SMESH::Controls::Skew();
916       aControl->SetPrecision( myControlsPrecision );
917       myFunctor.reset( aControl );
918       myControlActor = my2DActor;
919       break;
920     }
921     default:
922       return;
923     }
924
925     vtkUnstructuredGrid* aGrid = myControlActor->GetUnstructuredGrid();
926     vtkIdType aNbCells = aGrid->GetNumberOfCells();
927     if(aNbCells){
928       myControlMode = theMode;
929       switch(myControlMode){
930       case eFreeNodes:
931         myNodeExtActor->SetExtControlMode(myFunctor);
932         break;
933       case eFreeEdges:
934       case eFreeBorders:
935         my1DExtActor->SetExtControlMode(myFunctor);
936         break;
937       case eFreeFaces:
938       case eBareBorderFace:
939       case eOverConstrainedFace:
940         my2DExtActor->SetExtControlMode(myFunctor);
941         break;
942       case eBareBorderVolume:
943       case eOverConstrainedVolume:
944         my3DExtActor->SetExtControlMode(myFunctor);
945         break;
946       case eLength2D:
947       case eMultiConnection2D:
948         my1DExtActor->SetExtControlMode(myFunctor,myScalarBarActor,myLookupTable);
949         UpdateDistribution();
950         break;
951       default:
952         myControlActor->SetControlMode(myFunctor,myScalarBarActor,myLookupTable);
953         UpdateDistribution();
954       }
955     }
956
957     if(theCheckEntityMode){
958       if(myControlActor == my1DActor)
959         SetEntityMode(eEdges);
960       else if(myControlActor == my2DActor){
961         switch(myControlMode){
962         case eLength2D:
963         case eFreeEdges:
964         case eFreeFaces:
965         case eMultiConnection2D:
966           //SetEntityMode(eEdges);
967           SetEntityMode(eFaces);
968           break;
969         default:
970           SetEntityMode(eFaces);
971         }
972       }else if(myControlActor == my3DActor)
973         SetEntityMode(eVolumes);
974     }
975
976   }
977   else {
978     if(theCheckEntityMode)
979       myEntityMode = eAllEntity;
980     myFunctor.reset();
981   }
982
983   SetRepresentation(GetRepresentation());
984
985   myTimeStamp->Modified();
986   Modified();
987 }
988
989
990 void SMESH_ActorDef::AddToRender(vtkRenderer* theRenderer){
991   theRenderer->AddActor(myNodeActor);
992   theRenderer->AddActor(myBaseActor);
993   
994   theRenderer->AddActor(myNodeExtActor);
995
996   my3DActor->AddToRender(theRenderer);
997   my3DExtActor->AddToRender(theRenderer);
998   my2DActor->AddToRender(theRenderer);
999   my2DExtActor->AddToRender(theRenderer);
1000
1001   theRenderer->AddActor(my1DActor);
1002   theRenderer->AddActor(my1DExtActor);
1003
1004   theRenderer->AddActor(my0DActor);
1005   //theRenderer->AddActor(my0DExtActor);
1006
1007   theRenderer->AddActor(myHighlitableActor);
1008   
1009   theRenderer->AddActor2D(myScalarBarActor);
1010
1011   myPtsSelectVisiblePoints->SetRenderer(theRenderer);
1012   myClsSelectVisiblePoints->SetRenderer(theRenderer);
1013
1014   theRenderer->AddActor2D(myPointLabels);
1015   theRenderer->AddActor2D(myCellsLabels);
1016
1017   // the superclass' method should be called at the end
1018   // (in particular, for correct work of selection)
1019   SALOME_Actor::AddToRender(theRenderer);
1020 }
1021
1022 void SMESH_ActorDef::RemoveFromRender(vtkRenderer* theRenderer){
1023   SALOME_Actor::RemoveFromRender(theRenderer);
1024
1025   theRenderer->RemoveActor(myNodeActor);
1026   theRenderer->RemoveActor(myBaseActor);
1027
1028   theRenderer->RemoveActor(myNodeExtActor);
1029
1030   theRenderer->RemoveActor(myHighlitableActor);
1031
1032   theRenderer->RemoveActor(my0DActor);
1033   //theRenderer->RemoveActor(my0DExtActor);
1034
1035   theRenderer->RemoveActor(my1DActor);
1036   theRenderer->RemoveActor(my1DExtActor);
1037
1038   my2DActor->RemoveFromRender(theRenderer);
1039   my2DExtActor->RemoveFromRender(theRenderer);
1040   my3DActor->RemoveFromRender(theRenderer);
1041   my3DExtActor->RemoveFromRender(theRenderer);
1042
1043   theRenderer->RemoveActor(myScalarBarActor);
1044   theRenderer->RemoveActor(myPointLabels);
1045   theRenderer->RemoveActor(myCellsLabels);
1046 }
1047
1048
1049 bool SMESH_ActorDef::Init(TVisualObjPtr theVisualObj, 
1050                           const char* theEntry, 
1051                           const char* theName,
1052                           int theIsClear)
1053 {
1054   Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry,"SMESH",theName);
1055   setIO(anIO);
1056   setName(theName);
1057
1058   myVisualObj = theVisualObj;
1059   myVisualObj->Update(theIsClear);
1060
1061   myNodeActor->Init(myVisualObj,myImplicitBoolean);
1062   myBaseActor->Init(myVisualObj,myImplicitBoolean);
1063
1064   myHighlitableActor->Init(myVisualObj,myImplicitBoolean);
1065
1066   myNodeExtActor->Init(myVisualObj,myImplicitBoolean);
1067   
1068   my0DActor->Init(myVisualObj,myImplicitBoolean);
1069   //my0DExtActor->Init(myVisualObj,myImplicitBoolean);
1070   
1071   my1DActor->Init(myVisualObj,myImplicitBoolean);
1072   my1DExtActor->Init(myVisualObj,myImplicitBoolean);
1073   
1074   my2DActor->Init(myVisualObj,myImplicitBoolean);
1075   my2DExtActor->Init(myVisualObj,myImplicitBoolean);
1076   my3DActor->Init(myVisualObj,myImplicitBoolean);
1077   my3DExtActor->Init(myVisualObj,myImplicitBoolean);
1078   
1079   my0DActor->GetMapper()->SetLookupTable(myLookupTable);
1080   //my0DExtActor->GetMapper()->SetLookupTable(myLookupTable);
1081   
1082   my1DActor->GetMapper()->SetLookupTable(myLookupTable);
1083   my1DExtActor->GetMapper()->SetLookupTable(myLookupTable);
1084
1085   my2DActor->GetMapper()->SetLookupTable(myLookupTable);
1086   my2DExtActor->GetMapper()->SetLookupTable(myLookupTable);
1087   my3DActor->GetMapper()->SetLookupTable(myLookupTable);
1088   my3DExtActor->GetMapper()->SetLookupTable(myLookupTable);
1089     
1090   vtkFloatingPointType aFactor, aUnits;
1091   my2DActor->GetPolygonOffsetParameters(aFactor,aUnits);
1092   my2DActor->SetPolygonOffsetParameters(aFactor,aUnits*0.75);
1093   my2DExtActor->SetPolygonOffsetParameters(aFactor,aUnits*0.5);
1094
1095   SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
1096   if( !mgr )
1097     return false;
1098
1099   //SetIsShrunkable(theGrid->GetNumberOfCells() > 10);
1100   SetIsShrunkable(true);
1101
1102   SetShrinkFactor( SMESH::GetFloat( "SMESH:shrink_coeff", 75 ) / 100. );
1103
1104   int aMode = mgr->integerValue( "SMESH", "display_mode" );
1105   SetRepresentation(-1);
1106   
1107   if(aMode == 0){
1108     SetRepresentation(eEdge);
1109   }else if(aMode == 1){
1110     SetRepresentation(eSurface);
1111   }else if(aMode == 2){
1112     SetRepresentation(ePoint);
1113   }
1114   
1115   if(aMode == 3){
1116     SetShrink();
1117   }
1118
1119   if( dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
1120     SetIsDisplayNameActor( true );
1121
1122   int aMarkerType = mgr->integerValue( "SMESH", "type_of_marker", 1 ); // dot
1123   int aMarkerScale = mgr->integerValue( "SMESH", "marker_scale", 9 );  // 5 pixels
1124   SetMarkerStd( (VTK::MarkerType)aMarkerType, (VTK::MarkerScale)aMarkerScale );
1125
1126   myTimeStamp->Modified();
1127   Modified();
1128   return true;
1129 }
1130
1131
1132 vtkFloatingPointType* SMESH_ActorDef::GetBounds(){
1133   return myNodeActor->GetBounds();
1134 }
1135
1136
1137 vtkDataSet* SMESH_ActorDef::GetInput(){
1138   return GetUnstructuredGrid();
1139 }
1140
1141
1142 void SMESH_ActorDef::SetTransform(VTKViewer_Transform* theTransform){
1143   Superclass::SetTransform(theTransform);
1144
1145   myNodeActor->SetTransform(theTransform);
1146   myBaseActor->SetTransform(theTransform);
1147   
1148   myHighlitableActor->SetTransform(theTransform);
1149
1150   myNodeExtActor->SetTransform(theTransform);
1151
1152   my0DActor->SetTransform(theTransform);
1153   //my0DExtActor->SetTransform(theTransform);
1154
1155   my1DActor->SetTransform(theTransform);
1156   my1DExtActor->SetTransform(theTransform);
1157
1158   my2DActor->SetTransform(theTransform);
1159   my2DExtActor->SetTransform(theTransform);
1160   my3DActor->SetTransform(theTransform);
1161   my3DExtActor->SetTransform(theTransform);
1162
1163   Modified();
1164 }
1165
1166
1167 void SMESH_ActorDef::SetMapper(vtkMapper* theMapper){
1168   vtkLODActor::SetMapper(theMapper);
1169 }
1170
1171
1172 void SMESH_ActorDef::ShallowCopy(vtkProp *prop){
1173   SALOME_Actor::ShallowCopy(prop);
1174 }
1175
1176
1177 vtkMapper* SMESH_ActorDef::GetMapper(){
1178   // VSR 13/07/2011: Revert back previous fix for issue 0020749 since it causes regressions, see issues 0021322, 0021323
1179   // To be removed later or fix to be improved
1180   //return myMapper;
1181   return myPickableActor->GetMapper();
1182 }
1183
1184
1185 vtkUnstructuredGrid* SMESH_ActorDef::GetUnstructuredGrid(){ 
1186   return myVisualObj->GetUnstructuredGrid();
1187 }
1188
1189
1190 bool SMESH_ActorDef::IsInfinitive(){
1191   vtkDataSet *aDataSet = myPickableActor->GetUnstructuredGrid();
1192   aDataSet->Update();
1193   myIsInfinite = aDataSet->GetNumberOfCells() == 0 ||
1194     ( aDataSet->GetNumberOfCells() == 1 && 
1195     aDataSet->GetCell(0)->GetCellType() == VTK_VERTEX );
1196   return SALOME_Actor::IsInfinitive();
1197 }
1198
1199
1200 void SMESH_ActorDef::SetIsShrunkable(bool theShrunkable){
1201   if ( myIsShrinkable == theShrunkable )
1202     return;
1203   myIsShrinkable = theShrunkable;
1204   Modified();
1205 }
1206
1207 vtkFloatingPointType SMESH_ActorDef::GetShrinkFactor(){
1208   return myBaseActor->GetShrinkFactor();
1209 }
1210
1211 void SMESH_ActorDef::SetShrinkFactor(vtkFloatingPointType theValue){
1212   myBaseActor->SetShrinkFactor(theValue);
1213
1214   my1DActor->SetShrinkFactor(theValue);
1215   my1DExtActor->SetShrinkFactor(theValue);
1216
1217   my2DActor->SetShrinkFactor(theValue);
1218   my2DExtActor->SetShrinkFactor(theValue);
1219   my3DActor->SetShrinkFactor(theValue);
1220   my3DExtActor->SetShrinkFactor(theValue);
1221
1222   Modified();
1223 }
1224
1225 void SMESH_ActorDef::SetShrink(){
1226   if(!myIsShrinkable) return;
1227
1228   myBaseActor->SetShrink();
1229
1230   my1DActor->SetShrink();
1231   my1DExtActor->SetShrink();
1232
1233   my2DActor->SetShrink();
1234   my2DExtActor->SetShrink();
1235   my3DActor->SetShrink();
1236   my3DExtActor->SetShrink();
1237
1238   myIsShrunk = true;
1239   Modified();
1240 }
1241
1242 void SMESH_ActorDef::UnShrink(){
1243   if(!myIsShrunk) return;
1244
1245   myBaseActor->UnShrink();
1246
1247   my1DActor->UnShrink();
1248   my1DExtActor->UnShrink();
1249
1250   my2DActor->UnShrink();
1251   my2DExtActor->UnShrink();
1252   my3DActor->UnShrink();
1253   my3DExtActor->UnShrink();
1254
1255   myIsShrunk = false;
1256   Modified();
1257 }
1258
1259
1260 int SMESH_ActorDef::GetNodeObjId(int theVtkID){
1261   return myPickableActor->GetNodeObjId(theVtkID);
1262 }
1263
1264 vtkFloatingPointType* SMESH_ActorDef::GetNodeCoord(int theObjID){
1265   return myPickableActor->GetNodeCoord(theObjID);
1266 }
1267
1268
1269 int SMESH_ActorDef::GetElemObjId(int theVtkID){
1270   return myPickableActor->GetElemObjId(theVtkID);
1271 }
1272
1273 vtkCell* SMESH_ActorDef::GetElemCell(int theObjID){
1274   return myPickableActor->GetElemCell(theObjID);
1275 }
1276
1277
1278 void SMESH_ActorDef::SetVisibility(int theMode){
1279   SetVisibility(theMode,true);
1280 }
1281
1282
1283 void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation){
1284   SALOME_Actor::SetVisibility(theMode);
1285
1286   myNodeActor->VisibilityOff();
1287   myBaseActor->VisibilityOff();
1288   
1289   myNodeExtActor->VisibilityOff();
1290
1291   my0DActor->VisibilityOff();
1292   //my0DExtActor->VisibilityOff();
1293
1294   my1DActor->VisibilityOff();
1295   my1DExtActor->VisibilityOff();
1296   
1297   my2DActor->VisibilityOff();
1298   my2DExtActor->VisibilityOff();
1299   my3DActor->VisibilityOff();
1300   my3DExtActor->VisibilityOff();
1301   
1302   myScalarBarActor->VisibilityOff();
1303   myPointLabels->VisibilityOff();
1304   myCellsLabels->VisibilityOff();
1305   
1306   if(GetVisibility()){
1307     if(theIsUpdateRepersentation)
1308       SetRepresentation(GetRepresentation());
1309     
1310     if(myControlMode != eNone){
1311       switch(myControlMode){
1312       case eFreeNodes:
1313         myNodeExtActor->VisibilityOn();
1314         break;
1315       case eFreeEdges:
1316       case eFreeBorders:
1317         my1DExtActor->VisibilityOn();
1318         break;
1319       case eFreeFaces:
1320       case eBareBorderFace:
1321       case eOverConstrainedFace:
1322         my2DExtActor->VisibilityOn();
1323         break;
1324       case eBareBorderVolume:
1325       case eOverConstrainedVolume:
1326         my3DExtActor->VisibilityOn();
1327         break;
1328       case eLength2D:
1329       case eMultiConnection2D:
1330         my1DExtActor->VisibilityOn();
1331       default:
1332         if(myControlActor->GetUnstructuredGrid()->GetNumberOfCells())
1333           myScalarBarActor->VisibilityOn();
1334       }
1335     }
1336
1337     if(myRepresentation != ePoint)
1338       myPickableActor->VisibilityOn();
1339     else {
1340       myNodeActor->VisibilityOn();
1341     }
1342
1343     if(myEntityMode & e0DElements){
1344       my0DActor->VisibilityOn();
1345     }
1346
1347     if(myEntityMode & eEdges && GetRepresentation() != ePoint){
1348       my1DActor->VisibilityOn();
1349     }
1350     
1351     if(myEntityMode & eFaces && GetRepresentation() != ePoint){
1352       my2DActor->VisibilityOn();
1353     }
1354     
1355     if(myEntityMode & eVolumes && GetRepresentation() != ePoint){
1356       my3DActor->VisibilityOn();
1357     }
1358     
1359     if(myIsPointsLabeled){ 
1360       myPointLabels->VisibilityOn();
1361       myNodeActor->VisibilityOn();
1362     }
1363
1364     if(myIsCellsLabeled) 
1365       myCellsLabels->VisibilityOn();
1366   } 
1367 #ifndef DISABLE_PLOT2DVIEWER
1368   else
1369     SMESH::ProcessIn2DViewers(this,SMESH::RemoveFrom2dViewer);
1370 #endif
1371   UpdateHighlight();
1372   Modified();
1373 }
1374
1375
1376 void SMESH_ActorDef::SetEntityMode(unsigned int theMode)
1377 {
1378   myEntityState = eAllEntity;
1379
1380   if(!myVisualObj->GetNbEntities(SMDSAbs_0DElement)) {
1381     myEntityState &= ~e0DElements;
1382     theMode &= ~e0DElements;
1383   }
1384
1385   if(!myVisualObj->GetNbEntities(SMDSAbs_Edge)) {
1386     myEntityState &= ~eEdges;
1387     theMode &= ~eEdges;
1388   }
1389
1390   if(!myVisualObj->GetNbEntities(SMDSAbs_Face)) {
1391     myEntityState &= ~eFaces;
1392     theMode &= ~eFaces;
1393   }
1394
1395   if(!myVisualObj->GetNbEntities(SMDSAbs_Volume)) {
1396     myEntityState &= ~eVolumes;
1397     theMode &= ~eVolumes;
1398   }
1399
1400   if (!theMode) {
1401     if(myVisualObj->GetNbEntities(SMDSAbs_0DElement))
1402       theMode |= e0DElements;
1403
1404     if(myVisualObj->GetNbEntities(SMDSAbs_Edge))
1405       theMode |= eEdges;
1406
1407     if(myVisualObj->GetNbEntities(SMDSAbs_Face))
1408       theMode |= eFaces;
1409
1410     if(myVisualObj->GetNbEntities(SMDSAbs_Volume))
1411       theMode |= eVolumes;
1412   }
1413
1414   myBaseActor->myGeomFilter->SetInside(myEntityMode != myEntityState);
1415
1416   myEntityMode = theMode;
1417   VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
1418   aFilter = myBaseActor->GetExtractUnstructuredGrid();
1419   aFilter->ClearRegisteredCellsWithType();
1420   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
1421
1422   VTKViewer_ExtractUnstructuredGrid* aHightFilter = myHighlitableActor->GetExtractUnstructuredGrid();
1423   aHightFilter->ClearRegisteredCellsWithType();
1424   aHightFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
1425
1426   if (myEntityMode & e0DElements) {
1427     if (MYDEBUG) MESSAGE("0D ELEMENTS");
1428     aFilter->RegisterCellsWithType(VTK_VERTEX);
1429     aHightFilter->RegisterCellsWithType(VTK_VERTEX);
1430   }
1431
1432   if (myEntityMode & eEdges) {
1433     if (MYDEBUG) MESSAGE("EDGES");
1434     aFilter->RegisterCellsWithType(VTK_LINE);
1435     aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
1436
1437     aHightFilter->RegisterCellsWithType(VTK_LINE);
1438     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
1439   }
1440
1441   if (myEntityMode & eFaces) {
1442     if (MYDEBUG) MESSAGE("FACES");
1443     aFilter->RegisterCellsWithType(VTK_TRIANGLE);
1444     aFilter->RegisterCellsWithType(VTK_POLYGON);
1445     aFilter->RegisterCellsWithType(VTK_QUAD);
1446     aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
1447     aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
1448
1449     aHightFilter->RegisterCellsWithType(VTK_TRIANGLE);
1450     aHightFilter->RegisterCellsWithType(VTK_POLYGON);
1451     aHightFilter->RegisterCellsWithType(VTK_QUAD);
1452     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
1453     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
1454   }
1455
1456   if (myEntityMode & eVolumes) {
1457     if (MYDEBUG) MESSAGE("VOLUMES");
1458     aFilter->RegisterCellsWithType(VTK_TETRA);
1459     aFilter->RegisterCellsWithType(VTK_VOXEL);
1460     aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1461     aFilter->RegisterCellsWithType(VTK_WEDGE);
1462     aFilter->RegisterCellsWithType(VTK_PYRAMID);
1463     aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
1464     aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
1465     aFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
1466     aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1467 //#ifdef VTK_HAVE_POLYHEDRON
1468     aFilter->RegisterCellsWithType(VTK_POLYHEDRON);
1469 //#endif
1470     
1471     aHightFilter->RegisterCellsWithType(VTK_TETRA);
1472     aHightFilter->RegisterCellsWithType(VTK_VOXEL);
1473     aHightFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1474     aHightFilter->RegisterCellsWithType(VTK_WEDGE);
1475     aHightFilter->RegisterCellsWithType(VTK_PYRAMID);
1476     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
1477     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
1478     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
1479     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_PYRAMID);
1480     aHightFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1481 //#ifdef VTK_HAVE_POLYHEDRON
1482     aHightFilter->RegisterCellsWithType(VTK_POLYHEDRON);
1483 //#endif
1484   }
1485   aFilter->Update();
1486   if (MYDEBUG) MESSAGE(aFilter->GetOutput()->GetNumberOfCells());
1487   SetVisibility(GetVisibility(),false);
1488 }
1489
1490 void SMESH_ActorDef::SetRepresentation (int theMode)
1491
1492   int aNbEdges = myVisualObj->GetNbEntities(SMDSAbs_Edge);
1493   int aNbFaces = myVisualObj->GetNbEntities(SMDSAbs_Face);
1494   int aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume);
1495
1496   if (theMode < 0) {
1497     myRepresentation = eSurface;
1498     if (!aNbFaces && !aNbVolumes && aNbEdges) {
1499       myRepresentation = eEdge;
1500     } else if (!aNbFaces && !aNbVolumes && !aNbEdges) {
1501       myRepresentation = ePoint;
1502     }
1503   } else {
1504     switch (theMode) {
1505     case eEdge:
1506       if (!aNbFaces && !aNbVolumes && !aNbEdges) return;
1507       break;
1508     case eSurface:
1509       if (!aNbFaces && !aNbVolumes) return;
1510       break;
1511     }    
1512     myRepresentation = theMode;
1513   }
1514
1515   if (!GetUnstructuredGrid()->GetNumberOfCells())
1516     myRepresentation = ePoint;
1517
1518   if (myIsShrunk) {
1519     if (myRepresentation == ePoint) {
1520       UnShrink();
1521       myIsShrunk = true;
1522     } else {
1523       SetShrink();
1524     }      
1525   }
1526
1527   myPickableActor = myBaseActor;
1528   myNodeActor->SetVisibility(false);
1529   myNodeExtActor->SetVisibility(false);
1530   vtkProperty *aProp = NULL, *aBackProp = NULL;
1531   SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::EReperesent(-1);
1532   SMESH_Actor::EQuadratic2DRepresentation aQuadraticMode = GetQuadratic2DRepresentation();
1533   switch (myRepresentation) {
1534   case ePoint:
1535     myPickableActor = myNodeActor;
1536     myNodeActor->SetVisibility(true);
1537     aQuadraticMode = SMESH_Actor::eLines;
1538     aProp = aBackProp = myNodeProp;
1539     aReperesent = SMESH_DeviceActor::ePoint;
1540     break;
1541   case eEdge:
1542     aProp = aBackProp = myEdgeProp;
1543     aReperesent = SMESH_DeviceActor::eInsideframe;
1544     break;
1545   case eSurface:
1546     aProp = mySurfaceProp;
1547     aBackProp = myBackSurfaceProp;
1548     aReperesent = SMESH_DeviceActor::eSurface;
1549     break;
1550   }
1551
1552   my2DActor->SetProperty(aProp);
1553   my2DActor->SetBackfaceProperty(aBackProp);
1554   my2DActor->SetRepresentation(aReperesent);
1555
1556   if(aQuadraticMode == SMESH_Actor::eLines)
1557     my2DActor->SetQuadraticArcMode(false);
1558   else if(aQuadraticMode == SMESH_Actor::eArcs)
1559     my2DActor->SetQuadraticArcMode(true);
1560
1561   my2DExtActor->SetRepresentation(aReperesent);
1562   
1563   my3DActor->SetProperty(aProp);
1564   my3DActor->SetBackfaceProperty(aBackProp);
1565   my3DActor->SetRepresentation(aReperesent);
1566
1567   //my0DExtActor->SetVisibility(false);
1568   my1DExtActor->SetVisibility(false);
1569   my2DExtActor->SetVisibility(false);
1570   my3DExtActor->SetVisibility(false);
1571
1572   // ???
1573   //my0DActor->SetProperty(aProp);
1574   //my0DActor->SetBackfaceProperty(aBackProp);
1575   my0DActor->SetRepresentation(aReperesent);
1576   //my0DExtActor->SetRepresentation(aReperesent);
1577
1578   switch(myControlMode){
1579   case eLength:
1580   case eMultiConnection:
1581     aProp = aBackProp = my1DProp;
1582     if(myRepresentation != ePoint)
1583       aReperesent = SMESH_DeviceActor::eInsideframe;
1584     break;
1585   }
1586   
1587   if(aQuadraticMode == SMESH_Actor::eLines)
1588     my1DActor->SetQuadraticArcMode(false);
1589   else if(aQuadraticMode == SMESH_Actor::eArcs)
1590     my1DActor->SetQuadraticArcMode(true);
1591
1592   my1DActor->SetProperty(aProp);
1593   my1DActor->SetBackfaceProperty(aBackProp);
1594   my1DActor->SetRepresentation(aReperesent);
1595
1596   my1DExtActor->SetRepresentation(aReperesent);
1597
1598   if(myIsPointsVisible)
1599     myPickableActor = myNodeActor;
1600   if(GetPointRepresentation())
1601     myNodeActor->SetVisibility(true);
1602
1603   SetMapper(myPickableActor->GetMapper());
1604
1605   SetVisibility(GetVisibility(),false);
1606
1607   Modified();
1608 }
1609
1610
1611 void SMESH_ActorDef::SetPointRepresentation(bool theIsPointsVisible){
1612   if ( myIsPointsVisible == theIsPointsVisible )
1613     return;
1614   myIsPointsVisible = theIsPointsVisible;
1615   SetRepresentation(GetRepresentation());
1616 }
1617
1618 bool SMESH_ActorDef::GetPointRepresentation(){ 
1619   return myIsPointsVisible || myIsPointsLabeled;
1620 }
1621
1622
1623 void SMESH_ActorDef::UpdateHighlight(){
1624   myHighlitableActor->SetVisibility(false);
1625   myHighlitableActor->SetHighlited(false);
1626
1627   if(myIsHighlighted){
1628     myHighlitableActor->SetProperty(myHighlightProp);
1629   }else if(myIsPreselected){
1630     myHighlitableActor->SetProperty(myPreselectProp);
1631   }
1632
1633   bool anIsVisible = GetVisibility();
1634
1635   if(myIsHighlighted || myIsPreselected){
1636     if(GetUnstructuredGrid()->GetNumberOfCells()){
1637       myHighlitableActor->SetHighlited(anIsVisible);
1638       myHighlitableActor->SetVisibility(anIsVisible);
1639       myHighlitableActor->GetExtractUnstructuredGrid()->
1640         SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::eCells);
1641       myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
1642     }else if(myRepresentation == ePoint || GetPointRepresentation()){
1643       myHighlitableActor->SetHighlited(anIsVisible);
1644       myHighlitableActor->GetExtractUnstructuredGrid()->
1645         SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
1646       myHighlitableActor->SetVisibility(anIsVisible);
1647       myHighlitableActor->SetRepresentation(SMESH_DeviceActor::ePoint);
1648
1649       VTK::MarkerType aMarkerType = GetMarkerType();
1650       if(aMarkerType != VTK::MT_USER)
1651         myHighlitableActor->SetMarkerStd(aMarkerType, GetMarkerScale());
1652       else
1653         myHighlitableActor->SetMarkerTexture(GetMarkerTexture(), myMarkerTexture);
1654     }
1655   }
1656 }
1657
1658
1659 void SMESH_ActorDef::highlight(bool theHighlight){
1660   if ( myIsHighlighted == theHighlight )
1661     return;
1662   myIsHighlighted = theHighlight;
1663   UpdateHighlight();
1664 }
1665
1666
1667 void SMESH_ActorDef::SetPreSelected(bool thePreselect){ 
1668   if ( myIsPreselected == thePreselect )
1669     return;
1670   myIsPreselected = thePreselect; 
1671   UpdateHighlight();
1672 }
1673
1674
1675 // From vtkFollower
1676 int SMESH_ActorDef::RenderOpaqueGeometry(vtkViewport *vp)
1677 {
1678   if (myPickableActor->GetIsOpaque())
1679     {
1680     vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1681     this->Render(ren);
1682     return 1;
1683     }
1684   return 0;
1685 }
1686
1687
1688 int SMESH_ActorDef::RenderTranslucentGeometry(vtkViewport *vp)
1689 {
1690   if (!myPickableActor->GetIsOpaque())
1691     {
1692     vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1693     this->Render(ren);
1694     return 1;
1695     }
1696   return 0;
1697 }
1698
1699
1700 void SMESH_ActorDef::Render(vtkRenderer *ren){
1701   unsigned long aTime = myTimeStamp->GetMTime();
1702   unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1703   unsigned long aClippingTime = myImplicitBoolean->GetMTime();
1704   if(anObjTime > aTime || aClippingTime > aTime)
1705     Update();
1706 }
1707
1708
1709 void SMESH_ActorDef::Update(){
1710   if(MYDEBUG) MESSAGE("SMESH_ActorDef::Update");
1711
1712   if(GetControlMode() != eNone) {
1713     unsigned long aTime = myTimeStamp->GetMTime();
1714     unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1715     if (anObjTime > aTime)
1716       SetControlMode(GetControlMode(),false);
1717   }
1718   if(myIsPointsLabeled){
1719     SetPointsLabeled(myIsPointsLabeled);
1720   }
1721   if(myIsCellsLabeled){
1722     SetCellsLabeled(myIsCellsLabeled);
1723   }
1724   if(myIsFacesOriented){
1725     SetFacesOriented(myIsFacesOriented);
1726   }
1727   SetEntityMode(GetEntityMode());
1728   SetVisibility(GetVisibility());
1729   
1730   myTimeStamp->Modified();
1731   Modified();
1732 }
1733
1734
1735 void SMESH_ActorDef::ReleaseGraphicsResources(vtkWindow *renWin){
1736   SALOME_Actor::ReleaseGraphicsResources(renWin);
1737
1738   myPickableActor->ReleaseGraphicsResources(renWin);
1739 }
1740
1741
1742 static void GetColor(vtkProperty *theProperty, vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1743   vtkFloatingPointType* aColor = theProperty->GetColor();
1744   r = aColor[0];
1745   g = aColor[1];
1746   b = aColor[2];
1747 }
1748
1749
1750 void SMESH_ActorDef::SetOpacity(vtkFloatingPointType theValue){
1751   mySurfaceProp->SetOpacity(theValue);
1752   myBackSurfaceProp->SetOpacity(theValue);
1753   myEdgeProp->SetOpacity(theValue);
1754   myNodeProp->SetOpacity(theValue);
1755
1756   my1DProp->SetOpacity(theValue);
1757 }
1758
1759
1760 vtkFloatingPointType SMESH_ActorDef::GetOpacity(){
1761   return mySurfaceProp->GetOpacity();
1762 }
1763
1764
1765 void SMESH_ActorDef::SetSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1766   mySurfaceProp->SetColor(r,g,b);
1767   if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
1768     if( aGroupObj->GetElementType() == SMDSAbs_Face ||
1769         aGroupObj->GetElementType() == SMDSAbs_Volume )
1770       myNameActor->SetBackgroundColor(r,g,b);
1771   Modified();
1772 }
1773
1774 void SMESH_ActorDef::GetSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1775   ::GetColor(mySurfaceProp,r,g,b);
1776   my2DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1777 }
1778
1779 void SMESH_ActorDef::SetBackSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1780   myBackSurfaceProp->SetColor(r,g,b);
1781   Modified();
1782 }
1783
1784 void SMESH_ActorDef::GetBackSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1785   ::GetColor(myBackSurfaceProp,r,g,b);
1786 }
1787
1788 void SMESH_ActorDef::SetEdgeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1789   myEdgeProp->SetColor(r,g,b);
1790   my1DProp->SetColor(r,g,b);
1791   my1DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1792   if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
1793     if( aGroupObj->GetElementType() == SMDSAbs_Edge )
1794       myNameActor->SetBackgroundColor(r,g,b);
1795   Modified();
1796 }
1797
1798 void SMESH_ActorDef::GetEdgeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1799   ::GetColor(myEdgeProp,r,g,b);
1800 }
1801
1802 void SMESH_ActorDef::SetNodeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){ 
1803   myNodeProp->SetColor(r,g,b);
1804   myNodeExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1805   if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
1806     if( aGroupObj->GetElementType() == SMDSAbs_Node )
1807       myNameActor->SetBackgroundColor(r,g,b);
1808   Modified();
1809 }
1810
1811 void SMESH_ActorDef::GetNodeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){ 
1812   ::GetColor(myNodeProp,r,g,b);
1813 }
1814
1815 void SMESH_ActorDef::Set0DColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){ 
1816   my0DProp->SetColor(r,g,b);
1817   if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
1818     if( aGroupObj->GetElementType() == SMDSAbs_0DElement )
1819       myNameActor->SetBackgroundColor(r,g,b);
1820   Modified();
1821 }
1822
1823 void SMESH_ActorDef::Get0DColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){ 
1824   ::GetColor(my0DProp,r,g,b);
1825 }
1826
1827 void SMESH_ActorDef::SetHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){ 
1828   myHighlightProp->SetColor(r,g,b);
1829   Modified();
1830 }
1831
1832 void SMESH_ActorDef::GetHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){ 
1833   ::GetColor(myHighlightProp,r,g,b);
1834 }
1835
1836 void SMESH_ActorDef::SetPreHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){ 
1837   myPreselectProp->SetColor(r,g,b);
1838   Modified();
1839 }
1840
1841 void SMESH_ActorDef::GetPreHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){ 
1842   ::GetColor(myPreselectProp,r,g,b);
1843 }
1844
1845
1846 vtkFloatingPointType SMESH_ActorDef::GetLineWidth(){
1847   return myEdgeProp->GetLineWidth();
1848 }
1849
1850
1851 void SMESH_ActorDef::SetLineWidth(vtkFloatingPointType theVal){
1852   myEdgeProp->SetLineWidth(theVal);
1853
1854   my1DProp->SetLineWidth(theVal + aLineWidthInc);
1855   my1DExtProp->SetLineWidth(theVal + aLineWidthInc);
1856
1857   Modified();
1858 }
1859
1860
1861 void SMESH_ActorDef::Set0DSize(vtkFloatingPointType theVal){
1862   my0DProp->SetPointSize(theVal);
1863   Modified();
1864 }
1865
1866 vtkFloatingPointType SMESH_ActorDef::Get0DSize(){
1867   return my0DProp->GetPointSize();
1868 }
1869
1870 int SMESH_ActorDef::GetObjDimension( const int theObjId )
1871 {
1872   return myVisualObj->GetElemDimension( theObjId );
1873 }
1874
1875 bool
1876 SMESH_ActorDef::
1877 IsImplicitFunctionUsed() const
1878 {
1879   return myBaseActor->IsImplicitFunctionUsed();
1880 }
1881
1882 void
1883 SMESH_ActorDef::SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed)
1884 {
1885   myNodeActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1886   myBaseActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1887
1888   myHighlitableActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1889
1890   myNodeExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1891
1892   my0DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1893   //my0DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1894
1895   my1DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1896   my1DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1897
1898   my2DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1899   my2DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1900   my3DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1901   my3DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1902 }
1903
1904 vtkIdType 
1905 SMESH_ActorDef::AddClippingPlane(vtkPlane* thePlane)
1906 {
1907   if(thePlane){
1908     myImplicitBoolean->GetFunction()->AddItem(thePlane);
1909     myCippingPlaneCont.push_back(thePlane);
1910     if(!IsImplicitFunctionUsed())
1911       SetImplicitFunctionUsed(true);
1912   }
1913   return myCippingPlaneCont.size();
1914 }
1915
1916 void
1917 SMESH_ActorDef::
1918 RemoveAllClippingPlanes()
1919 {
1920   myImplicitBoolean->GetFunction()->RemoveAllItems();
1921   myImplicitBoolean->GetFunction()->Modified(); // VTK bug
1922   myCippingPlaneCont.clear();
1923   SetImplicitFunctionUsed(false);
1924 }
1925
1926 vtkIdType
1927 SMESH_ActorDef::
1928 GetNumberOfClippingPlanes()
1929 {
1930   return myCippingPlaneCont.size();
1931 }
1932
1933 vtkPlane* 
1934 SMESH_ActorDef::
1935 GetClippingPlane(vtkIdType theID)
1936 {
1937   if(theID >= myCippingPlaneCont.size())
1938     return NULL;
1939   return myCippingPlaneCont[theID].Get();
1940 }
1941
1942 void SMESH_ActorDef::UpdateScalarBar()
1943 {
1944   SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
1945   if( !mgr )
1946     return;
1947
1948   vtkTextProperty* aScalarBarTitleProp = vtkTextProperty::New();
1949
1950   QColor aTColor = mgr->colorValue( "SMESH", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
1951   aScalarBarTitleProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1952
1953   aScalarBarTitleProp->SetFontFamilyToArial();
1954
1955   if ( mgr->hasValue( "SMESH", "scalar_bar_title_font" ) )
1956   {
1957     QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
1958     if ( f.family() == "Arial" )
1959       aScalarBarTitleProp->SetFontFamilyToArial();
1960     else if ( f.family() == "Courier" )
1961       aScalarBarTitleProp->SetFontFamilyToCourier();
1962     else if ( f.family() == "Times" )
1963       aScalarBarTitleProp->SetFontFamilyToTimes();
1964
1965     if ( f.bold() )
1966       aScalarBarTitleProp->BoldOn();
1967     else
1968       aScalarBarTitleProp->BoldOff();
1969
1970     if ( f.italic() )
1971       aScalarBarTitleProp->ItalicOn();
1972     else
1973      aScalarBarTitleProp->ItalicOff();
1974
1975     if ( f.overline() )
1976       aScalarBarTitleProp->ShadowOn();
1977     else
1978       aScalarBarTitleProp->ShadowOff();
1979   }
1980
1981   myScalarBarActor->SetTitleTextProperty( aScalarBarTitleProp );
1982   aScalarBarTitleProp->Delete();
1983
1984   vtkTextProperty* aScalarBarLabelProp = vtkTextProperty::New();
1985
1986   aTColor = mgr->colorValue( "SMESH", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
1987   aScalarBarLabelProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1988
1989   aScalarBarLabelProp->SetFontFamilyToArial();
1990   if( mgr->hasValue( "SMESH", "scalar_bar_label_font" ) )
1991   {
1992     QFont f = mgr->fontValue( "SMESH", "scalar_bar_label_font" );
1993     if( f.family() == "Arial" )
1994       aScalarBarLabelProp->SetFontFamilyToArial();
1995     else if( f.family() == "Courier" )
1996       aScalarBarLabelProp->SetFontFamilyToCourier();
1997     else if( f.family() == "Times" )
1998       aScalarBarLabelProp->SetFontFamilyToTimes();
1999
2000     if ( f.bold() )
2001       aScalarBarLabelProp->BoldOn();
2002     else
2003       aScalarBarLabelProp->BoldOff();
2004
2005     if ( f.italic() )
2006       aScalarBarLabelProp->ItalicOn();
2007     else
2008       aScalarBarLabelProp->ItalicOff();
2009
2010     if( f.overline() )
2011       aScalarBarLabelProp->ShadowOn();
2012     else
2013       aScalarBarLabelProp->ShadowOff();
2014   }
2015
2016   myScalarBarActor->SetLabelTextProperty( aScalarBarLabelProp );
2017   aScalarBarLabelProp->Delete();
2018
2019   bool horiz = ( mgr->integerValue( "SMESH", "scalar_bar_orientation" ) == 1 );
2020   QString name = QString( "scalar_bar_%1_" ).arg( horiz ? "horizontal" : "vertical" );
2021   if( horiz )
2022     myScalarBarActor->SetOrientationToHorizontal();
2023   else
2024     myScalarBarActor->SetOrientationToVertical();
2025
2026
2027   vtkFloatingPointType aXVal = horiz ? 0.20 : 0.01;
2028   if( mgr->hasValue( "SMESH", name + "x" ) )
2029     aXVal = mgr->doubleValue( "SMESH", name + "x", aXVal );
2030
2031   vtkFloatingPointType aYVal = horiz ? 0.01 : 0.1;
2032   if( mgr->hasValue( "SMESH", name + "y" ) )
2033     aYVal = mgr->doubleValue( "SMESH", name + "y", aYVal );
2034   myScalarBarActor->SetPosition( aXVal, aYVal );
2035
2036   vtkFloatingPointType aWVal = horiz ? 0.60 : 0.10;
2037   if( mgr->hasValue( "SMESH", name + "width" ) )
2038     aWVal = mgr->doubleValue( "SMESH", name + "width", aWVal );
2039   myScalarBarActor->SetWidth( aWVal );
2040
2041   vtkFloatingPointType aHVal = horiz ? 0.12 : 0.80;
2042   if( mgr->hasValue( "SMESH", name + "height" ) )
2043     aHVal = mgr->doubleValue( "SMESH", name + "height", aHVal );
2044   myScalarBarActor->SetHeight( aHVal );
2045
2046   int anIntVal = 5;
2047   if( mgr->hasValue( "SMESH", "scalar_bar_num_labels" ) )
2048     anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_labels", anIntVal );
2049   myScalarBarActor->SetNumberOfLabels( anIntVal == 0 ? 5: anIntVal );
2050
2051   anIntVal = 64;
2052   if( mgr->hasValue( "SMESH", "scalar_bar_num_colors" ) )
2053     anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_colors", anIntVal );
2054   myScalarBarActor->SetMaximumNumberOfColors( anIntVal == 0 ? 64 : anIntVal );
2055
2056   bool distributionVisibility = mgr->booleanValue("SMESH","distribution_visibility");
2057   myScalarBarActor->SetDistributionVisibility(distributionVisibility);
2058
2059   int coloringType = mgr->integerValue("SMESH", "distribution_coloring_type", 0);
2060   myScalarBarActor->SetDistributionColoringType(coloringType);
2061   
2062   QColor distributionColor = mgr->colorValue("SMESH", "distribution_color",
2063                                              QColor(255, 255, 255));
2064   double rgb[3];
2065   rgb[0]= distributionColor.red()/255.;
2066   rgb[1]= distributionColor.green()/255.;
2067   rgb[2]= distributionColor.blue()/255.;
2068   myScalarBarActor->SetDistributionColor(rgb);
2069
2070   
2071 }
2072
2073 void SMESH_ActorDef::UpdateDistribution()
2074 {
2075   if(SMESH::Controls::NumericalFunctor* fun =
2076      dynamic_cast<SMESH::Controls::NumericalFunctor*>(myFunctor.get()))
2077   {
2078     int nbIntervals = myScalarBarActor->GetMaximumNumberOfColors();
2079     std::vector<int> nbEvents;
2080     std::vector<double> funValues;
2081     SMESH_VisualObjDef::TEntityList elems;
2082     if ( ! dynamic_cast<SMESH_MeshObj*>(myVisualObj.get()))
2083       dynamic_cast<SMESH_VisualObjDef*>(myVisualObj.get())->GetEntities( fun->GetType(), elems );
2084     std::vector<int> elemIds;
2085     for ( SMESH_VisualObjDef::TEntityList::iterator e = elems.begin(); e != elems.end(); ++e)
2086       elemIds.push_back( (*e)->GetID());
2087     vtkLookupTable* lookupTable = static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
2088     double * range = lookupTable->GetRange();
2089     fun->GetHistogram(nbIntervals, nbEvents, funValues, elemIds, range);
2090     myScalarBarActor->SetDistribution(nbEvents);
2091   }
2092 }
2093
2094 void SMESH_ActorDef::SetQuadratic2DRepresentation(EQuadratic2DRepresentation theMode)
2095 {
2096   switch(theMode) {
2097   case SMESH_Actor::eLines :
2098     myHighlitableActor->SetQuadraticArcMode(false);
2099     my2DActor->SetQuadraticArcMode(false);
2100     my1DActor->SetQuadraticArcMode(false);
2101     break;
2102   case SMESH_Actor::eArcs :
2103     myHighlitableActor->SetQuadraticArcMode(true);
2104     if(GetRepresentation() != SMESH_Actor::ePoint) {
2105       my2DActor->SetQuadraticArcMode(true);
2106       my1DActor->SetQuadraticArcMode(true);
2107     }
2108     break;
2109   default:
2110     break;
2111   }
2112 }
2113
2114
2115 SMESH_Actor::EQuadratic2DRepresentation SMESH_ActorDef::GetQuadratic2DRepresentation()
2116 {
2117   if(myHighlitableActor->GetQuadraticArcMode())
2118     return SMESH_Actor::eArcs;
2119   else
2120     return SMESH_Actor::eLines;
2121 }
2122
2123 void SMESH_ActorDef::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale )
2124 {
2125   SALOME_Actor::SetMarkerStd( theMarkerType, theMarkerScale );
2126   myNodeActor->SetMarkerStd( theMarkerType, theMarkerScale );
2127   myNodeExtActor->SetMarkerStd( theMarkerType, theMarkerScale );
2128 }
2129
2130 void SMESH_ActorDef::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
2131 {
2132   SALOME_Actor::SetMarkerTexture( theMarkerId, theMarkerTexture );
2133   myNodeActor->SetMarkerTexture( theMarkerId, theMarkerTexture );
2134   myNodeExtActor->SetMarkerTexture( theMarkerId, theMarkerTexture );
2135   myMarkerTexture = theMarkerTexture; // for deferred update of myHighlightActor
2136 }
2137
2138 #ifndef DISABLE_PLOT2DVIEWER
2139 SPlot2d_Histogram* SMESH_ActorDef::UpdatePlot2Histogram() {
2140
2141   if(my2dHistogram)
2142     my2dHistogram->clearAllPoints();
2143   
2144   if(SMESH::Controls::NumericalFunctor* fun =
2145      dynamic_cast<SMESH::Controls::NumericalFunctor*>(myFunctor.get()))
2146   {
2147     
2148     if(!my2dHistogram) {
2149       my2dHistogram = new SPlot2d_Histogram();
2150       Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(getIO()->getEntry(),"SMESH",getName());
2151       my2dHistogram->setIO(anIO);
2152     }
2153     
2154     int nbIntervals = myScalarBarActor->GetMaximumNumberOfColors();
2155     std::vector<int> nbEvents;
2156     std::vector<double> funValues;
2157     SMESH_VisualObjDef::TEntityList elems;
2158     if ( ! dynamic_cast<SMESH_MeshObj*>(myVisualObj.get()))
2159       dynamic_cast<SMESH_VisualObjDef*>(myVisualObj.get())->GetEntities( fun->GetType(), elems );
2160     std::vector<int> elemIds;
2161     
2162     for ( SMESH_VisualObjDef::TEntityList::iterator e = elems.begin(); e != elems.end(); ++e)
2163       elemIds.push_back( (*e)->GetID());
2164
2165     vtkLookupTable* lookupTable = static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
2166     double * range = lookupTable->GetRange();
2167     fun->GetHistogram(nbIntervals, nbEvents, funValues, elemIds, range);
2168
2169     for ( int i = 0; i < std::min( nbEvents.size(), funValues.size() -1 ); i++ ) 
2170       my2dHistogram->addPoint(funValues[i] + (funValues[i+1] - funValues[i])/2.0, static_cast<double>(nbEvents[i]));
2171
2172     if(funValues.size() >= 2)
2173       my2dHistogram->setWidth((funValues[1] - funValues[0]) * 0.8) ;
2174
2175   }
2176   
2177   //Color of the histogram
2178   if(myScalarBarActor->GetDistributionColoringType() == SMESH_MULTICOLOR_TYPE)
2179     my2dHistogram->setAutoAssign(true);
2180   else {
2181     double rgb[3];
2182     myScalarBarActor->GetDistributionColor(rgb);
2183     QColor aColor = QColor( (int)( rgb[0]*255 ), (int)( rgb[1]*255 ), (int)( rgb[2]*255 ) );
2184     my2dHistogram->setColor(aColor);
2185
2186   }
2187       
2188   return my2dHistogram;
2189 }
2190 #endif