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