Salome HOME
23303: [EDF 12024] Filter for nodes connectivity
[modules/smesh.git] / src / OBJECT / SMESH_Actor.cxx
1 // Copyright (C) 2007-2016  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, or (at your option) any later version.
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_NodeLabelActor.h"
32 #include "SMESH_CellLabelActor.h"
33 #include "SMESH_ObjectDef.h"
34 #include "SMESH_ControlsDef.hxx"
35 #include "SMDS_UnstructuredGrid.hxx"
36 #include "SMESH_ScalarBarActor.h"
37 #include "VTKViewer_ExtractUnstructuredGrid.h"
38 #include "VTKViewer_FramedTextActor.h"
39 #include "SALOME_InteractiveObject.hxx"
40 #include "SMESH_SVTKActor.h"
41
42 #include "SUIT_Session.h"
43 #include "SUIT_ResourceMgr.h"
44
45 #include <Qtx.h>
46
47 #ifndef DISABLE_PLOT2DVIEWER
48 #include <SPlot2d_Histogram.h>
49 #endif
50
51 #include <vtkProperty.h>
52 #include <vtkTimeStamp.h>
53 #include <vtkObjectFactory.h>
54 #include <vtkShrinkPolyData.h>
55 #include <vtkMergeFilter.h>
56
57 #include <vtkMatrix4x4.h>
58 #include <vtkUnstructuredGrid.h>
59 #include <vtkPointData.h>
60 #include <vtkCellData.h>
61
62 #include <vtkMapper.h>
63 #include <vtkRenderer.h>
64
65 #include <vtkCell.h>
66 #include <vtkIdList.h>
67 #include <vtkIntArray.h>
68
69 #include <vtkActor2D.h>
70 #include <vtkProperty2D.h>
71 #include <vtkPolyData.h>
72 #include <vtkTextProperty.h>
73
74 #include <vtkLookupTable.h>
75
76 #include <vtkMath.h>
77 #include <vtkPlane.h>
78 #include <vtkPlaneCollection.h>
79 #include <vtkImplicitBoolean.h>
80 #include <vtkImplicitFunctionCollection.h>
81
82 #include "utilities.h"
83
84 #ifdef _DEBUG_
85 static int MYDEBUG = 0;
86 #else
87 static int MYDEBUG = 0;
88 #endif
89
90 static int aLineWidthInc = 2;
91
92
93 SMESH_ActorDef* SMESH_ActorDef::New(){
94   return new SMESH_ActorDef();
95 }
96
97
98 SMESH_Actor* SMESH_Actor::New(TVisualObjPtr theVisualObj,
99                               const char* theEntry,
100                               const char* theName,
101                               int theIsClear)
102 {
103   SMESH_ActorDef* anActor = NULL;
104   if(theVisualObj->IsValid() ) {
105     anActor = SMESH_ActorDef::New();
106     if(!anActor->Init(theVisualObj,theEntry,theName,theIsClear)){
107       anActor->Delete();
108       anActor = NULL;
109     }
110     if( anActor )
111       anActor->UpdateScalarBar();
112   }
113   return anActor;
114 }
115
116
117 SMESH_ActorDef::SMESH_ActorDef()
118 {
119   if(MYDEBUG) MESSAGE("SMESH_ActorDef - "<<this);
120   myBaseActor = SMESH_DeviceActor::New();
121
122   myTimeStamp = vtkTimeStamp::New();
123
124   myIsPointsVisible = false;
125   myIsEntityModeCache = false;
126
127   myHighlightActor = SMESH_SVTKActor::New();
128   myHighlightActor->Delete(); // vtkSmartPointer!
129   myHighlightActor->Initialize();
130
131   myPreHighlightActor = SMESH_SVTKActor::New();
132   myPreHighlightActor->Delete();
133   myPreHighlightActor->Initialize();
134
135   myIsShrinkable = false;
136   myIsShrunk = false;
137
138   myIsFacesOriented = false;
139
140   myControlsPrecision = -1;
141   SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
142
143   if ( mgr && mgr->booleanValue( "SMESH", "use_precision", false ) )
144     myControlsPrecision = mgr->integerValue( "SMESH", "controls_precision", -1);
145
146   double aElem0DSize    = SMESH::GetFloat("SMESH:elem0d_size",5);
147   double aBallElemSize  = SMESH::GetFloat("SMESH:ball_elem_size",10);
148   double aBallElemScale = SMESH::GetFloat("SMESH:ball_elem_scale",1.0);
149   double aLineWidth     = SMESH::GetFloat("SMESH:element_width",1);
150   double aOutlineWidth  = SMESH::GetFloat("SMESH:outline_width",1);
151
152   SMESH::LabelFont aFamilyNd = SMESH::FntTimes;
153   bool aBoldNd    = true;
154   bool anItalicNd = false;
155   bool aShadowNd  = false;
156   int  aSizeNd    = 10;
157   if ( mgr->hasValue( "SMESH", "numbering_node_font" ) ) {
158     QFont f = mgr->fontValue( "SMESH", "numbering_node_font" );
159     if ( f.family()      == "Arial" )   aFamilyNd = SMESH::FntArial;
160     else if ( f.family() == "Courier" ) aFamilyNd = SMESH::FntCourier;
161     else if ( f.family() == "Times" )   aFamilyNd = SMESH::FntTimes;
162     aBoldNd    = f.bold();
163     anItalicNd = f.italic();
164     aShadowNd  = f.overline();
165     aSizeNd    = f.pointSize();
166   }
167   double anRGBNd[3] = {1,1,1};
168   SMESH::GetColor( "SMESH", "numbering_node_color", anRGBNd[0], anRGBNd[1], anRGBNd[2], QColor( 255, 255, 255 ) );
169
170   SMESH::LabelFont aFamilyEl = SMESH::FntTimes;
171   bool aBoldEl    = true;
172   bool anItalicEl = false;
173   bool aShadowEl  = false;
174   int  aSizeEl    = 12;
175   if ( mgr->hasValue( "SMESH", "numbering_elem_font" ) ) {
176     QFont f = mgr->fontValue( "SMESH", "numbering_elem_font" );
177     if ( f.family()      == "Arial" )   aFamilyEl = SMESH::FntArial;
178     else if ( f.family() == "Courier" ) aFamilyEl = SMESH::FntCourier;
179     else if ( f.family() == "Times" )   aFamilyEl = SMESH::FntTimes;
180     aBoldEl    = f.bold();
181     anItalicEl = f.italic();
182     aShadowEl  = f.overline();
183     aSizeEl    = f.pointSize();
184   }
185   double anRGBEl[3] = {0,1,0};
186   SMESH::GetColor( "SMESH", "numbering_elem_color", anRGBEl[0], anRGBEl[1], anRGBEl[2], QColor( 0, 255, 0 ) );
187
188   vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
189   VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
190
191   //Definition 2D and 3D devices of the actor
192   //-----------------------------------------
193   double anRGB[3] = {1,1,1};
194   mySurfaceProp = vtkProperty::New();
195   QColor ffc, bfc;
196   int delta;
197   SMESH::GetColor( "SMESH", "fill_color", ffc, delta, "0,170,255|-100" ) ;
198   mySurfaceProp->SetColor( ffc.red() / 255. , ffc.green() / 255. , ffc.blue() / 255. );
199   myDeltaBrightness = delta;
200
201   myBackSurfaceProp = vtkProperty::New();
202   bfc = Qtx::mainColorToSecondary(ffc, delta);
203   myBackSurfaceProp->SetColor( bfc.red() / 255. , bfc.green() / 255. , bfc.blue() / 255. );
204
205   myNormalVProp = vtkProperty::New();
206   SMESH::GetColor( "SMESH", "volume_color", ffc, delta, "255,0,170|-100" );
207   myNormalVProp->SetColor( ffc.redF(), ffc.greenF(), ffc.blueF() );
208   myDeltaVBrightness = delta;
209
210   myReversedVProp = vtkProperty::New();
211   bfc = Qtx::mainColorToSecondary(ffc, delta);
212   myReversedVProp->SetColor( bfc.red() / 255. , bfc.green() / 255. , bfc.blue() / 255. );
213
214   my2DActor = SMESH_CellLabelActor::New();
215   my2DActor->SetStoreGemetryMapping(true);
216   my2DActor->SetUserMatrix(aMatrix);
217   my2DActor->PickableOff();
218   my2DActor->SetFontProperties( aFamilyEl, aSizeEl, aBoldEl, anItalicEl, aShadowEl, anRGBEl[0], anRGBEl[1], anRGBEl[2] );
219   my2DActor->SetProperty(mySurfaceProp);
220   my2DActor->SetBackfaceProperty(myBackSurfaceProp);
221   my2DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
222   aFilter = my2DActor->GetExtractUnstructuredGrid();
223   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
224   aFilter->RegisterCellsWithType(VTK_TRIANGLE);
225   aFilter->RegisterCellsWithType(VTK_QUAD);
226   aFilter->RegisterCellsWithType(VTK_POLYGON);
227   aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
228   aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
229   aFilter->RegisterCellsWithType(VTK_QUADRATIC_POLYGON);
230   aFilter->RegisterCellsWithType(VTK_BIQUADRATIC_QUAD);
231   aFilter->RegisterCellsWithType(VTK_BIQUADRATIC_TRIANGLE);
232
233   my2DExtProp = vtkProperty::New();
234   my2DExtProp->DeepCopy(mySurfaceProp);
235   SMESH::GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
236   anRGB[0] = 1 - anRGB[0];
237   anRGB[1] = 1 - anRGB[1];
238   anRGB[2] = 1 - anRGB[2];
239   my2DExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
240
241   my2DExtActor = SMESH_DeviceActor::New();
242   my2DExtActor->SetUserMatrix(aMatrix);
243   my2DExtActor->PickableOff();
244   my2DExtActor->SetProperty(my2DExtProp);
245   my2DExtActor->SetBackfaceProperty(my2DExtProp);
246   my2DExtActor->SetRepresentation(SMESH_DeviceActor::eInsideframe);
247   aFilter = my2DExtActor->GetExtractUnstructuredGrid();
248   aFilter->RegisterCellsWithType(VTK_TRIANGLE);
249   aFilter->RegisterCellsWithType(VTK_QUAD);
250   aFilter->RegisterCellsWithType(VTK_POLYGON);
251   aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
252   aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
253   aFilter->RegisterCellsWithType(VTK_QUADRATIC_POLYGON);
254   aFilter->RegisterCellsWithType(VTK_BIQUADRATIC_QUAD);
255   aFilter->RegisterCellsWithType(VTK_BIQUADRATIC_TRIANGLE);
256
257   my3DActor = SMESH_CellLabelActor::New();
258   my3DActor->SetStoreGemetryMapping(true);
259   my3DActor->SetUserMatrix(aMatrix);
260   my3DActor->PickableOff();
261   my3DActor->SetFontProperties( aFamilyEl, aSizeEl, aBoldEl, anItalicEl, aShadowEl, anRGBEl[0], anRGBEl[1], anRGBEl[2] );
262   my3DActor->SetProperty(myNormalVProp);
263   my3DActor->SetBackfaceProperty(myReversedVProp);
264   my3DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
265   my3DActor->SetCoincident3DAllowed(true);
266   aFilter = my3DActor->GetExtractUnstructuredGrid();
267   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
268   aFilter->RegisterCellsWithType(VTK_TETRA);
269   aFilter->RegisterCellsWithType(VTK_VOXEL);
270   aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
271   aFilter->RegisterCellsWithType(VTK_WEDGE);
272   aFilter->RegisterCellsWithType(VTK_PYRAMID);
273   aFilter->RegisterCellsWithType(VTK_HEXAGONAL_PRISM);
274   aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
275   aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
276   aFilter->RegisterCellsWithType(VTK_TRIQUADRATIC_HEXAHEDRON);
277   aFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
278   aFilter->RegisterCellsWithType(VTK_QUADRATIC_PYRAMID);
279   aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
280   aFilter->RegisterCellsWithType(VTK_POLYHEDRON);
281
282   my3DExtProp = vtkProperty::New();
283   my3DExtProp->DeepCopy(myNormalVProp);
284   SMESH::GetColor( "SMESH", "volume_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 0, 170 ) );
285   anRGB[0] = 1 - anRGB[0];
286   anRGB[1] = 1 - anRGB[1];
287   anRGB[2] = 1 - anRGB[2];
288   my3DExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
289
290   my3DExtActor = SMESH_DeviceActor::New();
291   my3DExtActor->SetUserMatrix(aMatrix);
292   my3DExtActor->PickableOff();
293   my3DExtActor->SetProperty(my3DExtProp);
294   my3DExtActor->SetBackfaceProperty(my3DExtProp);
295   my3DExtActor->SetRepresentation(SMESH_DeviceActor::eSurface);
296   my3DExtActor->SetCoincident3DAllowed(true);
297   aFilter = my3DExtActor->GetExtractUnstructuredGrid();
298   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
299   aFilter->RegisterCellsWithType(VTK_TETRA);
300   aFilter->RegisterCellsWithType(VTK_VOXEL);
301   aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
302   aFilter->RegisterCellsWithType(VTK_WEDGE);
303   aFilter->RegisterCellsWithType(VTK_PYRAMID);
304   aFilter->RegisterCellsWithType(VTK_HEXAGONAL_PRISM);
305   aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
306   aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
307   aFilter->RegisterCellsWithType(VTK_TRIQUADRATIC_HEXAHEDRON);
308   aFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
309   aFilter->RegisterCellsWithType(VTK_QUADRATIC_PYRAMID);
310   aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
311   aFilter->RegisterCellsWithType(VTK_POLYHEDRON);
312
313   //Definition 1D device of the actor
314   //---------------------------------
315   myEdgeProp = vtkProperty::New();
316   myEdgeProp->SetAmbient(1.0);
317   myEdgeProp->SetDiffuse(0.0);
318   myEdgeProp->SetSpecular(0.0);
319   SMESH::GetColor( "SMESH", "wireframe_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
320   myEdgeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
321   myEdgeProp->SetLineWidth(aLineWidth);
322
323   my1DActor = SMESH_CellLabelActor::New();
324   my1DActor->SetStoreGemetryMapping(true);
325   my1DActor->SetUserMatrix(aMatrix);
326   my1DActor->PickableOff();
327   my1DActor->SetHighlited(true);
328   my1DActor->SetFontProperties( aFamilyEl, aSizeEl, aBoldEl, anItalicEl, aShadowEl, anRGBEl[0], anRGBEl[1], anRGBEl[2] );
329   my1DActor->SetProperty(myEdgeProp);
330   my1DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
331   aFilter = my1DActor->GetExtractUnstructuredGrid();
332   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
333   aFilter->RegisterCellsWithType(VTK_LINE);
334   aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
335
336   my1DProp = vtkProperty::New();
337   my1DProp->DeepCopy(myEdgeProp);
338   my1DProp->SetLineWidth(aLineWidth + aLineWidthInc);
339   my1DProp->SetPointSize(aElem0DSize);
340
341   my1DExtProp = vtkProperty::New();
342   my1DExtProp->DeepCopy(myEdgeProp);
343   anRGB[0] = 1 - anRGB[0];
344   anRGB[1] = 1 - anRGB[1];
345   anRGB[2] = 1 - anRGB[2];
346   my1DExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
347   my1DExtProp->SetLineWidth(aLineWidth + aLineWidthInc);
348   my1DExtProp->SetPointSize(aElem0DSize);
349
350   my1DExtActor = SMESH_DeviceActor::New();
351   my1DExtActor->SetUserMatrix(aMatrix);
352   my1DExtActor->PickableOff();
353   my1DExtActor->SetHighlited(true);
354   my1DExtActor->SetVisibility(false);
355   my1DExtActor->SetProperty(my1DExtProp);
356   my1DExtActor->SetRepresentation(SMESH_DeviceActor::eInsideframe);
357   aFilter = my1DExtActor->GetExtractUnstructuredGrid();
358   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
359   aFilter->RegisterCellsWithType(VTK_LINE);
360   aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
361
362
363   //Definition 0D device of the actor (0d elements)
364   //-----------------------------------------------
365   my0DProp = vtkProperty::New();
366   SMESH::GetColor( "SMESH", "elem0d_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 255, 0 ) );
367   my0DProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
368   my0DProp->SetPointSize(aElem0DSize);
369
370   my0DActor = SMESH_CellLabelActor::New();
371   my0DActor->SetUserMatrix(aMatrix);
372   my0DActor->SetStoreGemetryMapping(true);
373   my0DActor->PickableOff();
374   my0DActor->SetFontProperties( aFamilyEl, aSizeEl, aBoldEl, anItalicEl, aShadowEl, anRGBEl[0], anRGBEl[1], anRGBEl[2] );
375   my0DActor->SetVisibility(false);
376   my0DActor->SetProperty(my0DProp);
377   my0DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
378   aFilter = my0DActor->GetExtractUnstructuredGrid();
379   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
380   aFilter->RegisterCellsWithType(VTK_VERTEX);
381
382   //Definition 0D device of the actor (ball elements)
383   //-----------------------------------------------
384   myBallProp = vtkProperty::New();
385   SMESH::GetColor( "SMESH", "ball_elem_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 85, 255 ) );
386   myBallProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
387   myBallProp->SetPointSize(aBallElemSize);
388
389   myBallActor = SMESH_CellLabelActor::New();
390   myBallActor->SetUserMatrix(aMatrix);
391   myBallActor->SetStoreGemetryMapping(true);
392   myBallActor->PickableOff();
393   myBallActor->SetFontProperties( aFamilyEl, aSizeEl, aBoldEl, anItalicEl, aShadowEl, anRGBEl[0], anRGBEl[1], anRGBEl[2] );
394   myBallActor->SetVisibility(false);
395   myBallActor->SetProperty(myBallProp);
396   myBallActor->SetRepresentation(SMESH_DeviceActor::eSurface);
397   myBallActor->SetBallEnabled(true);
398   aFilter = myBallActor->GetExtractUnstructuredGrid();
399   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
400   aFilter->RegisterCellsWithType(VTK_POLY_VERTEX);
401
402   //my0DExtProp = vtkProperty::New();
403   //my0DExtProp->DeepCopy(my0DProp);
404   //anRGB[0] = 1 - anRGB[0];
405   //anRGB[1] = 1 - anRGB[1];
406   //anRGB[2] = 1 - anRGB[2];
407   //my0DExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
408   //my0DExtProp->SetPointSize(aElem0DSize);
409   //
410   //my0DExtActor = SMESH_DeviceActor::New();
411   //my0DExtActor->SetUserMatrix(aMatrix);
412   //my0DExtActor->SetStoreClippingMapping(true);
413   //my0DExtActor->PickableOff();
414   //my0DExtActor->SetHighlited(true);
415   //my0DExtActor->SetVisibility(false);
416   //my0DExtActor->SetProperty(my0DExtProp);
417   //my0DExtActor->SetRepresentation(SMESH_DeviceActor::eInsideframe);
418   //aFilter = my0DExtActor->GetExtractUnstructuredGrid();
419   ////aFilter->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
420   //aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
421   //aFilter->RegisterCellsWithType(VTK_VERTEX);
422
423
424   //Definition 0D device of the actor (nodes)
425   //-----------------------------------------
426   myNodeProp = vtkProperty::New();
427   SMESH::GetColor( "SMESH", "node_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 0, 0 ) );
428   myNodeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
429
430   myNodeActor = SMESH_NodeLabelActor::New();
431   myNodeActor->SetUserMatrix(aMatrix);
432   myNodeActor->SetStoreClippingMapping(true);
433   myNodeActor->PickableOff();
434   myNodeActor->SetVisibility(false);
435   myNodeActor->SetFontProperties( aFamilyNd, aSizeNd, aBoldNd, anItalicNd, aShadowNd, anRGBNd[0], anRGBNd[1], anRGBNd[2] );
436   myNodeActor->SetProperty(myNodeProp);
437   myNodeActor->SetRepresentation(SMESH_DeviceActor::ePoint);
438   aFilter = myNodeActor->GetExtractUnstructuredGrid();
439   aFilter->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
440
441   myNodeExtProp = vtkProperty::New();
442   myNodeExtProp->DeepCopy(myNodeProp);
443   anRGB[0] = 1 - anRGB[0];
444   anRGB[1] = 1 - anRGB[1];
445   anRGB[2] = 1 - anRGB[2];
446   myNodeExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
447
448   myNodeExtActor = SMESH_DeviceActor::New();
449   myNodeExtActor->SetUserMatrix(aMatrix);
450   myNodeExtActor->SetStoreClippingMapping(true);
451   myNodeExtActor->PickableOff();
452   myNodeExtActor->SetHighlited(true);
453   myNodeExtActor->SetVisibility(false);
454   myNodeExtActor->SetProperty(myNodeExtProp);
455   myNodeExtActor->SetRepresentation(SMESH_DeviceActor::ePoint);
456   aFilter = myNodeExtActor->GetExtractUnstructuredGrid();
457   aFilter->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
458   aFilter->RegisterCellsWithType(VTK_VERTEX);
459
460   //Definition of Pickable and Highlitable engines
461   //----------------------------------------------
462
463   myBaseActor->SetUserMatrix(aMatrix);
464   myBaseActor->SetStoreGemetryMapping(true);
465   myBaseActor->GetProperty()->SetOpacity(0.0);
466   myPickableActor = myBaseActor;
467
468   myHighlightProp = vtkProperty::New();
469   myHighlightProp->SetAmbient(1.0);
470   myHighlightProp->SetDiffuse(0.0);
471   myHighlightProp->SetSpecular(0.0);
472   SMESH::GetColor( "SMESH", "selection_object_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
473   myHighlightProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
474   myHighlightProp->SetPointSize(aElem0DSize); // ??
475   myHighlightProp->SetLineWidth(aLineWidth);
476   myHighlightProp->SetRepresentation(1);
477
478   myOutLineProp = vtkProperty::New();
479   myOutLineProp->SetAmbient(1.0);
480   myOutLineProp->SetDiffuse(0.0);
481   myOutLineProp->SetSpecular(0.0);
482   SMESH::GetColor( "SMESH", "outline_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 70, 0 ) );
483   myOutLineProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
484   myOutLineProp->SetLineWidth(aOutlineWidth);
485   myOutLineProp->SetRepresentation(1);
486
487   myPreselectProp = vtkProperty::New();
488   myPreselectProp->SetAmbient(1.0);
489   myPreselectProp->SetDiffuse(0.0);
490   myPreselectProp->SetSpecular(0.0);
491   SMESH::GetColor( "SMESH", "highlight_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 255, 255 ) );
492   myPreselectProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
493   myPreselectProp->SetPointSize(aElem0DSize); // ??
494   myPreselectProp->SetLineWidth(aLineWidth);
495   myPreselectProp->SetRepresentation(1);
496
497   myHighlitableActor = SMESH_DeviceActor::New();
498   myHighlitableActor->SetUserMatrix(aMatrix);
499   myHighlitableActor->PickableOff();
500   myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
501   myHighlitableActor->SetCoincident3DAllowed(true);
502
503   aMatrix->Delete();
504
505   myName = "";
506   myIO = NULL;
507
508   myControlMode = eNone;
509   myControlActor = my2DActor;
510
511   //Definition of myScalarBarActor
512   //------------------------------
513   myLookupTable = vtkLookupTable::New();
514   //Fix for Bug PAL5195 - SMESH764:
515   //Controls - Aspect Ratio: incorrect colors of the best and worst values
516   myLookupTable->SetHueRange(0.667,0.0);
517
518   myScalarBarActor = SMESH_ScalarBarActor::New();
519   myScalarBarActor->SetVisibility(false);
520   myScalarBarActor->SetLookupTable(myLookupTable);
521
522   //Fix for Bug 13314:
523   //Incorrect "Min value" in Scalar Bar in Mesh:
524   //  myScalarBarActor->SetLabelFormat("%.4g");
525   // changes was commented because of regression bug IPAL 19981
526
527   mgr = SUIT_Session::session()->resourceMgr();
528   if( !mgr )
529     return;
530
531   myEntityMode = eAllEntity;
532   myEntityModeCache = eAllEntity;
533
534   // Clipping planes
535   myImplicitBoolean = vtkImplicitBoolean::New();
536   myImplicitBoolean->SetOperationTypeToIntersection();
537
538   myPlaneCollection = vtkPlaneCollection::New();
539
540   //Quadratic 2D elements representation
541   //-----------------------------------------------------------------------------
542   int aQuadratic2DMode = mgr->integerValue( "SMESH", "quadratic_mode", 0);
543   if(aQuadratic2DMode == 0){
544     myHighlitableActor->SetQuadraticArcMode(false);
545     my2DActor->SetQuadraticArcMode(false);
546     my1DActor->SetQuadraticArcMode(false);
547   }
548   else if(aQuadratic2DMode == 1){
549     myHighlitableActor->SetQuadraticArcMode(true);
550     my2DActor->SetQuadraticArcMode(true);
551     my1DActor->SetQuadraticArcMode(true);
552   }
553
554   int aQuadraticAngle = mgr->integerValue( "SMESH", "max_angle", 2);
555   myHighlitableActor->SetQuadraticArcAngle(aQuadraticAngle);
556   my2DActor->SetQuadraticArcAngle(aQuadraticAngle);
557
558   // Set colors of the name actor
559   SMESH::GetColor( "SMESH", "default_grp_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
560   myNameActor->SetBackgroundColor(anRGB[0], anRGB[1], anRGB[2]);
561   SMESH::GetColor( "SMESH", "group_name_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
562   myNameActor->SetForegroundColor(anRGB[0], anRGB[1], anRGB[2]);
563
564 #ifndef DISABLE_PLOT2DVIEWER
565   my2dHistogram = 0;
566 #endif
567
568   SetBallSize(aBallElemSize);
569   SetBallScale(aBallElemScale);
570   Set0DSize(aElem0DSize);
571 }
572
573
574 SMESH_ActorDef::~SMESH_ActorDef()
575 {
576   if(MYDEBUG) MESSAGE("~SMESH_ActorDef - "<<this);
577
578   // Please keep the order same as one in the header file
579
580   myTimeStamp->Delete();
581
582   myScalarBarActor->Delete();
583   myLookupTable->Delete();
584
585   mySurfaceProp->Delete();
586   myBackSurfaceProp->Delete();
587   myNormalVProp->Delete();
588   myReversedVProp->Delete();
589   myEdgeProp->Delete();
590   myNodeProp->Delete();
591
592   myNodeActor->Delete();
593   myBaseActor->Delete();
594   //myPickableActor->Delete(); myPickableActor == myBaseActor
595
596   myHighlightProp->Delete();
597   myOutLineProp->Delete();
598   myPreselectProp->Delete();
599
600   myHighlitableActor->Delete();
601
602   my2DExtProp->Delete();
603   my3DExtProp->Delete();
604   my2DActor->Delete();
605   my2DExtActor->Delete();
606   my3DActor->Delete();
607   my3DExtActor->Delete();
608   // myControlActor->Delete(); myControlActor == my2DActor
609
610   myNodeExtProp->Delete();
611   myNodeExtActor->Delete();
612
613   my1DProp->Delete();
614   my1DActor->Delete();
615   my1DExtProp->Delete();
616   my1DExtActor->Delete();
617
618   my0DProp->Delete();
619   my0DActor->Delete();
620   myBallProp->Delete();
621   myBallActor->Delete();
622   //my0DExtProp->Delete();
623   //my0DExtActor->Delete();
624
625   myImplicitBoolean->Delete();
626   myPlaneCollection->Delete();
627
628 #ifndef DISABLE_PLOT2DVIEWER
629   if(my2dHistogram) {
630     SMESH::ProcessIn2DViewers(this,SMESH::RemoveFrom2dViewer);
631     delete my2dHistogram;
632   }
633 #endif
634 }
635
636 void SMESH_ActorDef::Delete()
637 {
638   // This is just to guarantee that the DeleteActorEvent (which was previously invoked
639   // from the actor's destructor) will be thrown before removing the actor's observers,
640   // that is done inside the Superclass::Delete() method but before the destructor itself
641   // (see the issue 0021562: EDF SMESH: clipping and delete mesh clipped leads to crash).
642   // The event is caught by SMESHGUI::ProcessEvents() static method.
643   this->InvokeEvent( SMESH::DeleteActorEvent, NULL );
644
645   Superclass::Delete();
646 }
647
648 void SMESH_ActorDef::SetPointsLabeled( bool theIsPointsLabeled )
649 {
650   if(myNodeActor) {
651     myNodeActor->SetPointsLabeled(theIsPointsLabeled);
652     SetRepresentation(GetRepresentation());
653     myTimeStamp->Modified();
654   }
655 }
656
657 void SMESH_ActorDef::SetPointsFontProperties( SMESH::LabelFont theFamily, int theSize,
658                                               bool theBold, bool theItalic, bool theShadow,
659                                               double r, double g, double b )
660 {    
661   if(myNodeActor) {
662     myNodeActor->SetFontProperties( theFamily, theSize, theBold, theItalic, theShadow, r, g, b );
663     SetRepresentation( GetRepresentation() );
664     myTimeStamp->Modified();
665   }
666 }
667
668 void SMESH_ActorDef::SetCellsFontProperties( SMESH::LabelFont theFamily, int theSize,
669                                              bool theBold, bool theItalic, bool theShadow,
670                                              double r, double g, double b )
671 {    
672   if(my3DActor) {
673     my3DActor->SetFontProperties( theFamily, theSize, theBold, theItalic, theShadow, r, g, b );
674   }
675   if(my2DActor) {
676     my2DActor->SetFontProperties( theFamily, theSize, theBold, theItalic, theShadow, r, g, b );
677     SetRepresentation( GetRepresentation() );
678     myTimeStamp->Modified();
679   }
680   if(my1DActor) {
681     my1DActor->SetFontProperties( theFamily, theSize, theBold, theItalic, theShadow, r, g, b );
682     SetRepresentation( GetRepresentation() );
683     myTimeStamp->Modified();
684   }
685   if(my0DActor) {
686     my0DActor->SetFontProperties( theFamily, theSize, theBold, theItalic, theShadow, r, g, b );
687     SetRepresentation( GetRepresentation() );
688     myTimeStamp->Modified();
689   }
690   if(myBallActor) {
691     myBallActor->SetFontProperties( theFamily, theSize, theBold, theItalic, theShadow, r, g, b );
692     SetRepresentation( GetRepresentation() );
693     myTimeStamp->Modified();
694   }
695 }
696
697 bool SMESH_ActorDef::GetPointsLabeled()
698 {
699   return myNodeActor && myNodeActor->GetPointsLabeled();
700 }
701
702 void SMESH_ActorDef::SetCellsLabeled(bool theIsCellsLabeled)
703 {
704   if(my3DActor)
705     my3DActor->SetCellsLabeled(theIsCellsLabeled);
706
707   if(my2DActor)
708     my2DActor->SetCellsLabeled(theIsCellsLabeled);
709
710   if(my1DActor)
711     my1DActor->SetCellsLabeled(theIsCellsLabeled);
712
713   if(my0DActor)
714     my0DActor->SetCellsLabeled(theIsCellsLabeled);
715
716   if(myBallActor)
717     myBallActor->SetCellsLabeled(theIsCellsLabeled);
718
719   myTimeStamp->Modified();
720 }
721
722
723 bool SMESH_ActorDef::GetCellsLabeled()
724 {
725   bool result = false;
726   if(my3DActor)
727     result = result || my3DActor->GetCellsLabeled();
728
729   if(my2DActor)
730     result = result || my2DActor->GetCellsLabeled();
731
732   if(my1DActor)
733     result = result || my1DActor->GetCellsLabeled();
734
735   if(my0DActor)
736     result = result || my0DActor->GetCellsLabeled();
737
738   if(myBallActor)
739     result = result || myBallActor->GetCellsLabeled();
740
741   return result;
742 }
743
744
745 void SMESH_ActorDef::SetFacesOriented(bool theIsFacesOriented)
746 {
747   myIsFacesOriented = theIsFacesOriented;
748
749   my2DActor->SetFacesOriented(theIsFacesOriented);
750   my3DActor->SetFacesOriented(theIsFacesOriented);
751
752   myTimeStamp->Modified();
753 }
754
755 bool SMESH_ActorDef::GetFacesOriented()
756 {
757   return myIsFacesOriented;
758 }
759
760 void SMESH_ActorDef::SetFacesOrientationColor(double r,double g,double b)
761 {
762   my2DActor->SetFacesOrientationColor( r, g, b );
763   my3DActor->SetFacesOrientationColor( r, g, b );
764 }
765
766 void SMESH_ActorDef::GetFacesOrientationColor(double& r,double& g,double& b)
767 {
768   my3DActor->GetFacesOrientationColor( r, g, b );
769 }
770
771 void SMESH_ActorDef::SetFacesOrientationScale(double theScale)
772 {
773   my2DActor->SetFacesOrientationScale( theScale );
774   my3DActor->SetFacesOrientationScale( theScale );
775 }
776
777 double SMESH_ActorDef::GetFacesOrientationScale()
778 {
779   return my3DActor->GetFacesOrientationScale();
780 }
781
782 void SMESH_ActorDef::SetFacesOrientation3DVectors(bool theState)
783 {
784   my2DActor->SetFacesOrientation3DVectors( theState );
785   my3DActor->SetFacesOrientation3DVectors( theState );
786 }
787
788 bool SMESH_ActorDef::GetFacesOrientation3DVectors()
789 {
790   return my3DActor->GetFacesOrientation3DVectors();
791 }
792
793
794 void SMESH_ActorDef::SetControlMode(eControl theMode)
795 {
796   SetControlMode(theMode,true);
797 }
798
799
800 void SMESH_ActorDef::SetControlMode( eControl theMode, bool theCheckEntityMode )
801 {
802   vtkLookupTable* lookupTable = static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
803   bool isLogarithmic = lookupTable->GetScale() == VTK_SCALE_LOG10;
804   lookupTable->SetScale(VTK_SCALE_LINEAR);
805
806   SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
807   if( !mgr )
808     return;
809
810   myControlMode = eNone;
811   theCheckEntityMode &= mgr->booleanValue( "SMESH", "display_entity", false );
812
813   my0DActor->GetMapper()->SetScalarVisibility(false);
814   my1DActor->GetMapper()->SetScalarVisibility(false);
815   my2DActor->GetMapper()->SetScalarVisibility(false);
816   my3DActor->GetMapper()->SetScalarVisibility(false);
817   myBallActor->GetMapper()->SetScalarVisibility(false);
818   myScalarBarActor->SetVisibility(false);
819
820   bool anIsScalarVisible = theMode > eNone;
821
822   if(anIsScalarVisible) {
823     switch(theMode) {
824     case eLength:
825     {
826       SMESH::Controls::Length* aControl = new SMESH::Controls::Length();
827       aControl->SetPrecision( myControlsPrecision );
828       myFunctor.reset( aControl );
829       myControlActor = my1DActor;
830       break;
831     }
832     case eLength2D:
833     {
834       myFunctor.reset(new SMESH::Controls::Length2D());
835       myControlActor = my2DActor;
836       break;
837     }
838     case eFreeBorders:
839       myFunctor.reset(new SMESH::Controls::FreeBorders());
840       myControlActor = my1DActor;
841       break;
842     case eFreeEdges:
843       myFunctor.reset(new SMESH::Controls::FreeEdges());
844       myControlActor = my2DActor;
845       break;
846     case eFreeNodes:
847       myFunctor.reset(new SMESH::Controls::FreeNodes());
848       myControlActor = myNodeActor;
849       break;
850     case eFreeFaces:
851       myFunctor.reset(new SMESH::Controls::FreeFaces());
852       myControlActor = my2DActor;
853       break;
854     case eCoincidentNodes:
855       {
856         SMESH::Controls::CoincidentNodes* cn = new SMESH::Controls::CoincidentNodes();
857         double tol = mgr->doubleValue( "SMESH", "equal_nodes_tolerance", 1e-7 );
858         cn->SetTolerance( tol );
859         myFunctor.reset(cn);
860         myControlActor = myNodeActor;
861         break;
862       }
863     case eCoincidentElems1D:
864       myFunctor.reset(new SMESH::Controls::CoincidentElements1D());
865       myControlActor = my1DActor;
866       break;
867     case eCoincidentElems2D:
868       myFunctor.reset(new SMESH::Controls::CoincidentElements2D());
869       myControlActor = my2DActor;
870       break;
871     case eCoincidentElems3D:
872       myFunctor.reset(new SMESH::Controls::CoincidentElements3D());
873       myControlActor = my3DActor;
874       break;
875     case eBareBorderFace:
876       myFunctor.reset(new SMESH::Controls::BareBorderFace());
877       myControlActor = my2DActor;
878       break;
879     case eOverConstrainedFace:
880       myFunctor.reset(new SMESH::Controls::OverConstrainedFace());
881       myControlActor = my2DActor;
882       break;
883     case eMultiConnection:
884       myFunctor.reset(new SMESH::Controls::MultiConnection());
885       myControlActor = my1DActor;
886       break;
887     case eMultiConnection2D:
888       myFunctor.reset(new SMESH::Controls::MultiConnection2D());
889       myControlActor = my2DActor;
890       break;
891     case eArea:
892     {
893       SMESH::Controls::Area* aControl = new SMESH::Controls::Area();
894       aControl->SetPrecision( myControlsPrecision );
895       myFunctor.reset( aControl );
896       myControlActor = my2DActor;
897       break;
898     }
899     case eTaper:
900     {
901       SMESH::Controls::Taper* aControl = new SMESH::Controls::Taper();
902       aControl->SetPrecision( myControlsPrecision );
903       myFunctor.reset( aControl );
904       myControlActor = my2DActor;
905       break;
906     }
907     case eAspectRatio:
908     {
909       SMESH::Controls::AspectRatio* aControl = new SMESH::Controls::AspectRatio();
910       aControl->SetPrecision( myControlsPrecision );
911       myFunctor.reset( aControl );
912       myControlActor = my2DActor;
913       break;
914     }
915     case eAspectRatio3D:
916     {
917       SMESH::Controls::AspectRatio3D* aControl = new SMESH::Controls::AspectRatio3D();
918       aControl->SetPrecision( myControlsPrecision );
919       myFunctor.reset( aControl );
920       myControlActor = my3DActor;
921       break;
922     }
923     case eVolume3D:
924     {
925       SMESH::Controls::Volume* aControl = new SMESH::Controls::Volume();
926       aControl->SetPrecision( myControlsPrecision );
927       myFunctor.reset( aControl );
928       myControlActor = my3DActor;
929       break;
930     }
931     case eMaxElementLength2D:
932     {
933       SMESH::Controls::MaxElementLength2D* aControl = new SMESH::Controls::MaxElementLength2D();
934       aControl->SetPrecision( myControlsPrecision );
935       myFunctor.reset( aControl );
936       myControlActor = my2DActor;
937       break;
938     }
939     case eMaxElementLength3D:
940     {
941       SMESH::Controls::MaxElementLength3D* aControl = new SMESH::Controls::MaxElementLength3D();
942       aControl->SetPrecision( myControlsPrecision );
943       myFunctor.reset( aControl );
944       myControlActor = my3DActor;
945       break;
946     }
947     case eBareBorderVolume:
948     {
949       myFunctor.reset(new SMESH::Controls::BareBorderVolume());
950       myControlActor = my3DActor;
951       break;
952     }
953     case eOverConstrainedVolume:
954     {
955       myFunctor.reset(new SMESH::Controls::OverConstrainedVolume());
956       myControlActor = my3DActor;
957       break;
958     }
959     case eMinimumAngle:
960     {
961       SMESH::Controls::MinimumAngle* aControl = new SMESH::Controls::MinimumAngle();
962       aControl->SetPrecision( myControlsPrecision );
963       myFunctor.reset( aControl );
964       myControlActor = my2DActor;
965       break;
966     }
967     case eWarping:
968     {
969       SMESH::Controls::Warping* aControl = new SMESH::Controls::Warping();
970       aControl->SetPrecision( myControlsPrecision );
971       myFunctor.reset( aControl );
972       myControlActor = my2DActor;
973       break;
974     }
975     case eSkew:
976     {
977       SMESH::Controls::Skew* aControl = new SMESH::Controls::Skew();
978       aControl->SetPrecision( myControlsPrecision );
979       myFunctor.reset( aControl );
980       myControlActor = my2DActor;
981       break;
982     }
983     case eNodeConnectivityNb:
984     {
985       myFunctor.reset( new SMESH::Controls::NodeConnectivityNumber() );
986       myControlActor = myNodeActor;
987       break;
988     }
989     default:
990       return;
991     }
992
993     vtkUnstructuredGrid* aGrid = myControlActor->GetUnstructuredGrid();
994     vtkIdType aNbCells = aGrid->GetNumberOfCells();
995     bool aShowOnlyScalarBarTitle = false;
996     if(aNbCells) {
997       myControlMode = theMode;
998       switch(myControlMode){
999       case eFreeNodes:
1000       case eCoincidentNodes:
1001         myNodeExtActor->SetExtControlMode(myFunctor);
1002         aShowOnlyScalarBarTitle = true;
1003         break;
1004       case eFreeEdges:
1005       case eFreeBorders:
1006       case eCoincidentElems1D:
1007         my1DExtActor->SetExtControlMode(myFunctor);
1008         aShowOnlyScalarBarTitle = true;
1009         break;
1010       case eFreeFaces:
1011       case eBareBorderFace:
1012       case eOverConstrainedFace:
1013       case eCoincidentElems2D:
1014         my2DExtActor->SetExtControlMode(myFunctor);
1015         aShowOnlyScalarBarTitle = true;
1016         break;
1017       case eBareBorderVolume:
1018       case eOverConstrainedVolume:
1019       case eCoincidentElems3D:
1020         my3DExtActor->SetExtControlMode(myFunctor);
1021         aShowOnlyScalarBarTitle = true;
1022         break;
1023       case eLength2D:
1024       case eMultiConnection2D:
1025         my1DExtActor->SetExtControlMode(myFunctor,myScalarBarActor,myLookupTable);
1026         UpdateDistribution();
1027         break;
1028       default:
1029         myControlActor->SetControlMode(myFunctor,myScalarBarActor,myLookupTable);
1030         UpdateDistribution();
1031       }
1032       myScalarBarActor->SetTitleOnlyVisibility(aShowOnlyScalarBarTitle);
1033     }
1034
1035     if(theCheckEntityMode) {
1036       // if(myControlActor == myNodeActor) {
1037       //   if ( myControlMode == eNodeConnectivityNb ) {
1038       //     if (!myIsEntityModeCache){
1039       //       myEntityModeCache = GetEntityMode();
1040       //       myIsEntityModeCache=true;
1041       //     }
1042       //     SetEntityMode(0);
1043       //   }
1044       // }
1045       if(myControlActor == my1DActor) {
1046         if (!myIsEntityModeCache){
1047           myEntityModeCache = GetEntityMode();
1048           myIsEntityModeCache=true;
1049         }
1050         SetEntityMode(eEdges);
1051       }
1052       else if(myControlActor == my2DActor) {
1053         switch(myControlMode) {
1054         case eLength2D:
1055         case eFreeEdges:
1056         case eFreeFaces:
1057         case eMultiConnection2D:
1058           if (!myIsEntityModeCache){
1059             myEntityModeCache = GetEntityMode();
1060             myIsEntityModeCache=true;
1061           }
1062           SetEntityMode(eFaces);
1063           break;
1064         default:
1065           if (!myIsEntityModeCache){
1066             myEntityModeCache = GetEntityMode();
1067             myIsEntityModeCache=true;
1068           }
1069           SetEntityMode(eFaces);
1070         }
1071       }else if(myControlActor == my3DActor) {
1072         if (!myIsEntityModeCache){
1073             myEntityModeCache = GetEntityMode();
1074             myIsEntityModeCache=true;
1075         }
1076         SetEntityMode(eVolumes);
1077     }
1078     }
1079     QString aTitle = QString(myScalarBarActor->GetTitle());
1080     aTitle.replace(QRegExp("(:\\s).*"),"\\1"+ QString::number(GetNumberControlEntities()));
1081     myScalarBarActor->SetTitle(aTitle.toLatin1().constData());
1082
1083   }
1084   else {
1085     if(theCheckEntityMode){
1086       myEntityMode = myEntityModeCache;
1087       myIsEntityModeCache = false;
1088     }
1089     myFunctor.reset();
1090   }
1091
1092   SetRepresentation(GetRepresentation());
1093
1094   myTimeStamp->Modified();
1095   Modified();
1096
1097   lookupTable = static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
1098   double * range = lookupTable->GetRange();
1099
1100   if (isLogarithmic && range[0] > 1e-07 && range[1] > 1e-07)
1101     lookupTable->SetScale(VTK_SCALE_LOG10);
1102
1103   Update();
1104 }
1105
1106 int SMESH_ActorDef::GetNumberControlEntities()
1107 {
1108   SMESH_DeviceActor* anAct = NULL;
1109   switch(myControlMode){
1110     case eFreeNodes:
1111     case eCoincidentNodes:
1112       anAct = myNodeExtActor;
1113       break;
1114     case eFreeEdges:
1115     case eFreeBorders:
1116     case eCoincidentElems1D:
1117       anAct = my1DExtActor;
1118       break;
1119     case eFreeFaces:
1120     case eBareBorderFace:
1121     case eOverConstrainedFace:
1122     case eCoincidentElems2D:
1123       anAct = my2DExtActor;
1124       break;
1125     case eBareBorderVolume:
1126     case eOverConstrainedVolume:
1127     case eCoincidentElems3D:
1128       anAct = my3DExtActor;
1129       break;
1130     default:;
1131   }
1132   return (anAct) ? anAct->GetUnstructuredGrid()->GetNumberOfCells() : -1;
1133 }
1134
1135 void SMESH_ActorDef::AddToRender(vtkRenderer* theRenderer)
1136 {
1137   theRenderer->AddActor(myBaseActor);
1138   theRenderer->AddActor(myNodeExtActor);
1139   theRenderer->AddActor(my1DExtActor);
1140
1141   my3DActor   ->AddToRender(theRenderer);
1142   my3DExtActor->AddToRender(theRenderer);
1143   my2DActor   ->AddToRender(theRenderer);
1144   my2DExtActor->AddToRender(theRenderer);
1145   myNodeActor ->AddToRender(theRenderer);
1146   my1DActor   ->AddToRender(theRenderer);
1147   my0DActor   ->AddToRender(theRenderer);
1148   myBallActor ->AddToRender(theRenderer);
1149
1150   theRenderer->AddActor(myHighlitableActor);
1151
1152   theRenderer->AddActor2D(myScalarBarActor);
1153
1154   // the superclass' method should be called at the end
1155   // (in particular, for correct work of selection)
1156   SALOME_Actor::AddToRender(theRenderer);
1157 }
1158
1159 void SMESH_ActorDef::RemoveFromRender(vtkRenderer* theRenderer)
1160 {
1161   SALOME_Actor::RemoveFromRender(theRenderer);
1162
1163   theRenderer->RemoveActor(myBaseActor);
1164
1165   theRenderer->RemoveActor(myNodeExtActor);
1166
1167   theRenderer->RemoveActor(myHighlitableActor);
1168
1169   //theRenderer->RemoveActor(my0DExtActor);
1170
1171   theRenderer->RemoveActor(my1DExtActor);
1172
1173   my2DActor->RemoveFromRender(theRenderer);
1174   my2DExtActor->RemoveFromRender(theRenderer);
1175   my3DActor->RemoveFromRender(theRenderer);
1176   my3DExtActor->RemoveFromRender(theRenderer);
1177   myNodeActor->RemoveFromRender(theRenderer);
1178   my0DActor->RemoveFromRender(theRenderer);
1179   myBallActor->RemoveFromRender(theRenderer);
1180   my1DActor->RemoveFromRender(theRenderer);
1181
1182   theRenderer->RemoveActor(myScalarBarActor);
1183 }
1184
1185
1186 bool SMESH_ActorDef::Init(TVisualObjPtr theVisualObj,
1187                           const char*   theEntry,
1188                           const char*   theName,
1189                           int           theIsClear)
1190 {
1191   Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry,"SMESH",theName);
1192   setIO(anIO);
1193   setName(theName);
1194
1195   myVisualObj = theVisualObj;
1196   myVisualObj->Update(theIsClear);
1197
1198   SMESH_SVTKActor::SafeDownCast(myHighlightActor)->SetVisualObject(myVisualObj);
1199   SMESH_SVTKActor::SafeDownCast(myPreHighlightActor)->SetVisualObject(myVisualObj);
1200
1201   myNodeActor->Init(myVisualObj,myImplicitBoolean);
1202   myBaseActor->Init(myVisualObj,myImplicitBoolean);
1203
1204   myHighlitableActor->Init(myVisualObj,myImplicitBoolean);
1205
1206   myNodeExtActor->Init(myVisualObj,myImplicitBoolean);
1207
1208   my0DActor->Init(myVisualObj,myImplicitBoolean);
1209   myBallActor->Init(myVisualObj,myImplicitBoolean);
1210   //my0DExtActor->Init(myVisualObj,myImplicitBoolean);
1211
1212   my1DActor->Init(myVisualObj,myImplicitBoolean);
1213   my1DExtActor->Init(myVisualObj,myImplicitBoolean);
1214
1215   my2DActor->Init(myVisualObj,myImplicitBoolean);
1216   my2DExtActor->Init(myVisualObj,myImplicitBoolean);
1217   my3DActor->Init(myVisualObj,myImplicitBoolean);
1218   my3DExtActor->Init(myVisualObj,myImplicitBoolean);
1219
1220   my0DActor->GetMapper()->SetLookupTable(myLookupTable);
1221   myBallActor->GetMapper()->SetLookupTable(myLookupTable);
1222   //my0DExtActor->GetMapper()->SetLookupTable(myLookupTable);
1223
1224   my1DActor->GetMapper()->SetLookupTable(myLookupTable);
1225   my1DExtActor->GetMapper()->SetLookupTable(myLookupTable);
1226
1227   my2DActor->GetMapper()->SetLookupTable(myLookupTable);
1228   my2DExtActor->GetMapper()->SetLookupTable(myLookupTable);
1229   my3DActor->GetMapper()->SetLookupTable(myLookupTable);
1230   my3DExtActor->GetMapper()->SetLookupTable(myLookupTable);
1231     
1232   double aFactor, aUnits;
1233   my2DActor->GetPolygonOffsetParameters(aFactor,aUnits);
1234   my2DActor->SetPolygonOffsetParameters(aFactor,aUnits*0.75);
1235   my2DExtActor->SetPolygonOffsetParameters(aFactor,aUnits*0.5);
1236   my3DActor->SetPolygonOffsetParameters(2*aFactor,aUnits);
1237
1238   SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
1239   if( !mgr )
1240     return false;
1241
1242   //SetIsShrunkable(theGrid->GetNumberOfCells() > 10);
1243   SetIsShrunkable(true);
1244
1245   SetShrinkFactor( SMESH::GetFloat( "SMESH:shrink_coeff", 75 ) / 100. );
1246
1247   int aMode = mgr->integerValue( "SMESH", "display_mode" );
1248   SetRepresentation(-1);
1249
1250   if(aMode == 0){
1251     SetRepresentation(eEdge);
1252   }else if(aMode == 1){
1253     SetRepresentation(eSurface);
1254   }else if(aMode == 2){
1255     SetRepresentation(ePoint);
1256   }
1257
1258   if(aMode == 3){
1259     SetShrink();
1260   }
1261
1262   if( dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
1263     SetIsDisplayNameActor( true );
1264
1265   int aMarkerType = mgr->integerValue( "SMESH", "type_of_marker", 1 ); // dot
1266   int aMarkerScale = mgr->integerValue( "SMESH", "marker_scale", 9 );  // 5 pixels
1267   SetMarkerStd( (VTK::MarkerType)aMarkerType, (VTK::MarkerScale)aMarkerScale );
1268
1269   myTimeStamp->Modified();
1270   Modified();
1271   return true;
1272 }
1273
1274
1275 double* SMESH_ActorDef::GetBounds()
1276 {
1277   return myNodeActor->GetBounds();
1278 }
1279
1280
1281 vtkDataSet* SMESH_ActorDef::GetInput()
1282 {
1283   return GetUnstructuredGrid();
1284 }
1285
1286
1287 void SMESH_ActorDef::SetTransform(VTKViewer_Transform* theTransform)
1288 {
1289   Superclass::SetTransform(theTransform);
1290
1291   myNodeActor->SetTransform(theTransform);
1292   myBaseActor->SetTransform(theTransform);
1293
1294   myHighlitableActor->SetTransform(theTransform);
1295
1296   myNodeExtActor->SetTransform(theTransform);
1297
1298   my0DActor->SetTransform(theTransform);
1299   myBallActor->SetTransform(theTransform);
1300   //my0DExtActor->SetTransform(theTransform);
1301
1302   my1DActor->SetTransform(theTransform);
1303   my1DExtActor->SetTransform(theTransform);
1304
1305   my2DActor->SetTransform(theTransform);
1306   my2DExtActor->SetTransform(theTransform);
1307   my3DActor->SetTransform(theTransform);
1308   my3DExtActor->SetTransform(theTransform);
1309
1310   Modified();
1311 }
1312
1313
1314 void SMESH_ActorDef::SetMapper(vtkMapper* theMapper)
1315 {
1316   vtkLODActor::SetMapper(theMapper);
1317 }
1318
1319
1320 void SMESH_ActorDef::ShallowCopy(vtkProp *prop)
1321 {
1322   SALOME_Actor::ShallowCopy(prop);
1323 }
1324
1325
1326 vtkMapper* SMESH_ActorDef::GetMapper()
1327 {
1328   return myPickableActor->GetMapper();
1329 }
1330
1331
1332 vtkUnstructuredGrid* SMESH_ActorDef::GetUnstructuredGrid()
1333 {
1334   return myVisualObj->GetUnstructuredGrid();
1335 }
1336
1337
1338 bool SMESH_ActorDef::IsInfinitive()
1339 {
1340   vtkDataSet *aDataSet = myPickableActor->GetUnstructuredGrid();
1341   myIsInfinite = aDataSet->GetNumberOfCells() == 0 ||
1342     ( aDataSet->GetNumberOfCells() == 1 &&
1343     aDataSet->GetCell(0)->GetCellType() == VTK_VERTEX );
1344   return SALOME_Actor::IsInfinitive();
1345 }
1346
1347
1348 void SMESH_ActorDef::SetIsShrunkable(bool theShrunkable)
1349 {
1350   if ( myIsShrinkable == theShrunkable )
1351     return;
1352   myIsShrinkable = theShrunkable;
1353   Modified();
1354 }
1355
1356 double SMESH_ActorDef::GetShrinkFactor()
1357 {
1358   return myBaseActor->GetShrinkFactor();
1359 }
1360
1361 void SMESH_ActorDef::SetShrinkFactor(double theValue)
1362 {
1363   myBaseActor->SetShrinkFactor(theValue);
1364
1365   my1DActor->SetShrinkFactor(theValue);
1366   my1DExtActor->SetShrinkFactor(theValue);
1367
1368   my2DActor->SetShrinkFactor(theValue);
1369   my2DExtActor->SetShrinkFactor(theValue);
1370   my3DActor->SetShrinkFactor(theValue);
1371   my3DExtActor->SetShrinkFactor(theValue);
1372   my3DExtActor->SetShrinkFactor(theValue);
1373   myHighlitableActor->SetShrinkFactor(theValue);
1374
1375   Modified();
1376 }
1377
1378 void SMESH_ActorDef::SetShrink()
1379 {
1380   if(!myIsShrinkable) return;
1381
1382   myBaseActor->SetShrink();
1383
1384   my1DActor->SetShrink();
1385   my1DExtActor->SetShrink();
1386
1387   my2DActor->SetShrink();
1388   my2DExtActor->SetShrink();
1389   my3DActor->SetShrink();
1390   my3DExtActor->SetShrink();
1391   myHighlitableActor->SetShrink();
1392
1393   myIsShrunk = true;
1394   Modified();
1395 }
1396
1397 void SMESH_ActorDef::UnShrink()
1398 {
1399   if(!myIsShrunk) return;
1400
1401   myBaseActor->UnShrink();
1402
1403   my1DActor->UnShrink();
1404   my1DExtActor->UnShrink();
1405
1406   my2DActor->UnShrink();
1407   my2DExtActor->UnShrink();
1408   my3DActor->UnShrink();
1409   my3DExtActor->UnShrink();
1410   myHighlitableActor->UnShrink();
1411
1412   myIsShrunk = false;
1413   Modified();
1414 }
1415
1416
1417 int SMESH_ActorDef::GetNodeObjId(int theVtkID)
1418 {
1419   return myPickableActor->GetNodeObjId(theVtkID);
1420 }
1421
1422 double* SMESH_ActorDef::GetNodeCoord(int theObjID)
1423 {
1424   return myPickableActor->GetNodeCoord(theObjID);
1425 }
1426
1427
1428 int SMESH_ActorDef::GetElemObjId(int theVtkID)
1429 {
1430   return myPickableActor->GetElemObjId(theVtkID);
1431 }
1432
1433 vtkCell* SMESH_ActorDef::GetElemCell(int theObjID)
1434 {
1435   return myPickableActor->GetElemCell(theObjID);
1436 }
1437
1438
1439 void SMESH_ActorDef::SetVisibility(int theMode)
1440 {
1441   SetVisibility(theMode,true);
1442 }
1443
1444
1445 void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation)
1446 {
1447   SALOME_Actor::SetVisibility(theMode);
1448
1449   myNodeActor->VisibilityOff();
1450   myBaseActor->VisibilityOff();
1451
1452   myNodeExtActor->VisibilityOff();
1453
1454   my0DActor->VisibilityOff();
1455   myBallActor->VisibilityOff();
1456   //my0DExtActor->VisibilityOff();
1457
1458   my1DActor->VisibilityOff();
1459   my1DExtActor->VisibilityOff();
1460
1461   my2DActor->VisibilityOff();
1462   my2DExtActor->VisibilityOff();
1463   my3DActor->VisibilityOff();
1464   my3DExtActor->VisibilityOff();
1465
1466   myScalarBarActor->VisibilityOff();
1467
1468   if(GetVisibility()){
1469     if(theIsUpdateRepersentation)
1470       SetRepresentation(GetRepresentation());
1471
1472     if(myControlMode != eNone) {
1473       switch(myControlMode) {
1474       case eFreeNodes:
1475       case eCoincidentNodes:
1476         myNodeExtActor->VisibilityOn();
1477         break;
1478       case eFreeEdges:
1479       case eFreeBorders:
1480       case eCoincidentElems1D:
1481         my1DExtActor->VisibilityOn();
1482         break;
1483       case eFreeFaces:
1484       case eBareBorderFace:
1485       case eOverConstrainedFace:
1486       case eCoincidentElems2D:
1487         my2DExtActor->VisibilityOn();
1488         break;
1489       case eBareBorderVolume:
1490       case eOverConstrainedVolume:
1491       case eCoincidentElems3D:
1492         my3DExtActor->VisibilityOn();
1493         break;
1494       case eLength2D:
1495       case eMultiConnection2D:
1496         my1DExtActor->VisibilityOn();
1497         break;
1498       default:;
1499       }
1500       if(myControlActor->GetUnstructuredGrid()->GetNumberOfCells())
1501         myScalarBarActor->VisibilityOn();
1502     }
1503
1504     if(myRepresentation != ePoint)
1505       myPickableActor->VisibilityOn();
1506     else {
1507       myNodeActor->VisibilityOn();
1508     }
1509
1510     if(myEntityMode & e0DElements && GetRepresentation() != ePoint ){
1511       my0DActor->VisibilityOn();
1512     }
1513     if(myEntityMode & eBallElem && GetRepresentation() != ePoint ){
1514       myBallActor->VisibilityOn();
1515     }
1516
1517     if(myEntityMode & eEdges && GetRepresentation() != ePoint){
1518       my1DActor->VisibilityOn();
1519     }
1520
1521     if(myEntityMode & eFaces && GetRepresentation() != ePoint){
1522       my2DActor->VisibilityOn();
1523     }
1524
1525     if(myEntityMode & eVolumes && GetRepresentation() != ePoint){
1526       my3DActor->VisibilityOn();
1527     }
1528
1529     if(myNodeActor->GetPointsLabeled()){
1530       myNodeActor->VisibilityOn();
1531     }
1532
1533     if(my0DActor)
1534       my0DActor->UpdateLabels();
1535
1536     if(myBallActor)
1537       myBallActor->UpdateLabels();
1538
1539     if(my1DActor)
1540       my1DActor->UpdateLabels();
1541
1542     if(my2DActor)
1543       my2DActor->UpdateLabels();
1544
1545     if(my3DActor)
1546       my3DActor->UpdateLabels();
1547   }
1548 #ifndef DISABLE_PLOT2DVIEWER
1549   else
1550     SMESH::ProcessIn2DViewers(this,SMESH::RemoveFrom2dViewer);
1551 #endif
1552   UpdateHighlight();
1553   Modified();
1554 }
1555
1556
1557 void SMESH_ActorDef::SetEntityMode(unsigned int theMode)
1558 {
1559   myEntityState = eAllEntity;
1560
1561   if(!myVisualObj->GetNbEntities(SMDSAbs_0DElement)) {
1562     myEntityState &= ~e0DElements;
1563     theMode &= ~e0DElements;
1564   }
1565
1566   if(!myVisualObj->GetNbEntities(SMDSAbs_Ball)) {
1567     myEntityState &= ~eBallElem;
1568     theMode &= ~eBallElem;
1569   }
1570
1571   if(!myVisualObj->GetNbEntities(SMDSAbs_Edge)) {
1572     myEntityState &= ~eEdges;
1573     theMode &= ~eEdges;
1574   }
1575
1576   if(!myVisualObj->GetNbEntities(SMDSAbs_Face)) {
1577     myEntityState &= ~eFaces;
1578     theMode &= ~eFaces;
1579   }
1580
1581   if(!myVisualObj->GetNbEntities(SMDSAbs_Volume)) {
1582     myEntityState &= ~eVolumes;
1583     theMode &= ~eVolumes;
1584   }
1585
1586   if (!theMode) {
1587     if(myVisualObj->GetNbEntities(SMDSAbs_0DElement))
1588       theMode |= e0DElements;
1589
1590     if(myVisualObj->GetNbEntities(SMDSAbs_Ball))
1591       theMode |= eBallElem;
1592
1593     if(myVisualObj->GetNbEntities(SMDSAbs_Edge))
1594       theMode |= eEdges;
1595
1596     if(myVisualObj->GetNbEntities(SMDSAbs_Face))
1597       theMode |= eFaces;
1598
1599     if(myVisualObj->GetNbEntities(SMDSAbs_Volume))
1600       theMode |= eVolumes;
1601   }
1602
1603   myBaseActor->myGeomFilter->SetInside(myEntityMode != myEntityState);
1604
1605   myEntityMode = theMode;
1606   VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
1607   aFilter = myBaseActor->GetExtractUnstructuredGrid();
1608   aFilter->ClearRegisteredCellsWithType();
1609   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
1610
1611   VTKViewer_ExtractUnstructuredGrid* aHightFilter = myHighlitableActor->GetExtractUnstructuredGrid();
1612   aHightFilter->ClearRegisteredCellsWithType();
1613   aHightFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
1614
1615   if (myEntityMode & e0DElements) {
1616     if (MYDEBUG) MESSAGE("0D ELEMENTS");
1617     aFilter->RegisterCellsWithType(VTK_VERTEX);
1618     aHightFilter->RegisterCellsWithType(VTK_VERTEX);
1619   }
1620
1621   if (myEntityMode & eBallElem) {
1622     aFilter->RegisterCellsWithType(VTK_POLY_VERTEX);
1623   }
1624
1625   if (myEntityMode & eEdges) {
1626     if (MYDEBUG) MESSAGE("EDGES");
1627     aFilter->RegisterCellsWithType(VTK_LINE);
1628     aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
1629
1630     aHightFilter->RegisterCellsWithType(VTK_LINE);
1631     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
1632   }
1633
1634   if (myEntityMode & eFaces) {
1635     if (MYDEBUG) MESSAGE("FACES");
1636     aFilter->RegisterCellsWithType(VTK_TRIANGLE);
1637     aFilter->RegisterCellsWithType(VTK_QUAD);
1638     aFilter->RegisterCellsWithType(VTK_POLYGON);
1639     aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
1640     aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
1641     aFilter->RegisterCellsWithType(VTK_QUADRATIC_POLYGON);
1642     aFilter->RegisterCellsWithType(VTK_BIQUADRATIC_QUAD);
1643     aFilter->RegisterCellsWithType(VTK_BIQUADRATIC_TRIANGLE);
1644
1645     aHightFilter->RegisterCellsWithType(VTK_TRIANGLE);
1646     aHightFilter->RegisterCellsWithType(VTK_QUAD);
1647     aHightFilter->RegisterCellsWithType(VTK_POLYGON);
1648     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
1649     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
1650     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_POLYGON);
1651     aHightFilter->RegisterCellsWithType(VTK_BIQUADRATIC_QUAD);
1652     aHightFilter->RegisterCellsWithType(VTK_BIQUADRATIC_TRIANGLE);
1653   }
1654
1655   if (myEntityMode & eVolumes) {
1656     if (MYDEBUG) MESSAGE("VOLUMES");
1657     aFilter->RegisterCellsWithType(VTK_TETRA);
1658     aFilter->RegisterCellsWithType(VTK_VOXEL);
1659     aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1660     aFilter->RegisterCellsWithType(VTK_WEDGE);
1661     aFilter->RegisterCellsWithType(VTK_PYRAMID);
1662     aFilter->RegisterCellsWithType(VTK_HEXAGONAL_PRISM);
1663     aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
1664     aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
1665     aFilter->RegisterCellsWithType(VTK_TRIQUADRATIC_HEXAHEDRON);
1666     aFilter->RegisterCellsWithType(VTK_QUADRATIC_PYRAMID);
1667     aFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
1668     aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1669     aFilter->RegisterCellsWithType(VTK_POLYHEDRON);
1670
1671     aHightFilter->RegisterCellsWithType(VTK_TETRA);
1672     aHightFilter->RegisterCellsWithType(VTK_VOXEL);
1673     aHightFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1674     aHightFilter->RegisterCellsWithType(VTK_WEDGE);
1675     aHightFilter->RegisterCellsWithType(VTK_PYRAMID);
1676     aHightFilter->RegisterCellsWithType(VTK_HEXAGONAL_PRISM);
1677     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
1678     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
1679     aHightFilter->RegisterCellsWithType(VTK_TRIQUADRATIC_HEXAHEDRON);
1680     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
1681     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_PYRAMID);
1682     aHightFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1683     aHightFilter->RegisterCellsWithType(VTK_POLYHEDRON);
1684   }
1685   aFilter->Update();
1686   if (MYDEBUG) MESSAGE(aFilter->GetOutput()->GetNumberOfCells());
1687   SetVisibility(GetVisibility(),false);
1688 }
1689
1690 void SMESH_ActorDef::SetRepresentation (int theMode)
1691 {
1692   int aNbEdges = myVisualObj->GetNbEntities(SMDSAbs_Edge);
1693   int aNbFaces = myVisualObj->GetNbEntities(SMDSAbs_Face);
1694   int aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume);
1695   int aNb0Ds       = myVisualObj->GetNbEntities(SMDSAbs_0DElement);
1696   int aNbBalls       = myVisualObj->GetNbEntities(SMDSAbs_Ball);
1697
1698   if (theMode < 0) {
1699     myRepresentation = eSurface;
1700     if (!aNbFaces && !aNbVolumes && !aNbBalls && aNbEdges) {
1701       myRepresentation = eEdge;
1702     } else if (!aNbFaces && !aNbVolumes && !aNbEdges && !aNbBalls) {
1703       myRepresentation = ePoint;
1704     }
1705   } else {
1706     switch (theMode) {
1707     case eEdge:
1708       if (!aNbFaces && !aNbVolumes && !aNbEdges && !aNb0Ds && !aNbBalls) return;
1709       break;
1710     case eSurface:
1711       if (!aNbFaces && !aNbVolumes && !aNb0Ds && !aNbBalls) return;
1712       break;
1713     }
1714     myRepresentation = theMode;
1715   }
1716
1717   if (!GetUnstructuredGrid()->GetNumberOfCells())
1718     myRepresentation = ePoint;
1719
1720   if (myIsShrunk) {
1721     if (myRepresentation == ePoint) {
1722       UnShrink();
1723       myIsShrunk = true;
1724     } else {
1725       SetShrink();
1726     }
1727   }
1728
1729   myPickableActor = myBaseActor;
1730   myNodeActor->SetVisibility(false);
1731   myNodeExtActor->SetVisibility(false);
1732   vtkProperty *aProp = NULL, *aBackProp = NULL;
1733   vtkProperty *aPropVN = NULL, *aPropVR = NULL;
1734   SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::EReperesent(-1);
1735   SMESH_Actor::EQuadratic2DRepresentation aQuadraticMode = GetQuadratic2DRepresentation();
1736   switch (myRepresentation) {
1737   case ePoint:
1738     myPickableActor = myNodeActor;
1739     myNodeActor->SetVisibility(true);
1740     aQuadraticMode = SMESH_Actor::eLines;
1741     aProp = aBackProp = aPropVN = aPropVR = myNodeProp;
1742     aReperesent = SMESH_DeviceActor::ePoint;
1743     break;
1744   case eEdge:
1745     aProp = aBackProp = aPropVN = aPropVR = myEdgeProp;
1746     aReperesent = SMESH_DeviceActor::eInsideframe;
1747     break;
1748   case eSurface:
1749     aProp = mySurfaceProp;
1750     aBackProp = myBackSurfaceProp;
1751     aPropVN = myNormalVProp;
1752     aPropVR = myReversedVProp;
1753     aReperesent = SMESH_DeviceActor::eSurface;
1754     break;
1755   }
1756
1757   my2DActor->SetProperty(aProp);
1758   my2DActor->SetBackfaceProperty(aBackProp);
1759   my2DActor->SetRepresentation(aReperesent);
1760
1761   if(aQuadraticMode == SMESH_Actor::eLines)
1762     my2DActor->SetQuadraticArcMode(false);
1763   else if(aQuadraticMode == SMESH_Actor::eArcs)
1764     my2DActor->SetQuadraticArcMode(true);
1765
1766   my2DExtActor->SetRepresentation(aReperesent);
1767
1768   my3DActor->SetProperty(aPropVN);
1769   my3DActor->SetBackfaceProperty(aPropVR);
1770   my3DActor->SetRepresentation(aReperesent);
1771
1772
1773   my1DExtActor->SetVisibility(false);
1774   my2DExtActor->SetVisibility(false);
1775   my3DExtActor->SetVisibility(false);
1776
1777   my0DActor->SetRepresentation(aReperesent);
1778   myBallActor->SetRepresentation(aReperesent);
1779
1780   switch ( myControlMode ) {
1781   case eLength:
1782   case eMultiConnection:
1783     aProp = aBackProp = my1DProp;
1784     if(myRepresentation != ePoint)
1785       aReperesent = SMESH_DeviceActor::eInsideframe;
1786     break;
1787   default:;
1788   }
1789
1790   if(aQuadraticMode == SMESH_Actor::eLines)
1791     my1DActor->SetQuadraticArcMode(false);
1792   else if(aQuadraticMode == SMESH_Actor::eArcs)
1793     my1DActor->SetQuadraticArcMode(true);
1794
1795   my1DActor->SetProperty(aProp);
1796   my1DActor->SetBackfaceProperty(aBackProp);
1797   my1DActor->SetRepresentation(aReperesent);
1798
1799   my1DExtActor->SetRepresentation(aReperesent);
1800
1801   if(myIsPointsVisible)
1802     myPickableActor = myNodeActor;
1803   if(GetPointRepresentation())
1804     myNodeActor->SetVisibility(true);
1805
1806   SetMapper(myPickableActor->GetMapper());
1807
1808   SetVisibility(GetVisibility(),false);
1809
1810   Modified();
1811 }
1812
1813
1814 void SMESH_ActorDef::SetPointRepresentation(bool theIsPointsVisible)
1815 {
1816   if ( myIsPointsVisible == theIsPointsVisible )
1817     return;
1818   myIsPointsVisible = theIsPointsVisible;
1819   SetRepresentation(GetRepresentation());
1820 }
1821
1822 bool SMESH_ActorDef::GetPointRepresentation()
1823 {
1824   return myIsPointsVisible || myNodeActor->GetPointsLabeled();
1825 }
1826
1827
1828 void SMESH_ActorDef::UpdateHighlight()
1829 {
1830   myHighlitableActor->SetHighlited(false);
1831   myHighlitableActor->SetVisibility(false);
1832   bool anIsVisible = GetVisibility();
1833
1834   switch(myRepresentation){
1835   case SMESH_DeviceActor::eSurface:
1836   case SMESH_DeviceActor::eWireframe:
1837     {
1838       if(myIsHighlighted) {
1839         myHighlitableActor->SetProperty(myHighlightProp);
1840       }else if(myIsPreselected){
1841         myHighlitableActor->SetProperty(myPreselectProp);
1842       } else if(anIsVisible){
1843         (myRepresentation == eSurface) ?
1844           myHighlitableActor->SetProperty(myOutLineProp) : myHighlitableActor->SetProperty(myEdgeProp);
1845       }
1846       if(GetUnstructuredGrid()->GetNumberOfCells()) {
1847         myHighlitableActor->SetHighlited(anIsVisible);
1848         myHighlitableActor->GetExtractUnstructuredGrid()->
1849           SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::eCells);
1850         myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
1851       }
1852       myHighlitableActor->SetVisibility(anIsVisible);
1853       break;
1854     }
1855   case SMESH_DeviceActor::ePoint:
1856     {
1857       if(myIsHighlighted) {
1858         myNodeActor->SetProperty(myHighlightProp);
1859       }else if(myIsPreselected) {
1860         myNodeActor->SetProperty(myPreselectProp);
1861       } else if(anIsVisible) {
1862         myNodeActor->SetProperty(myNodeProp);
1863       }
1864       myNodeActor->SetRepresentation(SMESH_DeviceActor::ePoint);
1865       myNodeActor->GetExtractUnstructuredGrid()->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
1866       break;
1867     }
1868   }
1869 }
1870
1871
1872 void SMESH_ActorDef::highlight(bool theHighlight)
1873 {
1874   if ( myIsHighlighted == theHighlight )
1875     return;
1876   myIsHighlighted = theHighlight;
1877   UpdateHighlight();
1878 }
1879
1880
1881 void SMESH_ActorDef::SetPreSelected(bool thePreselect)
1882 {
1883   if ( myIsPreselected == thePreselect )
1884     return;
1885   myIsPreselected = thePreselect;
1886   UpdateHighlight();
1887 }
1888
1889
1890 // From vtkFollower
1891 int SMESH_ActorDef::RenderOpaqueGeometry(vtkViewport *vp)
1892 {
1893   if (myPickableActor->GetIsOpaque())
1894     {
1895     vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1896     this->Render(ren);
1897     return 1;
1898     }
1899   return 0;
1900 }
1901
1902
1903 int SMESH_ActorDef::RenderTranslucentGeometry(vtkViewport *vp)
1904 {
1905   if (!myPickableActor->GetIsOpaque())
1906     {
1907     vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1908     this->Render(ren);
1909     return 1;
1910     }
1911   return 0;
1912 }
1913
1914
1915 void SMESH_ActorDef::Render(vtkRenderer *ren)
1916 {
1917   unsigned long aTime = myTimeStamp->GetMTime();
1918   unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1919   unsigned long aClippingTime = myImplicitBoolean->GetMTime();
1920   if(anObjTime > aTime || aClippingTime > aTime)
1921     Update();
1922 }
1923
1924
1925 void SMESH_ActorDef::Update()
1926 {
1927   if(MYDEBUG) MESSAGE("SMESH_ActorDef::Update");
1928
1929   if(GetControlMode() != eNone) {
1930     unsigned long aTime = myTimeStamp->GetMTime();
1931     unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1932     if (anObjTime > aTime)
1933       SetControlMode(GetControlMode(),false);
1934   }
1935
1936   if(myNodeActor)
1937     myNodeActor->UpdateLabels();
1938
1939   if(my0DActor)
1940     my0DActor->UpdateLabels();
1941
1942   if(myBallActor)
1943     myBallActor->UpdateLabels();
1944
1945   if(my1DActor)
1946     my1DActor->UpdateLabels();
1947
1948   if(my2DActor)
1949     my2DActor->UpdateLabels();
1950
1951   if(my3DActor)
1952     my3DActor->UpdateLabels();
1953
1954   if(myIsFacesOriented){
1955     SetFacesOriented(myIsFacesOriented);
1956   }
1957
1958   if(myVisualObj->GetEntitiesFlag()) {
1959     myEntityMode |= myVisualObj->GetEntitiesState();
1960   }
1961
1962   SetEntityMode(GetEntityMode());
1963   SetVisibility(GetVisibility());
1964
1965   myTimeStamp->Modified();
1966   Modified();
1967 }
1968
1969
1970 void SMESH_ActorDef::ReleaseGraphicsResources(vtkWindow *renWin)
1971 {
1972   SALOME_Actor::ReleaseGraphicsResources(renWin);
1973
1974   myPickableActor->ReleaseGraphicsResources(renWin);
1975 }
1976
1977
1978 static void GetColor(vtkProperty *theProperty, double& r,double& g,double& b)
1979 {
1980   double* aColor = theProperty->GetColor();
1981   r = aColor[0];
1982   g = aColor[1];
1983   b = aColor[2];
1984 }
1985
1986
1987 void SMESH_ActorDef::SetOpacity(double theValue)
1988 {
1989   mySurfaceProp->SetOpacity(theValue);
1990   myBackSurfaceProp->SetOpacity(theValue);
1991   myNormalVProp->SetOpacity(theValue);
1992   myReversedVProp->SetOpacity(theValue);
1993   myEdgeProp->SetOpacity(theValue);
1994   myOutLineProp->SetOpacity(theValue);
1995   myNodeProp->SetOpacity(theValue);
1996
1997   my1DProp->SetOpacity(theValue);
1998   my0DProp->SetOpacity(theValue);
1999   myBallProp->SetOpacity(theValue);
2000 }
2001
2002
2003 double SMESH_ActorDef::GetOpacity()
2004 {
2005   return mySurfaceProp->GetOpacity();
2006 }
2007
2008
2009 void SMESH_ActorDef::SetSufaceColor(double r,double g,double b, int delta)
2010 {
2011   mySurfaceProp->SetColor(r,g,b);
2012   my2DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
2013   if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
2014     if( aGroupObj->GetElementType() == SMDSAbs_Face )
2015       myNameActor->SetBackgroundColor(r,g,b);
2016
2017   myDeltaBrightness = delta;
2018   QColor bfc = Qtx::mainColorToSecondary(QColor(int(r*255),int(g*255),int(b*255)), delta);
2019   myBackSurfaceProp->SetColor( bfc.red() / 255. , bfc.green() / 255. , bfc.blue() / 255. );
2020   Modified();
2021 }
2022
2023 void SMESH_ActorDef::GetSufaceColor(double& r,double& g,double& b, int& delta)
2024 {
2025   ::GetColor(mySurfaceProp,r,g,b);
2026   delta = myDeltaBrightness;
2027 }
2028
2029 void SMESH_ActorDef::SetVolumeColor(double r,double g,double b, int delta)
2030 {
2031   myNormalVProp->SetColor(r,g,b);
2032   my3DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
2033   if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
2034     if( aGroupObj->GetElementType() == SMDSAbs_Volume )
2035       myNameActor->SetBackgroundColor(r,g,b);
2036
2037   myDeltaVBrightness = delta;
2038   QColor bfc = Qtx::mainColorToSecondary(QColor(int(r*255),int(g*255),int(b*255)), delta);
2039   myReversedVProp->SetColor( bfc.red() / 255. , bfc.green() / 255. , bfc.blue() / 255. );
2040   Modified();
2041 }
2042
2043 void SMESH_ActorDef::GetVolumeColor(double& r,double& g,double& b, int& delta)
2044 {
2045   ::GetColor(myNormalVProp,r,g,b);
2046   delta = myDeltaVBrightness;
2047 }
2048
2049 void SMESH_ActorDef::SetEdgeColor(double r,double g,double b)
2050 {
2051   myEdgeProp->SetColor(r,g,b);
2052   my1DProp->SetColor(r,g,b);
2053   my1DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
2054   if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
2055     if( aGroupObj->GetElementType() == SMDSAbs_Edge )
2056       myNameActor->SetBackgroundColor(r,g,b);
2057   Modified();
2058 }
2059
2060 void SMESH_ActorDef::GetEdgeColor(double& r,double& g,double& b)
2061 {
2062   ::GetColor(myEdgeProp,r,g,b);
2063 }
2064
2065 void SMESH_ActorDef::SetOutlineColor(double r,double g,double b)
2066 {
2067   myOutLineProp->SetColor(r,g,b);
2068   Modified();
2069 }
2070
2071 void SMESH_ActorDef::GetOutlineColor(double& r,double& g,double& b)
2072 {
2073   ::GetColor(myOutLineProp,r,g,b);
2074 }
2075
2076
2077 void SMESH_ActorDef::SetNodeColor(double r,double g,double b)
2078
2079   myNodeProp->SetColor(r,g,b);
2080   myNodeExtProp->SetColor(1.0-r,1.0-g,1.0-b);
2081   if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
2082     if( aGroupObj->GetElementType() == SMDSAbs_Node )
2083       myNameActor->SetBackgroundColor(r,g,b);
2084   Modified();
2085 }
2086
2087 void SMESH_ActorDef::GetNodeColor(double& r,double& g,double& b)
2088
2089   ::GetColor(myNodeProp,r,g,b);
2090 }
2091
2092 void SMESH_ActorDef::Set0DColor(double r,double g,double b)
2093
2094   my0DProp->SetColor(r,g,b);
2095   if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
2096     if( aGroupObj->GetElementType() == SMDSAbs_0DElement )
2097       myNameActor->SetBackgroundColor(r,g,b);
2098   Modified();
2099 }
2100
2101 void SMESH_ActorDef::Get0DColor(double& r,double& g,double& b)
2102
2103   ::GetColor(my0DProp,r,g,b);
2104 }
2105
2106 void SMESH_ActorDef::SetBallColor(double r,double g,double b)
2107
2108   myBallProp->SetColor(r,g,b);
2109   if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
2110     if( aGroupObj->GetElementType() == SMDSAbs_Ball )
2111       myNameActor->SetBackgroundColor(r,g,b);
2112   Modified();
2113 }
2114
2115 void SMESH_ActorDef::GetBallColor(double& r,double& g,double& b)
2116
2117   ::GetColor(myBallProp,r,g,b);
2118 }
2119
2120 void SMESH_ActorDef::SetHighlightColor(double r,double g,double b)
2121
2122   myHighlightProp->SetColor(r,g,b);
2123   Modified();
2124 }
2125
2126 void SMESH_ActorDef::GetHighlightColor(double& r,double& g,double& b)
2127
2128   ::GetColor(myHighlightProp,r,g,b);
2129 }
2130
2131 void SMESH_ActorDef::SetPreHighlightColor(double r,double g,double b)
2132
2133   myPreselectProp->SetColor(r,g,b);
2134   Modified();
2135 }
2136
2137 void SMESH_ActorDef::GetPreHighlightColor(double& r,double& g,double& b)
2138
2139   ::GetColor(myPreselectProp,r,g,b);
2140 }
2141
2142
2143 double SMESH_ActorDef::GetLineWidth()
2144 {
2145   return myEdgeProp->GetLineWidth();
2146 }
2147
2148
2149 void SMESH_ActorDef::SetLineWidth(double theVal)
2150 {
2151   myEdgeProp->SetLineWidth(theVal);
2152
2153   my1DProp->SetLineWidth(theVal + aLineWidthInc);
2154   my1DExtProp->SetLineWidth(theVal + aLineWidthInc);
2155   my2DExtProp->SetLineWidth(theVal + aLineWidthInc);
2156   my3DExtProp->SetLineWidth(theVal + aLineWidthInc);
2157   myOutLineProp->SetLineWidth(theVal);
2158   myHighlightProp->SetLineWidth(theVal);
2159   myPreselectProp->SetLineWidth(theVal);
2160   Modified();
2161 }
2162
2163 double SMESH_ActorDef::GetOutlineWidth()
2164 {
2165   return myOutLineProp->GetLineWidth();
2166 }
2167
2168 void SMESH_ActorDef::SetOutlineWidth(double theVal)
2169 {
2170   myOutLineProp->SetLineWidth(theVal);
2171   Modified();
2172 }
2173
2174 void SMESH_ActorDef::Set0DSize(double theVal)
2175 {
2176   my0DProp->SetPointSize(theVal);
2177   myHighlightProp->SetPointSize(theVal);
2178   myPreselectProp->SetPointSize(theVal);
2179
2180   if(SMESH_SVTKActor* aCustom = SMESH_SVTKActor::SafeDownCast( myHighlightActor )) {
2181     aCustom->Set0DSize(theVal);
2182   }
2183   if(SMESH_SVTKActor* aCustom = SMESH_SVTKActor::SafeDownCast( myPreHighlightActor )) {
2184     aCustom->Set0DSize(theVal);
2185   }
2186
2187   Modified();
2188 }
2189
2190 double SMESH_ActorDef::Get0DSize()
2191 {
2192   return my0DProp->GetPointSize();
2193 }
2194
2195 void SMESH_ActorDef::SetBallSize(double theVal)
2196 {
2197   myBallProp->SetPointSize(theVal);
2198
2199   if(SMESH_SVTKActor* aCustom = SMESH_SVTKActor::SafeDownCast( myHighlightActor )) {
2200     aCustom->SetBallSize(theVal);
2201   }
2202   if(SMESH_SVTKActor* aCustom = SMESH_SVTKActor::SafeDownCast( myPreHighlightActor )) {
2203     aCustom->SetBallSize(theVal);
2204   }
2205
2206   Modified();
2207 }
2208
2209 double SMESH_ActorDef::GetBallSize()
2210 {
2211   return myBallProp->GetPointSize();
2212 }
2213
2214 double SMESH_ActorDef::GetBallScale()
2215 {
2216   return myBallActor->GetBallScale();
2217 }
2218
2219 void SMESH_ActorDef::SetBallScale( double theVal )
2220 {
2221   myBallActor->SetBallScale( theVal );
2222   if(SMESH_SVTKActor* aCustom = SMESH_SVTKActor::SafeDownCast( myHighlightActor )) {
2223     aCustom->SetBallScale(theVal);
2224   }
2225   if(SMESH_SVTKActor* aCustom = SMESH_SVTKActor::SafeDownCast( myPreHighlightActor )) {
2226     aCustom->SetBallScale(theVal);
2227   }
2228
2229   Modified();
2230 }
2231
2232 int SMESH_ActorDef::GetObjDimension( const int theObjId )
2233 {
2234   return myVisualObj->GetElemDimension( theObjId );
2235 }
2236
2237 bool SMESH_ActorDef::IsImplicitFunctionUsed() const
2238 {
2239   return myBaseActor->IsImplicitFunctionUsed();
2240 }
2241
2242 void SMESH_ActorDef::SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed)
2243 {
2244   myNodeActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
2245   myBaseActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
2246
2247   myHighlitableActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
2248
2249   myNodeExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
2250
2251   my0DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
2252   myBallActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
2253   //my0DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
2254
2255   my1DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
2256   my1DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
2257
2258   my2DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
2259   my2DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
2260   my3DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
2261   my3DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
2262 }
2263
2264 vtkIdType SMESH_ActorDef::AddClippingPlane(vtkPlane* thePlane)
2265 {
2266   if(thePlane){
2267     myImplicitBoolean->GetFunction()->AddItem(thePlane);
2268     myCippingPlaneCont.push_back(thePlane);
2269     if(!IsImplicitFunctionUsed())
2270       SetImplicitFunctionUsed(true);
2271     myNodeActor->UpdateLabels();
2272   }
2273   return myCippingPlaneCont.size();
2274 }
2275
2276 void SMESH_ActorDef::AddOpenGLClippingPlane(vtkPlane* thePlane)
2277 {
2278   if(thePlane)
2279     myPlaneCollection->AddItem( thePlane );
2280 }
2281
2282 void SMESH_ActorDef::SetOpenGLClippingPlane()
2283 {
2284   // before use this method you must add clipping planes using method
2285   // SMESH_ActorDef::AddOpenGLClippingPlane(vtkPlane* thePlane)
2286   if( !myPlaneCollection->GetNumberOfItems() )
2287     return;
2288
2289   // It is necessary to set plane collection for each mapper of actor
2290   // and update current inputs of mapper
2291   myNodeActor->SetPlaneCollection( myPlaneCollection );
2292   myNodeActor->SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
2293
2294   myBaseActor->SetPlaneCollection( myPlaneCollection );
2295   myBaseActor->SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
2296
2297   myHighlitableActor->SetPlaneCollection( myPlaneCollection );
2298   myHighlitableActor->SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
2299
2300   my1DActor->SetPlaneCollection( myPlaneCollection );
2301   my1DActor->SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
2302
2303   my2DActor->SetPlaneCollection( myPlaneCollection );
2304   my2DActor->SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
2305
2306   myNodeExtActor->SetPlaneCollection( myPlaneCollection );
2307   myNodeExtActor->SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
2308
2309   my0DActor->SetPlaneCollection( myPlaneCollection );
2310   my0DActor->SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
2311
2312   myBallActor->SetPlaneCollection( myPlaneCollection );
2313   myBallActor->SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
2314
2315   my1DExtActor->SetPlaneCollection( myPlaneCollection );
2316   my1DExtActor->SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
2317
2318   my2DExtActor->SetPlaneCollection( myPlaneCollection );
2319   my2DExtActor->SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
2320
2321   my3DActor->SetPlaneCollection( myPlaneCollection );
2322   my3DActor->SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
2323
2324   my3DExtActor->SetPlaneCollection( myPlaneCollection );
2325   my3DExtActor->SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
2326
2327   if(IsShrunk())
2328     SetShrink();
2329   else  
2330     Modified();
2331 }
2332
2333 void SMESH_ActorDef::RemoveAllClippingPlanes()
2334 {
2335   myPlaneCollection->RemoveAllItems();
2336   myImplicitBoolean->GetFunction()->RemoveAllItems();
2337   myImplicitBoolean->GetFunction()->Modified(); // VTK bug
2338   myCippingPlaneCont.clear();
2339   SetImplicitFunctionUsed(false);
2340   myNodeActor->UpdateLabels();
2341 }
2342
2343 vtkIdType SMESH_ActorDef::GetNumberOfClippingPlanes()
2344 {
2345   return myCippingPlaneCont.size();
2346 }
2347
2348 vtkPlane* SMESH_ActorDef::GetClippingPlane(vtkIdType theID)
2349 {
2350   if ( theID >= (vtkIdType)myCippingPlaneCont.size() )
2351     return NULL;
2352   return myCippingPlaneCont[theID].Get();
2353 }
2354
2355 void SMESH_ActorDef::UpdateScalarBar()
2356 {
2357   SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
2358   if( !mgr )
2359     return;
2360
2361   vtkTextProperty* aScalarBarTitleProp = vtkTextProperty::New();
2362
2363   QColor aTColor = mgr->colorValue( "SMESH", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
2364   aScalarBarTitleProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
2365
2366   aScalarBarTitleProp->SetFontFamilyToArial();
2367
2368   if ( mgr->hasValue( "SMESH", "scalar_bar_title_font" ) )
2369   {
2370     QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
2371     if ( f.family() == "Arial" )
2372       aScalarBarTitleProp->SetFontFamilyToArial();
2373     else if ( f.family() == "Courier" )
2374       aScalarBarTitleProp->SetFontFamilyToCourier();
2375     else if ( f.family() == "Times" )
2376       aScalarBarTitleProp->SetFontFamilyToTimes();
2377
2378     if ( f.bold() )
2379       aScalarBarTitleProp->BoldOn();
2380     else
2381       aScalarBarTitleProp->BoldOff();
2382
2383     if ( f.italic() )
2384       aScalarBarTitleProp->ItalicOn();
2385     else
2386      aScalarBarTitleProp->ItalicOff();
2387
2388     if ( f.overline() )
2389       aScalarBarTitleProp->ShadowOn();
2390     else
2391       aScalarBarTitleProp->ShadowOff();
2392   }
2393
2394   myScalarBarActor->SetTitleTextProperty( aScalarBarTitleProp );
2395   aScalarBarTitleProp->Delete();
2396
2397   vtkTextProperty* aScalarBarLabelProp = vtkTextProperty::New();
2398
2399   aTColor = mgr->colorValue( "SMESH", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
2400   aScalarBarLabelProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
2401
2402   aScalarBarLabelProp->SetFontFamilyToArial();
2403   if( mgr->hasValue( "SMESH", "scalar_bar_label_font" ) )
2404   {
2405     QFont f = mgr->fontValue( "SMESH", "scalar_bar_label_font" );
2406     if( f.family() == "Arial" )
2407       aScalarBarLabelProp->SetFontFamilyToArial();
2408     else if( f.family() == "Courier" )
2409       aScalarBarLabelProp->SetFontFamilyToCourier();
2410     else if( f.family() == "Times" )
2411       aScalarBarLabelProp->SetFontFamilyToTimes();
2412
2413     if ( f.bold() )
2414       aScalarBarLabelProp->BoldOn();
2415     else
2416       aScalarBarLabelProp->BoldOff();
2417
2418     if ( f.italic() )
2419       aScalarBarLabelProp->ItalicOn();
2420     else
2421       aScalarBarLabelProp->ItalicOff();
2422
2423     if( f.overline() )
2424       aScalarBarLabelProp->ShadowOn();
2425     else
2426       aScalarBarLabelProp->ShadowOff();
2427   }
2428
2429   myScalarBarActor->SetLabelTextProperty( aScalarBarLabelProp );
2430   aScalarBarLabelProp->Delete();
2431
2432   bool horiz = ( mgr->integerValue( "SMESH", "scalar_bar_orientation" ) == 1 );
2433   QString name = QString( "scalar_bar_%1_" ).arg( horiz ? "horizontal" : "vertical" );
2434   if( horiz )
2435     myScalarBarActor->SetOrientationToHorizontal();
2436   else
2437     myScalarBarActor->SetOrientationToVertical();
2438
2439
2440   double aXVal = horiz ? 0.20 : 0.01;
2441   if( mgr->hasValue( "SMESH", name + "x" ) )
2442     aXVal = mgr->doubleValue( "SMESH", name + "x", aXVal );
2443
2444   double aYVal = horiz ? 0.01 : 0.1;
2445   if( mgr->hasValue( "SMESH", name + "y" ) )
2446     aYVal = mgr->doubleValue( "SMESH", name + "y", aYVal );
2447   myScalarBarActor->SetPosition( aXVal, aYVal );
2448
2449   double aWVal = horiz ? 0.60 : 0.10;
2450   if( mgr->hasValue( "SMESH", name + "width" ) )
2451     aWVal = mgr->doubleValue( "SMESH", name + "width", aWVal );
2452   myScalarBarActor->SetWidth( aWVal );
2453
2454   double aHVal = horiz ? 0.12 : 0.80;
2455   if( mgr->hasValue( "SMESH", name + "height" ) )
2456     aHVal = mgr->doubleValue( "SMESH", name + "height", aHVal );
2457   myScalarBarActor->SetHeight( aHVal );
2458
2459   int anIntVal = 5;
2460   if( mgr->hasValue( "SMESH", "scalar_bar_num_labels" ) )
2461     anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_labels", anIntVal );
2462   myScalarBarActor->SetNumberOfLabels( anIntVal == 0 ? 5: anIntVal );
2463
2464   anIntVal = 64;
2465   if( mgr->hasValue( "SMESH", "scalar_bar_num_colors" ) )
2466     anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_colors", anIntVal );
2467   myScalarBarActor->SetMaximumNumberOfColors( anIntVal == 0 ? 64 : anIntVal );
2468
2469   bool distributionVisibility = mgr->booleanValue("SMESH","distribution_visibility");
2470   myScalarBarActor->SetDistributionVisibility(distributionVisibility);
2471
2472   int coloringType = mgr->integerValue("SMESH", "distribution_coloring_type", 0);
2473   myScalarBarActor->SetDistributionColoringType(coloringType);
2474
2475   QColor distributionColor = mgr->colorValue("SMESH", "distribution_color",
2476                                              QColor(255, 255, 255));
2477   double rgb[3];
2478   rgb[0]= distributionColor.red()/255.;
2479   rgb[1]= distributionColor.green()/255.;
2480   rgb[2]= distributionColor.blue()/255.;
2481   myScalarBarActor->SetDistributionColor(rgb);
2482
2483
2484 }
2485
2486 void SMESH_ActorDef::UpdateDistribution()
2487 {
2488   if(SMESH::Controls::NumericalFunctor* fun =
2489      dynamic_cast<SMESH::Controls::NumericalFunctor*>(myFunctor.get()))
2490   {
2491     int nbIntervals = myScalarBarActor->GetMaximumNumberOfColors();
2492     std::vector<int> nbEvents;
2493     std::vector<double> funValues;
2494     SMESH_VisualObjDef::TEntityList elems;
2495     if ( ! dynamic_cast<SMESH_MeshObj*>(myVisualObj.get()))
2496       dynamic_cast<SMESH_VisualObjDef*>(myVisualObj.get())->GetEntities( fun->GetType(), elems );
2497     std::vector<int> elemIds; elemIds.reserve( elems.size() );
2498     for ( SMESH_VisualObjDef::TEntityList::iterator e = elems.begin(); e != elems.end(); ++e)
2499       elemIds.push_back( (*e)->GetID());
2500     vtkLookupTable* lookupTable = static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
2501     double * range = lookupTable->GetRange();
2502     bool isLogarithmic = lookupTable->GetScale() == VTK_SCALE_LOG10;
2503     fun->GetHistogram(nbIntervals, nbEvents, funValues, elemIds, range, isLogarithmic);
2504     myScalarBarActor->SetDistribution(nbEvents);
2505   }
2506 }
2507
2508 void SMESH_ActorDef::SetQuadratic2DRepresentation(EQuadratic2DRepresentation theMode)
2509 {
2510   switch(theMode) {
2511   case SMESH_Actor::eLines :
2512     myHighlitableActor->SetQuadraticArcMode(false);
2513     my2DActor->SetQuadraticArcMode(false);
2514     my1DActor->SetQuadraticArcMode(false);
2515     break;
2516   case SMESH_Actor::eArcs :
2517     myHighlitableActor->SetQuadraticArcMode(true);
2518     if(GetRepresentation() != SMESH_Actor::ePoint) {
2519       my2DActor->SetQuadraticArcMode(true);
2520       my1DActor->SetQuadraticArcMode(true);
2521     }
2522     break;
2523   default:
2524     break;
2525   }
2526 }
2527
2528
2529 SMESH_Actor::EQuadratic2DRepresentation SMESH_ActorDef::GetQuadratic2DRepresentation()
2530 {
2531   if(myHighlitableActor->GetQuadraticArcMode())
2532     return SMESH_Actor::eArcs;
2533   else
2534     return SMESH_Actor::eLines;
2535 }
2536
2537 void SMESH_ActorDef::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale )
2538 {
2539   SALOME_Actor::SetMarkerStd( theMarkerType, theMarkerScale );
2540   myNodeActor->SetMarkerStd( theMarkerType, theMarkerScale );
2541   myNodeExtActor->SetMarkerStd( theMarkerType, theMarkerScale );
2542 }
2543
2544 void SMESH_ActorDef::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
2545 {
2546   SALOME_Actor::SetMarkerTexture( theMarkerId, theMarkerTexture );
2547   myNodeActor->SetMarkerTexture( theMarkerId, theMarkerTexture );
2548   myNodeExtActor->SetMarkerTexture( theMarkerId, theMarkerTexture );
2549   myMarkerTexture = theMarkerTexture; // for deferred update of myHighlightActor
2550 }
2551
2552 #ifndef DISABLE_PLOT2DVIEWER
2553 SPlot2d_Histogram* SMESH_ActorDef::UpdatePlot2Histogram()
2554 {
2555   if(my2dHistogram)
2556     my2dHistogram->clearAllPoints();
2557
2558   if(SMESH::Controls::NumericalFunctor* fun =
2559      dynamic_cast<SMESH::Controls::NumericalFunctor*>(myFunctor.get()))
2560   {
2561
2562     if(!my2dHistogram) {
2563       my2dHistogram = new SPlot2d_Histogram();
2564       Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(getIO()->getEntry(),"SMESH",getName());
2565       my2dHistogram->setIO(anIO);
2566     }
2567
2568     int nbIntervals = myScalarBarActor->GetMaximumNumberOfColors();
2569     std::vector<int> nbEvents;
2570     std::vector<double> funValues;
2571     SMESH_VisualObjDef::TEntityList elems;
2572     if ( ! dynamic_cast<SMESH_MeshObj*>(myVisualObj.get()))
2573       dynamic_cast<SMESH_VisualObjDef*>(myVisualObj.get())->GetEntities( fun->GetType(), elems );
2574     std::vector<int> elemIds;
2575
2576     for ( SMESH_VisualObjDef::TEntityList::iterator e = elems.begin(); e != elems.end(); ++e)
2577       elemIds.push_back( (*e)->GetID());
2578
2579     vtkLookupTable* lookupTable = static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
2580     double * range = lookupTable->GetRange();
2581     bool isLogarithmic = lookupTable->GetScale() == VTK_SCALE_LOG10;
2582     fun->GetHistogram(nbIntervals, nbEvents, funValues, elemIds, range, isLogarithmic);
2583
2584     for ( size_t i = 0; i < std::min( nbEvents.size(), funValues.size() -1 ); i++ )
2585       my2dHistogram->addPoint(funValues[i] + (funValues[i+1] - funValues[i])/2.0, static_cast<double>(nbEvents[i]));
2586
2587     if(funValues.size() >= 2)
2588       my2dHistogram->setWidth((funValues[1] - funValues[0]) * 0.8) ;
2589
2590   }
2591
2592   //Color of the histogram
2593   if(myScalarBarActor->GetDistributionColoringType() == SMESH_MULTICOLOR_TYPE)
2594     my2dHistogram->setAutoAssign(true);
2595   else {
2596     double rgb[3];
2597     myScalarBarActor->GetDistributionColor(rgb);
2598     QColor aColor = QColor( (int)( rgb[0]*255 ), (int)( rgb[1]*255 ), (int)( rgb[2]*255 ) );
2599     my2dHistogram->setColor(aColor);
2600
2601   }
2602
2603   return my2dHistogram;
2604 }
2605 #endif