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