Salome HOME
0019939: EDF 762 SMESH : Definition of groups from other existing groups.
[modules/smesh.git] / src / OBJECT / SMESH_Actor.cxx
1 //  SMESH OBJECT : interactive object for SMESH visualization
2 //
3 //  Copyright (C) 2003  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 //
24 //  File   : SMESH_Actor.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SMESH
27 //  $Header$
28
29
30 #include "SMESH_ActorDef.h"
31 #include "SMESH_ActorUtils.h"
32 #include "SMESH_DeviceActor.h"
33 #include "SMESH_ControlsDef.hxx"
34 #include "VTKViewer_ExtractUnstructuredGrid.h"
35 #include "SALOME_InteractiveObject.hxx"
36
37 #include "SUIT_Session.h"
38 #include "SUIT_ResourceMgr.h"
39
40 #include <vtkProperty.h>
41 #include <vtkTimeStamp.h>
42 #include <vtkObjectFactory.h>
43 #include <vtkShrinkPolyData.h>
44 #include <vtkMergeFilter.h>
45
46 #include <vtkMatrix4x4.h>
47 #include <vtkUnstructuredGrid.h>
48 #include <vtkPointData.h>
49 #include <vtkCellData.h>
50
51 #include <vtkMapper.h>
52 #include <vtkRenderer.h>
53
54 #include <vtkCell.h>
55 #include <vtkIdList.h>
56 #include <vtkIntArray.h>
57
58 #include <vtkActor2D.h>
59 #include <vtkProperty2D.h>
60 #include <vtkPolyData.h>
61 #include <vtkMaskPoints.h>
62 #include <vtkCellCenters.h>
63 #include <vtkTextProperty.h>
64 #include <vtkLabeledDataMapper.h>
65 #include <vtkSelectVisiblePoints.h>
66
67 #include <vtkScalarBarActor.h>
68 #include <vtkLookupTable.h>
69
70 #include <vtkMath.h>
71 #include <vtkPlane.h>
72 #include <vtkImplicitBoolean.h>
73 #include <vtkImplicitFunctionCollection.h>
74
75 #include "utilities.h"
76
77 #ifdef _DEBUG_
78 static int MYDEBUG = 1;
79 #else
80 static int MYDEBUG = 0;
81 #endif
82
83 static int aLineWidthInc = 2;
84 static int aPointSizeInc = 2;
85
86
87 SMESH_ActorDef* SMESH_ActorDef::New(){
88   return new SMESH_ActorDef();
89 }
90
91
92 SMESH_Actor* SMESH_Actor::New(TVisualObjPtr theVisualObj, 
93                               const char* theEntry, 
94                               const char* theName,
95                               int theIsClear)
96 {
97   SMESH_ActorDef* anActor = SMESH_ActorDef::New();
98   if(!anActor->Init(theVisualObj,theEntry,theName,theIsClear)){
99     anActor->Delete();
100     anActor = NULL;
101   }
102   if( anActor )
103     anActor->UpdateScalarBar();
104   return anActor;
105 }
106
107
108 SMESH_ActorDef::SMESH_ActorDef()
109 {
110   if(MYDEBUG) MESSAGE("SMESH_ActorDef - "<<this);
111
112   myTimeStamp = vtkTimeStamp::New();
113
114   myIsPointsVisible = false;
115
116   myIsShrinkable = false;
117   myIsShrunk = false;
118
119   myIsFacesOriented = false;
120
121   myControlsPrecision = -1;
122   SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
123   if ( mgr && mgr->booleanValue( "SMESH", "use_precision", false ) )
124     myControlsPrecision = (long)SMESH::GetFloat( "SMESH", "controls_precision", -1 );
125
126   vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
127   vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
128
129   vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
130   VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
131
132   //Definition 2D and 3D divices of the actor
133   //-----------------------------------------
134   vtkFloatingPointType anRGB[3] = {1,1,1};
135   mySurfaceProp = vtkProperty::New();
136   SMESH::GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
137   mySurfaceProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
138
139   myBackSurfaceProp = vtkProperty::New();
140   SMESH::GetColor( "SMESH", "backface_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 0, 255 ) );
141   myBackSurfaceProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
142
143   my2DActor = SMESH_DeviceActor::New();
144   my2DActor->SetUserMatrix(aMatrix);
145   my2DActor->PickableOff();
146   my2DActor->SetProperty(mySurfaceProp);
147   my2DActor->SetBackfaceProperty(myBackSurfaceProp);
148   my2DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
149   aFilter = my2DActor->GetExtractUnstructuredGrid();
150   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
151   aFilter->RegisterCellsWithType(VTK_TRIANGLE);
152   aFilter->RegisterCellsWithType(VTK_POLYGON);
153   aFilter->RegisterCellsWithType(VTK_QUAD);
154   aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
155   aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
156
157   my3DActor = SMESH_DeviceActor::New();
158   my3DActor->SetUserMatrix(aMatrix);
159   my3DActor->PickableOff();
160   my3DActor->SetProperty(mySurfaceProp);
161   my3DActor->SetBackfaceProperty(myBackSurfaceProp);
162   my3DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
163   aFilter = my3DActor->GetExtractUnstructuredGrid();
164   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
165   aFilter->RegisterCellsWithType(VTK_TETRA);
166   aFilter->RegisterCellsWithType(VTK_VOXEL);
167   aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
168   aFilter->RegisterCellsWithType(VTK_WEDGE);
169   aFilter->RegisterCellsWithType(VTK_PYRAMID);
170   aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
171   aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
172   aFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
173   aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
174
175   //Definition 1D divice of the actor
176   //---------------------------------
177   myEdgeProp = vtkProperty::New();
178   myEdgeProp->SetAmbient(1.0);
179   myEdgeProp->SetDiffuse(0.0);
180   myEdgeProp->SetSpecular(0.0);
181   SMESH::GetColor( "SMESH", "outline_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
182   myEdgeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
183   myEdgeProp->SetLineWidth(aLineWidth);
184
185   my1DActor = SMESH_DeviceActor::New();
186   my1DActor->SetUserMatrix(aMatrix);
187   my1DActor->PickableOff();
188   my1DActor->SetHighlited(true);
189   my1DActor->SetProperty(myEdgeProp);
190   my1DActor->SetRepresentation(SMESH_DeviceActor::eSurface);
191   aFilter = my1DActor->GetExtractUnstructuredGrid();
192   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
193   aFilter->RegisterCellsWithType(VTK_LINE);
194   aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
195
196   my1DProp = vtkProperty::New();
197   my1DProp->DeepCopy(myEdgeProp);
198   my1DProp->SetLineWidth(aLineWidth + aLineWidthInc);
199   my1DProp->SetPointSize(aPointSize);
200
201   my1DExtProp = vtkProperty::New();
202   my1DExtProp->DeepCopy(myEdgeProp);
203   anRGB[0] = 1 - anRGB[0];
204   anRGB[1] = 1 - anRGB[1];
205   anRGB[2] = 1 - anRGB[2];
206   my1DExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
207   my1DExtProp->SetLineWidth(aLineWidth + aLineWidthInc);
208   my1DExtProp->SetPointSize(aPointSize + aPointSizeInc);
209
210   my1DExtActor = SMESH_DeviceActor::New();
211   my1DExtActor->SetUserMatrix(aMatrix);
212   my1DExtActor->PickableOff();
213   my1DExtActor->SetHighlited(true);
214   my1DExtActor->SetVisibility(false);
215   my1DExtActor->SetProperty(my1DExtProp);
216   my1DExtActor->SetRepresentation(SMESH_DeviceActor::eInsideframe);
217   aFilter = my1DExtActor->GetExtractUnstructuredGrid();
218   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
219   aFilter->RegisterCellsWithType(VTK_LINE);
220   aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
221
222
223   //Definition 0D divice of the actor
224   //---------------------------------
225   myNodeProp = vtkProperty::New();
226   SMESH::GetColor( "SMESH", "node_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 0, 0 ) );
227   myNodeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
228   myNodeProp->SetPointSize(aPointSize);
229
230   myNodeActor = SMESH_DeviceActor::New();
231   myNodeActor->SetUserMatrix(aMatrix);
232   myNodeActor->SetStoreClippingMapping(true);
233   myNodeActor->PickableOff();
234   myNodeActor->SetVisibility(false);
235   myNodeActor->SetProperty(myNodeProp);
236   myNodeActor->SetRepresentation(SMESH_DeviceActor::ePoint);
237   aFilter = myNodeActor->GetExtractUnstructuredGrid();
238   aFilter->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
239
240
241   //Definition of Pickable and Highlitable engines
242   //----------------------------------------------
243
244   myBaseActor = SMESH_DeviceActor::New();
245   myBaseActor->SetUserMatrix(aMatrix);
246   myBaseActor->SetStoreGemetryMapping(true);
247   myBaseActor->GetProperty()->SetOpacity(0.0);
248
249   myPickableActor = myBaseActor;
250   
251   myHighlightProp = vtkProperty::New();
252   myHighlightProp->SetAmbient(1.0);
253   myHighlightProp->SetDiffuse(0.0);
254   myHighlightProp->SetSpecular(0.0);
255   SMESH::GetColor( "SMESH", "selection_object_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
256   myHighlightProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
257   myHighlightProp->SetPointSize(aPointSize);
258   myHighlightProp->SetRepresentation(1);
259  
260   myPreselectProp = vtkProperty::New();
261   myPreselectProp->SetAmbient(1.0);
262   myPreselectProp->SetDiffuse(0.0);
263   myPreselectProp->SetSpecular(0.0);
264   SMESH::GetColor( "SMESH", "highlight_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 255, 255 ) );
265   myPreselectProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
266   myPreselectProp->SetPointSize(aPointSize);
267   myPreselectProp->SetRepresentation(1);
268
269   myHighlitableActor = SMESH_DeviceActor::New();
270   myHighlitableActor->SetUserMatrix(aMatrix);
271   myHighlitableActor->PickableOff();
272   myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
273
274   myName = "";
275   myIO = NULL;
276
277   myControlMode = eNone;
278   myControlActor = my2DActor;
279
280   //Definition of myScalarBarActor
281   //------------------------------
282   myLookupTable = vtkLookupTable::New();
283   //Fix for Bug PAL5195 - SMESH764: 
284   //Controls - Aspect Ratio: incorrect colors of the best and worst values
285   myLookupTable->SetHueRange(0.667,0.0);
286
287   myScalarBarActor = vtkScalarBarActor::New();
288   myScalarBarActor->SetVisibility(false);
289   myScalarBarActor->SetLookupTable(myLookupTable);
290
291   //Fix for Bug 13314:
292   //Incorrect "Min value" in Scalar Bar in Mesh:
293   //  myScalarBarActor->SetLabelFormat("%.4g");
294   // changes was commented because of regression bug IPAL 19981
295
296   mgr = SUIT_Session::session()->resourceMgr();
297   if( !mgr )
298     return;
299
300   //Definition of points numbering pipeline
301   //---------------------------------------
302   myPointsNumDataSet = vtkUnstructuredGrid::New();
303
304   myPtsMaskPoints = vtkMaskPoints::New();
305   myPtsMaskPoints->SetInput(myPointsNumDataSet);
306   myPtsMaskPoints->SetOnRatio(1);
307
308   myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
309   myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput());
310   myPtsSelectVisiblePoints->SelectInvisibleOff();
311   myPtsSelectVisiblePoints->SetTolerance(0.1);
312     
313   myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
314   myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
315   myPtsLabeledDataMapper->SetLabelFormat("%g");
316   myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
317     
318   vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
319   aPtsTextProp->SetFontFamilyToTimes();
320   static int aPointsFontSize = 10;
321   aPtsTextProp->SetFontSize(aPointsFontSize);
322   aPtsTextProp->SetBold(1);
323   aPtsTextProp->SetItalic(0);
324   aPtsTextProp->SetShadow(0);
325   myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
326   aPtsTextProp->Delete();
327   
328   myEntityMode = eAllEntity;
329
330   myIsPointsLabeled = false;
331
332   myPointLabels = vtkActor2D::New();
333   myPointLabels->SetMapper(myPtsLabeledDataMapper);
334   myPointLabels->GetProperty()->SetColor(1,1,1);
335   myPointLabels->SetVisibility(myIsPointsLabeled);
336
337
338   //Definition of cells numbering pipeline
339   //---------------------------------------
340   myCellsNumDataSet = vtkUnstructuredGrid::New();
341
342   myCellCenters = vtkCellCenters::New();
343   myCellCenters->SetInput(myCellsNumDataSet);
344
345   myClsMaskPoints = vtkMaskPoints::New();
346   myClsMaskPoints->SetInput(myCellCenters->GetOutput());
347   myClsMaskPoints->SetOnRatio(1);
348     
349   myClsSelectVisiblePoints = vtkSelectVisiblePoints::New();
350   myClsSelectVisiblePoints->SetInput(myClsMaskPoints->GetOutput());
351   myClsSelectVisiblePoints->SelectInvisibleOff();
352   myClsSelectVisiblePoints->SetTolerance(0.1);
353     
354   myClsLabeledDataMapper = vtkLabeledDataMapper::New();
355   myClsLabeledDataMapper->SetInput(myClsSelectVisiblePoints->GetOutput());
356   myClsLabeledDataMapper->SetLabelFormat("%g");
357   myClsLabeledDataMapper->SetLabelModeToLabelScalars();
358     
359   vtkTextProperty* aClsTextProp = vtkTextProperty::New();
360   aClsTextProp->SetFontFamilyToTimes();
361   static int aCellsFontSize = 12;
362   aClsTextProp->SetFontSize(aCellsFontSize);
363   aClsTextProp->SetBold(1);
364   aClsTextProp->SetItalic(0);
365   aClsTextProp->SetShadow(0);
366   myClsLabeledDataMapper->SetLabelTextProperty(aClsTextProp);
367   aClsTextProp->Delete();
368     
369   myIsCellsLabeled = false;
370
371   myCellsLabels = vtkActor2D::New();
372   myCellsLabels->SetMapper(myClsLabeledDataMapper);
373   myCellsLabels->GetProperty()->SetColor(0,1,0);
374   myCellsLabels->SetVisibility(myIsCellsLabeled);
375
376   // Clipping planes
377   myImplicitBoolean = vtkImplicitBoolean::New();
378   myImplicitBoolean->SetOperationTypeToIntersection();
379 }
380
381
382 SMESH_ActorDef::~SMESH_ActorDef()
383 {
384   if(MYDEBUG) MESSAGE("~SMESH_ActorDef - "<<this);
385
386   myScalarBarActor->Delete();
387   myLookupTable->Delete();
388
389   mySurfaceProp->Delete();
390   myBackSurfaceProp->Delete();
391
392   myEdgeProp->Delete();
393   myHighlightProp->Delete();
394   myPreselectProp->Delete();
395
396   myNodeProp->Delete();
397
398   my1DProp->Delete();
399   my1DActor->Delete();
400
401   my1DExtProp->Delete();
402   my1DExtActor->Delete();
403
404   my2DActor->Delete();
405   my3DActor->Delete();
406
407   myNodeActor->Delete();
408   myBaseActor->Delete();
409
410   myHighlitableActor->Delete();
411
412   //Deleting of pints numbering pipeline
413   //---------------------------------------
414   myPointsNumDataSet->Delete();
415
416   // commented: porting to vtk 5.0
417   //  myPtsLabeledDataMapper->RemoveAllInputs();
418   myPtsLabeledDataMapper->Delete();
419
420   // commented: porting to vtk 5.0
421   //  myPtsSelectVisiblePoints->UnRegisterAllOutputs();
422   myPtsSelectVisiblePoints->Delete();
423
424   // commented: porting to vtk 5.0
425   //  myPtsMaskPoints->UnRegisterAllOutputs();
426   myPtsMaskPoints->Delete();
427
428   myPointLabels->Delete();
429
430
431   //Deleting of cells numbering pipeline
432   //---------------------------------------
433   myCellsNumDataSet->Delete();
434
435   myClsLabeledDataMapper->RemoveAllInputs();
436   myClsLabeledDataMapper->Delete();
437
438   // commented: porting to vtk 5.0
439   //  myClsSelectVisiblePoints->UnRegisterAllOutputs();
440   myClsSelectVisiblePoints->Delete();
441
442   // commented: porting to vtk 5.0
443   //  myClsMaskPoints->UnRegisterAllOutputs();
444   myClsMaskPoints->Delete();
445
446   // commented: porting to vtk 5.0
447   //  myCellCenters->UnRegisterAllOutputs();
448   myCellCenters->Delete();
449
450   myCellsLabels->Delete();
451
452   myImplicitBoolean->Delete();
453
454   myTimeStamp->Delete();
455 }
456
457
458 void SMESH_ActorDef::SetPointsLabeled( bool theIsPointsLabeled )
459 {
460   vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
461   myIsPointsLabeled = theIsPointsLabeled && aGrid->GetNumberOfPoints();
462
463   if ( myIsPointsLabeled )
464   {
465     myPointsNumDataSet->ShallowCopy(aGrid);
466     vtkDataSet *aDataSet = myPointsNumDataSet;
467     
468     int aNbElem = aDataSet->GetNumberOfPoints();
469     
470     vtkIntArray *anArray = vtkIntArray::New();
471     anArray->SetNumberOfValues( aNbElem );
472     
473     for ( int anId = 0; anId < aNbElem; anId++ )
474     {
475       int aSMDSId = myVisualObj->GetNodeObjId( anId );
476       anArray->SetValue( anId, aSMDSId );
477     }
478     
479     aDataSet->GetPointData()->SetScalars( anArray );
480     anArray->Delete();
481     myPtsMaskPoints->SetInput( aDataSet );
482     myPointLabels->SetVisibility( GetVisibility() );
483   }
484   else
485   {
486     myPointLabels->SetVisibility( false );
487   }
488   SetRepresentation(GetRepresentation());
489   myTimeStamp->Modified();
490 }
491
492
493 void SMESH_ActorDef::SetCellsLabeled(bool theIsCellsLabeled)
494 {
495   vtkUnstructuredGrid* aGrid = GetUnstructuredGrid();
496   myIsCellsLabeled = theIsCellsLabeled && aGrid->GetNumberOfPoints();
497   if(myIsCellsLabeled){
498     myCellsNumDataSet->ShallowCopy(aGrid);
499     vtkDataSet *aDataSet = myCellsNumDataSet;
500     int aNbElem = aDataSet->GetNumberOfCells();
501     vtkIntArray *anArray = vtkIntArray::New();
502     anArray->SetNumberOfValues(aNbElem);
503     for(int anId = 0; anId < aNbElem; anId++){
504       int aSMDSId = myVisualObj->GetElemObjId(anId);
505       anArray->SetValue(anId,aSMDSId);
506     }
507     aDataSet->GetCellData()->SetScalars(anArray);
508     myCellCenters->SetInput(aDataSet);
509     myCellsLabels->SetVisibility(GetVisibility());
510   }else{
511     myCellsLabels->SetVisibility(false);
512   }
513   myTimeStamp->Modified();
514 }
515
516
517 void SMESH_ActorDef::SetFacesOriented(bool theIsFacesOriented)
518 {
519   myIsFacesOriented = theIsFacesOriented;
520
521   my2DActor->SetFacesOriented(theIsFacesOriented);
522   my3DActor->SetFacesOriented(theIsFacesOriented);
523
524   myTimeStamp->Modified();
525 }
526
527 bool SMESH_ActorDef::GetFacesOriented()
528 {
529   return myIsFacesOriented;
530 }
531
532
533 void 
534 SMESH_ActorDef::
535 SetControlMode(eControl theMode)
536 {
537   SetControlMode(theMode,true);
538 }
539
540
541 void 
542 SMESH_ActorDef::
543 SetControlMode(eControl theMode,
544                bool theCheckEntityMode)
545 {
546   SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();  
547   if( !mgr )
548     return;
549
550   myControlMode = eNone;
551   theCheckEntityMode &= mgr->booleanValue( "SMESH", "display_entity", false );
552
553   my1DActor->GetMapper()->SetScalarVisibility(false);
554   my2DActor->GetMapper()->SetScalarVisibility(false);
555   my3DActor->GetMapper()->SetScalarVisibility(false);
556   myScalarBarActor->SetVisibility(false);
557
558   bool anIsScalarVisible = theMode > eNone;
559
560   if(anIsScalarVisible){
561     SMESH::Controls::FunctorPtr aFunctor;
562     switch(theMode){
563     case eLength:
564     {
565       SMESH::Controls::Length* aControl = new SMESH::Controls::Length();
566       aControl->SetPrecision( myControlsPrecision );
567       aFunctor.reset( aControl );
568       myControlActor = my1DActor;
569       break;
570     }
571     case eLength2D:
572     {
573       aFunctor.reset(new SMESH::Controls::Length2D());
574       myControlActor = my2DActor;
575       break;
576     }
577     case eFreeBorders:
578       aFunctor.reset(new SMESH::Controls::FreeBorders());
579       myControlActor = my1DActor;
580       break;
581     case eFreeEdges:
582       aFunctor.reset(new SMESH::Controls::FreeEdges());
583       myControlActor = my2DActor;
584       break;
585     case eMultiConnection:
586       aFunctor.reset(new SMESH::Controls::MultiConnection());
587       myControlActor = my1DActor;
588       break;
589     case eMultiConnection2D:
590       aFunctor.reset(new SMESH::Controls::MultiConnection2D());
591       myControlActor = my2DActor;
592       break;
593     case eArea:
594     {
595       SMESH::Controls::Area* aControl = new SMESH::Controls::Area();
596       aControl->SetPrecision( myControlsPrecision );
597       aFunctor.reset( aControl );
598       myControlActor = my2DActor;
599       break;
600     }
601     case eTaper:
602     {
603       SMESH::Controls::Taper* aControl = new SMESH::Controls::Taper();
604       aControl->SetPrecision( myControlsPrecision );
605       aFunctor.reset( aControl );
606       myControlActor = my2DActor;
607       break;
608     }
609     case eAspectRatio:
610     {
611       SMESH::Controls::AspectRatio* aControl = new SMESH::Controls::AspectRatio();
612       aControl->SetPrecision( myControlsPrecision );
613       aFunctor.reset( aControl );
614       myControlActor = my2DActor;
615       break;
616     }
617     case eAspectRatio3D:
618     {
619       SMESH::Controls::AspectRatio3D* aControl = new SMESH::Controls::AspectRatio3D();
620       aControl->SetPrecision( myControlsPrecision );
621       aFunctor.reset( aControl );
622       myControlActor = my3DActor;
623       break;
624     }
625     case eVolume3D:
626     {
627       SMESH::Controls::Volume* aControl = new SMESH::Controls::Volume();
628       aControl->SetPrecision( myControlsPrecision );
629       aFunctor.reset( aControl );
630       myControlActor = my3DActor;
631       break;
632     }
633     case eMinimumAngle:
634     {
635       SMESH::Controls::MinimumAngle* aControl = new SMESH::Controls::MinimumAngle();
636       aControl->SetPrecision( myControlsPrecision );
637       aFunctor.reset( aControl );
638       myControlActor = my2DActor;
639       break;
640     }
641     case eWarping:
642     {
643       SMESH::Controls::Warping* aControl = new SMESH::Controls::Warping();
644       aControl->SetPrecision( myControlsPrecision );
645       aFunctor.reset( aControl );
646       myControlActor = my2DActor;
647       break;
648     }
649     case eSkew:
650     {
651       SMESH::Controls::Skew* aControl = new SMESH::Controls::Skew();
652       aControl->SetPrecision( myControlsPrecision );
653       aFunctor.reset( aControl );
654       myControlActor = my2DActor;
655       break;
656     }
657     default:
658       return;
659     }
660
661     vtkUnstructuredGrid* aGrid = myControlActor->GetUnstructuredGrid();
662     vtkIdType aNbCells = aGrid->GetNumberOfCells();
663     if(aNbCells){
664       myControlMode = theMode;
665       switch(myControlMode){
666       case eFreeEdges:
667       case eFreeBorders:
668         my1DExtActor->SetExtControlMode(aFunctor);
669         break;
670       case eLength2D:
671       case eMultiConnection2D:
672         my1DExtActor->SetExtControlMode(aFunctor,myScalarBarActor,myLookupTable);
673         break;
674       default:
675         myControlActor->SetControlMode(aFunctor,myScalarBarActor,myLookupTable);
676       }
677     }
678
679     if(theCheckEntityMode){
680       if(myControlActor == my1DActor)
681         SetEntityMode(eEdges);
682       else if(myControlActor == my2DActor){
683         switch(myControlMode){
684         case eLength2D:
685         case eFreeEdges:
686         case eMultiConnection2D:
687           //SetEntityMode(eEdges);
688           SetEntityMode(eFaces);
689           break;
690         default:
691           SetEntityMode(eFaces);
692         }
693       }else if(myControlActor == my3DActor)
694         SetEntityMode(eVolumes);
695     }
696
697   }else if(theCheckEntityMode){
698     myEntityMode = eAllEntity;
699   }
700
701   SetRepresentation(GetRepresentation());
702
703   myTimeStamp->Modified();
704   Modified();
705 }
706
707
708 void SMESH_ActorDef::AddToRender(vtkRenderer* theRenderer){
709   SALOME_Actor::AddToRender(theRenderer);
710
711   theRenderer->AddActor(myNodeActor);
712   theRenderer->AddActor(myBaseActor);
713
714   my3DActor->AddToRender(theRenderer);
715   my2DActor->AddToRender(theRenderer);
716
717   theRenderer->AddActor(my1DActor);
718   theRenderer->AddActor(my1DExtActor);
719
720   theRenderer->AddActor(myHighlitableActor);
721
722   theRenderer->AddActor2D(myScalarBarActor);
723
724   myPtsSelectVisiblePoints->SetRenderer(theRenderer);
725   myClsSelectVisiblePoints->SetRenderer(theRenderer);
726
727   theRenderer->AddActor2D(myPointLabels);
728   theRenderer->AddActor2D(myCellsLabels);
729 }
730
731 void SMESH_ActorDef::RemoveFromRender(vtkRenderer* theRenderer){
732   SALOME_Actor::RemoveFromRender(theRenderer);
733
734   theRenderer->RemoveActor(myNodeActor);
735   theRenderer->RemoveActor(myBaseActor);
736
737   theRenderer->RemoveActor(myHighlitableActor);
738
739   theRenderer->RemoveActor(my1DActor);
740   theRenderer->RemoveActor(my1DExtActor);
741
742   my2DActor->RemoveFromRender(theRenderer);
743   my3DActor->RemoveFromRender(theRenderer);
744
745   theRenderer->RemoveActor(myScalarBarActor);
746   theRenderer->RemoveActor(myPointLabels);
747   theRenderer->RemoveActor(myCellsLabels);
748 }
749
750
751 bool SMESH_ActorDef::Init(TVisualObjPtr theVisualObj, 
752                           const char* theEntry, 
753                           const char* theName,
754                           int theIsClear)
755 {
756   Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry,"SMESH",theName);
757   setIO(anIO);
758   setName(theName);
759
760   myVisualObj = theVisualObj;
761   myVisualObj->Update(theIsClear);
762
763   myNodeActor->Init(myVisualObj,myImplicitBoolean);
764   myBaseActor->Init(myVisualObj,myImplicitBoolean);
765   
766   myHighlitableActor->Init(myVisualObj,myImplicitBoolean);
767   
768   my1DActor->Init(myVisualObj,myImplicitBoolean);
769   my1DExtActor->Init(myVisualObj,myImplicitBoolean);
770   
771   my2DActor->Init(myVisualObj,myImplicitBoolean);
772   my3DActor->Init(myVisualObj,myImplicitBoolean);
773   
774   my1DActor->GetMapper()->SetLookupTable(myLookupTable);
775   my1DExtActor->GetMapper()->SetLookupTable(myLookupTable);
776
777   my2DActor->GetMapper()->SetLookupTable(myLookupTable);
778   my3DActor->GetMapper()->SetLookupTable(myLookupTable);
779     
780   vtkFloatingPointType aFactor, aUnits;
781   my2DActor->GetPolygonOffsetParameters(aFactor,aUnits);
782   my2DActor->SetPolygonOffsetParameters(aFactor,aUnits*0.75);
783
784   SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
785   if( !mgr )
786     return false;
787
788   //SetIsShrunkable(theGrid->GetNumberOfCells() > 10);
789   SetIsShrunkable(true);
790
791   SetShrinkFactor( SMESH::GetFloat( "SMESH:shrink_coeff", 75 ) / 100. );
792
793   int aMode = mgr->integerValue( "SMESH", "display_mode" );
794   SetRepresentation(-1);
795   
796   if(aMode == 0){
797     SetRepresentation(eEdge);
798   }else if(aMode == 1){
799     SetRepresentation(eSurface);
800   }else if(aMode == 2){
801     SetRepresentation(ePoint);
802   }
803   
804   if(aMode == 3){
805     SetShrink();
806   }
807
808   myTimeStamp->Modified();
809   Modified();
810   return true;
811 }
812
813
814 vtkFloatingPointType* SMESH_ActorDef::GetBounds(){
815   return myNodeActor->GetBounds();
816 }
817
818
819 vtkDataSet* SMESH_ActorDef::GetInput(){
820   return GetUnstructuredGrid();
821 }
822
823
824 void SMESH_ActorDef::SetTransform(VTKViewer_Transform* theTransform){
825   Superclass::SetTransform(theTransform);
826
827   myNodeActor->SetTransform(theTransform);
828   myBaseActor->SetTransform(theTransform);
829
830   myHighlitableActor->SetTransform(theTransform);
831
832   my1DActor->SetTransform(theTransform);
833   my1DExtActor->SetTransform(theTransform);
834
835   my2DActor->SetTransform(theTransform);
836   my3DActor->SetTransform(theTransform);
837
838   Modified();
839 }
840
841
842 void SMESH_ActorDef::SetMapper(vtkMapper* theMapper){
843   vtkLODActor::SetMapper(theMapper);
844 }
845
846
847 void SMESH_ActorDef::ShallowCopy(vtkProp *prop){
848   SALOME_Actor::ShallowCopy(prop);
849 }
850
851
852 vtkMapper* SMESH_ActorDef::GetMapper(){
853   return myPickableActor->GetMapper();
854 }
855
856
857 vtkUnstructuredGrid* SMESH_ActorDef::GetUnstructuredGrid(){ 
858   return myVisualObj->GetUnstructuredGrid();
859 }
860
861
862 bool SMESH_ActorDef::IsInfinitive(){
863   vtkDataSet *aDataSet = myPickableActor->GetUnstructuredGrid();
864   aDataSet->Update();
865   myIsInfinite = aDataSet->GetNumberOfCells() == 0 ||
866     aDataSet->GetNumberOfCells() == 1 && 
867     aDataSet->GetCell(0)->GetCellType() == VTK_VERTEX;
868   return SALOME_Actor::IsInfinitive();
869 }
870
871
872 void SMESH_ActorDef::SetIsShrunkable(bool theShrunkable){
873   if ( myIsShrinkable == theShrunkable )
874     return;
875   myIsShrinkable = theShrunkable;
876   Modified();
877 }
878
879 vtkFloatingPointType SMESH_ActorDef::GetShrinkFactor(){
880   return myBaseActor->GetShrinkFactor();
881 }
882
883 void SMESH_ActorDef::SetShrinkFactor(vtkFloatingPointType theValue){
884   myBaseActor->SetShrinkFactor(theValue);
885
886   my1DActor->SetShrinkFactor(theValue);
887   my1DExtActor->SetShrinkFactor(theValue);
888
889   my2DActor->SetShrinkFactor(theValue);
890   my3DActor->SetShrinkFactor(theValue);
891
892   Modified();
893 }
894
895 void SMESH_ActorDef::SetShrink(){
896   if(!myIsShrinkable) return;
897
898   myBaseActor->SetShrink();
899
900   my1DActor->SetShrink();
901   my1DExtActor->SetShrink();
902
903   my2DActor->SetShrink();
904   my3DActor->SetShrink();
905
906   myIsShrunk = true;
907   Modified();
908 }
909
910 void SMESH_ActorDef::UnShrink(){
911   if(!myIsShrunk) return;
912
913   myBaseActor->UnShrink();
914
915   my1DActor->UnShrink();
916   my1DExtActor->UnShrink();
917
918   my2DActor->UnShrink();
919   my3DActor->UnShrink();
920
921   myIsShrunk = false;
922   Modified();
923 }
924
925
926 int SMESH_ActorDef::GetNodeObjId(int theVtkID){
927   return myPickableActor->GetNodeObjId(theVtkID);
928 }
929
930 vtkFloatingPointType* SMESH_ActorDef::GetNodeCoord(int theObjID){
931   return myPickableActor->GetNodeCoord(theObjID);
932 }
933
934
935 int SMESH_ActorDef::GetElemObjId(int theVtkID){
936   return myPickableActor->GetElemObjId(theVtkID);
937 }
938
939 vtkCell* SMESH_ActorDef::GetElemCell(int theObjID){
940   return myPickableActor->GetElemCell(theObjID);
941 }
942
943
944 void SMESH_ActorDef::SetVisibility(int theMode){
945   SetVisibility(theMode,true);
946 }
947
948
949 void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation){
950   SALOME_Actor::SetVisibility(theMode);
951
952   myNodeActor->VisibilityOff();
953   myBaseActor->VisibilityOff();
954   
955   my1DActor->VisibilityOff();
956   my1DExtActor->VisibilityOff();
957   
958   my2DActor->VisibilityOff();
959   my3DActor->VisibilityOff();
960   
961   myScalarBarActor->VisibilityOff();
962   myPointLabels->VisibilityOff();
963   myCellsLabels->VisibilityOff();
964   
965   if(GetVisibility()){
966     if(theIsUpdateRepersentation)
967       SetRepresentation(GetRepresentation());
968
969     if(myControlMode != eNone){
970       switch(myControlMode){
971       case eFreeEdges:
972       case eFreeBorders:
973         my1DExtActor->VisibilityOn();
974         break;
975       case eLength2D:
976       case eMultiConnection2D:
977         my1DExtActor->VisibilityOn();
978       default:
979         if(myControlActor->GetUnstructuredGrid()->GetNumberOfCells())
980           myScalarBarActor->VisibilityOn();
981       }
982     }
983
984     if(myRepresentation != ePoint)
985       myPickableActor->VisibilityOn();
986     else {
987       myNodeActor->VisibilityOn();
988     }
989
990     if(myEntityMode & eEdges){
991       my1DActor->VisibilityOn();
992     }
993     
994     if(myEntityMode & eFaces){
995       my2DActor->VisibilityOn();
996     }
997     
998     if(myEntityMode & eVolumes){
999       my3DActor->VisibilityOn();
1000     }
1001     
1002     if(myIsPointsLabeled){ 
1003       myPointLabels->VisibilityOn();
1004       myNodeActor->VisibilityOn();
1005     }
1006
1007     if(myIsCellsLabeled) 
1008       myCellsLabels->VisibilityOn();
1009   }
1010   UpdateHighlight();
1011   Modified();
1012 }
1013
1014
1015 void SMESH_ActorDef::SetEntityMode(unsigned int theMode){
1016   myEntityState = eAllEntity;
1017
1018   if(!myVisualObj->GetNbEntities(SMDSAbs_Edge)){
1019     myEntityState &= ~eEdges;
1020     theMode &= ~eEdges;
1021   }
1022
1023   if(!myVisualObj->GetNbEntities(SMDSAbs_Face)){
1024     myEntityState &= ~eFaces;
1025     theMode &= ~eFaces;
1026   }
1027
1028   if(!myVisualObj->GetNbEntities(SMDSAbs_Volume)){
1029     myEntityState &= ~eVolumes;
1030     theMode &= ~eVolumes;
1031   }
1032
1033   if(!theMode){
1034     if(myVisualObj->GetNbEntities(SMDSAbs_Edge))
1035       theMode |= eEdges;
1036
1037     if(myVisualObj->GetNbEntities(SMDSAbs_Face))
1038       theMode |= eFaces;
1039
1040     if(myVisualObj->GetNbEntities(SMDSAbs_Volume))
1041       theMode |= eVolumes;
1042   }
1043
1044   myBaseActor->myGeomFilter->SetInside(myEntityMode != myEntityState);
1045
1046   myEntityMode = theMode;
1047   VTKViewer_ExtractUnstructuredGrid* aFilter = NULL;
1048   aFilter = myBaseActor->GetExtractUnstructuredGrid();
1049   aFilter->ClearRegisteredCellsWithType();
1050   aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
1051   
1052   if(myEntityMode & eEdges){
1053     if (MYDEBUG) MESSAGE("EDGES");
1054     aFilter->RegisterCellsWithType(VTK_LINE);
1055     aFilter->RegisterCellsWithType(VTK_QUADRATIC_EDGE);
1056   }
1057
1058   if(myEntityMode & eFaces){
1059     if (MYDEBUG) MESSAGE("FACES");
1060     aFilter->RegisterCellsWithType(VTK_TRIANGLE);
1061     aFilter->RegisterCellsWithType(VTK_POLYGON);
1062     aFilter->RegisterCellsWithType(VTK_QUAD);
1063     aFilter->RegisterCellsWithType(VTK_QUADRATIC_TRIANGLE);
1064     aFilter->RegisterCellsWithType(VTK_QUADRATIC_QUAD);
1065   }
1066
1067   if(myEntityMode & eVolumes){
1068     if (MYDEBUG) MESSAGE("VOLUMES");
1069     aFilter->RegisterCellsWithType(VTK_TETRA);
1070     aFilter->RegisterCellsWithType(VTK_VOXEL);
1071     aFilter->RegisterCellsWithType(VTK_HEXAHEDRON);
1072     aFilter->RegisterCellsWithType(VTK_WEDGE);
1073     aFilter->RegisterCellsWithType(VTK_PYRAMID);
1074     aFilter->RegisterCellsWithType(VTK_QUADRATIC_TETRA);
1075     aFilter->RegisterCellsWithType(VTK_QUADRATIC_HEXAHEDRON);
1076     aFilter->RegisterCellsWithType(VTK_QUADRATIC_WEDGE);
1077     aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET);
1078   }
1079   aFilter->Update();
1080   if (MYDEBUG) MESSAGE(aFilter->GetOutput()->GetNumberOfCells());
1081   SetVisibility(GetVisibility(),false);
1082 }
1083
1084 void SMESH_ActorDef::SetRepresentation(int theMode){ 
1085   int aNbEdges = myVisualObj->GetNbEntities(SMDSAbs_Edge);
1086   int aNbFaces = myVisualObj->GetNbEntities(SMDSAbs_Face);
1087   int aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume);
1088   if(theMode < 0){
1089     myRepresentation = eSurface;
1090     if(!aNbFaces && !aNbVolumes && aNbEdges){
1091       myRepresentation = eEdge;
1092     }else if(!aNbFaces && !aNbVolumes && !aNbEdges){
1093       myRepresentation = ePoint;
1094     }
1095   }else{
1096     switch(theMode){
1097     case eEdge:
1098       if(!aNbFaces && !aNbVolumes && !aNbEdges) return;
1099       break;
1100     case eSurface:
1101       if(!aNbFaces && !aNbVolumes) return;
1102       break;
1103     }    
1104     myRepresentation = theMode;
1105   }
1106
1107   if(!GetUnstructuredGrid()->GetNumberOfCells())
1108     myRepresentation = ePoint;
1109
1110   if(myIsShrunk){
1111     if(myRepresentation == ePoint){
1112       UnShrink();
1113       myIsShrunk = true;
1114     }else{
1115       SetShrink();
1116     }      
1117   }
1118
1119   myPickableActor = myBaseActor;
1120   myNodeActor->SetVisibility(false);
1121   vtkProperty *aProp = NULL, *aBackProp = NULL;
1122   SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::EReperesent(-1);
1123   switch(myRepresentation){
1124   case ePoint:
1125     myPickableActor = myNodeActor;
1126     myNodeActor->SetVisibility(true);
1127     
1128     aProp = aBackProp = myNodeProp;
1129     aReperesent = SMESH_DeviceActor::ePoint;
1130     break;
1131   case eEdge:
1132     aProp = aBackProp = myEdgeProp;
1133     aReperesent = SMESH_DeviceActor::eInsideframe;
1134     break;
1135   case eSurface:
1136     aProp = mySurfaceProp;
1137     aBackProp = myBackSurfaceProp;
1138     aReperesent = SMESH_DeviceActor::eSurface;
1139     break;
1140   }    
1141
1142   my2DActor->SetProperty(aProp);
1143   my2DActor->SetBackfaceProperty(aBackProp);
1144   my2DActor->SetRepresentation(aReperesent);
1145   
1146   my3DActor->SetProperty(aProp);
1147   my3DActor->SetBackfaceProperty(aBackProp);
1148   my3DActor->SetRepresentation(aReperesent);
1149
1150   my1DExtActor->SetVisibility(false);
1151
1152   switch(myControlMode){
1153   case eLength:
1154   case eMultiConnection:
1155     aProp = aBackProp = my1DProp;
1156     if(myRepresentation != ePoint)
1157       aReperesent = SMESH_DeviceActor::eInsideframe;
1158     break;
1159   }
1160   
1161   my1DActor->SetProperty(aProp);
1162   my1DActor->SetBackfaceProperty(aBackProp);
1163   my1DActor->SetRepresentation(aReperesent);
1164
1165   my1DExtActor->SetRepresentation(aReperesent);
1166   
1167   if(myIsPointsVisible)
1168     myPickableActor = myNodeActor;
1169   if(GetPointRepresentation())
1170     myNodeActor->SetVisibility(true);
1171
1172   SetMapper(myPickableActor->GetMapper());
1173
1174   SetVisibility(GetVisibility(),false);
1175
1176   Modified();
1177 }
1178
1179
1180 void SMESH_ActorDef::SetPointRepresentation(bool theIsPointsVisible){
1181   if ( myIsPointsVisible == theIsPointsVisible )
1182     return;
1183   myIsPointsVisible = theIsPointsVisible;
1184   SetRepresentation(GetRepresentation());
1185 }
1186
1187 bool SMESH_ActorDef::GetPointRepresentation(){ 
1188   return myIsPointsVisible || myIsPointsLabeled;
1189 }
1190
1191
1192 void SMESH_ActorDef::UpdateHighlight(){
1193   myHighlitableActor->SetVisibility(false);
1194   myHighlitableActor->SetHighlited(false);
1195
1196   if(myIsHighlighted){
1197     myHighlitableActor->SetProperty(myHighlightProp);
1198   }else if(myIsPreselected){
1199     myHighlitableActor->SetProperty(myPreselectProp);
1200   }
1201
1202   bool anIsVisible = GetVisibility();
1203
1204   if(myIsHighlighted || myIsPreselected){
1205     if(GetUnstructuredGrid()->GetNumberOfCells()){
1206       myHighlitableActor->SetHighlited(anIsVisible);
1207       myHighlitableActor->SetVisibility(anIsVisible);
1208       myHighlitableActor->GetExtractUnstructuredGrid()->
1209         SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::eCells);
1210       myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe);
1211     }else if(myRepresentation == ePoint || GetPointRepresentation()){
1212       myHighlitableActor->SetHighlited(anIsVisible);
1213       myHighlitableActor->GetExtractUnstructuredGrid()->
1214         SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints);
1215       myHighlitableActor->SetVisibility(anIsVisible);
1216       myHighlitableActor->SetRepresentation(SMESH_DeviceActor::ePoint);
1217     }
1218   }
1219 }
1220
1221
1222 void SMESH_ActorDef::highlight(bool theHighlight){
1223   if ( myIsHighlighted == theHighlight )
1224     return;
1225   myIsHighlighted = theHighlight;
1226   UpdateHighlight();
1227 }
1228
1229
1230 void SMESH_ActorDef::SetPreSelected(bool thePreselect){ 
1231   if ( myIsPreselected == thePreselect )
1232     return;
1233   myIsPreselected = thePreselect; 
1234   UpdateHighlight();
1235 }
1236
1237
1238 // From vtkFollower
1239 int SMESH_ActorDef::RenderOpaqueGeometry(vtkViewport *vp)
1240 {
1241   if (myPickableActor->GetIsOpaque())
1242     {
1243     vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1244     this->Render(ren);
1245     return 1;
1246     }
1247   return 0;
1248 }
1249
1250
1251 int SMESH_ActorDef::RenderTranslucentGeometry(vtkViewport *vp)
1252 {
1253   if (!myPickableActor->GetIsOpaque())
1254     {
1255     vtkRenderer *ren = static_cast<vtkRenderer *>(vp);
1256     this->Render(ren);
1257     return 1;
1258     }
1259   return 0;
1260 }
1261
1262
1263 void SMESH_ActorDef::Render(vtkRenderer *ren){
1264   unsigned long aTime = myTimeStamp->GetMTime();
1265   unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1266   unsigned long aClippingTime = myImplicitBoolean->GetMTime();
1267   if(anObjTime > aTime || aClippingTime > aTime)
1268     Update();
1269 }
1270
1271
1272 void SMESH_ActorDef::Update(){
1273   if(MYDEBUG) MESSAGE("SMESH_ActorDef::Update");
1274
1275   if(GetControlMode() != eNone) {
1276     unsigned long aTime = myTimeStamp->GetMTime();
1277     unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime();
1278     if (anObjTime > aTime)
1279       SetControlMode(GetControlMode(),false);
1280   }
1281   if(myIsPointsLabeled){
1282     SetPointsLabeled(myIsPointsLabeled);
1283   }
1284   if(myIsCellsLabeled){
1285     SetCellsLabeled(myIsCellsLabeled);
1286   }
1287   if(myIsFacesOriented){
1288     SetFacesOriented(myIsFacesOriented);
1289   }
1290   SetEntityMode(GetEntityMode());
1291   SetVisibility(GetVisibility());
1292   
1293   myTimeStamp->Modified();
1294   Modified();
1295 }
1296
1297
1298 void SMESH_ActorDef::ReleaseGraphicsResources(vtkWindow *renWin){
1299   SALOME_Actor::ReleaseGraphicsResources(renWin);
1300
1301   myPickableActor->ReleaseGraphicsResources(renWin);
1302 }
1303
1304
1305 static void GetColor(vtkProperty *theProperty, vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1306   vtkFloatingPointType* aColor = theProperty->GetColor();
1307   r = aColor[0];
1308   g = aColor[1];
1309   b = aColor[2];
1310 }
1311
1312
1313 void SMESH_ActorDef::SetOpacity(vtkFloatingPointType theValue){
1314   mySurfaceProp->SetOpacity(theValue);
1315   myBackSurfaceProp->SetOpacity(theValue);
1316   myEdgeProp->SetOpacity(theValue);
1317   myNodeProp->SetOpacity(theValue);
1318
1319   my1DProp->SetOpacity(theValue);
1320 }
1321
1322
1323 vtkFloatingPointType SMESH_ActorDef::GetOpacity(){
1324   return mySurfaceProp->GetOpacity();
1325 }
1326
1327
1328 void SMESH_ActorDef::SetSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1329   mySurfaceProp->SetColor(r,g,b);
1330   Modified();
1331 }
1332
1333 void SMESH_ActorDef::GetSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1334   ::GetColor(mySurfaceProp,r,g,b);
1335 }
1336
1337 void SMESH_ActorDef::SetBackSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1338   myBackSurfaceProp->SetColor(r,g,b);
1339   Modified();
1340 }
1341
1342 void SMESH_ActorDef::GetBackSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1343   ::GetColor(myBackSurfaceProp,r,g,b);
1344 }
1345
1346 void SMESH_ActorDef::SetEdgeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){
1347   myEdgeProp->SetColor(r,g,b);
1348   my1DProp->SetColor(r,g,b);
1349   my1DExtProp->SetColor(1.0-r,1.0-g,1.0-b);
1350   Modified();
1351 }
1352
1353 void SMESH_ActorDef::GetEdgeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){
1354   ::GetColor(myEdgeProp,r,g,b);
1355 }
1356
1357 void SMESH_ActorDef::SetNodeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){ 
1358   myNodeProp->SetColor(r,g,b);
1359   Modified();
1360 }
1361
1362 void SMESH_ActorDef::GetNodeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){ 
1363   ::GetColor(myNodeProp,r,g,b);
1364 }
1365
1366 void SMESH_ActorDef::SetHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){ 
1367   myHighlightProp->SetColor(r,g,b);
1368   Modified();
1369 }
1370
1371 void SMESH_ActorDef::GetHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){ 
1372   ::GetColor(myHighlightProp,r,g,b);
1373 }
1374
1375 void SMESH_ActorDef::SetPreHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){ 
1376   myPreselectProp->SetColor(r,g,b);
1377   Modified();
1378 }
1379
1380 void SMESH_ActorDef::GetPreHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b){ 
1381   ::GetColor(myPreselectProp,r,g,b);
1382 }
1383
1384
1385 vtkFloatingPointType SMESH_ActorDef::GetLineWidth(){
1386   return myEdgeProp->GetLineWidth();
1387 }
1388
1389
1390 void SMESH_ActorDef::SetLineWidth(vtkFloatingPointType theVal){
1391   myEdgeProp->SetLineWidth(theVal);
1392
1393   my1DProp->SetLineWidth(theVal + aLineWidthInc);
1394   my1DExtProp->SetLineWidth(theVal + aLineWidthInc);
1395
1396   Modified();
1397 }
1398
1399
1400 void SMESH_ActorDef::SetNodeSize(vtkFloatingPointType theVal){
1401   myNodeProp->SetPointSize(theVal);
1402   myHighlightProp->SetPointSize(theVal);
1403   myPreselectProp->SetPointSize(theVal);
1404
1405   my1DProp->SetPointSize(theVal + aPointSizeInc);
1406   my1DExtProp->SetPointSize(theVal + aPointSizeInc);
1407
1408   Modified();
1409 }
1410
1411 vtkFloatingPointType SMESH_ActorDef::GetNodeSize(){
1412   return myNodeProp->GetPointSize();
1413 }
1414
1415 int SMESH_ActorDef::GetObjDimension( const int theObjId )
1416 {
1417   return myVisualObj->GetElemDimension( theObjId );
1418 }
1419
1420 bool
1421 SMESH_ActorDef::
1422 IsImplicitFunctionUsed() const
1423 {
1424   return myBaseActor->IsImplicitFunctionUsed();
1425 }
1426
1427 void
1428 SMESH_ActorDef::
1429 SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed)
1430 {
1431   myNodeActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1432   myBaseActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1433   
1434   myHighlitableActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1435   
1436   my1DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1437   my1DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1438   
1439   my2DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1440   my3DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed);
1441 }
1442
1443 vtkIdType 
1444 SMESH_ActorDef::
1445 AddClippingPlane(vtkPlane* thePlane)
1446 {
1447   if(thePlane){
1448     myImplicitBoolean->GetFunction()->AddItem(thePlane);
1449     myCippingPlaneCont.push_back(thePlane);
1450     if(!IsImplicitFunctionUsed())
1451       SetImplicitFunctionUsed(true);
1452   }
1453   return myCippingPlaneCont.size();
1454 }
1455
1456 void
1457 SMESH_ActorDef::
1458 RemoveAllClippingPlanes()
1459 {
1460   myImplicitBoolean->GetFunction()->RemoveAllItems();
1461   myImplicitBoolean->GetFunction()->Modified(); // VTK bug
1462   myCippingPlaneCont.clear();
1463   SetImplicitFunctionUsed(false);
1464 }
1465
1466 vtkIdType
1467 SMESH_ActorDef::
1468 GetNumberOfClippingPlanes()
1469 {
1470   return myCippingPlaneCont.size();
1471 }
1472
1473 vtkPlane* 
1474 SMESH_ActorDef::
1475 GetClippingPlane(vtkIdType theID)
1476 {
1477   if(theID >= myCippingPlaneCont.size())
1478     return NULL;
1479   return myCippingPlaneCont[theID].Get();
1480 }
1481
1482
1483 static void ComputeBoundsParam(vtkDataSet* theDataSet,
1484                                vtkFloatingPointType theDirection[3], vtkFloatingPointType theMinPnt[3],
1485                                vtkFloatingPointType& theMaxBoundPrj, vtkFloatingPointType& theMinBoundPrj)
1486 {
1487   vtkFloatingPointType aBounds[6];
1488   theDataSet->GetBounds(aBounds);
1489
1490   //Enlarge bounds in order to avoid conflicts of precision
1491   for(int i = 0; i < 6; i += 2){
1492     static double EPS = 1.0E-3;
1493     vtkFloatingPointType aDelta = (aBounds[i+1] - aBounds[i])*EPS;
1494     aBounds[i] -= aDelta;
1495     aBounds[i+1] += aDelta;
1496   }
1497
1498   vtkFloatingPointType aBoundPoints[8][3] = { {aBounds[0],aBounds[2],aBounds[4]},
1499                                {aBounds[1],aBounds[2],aBounds[4]},
1500                                {aBounds[0],aBounds[3],aBounds[4]},
1501                                {aBounds[1],aBounds[3],aBounds[4]},
1502                                {aBounds[0],aBounds[2],aBounds[5]},
1503                                {aBounds[1],aBounds[2],aBounds[5]}, 
1504                                {aBounds[0],aBounds[3],aBounds[5]}, 
1505                                {aBounds[1],aBounds[3],aBounds[5]}};
1506
1507   int aMaxId = 0, aMinId = aMaxId;
1508   theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
1509   theMinBoundPrj = theMaxBoundPrj;
1510   for(int i = 1; i < 8; i++){
1511     vtkFloatingPointType aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
1512     if(theMaxBoundPrj < aTmp){
1513       theMaxBoundPrj = aTmp;
1514       aMaxId = i;
1515     }
1516     if(theMinBoundPrj > aTmp){
1517       theMinBoundPrj = aTmp;
1518       aMinId = i;
1519     }
1520   }
1521   vtkFloatingPointType *aMinPnt = aBoundPoints[aMaxId];
1522   theMinPnt[0] = aMinPnt[0];
1523   theMinPnt[1] = aMinPnt[1];
1524   theMinPnt[2] = aMinPnt[2];
1525 }
1526
1527
1528 static void DistanceToPosition(vtkDataSet* theDataSet,
1529                                vtkFloatingPointType theDirection[3], vtkFloatingPointType theDist, vtkFloatingPointType thePos[3])
1530 {
1531   vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1532   ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1533   vtkFloatingPointType aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
1534   thePos[0] = aMinPnt[0]-theDirection[0]*aLength;
1535   thePos[1] = aMinPnt[1]-theDirection[1]*aLength;
1536   thePos[2] = aMinPnt[2]-theDirection[2]*aLength;
1537 }
1538
1539
1540 static void PositionToDistance(vtkDataSet* theDataSet, 
1541                                vtkFloatingPointType theDirection[3], vtkFloatingPointType thePos[3], vtkFloatingPointType& theDist)
1542 {
1543   vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
1544   ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
1545   vtkFloatingPointType aPrj = vtkMath::Dot(theDirection,thePos);
1546   theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
1547 }
1548
1549
1550 void SMESH_ActorDef::SetPlaneParam(vtkFloatingPointType theDir[3], vtkFloatingPointType theDist, vtkPlane* thePlane)
1551 {
1552   thePlane->SetNormal(theDir);
1553   vtkFloatingPointType anOrigin[3];
1554   ::DistanceToPosition(GetUnstructuredGrid(),theDir,theDist,anOrigin);
1555   thePlane->SetOrigin(anOrigin);
1556 }
1557
1558
1559 void SMESH_ActorDef::GetPlaneParam(vtkFloatingPointType theDir[3], vtkFloatingPointType& theDist, vtkPlane* thePlane)
1560 {
1561   thePlane->GetNormal(theDir);
1562
1563   vtkFloatingPointType anOrigin[3];
1564   thePlane->GetOrigin(anOrigin);
1565   ::PositionToDistance(GetUnstructuredGrid(),theDir,anOrigin,theDist);
1566 }
1567
1568 void SMESH_ActorDef::UpdateScalarBar()
1569 {
1570   SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
1571   if( !mgr )
1572     return;
1573
1574   vtkTextProperty* aScalarBarTitleProp = vtkTextProperty::New();
1575
1576   QColor aTColor = mgr->colorValue( "SMESH", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
1577   aScalarBarTitleProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1578
1579   aScalarBarTitleProp->SetFontFamilyToArial();
1580
1581   if ( mgr->hasValue( "SMESH", "scalar_bar_title_font" ) )
1582   {
1583     QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" );
1584     if ( f.family() == "Arial" )
1585       aScalarBarTitleProp->SetFontFamilyToArial();
1586     else if ( f.family() == "Courier" )
1587       aScalarBarTitleProp->SetFontFamilyToCourier();
1588     else if ( f.family() == "Times" )
1589       aScalarBarTitleProp->SetFontFamilyToTimes();
1590
1591     if ( f.bold() )
1592       aScalarBarTitleProp->BoldOn();
1593     else
1594       aScalarBarTitleProp->BoldOff();
1595
1596     if ( f.italic() )
1597       aScalarBarTitleProp->ItalicOn();
1598     else
1599      aScalarBarTitleProp->ItalicOff();
1600
1601     if ( f.underline() )
1602       aScalarBarTitleProp->ShadowOn();
1603     else
1604       aScalarBarTitleProp->ShadowOff();
1605   }
1606
1607   myScalarBarActor->SetTitleTextProperty( aScalarBarTitleProp );
1608   aScalarBarTitleProp->Delete();
1609
1610   vtkTextProperty* aScalarBarLabelProp = vtkTextProperty::New();
1611
1612   aTColor = mgr->colorValue( "SMESH", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
1613   aScalarBarLabelProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. );
1614
1615   aScalarBarLabelProp->SetFontFamilyToArial();
1616   if( mgr->hasValue( "SMESH", "scalar_bar_label_font" ) )
1617   {
1618     QFont f = mgr->fontValue( "SMESH", "scalar_bar_label_font" );
1619     if( f.family() == "Arial" )
1620       aScalarBarLabelProp->SetFontFamilyToArial();
1621     else if( f.family() == "Courier" )
1622       aScalarBarLabelProp->SetFontFamilyToCourier();
1623     else if( f.family() == "Times" )
1624       aScalarBarLabelProp->SetFontFamilyToTimes();
1625
1626     if ( f.bold() )
1627       aScalarBarLabelProp->BoldOn();
1628     else
1629       aScalarBarLabelProp->BoldOff();
1630
1631     if ( f.italic() )
1632       aScalarBarLabelProp->ItalicOn();
1633     else
1634       aScalarBarLabelProp->ItalicOff();
1635
1636     if( f.underline() )
1637       aScalarBarLabelProp->ShadowOn();
1638     else
1639       aScalarBarLabelProp->ShadowOff();
1640   }
1641
1642   myScalarBarActor->SetLabelTextProperty( aScalarBarLabelProp );
1643   aScalarBarLabelProp->Delete();
1644
1645   bool horiz = ( mgr->integerValue( "SMESH", "scalar_bar_orientation" ) == 1 );
1646   QString name = QString( "scalar_bar_%1_" ).arg( horiz ? "horizontal" : "vertical" );
1647   if( horiz )
1648     myScalarBarActor->SetOrientationToHorizontal();
1649   else
1650     myScalarBarActor->SetOrientationToVertical();
1651
1652
1653   vtkFloatingPointType aXVal = horiz ? 0.20 : 0.01;
1654   if( mgr->hasValue( "SMESH", name + "x" ) )
1655     aXVal = mgr->doubleValue( "SMESH", name + "x", aXVal );
1656
1657   vtkFloatingPointType aYVal = horiz ? 0.01 : 0.1;
1658   if( mgr->hasValue( "SMESH", name + "y" ) )
1659     aYVal = mgr->doubleValue( "SMESH", name + "y", aYVal );
1660   myScalarBarActor->SetPosition( aXVal, aYVal );
1661
1662   vtkFloatingPointType aWVal = horiz ? 0.60 : 0.10;
1663   if( mgr->hasValue( "SMESH", name + "width" ) )
1664     aWVal = mgr->doubleValue( "SMESH", name + "width", aWVal );
1665   myScalarBarActor->SetWidth( aWVal );
1666
1667   vtkFloatingPointType aHVal = horiz ? 0.12 : 0.80;
1668   if( mgr->hasValue( "SMESH", name + "height" ) )
1669     aHVal = mgr->doubleValue( "SMESH", name + "height", aHVal );
1670   myScalarBarActor->SetHeight( aHVal );
1671
1672   int anIntVal = 5;
1673   if( mgr->hasValue( "SMESH", "scalar_bar_num_labels" ) )
1674     anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_labels", anIntVal );
1675   myScalarBarActor->SetNumberOfLabels( anIntVal == 0 ? 5: anIntVal );
1676
1677   anIntVal = 64;
1678   if( mgr->hasValue( "SMESH", "scalar_bar_num_colors" ) )
1679     anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_colors", anIntVal );
1680   myScalarBarActor->SetMaximumNumberOfColors( anIntVal == 0 ? 64 : anIntVal );
1681   
1682 }