Salome HOME
42800dd766c5caa79754eff3dd570f26760cc2cc
[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   myOutLineProp->Delete();
570
571   myEdgeProp->Delete();
572   myHighlightProp->Delete();
573   myPreselectProp->Delete();
574
575   myNodeProp->Delete();
576   myNodeExtProp->Delete();
577  
578   my0DProp->Delete();
579   my0DActor->Delete();
580
581   //my0DExtProp->Delete();
582   //my0DExtActor->Delete();
583  
584   my1DProp->Delete();
585   my1DActor->Delete();
586
587   my1DExtProp->Delete();
588   my1DExtActor->Delete();
589
590   my2DActor->Delete();
591   my2DExtProp->Delete();
592   my2DExtActor->Delete();
593   my3DActor->Delete();
594   my3DExtActor->Delete();
595
596   myNodeActor->Delete();
597   myBaseActor->Delete();
598
599   myNodeExtActor->Delete();
600   
601   myHighlitableActor->Delete();
602
603   //Deleting of points numbering pipeline
604   //---------------------------------------
605   myPointsNumDataSet->Delete();
606
607   // commented: porting to vtk 5.0
608   //  myPtsLabeledDataMapper->RemoveAllInputs();
609   myPtsLabeledDataMapper->Delete();
610
611   // commented: porting to vtk 5.0
612   //  myPtsSelectVisiblePoints->UnRegisterAllOutputs();
613   myPtsSelectVisiblePoints->Delete();
614
615   // commented: porting to vtk 5.0
616   //  myPtsMaskPoints->UnRegisterAllOutputs();
617   myPtsMaskPoints->Delete();
618
619   myPointLabels->Delete();
620
621
622   //Deleting of cells numbering pipeline
623   //---------------------------------------
624   myCellsNumDataSet->Delete();
625
626   myClsLabeledDataMapper->RemoveAllInputs();
627   myClsLabeledDataMapper->Delete();
628
629   // commented: porting to vtk 5.0
630   //  myClsSelectVisiblePoints->UnRegisterAllOutputs();
631   myClsSelectVisiblePoints->Delete();
632
633   // commented: porting to vtk 5.0
634   //  myClsMaskPoints->UnRegisterAllOutputs();
635   myClsMaskPoints->Delete();
636
637   // commented: porting to vtk 5.0
638   //  myCellCenters->UnRegisterAllOutputs();
639   myCellCenters->Delete();
640
641   myCellsLabels->Delete();
642
643   myImplicitBoolean->Delete();
644
645   myTimeStamp->Delete();
646 }
647
648
649 void SMESH_ActorDef::SetPointsLabeled( bool theIsPointsLabeled )
650 {    
651   vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
652     
653   myIsPointsLabeled = theIsPointsLabeled && aGrid->GetNumberOfPoints();
654
655   if ( myIsPointsLabeled )
656   {
657     myPointsNumDataSet->ShallowCopy(aGrid);
658     vtkDataSet *aDataSet = myPointsNumDataSet;
659     
660     int aNbElem = aDataSet->GetNumberOfPoints();
661     
662     vtkIntArray *anArray = vtkIntArray::New();
663     anArray->SetNumberOfValues( aNbElem );
664     
665     for ( vtkIdType anId = 0; anId < aNbElem; anId++ )
666     {
667       int aSMDSId = myVisualObj->GetNodeObjId( anId );
668       anArray->SetValue( anId, aSMDSId );
669     }
670     
671     aDataSet->GetPointData()->SetScalars( anArray );
672     anArray->Delete();
673     myPtsMaskPoints->SetInput( aDataSet );
674     myPointLabels->SetVisibility( GetVisibility() );
675   }
676   else
677   {
678     myPointLabels->SetVisibility( false );
679   }
680   SetRepresentation(GetRepresentation());
681   myTimeStamp->Modified();
682 }
683
684
685 void SMESH_ActorDef::SetCellsLabeled(bool theIsCellsLabeled)
686 {
687   vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
688   myIsCellsLabeled = theIsCellsLabeled && aGrid->GetNumberOfPoints();
689   if(myIsCellsLabeled){
690     myCellsNumDataSet->ShallowCopy(aGrid);
691     vtkDataSet *aDataSet = myCellsNumDataSet;
692     int aNbElem = aDataSet->GetNumberOfCells();
693     vtkIntArray *anArray = vtkIntArray::New();
694     anArray->SetNumberOfValues(aNbElem);
695     for(int anId = 0; anId < aNbElem; anId++){
696       int aSMDSId = myVisualObj->GetElemObjId(anId);
697       anArray->SetValue(anId,aSMDSId);
698     }
699     aDataSet->GetCellData()->SetScalars(anArray);
700     myCellCenters->SetInput(aDataSet);
701     myCellsLabels->SetVisibility(GetVisibility());
702   }else{
703     myCellsLabels->SetVisibility(false);
704   }
705   myTimeStamp->Modified();
706 }
707
708
709 void SMESH_ActorDef::SetFacesOriented(bool theIsFacesOriented)
710 {
711   myIsFacesOriented = theIsFacesOriented;
712
713   my2DActor->SetFacesOriented(theIsFacesOriented);
714   my3DActor->SetFacesOriented(theIsFacesOriented);
715
716   myTimeStamp->Modified();
717 }
718
719 bool SMESH_ActorDef::GetFacesOriented()
720 {
721   return myIsFacesOriented;
722 }
723
724 void SMESH_ActorDef::SetFacesOrientationColor(vtkFloatingPointType theColor[3])
725 {
726   my2DActor->SetFacesOrientationColor( theColor );
727   my3DActor->SetFacesOrientationColor( theColor );
728 }
729
730 void SMESH_ActorDef::GetFacesOrientationColor(vtkFloatingPointType theColor[3])
731 {
732   my3DActor->GetFacesOrientationColor( theColor );
733 }
734
735 void SMESH_ActorDef::SetFacesOrientationScale(vtkFloatingPointType theScale)
736 {
737   my2DActor->SetFacesOrientationScale( theScale );
738   my3DActor->SetFacesOrientationScale( theScale );
739 }
740
741 vtkFloatingPointType SMESH_ActorDef::GetFacesOrientationScale()
742 {
743   return my3DActor->GetFacesOrientationScale();
744 }
745
746 void SMESH_ActorDef::SetFacesOrientation3DVectors(bool theState)
747 {
748   my2DActor->SetFacesOrientation3DVectors( theState );
749   my3DActor->SetFacesOrientation3DVectors( theState );
750 }
751
752 bool SMESH_ActorDef::GetFacesOrientation3DVectors()
753 {
754   return my3DActor->GetFacesOrientation3DVectors();
755 }
756
757
758 void 
759 SMESH_ActorDef::
760 SetControlMode(eControl theMode)
761 {
762   SetControlMode(theMode,true);
763 }
764
765
766 void 
767 SMESH_ActorDef::
768 SetControlMode(eControl theMode,
769                bool theCheckEntityMode)
770 {
771   SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();  
772   if( !mgr )
773     return;
774
775   myControlMode = eNone;
776   theCheckEntityMode &= mgr->booleanValue( "SMESH", "display_entity", false );
777
778   my0DActor->GetMapper()->SetScalarVisibility(false);
779   my1DActor->GetMapper()->SetScalarVisibility(false);
780   my2DActor->GetMapper()->SetScalarVisibility(false);
781   my3DActor->GetMapper()->SetScalarVisibility(false);
782   myScalarBarActor->SetVisibility(false);
783
784   bool anIsScalarVisible = theMode > eNone;
785
786   if(anIsScalarVisible) {
787     switch(theMode) {
788     case eLength:
789     {
790       SMESH::Controls::Length* aControl = new SMESH::Controls::Length();
791       aControl->SetPrecision( myControlsPrecision );
792       myFunctor.reset( aControl );
793       myControlActor = my1DActor;
794       break;
795     }
796     case eLength2D:
797     {
798       myFunctor.reset(new SMESH::Controls::Length2D());
799       myControlActor = my2DActor;
800       break;
801     }
802     case eFreeBorders:
803       myFunctor.reset(new SMESH::Controls::FreeBorders());
804       myControlActor = my1DActor;
805       break;
806     case eFreeEdges:
807       myFunctor.reset(new SMESH::Controls::FreeEdges());
808       myControlActor = my2DActor;
809       break;
810     case eFreeNodes:
811       myFunctor.reset(new SMESH::Controls::FreeNodes());
812       myControlActor = myNodeActor;
813       break;
814     case eFreeFaces:
815       myFunctor.reset(new SMESH::Controls::FreeFaces());
816       myControlActor = my2DActor;
817       break;
818     case eBareBorderFace:
819       myFunctor.reset(new SMESH::Controls::BareBorderFace());
820       myControlActor = my2DActor;
821       break;
822     case eOverConstrainedFace:
823       myFunctor.reset(new SMESH::Controls::OverConstrainedFace());
824       myControlActor = my2DActor;
825       break;
826     case eMultiConnection:
827       myFunctor.reset(new SMESH::Controls::MultiConnection());
828       myControlActor = my1DActor;
829       break;
830     case eMultiConnection2D:
831       myFunctor.reset(new SMESH::Controls::MultiConnection2D());
832       myControlActor = my2DActor;
833       break;
834     case eArea:
835     {
836       SMESH::Controls::Area* aControl = new SMESH::Controls::Area();
837       aControl->SetPrecision( myControlsPrecision );
838       myFunctor.reset( aControl );
839       myControlActor = my2DActor;
840       break;
841     }
842     case eTaper:
843     {
844       SMESH::Controls::Taper* aControl = new SMESH::Controls::Taper();
845       aControl->SetPrecision( myControlsPrecision );
846       myFunctor.reset( aControl );
847       myControlActor = my2DActor;
848       break;
849     }
850     case eAspectRatio:
851     {
852       SMESH::Controls::AspectRatio* aControl = new SMESH::Controls::AspectRatio();
853       aControl->SetPrecision( myControlsPrecision );
854       myFunctor.reset( aControl );
855       myControlActor = my2DActor;
856       break;
857     }
858     case eAspectRatio3D:
859     {
860       SMESH::Controls::AspectRatio3D* aControl = new SMESH::Controls::AspectRatio3D();
861       aControl->SetPrecision( myControlsPrecision );
862       myFunctor.reset( aControl );
863       myControlActor = my3DActor;
864       break;
865     }
866     case eVolume3D:
867     {
868       SMESH::Controls::Volume* aControl = new SMESH::Controls::Volume();
869       aControl->SetPrecision( myControlsPrecision );
870       myFunctor.reset( aControl );
871       myControlActor = my3DActor;
872       break;
873     }
874     case eMaxElementLength2D:
875     {
876       SMESH::Controls::MaxElementLength2D* aControl = new SMESH::Controls::MaxElementLength2D();
877       aControl->SetPrecision( myControlsPrecision );
878       myFunctor.reset( aControl );
879       myControlActor = my2DActor;
880       break;
881     }
882     case eMaxElementLength3D:
883     {
884       SMESH::Controls::MaxElementLength3D* aControl = new SMESH::Controls::MaxElementLength3D();
885       aControl->SetPrecision( myControlsPrecision );
886       myFunctor.reset( aControl );
887       myControlActor = my3DActor;
888       break;
889     }
890     case eBareBorderVolume:
891     {
892       myFunctor.reset(new SMESH::Controls::BareBorderVolume());
893       myControlActor = my3DActor;
894       break;
895     }
896     case eOverConstrainedVolume:
897     {
898       myFunctor.reset(new SMESH::Controls::OverConstrainedVolume());
899       myControlActor = my3DActor;
900       break;
901     }
902     case eMinimumAngle:
903     {
904       SMESH::Controls::MinimumAngle* aControl = new SMESH::Controls::MinimumAngle();
905       aControl->SetPrecision( myControlsPrecision );
906       myFunctor.reset( aControl );
907       myControlActor = my2DActor;
908       break;
909     }
910     case eWarping:
911     {
912       SMESH::Controls::Warping* aControl = new SMESH::Controls::Warping();
913       aControl->SetPrecision( myControlsPrecision );
914       myFunctor.reset( aControl );
915       myControlActor = my2DActor;
916       break;
917     }
918     case eSkew:
919     {
920       SMESH::Controls::Skew* aControl = new SMESH::Controls::Skew();
921       aControl->SetPrecision( myControlsPrecision );
922       myFunctor.reset( aControl );
923       myControlActor = my2DActor;
924       break;
925     }
926     default:
927       return;
928     }
929
930     vtkUnstructuredGrid* aGrid = myControlActor->GetUnstructuredGrid();
931     vtkIdType aNbCells = aGrid->GetNumberOfCells();
932     if(aNbCells){
933       myControlMode = theMode;
934       switch(myControlMode){
935       case eFreeNodes:
936         myNodeExtActor->SetExtControlMode(myFunctor);
937         break;
938       case eFreeEdges:
939       case eFreeBorders:
940         my1DExtActor->SetExtControlMode(myFunctor);
941         break;
942       case eFreeFaces:
943       case eBareBorderFace:
944       case eOverConstrainedFace:
945         my2DExtActor->SetExtControlMode(myFunctor);
946         break;
947       case eBareBorderVolume:
948       case eOverConstrainedVolume:
949         my3DExtActor->SetExtControlMode(myFunctor);
950         break;
951       case eLength2D:
952       case eMultiConnection2D:
953         my1DExtActor->SetExtControlMode(myFunctor,myScalarBarActor,myLookupTable);
954         UpdateDistribution();
955         break;
956       default:
957         myControlActor->SetControlMode(myFunctor,myScalarBarActor,myLookupTable);
958         UpdateDistribution();
959       }
960     }
961
962     if(theCheckEntityMode){
963       if(myControlActor == my1DActor)
964         SetEntityMode(eEdges);
965       else if(myControlActor == my2DActor){
966         switch(myControlMode){
967         case eLength2D:
968         case eFreeEdges:
969         case eFreeFaces:
970         case eMultiConnection2D:
971           //SetEntityMode(eEdges);
972           SetEntityMode(eFaces);
973           break;
974         default:
975           SetEntityMode(eFaces);
976         }
977       }else if(myControlActor == my3DActor)
978         SetEntityMode(eVolumes);
979     }
980
981   }
982   else {
983     if(theCheckEntityMode)
984       myEntityMode = eAllEntity;
985     myFunctor.reset();
986   }
987
988   SetRepresentation(GetRepresentation());
989
990   myTimeStamp->Modified();
991   Modified();
992 }
993
994
995 void SMESH_ActorDef::AddToRender(vtkRenderer* theRenderer){
996   theRenderer->AddActor(myNodeActor);
997   theRenderer->AddActor(myBaseActor);
998   
999   theRenderer->AddActor(myNodeExtActor);
1000
1001   my3DActor->AddToRender(theRenderer);
1002   my3DExtActor->AddToRender(theRenderer);
1003   my2DActor->AddToRender(theRenderer);
1004   my2DExtActor->AddToRender(theRenderer);
1005
1006   theRenderer->AddActor(my1DActor);
1007   theRenderer->AddActor(my1DExtActor);
1008
1009   theRenderer->AddActor(my0DActor);
1010   //theRenderer->AddActor(my0DExtActor);
1011
1012   theRenderer->AddActor(myHighlitableActor);
1013   
1014   theRenderer->AddActor2D(myScalarBarActor);
1015
1016   myPtsSelectVisiblePoints->SetRenderer(theRenderer);
1017   myClsSelectVisiblePoints->SetRenderer(theRenderer);
1018
1019   theRenderer->AddActor2D(myPointLabels);
1020   theRenderer->AddActor2D(myCellsLabels);
1021
1022   // the superclass' method should be called at the end
1023   // (in particular, for correct work of selection)
1024   SALOME_Actor::AddToRender(theRenderer);
1025 }
1026
1027 void SMESH_ActorDef::RemoveFromRender(vtkRenderer* theRenderer){
1028   SALOME_Actor::RemoveFromRender(theRenderer);
1029
1030   theRenderer->RemoveActor(myNodeActor);
1031   theRenderer->RemoveActor(myBaseActor);
1032
1033   theRenderer->RemoveActor(myNodeExtActor);
1034
1035   theRenderer->RemoveActor(myHighlitableActor);
1036
1037   theRenderer->RemoveActor(my0DActor);
1038   //theRenderer->RemoveActor(my0DExtActor);
1039
1040   theRenderer->RemoveActor(my1DActor);
1041   theRenderer->RemoveActor(my1DExtActor);
1042
1043   my2DActor->RemoveFromRender(theRenderer);
1044   my2DExtActor->RemoveFromRender(theRenderer);
1045   my3DActor->RemoveFromRender(theRenderer);
1046   my3DExtActor->RemoveFromRender(theRenderer);
1047
1048   theRenderer->RemoveActor(myScalarBarActor);
1049   theRenderer->RemoveActor(myPointLabels);
1050   theRenderer->RemoveActor(myCellsLabels);
1051 }
1052
1053
1054 bool SMESH_ActorDef::Init(TVisualObjPtr theVisualObj, 
1055                           const char* theEntry, 
1056                           const char* theName,
1057                           int theIsClear)
1058 {
1059   Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry,"SMESH",theName);
1060   setIO(anIO);
1061   setName(theName);
1062
1063   myVisualObj = theVisualObj;
1064   myVisualObj->Update(theIsClear);
1065
1066   myNodeActor->Init(myVisualObj,myImplicitBoolean);
1067   myBaseActor->Init(myVisualObj,myImplicitBoolean);
1068
1069   myHighlitableActor->Init(myVisualObj,myImplicitBoolean);
1070
1071   myNodeExtActor->Init(myVisualObj,myImplicitBoolean);
1072   
1073   my0DActor->Init(myVisualObj,myImplicitBoolean);
1074   //my0DExtActor->Init(myVisualObj,myImplicitBoolean);
1075   
1076   my1DActor->Init(myVisualObj,myImplicitBoolean);
1077   my1DExtActor->Init(myVisualObj,myImplicitBoolean);
1078   
1079   my2DActor->Init(myVisualObj,myImplicitBoolean);
1080   my2DExtActor->Init(myVisualObj,myImplicitBoolean);
1081   my3DActor->Init(myVisualObj,myImplicitBoolean);
1082   my3DExtActor->Init(myVisualObj,myImplicitBoolean);
1083   
1084   my0DActor->GetMapper()->SetLookupTable(myLookupTable);
1085   //my0DExtActor->GetMapper()->SetLookupTable(myLookupTable);
1086   
1087   my1DActor->GetMapper()->SetLookupTable(myLookupTable);
1088   my1DExtActor->GetMapper()->SetLookupTable(myLookupTable);
1089
1090   my2DActor->GetMapper()->SetLookupTable(myLookupTable);
1091   my2DExtActor->GetMapper()->SetLookupTable(myLookupTable);
1092   my3DActor->GetMapper()->SetLookupTable(myLookupTable);
1093   my3DExtActor->GetMapper()->SetLookupTable(myLookupTable);
1094     
1095   vtkFloatingPointType aFactor, aUnits;
1096   my2DActor->GetPolygonOffsetParameters(aFactor,aUnits);
1097   my2DActor->SetPolygonOffsetParameters(aFactor,aUnits*0.75);
1098   my2DExtActor->SetPolygonOffsetParameters(aFactor,aUnits*0.5);
1099
1100   SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
1101   if( !mgr )
1102     return false;
1103
1104   //SetIsShrunkable(theGrid->GetNumberOfCells() > 10);
1105   SetIsShrunkable(true);
1106
1107   SetShrinkFactor( SMESH::GetFloat( "SMESH:shrink_coeff", 75 ) / 100. );
1108
1109   int aMode = mgr->integerValue( "SMESH", "display_mode" );
1110   SetRepresentation(-1);
1111   
1112   if(aMode == 0){
1113     SetRepresentation(eEdge);
1114   }else if(aMode == 1){
1115     SetRepresentation(eSurface);
1116   }else if(aMode == 2){
1117     SetRepresentation(ePoint);
1118   }
1119   
1120   if(aMode == 3){
1121     SetShrink();
1122   }
1123
1124   if( dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
1125     SetIsDisplayNameActor( true );
1126
1127   int aMarkerType = mgr->integerValue( "SMESH", "type_of_marker", 1 ); // dot
1128   int aMarkerScale = mgr->integerValue( "SMESH", "marker_scale", 9 );  // 5 pixels
1129   SetMarkerStd( (VTK::MarkerType)aMarkerType, (VTK::MarkerScale)aMarkerScale );
1130
1131   myTimeStamp->Modified();
1132   Modified();
1133   return true;
1134 }
1135
1136
1137 vtkFloatingPointType* SMESH_ActorDef::GetBounds(){
1138   return myNodeActor->GetBounds();
1139 }
1140
1141
1142 vtkDataSet* SMESH_ActorDef::GetInput(){
1143   return GetUnstructuredGrid();
1144 }
1145
1146
1147 void SMESH_ActorDef::SetTransform(VTKViewer_Transform* theTransform){
1148   Superclass::SetTransform(theTransform);
1149
1150   myNodeActor->SetTransform(theTransform);
1151   myBaseActor->SetTransform(theTransform);
1152   
1153   myHighlitableActor->SetTransform(theTransform);
1154
1155   myNodeExtActor->SetTransform(theTransform);
1156
1157   my0DActor->SetTransform(theTransform);
1158   //my0DExtActor->SetTransform(theTransform);
1159
1160   my1DActor->SetTransform(theTransform);
1161   my1DExtActor->SetTransform(theTransform);
1162
1163   my2DActor->SetTransform(theTransform);
1164   my2DExtActor->SetTransform(theTransform);
1165   my3DActor->SetTransform(theTransform);
1166   my3DExtActor->SetTransform(theTransform);
1167
1168   Modified();
1169 }
1170
1171
1172 void SMESH_ActorDef::SetMapper(vtkMapper* theMapper){
1173   vtkLODActor::SetMapper(theMapper);
1174 }
1175
1176
1177 void SMESH_ActorDef::ShallowCopy(vtkProp *prop){
1178   SALOME_Actor::ShallowCopy(prop);
1179 }
1180
1181
1182 vtkMapper* SMESH_ActorDef::GetMapper(){
1183   return myPickableActor->GetMapper();
1184 }
1185
1186
1187 vtkUnstructuredGrid* SMESH_ActorDef::GetUnstructuredGrid(){ 
1188   return myVisualObj->GetUnstructuredGrid();
1189 }
1190
1191
1192 bool SMESH_ActorDef::IsInfinitive(){
1193   vtkDataSet *aDataSet = myPickableActor->GetUnstructuredGrid();
1194   aDataSet->Update();
1195   myIsInfinite = aDataSet->GetNumberOfCells() == 0 ||
1196     ( aDataSet->GetNumberOfCells() == 1 && 
1197     aDataSet->GetCell(0)->GetCellType() == VTK_VERTEX );
1198   return SALOME_Actor::IsInfinitive();
1199 }
1200
1201
1202 void SMESH_ActorDef::SetIsShrunkable(bool theShrunkable){
1203   if ( myIsShrinkable == theShrunkable )
1204     return;
1205   myIsShrinkable = theShrunkable;
1206   Modified();
1207 }
1208
1209 vtkFloatingPointType SMESH_ActorDef::GetShrinkFactor(){
1210   return myBaseActor->GetShrinkFactor();
1211 }
1212
1213 void SMESH_ActorDef::SetShrinkFactor(vtkFloatingPointType theValue){
1214   myBaseActor->SetShrinkFactor(theValue);
1215
1216   my1DActor->SetShrinkFactor(theValue);
1217   my1DExtActor->SetShrinkFactor(theValue);
1218
1219   my2DActor->SetShrinkFactor(theValue);
1220   my2DExtActor->SetShrinkFactor(theValue);
1221   my3DActor->SetShrinkFactor(theValue);
1222   my3DExtActor->SetShrinkFactor(theValue);
1223   my3DExtActor->SetShrinkFactor(theValue);
1224   myHighlitableActor->SetShrinkFactor(theValue);
1225
1226   Modified();
1227 }
1228
1229 void SMESH_ActorDef::SetShrink(){
1230   if(!myIsShrinkable) return;
1231
1232   myBaseActor->SetShrink();
1233
1234   my1DActor->SetShrink();
1235   my1DExtActor->SetShrink();
1236
1237   my2DActor->SetShrink();
1238   my2DExtActor->SetShrink();
1239   my3DActor->SetShrink();
1240   my3DExtActor->SetShrink();
1241   myHighlitableActor->SetShrink();
1242
1243   myIsShrunk = true;
1244   Modified();
1245 }
1246
1247 void SMESH_ActorDef::UnShrink(){
1248   if(!myIsShrunk) return;
1249
1250   myBaseActor->UnShrink();
1251
1252   my1DActor->UnShrink();
1253   my1DExtActor->UnShrink();
1254
1255   my2DActor->UnShrink();
1256   my2DExtActor->UnShrink();
1257   my3DActor->UnShrink();
1258   my3DExtActor->UnShrink();
1259   myHighlitableActor->UnShrink();
1260
1261   myIsShrunk = false;
1262   Modified();
1263 }
1264
1265
1266 int SMESH_ActorDef::GetNodeObjId(int theVtkID){
1267   return myPickableActor->GetNodeObjId(theVtkID);
1268 }
1269
1270 vtkFloatingPointType* SMESH_ActorDef::GetNodeCoord(int theObjID){
1271   return myPickableActor->GetNodeCoord(theObjID);
1272 }
1273
1274
1275 int SMESH_ActorDef::GetElemObjId(int theVtkID){
1276   return myPickableActor->GetElemObjId(theVtkID);
1277 }
1278
1279 vtkCell* SMESH_ActorDef::GetElemCell(int theObjID){
1280   return myPickableActor->GetElemCell(theObjID);
1281 }
1282
1283
1284 void SMESH_ActorDef::SetVisibility(int theMode){
1285   SetVisibility(theMode,true);
1286 }
1287
1288
1289 void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation){
1290   SALOME_Actor::SetVisibility(theMode);
1291
1292   myNodeActor->VisibilityOff();
1293   myBaseActor->VisibilityOff();
1294   
1295   myNodeExtActor->VisibilityOff();
1296
1297   my0DActor->VisibilityOff();
1298   //my0DExtActor->VisibilityOff();
1299
1300   my1DActor->VisibilityOff();
1301   my1DExtActor->VisibilityOff();
1302   
1303   my2DActor->VisibilityOff();
1304   my2DExtActor->VisibilityOff();
1305   my3DActor->VisibilityOff();
1306   my3DExtActor->VisibilityOff();
1307   
1308   myScalarBarActor->VisibilityOff();
1309   myPointLabels->VisibilityOff();
1310   myCellsLabels->VisibilityOff();
1311   
1312   if(GetVisibility()){
1313     if(theIsUpdateRepersentation)
1314       SetRepresentation(GetRepresentation());
1315     
1316     if(myControlMode != eNone){
1317       switch(myControlMode){
1318       case eFreeNodes:
1319         myNodeExtActor->VisibilityOn();
1320         break;
1321       case eFreeEdges:
1322       case eFreeBorders:
1323         my1DExtActor->VisibilityOn();
1324         break;
1325       case eFreeFaces:
1326       case eBareBorderFace:
1327       case eOverConstrainedFace:
1328         my2DExtActor->VisibilityOn();
1329         break;
1330       case eBareBorderVolume:
1331       case eOverConstrainedVolume:
1332         my3DExtActor->VisibilityOn();
1333         break;
1334       case eLength2D:
1335       case eMultiConnection2D:
1336         my1DExtActor->VisibilityOn();
1337       default:
1338         if(myControlActor->GetUnstructuredGrid()->GetNumberOfCells())
1339           myScalarBarActor->VisibilityOn();
1340       }
1341     }
1342
1343     if(myRepresentation != ePoint)
1344       myPickableActor->VisibilityOn();
1345     else {
1346       myNodeActor->VisibilityOn();
1347     }
1348
1349     if(myEntityMode & e0DElements){
1350       my0DActor->VisibilityOn();
1351     }
1352
1353     if(myEntityMode & eEdges && GetRepresentation() != ePoint){
1354       my1DActor->VisibilityOn();
1355     }
1356     
1357     if(myEntityMode & eFaces && GetRepresentation() != ePoint){
1358       my2DActor->VisibilityOn();
1359     }
1360     
1361     if(myEntityMode & eVolumes && GetRepresentation() != ePoint){
1362       my3DActor->VisibilityOn();
1363     }
1364     
1365     if(myIsPointsLabeled){ 
1366       myPointLabels->VisibilityOn();
1367       myNodeActor->VisibilityOn();
1368     }
1369
1370     if(myIsCellsLabeled) 
1371       myCellsLabels->VisibilityOn();
1372   } 
1373 #ifndef DISABLE_PLOT2DVIEWER
1374   else
1375     SMESH::ProcessIn2DViewers(this,SMESH::RemoveFrom2dViewer);
1376 #endif
1377   UpdateHighlight();
1378   Modified();
1379 }
1380
1381
1382 void SMESH_ActorDef::SetEntityMode(unsigned int theMode)
1383 {
1384   myEntityState = eAllEntity;
1385
1386   if(!myVisualObj->GetNbEntities(SMDSAbs_0DElement)) {
1387     myEntityState &= ~e0DElements;
1388     theMode &= ~e0DElements;
1389   }
1390
1391   if(!myVisualObj->GetNbEntities(SMDSAbs_Edge)) {
1392     myEntityState &= ~eEdges;
1393     theMode &= ~eEdges;
1394   }
1395
1396   if(!myVisualObj->GetNbEntities(SMDSAbs_Face)) {
1397     myEntityState &= ~eFaces;
1398     theMode &= ~eFaces;
1399   }
1400
1401   if(!myVisualObj->GetNbEntities(SMDSAbs_Volume)) {
1402     myEntityState &= ~eVolumes;
1403     theMode &= ~eVolumes;
1404   }
1405
1406   if (!theMode) {
1407     if(myVisualObj->GetNbEntities(SMDSAbs_0DElement))
1408       theMode |= e0DElements;
1409
1410     if(myVisualObj->GetNbEntities(SMDSAbs_Edge))
1411       theMode |= eEdges;
1412
1413     if(myVisualObj->GetNbEntities(SMDSAbs_Face))
1414       theMode |= eFaces;
1415
1416     if(myVisualObj->GetNbEntities(SMDSAbs_Volume))
1417       theMode |= eVolumes;
1418   }
1419
1420   myBaseActor->myGeomFilter->SetInside(myEntityMode != myEntityState);
1421
1422   myEntityMode = theMode;
1423   VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
1424   aFilter = myBaseActor->GetExtractUnstructuredGrid();
1425   aFilter->ClearRegisteredCellsWithType();
1426   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
1427
1428   VTKViewer_ExtractUnstructuredGrid* aHightFilter = myHighlitableActor->GetExtractUnstructuredGrid();
1429   aHightFilter->ClearRegisteredCellsWithType();
1430   aHightFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
1431
1432   if (myEntityMode & e0DElements) {
1433     if (MYDEBUG) MESSAGE("0D ELEMENTS");
1434     aFilter->RegisterCellsWithType(VTK_VERTEX);
1435     aHightFilter->RegisterCellsWithType(VTK_VERTEX);
1436   }
1437
1438   if (myEntityMode & eEdges) {
1439     if (MYDEBUG) MESSAGE("EDGES");
1440     aFilter->RegisterCellsWithType(VTK_LINE);
1441     aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
1442
1443     aHightFilter->RegisterCellsWithType(VTK_LINE);
1444     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
1445   }
1446
1447   if (myEntityMode & eFaces) {
1448     if (MYDEBUG) MESSAGE("FACES");
1449     aFilter->RegisterCellsWithType(VTK_TRIANGLE);
1450     aFilter->RegisterCellsWithType(VTK_POLYGON);
1451     aFilter->RegisterCellsWithType(VTK_QUAD);
1452     aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
1453     aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
1454
1455     aHightFilter->RegisterCellsWithType(VTK_TRIANGLE);
1456     aHightFilter->RegisterCellsWithType(VTK_POLYGON);
1457     aHightFilter->RegisterCellsWithType(VTK_QUAD);
1458     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
1459     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
1460   }
1461
1462   if (myEntityMode & eVolumes) {
1463     if (MYDEBUG) MESSAGE("VOLUMES");
1464     aFilter->RegisterCellsWithType(VTK_TETRA);
1465     aFilter->RegisterCellsWithType(VTK_VOXEL);
1466     aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1467     aFilter->RegisterCellsWithType(VTK_WEDGE);
1468     aFilter->RegisterCellsWithType(VTK_PYRAMID);
1469     aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
1470     aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
1471     aFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
1472     aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1473 //#ifdef VTK_HAVE_POLYHEDRON
1474     aFilter->RegisterCellsWithType(VTK_POLYHEDRON);
1475 //#endif
1476     
1477     aHightFilter->RegisterCellsWithType(VTK_TETRA);
1478     aHightFilter->RegisterCellsWithType(VTK_VOXEL);
1479     aHightFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1480     aHightFilter->RegisterCellsWithType(VTK_WEDGE);
1481     aHightFilter->RegisterCellsWithType(VTK_PYRAMID);
1482     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
1483     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
1484     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
1485     aHightFilter->RegisterCellsWithType(VTK_QUADRATIC_PYRAMID);
1486     aHightFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1487 //#ifdef VTK_HAVE_POLYHEDRON
1488     aHightFilter->RegisterCellsWithType(VTK_POLYHEDRON);
1489 //#endif
1490   }
1491   aFilter->Update();
1492   if (MYDEBUG) MESSAGE(aFilter->GetOutput()->GetNumberOfCells());
1493   SetVisibility(GetVisibility(),false);
1494 }
1495
1496 void SMESH_ActorDef::SetRepresentation (int theMode)
1497
1498   int aNbEdges = myVisualObj->GetNbEntities(SMDSAbs_Edge);
1499   int aNbFaces = myVisualObj->GetNbEntities(SMDSAbs_Face);
1500   int aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume);
1501
1502   if (theMode < 0) {
1503     myRepresentation = eSurface;
1504     if (!aNbFaces && !aNbVolumes && aNbEdges) {
1505       myRepresentation = eEdge;
1506     } else if (!aNbFaces && !aNbVolumes && !aNbEdges) {
1507       myRepresentation = ePoint;
1508     }
1509   } else {
1510     switch (theMode) {
1511     case eEdge:
1512       if (!aNbFaces && !aNbVolumes && !aNbEdges) return;
1513       break;
1514     case eSurface:
1515       if (!aNbFaces && !aNbVolumes) return;
1516       break;
1517     }    
1518     myRepresentation = theMode;
1519   }
1520
1521   if (!GetUnstructuredGrid()->GetNumberOfCells())
1522     myRepresentation = ePoint;
1523
1524   if (myIsShrunk) {
1525     if (myRepresentation == ePoint) {
1526       UnShrink();
1527       myIsShrunk = true;
1528     } else {
1529       SetShrink();
1530     }      
1531   }
1532
1533   myPickableActor = myBaseActor;
1534   myNodeActor->SetVisibility(false);
1535   myNodeExtActor->SetVisibility(false);
1536   vtkProperty *aProp = NULL, *aBackProp = NULL;
1537   SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::EReperesent(-1);
1538   SMESH_Actor::EQuadratic2DRepresentation aQuadraticMode = GetQuadratic2DRepresentation();
1539   switch (myRepresentation) {
1540   case ePoint:
1541     myPickableActor = myNodeActor;
1542     myNodeActor->SetVisibility(true);
1543     aQuadraticMode = SMESH_Actor::eLines;
1544     aProp = aBackProp = myNodeProp;
1545     aReperesent = SMESH_DeviceActor::ePoint;
1546     break;
1547   case eEdge:
1548     aProp = aBackProp = myEdgeProp;
1549     aReperesent = SMESH_DeviceActor::eInsideframe;
1550     break;
1551   case eSurface:
1552     aProp = mySurfaceProp;
1553     aBackProp = myBackSurfaceProp;
1554     aReperesent = SMESH_DeviceActor::eSurface;
1555     break;
1556   }
1557
1558   my2DActor->SetProperty(aProp);
1559   my2DActor->SetBackfaceProperty(aBackProp);
1560   my2DActor->SetRepresentation(aReperesent);
1561
1562   if(aQuadraticMode == SMESH_Actor::eLines)
1563     my2DActor->SetQuadraticArcMode(false);
1564   else if(aQuadraticMode == SMESH_Actor::eArcs)
1565     my2DActor->SetQuadraticArcMode(true);
1566
1567   my2DExtActor->SetRepresentation(aReperesent);
1568   
1569   my3DActor->SetProperty(aProp);
1570   my3DActor->SetBackfaceProperty(aBackProp);
1571   my3DActor->SetRepresentation(aReperesent);
1572
1573   //my0DExtActor->SetVisibility(false);
1574   my1DExtActor->SetVisibility(false);
1575   my2DExtActor->SetVisibility(false);
1576   my3DExtActor->SetVisibility(false);
1577
1578   // ???
1579   //my0DActor->SetProperty(aProp);
1580   //my0DActor->SetBackfaceProperty(aBackProp);
1581   my0DActor->SetRepresentation(aReperesent);
1582   //my0DExtActor->SetRepresentation(aReperesent);
1583
1584   switch(myControlMode){
1585   case eLength:
1586   case eMultiConnection:
1587     aProp = aBackProp = my1DProp;
1588     if(myRepresentation != ePoint)
1589       aReperesent = SMESH_DeviceActor::eInsideframe;
1590     break;
1591   }
1592   
1593   if(aQuadraticMode == SMESH_Actor::eLines)
1594     my1DActor->SetQuadraticArcMode(false);
1595   else if(aQuadraticMode == SMESH_Actor::eArcs)
1596     my1DActor->SetQuadraticArcMode(true);
1597
1598   my1DActor->SetProperty(aProp);
1599   my1DActor->SetBackfaceProperty(aBackProp);
1600   my1DActor->SetRepresentation(aReperesent);
1601
1602   my1DExtActor->SetRepresentation(aReperesent);
1603
1604   if(myIsPointsVisible)
1605     myPickableActor = myNodeActor;
1606   if(GetPointRepresentation())
1607     myNodeActor->SetVisibility(true);
1608
1609   SetMapper(myPickableActor->GetMapper());
1610
1611   SetVisibility(GetVisibility(),false);
1612
1613   Modified();
1614 }
1615
1616
1617 void SMESH_ActorDef::SetPointRepresentation(bool theIsPointsVisible){
1618   if ( myIsPointsVisible == theIsPointsVisible )
1619     return;
1620   myIsPointsVisible = theIsPointsVisible;
1621   SetRepresentation(GetRepresentation());
1622 }
1623
1624 bool SMESH_ActorDef::GetPointRepresentation(){ 
1625   return myIsPointsVisible || myIsPointsLabeled;
1626 }
1627
1628
1629 void SMESH_ActorDef::UpdateHighlight(){
1630   myHighlitableActor->SetHighlited(false);
1631   myHighlitableActor->SetVisibility(false);
1632
1633   bool anIsVisible = GetVisibility();
1634
1635   switch(myRepresentation){
1636   case SMESH_DeviceActor::eSurface:
1637   case SMESH_DeviceActor::eWireframe:
1638     {
1639       if(myIsHighlighted) {
1640         myHighlitableActor->SetProperty(myHighlightProp);
1641       }else if(myIsPreselected){
1642         myHighlitableActor->SetProperty(myPreselectProp);
1643       } else if(anIsVisible){
1644         (myRepresentation == eSurface) ? 
1645           myHighlitableActor->SetProperty(myOutLineProp) : myHighlitableActor->SetProperty(myEdgeProp);
1646       }
1647       if(GetUnstructuredGrid()->GetNumberOfCells()) {
1648         myHighlitableActor->SetHighlited(anIsVisible);
1649         myHighlitableActor->GetExtractUnstructuredGrid()->
1650           SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::eCells);
1651         myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
1652       }
1653       myHighlitableActor->SetVisibility(anIsVisible);
1654       break;
1655     }
1656   case SMESH_DeviceActor::ePoint:
1657     {
1658       if(myIsHighlighted) {
1659         myNodeActor->SetProperty(myHighlightProp);
1660       }else if(myIsPreselected) {
1661         myNodeActor->SetProperty(myPreselectProp);
1662       } else if(anIsVisible) {
1663         myNodeActor->SetProperty(myNodeProp);
1664       }
1665       myNodeActor->SetRepresentation(SMESH_DeviceActor::ePoint);
1666       myNodeActor->GetExtractUnstructuredGrid()->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
1667       break;
1668     }
1669   }
1670 }
1671
1672
1673 void SMESH_ActorDef::highlight(bool theHighlight){
1674   if ( myIsHighlighted == theHighlight )
1675     return;
1676   myIsHighlighted = theHighlight;
1677   UpdateHighlight();
1678 }
1679
1680
1681 void SMESH_ActorDef::SetPreSelected(bool thePreselect){ 
1682   if ( myIsPreselected == thePreselect )
1683     return;
1684   myIsPreselected = thePreselect; 
1685   UpdateHighlight();
1686 }
1687
1688
1689 // From vtkFollower
1690 int SMESH_ActorDef::RenderOpaqueGeometry(vtkViewport *vp)
1691 {
1692   if (myPickableActor->GetIsOpaque())
1693     {
1694     vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1695     this->Render(ren);
1696     return 1;
1697     }
1698   return 0;
1699 }
1700
1701
1702 int SMESH_ActorDef::RenderTranslucentGeometry(vtkViewport *vp)
1703 {
1704   if (!myPickableActor->GetIsOpaque())
1705     {
1706     vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1707     this->Render(ren);
1708     return 1;
1709     }
1710   return 0;
1711 }
1712
1713
1714 void SMESH_ActorDef::Render(vtkRenderer *ren){
1715   unsigned long aTime = myTimeStamp->GetMTime();
1716   unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1717   unsigned long aClippingTime = myImplicitBoolean->GetMTime();
1718   if(anObjTime > aTime || aClippingTime > aTime)
1719     Update();
1720 }
1721
1722
1723 void SMESH_ActorDef::Update(){
1724   if(MYDEBUG) MESSAGE("SMESH_ActorDef::Update");
1725
1726   if(GetControlMode() != eNone) {
1727     unsigned long aTime = myTimeStamp->GetMTime();
1728     unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1729     if (anObjTime > aTime)
1730       SetControlMode(GetControlMode(),false);
1731   }
1732   if(myIsPointsLabeled){
1733     SetPointsLabeled(myIsPointsLabeled);
1734   }
1735   if(myIsCellsLabeled){
1736     SetCellsLabeled(myIsCellsLabeled);
1737   }
1738   if(myIsFacesOriented){
1739     SetFacesOriented(myIsFacesOriented);
1740   }
1741   SetEntityMode(GetEntityMode());
1742   SetVisibility(GetVisibility());
1743   
1744   myTimeStamp->Modified();
1745   Modified();
1746 }
1747
1748
1749 void SMESH_ActorDef::ReleaseGraphicsResources(vtkWindow *renWin){
1750   SALOME_Actor::ReleaseGraphicsResources(renWin);
1751
1752   myPickableActor->ReleaseGraphicsResources(renWin);
1753 }
1754
1755
1756 static void GetColor(vtkProperty *theProperty, vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1757   vtkFloatingPointType* aColor = theProperty->GetColor();
1758   r = aColor[0];
1759   g = aColor[1];
1760   b = aColor[2];
1761 }
1762
1763
1764 void SMESH_ActorDef::SetOpacity(vtkFloatingPointType theValue){
1765   mySurfaceProp->SetOpacity(theValue);
1766   myBackSurfaceProp->SetOpacity(theValue);
1767   myEdgeProp->SetOpacity(theValue);
1768   myNodeProp->SetOpacity(theValue);
1769
1770   my1DProp->SetOpacity(theValue);
1771 }
1772
1773
1774 vtkFloatingPointType SMESH_ActorDef::GetOpacity(){
1775   return mySurfaceProp->GetOpacity();
1776 }
1777
1778
1779 void SMESH_ActorDef::SetSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b, int delta){
1780   mySurfaceProp->SetColor(r,g,b);
1781   if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
1782     if( aGroupObj->GetElementType() == SMDSAbs_Face ||
1783         aGroupObj->GetElementType() == SMDSAbs_Volume )
1784       myNameActor->SetBackgroundColor(r,g,b);
1785   
1786   myDeltaBrightness = delta;
1787   QColor bfc = Qtx::mainColorToSecondary(QColor(int(r*255),int(g*255),int(b*255)), delta);
1788   myBackSurfaceProp->SetColor( bfc.red() / 255. , bfc.green() / 255. , bfc.blue() / 255. );
1789   Modified();
1790 }
1791
1792 void SMESH_ActorDef::GetSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b, int& delta){
1793   ::GetColor(mySurfaceProp,r,g,b);
1794   my2DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1795   delta = myDeltaBrightness;
1796 }
1797
1798 void SMESH_ActorDef::SetEdgeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1799   myEdgeProp->SetColor(r,g,b);
1800   my1DProp->SetColor(r,g,b);
1801   my1DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1802   if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
1803     if( aGroupObj->GetElementType() == SMDSAbs_Edge )
1804       myNameActor->SetBackgroundColor(r,g,b);
1805   Modified();
1806 }
1807
1808 void SMESH_ActorDef::GetEdgeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1809   ::GetColor(myEdgeProp,r,g,b);
1810 }
1811
1812 void SMESH_ActorDef::SetOutlineColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1813   myOutLineProp->SetColor(r,g,b);
1814   Modified();
1815 }
1816
1817 void SMESH_ActorDef::GetOutlineColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1818   ::GetColor(myOutLineProp,r,g,b);
1819 }
1820
1821
1822 void SMESH_ActorDef::SetNodeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){ 
1823   myNodeProp->SetColor(r,g,b);
1824   myNodeExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1825   if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
1826     if( aGroupObj->GetElementType() == SMDSAbs_Node )
1827       myNameActor->SetBackgroundColor(r,g,b);
1828   Modified();
1829 }
1830
1831 void SMESH_ActorDef::GetNodeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){ 
1832   ::GetColor(myNodeProp,r,g,b);
1833 }
1834
1835 void SMESH_ActorDef::Set0DColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){ 
1836   my0DProp->SetColor(r,g,b);
1837   if( SMESH_GroupObj* aGroupObj = dynamic_cast<SMESH_GroupObj*>( myVisualObj.get() ) )
1838     if( aGroupObj->GetElementType() == SMDSAbs_0DElement )
1839       myNameActor->SetBackgroundColor(r,g,b);
1840   Modified();
1841 }
1842
1843 void SMESH_ActorDef::Get0DColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){ 
1844   ::GetColor(my0DProp,r,g,b);
1845 }
1846
1847 void SMESH_ActorDef::SetHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){ 
1848   myHighlightProp->SetColor(r,g,b);
1849   Modified();
1850 }
1851
1852 void SMESH_ActorDef::GetHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){ 
1853   ::GetColor(myHighlightProp,r,g,b);
1854 }
1855
1856 void SMESH_ActorDef::SetPreHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){ 
1857   myPreselectProp->SetColor(r,g,b);
1858   Modified();
1859 }
1860
1861 void SMESH_ActorDef::GetPreHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){ 
1862   ::GetColor(myPreselectProp,r,g,b);
1863 }
1864
1865
1866 vtkFloatingPointType SMESH_ActorDef::GetLineWidth(){
1867   return myEdgeProp->GetLineWidth();
1868 }
1869
1870
1871 void SMESH_ActorDef::SetLineWidth(vtkFloatingPointType theVal){
1872   myEdgeProp->SetLineWidth(theVal);
1873
1874   my1DProp->SetLineWidth(theVal + aLineWidthInc);
1875   my1DExtProp->SetLineWidth(theVal + aLineWidthInc);
1876
1877   Modified();
1878 }
1879
1880
1881 void SMESH_ActorDef::Set0DSize(vtkFloatingPointType theVal){
1882   my0DProp->SetPointSize(theVal);
1883   Modified();
1884 }
1885
1886 vtkFloatingPointType SMESH_ActorDef::Get0DSize(){
1887   return my0DProp->GetPointSize();
1888 }
1889
1890 int SMESH_ActorDef::GetObjDimension( const int theObjId )
1891 {
1892   return myVisualObj->GetElemDimension( theObjId );
1893 }
1894
1895 bool
1896 SMESH_ActorDef::
1897 IsImplicitFunctionUsed() const
1898 {
1899   return myBaseActor->IsImplicitFunctionUsed();
1900 }
1901
1902 void
1903 SMESH_ActorDef::SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed)
1904 {
1905   myNodeActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1906   myBaseActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1907
1908   myHighlitableActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1909
1910   myNodeExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1911
1912   my0DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1913   //my0DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1914
1915   my1DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1916   my1DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1917
1918   my2DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1919   my2DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1920   my3DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1921   my3DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1922 }
1923
1924 vtkIdType 
1925 SMESH_ActorDef::AddClippingPlane(vtkPlane* thePlane)
1926 {
1927   if(thePlane){
1928     myImplicitBoolean->GetFunction()->AddItem(thePlane);
1929     myCippingPlaneCont.push_back(thePlane);
1930     if(!IsImplicitFunctionUsed())
1931       SetImplicitFunctionUsed(true);
1932   }
1933   return myCippingPlaneCont.size();
1934 }
1935
1936 void
1937 SMESH_ActorDef::
1938 RemoveAllClippingPlanes()
1939 {
1940   myImplicitBoolean->GetFunction()->RemoveAllItems();
1941   myImplicitBoolean->GetFunction()->Modified(); // VTK bug
1942   myCippingPlaneCont.clear();
1943   SetImplicitFunctionUsed(false);
1944 }
1945
1946 vtkIdType
1947 SMESH_ActorDef::
1948 GetNumberOfClippingPlanes()
1949 {
1950   return myCippingPlaneCont.size();
1951 }
1952
1953 vtkPlane* 
1954 SMESH_ActorDef::
1955 GetClippingPlane(vtkIdType theID)
1956 {
1957   if(theID >= myCippingPlaneCont.size())
1958     return NULL;
1959   return myCippingPlaneCont[theID].Get();
1960 }
1961
1962 void SMESH_ActorDef::UpdateScalarBar()
1963 {
1964   SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
1965   if( !mgr )
1966     return;
1967
1968   vtkTextProperty* aScalarBarTitleProp = vtkTextProperty::New();
1969
1970   QColor aTColor = mgr->colorValue( "SMESH", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
1971   aScalarBarTitleProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1972
1973   aScalarBarTitleProp->SetFontFamilyToArial();
1974
1975   if ( mgr->hasValue( "SMESH", "scalar_bar_title_font" ) )
1976   {
1977     QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
1978     if ( f.family() == "Arial" )
1979       aScalarBarTitleProp->SetFontFamilyToArial();
1980     else if ( f.family() == "Courier" )
1981       aScalarBarTitleProp->SetFontFamilyToCourier();
1982     else if ( f.family() == "Times" )
1983       aScalarBarTitleProp->SetFontFamilyToTimes();
1984
1985     if ( f.bold() )
1986       aScalarBarTitleProp->BoldOn();
1987     else
1988       aScalarBarTitleProp->BoldOff();
1989
1990     if ( f.italic() )
1991       aScalarBarTitleProp->ItalicOn();
1992     else
1993      aScalarBarTitleProp->ItalicOff();
1994
1995     if ( f.overline() )
1996       aScalarBarTitleProp->ShadowOn();
1997     else
1998       aScalarBarTitleProp->ShadowOff();
1999   }
2000
2001   myScalarBarActor->SetTitleTextProperty( aScalarBarTitleProp );
2002   aScalarBarTitleProp->Delete();
2003
2004   vtkTextProperty* aScalarBarLabelProp = vtkTextProperty::New();
2005
2006   aTColor = mgr->colorValue( "SMESH", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
2007   aScalarBarLabelProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
2008
2009   aScalarBarLabelProp->SetFontFamilyToArial();
2010   if( mgr->hasValue( "SMESH", "scalar_bar_label_font" ) )
2011   {
2012     QFont f = mgr->fontValue( "SMESH", "scalar_bar_label_font" );
2013     if( f.family() == "Arial" )
2014       aScalarBarLabelProp->SetFontFamilyToArial();
2015     else if( f.family() == "Courier" )
2016       aScalarBarLabelProp->SetFontFamilyToCourier();
2017     else if( f.family() == "Times" )
2018       aScalarBarLabelProp->SetFontFamilyToTimes();
2019
2020     if ( f.bold() )
2021       aScalarBarLabelProp->BoldOn();
2022     else
2023       aScalarBarLabelProp->BoldOff();
2024
2025     if ( f.italic() )
2026       aScalarBarLabelProp->ItalicOn();
2027     else
2028       aScalarBarLabelProp->ItalicOff();
2029
2030     if( f.overline() )
2031       aScalarBarLabelProp->ShadowOn();
2032     else
2033       aScalarBarLabelProp->ShadowOff();
2034   }
2035
2036   myScalarBarActor->SetLabelTextProperty( aScalarBarLabelProp );
2037   aScalarBarLabelProp->Delete();
2038
2039   bool horiz = ( mgr->integerValue( "SMESH", "scalar_bar_orientation" ) == 1 );
2040   QString name = QString( "scalar_bar_%1_" ).arg( horiz ? "horizontal" : "vertical" );
2041   if( horiz )
2042     myScalarBarActor->SetOrientationToHorizontal();
2043   else
2044     myScalarBarActor->SetOrientationToVertical();
2045
2046
2047   vtkFloatingPointType aXVal = horiz ? 0.20 : 0.01;
2048   if( mgr->hasValue( "SMESH", name + "x" ) )
2049     aXVal = mgr->doubleValue( "SMESH", name + "x", aXVal );
2050
2051   vtkFloatingPointType aYVal = horiz ? 0.01 : 0.1;
2052   if( mgr->hasValue( "SMESH", name + "y" ) )
2053     aYVal = mgr->doubleValue( "SMESH", name + "y", aYVal );
2054   myScalarBarActor->SetPosition( aXVal, aYVal );
2055
2056   vtkFloatingPointType aWVal = horiz ? 0.60 : 0.10;
2057   if( mgr->hasValue( "SMESH", name + "width" ) )
2058     aWVal = mgr->doubleValue( "SMESH", name + "width", aWVal );
2059   myScalarBarActor->SetWidth( aWVal );
2060
2061   vtkFloatingPointType aHVal = horiz ? 0.12 : 0.80;
2062   if( mgr->hasValue( "SMESH", name + "height" ) )
2063     aHVal = mgr->doubleValue( "SMESH", name + "height", aHVal );
2064   myScalarBarActor->SetHeight( aHVal );
2065
2066   int anIntVal = 5;
2067   if( mgr->hasValue( "SMESH", "scalar_bar_num_labels" ) )
2068     anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_labels", anIntVal );
2069   myScalarBarActor->SetNumberOfLabels( anIntVal == 0 ? 5: anIntVal );
2070
2071   anIntVal = 64;
2072   if( mgr->hasValue( "SMESH", "scalar_bar_num_colors" ) )
2073     anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_colors", anIntVal );
2074   myScalarBarActor->SetMaximumNumberOfColors( anIntVal == 0 ? 64 : anIntVal );
2075
2076   bool distributionVisibility = mgr->booleanValue("SMESH","distribution_visibility");
2077   myScalarBarActor->SetDistributionVisibility(distributionVisibility);
2078
2079   int coloringType = mgr->integerValue("SMESH", "distribution_coloring_type", 0);
2080   myScalarBarActor->SetDistributionColoringType(coloringType);
2081   
2082   QColor distributionColor = mgr->colorValue("SMESH", "distribution_color",
2083                                              QColor(255, 255, 255));
2084   double rgb[3];
2085   rgb[0]= distributionColor.red()/255.;
2086   rgb[1]= distributionColor.green()/255.;
2087   rgb[2]= distributionColor.blue()/255.;
2088   myScalarBarActor->SetDistributionColor(rgb);
2089
2090   
2091 }
2092
2093 void SMESH_ActorDef::UpdateDistribution()
2094 {
2095   if(SMESH::Controls::NumericalFunctor* fun =
2096      dynamic_cast<SMESH::Controls::NumericalFunctor*>(myFunctor.get()))
2097   {
2098     int nbIntervals = myScalarBarActor->GetMaximumNumberOfColors();
2099     std::vector<int> nbEvents;
2100     std::vector<double> funValues;
2101     SMESH_VisualObjDef::TEntityList elems;
2102     if ( ! dynamic_cast<SMESH_MeshObj*>(myVisualObj.get()))
2103       dynamic_cast<SMESH_VisualObjDef*>(myVisualObj.get())->GetEntities( fun->GetType(), elems );
2104     std::vector<int> elemIds;
2105     for ( SMESH_VisualObjDef::TEntityList::iterator e = elems.begin(); e != elems.end(); ++e)
2106       elemIds.push_back( (*e)->GetID());
2107     vtkLookupTable* lookupTable = static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
2108     double * range = lookupTable->GetRange();
2109     fun->GetHistogram(nbIntervals, nbEvents, funValues, elemIds, range);
2110     myScalarBarActor->SetDistribution(nbEvents);
2111   }
2112 }
2113
2114 void SMESH_ActorDef::SetQuadratic2DRepresentation(EQuadratic2DRepresentation theMode)
2115 {
2116   switch(theMode) {
2117   case SMESH_Actor::eLines :
2118     myHighlitableActor->SetQuadraticArcMode(false);
2119     my2DActor->SetQuadraticArcMode(false);
2120     my1DActor->SetQuadraticArcMode(false);
2121     break;
2122   case SMESH_Actor::eArcs :
2123     myHighlitableActor->SetQuadraticArcMode(true);
2124     if(GetRepresentation() != SMESH_Actor::ePoint) {
2125       my2DActor->SetQuadraticArcMode(true);
2126       my1DActor->SetQuadraticArcMode(true);
2127     }
2128     break;
2129   default:
2130     break;
2131   }
2132 }
2133
2134
2135 SMESH_Actor::EQuadratic2DRepresentation SMESH_ActorDef::GetQuadratic2DRepresentation()
2136 {
2137   if(myHighlitableActor->GetQuadraticArcMode())
2138     return SMESH_Actor::eArcs;
2139   else
2140     return SMESH_Actor::eLines;
2141 }
2142
2143 void SMESH_ActorDef::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale )
2144 {
2145   SALOME_Actor::SetMarkerStd( theMarkerType, theMarkerScale );
2146   myNodeActor->SetMarkerStd( theMarkerType, theMarkerScale );
2147   myNodeExtActor->SetMarkerStd( theMarkerType, theMarkerScale );
2148 }
2149
2150 void SMESH_ActorDef::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
2151 {
2152   SALOME_Actor::SetMarkerTexture( theMarkerId, theMarkerTexture );
2153   myNodeActor->SetMarkerTexture( theMarkerId, theMarkerTexture );
2154   myNodeExtActor->SetMarkerTexture( theMarkerId, theMarkerTexture );
2155   myMarkerTexture = theMarkerTexture; // for deferred update of myHighlightActor
2156 }
2157
2158 #ifndef DISABLE_PLOT2DVIEWER
2159 SPlot2d_Histogram* SMESH_ActorDef::UpdatePlot2Histogram() {
2160
2161   if(my2dHistogram)
2162     my2dHistogram->clearAllPoints();
2163   
2164   if(SMESH::Controls::NumericalFunctor* fun =
2165      dynamic_cast<SMESH::Controls::NumericalFunctor*>(myFunctor.get()))
2166   {
2167     
2168     if(!my2dHistogram) {
2169       my2dHistogram = new SPlot2d_Histogram();
2170       Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(getIO()->getEntry(),"SMESH",getName());
2171       my2dHistogram->setIO(anIO);
2172     }
2173     
2174     int nbIntervals = myScalarBarActor->GetMaximumNumberOfColors();
2175     std::vector<int> nbEvents;
2176     std::vector<double> funValues;
2177     SMESH_VisualObjDef::TEntityList elems;
2178     if ( ! dynamic_cast<SMESH_MeshObj*>(myVisualObj.get()))
2179       dynamic_cast<SMESH_VisualObjDef*>(myVisualObj.get())->GetEntities( fun->GetType(), elems );
2180     std::vector<int> elemIds;
2181     
2182     for ( SMESH_VisualObjDef::TEntityList::iterator e = elems.begin(); e != elems.end(); ++e)
2183       elemIds.push_back( (*e)->GetID());
2184
2185     vtkLookupTable* lookupTable = static_cast<vtkLookupTable*>(myScalarBarActor->GetLookupTable());
2186     double * range = lookupTable->GetRange();
2187     fun->GetHistogram(nbIntervals, nbEvents, funValues, elemIds, range);
2188
2189     for ( int i = 0; i < std::min( nbEvents.size(), funValues.size() -1 ); i++ ) 
2190       my2dHistogram->addPoint(funValues[i] + (funValues[i+1] - funValues[i])/2.0, static_cast<double>(nbEvents[i]));
2191
2192     if(funValues.size() >= 2)
2193       my2dHistogram->setWidth((funValues[1] - funValues[0]) * 0.8) ;
2194
2195   }
2196   
2197   //Color of the histogram
2198   if(myScalarBarActor->GetDistributionColoringType() == SMESH_MULTICOLOR_TYPE)
2199     my2dHistogram->setAutoAssign(true);
2200   else {
2201     double rgb[3];
2202     myScalarBarActor->GetDistributionColor(rgb);
2203     QColor aColor = QColor( (int)( rgb[0]*255 ), (int)( rgb[1]*255 ), (int)( rgb[2]*255 ) );
2204     my2dHistogram->setColor(aColor);
2205
2206   }
2207       
2208   return my2dHistogram;
2209 }
2210 #endif