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