Salome HOME
bf746b0d75b2340129fe184c43c478af538b5e0b
[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 #if defined(WIN32) && !defined(_DEBUG)
208 #pragma optimize( "", off )
209 #endif
210 void
211 SVTK_ViewWindow
212 ::createActions()
213 {
214   if (!myActionsMap.isEmpty()) return;
215   
216   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
217   
218   QtxAction* aAction;
219
220   // Dump view
221   aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
222                            tr( "MNU_DUMP_VIEW" ), 0, this);
223   aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
224   connect(aAction, SIGNAL(activated()), this, SLOT(onDumpView()));
225   myActionsMap[ DumpId ] = aAction;
226
227   // FitAll
228   aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
229                            tr( "MNU_FITALL" ), 0, this);
230   aAction->setStatusTip(tr("DSC_FITALL"));
231   connect(aAction, SIGNAL(activated()), this, SLOT(onFitAll()));
232   myActionsMap[ FitAllId ] = aAction;
233
234   // FitRect
235   aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
236                            tr( "MNU_FITRECT" ), 0, this);
237   aAction->setStatusTip(tr("DSC_FITRECT"));
238   connect(aAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
239   myActionsMap[ FitRectId ] = aAction;
240
241   // Zoom
242   aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
243                            tr( "MNU_ZOOM_VIEW" ), 0, this);
244   aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
245   connect(aAction, SIGNAL(activated()), this, SLOT(activateZoom()));
246   myActionsMap[ ZoomId ] = aAction;
247
248   // Panning
249   aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
250                            tr( "MNU_PAN_VIEW" ), 0, this);
251   aAction->setStatusTip(tr("DSC_PAN_VIEW"));
252   connect(aAction, SIGNAL(activated()), this, SLOT(activatePanning()));
253   myActionsMap[ PanId ] = aAction;
254
255   // Global Panning
256   aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
257                            tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
258   aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
259   connect(aAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
260   myActionsMap[ GlobalPanId ] = aAction;
261
262   // Rotation
263   aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
264                            tr( "MNU_ROTATE_VIEW" ), 0, this);
265   aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
266   connect(aAction, SIGNAL(activated()), this, SLOT(activateRotation()));
267   myActionsMap[ RotationId ] = aAction;
268
269   // Projections
270   aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
271                            tr( "MNU_FRONT_VIEW" ), 0, this);
272   aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
273   connect(aAction, SIGNAL(activated()), this, SLOT(onFrontView()));
274   myActionsMap[ FrontId ] = aAction;
275
276   aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
277                            tr( "MNU_BACK_VIEW" ), 0, this);
278   aAction->setStatusTip(tr("DSC_BACK_VIEW"));
279   connect(aAction, SIGNAL(activated()), this, SLOT(onBackView()));
280   myActionsMap[ BackId ] = aAction;
281
282   aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
283                            tr( "MNU_TOP_VIEW" ), 0, this);
284   aAction->setStatusTip(tr("DSC_TOP_VIEW"));
285   connect(aAction, SIGNAL(activated()), this, SLOT(onTopView()));
286   myActionsMap[ TopId ] = aAction;
287
288   aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
289                            tr( "MNU_BOTTOM_VIEW" ), 0, this);
290   aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
291   connect(aAction, SIGNAL(activated()), this, SLOT(onBottomView()));
292   myActionsMap[ BottomId ] = aAction;
293
294   aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
295                            tr( "MNU_LEFT_VIEW" ), 0, this);
296   aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
297   connect(aAction, SIGNAL(activated()), this, SLOT(onLeftView()));
298   myActionsMap[ LeftId ] = aAction;
299
300   aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
301                            tr( "MNU_RIGHT_VIEW" ), 0, this);
302   aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
303   connect(aAction, SIGNAL(activated()), this, SLOT(onRightView()));
304   myActionsMap[ RightId ] = aAction;
305
306   // Reset
307   aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
308                            tr( "MNU_RESET_VIEW" ), 0, this);
309   aAction->setStatusTip(tr("DSC_RESET_VIEW"));
310   connect(aAction, SIGNAL(activated()), this, SLOT(onResetView()));
311   myActionsMap[ ResetId ] = aAction;
312
313   // onViewTrihedron: Shows - Hides Trihedron
314   aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ),
315                            tr( "MNU_SHOW_TRIHEDRON" ), 0, this);
316   aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON"));
317   connect(aAction, SIGNAL(activated()), this, SLOT(onViewTrihedron()));
318   myActionsMap[ ViewTrihedronId ] = aAction;
319 }
320 #if defined(WIN32) && !defined(_DEBUG)
321 #pragma optimize( "", on )
322 #endif
323
324 //----------------------------------------------------------------------------
325 void
326 SVTK_ViewWindow
327 ::createToolBar()
328 {
329   myActionsMap[DumpId]->addTo(myToolBar);
330   myActionsMap[ViewTrihedronId]->addTo(myToolBar);
331
332   SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar);
333   aScaleBtn->AddAction(myActionsMap[FitAllId]);
334   aScaleBtn->AddAction(myActionsMap[FitRectId]);
335   aScaleBtn->AddAction(myActionsMap[ZoomId]);
336
337   SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar);
338   aPanningBtn->AddAction(myActionsMap[PanId]);
339   aPanningBtn->AddAction(myActionsMap[GlobalPanId]);
340
341   myActionsMap[RotationId]->addTo(myToolBar);
342
343   SUIT_ToolButton* aViewsBtn = new SUIT_ToolButton(myToolBar);
344   aViewsBtn->AddAction(myActionsMap[FrontId]);
345   aViewsBtn->AddAction(myActionsMap[BackId]);
346   aViewsBtn->AddAction(myActionsMap[TopId]);
347   aViewsBtn->AddAction(myActionsMap[BottomId]);
348   aViewsBtn->AddAction(myActionsMap[LeftId]);
349   aViewsBtn->AddAction(myActionsMap[RightId]);
350
351   myActionsMap[ResetId]->addTo(myToolBar);
352 }
353
354 //----------------------------------------------------------------------------
355 void
356 SVTK_ViewWindow
357 ::onFrontView()
358 {
359   vtkCamera* camera = myRenderer->GetActiveCamera();
360   camera->SetPosition(1,0,0);
361   camera->SetViewUp(0,0,1);
362   camera->SetFocalPoint(0,0,0);
363   onFitAll();
364 }
365
366 //----------------------------------------------------------------------------
367 void
368 SVTK_ViewWindow
369 ::onBackView()
370 {
371   vtkCamera* camera = myRenderer->GetActiveCamera();
372   camera->SetPosition(-1,0,0);
373   camera->SetViewUp(0,0,1);
374   camera->SetFocalPoint(0,0,0);
375   onFitAll();
376 }
377
378 //----------------------------------------------------------------------------
379 void
380 SVTK_ViewWindow
381 ::onTopView()
382 {
383   vtkCamera* camera = myRenderer->GetActiveCamera();
384   camera->SetPosition(0,0,1);
385   camera->SetViewUp(0,1,0);
386   camera->SetFocalPoint(0,0,0);
387   onFitAll();
388 }
389
390 //----------------------------------------------------------------------------
391 void
392 SVTK_ViewWindow
393 ::onBottomView()
394 {
395   vtkCamera* camera = myRenderer->GetActiveCamera();
396   camera->SetPosition(0,0,-1);
397   camera->SetViewUp(0,1,0);
398   camera->SetFocalPoint(0,0,0);
399   onFitAll();
400 }
401
402 //----------------------------------------------------------------------------
403 void
404 SVTK_ViewWindow
405 ::onLeftView()
406 {
407   vtkCamera* camera = myRenderer->GetActiveCamera(); 
408   camera->SetPosition(0,-1,0);
409   camera->SetViewUp(0,0,1);
410   camera->SetFocalPoint(0,0,0);
411   onFitAll();
412 }
413
414 //----------------------------------------------------------------------------
415 void
416 SVTK_ViewWindow
417 ::onRightView()
418 {
419   vtkCamera* camera = myRenderer->GetActiveCamera();
420   camera->SetPosition(0,1,0);
421   camera->SetViewUp(0,0,1);
422   camera->SetFocalPoint(0,0,0);
423   onFitAll();
424 }
425
426 //----------------------------------------------------------------------------
427 void
428 SVTK_ViewWindow
429 ::onResetView()
430 {
431   int aTrihedronIsVisible = isTrihedronDisplayed();
432   int aCubeAxesIsVisible  = isCubeAxesDisplayed();
433
434   myTrihedron->SetVisibility( VTKViewer_Trihedron::eOnlyLineOn );
435   myCubeAxes->SetVisibility(0);
436
437   ::ResetCamera(myRenderer,true);  
438   vtkCamera* aCamera = myRenderer->GetActiveCamera();
439   aCamera->SetPosition(1,-1,1);
440   aCamera->SetViewUp(0,0,1);
441   ::ResetCamera(myRenderer,true);  
442
443   if (aTrihedronIsVisible) myTrihedron->VisibilityOn();
444   else myTrihedron->VisibilityOff();
445
446   if (aCubeAxesIsVisible) myCubeAxes->VisibilityOn();
447   else myCubeAxes->VisibilityOff();
448
449   static float aCoeff = 3.0;
450   aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale());
451   Repaint();
452 }
453
454 //----------------------------------------------------------------------------
455 void
456 SVTK_ViewWindow
457 ::onFitAll()
458 {
459   int aTrihedronWasVisible = false;
460   int aCubeAxesWasVisible = false;
461   if (myTrihedron) {
462     aTrihedronWasVisible = isTrihedronDisplayed();
463     if (aTrihedronWasVisible)
464       myTrihedron->VisibilityOff();
465   }
466
467   if (myCubeAxes) {
468     aCubeAxesWasVisible = isCubeAxesDisplayed();
469     if (aCubeAxesWasVisible)
470       myCubeAxes->VisibilityOff();
471   }
472
473   if (myTrihedron->GetVisibleActorCount(myRenderer)) {
474     myTrihedron->VisibilityOff();
475     myCubeAxes->VisibilityOff();
476     ::ResetCamera(myRenderer);
477   } else {
478     myTrihedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
479     myCubeAxes->SetVisibility(2);
480     ::ResetCamera(myRenderer,true);
481   }
482
483   if (aTrihedronWasVisible)
484     myTrihedron->VisibilityOn();
485   else
486     myTrihedron->VisibilityOff();
487
488   if (aCubeAxesWasVisible)
489     myCubeAxes->VisibilityOn();
490   else
491     myCubeAxes->VisibilityOff();
492
493   ::ResetCameraClippingRange(myRenderer);
494
495   Repaint();
496 }
497
498 //----------------------------------------------------------------
499 void
500 SVTK_ViewWindow
501 ::onSelectionChanged()
502 {
503   unHighlightAll();
504
505   const SALOME_ListIO& aListIO = mySelector->StoredIObjects();
506   SALOME_ListIteratorOfListIO anIter(aListIO);
507   for(; anIter.More(); anIter.Next()){
508     highlight(anIter.Value(),true,!anIter.More());
509   }
510
511   emit selectionChanged();
512 }
513
514 //----------------------------------------------------------------
515 void
516 SVTK_ViewWindow
517 ::SetSelectionMode(Selection_Mode theMode)
518 {
519   mySelector->SetSelectionMode(theMode);
520   myRWInteractor->SetSelectionMode(theMode);
521 }
522
523 //----------------------------------------------------------------
524 Selection_Mode
525 SVTK_ViewWindow
526 ::SelectionMode() const
527 {
528   return mySelector->SelectionMode();
529 }
530
531 //----------------------------------------------------------------
532 void 
533 SVTK_ViewWindow
534 ::unHighlightAll() 
535 {
536   myRWInteractor->unHighlightAll();
537 }
538
539 //----------------------------------------------------------------
540 void
541 SVTK_ViewWindow
542 ::highlight( const Handle(SALOME_InteractiveObject)& theIO, 
543              bool theIsHighlight, 
544              bool theIsUpdate ) 
545 {
546   myRWInteractor->highlight(theIO, theIsHighlight, theIsUpdate);
547
548   if(mySelector->HasIndex(theIO) && theIO->hasEntry()){
549     TColStd_IndexedMapOfInteger aMapIndex;
550     mySelector->GetIndex(theIO,aMapIndex);
551     using namespace VTK;
552     const char* anEntry = theIO->getEntry();
553     vtkActorCollection* aCollection = myRenderer->GetActors();
554     if(SALOME_Actor* anActor = Find<SALOME_Actor>(aCollection,TIsSameEntry<SALOME_Actor>(anEntry))){
555       switch (mySelector->SelectionMode()) {
556       case NodeSelection:
557         myRWInteractor->highlightPoint(aMapIndex,anActor,theIsHighlight,theIsUpdate);
558         break;
559       case EdgeOfCellSelection:
560         myRWInteractor->highlightEdge(aMapIndex,anActor,theIsHighlight,theIsUpdate);
561         break;
562       case CellSelection:
563       case EdgeSelection:
564       case FaceSelection:
565       case VolumeSelection:
566         myRWInteractor->highlightCell(aMapIndex,anActor,theIsHighlight,theIsUpdate);
567         break;
568       }
569     }
570   }else{
571     myRWInteractor->unHighlightSubSelection();
572   }
573 }
574
575 //----------------------------------------------------------------
576 bool
577 SVTK_ViewWindow
578 ::isInViewer( const Handle(SALOME_InteractiveObject)& theIO ) 
579 {
580   return myRWInteractor->isInViewer( theIO );
581 }
582
583 //----------------------------------------------------------------
584 bool
585 SVTK_ViewWindow
586 ::isVisible( const Handle(SALOME_InteractiveObject)& theIO ) 
587 {
588   return myRWInteractor->isVisible( theIO );
589 }
590
591 //----------------------------------------------------------------------------
592 void
593 SVTK_ViewWindow
594 ::setBackgroundColor( const QColor& color )
595 {
596   if ( myRenderer )
597     myRenderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. );
598 }
599
600 //----------------------------------------------------------------------------
601 QColor
602 SVTK_ViewWindow
603 ::backgroundColor() const
604 {
605   float backint[3];
606   if ( myRenderer ) {
607     myRenderer->GetBackground( backint );
608     return QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255));
609   }
610   return SUIT_ViewWindow::backgroundColor();
611 }
612
613 //----------------------------------------------------------------------------
614 void
615 SVTK_ViewWindow
616 ::Repaint(bool theUpdateTrihedron)
617 {
618   if (theUpdateTrihedron) 
619     onAdjustTrihedron();
620   myRenderWindow->update();
621 }
622
623 //----------------------------------------------------------------------------
624 void
625 SVTK_ViewWindow
626 ::GetScale( double theScale[3] ) 
627 {
628   myTransform->GetMatrixScale( theScale );
629 }
630
631 //----------------------------------------------------------------------------
632 void
633 SVTK_ViewWindow
634 ::SetScale( double theScale[3] ) 
635 {
636   myTransform->SetMatrixScale( theScale[0], theScale[1], theScale[2] );
637   myRWInteractor->Render();
638   Repaint();
639 }
640
641 //----------------------------------------------------------------------------
642 bool
643 SVTK_ViewWindow
644 ::isTrihedronDisplayed()
645 {
646   return myTrihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
647 }
648
649 bool
650 SVTK_ViewWindow
651 ::isCubeAxesDisplayed()
652 {
653   return myCubeAxes->GetVisibility() == 1;
654 }
655
656 //----------------------------------------------------------------------------
657 void 
658 SVTK_ViewWindow
659 ::onViewTrihedron()
660 {
661   if(!myTrihedron) 
662     return;
663
664   if(isTrihedronDisplayed())
665     myTrihedron->VisibilityOff();
666   else
667     myTrihedron->VisibilityOn();
668
669   Repaint();
670 }
671
672 void
673 SVTK_ViewWindow
674 ::onViewCubeAxes()
675 {
676   if(!myCubeAxes)
677     return;
678
679   if(isCubeAxesDisplayed())
680     myCubeAxes->VisibilityOff();
681   else
682     myCubeAxes->VisibilityOn();
683
684   Repaint();
685 }
686
687 //----------------------------------------------------------------------------
688 /*bool
689 SVTK_ViewWindow
690 ::ComputeTrihedronSize( double& theNewSize, double& theSize )
691 {
692   // calculating diagonal of visible props of the renderer
693   float aBndBox[ 6 ];
694   myTrihedron->VisibilityOff();
695
696   if ( ::ComputeVisiblePropBounds( myRenderer, aBndBox ) == 0 ) {
697     aBndBox[ 1 ] = aBndBox[ 3 ] = aBndBox[ 5 ] = 100;
698     aBndBox[ 0 ] = aBndBox[ 2 ] = aBndBox[ 4 ] = 0;
699   }
700
701   myTrihedron->VisibilityOn();
702   float aLength = 0;
703   static bool aCalcByDiag = false;
704   if ( aCalcByDiag ) {
705     aLength = sqrt( ( aBndBox[1]-aBndBox[0])*(aBndBox[1]-aBndBox[0] )+
706                     ( aBndBox[3]-aBndBox[2])*(aBndBox[3]-aBndBox[2] )+
707                     ( aBndBox[5]-aBndBox[4])*(aBndBox[5]-aBndBox[4] ) );
708   } else {
709     aLength = aBndBox[ 1 ]-aBndBox[ 0 ];
710     aLength = max( ( aBndBox[ 3 ] - aBndBox[ 2 ] ),aLength );
711     aLength = max( ( aBndBox[ 5 ] - aBndBox[ 4 ] ),aLength );
712   }
713
714   float aSizeInPercents = myTrihedronSize;
715
716   static float EPS_SIZE = 5.0E-3;
717   theSize = myTrihedron->GetSize();
718   theNewSize = aLength * aSizeInPercents / 100.0;
719
720   // if the new trihedron size have sufficient difference, then apply the value
721   return fabs( theNewSize - theSize) > theSize * EPS_SIZE ||
722          fabs( theNewSize-theSize ) > theNewSize * EPS_SIZE;
723 }*/
724
725 //----------------------------------------------------------------------------
726 int SVTK_ViewWindow::GetTrihedronSize() const
727 {
728   return myTrihedronSize;
729 }
730
731 void SVTK_ViewWindow::SetTrihedronSize( const int sz )
732 {
733   if ( myTrihedronSize == sz )
734     return;
735
736   myTrihedronSize = sz;
737   AdjustTrihedrons( true );
738 }
739
740 /*! If parameter theIsForcedUpdate is true, recalculate parameters for
741  *  trihedron and cube axes, even if trihedron and cube axes is invisible.
742  */
743 void
744 SVTK_ViewWindow
745 ::AdjustTrihedrons(const bool theIsForcedUpdate)
746 {
747   if ((!isCubeAxesDisplayed() && !isTrihedronDisplayed()) && !theIsForcedUpdate)
748     return;
749
750   float bnd[ 6 ];
751   float newbnd[6];
752   newbnd[ 0 ] = newbnd[ 2 ] = newbnd[ 4 ] = VTK_LARGE_FLOAT;
753   newbnd[ 1 ] = newbnd[ 3 ] = newbnd[ 5 ] = -VTK_LARGE_FLOAT;
754
755   myCubeAxes->GetBounds(bnd);
756
757   int aVisibleNum = myTrihedron->GetVisibleActorCount( myRenderer );
758   //if (aVisibleNum || theIsForcedUpdate) {
759   if (aVisibleNum) {
760     // if the new trihedron size have sufficient difference, then apply the value
761     double aNewSize = 100, anOldSize=myTrihedron->GetSize();
762     bool aTDisplayed = isTrihedronDisplayed();
763     bool aCDisplayed = isCubeAxesDisplayed();
764     if(aTDisplayed) myTrihedron->VisibilityOff();
765     if(aCDisplayed) myCubeAxes->VisibilityOff();
766
767     SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
768     QString aSetting = aResMgr->stringValue("Viewer", "TrihedronSize", "105");
769     static float aSizeInPercents = aSetting.toFloat();
770
771     //bool isComputeTrihedronSize =
772       ::ComputeTrihedronSize(myRenderer, aNewSize, anOldSize, aSizeInPercents);
773
774     myTrihedron->SetSize( aNewSize );
775
776     // iterate through displayed objects and set size if necessary
777     vtkActorCollection* anActors = getRenderer()->GetActors();
778     anActors->InitTraversal();
779     while (vtkActor* anActor = anActors->GetNextActor())
780     {
781       if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast( anActor ))
782       {
783         if (aSActor->IsResizable())
784           aSActor->SetSize( 0.5 * aNewSize );
785         if (aSActor->GetVisibility() && !aSActor->IsInfinitive()) {
786           float *abounds = aSActor->GetBounds();
787           if (abounds[0] > -VTK_LARGE_FLOAT && abounds[1] < VTK_LARGE_FLOAT &&
788               abounds[2] > -VTK_LARGE_FLOAT && abounds[3] < VTK_LARGE_FLOAT &&
789               abounds[4] > -VTK_LARGE_FLOAT && abounds[5] < VTK_LARGE_FLOAT)
790             for (int i = 0; i < 5; i = i + 2) {
791               if (abounds[i] < newbnd[i]) newbnd[i] = abounds[i];
792               if (abounds[i+1] > newbnd[i+1]) newbnd[i+1] = abounds[i+1];
793             }
794         }
795       }
796     }
797     if (aTDisplayed) myTrihedron->VisibilityOn();
798     if (aCDisplayed) myCubeAxes->VisibilityOn();
799     
800   } else {
801      double aSize = myTrihedron->GetSize();
802      newbnd[0] = newbnd[2] = newbnd[4] = 0;
803      newbnd[1] = newbnd[3] = newbnd[5] = aSize;
804   }
805   
806   if (newbnd[0] < VTK_LARGE_FLOAT && newbnd[2] < VTK_LARGE_FLOAT && newbnd[4] < VTK_LARGE_FLOAT &&
807       newbnd[1] >-VTK_LARGE_FLOAT && newbnd[3] >-VTK_LARGE_FLOAT && newbnd[5] >-VTK_LARGE_FLOAT) {
808     for(int i=0;i<6;i++) bnd[i] = newbnd[i];
809     myCubeAxes->SetBounds(bnd);
810   }
811   
812   myCubeAxes->SetBounds(bnd);
813
814   ::ResetCameraClippingRange(myRenderer);
815 }
816
817 //----------------------------------------------------------------------------
818 void
819 SVTK_ViewWindow
820 ::onAdjustTrihedron()
821 {   
822   AdjustTrihedrons( false );
823 }
824
825 void
826 SVTK_ViewWindow
827 ::onAdjustCubeAxes()
828 {   
829   AdjustTrihedrons(false);
830 }
831
832 #define INCREMENT_FOR_OP 10
833
834 //=======================================================================
835 // name    : onPanLeft
836 // Purpose : Performs incremental panning to the left
837 //=======================================================================
838 void
839 SVTK_ViewWindow
840 ::onPanLeft()
841 {
842   myRWInteractor->GetSInteractorStyle()->IncrementalPan( -INCREMENT_FOR_OP, 0 );
843 }
844
845 //=======================================================================
846 // name    : onPanRight
847 // Purpose : Performs incremental panning to the right
848 //=======================================================================
849 void
850 SVTK_ViewWindow
851 ::onPanRight()
852 {
853   myRWInteractor->GetSInteractorStyle()->IncrementalPan( INCREMENT_FOR_OP, 0 );
854 }
855
856 //=======================================================================
857 // name    : onPanUp
858 // Purpose : Performs incremental panning to the top
859 //=======================================================================
860 void
861 SVTK_ViewWindow
862 ::onPanUp()
863 {
864   myRWInteractor->GetSInteractorStyle()->IncrementalPan( 0, INCREMENT_FOR_OP );
865 }
866
867 //=======================================================================
868 // name    : onPanDown
869 // Purpose : Performs incremental panning to the bottom
870 //=======================================================================
871 void
872 SVTK_ViewWindow
873 ::onPanDown()
874 {
875   myRWInteractor->GetSInteractorStyle()->IncrementalPan( 0, -INCREMENT_FOR_OP );
876 }
877
878 //=======================================================================
879 // name    : onZoomIn
880 // Purpose : Performs incremental zooming in
881 //=======================================================================
882 void
883 SVTK_ViewWindow
884 ::onZoomIn()
885 {
886   myRWInteractor->GetSInteractorStyle()->IncrementalZoom( INCREMENT_FOR_OP );
887 }
888
889 //=======================================================================
890 // name    : onZoomOut
891 // Purpose : Performs incremental zooming out
892 //=======================================================================
893 void
894 SVTK_ViewWindow
895 ::onZoomOut()
896 {
897   myRWInteractor->GetSInteractorStyle()->IncrementalZoom( -INCREMENT_FOR_OP );
898 }
899
900 //=======================================================================
901 // name    : onRotateLeft
902 // Purpose : Performs incremental rotating to the left
903 //=======================================================================
904 void
905 SVTK_ViewWindow
906 ::onRotateLeft()
907 {
908   myRWInteractor->GetSInteractorStyle()->IncrementalRotate( -INCREMENT_FOR_OP, 0 );
909 }
910
911 //=======================================================================
912 // name    : onRotateRight
913 // Purpose : Performs incremental rotating to the right
914 //=======================================================================
915 void
916 SVTK_ViewWindow
917 ::onRotateRight()
918 {
919   myRWInteractor->GetSInteractorStyle()->IncrementalRotate( INCREMENT_FOR_OP, 0 );
920 }
921
922 //=======================================================================
923 // name    : onRotateUp
924 // Purpose : Performs incremental rotating to the top
925 //=======================================================================
926 void
927 SVTK_ViewWindow
928 ::onRotateUp()
929 {
930   myRWInteractor->GetSInteractorStyle()->IncrementalRotate( 0, -INCREMENT_FOR_OP );
931 }
932
933 //=======================================================================
934 void
935 SVTK_ViewWindow
936 ::onKeyPressed(QKeyEvent* event)
937 {
938   emit keyPressed( this, event );
939 }
940
941 //=======================================================================
942 void
943 SVTK_ViewWindow
944 ::onKeyReleased(QKeyEvent* event)
945 {
946   emit keyReleased( this, event );
947 }
948
949 //=======================================================================
950 void
951 SVTK_ViewWindow
952 ::onMousePressed(QMouseEvent* event)
953 {
954   emit mousePressed(this, event);
955 }
956
957 //=======================================================================
958 void
959 SVTK_ViewWindow
960 ::onMouseReleased(QMouseEvent* event)
961 {
962   emit mouseReleased( this, event );
963 }
964
965 //=======================================================================
966 void
967 SVTK_ViewWindow
968 ::onMouseMoving(QMouseEvent* event)
969 {
970   emit mouseMoving( this, event );
971 }
972
973 //=======================================================================
974 void
975 SVTK_ViewWindow
976 ::onMouseDoubleClicked( QMouseEvent* event )
977 {
978   emit mouseDoubleClicked( this, event );
979 }
980
981 //=======================================================================
982 // name    : onRotateDown
983 // Purpose : Performs incremental rotating to the bottom
984 //=======================================================================
985 void
986 SVTK_ViewWindow
987 ::onRotateDown()
988 {
989   myRWInteractor->GetSInteractorStyle()->IncrementalRotate( 0, INCREMENT_FOR_OP );
990 }
991
992 //----------------------------------------------------------------------------
993 void
994 SVTK_ViewWindow
995 ::InsertActor( SALOME_Actor* theActor, bool theMoveInternalActors )
996 {
997   theActor->AddToRender(myRenderer);
998   theActor->SetTransform(myTransform);
999   if(theMoveInternalActors) 
1000     myRWInteractor->MoveInternalActors();
1001 }
1002
1003 //----------------------------------------------------------------------------
1004 void
1005 SVTK_ViewWindow
1006 ::AddActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ )
1007 {
1008   InsertActor(theActor);
1009   if(theUpdate) 
1010     Repaint();
1011 }
1012
1013 //----------------------------------------------------------------------------
1014 void
1015 SVTK_ViewWindow
1016 ::RemoveActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ )
1017 {
1018   theActor->RemoveFromRender(myRenderer);
1019   if(theUpdate) 
1020     Repaint();
1021 }
1022
1023 //----------------------------------------------------------------------------
1024 void
1025 SVTK_ViewWindow
1026 ::MoveActor( SALOME_Actor* theActor)
1027 {
1028   RemoveActor(theActor);
1029   InsertActor(theActor,true);
1030 }
1031
1032 //----------------------------------------------------------------------------
1033 QImage
1034 SVTK_ViewWindow
1035 ::dumpView()
1036 {
1037   QPixmap px = QPixmap::grabWindow( myRenderWindow->winId() );
1038   return px.convertToImage();
1039 }
1040
1041 //----------------------------------------------------------------------------
1042 void 
1043 SVTK_ViewWindow
1044 ::action( const int theAction  )
1045 {
1046   switch ( theAction ) {
1047   case SUIT_Accel::PanLeft     : onPanLeft();     break;
1048   case SUIT_Accel::PanRight    : onPanRight();    break;
1049   case SUIT_Accel::PanUp       : onPanUp();       break;
1050   case SUIT_Accel::PanDown     : onPanDown();     break;
1051   case SUIT_Accel::ZoomIn      : onZoomIn();      break;
1052   case SUIT_Accel::ZoomOut     : onZoomOut();     break;
1053   case SUIT_Accel::ZoomFit     : onFitAll();      break;
1054   case SUIT_Accel::RotateLeft  : onRotateLeft();  break;
1055   case SUIT_Accel::RotateRight : onRotateRight(); break;
1056   case SUIT_Accel::RotateUp    : onRotateUp();    break;
1057   case SUIT_Accel::RotateDown  : onRotateDown();  break;
1058   }   
1059 }