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