Salome HOME
0021338: EDF 1926 SMESH: New controls and filters
[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 eCoincidentNodes:
695       myFunctor.reset(new SMESH::Controls::CoincidentNodes());
696       myControlActor = myNodeActor;
697       break;
698     case eCoincidentElems1D:
699       myFunctor.reset(new SMESH::Controls::CoincidentElements1D());
700       myControlActor = my1DActor;
701       break;
702     case eCoincidentElems2D:
703       myFunctor.reset(new SMESH::Controls::CoincidentElements2D());
704       myControlActor = my2DActor;
705       break;
706     case eCoincidentElems3D:
707       myFunctor.reset(new SMESH::Controls::CoincidentElements3D());
708       myControlActor = my3DActor;
709       break;
710     case eBareBorderFace:
711       myFunctor.reset(new SMESH::Controls::BareBorderFace());
712       myControlActor = my2DActor;
713       break;
714     case eOverConstrainedFace:
715       myFunctor.reset(new SMESH::Controls::OverConstrainedFace());
716       myControlActor = my2DActor;
717       break;
718     case eMultiConnection:
719       myFunctor.reset(new SMESH::Controls::MultiConnection());
720       myControlActor = my1DActor;
721       break;
722     case eMultiConnection2D:
723       myFunctor.reset(new SMESH::Controls::MultiConnection2D());
724       myControlActor = my2DActor;
725       break;
726     case eArea:
727     {
728       SMESH::Controls::Area* aControl = new SMESH::Controls::Area();
729       aControl->SetPrecision( myControlsPrecision );
730       myFunctor.reset( aControl );
731       myControlActor = my2DActor;
732       break;
733     }
734     case eTaper:
735     {
736       SMESH::Controls::Taper* aControl = new SMESH::Controls::Taper();
737       aControl->SetPrecision( myControlsPrecision );
738       myFunctor.reset( aControl );
739       myControlActor = my2DActor;
740       break;
741     }
742     case eAspectRatio:
743     {
744       SMESH::Controls::AspectRatio* aControl = new SMESH::Controls::AspectRatio();
745       aControl->SetPrecision( myControlsPrecision );
746       myFunctor.reset( aControl );
747       myControlActor = my2DActor;
748       break;
749     }
750     case eAspectRatio3D:
751     {
752       SMESH::Controls::AspectRatio3D* aControl = new SMESH::Controls::AspectRatio3D();
753       aControl->SetPrecision( myControlsPrecision );
754       myFunctor.reset( aControl );
755       myControlActor = my3DActor;
756       break;
757     }
758     case eVolume3D:
759     {
760       SMESH::Controls::Volume* aControl = new SMESH::Controls::Volume();
761       aControl->SetPrecision( myControlsPrecision );
762       myFunctor.reset( aControl );
763       myControlActor = my3DActor;
764       break;
765     }
766     case eMaxElementLength2D:
767     {
768       SMESH::Controls::MaxElementLength2D* aControl = new SMESH::Controls::MaxElementLength2D();
769       aControl->SetPrecision( myControlsPrecision );
770       myFunctor.reset( aControl );
771       myControlActor = my2DActor;
772       break;
773     }
774     case eMaxElementLength3D:
775     {
776       SMESH::Controls::MaxElementLength3D* aControl = new SMESH::Controls::MaxElementLength3D();
777       aControl->SetPrecision( myControlsPrecision );
778       myFunctor.reset( aControl );
779       myControlActor = my3DActor;
780       break;
781     }
782     case eBareBorderVolume:
783     {
784       myFunctor.reset(new SMESH::Controls::BareBorderVolume());
785       myControlActor = my3DActor;
786       break;
787     }
788     case eOverConstrainedVolume:
789     {
790       myFunctor.reset(new SMESH::Controls::OverConstrainedVolume());
791       myControlActor = my3DActor;
792       break;
793     }
794     case eMinimumAngle:
795     {
796       SMESH::Controls::MinimumAngle* aControl = new SMESH::Controls::MinimumAngle();
797       aControl->SetPrecision( myControlsPrecision );
798       myFunctor.reset( aControl );
799       myControlActor = my2DActor;
800       break;
801     }
802     case eWarping:
803     {
804       SMESH::Controls::Warping* aControl = new SMESH::Controls::Warping();
805       aControl->SetPrecision( myControlsPrecision );
806       myFunctor.reset( aControl );
807       myControlActor = my2DActor;
808       break;
809     }
810     case eSkew:
811     {
812       SMESH::Controls::Skew* aControl = new SMESH::Controls::Skew();
813       aControl->SetPrecision( myControlsPrecision );
814       myFunctor.reset( aControl );
815       myControlActor = my2DActor;
816       break;
817     }
818     default:
819       return;
820     }
821
822     vtkUnstructuredGrid* aGrid = myControlActor->GetUnstructuredGrid();
823     vtkIdType aNbCells = aGrid->GetNumberOfCells();
824     if(aNbCells){
825       myControlMode = theMode;
826       switch(myControlMode){
827       case eFreeNodes:
828       case eCoincidentNodes:
829         myNodeExtActor->SetExtControlMode(myFunctor);
830         break;
831       case eFreeEdges:
832       case eFreeBorders:
833       case eCoincidentElems1D:
834         my1DExtActor->SetExtControlMode(myFunctor);
835         break;
836       case eFreeFaces:
837       case eBareBorderFace:
838       case eOverConstrainedFace:
839       case eCoincidentElems2D:
840         my2DExtActor->SetExtControlMode(myFunctor);
841         break;
842       case eBareBorderVolume:
843       case eOverConstrainedVolume:
844       case eCoincidentElems3D:
845         my3DExtActor->SetExtControlMode(myFunctor);
846         break;
847       case eLength2D:
848       case eMultiConnection2D:
849         my1DExtActor->SetExtControlMode(myFunctor,myScalarBarActor,myLookupTable);
850         UpdateDistribution();
851         break;
852       default:
853         myControlActor->SetControlMode(myFunctor,myScalarBarActor,myLookupTable);
854         UpdateDistribution();
855       }
856     }
857
858     if(theCheckEntityMode) {
859       if(myControlActor == my1DActor) {
860         if (!myIsEntityModeCache){
861           myEntityModeCache = GetEntityMode();
862           myIsEntityModeCache=true;
863         } 
864         SetEntityMode(eEdges);
865       }
866       else if(myControlActor == my2DActor) {
867         switch(myControlMode) {
868         case eLength2D:
869         case eFreeEdges:
870         case eFreeFaces:
871         case eMultiConnection2D:
872           if (!myIsEntityModeCache){
873             myEntityModeCache = GetEntityMode();
874             myIsEntityModeCache=true;
875           } 
876           SetEntityMode(eFaces);
877           break;
878         default:
879           if (!myIsEntityModeCache){
880             myEntityModeCache = GetEntityMode();
881             myIsEntityModeCache=true;
882           }
883           SetEntityMode(eFaces);
884         }
885       }else if(myControlActor == my3DActor) {
886         if (!myIsEntityModeCache){
887             myEntityModeCache = GetEntityMode();
888             myIsEntityModeCache=true;
889         } 
890         SetEntityMode(eVolumes);
891     }
892     }
893
894   }
895   else {
896     if(theCheckEntityMode){
897       myEntityMode = myEntityModeCache;
898       myIsEntityModeCache = false;
899     }
900     myFunctor.reset();
901   }
902
903   SetRepresentation(GetRepresentation());
904
905   myTimeStamp->Modified();
906   Modified();
907   Update();
908 }
909
910
911 void SMESH_ActorDef::AddToRender(vtkRenderer* theRenderer){
912   theRenderer->AddActor(myBaseActor);  
913   theRenderer->AddActor(myNodeExtActor);
914   theRenderer->AddActor(my1DExtActor);
915
916   my3DActor->AddToRender(theRenderer);
917   my3DExtActor->AddToRender(theRenderer);
918   my2DActor->AddToRender(theRenderer);
919   my2DExtActor->AddToRender(theRenderer);
920   myNodeActor->AddToRender(theRenderer);
921   my1DActor->AddToRender(theRenderer);
922   my0DActor->AddToRender(theRenderer);
923   //theRenderer->AddActor(my0DExtActor);
924
925   theRenderer->AddActor(myHighlitableActor);
926   
927   theRenderer->AddActor2D(myScalarBarActor);
928
929   // the superclass' method should be called at the end
930   // (in particular, for correct work of selection)
931   SALOME_Actor::AddToRender(theRenderer);
932 }
933
934 void SMESH_ActorDef::RemoveFromRender(vtkRenderer* theRenderer){
935   SALOME_Actor::RemoveFromRender(theRenderer);
936
937   theRenderer->RemoveActor(myBaseActor);
938
939   theRenderer->RemoveActor(myNodeExtActor);
940
941   theRenderer->RemoveActor(myHighlitableActor);
942
943   //theRenderer->RemoveActor(my0DExtActor);
944
945   theRenderer->RemoveActor(my1DExtActor);
946
947   my2DActor->RemoveFromRender(theRenderer);
948   my2DExtActor->RemoveFromRender(theRenderer);
949   my3DActor->RemoveFromRender(theRenderer);
950   my3DExtActor->RemoveFromRender(theRenderer);
951   myNodeActor->RemoveFromRender(theRenderer);
952   my0DActor->RemoveFromRender(theRenderer);
953   my1DActor->RemoveFromRender(theRenderer);
954
955   theRenderer->RemoveActor(myScalarBarActor);
956 }
957
958
959 bool SMESH_ActorDef::Init(TVisualObjPtr theVisualObj, 
960                           const char* theEntry, 
961                           const char* theName,
962                           int theIsClear)
963 {
964   Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry,"SMESH",theName);
965   setIO(anIO);
966   setName(theName);
967
968   myVisualObj = theVisualObj;
969   myVisualObj->Update(theIsClear);
970
971   myNodeActor->Init(myVisualObj,myImplicitBoolean);
972   myBaseActor->Init(myVisualObj,myImplicitBoolean);
973
974   myHighlitableActor->Init(myVisualObj,myImplicitBoolean);
975
976   myNodeExtActor->Init(myVisualObj,myImplicitBoolean);
977   
978   my0DActor->Init(myVisualObj,myImplicitBoolean);
979   //my0DExtActor->Init(myVisualObj,myImplicitBoolean);
980   
981   my1DActor->Init(myVisualObj,myImplicitBoolean);
982   my1DExtActor->Init(myVisualObj,myImplicitBoolean);
983   
984   my2DActor->Init(myVisualObj,myImplicitBoolean);
985   my2DExtActor->Init(myVisualObj,myImplicitBoolean);
986   my3DActor->Init(myVisualObj,myImplicitBoolean);
987   my3DExtActor->Init(myVisualObj,myImplicitBoolean);
988   
989   my0DActor->GetMapper()->SetLookupTable(myLookupTable);
990   //my0DExtActor->GetMapper()->SetLookupTable(myLookupTable);
991   
992   my1DActor->GetMapper()->SetLookupTable(myLookupTable);
993   my1DExtActor->GetMapper()->SetLookupTable(myLookupTable);
994
995   my2DActor->GetMapper()->SetLookupTable(myLookupTable);
996   my2DExtActor->GetMapper()->SetLookupTable(myLookupTable);
997   my3DActor->GetMapper()->SetLookupTable(myLookupTable);
998   my3DExtActor->GetMapper()->SetLookupTable(myLookupTable);
999     
1000   vtkFloatingPointType aFactor, aUnits;
1001   my2DActor->GetPolygonOffsetParameters(aFactor,aUnits);
1002   my2DActor->SetPolygonOffsetParameters(aFactor,aUnits*0.75);
1003   my2DExtActor->SetPolygonOffsetParameters(aFactor,aUnits*0.5);
1004
1005   SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
1006   if( !mgr )
1007     return false;
1008
1009   //SetIsShrunkable(theGrid->GetNumberOfCells() > 10);
1010   SetIsShrunkable(true);
1011
1012   SetShrinkFactor( SMESH::GetFloat( "SMESH:shrink_coeff", 75 ) / 100. );
1013
1014   int aMode = mgr->integerValue( "SMESH", "display_mode" );
1015   SetRepresentation(-1);
1016   
1017   if(aMode == 0){
1018     SetRepresentation(eEdge);
1019   }else if(aMode == 1){
1020     SetRepresentation(eSurface);
1021   }else if(aMode == 2){
1022     SetRepresentation(ePoint);
1023   }
1024   
1025   if(aMode == 3){
1026     SetShrink();
1027   }
1028
1029   if( dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
1030     SetIsDisplayNameActor( true );
1031
1032   int aMarkerType = mgr->integerValue( "SMESH", "type_of_marker", 1 ); // dot
1033   int aMarkerScale = mgr->integerValue( "SMESH", "marker_scale", 9 );  // 5 pixels
1034   SetMarkerStd( (VTK::MarkerType)aMarkerType, (VTK::MarkerScale)aMarkerScale );
1035
1036   myTimeStamp->Modified();
1037   Modified();
1038   return true;
1039 }
1040
1041
1042 vtkFloatingPointType* SMESH_ActorDef::GetBounds(){
1043   return myNodeActor->GetBounds();
1044 }
1045
1046
1047 vtkDataSet* SMESH_ActorDef::GetInput(){
1048   return GetUnstructuredGrid();
1049 }
1050
1051
1052 void SMESH_ActorDef::SetTransform(VTKViewer_Transform* theTransform){
1053   Superclass::SetTransform(theTransform);
1054
1055   myNodeActor->SetTransform(theTransform);
1056   myBaseActor->SetTransform(theTransform);
1057   
1058   myHighlitableActor->SetTransform(theTransform);
1059
1060   myNodeExtActor->SetTransform(theTransform);
1061
1062   my0DActor->SetTransform(theTransform);
1063   //my0DExtActor->SetTransform(theTransform);
1064
1065   my1DActor->SetTransform(theTransform);
1066   my1DExtActor->SetTransform(theTransform);
1067
1068   my2DActor->SetTransform(theTransform);
1069   my2DExtActor->SetTransform(theTransform);
1070   my3DActor->SetTransform(theTransform);
1071   my3DExtActor->SetTransform(theTransform);
1072
1073   Modified();
1074 }
1075
1076
1077 void SMESH_ActorDef::SetMapper(vtkMapper* theMapper){
1078   vtkLODActor::SetMapper(theMapper);
1079 }
1080
1081
1082 void SMESH_ActorDef::ShallowCopy(vtkProp *prop){
1083   SALOME_Actor::ShallowCopy(prop);
1084 }
1085
1086
1087 vtkMapper* SMESH_ActorDef::GetMapper(){
1088   return myPickableActor->GetMapper();
1089 }
1090
1091
1092 vtkUnstructuredGrid* SMESH_ActorDef::GetUnstructuredGrid(){ 
1093   return myVisualObj->GetUnstructuredGrid();
1094 }
1095
1096
1097 bool SMESH_ActorDef::IsInfinitive(){
1098   vtkDataSet *aDataSet = myPickableActor->GetUnstructuredGrid();
1099   aDataSet->Update();
1100   myIsInfinite = aDataSet->GetNumberOfCells() == 0 ||
1101     ( aDataSet->GetNumberOfCells() == 1 && 
1102     aDataSet->GetCell(0)->GetCellType() == VTK_VERTEX );
1103   return SALOME_Actor::IsInfinitive();
1104 }
1105
1106
1107 void SMESH_ActorDef::SetIsShrunkable(bool theShrunkable){
1108   if ( myIsShrinkable == theShrunkable )
1109     return;
1110   myIsShrinkable = theShrunkable;
1111   Modified();
1112 }
1113
1114 vtkFloatingPointType SMESH_ActorDef::GetShrinkFactor(){
1115   return myBaseActor->GetShrinkFactor();
1116 }
1117
1118 void SMESH_ActorDef::SetShrinkFactor(vtkFloatingPointType theValue){
1119   myBaseActor->SetShrinkFactor(theValue);
1120
1121   my1DActor->SetShrinkFactor(theValue);
1122   my1DExtActor->SetShrinkFactor(theValue);
1123
1124   my2DActor->SetShrinkFactor(theValue);
1125   my2DExtActor->SetShrinkFactor(theValue);
1126   my3DActor->SetShrinkFactor(theValue);
1127   my3DExtActor->SetShrinkFactor(theValue);
1128   my3DExtActor->SetShrinkFactor(theValue);
1129   myHighlitableActor->SetShrinkFactor(theValue);
1130
1131   Modified();
1132 }
1133
1134 void SMESH_ActorDef::SetShrink(){
1135   if(!myIsShrinkable) return;
1136
1137   myBaseActor->SetShrink();
1138
1139   my1DActor->SetShrink();
1140   my1DExtActor->SetShrink();
1141
1142   my2DActor->SetShrink();
1143   my2DExtActor->SetShrink();
1144   my3DActor->SetShrink();
1145   my3DExtActor->SetShrink();
1146   myHighlitableActor->SetShrink();
1147
1148   myIsShrunk = true;
1149   Modified();
1150 }
1151
1152 void SMESH_ActorDef::UnShrink(){
1153   if(!myIsShrunk) return;
1154
1155   myBaseActor->UnShrink();
1156
1157   my1DActor->UnShrink();
1158   my1DExtActor->UnShrink();
1159
1160   my2DActor->UnShrink();
1161   my2DExtActor->UnShrink();
1162   my3DActor->UnShrink();
1163   my3DExtActor->UnShrink();
1164   myHighlitableActor->UnShrink();
1165
1166   myIsShrunk = false;
1167   Modified();
1168 }
1169
1170
1171 int SMESH_ActorDef::GetNodeObjId(int theVtkID){
1172   return myPickableActor->GetNodeObjId(theVtkID);
1173 }
1174
1175 vtkFloatingPointType* SMESH_ActorDef::GetNodeCoord(int theObjID){
1176   return myPickableActor->GetNodeCoord(theObjID);
1177 }
1178
1179
1180 int SMESH_ActorDef::GetElemObjId(int theVtkID){
1181   return myPickableActor->GetElemObjId(theVtkID);
1182 }
1183
1184 vtkCell* SMESH_ActorDef::GetElemCell(int theObjID){
1185   return myPickableActor->GetElemCell(theObjID);
1186 }
1187
1188
1189 void SMESH_ActorDef::SetVisibility(int theMode){
1190   SetVisibility(theMode,true);
1191 }
1192
1193
1194 void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation){
1195   SALOME_Actor::SetVisibility(theMode);
1196
1197   myNodeActor->VisibilityOff();
1198   myBaseActor->VisibilityOff();
1199   
1200   myNodeExtActor->VisibilityOff();
1201
1202   my0DActor->VisibilityOff();
1203   //my0DExtActor->VisibilityOff();
1204
1205   my1DActor->VisibilityOff();
1206   my1DExtActor->VisibilityOff();
1207   
1208   my2DActor->VisibilityOff();
1209   my2DExtActor->VisibilityOff();
1210   my3DActor->VisibilityOff();
1211   my3DExtActor->VisibilityOff();
1212   
1213   myScalarBarActor->VisibilityOff();
1214   
1215   if(GetVisibility()){
1216     if(theIsUpdateRepersentation)
1217       SetRepresentation(GetRepresentation());
1218     
1219     if(myControlMode != eNone){
1220       switch(myControlMode){
1221       case eFreeNodes:
1222       case eCoincidentNodes:
1223         myNodeExtActor->VisibilityOn();
1224         break;
1225       case eFreeEdges:
1226       case eFreeBorders:
1227       case eCoincidentElems1D:
1228       case eLength2D:
1229       case eMultiConnection2D:
1230         my1DExtActor->VisibilityOn();
1231         break;
1232       case eFreeFaces:
1233       case eBareBorderFace:
1234       case eOverConstrainedFace:
1235       case eCoincidentElems2D:
1236         my2DExtActor->VisibilityOn();
1237         break;
1238       case eBareBorderVolume:
1239       case eOverConstrainedVolume:
1240       case eCoincidentElems3D:
1241         my3DExtActor->VisibilityOn();
1242         break;
1243       default:
1244         if(myControlActor->GetUnstructuredGrid()->GetNumberOfCells())
1245           myScalarBarActor->VisibilityOn();
1246       }
1247     }
1248
1249     if(myRepresentation != ePoint)
1250       myPickableActor->VisibilityOn();
1251     else {
1252       myNodeActor->VisibilityOn();
1253     }
1254
1255     if(myEntityMode & e0DElements){
1256       my0DActor->VisibilityOn();
1257     }
1258
1259     if(myEntityMode & eEdges && GetRepresentation() != ePoint){
1260       my1DActor->VisibilityOn();
1261     }
1262     
1263     if(myEntityMode & eFaces && GetRepresentation() != ePoint){
1264       my2DActor->VisibilityOn();
1265     }
1266     
1267     if(myEntityMode & eVolumes && GetRepresentation() != ePoint){
1268       my3DActor->VisibilityOn();
1269     }
1270     
1271     if(myNodeActor->GetPointsLabeled()){ 
1272       myNodeActor->VisibilityOn();
1273     }
1274
1275     if(my0DActor)
1276       my0DActor->UpdateLabels();
1277     
1278     if(my1DActor)
1279       my1DActor->UpdateLabels();
1280     
1281     if(my2DActor)
1282       my2DActor->UpdateLabels();
1283     
1284     if(my3DActor)
1285       my3DActor->UpdateLabels();    
1286   } 
1287 #ifndef DISABLE_PLOT2DVIEWER
1288   else
1289     SMESH::ProcessIn2DViewers(this,SMESH::RemoveFrom2dViewer);
1290 #endif
1291   UpdateHighlight();
1292   Modified();
1293 }
1294
1295
1296 void SMESH_ActorDef::SetEntityMode(unsigned int theMode)
1297 {
1298   myEntityState = eAllEntity;
1299
1300   if(!myVisualObj->GetNbEntities(SMDSAbs_0DElement)) {
1301     myEntityState &= ~e0DElements;
1302     theMode &= ~e0DElements;
1303   }
1304
1305   if(!myVisualObj->GetNbEntities(SMDSAbs_Edge)) {
1306     myEntityState &= ~eEdges;
1307     theMode &= ~eEdges;
1308   }
1309
1310   if(!myVisualObj->GetNbEntities(SMDSAbs_Face)) {
1311     myEntityState &= ~eFaces;
1312     theMode &= ~eFaces;
1313   }
1314
1315   if(!myVisualObj->GetNbEntities(SMDSAbs_Volume)) {
1316     myEntityState &= ~eVolumes;
1317     theMode &= ~eVolumes;
1318   }
1319
1320   if (!theMode) {
1321     if(myVisualObj->GetNbEntities(SMDSAbs_0DElement))
1322       theMode |= e0DElements;
1323
1324     if(myVisualObj->GetNbEntities(SMDSAbs_Edge))
1325       theMode |= eEdges;
1326
1327     if(myVisualObj->GetNbEntities(SMDSAbs_Face))
1328       theMode |= eFaces;
1329
1330     if(myVisualObj->GetNbEntities(SMDSAbs_Volume))
1331       theMode |= eVolumes;
1332   }
1333
1334   myBaseActor->myGeomFilter->SetInside(myEntityMode != myEntityState);
1335
1336   myEntityMode = theMode;
1337   VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
1338   aFilter = myBaseActor->GetExtractUnstructuredGrid();
1339   aFilter->ClearRegisteredCellsWithType();
1340   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
1341
1342   VTKViewer_ExtractUnstructuredGrid* aHightFilter = myHighlitableActor->GetExtractUnstructuredGrid();
1343   aHightFilter->ClearRegisteredCellsWithType();
1344   aHightFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
1345
1346   if (myEntityMode & e0DElements) {
1347     if (MYDEBUG) MESSAGE("0D ELEMENTS");
1348     aFilter->RegisterCellsWithType(VTK_VERTEX);
1349     aHightFilter->RegisterCellsWithType(VTK_VERTEX);
1350   }
1351
1352   if (myEntityMode & eEdges) {
1353     if (MYDEBUG) MESSAGE("EDGES");
1354     aFilter->RegisterCellsWithType(VTK_LINE);
1355     aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
1356
1357     aHightFilter->RegisterCellsWithType(VTK_LINE);
1358     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
1359   }
1360
1361   if (myEntityMode & eFaces) {
1362     if (MYDEBUG) MESSAGE("FACES");
1363     aFilter->RegisterCellsWithType(VTK_TRIANGLE);
1364     aFilter->RegisterCellsWithType(VTK_POLYGON);
1365     aFilter->RegisterCellsWithType(VTK_QUAD);
1366     aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
1367     aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
1368     aFilter->RegisterCellsWithType(VTK_BIQUADRATIC_QUAD);
1369
1370     aHightFilter->RegisterCellsWithType(VTK_TRIANGLE);
1371     aHightFilter->RegisterCellsWithType(VTK_POLYGON);
1372     aHightFilter->RegisterCellsWithType(VTK_QUAD);
1373     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
1374     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
1375     aHightFilter->RegisterCellsWithType(VTK_BIQUADRATIC_QUAD);
1376   }
1377
1378   if (myEntityMode & eVolumes) {
1379     if (MYDEBUG) MESSAGE("VOLUMES");
1380     aFilter->RegisterCellsWithType(VTK_TETRA);
1381     aFilter->RegisterCellsWithType(VTK_VOXEL);
1382     aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1383     aFilter->RegisterCellsWithType(VTK_WEDGE);
1384     aFilter->RegisterCellsWithType(VTK_PYRAMID);
1385     aFilter->RegisterCellsWithType(VTK_HEXAGONAL_PRISM);
1386     aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
1387     aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
1388     aFilter->RegisterCellsWithType(VTK_TRIQUADRATIC_HEXAHEDRON);
1389     aFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
1390     aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1391 //#ifdef VTK_HAVE_POLYHEDRON
1392     aFilter->RegisterCellsWithType(VTK_POLYHEDRON);
1393 //#endif
1394     
1395     aHightFilter->RegisterCellsWithType(VTK_TETRA);
1396     aHightFilter->RegisterCellsWithType(VTK_VOXEL);
1397     aHightFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1398     aHightFilter->RegisterCellsWithType(VTK_WEDGE);
1399     aHightFilter->RegisterCellsWithType(VTK_PYRAMID);
1400     aHightFilter->RegisterCellsWithType(VTK_HEXAGONAL_PRISM);
1401     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
1402     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
1403     aHightFilter->RegisterCellsWithType(VTK_TRIQUADRATIC_HEXAHEDRON);
1404     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
1405     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_PYRAMID);
1406     aHightFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1407 //#ifdef VTK_HAVE_POLYHEDRON
1408     aHightFilter->RegisterCellsWithType(VTK_POLYHEDRON);
1409 //#endif
1410   }
1411   aFilter->Update();
1412   if (MYDEBUG) MESSAGE(aFilter->GetOutput()->GetNumberOfCells());
1413   SetVisibility(GetVisibility(),false);
1414 }
1415
1416 void SMESH_ActorDef::SetRepresentation (int theMode)
1417
1418   int aNbEdges = myVisualObj->GetNbEntities(SMDSAbs_Edge);
1419   int aNbFaces = myVisualObj->GetNbEntities(SMDSAbs_Face);
1420   int aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume);
1421
1422   if (theMode < 0) {
1423     myRepresentation = eSurface;
1424     if (!aNbFaces && !aNbVolumes && aNbEdges) {
1425       myRepresentation = eEdge;
1426     } else if (!aNbFaces && !aNbVolumes && !aNbEdges) {
1427       myRepresentation = ePoint;
1428     }
1429   } else {
1430     switch (theMode) {
1431     case eEdge:
1432       if (!aNbFaces && !aNbVolumes && !aNbEdges) return;
1433       break;
1434     case eSurface:
1435       if (!aNbFaces && !aNbVolumes) return;
1436       break;
1437     }    
1438     myRepresentation = theMode;
1439   }
1440
1441   if (!GetUnstructuredGrid()->GetNumberOfCells())
1442     myRepresentation = ePoint;
1443
1444   if (myIsShrunk) {
1445     if (myRepresentation == ePoint) {
1446       UnShrink();
1447       myIsShrunk = true;
1448     } else {
1449       SetShrink();
1450     }      
1451   }
1452
1453   myPickableActor = myBaseActor;
1454   myNodeActor->SetVisibility(false);
1455   myNodeExtActor->SetVisibility(false);
1456   vtkProperty *aProp = NULL, *aBackProp = NULL;
1457   SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::EReperesent(-1);
1458   SMESH_Actor::EQuadratic2DRepresentation aQuadraticMode = GetQuadratic2DRepresentation();
1459   switch (myRepresentation) {
1460   case ePoint:
1461     myPickableActor = myNodeActor;
1462     myNodeActor->SetVisibility(true);
1463     aQuadraticMode = SMESH_Actor::eLines;
1464     aProp = aBackProp = myNodeProp;
1465     aReperesent = SMESH_DeviceActor::ePoint;
1466     break;
1467   case eEdge:
1468     aProp = aBackProp = myEdgeProp;
1469     aReperesent = SMESH_DeviceActor::eInsideframe;
1470     break;
1471   case eSurface:
1472     aProp = mySurfaceProp;
1473     aBackProp = myBackSurfaceProp;
1474     aReperesent = SMESH_DeviceActor::eSurface;
1475     break;
1476   }
1477
1478   my2DActor->SetProperty(aProp);
1479   my2DActor->SetBackfaceProperty(aBackProp);
1480   my2DActor->SetRepresentation(aReperesent);
1481
1482   if(aQuadraticMode == SMESH_Actor::eLines)
1483     my2DActor->SetQuadraticArcMode(false);
1484   else if(aQuadraticMode == SMESH_Actor::eArcs)
1485     my2DActor->SetQuadraticArcMode(true);
1486
1487   my2DExtActor->SetRepresentation(aReperesent);
1488   
1489   my3DActor->SetProperty(aProp);
1490   my3DActor->SetBackfaceProperty(aBackProp);
1491   my3DActor->SetRepresentation(aReperesent);
1492
1493   //my0DExtActor->SetVisibility(false);
1494   my1DExtActor->SetVisibility(false);
1495   my2DExtActor->SetVisibility(false);
1496   my3DExtActor->SetVisibility(false);
1497
1498   // ???
1499   //my0DActor->SetProperty(aProp);
1500   //my0DActor->SetBackfaceProperty(aBackProp);
1501   my0DActor->SetRepresentation(aReperesent);
1502   //my0DExtActor->SetRepresentation(aReperesent);
1503
1504   switch(myControlMode){
1505   case eLength:
1506   case eMultiConnection:
1507     aProp = aBackProp = my1DProp;
1508     if(myRepresentation != ePoint)
1509       aReperesent = SMESH_DeviceActor::eInsideframe;
1510     break;
1511   }
1512   
1513   if(aQuadraticMode == SMESH_Actor::eLines)
1514     my1DActor->SetQuadraticArcMode(false);
1515   else if(aQuadraticMode == SMESH_Actor::eArcs)
1516     my1DActor->SetQuadraticArcMode(true);
1517
1518   my1DActor->SetProperty(aProp);
1519   my1DActor->SetBackfaceProperty(aBackProp);
1520   my1DActor->SetRepresentation(aReperesent);
1521
1522   my1DExtActor->SetRepresentation(aReperesent);
1523
1524   if(myIsPointsVisible)
1525     myPickableActor = myNodeActor;
1526   if(GetPointRepresentation())
1527     myNodeActor->SetVisibility(true);
1528
1529   SetMapper(myPickableActor->GetMapper());
1530
1531   SetVisibility(GetVisibility(),false);
1532
1533   Modified();
1534 }
1535
1536
1537 void SMESH_ActorDef::SetPointRepresentation(bool theIsPointsVisible){
1538   if ( myIsPointsVisible == theIsPointsVisible )
1539     return;
1540   myIsPointsVisible = theIsPointsVisible;
1541   SetRepresentation(GetRepresentation());
1542 }
1543
1544 bool SMESH_ActorDef::GetPointRepresentation(){ 
1545   return myIsPointsVisible || myNodeActor->GetPointsLabeled();
1546 }
1547
1548
1549 void SMESH_ActorDef::UpdateHighlight(){
1550   myHighlitableActor->SetHighlited(false);
1551   myHighlitableActor->SetVisibility(false);
1552
1553   bool anIsVisible = GetVisibility();
1554
1555   switch(myRepresentation){
1556   case SMESH_DeviceActor::eSurface:
1557   case SMESH_DeviceActor::eWireframe:
1558     {
1559       if(myIsHighlighted) {
1560         myHighlitableActor->SetProperty(myHighlightProp);
1561       }else if(myIsPreselected){
1562         myHighlitableActor->SetProperty(myPreselectProp);
1563       } else if(anIsVisible){
1564         (myRepresentation == eSurface) ? 
1565           myHighlitableActor->SetProperty(myOutLineProp) : myHighlitableActor->SetProperty(myEdgeProp);
1566       }
1567       if(GetUnstructuredGrid()->GetNumberOfCells()) {
1568         myHighlitableActor->SetHighlited(anIsVisible);
1569         myHighlitableActor->GetExtractUnstructuredGrid()->
1570           SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::eCells);
1571         myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
1572       }
1573       myHighlitableActor->SetVisibility(anIsVisible);
1574       break;
1575     }
1576   case SMESH_DeviceActor::ePoint:
1577     {
1578       if(myIsHighlighted) {
1579         myNodeActor->SetProperty(myHighlightProp);
1580       }else if(myIsPreselected) {
1581         myNodeActor->SetProperty(myPreselectProp);
1582       } else if(anIsVisible) {
1583         myNodeActor->SetProperty(myNodeProp);
1584       }
1585       myNodeActor->SetRepresentation(SMESH_DeviceActor::ePoint);
1586       myNodeActor->GetExtractUnstructuredGrid()->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
1587       break;
1588     }
1589   }
1590 }
1591
1592
1593 void SMESH_ActorDef::highlight(bool theHighlight){
1594   if ( myIsHighlighted == theHighlight )
1595     return;
1596   myIsHighlighted = theHighlight;
1597   UpdateHighlight();
1598 }
1599
1600
1601 void SMESH_ActorDef::SetPreSelected(bool thePreselect){ 
1602   if ( myIsPreselected == thePreselect )
1603     return;
1604   myIsPreselected = thePreselect; 
1605   UpdateHighlight();
1606 }
1607
1608
1609 // From vtkFollower
1610 int SMESH_ActorDef::RenderOpaqueGeometry(vtkViewport *vp)
1611 {
1612   if (myPickableActor->GetIsOpaque())
1613     {
1614     vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1615     this->Render(ren);
1616     return 1;
1617     }
1618   return 0;
1619 }
1620
1621
1622 int SMESH_ActorDef::RenderTranslucentGeometry(vtkViewport *vp)
1623 {
1624   if (!myPickableActor->GetIsOpaque())
1625     {
1626     vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1627     this->Render(ren);
1628     return 1;
1629     }
1630   return 0;
1631 }
1632
1633
1634 void SMESH_ActorDef::Render(vtkRenderer *ren){
1635   unsigned long aTime = myTimeStamp->GetMTime();
1636   unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1637   unsigned long aClippingTime = myImplicitBoolean->GetMTime();
1638   if(anObjTime > aTime || aClippingTime > aTime)
1639     Update();
1640 }
1641
1642
1643 void SMESH_ActorDef::Update(){
1644   if(MYDEBUG) MESSAGE("SMESH_ActorDef::Update");
1645
1646   if(GetControlMode() != eNone) {
1647     unsigned long aTime = myTimeStamp->GetMTime();
1648     unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1649     if (anObjTime > aTime)
1650       SetControlMode(GetControlMode(),false);
1651   }
1652
1653   if(myNodeActor)
1654     myNodeActor->UpdateLabels();
1655
1656   if(my0DActor)
1657     my0DActor->UpdateLabels();
1658   
1659   if(my1DActor)
1660     my1DActor->UpdateLabels();
1661   
1662   if(my2DActor)
1663     my2DActor->UpdateLabels();
1664
1665   if(my3DActor)
1666     my3DActor->UpdateLabels();
1667   
1668   if(myIsFacesOriented){
1669     SetFacesOriented(myIsFacesOriented);
1670   }
1671     
1672   if(myVisualObj->GetEntitiesFlag()) {
1673     myEntityMode |= myVisualObj->GetEntitiesState();
1674   }
1675   
1676   SetEntityMode(GetEntityMode());
1677   SetVisibility(GetVisibility());
1678   
1679   myTimeStamp->Modified();
1680   Modified();
1681 }
1682
1683
1684 void SMESH_ActorDef::ReleaseGraphicsResources(vtkWindow *renWin){
1685   SALOME_Actor::ReleaseGraphicsResources(renWin);
1686
1687   myPickableActor->ReleaseGraphicsResources(renWin);
1688 }
1689
1690
1691 static void GetColor(vtkProperty *theProperty, vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1692   vtkFloatingPointType* aColor = theProperty->GetColor();
1693   r = aColor[0];
1694   g = aColor[1];
1695   b = aColor[2];
1696 }
1697
1698
1699 void SMESH_ActorDef::SetOpacity(vtkFloatingPointType theValue){
1700   mySurfaceProp->SetOpacity(theValue);
1701   myBackSurfaceProp->SetOpacity(theValue);
1702   myEdgeProp->SetOpacity(theValue);
1703   myNodeProp->SetOpacity(theValue);
1704
1705   my1DProp->SetOpacity(theValue);
1706 }
1707
1708
1709 vtkFloatingPointType SMESH_ActorDef::GetOpacity(){
1710   return mySurfaceProp->GetOpacity();
1711 }
1712
1713
1714 void SMESH_ActorDef::SetSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b, int delta){
1715   mySurfaceProp->SetColor(r,g,b);
1716   if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
1717     if( aGroupObj->GetElementType() == SMDSAbs_Face ||
1718         aGroupObj->GetElementType() == SMDSAbs_Volume )
1719       myNameActor->SetBackgroundColor(r,g,b);
1720   
1721   myDeltaBrightness = delta;
1722   QColor bfc = Qtx::mainColorToSecondary(QColor(int(r*255),int(g*255),int(b*255)), delta);
1723   myBackSurfaceProp->SetColor( bfc.red() / 255. , bfc.green() / 255. , bfc.blue() / 255. );
1724   Modified();
1725 }
1726
1727 void SMESH_ActorDef::GetSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b, int& delta){
1728   ::GetColor(mySurfaceProp,r,g,b);
1729   my2DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1730   delta = myDeltaBrightness;
1731 }
1732
1733 void SMESH_ActorDef::SetEdgeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1734   myEdgeProp->SetColor(r,g,b);
1735   my1DProp->SetColor(r,g,b);
1736   my1DExtProp->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_Edge )
1739       myNameActor->SetBackgroundColor(r,g,b);
1740   Modified();
1741 }
1742
1743 void SMESH_ActorDef::GetEdgeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1744   ::GetColor(myEdgeProp,r,g,b);
1745 }
1746
1747 void SMESH_ActorDef::SetOutlineColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1748   myOutLineProp->SetColor(r,g,b);
1749   Modified();
1750 }
1751
1752 void SMESH_ActorDef::GetOutlineColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1753   ::GetColor(myOutLineProp,r,g,b);
1754 }
1755
1756
1757 void SMESH_ActorDef::SetNodeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){ 
1758   myNodeProp->SetColor(r,g,b);
1759   myNodeExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1760   if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
1761     if( aGroupObj->GetElementType() == SMDSAbs_Node )
1762       myNameActor->SetBackgroundColor(r,g,b);
1763   Modified();
1764 }
1765
1766 void SMESH_ActorDef::GetNodeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){ 
1767   ::GetColor(myNodeProp,r,g,b);
1768 }
1769
1770 void SMESH_ActorDef::Set0DColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){ 
1771   my0DProp->SetColor(r,g,b);
1772   if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
1773     if( aGroupObj->GetElementType() == SMDSAbs_0DElement )
1774       myNameActor->SetBackgroundColor(r,g,b);
1775   Modified();
1776 }
1777
1778 void SMESH_ActorDef::Get0DColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){ 
1779   ::GetColor(my0DProp,r,g,b);
1780 }
1781
1782 void SMESH_ActorDef::SetHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){ 
1783   myHighlightProp->SetColor(r,g,b);
1784   Modified();
1785 }
1786
1787 void SMESH_ActorDef::GetHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){ 
1788   ::GetColor(myHighlightProp,r,g,b);
1789 }
1790
1791 void SMESH_ActorDef::SetPreHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){ 
1792   myPreselectProp->SetColor(r,g,b);
1793   Modified();
1794 }
1795
1796 void SMESH_ActorDef::GetPreHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){ 
1797   ::GetColor(myPreselectProp,r,g,b);
1798 }
1799
1800
1801 vtkFloatingPointType SMESH_ActorDef::GetLineWidth(){
1802   return myEdgeProp->GetLineWidth();
1803 }
1804
1805
1806 void SMESH_ActorDef::SetLineWidth(vtkFloatingPointType theVal){
1807   myEdgeProp->SetLineWidth(theVal);
1808
1809   my1DProp->SetLineWidth(theVal + aLineWidthInc);
1810   my1DExtProp->SetLineWidth(theVal + aLineWidthInc);
1811
1812   Modified();
1813 }
1814
1815
1816 void SMESH_ActorDef::Set0DSize(vtkFloatingPointType theVal){
1817   my0DProp->SetPointSize(theVal);
1818   Modified();
1819 }
1820
1821 vtkFloatingPointType SMESH_ActorDef::Get0DSize(){
1822   return my0DProp->GetPointSize();
1823 }
1824
1825 int SMESH_ActorDef::GetObjDimension( const int theObjId )
1826 {
1827   return myVisualObj->GetElemDimension( theObjId );
1828 }
1829
1830 bool
1831 SMESH_ActorDef::
1832 IsImplicitFunctionUsed() const
1833 {
1834   return myBaseActor->IsImplicitFunctionUsed();
1835 }
1836
1837 void
1838 SMESH_ActorDef::SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed)
1839 {
1840   myNodeActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1841   myBaseActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1842
1843   myHighlitableActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1844
1845   myNodeExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1846
1847   my0DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1848   //my0DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1849
1850   my1DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1851   my1DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1852
1853   my2DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1854   my2DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1855   my3DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1856   my3DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1857 }
1858
1859 vtkIdType 
1860 SMESH_ActorDef::AddClippingPlane(vtkPlane* thePlane)
1861 {
1862   if(thePlane){
1863     myImplicitBoolean->GetFunction()->AddItem(thePlane);
1864     myCippingPlaneCont.push_back(thePlane);
1865     if(!IsImplicitFunctionUsed())
1866       SetImplicitFunctionUsed(true);
1867     myNodeActor->UpdateLabels();
1868   }
1869   return myCippingPlaneCont.size();
1870 }
1871
1872 void
1873 SMESH_ActorDef::
1874 RemoveAllClippingPlanes()
1875 {
1876   myImplicitBoolean->GetFunction()->RemoveAllItems();
1877   myImplicitBoolean->GetFunction()->Modified(); // VTK bug
1878   myCippingPlaneCont.clear();
1879   SetImplicitFunctionUsed(false);
1880   myNodeActor->UpdateLabels();
1881 }
1882
1883 vtkIdType
1884 SMESH_ActorDef::
1885 GetNumberOfClippingPlanes()
1886 {
1887   return myCippingPlaneCont.size();
1888 }
1889
1890 vtkPlane* 
1891 SMESH_ActorDef::
1892 GetClippingPlane(vtkIdType theID)
1893 {
1894   if(theID >= myCippingPlaneCont.size())
1895     return NULL;
1896   return myCippingPlaneCont[theID].Get();
1897 }
1898
1899 void SMESH_ActorDef::UpdateScalarBar()
1900 {
1901   SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
1902   if( !mgr )
1903     return;
1904
1905   vtkTextProperty* aScalarBarTitleProp = vtkTextProperty::New();
1906
1907   QColor aTColor = mgr->colorValue( "SMESH", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
1908   aScalarBarTitleProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1909
1910   aScalarBarTitleProp->SetFontFamilyToArial();
1911
1912   if ( mgr->hasValue( "SMESH", "scalar_bar_title_font" ) )
1913   {
1914     QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
1915     if ( f.family() == "Arial" )
1916       aScalarBarTitleProp->SetFontFamilyToArial();
1917     else if ( f.family() == "Courier" )
1918       aScalarBarTitleProp->SetFontFamilyToCourier();
1919     else if ( f.family() == "Times" )
1920       aScalarBarTitleProp->SetFontFamilyToTimes();
1921
1922     if ( f.bold() )
1923       aScalarBarTitleProp->BoldOn();
1924     else
1925       aScalarBarTitleProp->BoldOff();
1926
1927     if ( f.italic() )
1928       aScalarBarTitleProp->ItalicOn();
1929     else
1930      aScalarBarTitleProp->ItalicOff();
1931
1932     if ( f.overline() )
1933       aScalarBarTitleProp->ShadowOn();
1934     else
1935       aScalarBarTitleProp->ShadowOff();
1936   }
1937
1938   myScalarBarActor->SetTitleTextProperty( aScalarBarTitleProp );
1939   aScalarBarTitleProp->Delete();
1940
1941   vtkTextProperty* aScalarBarLabelProp = vtkTextProperty::New();
1942
1943   aTColor = mgr->colorValue( "SMESH", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
1944   aScalarBarLabelProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1945
1946   aScalarBarLabelProp->SetFontFamilyToArial();
1947   if( mgr->hasValue( "SMESH", "scalar_bar_label_font" ) )
1948   {
1949     QFont f = mgr->fontValue( "SMESH", "scalar_bar_label_font" );
1950     if( f.family() == "Arial" )
1951       aScalarBarLabelProp->SetFontFamilyToArial();
1952     else if( f.family() == "Courier" )
1953       aScalarBarLabelProp->SetFontFamilyToCourier();
1954     else if( f.family() == "Times" )
1955       aScalarBarLabelProp->SetFontFamilyToTimes();
1956
1957     if ( f.bold() )
1958       aScalarBarLabelProp->BoldOn();
1959     else
1960       aScalarBarLabelProp->BoldOff();
1961
1962     if ( f.italic() )
1963       aScalarBarLabelProp->ItalicOn();
1964     else
1965       aScalarBarLabelProp->ItalicOff();
1966
1967     if( f.overline() )
1968       aScalarBarLabelProp->ShadowOn();
1969     else
1970       aScalarBarLabelProp->ShadowOff();
1971   }
1972
1973   myScalarBarActor->SetLabelTextProperty( aScalarBarLabelProp );
1974   aScalarBarLabelProp->Delete();
1975
1976   bool horiz = ( mgr->integerValue( "SMESH", "scalar_bar_orientation" ) == 1 );
1977   QString name = QString( "scalar_bar_%1_" ).arg( horiz ? "horizontal" : "vertical" );
1978   if( horiz )
1979     myScalarBarActor->SetOrientationToHorizontal();
1980   else
1981     myScalarBarActor->SetOrientationToVertical();
1982
1983
1984   vtkFloatingPointType aXVal = horiz ? 0.20 : 0.01;
1985   if( mgr->hasValue( "SMESH", name + "x" ) )
1986     aXVal = mgr->doubleValue( "SMESH", name + "x", aXVal );
1987
1988   vtkFloatingPointType aYVal = horiz ? 0.01 : 0.1;
1989   if( mgr->hasValue( "SMESH", name + "y" ) )
1990     aYVal = mgr->doubleValue( "SMESH", name + "y", aYVal );
1991   myScalarBarActor->SetPosition( aXVal, aYVal );
1992
1993   vtkFloatingPointType aWVal = horiz ? 0.60 : 0.10;
1994   if( mgr->hasValue( "SMESH", name + "width" ) )
1995     aWVal = mgr->doubleValue( "SMESH", name + "width", aWVal );
1996   myScalarBarActor->SetWidth( aWVal );
1997
1998   vtkFloatingPointType aHVal = horiz ? 0.12 : 0.80;
1999   if( mgr->hasValue( "SMESH", name + "height" ) )
2000     aHVal = mgr->doubleValue( "SMESH", name + "height", aHVal );
2001   myScalarBarActor->SetHeight( aHVal );
2002
2003   int anIntVal = 5;
2004   if( mgr->hasValue( "SMESH", "scalar_bar_num_labels" ) )
2005     anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_labels", anIntVal );
2006   myScalarBarActor->SetNumberOfLabels( anIntVal == 0 ? 5: anIntVal );
2007
2008   anIntVal = 64;
2009   if( mgr->hasValue( "SMESH", "scalar_bar_num_colors" ) )
2010     anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_colors", anIntVal );
2011   myScalarBarActor->SetMaximumNumberOfColors( anIntVal == 0 ? 64 : anIntVal );
2012
2013   bool distributionVisibility = mgr->booleanValue("SMESH","distribution_visibility");
2014   myScalarBarActor->SetDistributionVisibility(distributionVisibility);
2015
2016   int coloringType = mgr->integerValue("SMESH", "distribution_coloring_type", 0);
2017   myScalarBarActor->SetDistributionColoringType(coloringType);
2018   
2019   QColor distributionColor = mgr->colorValue("SMESH", "distribution_color",
2020                                              QColor(255, 255, 255));
2021   double rgb[3];
2022   rgb[0]= distributionColor.red()/255.;
2023   rgb[1]= distributionColor.green()/255.;
2024   rgb[2]= distributionColor.blue()/255.;
2025   myScalarBarActor->SetDistributionColor(rgb);
2026
2027   
2028 }
2029
2030 void SMESH_ActorDef::UpdateDistribution()
2031 {
2032   if(SMESH::Controls::NumericalFunctor* fun =
2033      dynamic_cast<SMESH::Controls::NumericalFunctor*>(myFunctor.get()))
2034   {
2035     int nbIntervals = myScalarBarActor->GetMaximumNumberOfColors();
2036     std::vector<int> nbEvents;
2037     std::vector<double> funValues;
2038     SMESH_VisualObjDef::TEntityList elems;
2039     if ( ! dynamic_cast<SMESH_MeshObj*>(myVisualObj.get()))
2040       dynamic_cast<SMESH_VisualObjDef*>(myVisualObj.get())->GetEntities( fun->GetType(), elems );
2041     std::vector<int> elemIds;
2042     for ( SMESH_VisualObjDef::TEntityList::iterator e = elems.begin(); e != elems.end(); ++e)
2043       elemIds.push_back( (*e)->GetID());
2044     vtkLookupTable* lookupTable = static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
2045     double * range = lookupTable->GetRange();
2046     fun->GetHistogram(nbIntervals, nbEvents, funValues, elemIds, range);
2047     myScalarBarActor->SetDistribution(nbEvents);
2048   }
2049 }
2050
2051 void SMESH_ActorDef::SetQuadratic2DRepresentation(EQuadratic2DRepresentation theMode)
2052 {
2053   switch(theMode) {
2054   case SMESH_Actor::eLines :
2055     myHighlitableActor->SetQuadraticArcMode(false);
2056     my2DActor->SetQuadraticArcMode(false);
2057     my1DActor->SetQuadraticArcMode(false);
2058     break;
2059   case SMESH_Actor::eArcs :
2060     myHighlitableActor->SetQuadraticArcMode(true);
2061     if(GetRepresentation() != SMESH_Actor::ePoint) {
2062       my2DActor->SetQuadraticArcMode(true);
2063       my1DActor->SetQuadraticArcMode(true);
2064     }
2065     break;
2066   default:
2067     break;
2068   }
2069 }
2070
2071
2072 SMESH_Actor::EQuadratic2DRepresentation SMESH_ActorDef::GetQuadratic2DRepresentation()
2073 {
2074   if(myHighlitableActor->GetQuadraticArcMode())
2075     return SMESH_Actor::eArcs;
2076   else
2077     return SMESH_Actor::eLines;
2078 }
2079
2080 void SMESH_ActorDef::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale )
2081 {
2082   SALOME_Actor::SetMarkerStd( theMarkerType, theMarkerScale );
2083   myNodeActor->SetMarkerStd( theMarkerType, theMarkerScale );
2084   myNodeExtActor->SetMarkerStd( theMarkerType, theMarkerScale );
2085 }
2086
2087 void SMESH_ActorDef::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
2088 {
2089   SALOME_Actor::SetMarkerTexture( theMarkerId, theMarkerTexture );
2090   myNodeActor->SetMarkerTexture( theMarkerId, theMarkerTexture );
2091   myNodeExtActor->SetMarkerTexture( theMarkerId, theMarkerTexture );
2092   myMarkerTexture = theMarkerTexture; // for deferred update of myHighlightActor
2093 }
2094
2095 #ifndef DISABLE_PLOT2DVIEWER
2096 SPlot2d_Histogram* SMESH_ActorDef::UpdatePlot2Histogram() {
2097
2098   if(my2dHistogram)
2099     my2dHistogram->clearAllPoints();
2100   
2101   if(SMESH::Controls::NumericalFunctor* fun =
2102      dynamic_cast<SMESH::Controls::NumericalFunctor*>(myFunctor.get()))
2103   {
2104     
2105     if(!my2dHistogram) {
2106       my2dHistogram = new SPlot2d_Histogram();
2107       Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(getIO()->getEntry(),"SMESH",getName());
2108       my2dHistogram->setIO(anIO);
2109     }
2110     
2111     int nbIntervals = myScalarBarActor->GetMaximumNumberOfColors();
2112     std::vector<int> nbEvents;
2113     std::vector<double> funValues;
2114     SMESH_VisualObjDef::TEntityList elems;
2115     if ( ! dynamic_cast<SMESH_MeshObj*>(myVisualObj.get()))
2116       dynamic_cast<SMESH_VisualObjDef*>(myVisualObj.get())->GetEntities( fun->GetType(), elems );
2117     std::vector<int> elemIds;
2118     
2119     for ( SMESH_VisualObjDef::TEntityList::iterator e = elems.begin(); e != elems.end(); ++e)
2120       elemIds.push_back( (*e)->GetID());
2121
2122     vtkLookupTable* lookupTable = static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
2123     double * range = lookupTable->GetRange();
2124     fun->GetHistogram(nbIntervals, nbEvents, funValues, elemIds, range);
2125
2126     for ( int i = 0; i < std::min( nbEvents.size(), funValues.size() -1 ); i++ ) 
2127       my2dHistogram->addPoint(funValues[i] + (funValues[i+1] - funValues[i])/2.0, static_cast<double>(nbEvents[i]));
2128
2129     if(funValues.size() >= 2)
2130       my2dHistogram->setWidth((funValues[1] - funValues[0]) * 0.8) ;
2131
2132   }
2133   
2134   //Color of the histogram
2135   if(myScalarBarActor->GetDistributionColoringType() == SMESH_MULTICOLOR_TYPE)
2136     my2dHistogram->setAutoAssign(true);
2137   else {
2138     double rgb[3];
2139     myScalarBarActor->GetDistributionColor(rgb);
2140     QColor aColor = QColor( (int)( rgb[0]*255 ), (int)( rgb[1]*255 ), (int)( rgb[2]*255 ) );
2141     my2dHistogram->setColor(aColor);
2142
2143   }
2144       
2145   return my2dHistogram;
2146 }
2147 #endif