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