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