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