Salome HOME
Merge from V5_1_3_BR branch (07/12/09)
[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("%d");
409 #else
410   myPtsLabeledDataMapper->SetLabelFormat("%g");
411 #endif
412   myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
413     
414   vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
415   aPtsTextProp->SetFontFamilyToTimes();
416   static int aPointsFontSize = 10;
417   aPtsTextProp->SetFontSize(aPointsFontSize);
418   aPtsTextProp->SetBold(1);
419   aPtsTextProp->SetItalic(0);
420   aPtsTextProp->SetShadow(0);
421   myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
422   aPtsTextProp->Delete();
423   
424   myEntityMode = eAllEntity;
425
426   myIsPointsLabeled = false;
427
428   myPointLabels = vtkActor2D::New();
429   myPointLabels->SetMapper(myPtsLabeledDataMapper);
430   myPointLabels->GetProperty()->SetColor(1,1,1);
431   myPointLabels->SetVisibility(myIsPointsLabeled);
432
433
434   //Definition of cells numbering pipeline
435   //---------------------------------------
436   myCellsNumDataSet = vtkUnstructuredGrid::New();
437
438   myCellCenters = vtkCellCenters::New();
439   myCellCenters->SetInput(myCellsNumDataSet);
440
441   myClsMaskPoints = vtkMaskPoints::New();
442   myClsMaskPoints->SetInput(myCellCenters->GetOutput());
443   myClsMaskPoints->SetOnRatio(1);
444     
445   myClsSelectVisiblePoints = vtkSelectVisiblePoints::New();
446   myClsSelectVisiblePoints->SetInput(myClsMaskPoints->GetOutput());
447   myClsSelectVisiblePoints->SelectInvisibleOff();
448   myClsSelectVisiblePoints->SetTolerance(0.1);
449     
450   myClsLabeledDataMapper = vtkLabeledDataMapper::New();
451   myClsLabeledDataMapper->SetInput(myClsSelectVisiblePoints->GetOutput());
452 #if (VTK_XVERSION >= 0x050200)
453   myClsLabeledDataMapper->SetLabelFormat("%d");
454 #else
455   myClsLabeledDataMapper->SetLabelFormat("%g");
456 #endif
457   myClsLabeledDataMapper->SetLabelModeToLabelScalars();
458     
459   vtkTextProperty* aClsTextProp = vtkTextProperty::New();
460   aClsTextProp->SetFontFamilyToTimes();
461   static int aCellsFontSize = 12;
462   aClsTextProp->SetFontSize(aCellsFontSize);
463   aClsTextProp->SetBold(1);
464   aClsTextProp->SetItalic(0);
465   aClsTextProp->SetShadow(0);
466   myClsLabeledDataMapper->SetLabelTextProperty(aClsTextProp);
467   aClsTextProp->Delete();
468     
469   myIsCellsLabeled = false;
470
471   myCellsLabels = vtkActor2D::New();
472   myCellsLabels->SetMapper(myClsLabeledDataMapper);
473   myCellsLabels->GetProperty()->SetColor(0,1,0);
474   myCellsLabels->SetVisibility(myIsCellsLabeled);
475
476   // Clipping planes
477   myImplicitBoolean = vtkImplicitBoolean::New();
478   myImplicitBoolean->SetOperationTypeToIntersection();
479   
480
481
482   //Quadratic 2D elements representation
483   //-----------------------------------------------------------------------------
484   int aQuadratic2DMode = mgr->integerValue( "SMESH", "quadratic_mode", 0);
485   if(aQuadratic2DMode == 0){
486     myHighlitableActor->SetQuadraticArcMode(false);
487     my2DActor->SetQuadraticArcMode(false);
488     my1DActor->SetQuadraticArcMode(false);
489   }
490   else if(aQuadratic2DMode == 1){
491     myHighlitableActor->SetQuadraticArcMode(true);
492     my2DActor->SetQuadraticArcMode(true);
493     my1DActor->SetQuadraticArcMode(true);
494   }
495   
496   int aQuadraticAngle = mgr->integerValue( "SMESH", "max_angle", 2);
497   myHighlitableActor->SetQuadraticArcAngle(aQuadraticAngle);
498   my2DActor->SetQuadraticArcAngle(aQuadraticAngle);
499   
500   // Set color of the name actor
501   SMESH::GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
502   myNameActor->SetBackgroundColor(anRGB[0], anRGB[1], anRGB[2]);
503 }
504
505
506 SMESH_ActorDef::~SMESH_ActorDef()
507 {
508   if(MYDEBUG) MESSAGE("~SMESH_ActorDef - "<<this);
509
510   myScalarBarActor->Delete();
511   myLookupTable->Delete();
512
513   mySurfaceProp->Delete();
514   myBackSurfaceProp->Delete();
515
516   myEdgeProp->Delete();
517   myHighlightProp->Delete();
518   myPreselectProp->Delete();
519
520   myNodeProp->Delete();
521   myNodeExtProp->Delete();
522  
523   my0DProp->Delete();
524   my0DActor->Delete();
525
526   //my0DExtProp->Delete();
527   //my0DExtActor->Delete();
528  
529   my1DProp->Delete();
530   my1DActor->Delete();
531
532   my1DExtProp->Delete();
533   my1DExtActor->Delete();
534
535   my2DActor->Delete();
536   my2DExtProp->Delete();
537   my2DExtActor->Delete();
538   my3DActor->Delete();
539
540   myNodeActor->Delete();
541   myBaseActor->Delete();
542
543   myNodeExtActor->Delete();
544   
545   myHighlitableActor->Delete();
546
547   //Deleting of points numbering pipeline
548   //---------------------------------------
549   myPointsNumDataSet->Delete();
550
551   // commented: porting to vtk 5.0
552   //  myPtsLabeledDataMapper->RemoveAllInputs();
553   myPtsLabeledDataMapper->Delete();
554
555   // commented: porting to vtk 5.0
556   //  myPtsSelectVisiblePoints->UnRegisterAllOutputs();
557   myPtsSelectVisiblePoints->Delete();
558
559   // commented: porting to vtk 5.0
560   //  myPtsMaskPoints->UnRegisterAllOutputs();
561   myPtsMaskPoints->Delete();
562
563   myPointLabels->Delete();
564
565
566   //Deleting of cells numbering pipeline
567   //---------------------------------------
568   myCellsNumDataSet->Delete();
569
570   myClsLabeledDataMapper->RemoveAllInputs();
571   myClsLabeledDataMapper->Delete();
572
573   // commented: porting to vtk 5.0
574   //  myClsSelectVisiblePoints->UnRegisterAllOutputs();
575   myClsSelectVisiblePoints->Delete();
576
577   // commented: porting to vtk 5.0
578   //  myClsMaskPoints->UnRegisterAllOutputs();
579   myClsMaskPoints->Delete();
580
581   // commented: porting to vtk 5.0
582   //  myCellCenters->UnRegisterAllOutputs();
583   myCellCenters->Delete();
584
585   myCellsLabels->Delete();
586
587   myImplicitBoolean->Delete();
588
589   myTimeStamp->Delete();
590 }
591
592
593 void SMESH_ActorDef::SetPointsLabeled( bool theIsPointsLabeled )
594 {    
595   vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
596     
597   myIsPointsLabeled = theIsPointsLabeled && aGrid->GetNumberOfPoints();
598
599   if ( myIsPointsLabeled )
600   {
601     myPointsNumDataSet->ShallowCopy(aGrid);
602     vtkDataSet *aDataSet = myPointsNumDataSet;
603     
604     int aNbElem = aDataSet->GetNumberOfPoints();
605     
606     vtkIntArray *anArray = vtkIntArray::New();
607     anArray->SetNumberOfValues( aNbElem );
608     
609     for ( vtkIdType anId = 0; anId < aNbElem; anId++ )
610     {
611       int aSMDSId = myVisualObj->GetNodeObjId( anId );
612       anArray->SetValue( anId, aSMDSId );
613     }
614     
615     aDataSet->GetPointData()->SetScalars( anArray );
616     anArray->Delete();
617     myPtsMaskPoints->SetInput( aDataSet );
618     myPointLabels->SetVisibility( GetVisibility() );
619   }
620   else
621   {
622     myPointLabels->SetVisibility( false );
623   }
624   SetRepresentation(GetRepresentation());
625   myTimeStamp->Modified();
626 }
627
628
629 void SMESH_ActorDef::SetCellsLabeled(bool theIsCellsLabeled)
630 {
631   vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
632   myIsCellsLabeled = theIsCellsLabeled && aGrid->GetNumberOfPoints();
633   if(myIsCellsLabeled){
634     myCellsNumDataSet->ShallowCopy(aGrid);
635     vtkDataSet *aDataSet = myCellsNumDataSet;
636     int aNbElem = aDataSet->GetNumberOfCells();
637     vtkIntArray *anArray = vtkIntArray::New();
638     anArray->SetNumberOfValues(aNbElem);
639     for(int anId = 0; anId < aNbElem; anId++){
640       int aSMDSId = myVisualObj->GetElemObjId(anId);
641       anArray->SetValue(anId,aSMDSId);
642     }
643     aDataSet->GetCellData()->SetScalars(anArray);
644     myCellCenters->SetInput(aDataSet);
645     myCellsLabels->SetVisibility(GetVisibility());
646   }else{
647     myCellsLabels->SetVisibility(false);
648   }
649   myTimeStamp->Modified();
650 }
651
652
653 void SMESH_ActorDef::SetFacesOriented(bool theIsFacesOriented)
654 {
655   myIsFacesOriented = theIsFacesOriented;
656
657   my2DActor->SetFacesOriented(theIsFacesOriented);
658   my3DActor->SetFacesOriented(theIsFacesOriented);
659
660   myTimeStamp->Modified();
661 }
662
663 bool SMESH_ActorDef::GetFacesOriented()
664 {
665   return myIsFacesOriented;
666 }
667
668
669 void 
670 SMESH_ActorDef::
671 SetControlMode(eControl theMode)
672 {
673   SetControlMode(theMode,true);
674 }
675
676
677 void 
678 SMESH_ActorDef::
679 SetControlMode(eControl theMode,
680                bool theCheckEntityMode)
681 {
682   SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();  
683   if( !mgr )
684     return;
685
686   myControlMode = eNone;
687   theCheckEntityMode &= mgr->booleanValue( "SMESH", "display_entity", false );
688
689   my0DActor->GetMapper()->SetScalarVisibility(false);
690   my1DActor->GetMapper()->SetScalarVisibility(false);
691   my2DActor->GetMapper()->SetScalarVisibility(false);
692   my3DActor->GetMapper()->SetScalarVisibility(false);
693   myScalarBarActor->SetVisibility(false);
694
695   bool anIsScalarVisible = theMode > eNone;
696
697   if(anIsScalarVisible){
698     SMESH::Controls::FunctorPtr aFunctor;
699     switch(theMode){
700     case eLength:
701     {
702       SMESH::Controls::Length* aControl = new SMESH::Controls::Length();
703       aControl->SetPrecision( myControlsPrecision );
704       aFunctor.reset( aControl );
705       myControlActor = my1DActor;
706       break;
707     }
708     case eLength2D:
709     {
710       aFunctor.reset(new SMESH::Controls::Length2D());
711       myControlActor = my2DActor;
712       break;
713     }
714     case eFreeBorders:
715       aFunctor.reset(new SMESH::Controls::FreeBorders());
716       myControlActor = my1DActor;
717       break;
718     case eFreeEdges:
719       aFunctor.reset(new SMESH::Controls::FreeEdges());
720       myControlActor = my2DActor;
721       break;
722     case eFreeNodes:
723       aFunctor.reset(new SMESH::Controls::FreeNodes());
724       myControlActor = myNodeActor;
725       break;
726     case eFreeFaces:
727       aFunctor.reset(new SMESH::Controls::FreeFaces());
728       myControlActor = my2DActor;
729       break;
730     case eMultiConnection:
731       aFunctor.reset(new SMESH::Controls::MultiConnection());
732       myControlActor = my1DActor;
733       break;
734     case eMultiConnection2D:
735       aFunctor.reset(new SMESH::Controls::MultiConnection2D());
736       myControlActor = my2DActor;
737       break;
738     case eArea:
739     {
740       SMESH::Controls::Area* aControl = new SMESH::Controls::Area();
741       aControl->SetPrecision( myControlsPrecision );
742       aFunctor.reset( aControl );
743       myControlActor = my2DActor;
744       break;
745     }
746     case eTaper:
747     {
748       SMESH::Controls::Taper* aControl = new SMESH::Controls::Taper();
749       aControl->SetPrecision( myControlsPrecision );
750       aFunctor.reset( aControl );
751       myControlActor = my2DActor;
752       break;
753     }
754     case eAspectRatio:
755     {
756       SMESH::Controls::AspectRatio* aControl = new SMESH::Controls::AspectRatio();
757       aControl->SetPrecision( myControlsPrecision );
758       aFunctor.reset( aControl );
759       myControlActor = my2DActor;
760       break;
761     }
762     case eAspectRatio3D:
763     {
764       SMESH::Controls::AspectRatio3D* aControl = new SMESH::Controls::AspectRatio3D();
765       aControl->SetPrecision( myControlsPrecision );
766       aFunctor.reset( aControl );
767       myControlActor = my3DActor;
768       break;
769     }
770     case eVolume3D:
771     {
772       SMESH::Controls::Volume* aControl = new SMESH::Controls::Volume();
773       aControl->SetPrecision( myControlsPrecision );
774       aFunctor.reset( aControl );
775       myControlActor = my3DActor;
776       break;
777     }
778     case eMinimumAngle:
779     {
780       SMESH::Controls::MinimumAngle* aControl = new SMESH::Controls::MinimumAngle();
781       aControl->SetPrecision( myControlsPrecision );
782       aFunctor.reset( aControl );
783       myControlActor = my2DActor;
784       break;
785     }
786     case eWarping:
787     {
788       SMESH::Controls::Warping* aControl = new SMESH::Controls::Warping();
789       aControl->SetPrecision( myControlsPrecision );
790       aFunctor.reset( aControl );
791       myControlActor = my2DActor;
792       break;
793     }
794     case eSkew:
795     {
796       SMESH::Controls::Skew* aControl = new SMESH::Controls::Skew();
797       aControl->SetPrecision( myControlsPrecision );
798       aFunctor.reset( aControl );
799       myControlActor = my2DActor;
800       break;
801     }
802     default:
803       return;
804     }
805
806     vtkUnstructuredGrid* aGrid = myControlActor->GetUnstructuredGrid();
807     vtkIdType aNbCells = aGrid->GetNumberOfCells();
808     if(aNbCells){
809       myControlMode = theMode;
810       switch(myControlMode){
811       case eFreeNodes:
812         myNodeExtActor->SetExtControlMode(aFunctor);
813         break;
814       case eFreeEdges:
815       case eFreeBorders:
816         my1DExtActor->SetExtControlMode(aFunctor);
817         break;
818       case eFreeFaces:
819         my2DExtActor->SetExtControlMode(aFunctor);
820         break;
821       case eLength2D:
822       case eMultiConnection2D:
823         my1DExtActor->SetExtControlMode(aFunctor,myScalarBarActor,myLookupTable);
824         break;
825       default:
826         myControlActor->SetControlMode(aFunctor,myScalarBarActor,myLookupTable);
827       }
828     }
829
830     if(theCheckEntityMode){
831       if(myControlActor == my1DActor)
832         SetEntityMode(eEdges);
833       else if(myControlActor == my2DActor){
834         switch(myControlMode){
835         case eLength2D:
836         case eFreeEdges:
837         case eFreeFaces:
838         case eMultiConnection2D:
839           //SetEntityMode(eEdges);
840           SetEntityMode(eFaces);
841           break;
842         default:
843           SetEntityMode(eFaces);
844         }
845       }else if(myControlActor == my3DActor)
846         SetEntityMode(eVolumes);
847     }
848
849   }else if(theCheckEntityMode){
850     myEntityMode = eAllEntity;
851   }
852
853   SetRepresentation(GetRepresentation());
854
855   myTimeStamp->Modified();
856   Modified();
857 }
858
859
860 void SMESH_ActorDef::AddToRender(vtkRenderer* theRenderer){
861   SALOME_Actor::AddToRender(theRenderer);
862
863   theRenderer->AddActor(myNodeActor);
864   theRenderer->AddActor(myBaseActor);
865   
866   theRenderer->AddActor(myNodeExtActor);
867
868   my3DActor->AddToRender(theRenderer);
869   my2DActor->AddToRender(theRenderer);
870   my2DExtActor->AddToRender(theRenderer);
871
872   theRenderer->AddActor(my1DActor);
873   theRenderer->AddActor(my1DExtActor);
874
875   theRenderer->AddActor(my0DActor);
876   //theRenderer->AddActor(my0DExtActor);
877
878   theRenderer->AddActor(myHighlitableActor);
879   
880   theRenderer->AddActor2D(myScalarBarActor);
881
882   myPtsSelectVisiblePoints->SetRenderer(theRenderer);
883   myClsSelectVisiblePoints->SetRenderer(theRenderer);
884
885   theRenderer->AddActor2D(myPointLabels);
886   theRenderer->AddActor2D(myCellsLabels);
887 }
888
889 void SMESH_ActorDef::RemoveFromRender(vtkRenderer* theRenderer){
890   SALOME_Actor::RemoveFromRender(theRenderer);
891
892   theRenderer->RemoveActor(myNodeActor);
893   theRenderer->RemoveActor(myBaseActor);
894
895   theRenderer->RemoveActor(myNodeExtActor);
896
897   theRenderer->RemoveActor(myHighlitableActor);
898
899   theRenderer->RemoveActor(my0DActor);
900   //theRenderer->RemoveActor(my0DExtActor);
901
902   theRenderer->RemoveActor(my1DActor);
903   theRenderer->RemoveActor(my1DExtActor);
904
905   my2DActor->RemoveFromRender(theRenderer);
906   my2DExtActor->RemoveFromRender(theRenderer);
907   my3DActor->RemoveFromRender(theRenderer);
908
909   theRenderer->RemoveActor(myScalarBarActor);
910   theRenderer->RemoveActor(myPointLabels);
911   theRenderer->RemoveActor(myCellsLabels);
912 }
913
914
915 bool SMESH_ActorDef::Init(TVisualObjPtr theVisualObj, 
916                           const char* theEntry, 
917                           const char* theName,
918                           int theIsClear)
919 {
920   Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry,"SMESH",theName);
921   setIO(anIO);
922   setName(theName);
923
924   myVisualObj = theVisualObj;
925   myVisualObj->Update(theIsClear);
926
927   myNodeActor->Init(myVisualObj,myImplicitBoolean);
928   myBaseActor->Init(myVisualObj,myImplicitBoolean);
929
930   myHighlitableActor->Init(myVisualObj,myImplicitBoolean);
931
932   myNodeExtActor->Init(myVisualObj,myImplicitBoolean);
933   
934   my0DActor->Init(myVisualObj,myImplicitBoolean);
935   //my0DExtActor->Init(myVisualObj,myImplicitBoolean);
936   
937   my1DActor->Init(myVisualObj,myImplicitBoolean);
938   my1DExtActor->Init(myVisualObj,myImplicitBoolean);
939   
940   my2DActor->Init(myVisualObj,myImplicitBoolean);
941   my2DExtActor->Init(myVisualObj,myImplicitBoolean);
942   my3DActor->Init(myVisualObj,myImplicitBoolean);
943   
944   my0DActor->GetMapper()->SetLookupTable(myLookupTable);
945   //my0DExtActor->GetMapper()->SetLookupTable(myLookupTable);
946   
947   my1DActor->GetMapper()->SetLookupTable(myLookupTable);
948   my1DExtActor->GetMapper()->SetLookupTable(myLookupTable);
949
950   my2DActor->GetMapper()->SetLookupTable(myLookupTable);
951   my2DExtActor->GetMapper()->SetLookupTable(myLookupTable);
952   my3DActor->GetMapper()->SetLookupTable(myLookupTable);
953     
954   vtkFloatingPointType aFactor, aUnits;
955   my2DActor->GetPolygonOffsetParameters(aFactor,aUnits);
956   my2DActor->SetPolygonOffsetParameters(aFactor,aUnits*0.75);
957   my2DExtActor->SetPolygonOffsetParameters(aFactor,aUnits*0.5);
958
959   SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
960   if( !mgr )
961     return false;
962
963   //SetIsShrunkable(theGrid->GetNumberOfCells() > 10);
964   SetIsShrunkable(true);
965
966   SetShrinkFactor( SMESH::GetFloat( "SMESH:shrink_coeff", 75 ) / 100. );
967
968   int aMode = mgr->integerValue( "SMESH", "display_mode" );
969   SetRepresentation(-1);
970   
971   if(aMode == 0){
972     SetRepresentation(eEdge);
973   }else if(aMode == 1){
974     SetRepresentation(eSurface);
975   }else if(aMode == 2){
976     SetRepresentation(ePoint);
977   }
978   
979   if(aMode == 3){
980     SetShrink();
981   }
982
983   if( dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
984     SetIsDisplayNameActor( true );
985
986   myTimeStamp->Modified();
987   Modified();
988   return true;
989 }
990
991
992 vtkFloatingPointType* SMESH_ActorDef::GetBounds(){
993   return myNodeActor->GetBounds();
994 }
995
996
997 vtkDataSet* SMESH_ActorDef::GetInput(){
998   return GetUnstructuredGrid();
999 }
1000
1001
1002 void SMESH_ActorDef::SetTransform(VTKViewer_Transform* theTransform){
1003   Superclass::SetTransform(theTransform);
1004
1005   myNodeActor->SetTransform(theTransform);
1006   myBaseActor->SetTransform(theTransform);
1007   
1008   myHighlitableActor->SetTransform(theTransform);
1009
1010   myNodeExtActor->SetTransform(theTransform);
1011
1012   my0DActor->SetTransform(theTransform);
1013   //my0DExtActor->SetTransform(theTransform);
1014
1015   my1DActor->SetTransform(theTransform);
1016   my1DExtActor->SetTransform(theTransform);
1017
1018   my2DActor->SetTransform(theTransform);
1019   my2DExtActor->SetTransform(theTransform);
1020   my3DActor->SetTransform(theTransform);
1021
1022   Modified();
1023 }
1024
1025
1026 void SMESH_ActorDef::SetMapper(vtkMapper* theMapper){
1027   vtkLODActor::SetMapper(theMapper);
1028 }
1029
1030
1031 void SMESH_ActorDef::ShallowCopy(vtkProp *prop){
1032   SALOME_Actor::ShallowCopy(prop);
1033 }
1034
1035
1036 vtkMapper* SMESH_ActorDef::GetMapper(){
1037   return myPickableActor->GetMapper();
1038 }
1039
1040
1041 vtkUnstructuredGrid* SMESH_ActorDef::GetUnstructuredGrid(){ 
1042   return myVisualObj->GetUnstructuredGrid();
1043 }
1044
1045
1046 bool SMESH_ActorDef::IsInfinitive(){
1047   vtkDataSet *aDataSet = myPickableActor->GetUnstructuredGrid();
1048   aDataSet->Update();
1049   myIsInfinite = aDataSet->GetNumberOfCells() == 0 ||
1050     ( aDataSet->GetNumberOfCells() == 1 && 
1051     aDataSet->GetCell(0)->GetCellType() == VTK_VERTEX );
1052   return SALOME_Actor::IsInfinitive();
1053 }
1054
1055
1056 void SMESH_ActorDef::SetIsShrunkable(bool theShrunkable){
1057   if ( myIsShrinkable == theShrunkable )
1058     return;
1059   myIsShrinkable = theShrunkable;
1060   Modified();
1061 }
1062
1063 vtkFloatingPointType SMESH_ActorDef::GetShrinkFactor(){
1064   return myBaseActor->GetShrinkFactor();
1065 }
1066
1067 void SMESH_ActorDef::SetShrinkFactor(vtkFloatingPointType theValue){
1068   myBaseActor->SetShrinkFactor(theValue);
1069
1070   my1DActor->SetShrinkFactor(theValue);
1071   my1DExtActor->SetShrinkFactor(theValue);
1072
1073   my2DActor->SetShrinkFactor(theValue);
1074   my2DExtActor->SetShrinkFactor(theValue);
1075   my3DActor->SetShrinkFactor(theValue);
1076
1077   Modified();
1078 }
1079
1080 void SMESH_ActorDef::SetShrink(){
1081   if(!myIsShrinkable) return;
1082
1083   myBaseActor->SetShrink();
1084
1085   my1DActor->SetShrink();
1086   my1DExtActor->SetShrink();
1087
1088   my2DActor->SetShrink();
1089   my2DExtActor->SetShrink();
1090   my3DActor->SetShrink();
1091
1092   myIsShrunk = true;
1093   Modified();
1094 }
1095
1096 void SMESH_ActorDef::UnShrink(){
1097   if(!myIsShrunk) return;
1098
1099   myBaseActor->UnShrink();
1100
1101   my1DActor->UnShrink();
1102   my1DExtActor->UnShrink();
1103
1104   my2DActor->UnShrink();
1105   my2DExtActor->UnShrink();
1106   my3DActor->UnShrink();
1107
1108   myIsShrunk = false;
1109   Modified();
1110 }
1111
1112
1113 int SMESH_ActorDef::GetNodeObjId(int theVtkID){
1114   return myPickableActor->GetNodeObjId(theVtkID);
1115 }
1116
1117 vtkFloatingPointType* SMESH_ActorDef::GetNodeCoord(int theObjID){
1118   return myPickableActor->GetNodeCoord(theObjID);
1119 }
1120
1121
1122 int SMESH_ActorDef::GetElemObjId(int theVtkID){
1123   return myPickableActor->GetElemObjId(theVtkID);
1124 }
1125
1126 vtkCell* SMESH_ActorDef::GetElemCell(int theObjID){
1127   return myPickableActor->GetElemCell(theObjID);
1128 }
1129
1130
1131 void SMESH_ActorDef::SetVisibility(int theMode){
1132   SetVisibility(theMode,true);
1133 }
1134
1135
1136 void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation){
1137   SALOME_Actor::SetVisibility(theMode);
1138
1139   myNodeActor->VisibilityOff();
1140   myBaseActor->VisibilityOff();
1141   
1142   myNodeExtActor->VisibilityOff();
1143
1144   my0DActor->VisibilityOff();
1145   //my0DExtActor->VisibilityOff();
1146
1147   my1DActor->VisibilityOff();
1148   my1DExtActor->VisibilityOff();
1149   
1150   my2DActor->VisibilityOff();
1151   my2DExtActor->VisibilityOff();
1152   my3DActor->VisibilityOff();
1153   
1154   myScalarBarActor->VisibilityOff();
1155   myPointLabels->VisibilityOff();
1156   myCellsLabels->VisibilityOff();
1157   
1158   if(GetVisibility()){
1159     if(theIsUpdateRepersentation)
1160       SetRepresentation(GetRepresentation());
1161     
1162     if(myControlMode != eNone){
1163       switch(myControlMode){
1164       case eFreeNodes:
1165         myNodeExtActor->VisibilityOn();
1166         break;
1167       case eFreeEdges:
1168       case eFreeBorders:
1169         my1DExtActor->VisibilityOn();
1170         break;
1171       case eFreeFaces:
1172         my2DExtActor->VisibilityOn();
1173         break;
1174       case eLength2D:
1175       case eMultiConnection2D:
1176         my1DExtActor->VisibilityOn();
1177       default:
1178         if(myControlActor->GetUnstructuredGrid()->GetNumberOfCells())
1179           myScalarBarActor->VisibilityOn();
1180       }
1181     }
1182
1183     if(myRepresentation != ePoint)
1184       myPickableActor->VisibilityOn();
1185     else {
1186       myNodeActor->VisibilityOn();
1187     }
1188
1189     if(myEntityMode & e0DElements){
1190       my0DActor->VisibilityOn();
1191     }
1192
1193     if(myEntityMode & eEdges){
1194       my1DActor->VisibilityOn();
1195     }
1196     
1197     if(myEntityMode & eFaces){
1198       my2DActor->VisibilityOn();
1199     }
1200     
1201     if(myEntityMode & eVolumes){
1202       my3DActor->VisibilityOn();
1203     }
1204     
1205     if(myIsPointsLabeled){ 
1206       myPointLabels->VisibilityOn();
1207       myNodeActor->VisibilityOn();
1208     }
1209
1210     if(myIsCellsLabeled) 
1211       myCellsLabels->VisibilityOn();
1212   }
1213   UpdateHighlight();
1214   Modified();
1215 }
1216
1217
1218 void SMESH_ActorDef::SetEntityMode(unsigned int theMode)
1219 {
1220   myEntityState = eAllEntity;
1221
1222   if(!myVisualObj->GetNbEntities(SMDSAbs_0DElement)) {
1223     myEntityState &= ~e0DElements;
1224     theMode &= ~e0DElements;
1225   }
1226
1227   if(!myVisualObj->GetNbEntities(SMDSAbs_Edge)) {
1228     myEntityState &= ~eEdges;
1229     theMode &= ~eEdges;
1230   }
1231
1232   if(!myVisualObj->GetNbEntities(SMDSAbs_Face)) {
1233     myEntityState &= ~eFaces;
1234     theMode &= ~eFaces;
1235   }
1236
1237   if(!myVisualObj->GetNbEntities(SMDSAbs_Volume)) {
1238     myEntityState &= ~eVolumes;
1239     theMode &= ~eVolumes;
1240   }
1241
1242   if (!theMode) {
1243     if(myVisualObj->GetNbEntities(SMDSAbs_0DElement))
1244       theMode |= e0DElements;
1245
1246     if(myVisualObj->GetNbEntities(SMDSAbs_Edge))
1247       theMode |= eEdges;
1248
1249     if(myVisualObj->GetNbEntities(SMDSAbs_Face))
1250       theMode |= eFaces;
1251
1252     if(myVisualObj->GetNbEntities(SMDSAbs_Volume))
1253       theMode |= eVolumes;
1254   }
1255
1256   myBaseActor->myGeomFilter->SetInside(myEntityMode != myEntityState);
1257
1258   myEntityMode = theMode;
1259   VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
1260   aFilter = myBaseActor->GetExtractUnstructuredGrid();
1261   aFilter->ClearRegisteredCellsWithType();
1262   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
1263
1264   VTKViewer_ExtractUnstructuredGrid* aHightFilter = myHighlitableActor->GetExtractUnstructuredGrid();
1265   aHightFilter->ClearRegisteredCellsWithType();
1266
1267   // The following row has been commented (initially added in 1.28.2.3.1 revision)
1268   // Reason: seems to be unnecessary, this filter should always have default (ePassAll) mode of changing
1269   // In addition, it leads to exception (see bug IPAL21372)
1270   //aHightFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
1271
1272   if (myEntityMode & e0DElements) {
1273     if (MYDEBUG) MESSAGE("0D ELEMENTS");
1274     aFilter->RegisterCellsWithType(VTK_VERTEX);
1275     aHightFilter->RegisterCellsWithType(VTK_VERTEX);
1276   }
1277
1278   if (myEntityMode & eEdges) {
1279     if (MYDEBUG) MESSAGE("EDGES");
1280     aFilter->RegisterCellsWithType(VTK_LINE);
1281     aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
1282
1283     aHightFilter->RegisterCellsWithType(VTK_LINE);
1284     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
1285   }
1286
1287   if (myEntityMode & eFaces) {
1288     if (MYDEBUG) MESSAGE("FACES");
1289     aFilter->RegisterCellsWithType(VTK_TRIANGLE);
1290     aFilter->RegisterCellsWithType(VTK_POLYGON);
1291     aFilter->RegisterCellsWithType(VTK_QUAD);
1292     aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
1293     aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
1294
1295     aHightFilter->RegisterCellsWithType(VTK_TRIANGLE);
1296     aHightFilter->RegisterCellsWithType(VTK_POLYGON);
1297     aHightFilter->RegisterCellsWithType(VTK_QUAD);
1298     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
1299     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
1300   }
1301
1302   if (myEntityMode & eVolumes) {
1303     if (MYDEBUG) MESSAGE("VOLUMES");
1304     aFilter->RegisterCellsWithType(VTK_TETRA);
1305     aFilter->RegisterCellsWithType(VTK_VOXEL);
1306     aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1307     aFilter->RegisterCellsWithType(VTK_WEDGE);
1308     aFilter->RegisterCellsWithType(VTK_PYRAMID);
1309     aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
1310     aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
1311     aFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
1312     aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1313     
1314     aHightFilter->RegisterCellsWithType(VTK_TETRA);
1315     aHightFilter->RegisterCellsWithType(VTK_VOXEL);
1316     aHightFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1317     aHightFilter->RegisterCellsWithType(VTK_WEDGE);
1318     aHightFilter->RegisterCellsWithType(VTK_PYRAMID);
1319     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
1320     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
1321     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
1322     aHightFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1323   }
1324   aFilter->Update();
1325   if (MYDEBUG) MESSAGE(aFilter->GetOutput()->GetNumberOfCells());
1326   SetVisibility(GetVisibility(),false);
1327 }
1328
1329 void SMESH_ActorDef::SetRepresentation (int theMode)
1330
1331   int aNbEdges = myVisualObj->GetNbEntities(SMDSAbs_Edge);
1332   int aNbFaces = myVisualObj->GetNbEntities(SMDSAbs_Face);
1333   int aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume);
1334
1335   if (theMode < 0) {
1336     myRepresentation = eSurface;
1337     if (!aNbFaces && !aNbVolumes && aNbEdges) {
1338       myRepresentation = eEdge;
1339     } else if (!aNbFaces && !aNbVolumes && !aNbEdges) {
1340       myRepresentation = ePoint;
1341     }
1342   } else {
1343     switch (theMode) {
1344     case eEdge:
1345       if (!aNbFaces && !aNbVolumes && !aNbEdges) return;
1346       break;
1347     case eSurface:
1348       if (!aNbFaces && !aNbVolumes) return;
1349       break;
1350     }    
1351     myRepresentation = theMode;
1352   }
1353
1354   if (!GetUnstructuredGrid()->GetNumberOfCells())
1355     myRepresentation = ePoint;
1356
1357   if (myIsShrunk) {
1358     if (myRepresentation == ePoint) {
1359       UnShrink();
1360       myIsShrunk = true;
1361     } else {
1362       SetShrink();
1363     }      
1364   }
1365
1366   myPickableActor = myBaseActor;
1367   myNodeActor->SetVisibility(false);
1368   myNodeExtActor->SetVisibility(false);
1369   vtkProperty *aProp = NULL, *aBackProp = NULL;
1370   SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::EReperesent(-1);
1371   SMESH_Actor::EQuadratic2DRepresentation aQuadraticMode = GetQuadratic2DRepresentation();
1372   switch (myRepresentation) {
1373   case ePoint:
1374     myPickableActor = myNodeActor;
1375     myNodeActor->SetVisibility(true);
1376     aQuadraticMode = SMESH_Actor::eLines;
1377     aProp = aBackProp = myNodeProp;
1378     aReperesent = SMESH_DeviceActor::ePoint;
1379     break;
1380   case eEdge:
1381     aProp = aBackProp = myEdgeProp;
1382     aReperesent = SMESH_DeviceActor::eInsideframe;
1383     break;
1384   case eSurface:
1385     aProp = mySurfaceProp;
1386     aBackProp = myBackSurfaceProp;
1387     aReperesent = SMESH_DeviceActor::eSurface;
1388     break;
1389   }
1390
1391   my2DActor->SetProperty(aProp);
1392   my2DActor->SetBackfaceProperty(aBackProp);
1393   my2DActor->SetRepresentation(aReperesent);
1394
1395   if(aQuadraticMode == SMESH_Actor::eLines)
1396     my2DActor->SetQuadraticArcMode(false);
1397   else if(aQuadraticMode == SMESH_Actor::eArcs)
1398     my2DActor->SetQuadraticArcMode(true);
1399
1400   my2DExtActor->SetRepresentation(aReperesent);
1401   
1402   my3DActor->SetProperty(aProp);
1403   my3DActor->SetBackfaceProperty(aBackProp);
1404   my3DActor->SetRepresentation(aReperesent);
1405
1406   //my0DExtActor->SetVisibility(false);
1407   my1DExtActor->SetVisibility(false);
1408   my2DExtActor->SetVisibility(false);
1409
1410   // ???
1411   //my0DActor->SetProperty(aProp);
1412   //my0DActor->SetBackfaceProperty(aBackProp);
1413   my0DActor->SetRepresentation(aReperesent);
1414   //my0DExtActor->SetRepresentation(aReperesent);
1415
1416   switch(myControlMode){
1417   case eLength:
1418   case eMultiConnection:
1419     aProp = aBackProp = my1DProp;
1420     if(myRepresentation != ePoint)
1421       aReperesent = SMESH_DeviceActor::eInsideframe;
1422     break;
1423   }
1424   
1425   if(aQuadraticMode == SMESH_Actor::eLines)
1426     my1DActor->SetQuadraticArcMode(false);
1427   else if(aQuadraticMode == SMESH_Actor::eArcs)
1428     my1DActor->SetQuadraticArcMode(true);
1429
1430   my1DActor->SetProperty(aProp);
1431   my1DActor->SetBackfaceProperty(aBackProp);
1432   my1DActor->SetRepresentation(aReperesent);
1433
1434   my1DExtActor->SetRepresentation(aReperesent);
1435
1436   if(myIsPointsVisible)
1437     myPickableActor = myNodeActor;
1438   if(GetPointRepresentation())
1439     myNodeActor->SetVisibility(true);
1440
1441   SetMapper(myPickableActor->GetMapper());
1442
1443   SetVisibility(GetVisibility(),false);
1444
1445   Modified();
1446 }
1447
1448
1449 void SMESH_ActorDef::SetPointRepresentation(bool theIsPointsVisible){
1450   if ( myIsPointsVisible == theIsPointsVisible )
1451     return;
1452   myIsPointsVisible = theIsPointsVisible;
1453   SetRepresentation(GetRepresentation());
1454 }
1455
1456 bool SMESH_ActorDef::GetPointRepresentation(){ 
1457   return myIsPointsVisible || myIsPointsLabeled;
1458 }
1459
1460
1461 void SMESH_ActorDef::UpdateHighlight(){
1462   myHighlitableActor->SetVisibility(false);
1463   myHighlitableActor->SetHighlited(false);
1464
1465   if(myIsHighlighted){
1466     myHighlitableActor->SetProperty(myHighlightProp);
1467   }else if(myIsPreselected){
1468     myHighlitableActor->SetProperty(myPreselectProp);
1469   }
1470
1471   bool anIsVisible = GetVisibility();
1472
1473   if(myIsHighlighted || myIsPreselected){
1474     if(GetUnstructuredGrid()->GetNumberOfCells()){
1475       myHighlitableActor->SetHighlited(anIsVisible);
1476       myHighlitableActor->SetVisibility(anIsVisible);
1477       myHighlitableActor->GetExtractUnstructuredGrid()->
1478         SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::eCells);
1479       myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
1480     }else if(myRepresentation == ePoint || GetPointRepresentation()){
1481       myHighlitableActor->SetHighlited(anIsVisible);
1482       myHighlitableActor->GetExtractUnstructuredGrid()->
1483         SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
1484       myHighlitableActor->SetVisibility(anIsVisible);
1485       myHighlitableActor->SetRepresentation(SMESH_DeviceActor::ePoint);
1486     }
1487   }
1488 }
1489
1490
1491 void SMESH_ActorDef::highlight(bool theHighlight){
1492   if ( myIsHighlighted == theHighlight )
1493     return;
1494   myIsHighlighted = theHighlight;
1495   UpdateHighlight();
1496 }
1497
1498
1499 void SMESH_ActorDef::SetPreSelected(bool thePreselect){ 
1500   if ( myIsPreselected == thePreselect )
1501     return;
1502   myIsPreselected = thePreselect; 
1503   UpdateHighlight();
1504 }
1505
1506
1507 // From vtkFollower
1508 int SMESH_ActorDef::RenderOpaqueGeometry(vtkViewport *vp)
1509 {
1510   if (myPickableActor->GetIsOpaque())
1511     {
1512     vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1513     this->Render(ren);
1514     return 1;
1515     }
1516   return 0;
1517 }
1518
1519
1520 int SMESH_ActorDef::RenderTranslucentGeometry(vtkViewport *vp)
1521 {
1522   if (!myPickableActor->GetIsOpaque())
1523     {
1524     vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1525     this->Render(ren);
1526     return 1;
1527     }
1528   return 0;
1529 }
1530
1531
1532 void SMESH_ActorDef::Render(vtkRenderer *ren){
1533   unsigned long aTime = myTimeStamp->GetMTime();
1534   unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1535   unsigned long aClippingTime = myImplicitBoolean->GetMTime();
1536   if(anObjTime > aTime || aClippingTime > aTime)
1537     Update();
1538 }
1539
1540
1541 void SMESH_ActorDef::Update(){
1542   if(MYDEBUG) MESSAGE("SMESH_ActorDef::Update");
1543
1544   if(GetControlMode() != eNone) {
1545     unsigned long aTime = myTimeStamp->GetMTime();
1546     unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1547     if (anObjTime > aTime)
1548       SetControlMode(GetControlMode(),false);
1549   }
1550   if(myIsPointsLabeled){
1551     SetPointsLabeled(myIsPointsLabeled);
1552   }
1553   if(myIsCellsLabeled){
1554     SetCellsLabeled(myIsCellsLabeled);
1555   }
1556   if(myIsFacesOriented){
1557     SetFacesOriented(myIsFacesOriented);
1558   }
1559   SetEntityMode(GetEntityMode());
1560   SetVisibility(GetVisibility());
1561   
1562   myTimeStamp->Modified();
1563   Modified();
1564 }
1565
1566
1567 void SMESH_ActorDef::ReleaseGraphicsResources(vtkWindow *renWin){
1568   SALOME_Actor::ReleaseGraphicsResources(renWin);
1569
1570   myPickableActor->ReleaseGraphicsResources(renWin);
1571 }
1572
1573
1574 static void GetColor(vtkProperty *theProperty, vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1575   vtkFloatingPointType* aColor = theProperty->GetColor();
1576   r = aColor[0];
1577   g = aColor[1];
1578   b = aColor[2];
1579 }
1580
1581
1582 void SMESH_ActorDef::SetOpacity(vtkFloatingPointType theValue){
1583   mySurfaceProp->SetOpacity(theValue);
1584   myBackSurfaceProp->SetOpacity(theValue);
1585   myEdgeProp->SetOpacity(theValue);
1586   myNodeProp->SetOpacity(theValue);
1587
1588   my1DProp->SetOpacity(theValue);
1589 }
1590
1591
1592 vtkFloatingPointType SMESH_ActorDef::GetOpacity(){
1593   return mySurfaceProp->GetOpacity();
1594 }
1595
1596
1597 void SMESH_ActorDef::SetSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1598   mySurfaceProp->SetColor(r,g,b);
1599   if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
1600     if( aGroupObj->GetElementType() == SMDSAbs_Face ||
1601         aGroupObj->GetElementType() == SMDSAbs_Volume )
1602       myNameActor->SetBackgroundColor(r,g,b);
1603   Modified();
1604 }
1605
1606 void SMESH_ActorDef::GetSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1607   ::GetColor(mySurfaceProp,r,g,b);
1608   my2DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1609 }
1610
1611 void SMESH_ActorDef::SetBackSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1612   myBackSurfaceProp->SetColor(r,g,b);
1613   Modified();
1614 }
1615
1616 void SMESH_ActorDef::GetBackSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1617   ::GetColor(myBackSurfaceProp,r,g,b);
1618 }
1619
1620 void SMESH_ActorDef::SetEdgeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1621   myEdgeProp->SetColor(r,g,b);
1622   my1DProp->SetColor(r,g,b);
1623   my1DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1624   if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
1625     if( aGroupObj->GetElementType() == SMDSAbs_Edge )
1626       myNameActor->SetBackgroundColor(r,g,b);
1627   Modified();
1628 }
1629
1630 void SMESH_ActorDef::GetEdgeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1631   ::GetColor(myEdgeProp,r,g,b);
1632 }
1633
1634 void SMESH_ActorDef::SetNodeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){ 
1635   myNodeProp->SetColor(r,g,b);
1636   myNodeExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1637   if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
1638     if( aGroupObj->GetElementType() == SMDSAbs_Node )
1639       myNameActor->SetBackgroundColor(r,g,b);
1640   Modified();
1641 }
1642
1643 void SMESH_ActorDef::GetNodeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){ 
1644   ::GetColor(myNodeProp,r,g,b);
1645 }
1646
1647 void SMESH_ActorDef::SetHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){ 
1648   myHighlightProp->SetColor(r,g,b);
1649   Modified();
1650 }
1651
1652 void SMESH_ActorDef::GetHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){ 
1653   ::GetColor(myHighlightProp,r,g,b);
1654 }
1655
1656 void SMESH_ActorDef::SetPreHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){ 
1657   myPreselectProp->SetColor(r,g,b);
1658   Modified();
1659 }
1660
1661 void SMESH_ActorDef::GetPreHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){ 
1662   ::GetColor(myPreselectProp,r,g,b);
1663 }
1664
1665
1666 vtkFloatingPointType SMESH_ActorDef::GetLineWidth(){
1667   return myEdgeProp->GetLineWidth();
1668 }
1669
1670
1671 void SMESH_ActorDef::SetLineWidth(vtkFloatingPointType theVal){
1672   myEdgeProp->SetLineWidth(theVal);
1673
1674   my1DProp->SetLineWidth(theVal + aLineWidthInc);
1675   my1DExtProp->SetLineWidth(theVal + aLineWidthInc);
1676
1677   Modified();
1678 }
1679
1680
1681 void SMESH_ActorDef::SetNodeSize(vtkFloatingPointType theVal){
1682   myNodeProp->SetPointSize(theVal);
1683   myNodeExtProp->SetPointSize(theVal);
1684
1685   vtkFloatingPointType aPointSize = my0DProp->GetPointSize() > theVal ? my0DProp->GetPointSize() : theVal;
1686   //myHighlightProp->SetPointSize(theVal);
1687   myHighlightProp->SetPointSize(aPointSize); // ??
1688   //myPreselectProp->SetPointSize(theVal);
1689   myPreselectProp->SetPointSize(aPointSize); // ??
1690
1691   my1DProp->SetPointSize(theVal + aPointSizeInc);
1692   my1DExtProp->SetPointSize(theVal + aPointSizeInc);
1693
1694   Modified();
1695 }
1696
1697 vtkFloatingPointType SMESH_ActorDef::GetNodeSize(){
1698   return myNodeProp->GetPointSize();
1699 }
1700
1701 int SMESH_ActorDef::GetObjDimension( const int theObjId )
1702 {
1703   return myVisualObj->GetElemDimension( theObjId );
1704 }
1705
1706 bool
1707 SMESH_ActorDef::
1708 IsImplicitFunctionUsed() const
1709 {
1710   return myBaseActor->IsImplicitFunctionUsed();
1711 }
1712
1713 void
1714 SMESH_ActorDef::SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed)
1715 {
1716   myNodeActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1717   myBaseActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1718
1719   myHighlitableActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1720
1721   myNodeExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1722
1723   my0DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1724   //my0DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1725
1726   my1DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1727   my1DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1728
1729   my2DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1730   my2DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1731   my3DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1732 }
1733
1734 vtkIdType 
1735 SMESH_ActorDef::AddClippingPlane(vtkPlane* thePlane)
1736 {
1737   if(thePlane){
1738     myImplicitBoolean->GetFunction()->AddItem(thePlane);
1739     myCippingPlaneCont.push_back(thePlane);
1740     if(!IsImplicitFunctionUsed())
1741       SetImplicitFunctionUsed(true);
1742   }
1743   return myCippingPlaneCont.size();
1744 }
1745
1746 void
1747 SMESH_ActorDef::
1748 RemoveAllClippingPlanes()
1749 {
1750   myImplicitBoolean->GetFunction()->RemoveAllItems();
1751   myImplicitBoolean->GetFunction()->Modified(); // VTK bug
1752   myCippingPlaneCont.clear();
1753   SetImplicitFunctionUsed(false);
1754 }
1755
1756 vtkIdType
1757 SMESH_ActorDef::
1758 GetNumberOfClippingPlanes()
1759 {
1760   return myCippingPlaneCont.size();
1761 }
1762
1763 vtkPlane* 
1764 SMESH_ActorDef::
1765 GetClippingPlane(vtkIdType theID)
1766 {
1767   if(theID >= myCippingPlaneCont.size())
1768     return NULL;
1769   return myCippingPlaneCont[theID].Get();
1770 }
1771
1772
1773 static void ComputeBoundsParam(vtkDataSet* theDataSet,
1774                                vtkFloatingPointType theDirection[3], vtkFloatingPointType theMinPnt[3],
1775                                vtkFloatingPointType& theMaxBoundPrj, vtkFloatingPointType& theMinBoundPrj)
1776 {
1777   vtkFloatingPointType aBounds[6];
1778   theDataSet->GetBounds(aBounds);
1779
1780   //Enlarge bounds in order to avoid conflicts of precision
1781   for(int i = 0; i < 6; i += 2){
1782     static double EPS = 1.0E-3;
1783     vtkFloatingPointType aDelta = (aBounds[i+1] - aBounds[i])*EPS;
1784     aBounds[i] -= aDelta;
1785     aBounds[i+1] += aDelta;
1786   }
1787
1788   vtkFloatingPointType aBoundPoints[8][3] = { {aBounds[0],aBounds[2],aBounds[4]},
1789                                {aBounds[1],aBounds[2],aBounds[4]},
1790                                {aBounds[0],aBounds[3],aBounds[4]},
1791                                {aBounds[1],aBounds[3],aBounds[4]},
1792                                {aBounds[0],aBounds[2],aBounds[5]},
1793                                {aBounds[1],aBounds[2],aBounds[5]}, 
1794                                {aBounds[0],aBounds[3],aBounds[5]}, 
1795                                {aBounds[1],aBounds[3],aBounds[5]}};
1796
1797   int aMaxId = 0, aMinId = aMaxId;
1798   theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
1799   theMinBoundPrj = theMaxBoundPrj;
1800   for(int i = 1; i < 8; i++){
1801     vtkFloatingPointType aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
1802     if(theMaxBoundPrj < aTmp){
1803       theMaxBoundPrj = aTmp;
1804       aMaxId = i;
1805     }
1806     if(theMinBoundPrj > aTmp){
1807       theMinBoundPrj = aTmp;
1808       aMinId = i;
1809     }
1810   }
1811   vtkFloatingPointType *aMinPnt = aBoundPoints[aMaxId];
1812   theMinPnt[0] = aMinPnt[0];
1813   theMinPnt[1] = aMinPnt[1];
1814   theMinPnt[2] = aMinPnt[2];
1815 }
1816
1817
1818 static void DistanceToPosition(vtkDataSet* theDataSet,
1819                                vtkFloatingPointType theDirection[3], vtkFloatingPointType theDist, vtkFloatingPointType thePos[3])
1820 {
1821   vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1822   ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1823   vtkFloatingPointType aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
1824   thePos[0] = aMinPnt[0]-theDirection[0]*aLength;
1825   thePos[1] = aMinPnt[1]-theDirection[1]*aLength;
1826   thePos[2] = aMinPnt[2]-theDirection[2]*aLength;
1827 }
1828
1829
1830 static void PositionToDistance(vtkDataSet* theDataSet, 
1831                                vtkFloatingPointType theDirection[3], vtkFloatingPointType thePos[3], vtkFloatingPointType& theDist)
1832 {
1833   vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1834   ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1835   vtkFloatingPointType aPrj = vtkMath::Dot(theDirection,thePos);
1836   theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
1837 }
1838
1839
1840 void SMESH_ActorDef::SetPlaneParam(vtkFloatingPointType theDir[3], vtkFloatingPointType theDist, vtkPlane* thePlane)
1841 {
1842   thePlane->SetNormal(theDir);
1843   vtkFloatingPointType anOrigin[3];
1844   ::DistanceToPosition(GetUnstructuredGrid(),theDir,theDist,anOrigin);
1845   thePlane->SetOrigin(anOrigin);
1846 }
1847
1848
1849 void SMESH_ActorDef::GetPlaneParam(vtkFloatingPointType theDir[3], vtkFloatingPointType& theDist, vtkPlane* thePlane)
1850 {
1851   thePlane->GetNormal(theDir);
1852
1853   vtkFloatingPointType anOrigin[3];
1854   thePlane->GetOrigin(anOrigin);
1855   ::PositionToDistance(GetUnstructuredGrid(),theDir,anOrigin,theDist);
1856 }
1857
1858 void SMESH_ActorDef::UpdateScalarBar()
1859 {
1860   SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
1861   if( !mgr )
1862     return;
1863
1864   vtkTextProperty* aScalarBarTitleProp = vtkTextProperty::New();
1865
1866   QColor aTColor = mgr->colorValue( "SMESH", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
1867   aScalarBarTitleProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1868
1869   aScalarBarTitleProp->SetFontFamilyToArial();
1870
1871   if ( mgr->hasValue( "SMESH", "scalar_bar_title_font" ) )
1872   {
1873     QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
1874     if ( f.family() == "Arial" )
1875       aScalarBarTitleProp->SetFontFamilyToArial();
1876     else if ( f.family() == "Courier" )
1877       aScalarBarTitleProp->SetFontFamilyToCourier();
1878     else if ( f.family() == "Times" )
1879       aScalarBarTitleProp->SetFontFamilyToTimes();
1880
1881     if ( f.bold() )
1882       aScalarBarTitleProp->BoldOn();
1883     else
1884       aScalarBarTitleProp->BoldOff();
1885
1886     if ( f.italic() )
1887       aScalarBarTitleProp->ItalicOn();
1888     else
1889      aScalarBarTitleProp->ItalicOff();
1890
1891     if ( f.overline() )
1892       aScalarBarTitleProp->ShadowOn();
1893     else
1894       aScalarBarTitleProp->ShadowOff();
1895   }
1896
1897   myScalarBarActor->SetTitleTextProperty( aScalarBarTitleProp );
1898   aScalarBarTitleProp->Delete();
1899
1900   vtkTextProperty* aScalarBarLabelProp = vtkTextProperty::New();
1901
1902   aTColor = mgr->colorValue( "SMESH", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
1903   aScalarBarLabelProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1904
1905   aScalarBarLabelProp->SetFontFamilyToArial();
1906   if( mgr->hasValue( "SMESH", "scalar_bar_label_font" ) )
1907   {
1908     QFont f = mgr->fontValue( "SMESH", "scalar_bar_label_font" );
1909     if( f.family() == "Arial" )
1910       aScalarBarLabelProp->SetFontFamilyToArial();
1911     else if( f.family() == "Courier" )
1912       aScalarBarLabelProp->SetFontFamilyToCourier();
1913     else if( f.family() == "Times" )
1914       aScalarBarLabelProp->SetFontFamilyToTimes();
1915
1916     if ( f.bold() )
1917       aScalarBarLabelProp->BoldOn();
1918     else
1919       aScalarBarLabelProp->BoldOff();
1920
1921     if ( f.italic() )
1922       aScalarBarLabelProp->ItalicOn();
1923     else
1924       aScalarBarLabelProp->ItalicOff();
1925
1926     if( f.overline() )
1927       aScalarBarLabelProp->ShadowOn();
1928     else
1929       aScalarBarLabelProp->ShadowOff();
1930   }
1931
1932   myScalarBarActor->SetLabelTextProperty( aScalarBarLabelProp );
1933   aScalarBarLabelProp->Delete();
1934
1935   bool horiz = ( mgr->integerValue( "SMESH", "scalar_bar_orientation" ) == 1 );
1936   QString name = QString( "scalar_bar_%1_" ).arg( horiz ? "horizontal" : "vertical" );
1937   if( horiz )
1938     myScalarBarActor->SetOrientationToHorizontal();
1939   else
1940     myScalarBarActor->SetOrientationToVertical();
1941
1942
1943   vtkFloatingPointType aXVal = horiz ? 0.20 : 0.01;
1944   if( mgr->hasValue( "SMESH", name + "x" ) )
1945     aXVal = mgr->doubleValue( "SMESH", name + "x", aXVal );
1946
1947   vtkFloatingPointType aYVal = horiz ? 0.01 : 0.1;
1948   if( mgr->hasValue( "SMESH", name + "y" ) )
1949     aYVal = mgr->doubleValue( "SMESH", name + "y", aYVal );
1950   myScalarBarActor->SetPosition( aXVal, aYVal );
1951
1952   vtkFloatingPointType aWVal = horiz ? 0.60 : 0.10;
1953   if( mgr->hasValue( "SMESH", name + "width" ) )
1954     aWVal = mgr->doubleValue( "SMESH", name + "width", aWVal );
1955   myScalarBarActor->SetWidth( aWVal );
1956
1957   vtkFloatingPointType aHVal = horiz ? 0.12 : 0.80;
1958   if( mgr->hasValue( "SMESH", name + "height" ) )
1959     aHVal = mgr->doubleValue( "SMESH", name + "height", aHVal );
1960   myScalarBarActor->SetHeight( aHVal );
1961
1962   int anIntVal = 5;
1963   if( mgr->hasValue( "SMESH", "scalar_bar_num_labels" ) )
1964     anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_labels", anIntVal );
1965   myScalarBarActor->SetNumberOfLabels( anIntVal == 0 ? 5: anIntVal );
1966
1967   anIntVal = 64;
1968   if( mgr->hasValue( "SMESH", "scalar_bar_num_colors" ) )
1969     anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_colors", anIntVal );
1970   myScalarBarActor->SetMaximumNumberOfColors( anIntVal == 0 ? 64 : anIntVal );
1971   
1972 }
1973
1974 void SMESH_ActorDef::SetQuadratic2DRepresentation(EQuadratic2DRepresentation theMode)
1975 {
1976   switch(theMode) {
1977   case SMESH_Actor::eLines :
1978     myHighlitableActor->SetQuadraticArcMode(false);
1979     my2DActor->SetQuadraticArcMode(false);
1980     my1DActor->SetQuadraticArcMode(false);
1981     break;
1982   case SMESH_Actor::eArcs :
1983     myHighlitableActor->SetQuadraticArcMode(true);
1984     if(GetRepresentation() != SMESH_Actor::ePoint) {
1985       my2DActor->SetQuadraticArcMode(true);
1986       my1DActor->SetQuadraticArcMode(true);
1987     }
1988     break;
1989   default:
1990     break;
1991   }
1992 }
1993
1994
1995 SMESH_Actor::EQuadratic2DRepresentation SMESH_ActorDef::GetQuadratic2DRepresentation()
1996 {
1997   if(myHighlitableActor->GetQuadraticArcMode())
1998     return SMESH_Actor::eArcs;
1999   else
2000     return SMESH_Actor::eLines;
2001 }