Salome HOME
Merge with branch V2_2_0_VISU_improvement
[modules/gui.git] / src / SVTK / SVTK_ViewWindow.cxx
1 #include "SALOME_Actor.h"
2
3 #include <qapplication.h>
4
5 #include <vtkTextProperty.h>
6 #include <vtkActorCollection.h>
7 #include <vtkRenderWindow.h>
8 #include <vtkRenderer.h>
9 #include <vtkCamera.h>
10
11 #include "QtxAction.h"
12
13 #include "SUIT_Session.h"
14 #include "SUIT_ToolButton.h"
15 #include "SUIT_MessageBox.h"
16
17 #include "SUIT_Tools.h"
18 #include "SUIT_ResourceMgr.h"
19
20 #include "VTKViewer_Transform.h"
21 #include "VTKViewer_Utilities.h"
22
23 #include "SVTK_Trihedron.h"
24 #include "SVTK_CubeAxesActor2D.h"
25 #include "SVTK_ViewWindow.h"
26 #include "SVTK_ViewModel.h"
27 #include "SVTK_RenderWindow.h"
28 #include "SVTK_RenderWindowInteractor.h"
29 #include "SVTK_InteractorStyle.h"
30
31 #include "SALOME_ListIteratorOfListIO.hxx"
32
33 #include "SVTK_SelectorDef.h"
34
35 #include "VTKViewer_Algorithm.h"
36 #include "SVTK_Functor.h"
37
38 //----------------------------------------------------------------------------
39 SVTK_ViewWindow
40 ::SVTK_ViewWindow( SUIT_Desktop* theDesktop, 
41                    SVTK_Viewer* theModel)
42   : SUIT_ViewWindow( theDesktop ),
43     myTrihedronSize( 100 )
44 {
45   myModel = theModel;
46   mySelector = new SVTK_SelectorDef();
47   connect(this,SIGNAL(selectionChanged()),theModel,SLOT(onSelectionChanged()));
48
49   myTransform = VTKViewer_Transform::New();
50   myTrihedron = SVTK_Trihedron::New();
51   myCubeAxes  = SVTK_CubeAxesActor2D::New();
52   myRenderer  = vtkRenderer::New() ;
53
54   myTrihedron->AddToRender( myRenderer );
55   myRenderer->AddProp(myCubeAxes);
56
57   myRenderWindow = new SVTK_RenderWindow( this, "RenderWindow" );
58   setCentralWidget(myRenderWindow);
59   myRenderWindow->setFocusPolicy( StrongFocus );
60   myRenderWindow->setFocus();
61
62   myRenderWindow->getRenderWindow()->AddRenderer( myRenderer );
63
64   myRenderer->GetActiveCamera()->ParallelProjectionOn();
65   myRenderer->LightFollowCameraOn();
66   myRenderer->TwoSidedLightingOn();
67
68   // Set BackgroundColor
69   QString BgrColorRed   = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorRed");
70   QString BgrColorGreen = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorGreen");
71   QString BgrColorBlue  = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorBlue");
72
73   if( !BgrColorRed.isEmpty() && !BgrColorGreen.isEmpty() && !BgrColorBlue.isEmpty() ) 
74     myRenderer->SetBackground( BgrColorRed.toInt()/255., BgrColorGreen.toInt()/255., BgrColorBlue.toInt()/255. );
75   else
76     myRenderer->SetBackground( 0, 0, 0 );
77   
78   // Create an interactor.
79   myRWInteractor = SVTK_RenderWindowInteractor::New();
80   myRWInteractor->SetRenderWindow( myRenderWindow->getRenderWindow() );
81   myRWInteractor->setViewWindow( this );
82
83   SVTK_InteractorStyle* RWS = SVTK_InteractorStyle::New();
84   RWS->setGUIWindow( myRenderWindow );
85   RWS->setViewWindow( this );
86
87   myRWInteractor->SetInteractorStyle( RWS ); 
88   myRWInteractor->Initialize();
89
90   //merge with V2_2_0_VISU_improvements:RWS->setTriedron( myTrihedron );
91   RWS->FindPokedRenderer( 0, 0 );
92
93   SetSelectionMode(ActorSelection);
94
95   vtkTextProperty* tprop = vtkTextProperty::New();
96   tprop->SetColor(1, 1, 1);
97   tprop->ShadowOn();
98   
99   float bnd[6];
100   bnd[0] = bnd[2] = bnd[4] = 0;
101   bnd[1] = bnd[3] = bnd[5] = myTrihedron->GetSize();
102   myCubeAxes->SetLabelFormat("%6.4g");
103   myCubeAxes->SetBounds(bnd);
104   myCubeAxes->SetCamera(myRenderer->GetActiveCamera());
105   myCubeAxes->SetFlyModeToOuterEdges(); // ENK remarks: it must bee
106   myCubeAxes->SetFontFactor(0.8);
107   myCubeAxes->SetAxisTitleTextProperty(tprop);
108   myCubeAxes->SetAxisLabelTextProperty(tprop);
109   myCubeAxes->SetCornerOffset(0);
110   myCubeAxes->SetScaling(0);
111   myCubeAxes->SetNumberOfLabels(5);
112   myCubeAxes->VisibilityOff();
113   myCubeAxes->SetTransform(myTransform);
114   tprop->Delete();
115   
116   setCentralWidget( myRenderWindow );
117
118   myToolBar = new QToolBar(this);
119   myToolBar->setCloseMode(QDockWindow::Undocked);
120   myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL"));
121
122   createActions();
123   createToolBar();
124
125   connect( myRenderWindow, SIGNAL(KeyPressed( QKeyEvent* )),
126            this,           SLOT(onKeyPressed( QKeyEvent* )) );
127   connect( myRenderWindow, SIGNAL(KeyReleased( QKeyEvent* )),
128            this,           SLOT(onKeyReleased( QKeyEvent* )) );
129   connect( myRenderWindow, SIGNAL(MouseButtonPressed( QMouseEvent* )),
130            this,           SLOT(onMousePressed( QMouseEvent* )) );
131   connect( myRenderWindow, SIGNAL(MouseButtonReleased( QMouseEvent* )),
132            this,           SLOT(onMouseReleased( QMouseEvent* )) );
133   connect( myRenderWindow, SIGNAL(MouseDoubleClicked( QMouseEvent* )),
134            this,           SLOT(onMouseDoubleClicked( QMouseEvent* )) );
135   connect( myRenderWindow, SIGNAL(MouseMove( QMouseEvent* )),
136            this,           SLOT(onMouseMoving( QMouseEvent* )) );
137
138   connect( myRWInteractor, SIGNAL(RenderWindowModified()),
139            myRenderWindow, SLOT(update()) );
140   connect( myRWInteractor, SIGNAL(contextMenuRequested( QContextMenuEvent * )),
141            this,           SIGNAL(contextMenuRequested( QContextMenuEvent * )) );
142
143   onResetView();
144 }
145
146 //----------------------------------------------------------------------------
147 SVTK_ViewWindow
148 ::~SVTK_ViewWindow()
149 {
150   myTransform->Delete();
151   // In order to ensure that the interactor unregisters
152   // this RenderWindow, we assign a NULL RenderWindow to 
153   // it before deleting it.
154   myRWInteractor->SetRenderWindow( NULL );
155   myRWInteractor->Delete();
156   
157   //m_RW->Delete() ;
158   myRenderer->RemoveAllProps();
159   //m_Renderer->Delete();
160   myTrihedron->Delete();
161   myCubeAxes->Delete();
162 }
163
164 //----------------------------------------------------------------------------
165 void
166 SVTK_ViewWindow
167 ::activateZoom()
168 {
169   myRWInteractor->GetSInteractorStyle()->startZoom();
170 }
171
172 //----------------------------------------------------------------------------
173 void
174 SVTK_ViewWindow
175 ::activatePanning()
176 {
177   myRWInteractor->GetSInteractorStyle()->startPan();
178 }
179
180 //----------------------------------------------------------------------------
181 void
182 SVTK_ViewWindow
183 ::activateRotation()
184 {
185   myRWInteractor->GetSInteractorStyle()->startRotate();
186 }
187
188 //----------------------------------------------------------------------------
189 void
190 SVTK_ViewWindow
191 ::activateGlobalPanning()
192 {
193   if(myTrihedron->GetVisibleActorCount(myRenderer))
194     myRWInteractor->GetSInteractorStyle()->startGlobalPan();
195 }
196
197 //----------------------------------------------------------------------------
198 void
199 SVTK_ViewWindow
200 ::activateWindowFit()
201 {
202   myRWInteractor->GetSInteractorStyle()->startFitArea();
203 }
204
205 //----------------------------------------------------------------------------
206 void
207 SVTK_ViewWindow
208 ::createActions()
209 {
210   if (!myActionsMap.isEmpty()) return;
211   
212   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
213   
214   QtxAction* aAction;
215
216   // Dump view
217   aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
218                            tr( "MNU_DUMP_VIEW" ), 0, this);
219   aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
220   connect(aAction, SIGNAL(activated()), this, SLOT(onDumpView()));
221   myActionsMap[ DumpId ] = aAction;
222
223   // FitAll
224   aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
225                            tr( "MNU_FITALL" ), 0, this);
226   aAction->setStatusTip(tr("DSC_FITALL"));
227   connect(aAction, SIGNAL(activated()), this, SLOT(onFitAll()));
228   myActionsMap[ FitAllId ] = aAction;
229
230   // FitRect
231   aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
232                            tr( "MNU_FITRECT" ), 0, this);
233   aAction->setStatusTip(tr("DSC_FITRECT"));
234   connect(aAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
235   myActionsMap[ FitRectId ] = aAction;
236
237   // Zoom
238   aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
239                            tr( "MNU_ZOOM_VIEW" ), 0, this);
240   aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
241   connect(aAction, SIGNAL(activated()), this, SLOT(activateZoom()));
242   myActionsMap[ ZoomId ] = aAction;
243
244   // Panning
245   aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
246                            tr( "MNU_PAN_VIEW" ), 0, this);
247   aAction->setStatusTip(tr("DSC_PAN_VIEW"));
248   connect(aAction, SIGNAL(activated()), this, SLOT(activatePanning()));
249   myActionsMap[ PanId ] = aAction;
250
251   // Global Panning
252   aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
253                            tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
254   aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
255   connect(aAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
256   myActionsMap[ GlobalPanId ] = aAction;
257
258   // Rotation
259   aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
260                            tr( "MNU_ROTATE_VIEW" ), 0, this);
261   aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
262   connect(aAction, SIGNAL(activated()), this, SLOT(activateRotation()));
263   myActionsMap[ RotationId ] = aAction;
264
265   // Projections
266   aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
267                            tr( "MNU_FRONT_VIEW" ), 0, this);
268   aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
269   connect(aAction, SIGNAL(activated()), this, SLOT(onFrontView()));
270   myActionsMap[ FrontId ] = aAction;
271
272   aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
273                            tr( "MNU_BACK_VIEW" ), 0, this);
274   aAction->setStatusTip(tr("DSC_BACK_VIEW"));
275   connect(aAction, SIGNAL(activated()), this, SLOT(onBackView()));
276   myActionsMap[ BackId ] = aAction;
277
278   aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
279                            tr( "MNU_TOP_VIEW" ), 0, this);
280   aAction->setStatusTip(tr("DSC_TOP_VIEW"));
281   connect(aAction, SIGNAL(activated()), this, SLOT(onTopView()));
282   myActionsMap[ TopId ] = aAction;
283
284   aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
285                            tr( "MNU_BOTTOM_VIEW" ), 0, this);
286   aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
287   connect(aAction, SIGNAL(activated()), this, SLOT(onBottomView()));
288   myActionsMap[ BottomId ] = aAction;
289
290   aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
291                            tr( "MNU_LEFT_VIEW" ), 0, this);
292   aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
293   connect(aAction, SIGNAL(activated()), this, SLOT(onLeftView()));
294   myActionsMap[ LeftId ] = aAction;
295
296   aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
297                            tr( "MNU_RIGHT_VIEW" ), 0, this);
298   aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
299   connect(aAction, SIGNAL(activated()), this, SLOT(onRightView()));
300   myActionsMap[ RightId ] = aAction;
301
302   // Reset
303   aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
304                            tr( "MNU_RESET_VIEW" ), 0, this);
305   aAction->setStatusTip(tr("DSC_RESET_VIEW"));
306   connect(aAction, SIGNAL(activated()), this, SLOT(onResetView()));
307   myActionsMap[ ResetId ] = aAction;
308
309   // onViewTrihedron: Shows - Hides Trihedron
310   aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ),
311                            tr( "MNU_SHOW_TRIHEDRON" ), 0, this);
312   aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON"));
313   connect(aAction, SIGNAL(activated()), this, SLOT(onViewTrihedron()));
314   myActionsMap[ ViewTrihedronId ] = aAction;
315 }
316
317 //----------------------------------------------------------------------------
318 void
319 SVTK_ViewWindow
320 ::createToolBar()
321 {
322   myActionsMap[DumpId]->addTo(myToolBar);
323   myActionsMap[ViewTrihedronId]->addTo(myToolBar);
324
325   SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar);
326   aScaleBtn->AddAction(myActionsMap[FitAllId]);
327   aScaleBtn->AddAction(myActionsMap[FitRectId]);
328   aScaleBtn->AddAction(myActionsMap[ZoomId]);
329
330   SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar);
331   aPanningBtn->AddAction(myActionsMap[PanId]);
332   aPanningBtn->AddAction(myActionsMap[GlobalPanId]);
333
334   myActionsMap[RotationId]->addTo(myToolBar);
335
336   SUIT_ToolButton* aViewsBtn = new SUIT_ToolButton(myToolBar);
337   aViewsBtn->AddAction(myActionsMap[FrontId]);
338   aViewsBtn->AddAction(myActionsMap[BackId]);
339   aViewsBtn->AddAction(myActionsMap[TopId]);
340   aViewsBtn->AddAction(myActionsMap[BottomId]);
341   aViewsBtn->AddAction(myActionsMap[LeftId]);
342   aViewsBtn->AddAction(myActionsMap[RightId]);
343
344   myActionsMap[ResetId]->addTo(myToolBar);
345 }
346
347 //----------------------------------------------------------------------------
348 void
349 SVTK_ViewWindow
350 ::onFrontView()
351 {
352   vtkCamera* camera = myRenderer->GetActiveCamera();
353   camera->SetPosition(1,0,0);
354   camera->SetViewUp(0,0,1);
355   camera->SetFocalPoint(0,0,0);
356   onFitAll();
357 }
358
359 //----------------------------------------------------------------------------
360 void
361 SVTK_ViewWindow
362 ::onBackView()
363 {
364   vtkCamera* camera = myRenderer->GetActiveCamera();
365   camera->SetPosition(-1,0,0);
366   camera->SetViewUp(0,0,1);
367   camera->SetFocalPoint(0,0,0);
368   onFitAll();
369 }
370
371 //----------------------------------------------------------------------------
372 void
373 SVTK_ViewWindow
374 ::onTopView()
375 {
376   vtkCamera* camera = myRenderer->GetActiveCamera();
377   camera->SetPosition(0,0,1);
378   camera->SetViewUp(0,1,0);
379   camera->SetFocalPoint(0,0,0);
380   onFitAll();
381 }
382
383 //----------------------------------------------------------------------------
384 void
385 SVTK_ViewWindow
386 ::onBottomView()
387 {
388   vtkCamera* camera = myRenderer->GetActiveCamera();
389   camera->SetPosition(0,0,-1);
390   camera->SetViewUp(0,1,0);
391   camera->SetFocalPoint(0,0,0);
392   onFitAll();
393 }
394
395 //----------------------------------------------------------------------------
396 void
397 SVTK_ViewWindow
398 ::onLeftView()
399 {
400   vtkCamera* camera = myRenderer->GetActiveCamera(); 
401   camera->SetPosition(0,-1,0);
402   camera->SetViewUp(0,0,1);
403   camera->SetFocalPoint(0,0,0);
404   onFitAll();
405 }
406
407 //----------------------------------------------------------------------------
408 void
409 SVTK_ViewWindow
410 ::onRightView()
411 {
412   vtkCamera* camera = myRenderer->GetActiveCamera();
413   camera->SetPosition(0,1,0);
414   camera->SetViewUp(0,0,1);
415   camera->SetFocalPoint(0,0,0);
416   onFitAll();
417 }
418
419 //----------------------------------------------------------------------------
420 void
421 SVTK_ViewWindow
422 ::onResetView()
423 {
424   int aTrihedronIsVisible = isTrihedronDisplayed();
425   int aCubeAxesIsVisible  = isCubeAxesDisplayed();
426
427   myTrihedron->SetVisibility( VTKViewer_Trihedron::eOnlyLineOn );
428   myCubeAxes->SetVisibility(0);
429
430   ::ResetCamera(myRenderer,true);  
431   vtkCamera* aCamera = myRenderer->GetActiveCamera();
432   aCamera->SetPosition(1,-1,1);
433   aCamera->SetViewUp(0,0,1);
434   ::ResetCamera(myRenderer,true);  
435
436   if (aTrihedronIsVisible) myTrihedron->VisibilityOn();
437   else myTrihedron->VisibilityOff();
438
439   if (aCubeAxesIsVisible) myCubeAxes->VisibilityOn();
440   else myCubeAxes->VisibilityOff();
441
442   static float aCoeff = 3.0;
443   aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale());
444   Repaint();
445 }
446
447 //----------------------------------------------------------------------------
448 void
449 SVTK_ViewWindow
450 ::onFitAll()
451 {
452   int aTrihedronWasVisible = false;
453   int aCubeAxesWasVisible = false;
454   if (myTrihedron) {
455     aTrihedronWasVisible = isTrihedronDisplayed();
456     if (aTrihedronWasVisible)
457       myTrihedron->VisibilityOff();
458   }
459
460   if (myCubeAxes) {
461     aCubeAxesWasVisible = isCubeAxesDisplayed();
462     if (aCubeAxesWasVisible)
463       myCubeAxes->VisibilityOff();
464   }
465
466   if (myTrihedron->GetVisibleActorCount(myRenderer)) {
467     myTrihedron->VisibilityOff();
468     myCubeAxes->VisibilityOff();
469     ::ResetCamera(myRenderer);
470   } else {
471     myTrihedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
472     myCubeAxes->SetVisibility(2);
473     ::ResetCamera(myRenderer,true);
474   }
475
476   if (aTrihedronWasVisible)
477     myTrihedron->VisibilityOn();
478   else
479     myTrihedron->VisibilityOff();
480
481   if (aCubeAxesWasVisible)
482     myCubeAxes->VisibilityOn();
483   else
484     myCubeAxes->VisibilityOff();
485
486   ::ResetCameraClippingRange(myRenderer);
487
488   Repaint();
489 }
490
491 //----------------------------------------------------------------
492 void
493 SVTK_ViewWindow
494 ::onSelectionChanged()
495 {
496   unHighlightAll();
497
498   const SALOME_ListIO& aListIO = mySelector->StoredIObjects();
499   SALOME_ListIteratorOfListIO anIter(aListIO);
500   for(; anIter.More(); anIter.Next()){
501     highlight(anIter.Value(),true,!anIter.More());
502   }
503
504   emit selectionChanged();
505 }
506
507 //----------------------------------------------------------------
508 void
509 SVTK_ViewWindow
510 ::SetSelectionMode(Selection_Mode theMode)
511 {
512   mySelector->SetSelectionMode(theMode);
513   myRWInteractor->SetSelectionMode(theMode);
514 }
515
516 //----------------------------------------------------------------
517 Selection_Mode
518 SVTK_ViewWindow
519 ::SelectionMode() const
520 {
521   return mySelector->SelectionMode();
522 }
523
524 //----------------------------------------------------------------
525 void 
526 SVTK_ViewWindow
527 ::unHighlightAll() 
528 {
529   myRWInteractor->unHighlightAll();
530 }
531
532 //----------------------------------------------------------------
533 void
534 SVTK_ViewWindow
535 ::highlight( const Handle(SALOME_InteractiveObject)& theIO, 
536              bool theIsHighlight, 
537              bool theIsUpdate ) 
538 {
539   myRWInteractor->highlight(theIO, theIsHighlight, theIsUpdate);
540
541   if(mySelector->HasIndex(theIO) && theIO->hasEntry()){
542     TColStd_IndexedMapOfInteger aMapIndex;
543     mySelector->GetIndex(theIO,aMapIndex);
544     using namespace VTK;
545     const char* anEntry = theIO->getEntry();
546     vtkActorCollection* aCollection = myRenderer->GetActors();
547     if(SALOME_Actor* anActor = Find<SALOME_Actor>(aCollection,TIsSameEntry<SALOME_Actor>(anEntry))){
548       switch (mySelector->SelectionMode()) {
549       case NodeSelection:
550         myRWInteractor->highlightPoint(aMapIndex,anActor,theIsHighlight,theIsUpdate);
551         break;
552       case EdgeOfCellSelection:
553         myRWInteractor->highlightEdge(aMapIndex,anActor,theIsHighlight,theIsUpdate);
554         break;
555       case CellSelection:
556       case EdgeSelection:
557       case FaceSelection:
558       case VolumeSelection:
559         myRWInteractor->highlightCell(aMapIndex,anActor,theIsHighlight,theIsUpdate);
560         break;
561       }
562     }
563   }else{
564     myRWInteractor->unHighlightSubSelection();
565   }
566 }
567
568 //----------------------------------------------------------------
569 bool
570 SVTK_ViewWindow
571 ::isInViewer( const Handle(SALOME_InteractiveObject)& theIO ) 
572 {
573   return myRWInteractor->isInViewer( theIO );
574 }
575
576 //----------------------------------------------------------------
577 bool
578 SVTK_ViewWindow
579 ::isVisible( const Handle(SALOME_InteractiveObject)& theIO ) 
580 {
581   return myRWInteractor->isVisible( theIO );
582 }
583
584 //----------------------------------------------------------------------------
585 void
586 SVTK_ViewWindow
587 ::setBackgroundColor( const QColor& color )
588 {
589   if ( myRenderer )
590     myRenderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. );
591 }
592
593 //----------------------------------------------------------------------------
594 QColor
595 SVTK_ViewWindow
596 ::backgroundColor() const
597 {
598   float backint[3];
599   if ( myRenderer ) {
600     myRenderer->GetBackground( backint );
601     return QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255));
602   }
603   return SUIT_ViewWindow::backgroundColor();
604 }
605
606 //----------------------------------------------------------------------------
607 void
608 SVTK_ViewWindow
609 ::Repaint(bool theUpdateTrihedron)
610 {
611   if (theUpdateTrihedron) 
612     onAdjustTrihedron();
613   myRenderWindow->update();
614 }
615
616 //----------------------------------------------------------------------------
617 void
618 SVTK_ViewWindow
619 ::GetScale( double theScale[3] ) 
620 {
621   myTransform->GetMatrixScale( theScale );
622 }
623
624 //----------------------------------------------------------------------------
625 void
626 SVTK_ViewWindow
627 ::SetScale( double theScale[3] ) 
628 {
629   myTransform->SetMatrixScale( theScale[0], theScale[1], theScale[2] );
630   myRWInteractor->Render();
631   Repaint();
632 }
633
634 //----------------------------------------------------------------------------
635 bool
636 SVTK_ViewWindow
637 ::isTrihedronDisplayed()
638 {
639   return myTrihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
640 }
641
642 bool
643 SVTK_ViewWindow
644 ::isCubeAxesDisplayed()
645 {
646   return myCubeAxes->GetVisibility() == 1;
647 }
648
649 //----------------------------------------------------------------------------
650 void 
651 SVTK_ViewWindow
652 ::onViewTrihedron()
653 {
654   if(!myTrihedron) 
655     return;
656
657   if(isTrihedronDisplayed())
658     myTrihedron->VisibilityOff();
659   else
660     myTrihedron->VisibilityOn();
661
662   Repaint();
663 }
664
665 void
666 SVTK_ViewWindow
667 ::onViewCubeAxes()
668 {
669   if(!myCubeAxes)
670     return;
671
672   if(isCubeAxesDisplayed())
673     myCubeAxes->VisibilityOff();
674   else
675     myCubeAxes->VisibilityOn();
676
677   Repaint();
678 }
679
680 //----------------------------------------------------------------------------
681 /*bool
682 SVTK_ViewWindow
683 ::ComputeTrihedronSize( double& theNewSize, double& theSize )
684 {
685   // calculating diagonal of visible props of the renderer
686   float aBndBox[ 6 ];
687   myTrihedron->VisibilityOff();
688
689   if ( ::ComputeVisiblePropBounds( myRenderer, aBndBox ) == 0 ) {
690     aBndBox[ 1 ] = aBndBox[ 3 ] = aBndBox[ 5 ] = 100;
691     aBndBox[ 0 ] = aBndBox[ 2 ] = aBndBox[ 4 ] = 0;
692   }
693
694   myTrihedron->VisibilityOn();
695   float aLength = 0;
696   static bool aCalcByDiag = false;
697   if ( aCalcByDiag ) {
698     aLength = sqrt( ( aBndBox[1]-aBndBox[0])*(aBndBox[1]-aBndBox[0] )+
699                     ( aBndBox[3]-aBndBox[2])*(aBndBox[3]-aBndBox[2] )+
700                     ( aBndBox[5]-aBndBox[4])*(aBndBox[5]-aBndBox[4] ) );
701   } else {
702     aLength = aBndBox[ 1 ]-aBndBox[ 0 ];
703     aLength = max( ( aBndBox[ 3 ] - aBndBox[ 2 ] ),aLength );
704     aLength = max( ( aBndBox[ 5 ] - aBndBox[ 4 ] ),aLength );
705   }
706
707   float aSizeInPercents = myTrihedronSize;
708
709   static float EPS_SIZE = 5.0E-3;
710   theSize = myTrihedron->GetSize();
711   theNewSize = aLength * aSizeInPercents / 100.0;
712
713   // if the new trihedron size have sufficient difference, then apply the value
714   return fabs( theNewSize - theSize) > theSize * EPS_SIZE ||
715          fabs( theNewSize-theSize ) > theNewSize * EPS_SIZE;
716 }*/
717
718 //----------------------------------------------------------------------------
719 int SVTK_ViewWindow::GetTrihedronSize() const
720 {
721   return myTrihedronSize;
722 }
723
724 void SVTK_ViewWindow::SetTrihedronSize( const int sz )
725 {
726   if ( myTrihedronSize == sz )
727     return;
728
729   myTrihedronSize = sz;
730   AdjustTrihedrons( true );
731 }
732
733 /*! If parameter theIsForcedUpdate is true, recalculate parameters for
734  *  trihedron and cube axes, even if trihedron and cube axes is invisible.
735  */
736 void
737 SVTK_ViewWindow
738 ::AdjustTrihedrons(const bool theIsForcedUpdate)
739 {
740   if ((!isCubeAxesDisplayed() && !isTrihedronDisplayed()) && !theIsForcedUpdate)
741     return;
742
743   float bnd[ 6 ];
744   float newbnd[6];
745   newbnd[ 0 ] = newbnd[ 2 ] = newbnd[ 4 ] = VTK_LARGE_FLOAT;
746   newbnd[ 1 ] = newbnd[ 3 ] = newbnd[ 5 ] = -VTK_LARGE_FLOAT;
747
748   myCubeAxes->GetBounds(bnd);
749
750   int aVisibleNum = myTrihedron->GetVisibleActorCount( myRenderer );
751   //if (aVisibleNum || theIsForcedUpdate) {
752   if (aVisibleNum) {
753     // if the new trihedron size have sufficient difference, then apply the value
754     double aNewSize = 100, anOldSize=myTrihedron->GetSize();
755     bool aTDisplayed = isTrihedronDisplayed();
756     bool aCDisplayed = isCubeAxesDisplayed();
757     if(aTDisplayed) myTrihedron->VisibilityOff();
758     if(aCDisplayed) myCubeAxes->VisibilityOff();
759
760     SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
761     QString aSetting = aResMgr->stringValue("Viewer:TrihedronSize", "105");
762     static float aSizeInPercents = aSetting.toFloat();
763
764     //bool isComputeTrihedronSize =
765       ::ComputeTrihedronSize(myRenderer, aNewSize, anOldSize, aSizeInPercents);
766
767     myTrihedron->SetSize( aNewSize );
768
769     // iterate through displayed objects and set size if necessary
770     vtkActorCollection* anActors = getRenderer()->GetActors();
771     anActors->InitTraversal();
772     while (vtkActor* anActor = anActors->GetNextActor())
773     {
774       if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast( anActor ))
775       {
776         if (aSActor->IsResizable())
777           aSActor->SetSize( 0.5 * aNewSize );
778         if (aSActor->GetVisibility() && !aSActor->IsInfinitive()) {
779           float *abounds = aSActor->GetBounds();
780           if (abounds[0] > -VTK_LARGE_FLOAT && abounds[1] < VTK_LARGE_FLOAT &&
781               abounds[2] > -VTK_LARGE_FLOAT && abounds[3] < VTK_LARGE_FLOAT &&
782               abounds[4] > -VTK_LARGE_FLOAT && abounds[5] < VTK_LARGE_FLOAT)
783             for (int i = 0; i < 5; i = i + 2) {
784               if (abounds[i] < newbnd[i]) newbnd[i] = abounds[i];
785               if (abounds[i+1] > newbnd[i+1]) newbnd[i+1] = abounds[i+1];
786             }
787         }
788       }
789     }
790     if (aTDisplayed) myTrihedron->VisibilityOn();
791     if (aCDisplayed) myCubeAxes->VisibilityOn();
792     
793   } else {
794      double aSize = myTrihedron->GetSize();
795      newbnd[0] = newbnd[2] = newbnd[4] = 0;
796      newbnd[1] = newbnd[3] = newbnd[5] = aSize;
797   }
798   
799   if (newbnd[0] < VTK_LARGE_FLOAT && newbnd[2] < VTK_LARGE_FLOAT && newbnd[4] < VTK_LARGE_FLOAT &&
800       newbnd[1] >-VTK_LARGE_FLOAT && newbnd[3] >-VTK_LARGE_FLOAT && newbnd[5] >-VTK_LARGE_FLOAT) {
801     for(int i=0;i<6;i++) bnd[i] = newbnd[i];
802     myCubeAxes->SetBounds(bnd);
803   }
804   
805   myCubeAxes->SetBounds(bnd);
806
807   ::ResetCameraClippingRange(myRenderer);
808 }
809
810 //----------------------------------------------------------------------------
811 void
812 SVTK_ViewWindow
813 ::onAdjustTrihedron()
814 {   
815   AdjustTrihedrons( false );
816 }
817
818 void
819 SVTK_ViewWindow
820 ::onAdjustCubeAxes()
821 {   
822   AdjustTrihedrons(false);
823 }
824
825 #define INCREMENT_FOR_OP 10
826
827 //=======================================================================
828 // name    : onPanLeft
829 // Purpose : Performs incremental panning to the left
830 //=======================================================================
831 void
832 SVTK_ViewWindow
833 ::onPanLeft()
834 {
835   myRWInteractor->GetSInteractorStyle()->IncrementalPan( -INCREMENT_FOR_OP, 0 );
836 }
837
838 //=======================================================================
839 // name    : onPanRight
840 // Purpose : Performs incremental panning to the right
841 //=======================================================================
842 void
843 SVTK_ViewWindow
844 ::onPanRight()
845 {
846   myRWInteractor->GetSInteractorStyle()->IncrementalPan( INCREMENT_FOR_OP, 0 );
847 }
848
849 //=======================================================================
850 // name    : onPanUp
851 // Purpose : Performs incremental panning to the top
852 //=======================================================================
853 void
854 SVTK_ViewWindow
855 ::onPanUp()
856 {
857   myRWInteractor->GetSInteractorStyle()->IncrementalPan( 0, INCREMENT_FOR_OP );
858 }
859
860 //=======================================================================
861 // name    : onPanDown
862 // Purpose : Performs incremental panning to the bottom
863 //=======================================================================
864 void
865 SVTK_ViewWindow
866 ::onPanDown()
867 {
868   myRWInteractor->GetSInteractorStyle()->IncrementalPan( 0, -INCREMENT_FOR_OP );
869 }
870
871 //=======================================================================
872 // name    : onZoomIn
873 // Purpose : Performs incremental zooming in
874 //=======================================================================
875 void
876 SVTK_ViewWindow
877 ::onZoomIn()
878 {
879   myRWInteractor->GetSInteractorStyle()->IncrementalZoom( INCREMENT_FOR_OP );
880 }
881
882 //=======================================================================
883 // name    : onZoomOut
884 // Purpose : Performs incremental zooming out
885 //=======================================================================
886 void
887 SVTK_ViewWindow
888 ::onZoomOut()
889 {
890   myRWInteractor->GetSInteractorStyle()->IncrementalZoom( -INCREMENT_FOR_OP );
891 }
892
893 //=======================================================================
894 // name    : onRotateLeft
895 // Purpose : Performs incremental rotating to the left
896 //=======================================================================
897 void
898 SVTK_ViewWindow
899 ::onRotateLeft()
900 {
901   myRWInteractor->GetSInteractorStyle()->IncrementalRotate( -INCREMENT_FOR_OP, 0 );
902 }
903
904 //=======================================================================
905 // name    : onRotateRight
906 // Purpose : Performs incremental rotating to the right
907 //=======================================================================
908 void
909 SVTK_ViewWindow
910 ::onRotateRight()
911 {
912   myRWInteractor->GetSInteractorStyle()->IncrementalRotate( INCREMENT_FOR_OP, 0 );
913 }
914
915 //=======================================================================
916 // name    : onRotateUp
917 // Purpose : Performs incremental rotating to the top
918 //=======================================================================
919 void
920 SVTK_ViewWindow
921 ::onRotateUp()
922 {
923   myRWInteractor->GetSInteractorStyle()->IncrementalRotate( 0, -INCREMENT_FOR_OP );
924 }
925
926 //=======================================================================
927 void
928 SVTK_ViewWindow
929 ::onKeyPressed(QKeyEvent* event)
930 {
931   emit keyPressed( this, event );
932 }
933
934 //=======================================================================
935 void
936 SVTK_ViewWindow
937 ::onKeyReleased(QKeyEvent* event)
938 {
939   emit keyReleased( this, event );
940 }
941
942 //=======================================================================
943 void
944 SVTK_ViewWindow
945 ::onMousePressed(QMouseEvent* event)
946 {
947   emit mousePressed(this, event);
948 }
949
950 //=======================================================================
951 void
952 SVTK_ViewWindow
953 ::onMouseReleased(QMouseEvent* event)
954 {
955   emit mouseReleased( this, event );
956 }
957
958 //=======================================================================
959 void
960 SVTK_ViewWindow
961 ::onMouseMoving(QMouseEvent* event)
962 {
963   emit mouseMoving( this, event );
964 }
965
966 //=======================================================================
967 void
968 SVTK_ViewWindow
969 ::onMouseDoubleClicked( QMouseEvent* event )
970 {
971   emit mouseDoubleClicked( this, event );
972 }
973
974 //=======================================================================
975 // name    : onRotateDown
976 // Purpose : Performs incremental rotating to the bottom
977 //=======================================================================
978 void
979 SVTK_ViewWindow
980 ::onRotateDown()
981 {
982   myRWInteractor->GetSInteractorStyle()->IncrementalRotate( 0, INCREMENT_FOR_OP );
983 }
984
985 //----------------------------------------------------------------------------
986 void
987 SVTK_ViewWindow
988 ::InsertActor( SALOME_Actor* theActor, bool theMoveInternalActors )
989 {
990   theActor->AddToRender(myRenderer);
991   theActor->SetTransform(myTransform);
992   if(theMoveInternalActors) 
993     myRWInteractor->MoveInternalActors();
994 }
995
996 //----------------------------------------------------------------------------
997 void
998 SVTK_ViewWindow
999 ::AddActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ )
1000 {
1001   InsertActor(theActor);
1002   if(theUpdate) 
1003     Repaint();
1004 }
1005
1006 //----------------------------------------------------------------------------
1007 void
1008 SVTK_ViewWindow
1009 ::RemoveActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ )
1010 {
1011   theActor->RemoveFromRender(myRenderer);
1012   if(theUpdate) 
1013     Repaint();
1014 }
1015
1016 //----------------------------------------------------------------------------
1017 void
1018 SVTK_ViewWindow
1019 ::MoveActor( SALOME_Actor* theActor)
1020 {
1021   RemoveActor(theActor);
1022   InsertActor(theActor,true);
1023 }
1024
1025 //----------------------------------------------------------------------------
1026 QImage
1027 SVTK_ViewWindow
1028 ::dumpView()
1029 {
1030   QPixmap px = QPixmap::grabWindow( myRenderWindow->winId() );
1031   return px.convertToImage();
1032 }