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