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