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