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