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