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