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