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