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