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