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