Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / VTKViewer / VTKViewer_ViewWindow.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include "VTKViewer_ViewWindow.h"
23 #include "VTKViewer_ViewModel.h"
24 #include "VTKViewer_RenderWindow.h"
25 #include "VTKViewer_RenderWindowInteractor.h"
26 #include "VTKViewer_InteractorStyle.h"
27 #include "VTKViewer_Trihedron.h"
28 #include "VTKViewer_Transform.h"
29 #include "VTKViewer_Utilities.h"
30
31 #include <SUIT_Session.h>
32 #include <SUIT_MessageBox.h>
33 #include <SUIT_Tools.h>
34 #include <SUIT_ResourceMgr.h>
35
36 #include <QImage>
37
38 #include <vtkRenderer.h>
39 #include <vtkCamera.h>
40
41 #include <QtxToolBar.h>
42 #include <QtxMultiAction.h>
43
44 /*! Construction*/
45 VTKViewer_ViewWindow::VTKViewer_ViewWindow( SUIT_Desktop* theDesktop, 
46                                             VTKViewer_Viewer* theModel,
47                                             VTKViewer_InteractorStyle* iStyle,
48                                             VTKViewer_RenderWindowInteractor* rw )
49 : SUIT_ViewWindow( theDesktop )
50 {
51   myModel = theModel;
52
53   myTrihedron = VTKViewer_Trihedron::New();
54   myTransform = VTKViewer_Transform::New();
55   myRenderer  = vtkRenderer::New() ;
56
57   myTrihedron->AddToRender( myRenderer );
58
59   myRenderWindow = new VTKViewer_RenderWindow( this, "RenderWindow" );
60   setCentralWidget(myRenderWindow);
61   myRenderWindow->setFocusPolicy( Qt::StrongFocus );
62   myRenderWindow->setFocus();
63
64   myRenderWindow->getRenderWindow()->AddRenderer( myRenderer );
65
66   myRenderer->GetActiveCamera()->ParallelProjectionOn();
67   myRenderer->LightFollowCameraOn();
68   myRenderer->TwoSidedLightingOn();
69
70   // Set BackgroundColor
71   QString BgrColorRed   = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorRed");
72   QString BgrColorGreen = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorGreen");
73   QString BgrColorBlue  = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorBlue");
74
75   if( !BgrColorRed.isEmpty() && !BgrColorGreen.isEmpty() && !BgrColorBlue.isEmpty() ) 
76     myRenderer->SetBackground( BgrColorRed.toInt()/255., BgrColorGreen.toInt()/255., BgrColorBlue.toInt()/255. );
77   else
78     myRenderer->SetBackground( 0, 0, 0 );
79   
80   // Create an interactor.
81   myRWInteractor = rw ? rw : VTKViewer_RenderWindowInteractor::New();
82   myRWInteractor->SetRenderWindow( myRenderWindow->getRenderWindow() );
83
84   VTKViewer_InteractorStyle* RWS = iStyle ? iStyle : VTKViewer_InteractorStyle::New();
85   RWS->setGUIWindow( myRenderWindow );
86   myRWInteractor->SetInteractorStyle( RWS ); 
87
88   myRWInteractor->Initialize();
89   RWS->setTriedron( myTrihedron );
90   RWS->FindPokedRenderer( 0, 0 );
91
92   setCentralWidget( myRenderWindow );
93
94   myToolBar = new QtxToolBar( true, tr("LBL_TOOLBAR_LABEL"), this );
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   connect( myRWInteractor, SIGNAL(RenderWindowModified()),
112            myRenderWindow, SLOT(update()) );
113
114   connect( myRenderWindow, SIGNAL(contextMenuRequested( QContextMenuEvent * )),
115            this,           SIGNAL(contextMenuRequested( QContextMenuEvent * )) );
116
117   connect( myRWInteractor, SIGNAL(contextMenuRequested( QContextMenuEvent * )),
118            this,           SIGNAL(contextMenuRequested( QContextMenuEvent * )) );
119
120
121   onResetView();
122 }
123
124 /*!Destructor.*/
125 VTKViewer_ViewWindow::~VTKViewer_ViewWindow()
126 {
127   myTransform->Delete();
128   // In order to ensure that the interactor unregisters
129   // this RenderWindow, we assign a NULL RenderWindow to 
130   // it before deleting it.
131   myRWInteractor->SetRenderWindow( NULL );
132   myRWInteractor->Delete();
133   
134   //m_RW->Delete() ;
135   myRenderer->RemoveAllViewProps();
136   //m_Renderer->Delete() ;
137   myTrihedron->Delete();
138 }
139
140 /*!Checks: is trihedron displayed.*/
141 bool VTKViewer_ViewWindow::isTrihedronDisplayed(){
142   return myTrihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
143 }
144
145 /*!Activates 'zooming' transformation*/
146 void VTKViewer_ViewWindow::activateZoom()
147 {
148   myRWInteractor->GetInteractorStyle()->startZoom();
149 }
150
151 /*!Activates 'panning' transformation*/
152 void VTKViewer_ViewWindow::activatePanning()
153 {
154   myRWInteractor->GetInteractorStyle()->startPan();
155 }
156
157 /*!Activates 'rotation' transformation*/
158 void VTKViewer_ViewWindow::activateRotation()
159 {
160   myRWInteractor->GetInteractorStyle()->startRotate();
161 }
162
163 /*!Activate global panning.*/
164 void VTKViewer_ViewWindow::activateGlobalPanning()
165 {
166   //if(myTrihedron->GetVisibleActorCount(myRenderer))
167   myRWInteractor->GetInteractorStyle()->startGlobalPan();
168 }
169
170 /*!Activates 'fit area' transformation*/
171 void VTKViewer_ViewWindow::activateWindowFit()
172 {
173   myRWInteractor->GetInteractorStyle()->startFitArea();
174 }
175
176 /*!Create actions:*/
177 void VTKViewer_ViewWindow::createActions()
178 {
179   if (!myActionsMap.isEmpty()) return;
180   
181   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
182   
183   QtxAction* aAction;
184
185   //! \li Dump view
186   aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
187                            tr( "MNU_DUMP_VIEW" ), 0, this);
188   aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
189   connect(aAction, SIGNAL(activated()), this, SLOT(onDumpView()));
190   myActionsMap[ DumpId ] = aAction;
191
192   //! \li FitAll
193   aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
194                            tr( "MNU_FITALL" ), 0, this);
195   aAction->setStatusTip(tr("DSC_FITALL"));
196   connect(aAction, SIGNAL(activated()), this, SLOT(onFitAll()));
197   myActionsMap[ FitAllId ] = aAction;
198
199   //! \li FitRect
200   aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
201                            tr( "MNU_FITRECT" ), 0, this);
202   aAction->setStatusTip(tr("DSC_FITRECT"));
203   connect(aAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
204   myActionsMap[ FitRectId ] = aAction;
205
206   //! \li Zoom
207   aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
208                            tr( "MNU_ZOOM_VIEW" ), 0, this);
209   aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
210   connect(aAction, SIGNAL(activated()), this, SLOT(activateZoom()));
211   myActionsMap[ ZoomId ] = aAction;
212
213   //! \li Panning
214   aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
215                            tr( "MNU_PAN_VIEW" ), 0, this);
216   aAction->setStatusTip(tr("DSC_PAN_VIEW"));
217   connect(aAction, SIGNAL(activated()), this, SLOT(activatePanning()));
218   myActionsMap[ PanId ] = aAction;
219
220   //! \li Global Panning
221   aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
222                            tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
223   aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
224   connect(aAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
225   myActionsMap[ GlobalPanId ] = aAction;
226
227   //! \li Rotation
228   aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
229                            tr( "MNU_ROTATE_VIEW" ), 0, this);
230   aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
231   connect(aAction, SIGNAL(activated()), this, SLOT(activateRotation()));
232   myActionsMap[ RotationId ] = aAction;
233
234   //! \li Projections
235   aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
236                            tr( "MNU_FRONT_VIEW" ), 0, this);
237   aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
238   connect(aAction, SIGNAL(activated()), this, SLOT(onFrontView()));
239   myActionsMap[ FrontId ] = aAction;
240
241   //! \li Back view
242   aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
243                            tr( "MNU_BACK_VIEW" ), 0, this);
244   aAction->setStatusTip(tr("DSC_BACK_VIEW"));
245   connect(aAction, SIGNAL(activated()), this, SLOT(onBackView()));
246   myActionsMap[ BackId ] = aAction;
247
248   //! \li Top view
249   aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
250                            tr( "MNU_TOP_VIEW" ), 0, this);
251   aAction->setStatusTip(tr("DSC_TOP_VIEW"));
252   connect(aAction, SIGNAL(activated()), this, SLOT(onTopView()));
253   myActionsMap[ TopId ] = aAction;
254
255   //! \li Bottom view
256   aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
257                            tr( "MNU_BOTTOM_VIEW" ), 0, this);
258   aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
259   connect(aAction, SIGNAL(activated()), this, SLOT(onBottomView()));
260   myActionsMap[ BottomId ] = aAction;
261
262   //! \li Left view
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   //! \li Right view
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   //! \li 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   //! \li Trihedron shown
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(onTrihedronShow()));
288   myActionsMap[ TrihedronShowId ] = aAction;
289 }
290
291 /*!Create tool bar.*/
292 void VTKViewer_ViewWindow::createToolBar()
293 {
294   myToolBar->addAction( myActionsMap[DumpId] );
295   myToolBar->addAction( myActionsMap[TrihedronShowId] );
296
297   QtxMultiAction* aScaleAction = new QtxMultiAction( this );
298   aScaleAction->insertAction( myActionsMap[FitAllId] );
299   aScaleAction->insertAction( myActionsMap[FitRectId] );
300   aScaleAction->insertAction( myActionsMap[ZoomId] );
301   myToolBar->addAction( aScaleAction );
302
303   QtxMultiAction* aPanningAction = new QtxMultiAction( this );
304   aPanningAction->insertAction( myActionsMap[PanId] );
305   aPanningAction->insertAction( myActionsMap[GlobalPanId] );
306   myToolBar->addAction( aPanningAction );
307
308   myToolBar->addAction( myActionsMap[RotationId] );
309
310   QtxMultiAction* aViewsAction = new QtxMultiAction(myToolBar);
311   aViewsAction->insertAction( myActionsMap[FrontId] );
312   aViewsAction->insertAction( myActionsMap[BackId] );
313   aViewsAction->insertAction( myActionsMap[TopId] );
314   aViewsAction->insertAction( myActionsMap[BottomId] );
315   aViewsAction->insertAction( myActionsMap[LeftId] );
316   aViewsAction->insertAction( myActionsMap[RightId] );
317   myToolBar->addAction( aViewsAction );
318
319   myToolBar->addAction( myActionsMap[ResetId] );
320 }
321
322 /*!On front view event.*/
323 void VTKViewer_ViewWindow::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 /*!On back view slot.*/
333 void VTKViewer_ViewWindow::onBackView()
334 {
335   vtkCamera* camera = myRenderer->GetActiveCamera();
336   camera->SetPosition(-1,0,0);
337   camera->SetViewUp(0,0,1);
338   camera->SetFocalPoint(0,0,0);
339   onFitAll();
340 }
341
342 /*!On back view slot.*/
343 void VTKViewer_ViewWindow::onTopView()
344 {
345   vtkCamera* camera = myRenderer->GetActiveCamera();
346   camera->SetPosition(0,0,1);
347   camera->SetViewUp(0,1,0);
348   camera->SetFocalPoint(0,0,0);
349   onFitAll();
350 }
351
352 /*!On bottom view slot.*/
353 void VTKViewer_ViewWindow::onBottomView()
354 {
355   vtkCamera* camera = myRenderer->GetActiveCamera();
356   camera->SetPosition(0,0,-1);
357   camera->SetViewUp(0,1,0);
358   camera->SetFocalPoint(0,0,0);
359   onFitAll();
360 }
361
362 /*!On left view slot.*/
363 void VTKViewer_ViewWindow::onLeftView()
364 {
365   vtkCamera* camera = myRenderer->GetActiveCamera(); 
366   camera->SetPosition(0,-1,0);
367   camera->SetViewUp(0,0,1);
368   camera->SetFocalPoint(0,0,0);
369   onFitAll();
370 }
371
372 /*!On right view slot.*/
373 void VTKViewer_ViewWindow::onRightView()
374 {
375   vtkCamera* camera = myRenderer->GetActiveCamera();
376   camera->SetPosition(0,1,0);
377   camera->SetViewUp(0,0,1);
378   camera->SetFocalPoint(0,0,0);
379   onFitAll();
380 }
381
382 /*!On reset view slot.*/
383 void VTKViewer_ViewWindow::onResetView()
384 {
385   int aTriedronIsVisible = isTrihedronDisplayed();
386   myTrihedron->SetVisibility( VTKViewer_Trihedron::eOnlyLineOn );
387   ::ResetCamera(myRenderer,true);  
388   vtkCamera* aCamera = myRenderer->GetActiveCamera();
389   aCamera->SetPosition(1,-1,1);
390   aCamera->SetViewUp(0,0,1);
391   ::ResetCamera(myRenderer,true);  
392   if(aTriedronIsVisible) myTrihedron->VisibilityOn();
393   else myTrihedron->VisibilityOff();
394   static vtkFloatingPointType aCoeff = 3.0;
395   aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale());
396   Repaint();
397 }
398
399 /*!On fit all slot.*/
400 void VTKViewer_ViewWindow::onFitAll()
401 {
402   myRWInteractor->GetInteractorStyle()->ViewFitAll();
403   Repaint();
404 }
405
406 /*!Set background of the viewport*/
407 void VTKViewer_ViewWindow::setBackgroundColor( const QColor& color )
408 {
409   if ( myRenderer )
410     myRenderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. );
411 }
412
413 /*!Returns background of the viewport*/
414 QColor VTKViewer_ViewWindow::backgroundColor() const
415 {
416   vtkFloatingPointType backint[3];
417   if ( myRenderer ) {
418     myRenderer->GetBackground( backint );
419     return QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255));
420   }
421   return palette().color( backgroundRole() );
422 }
423
424 /*!Repaint window. If \a theUpdateTrihedron is true - recalculate trihedron.*/
425 void VTKViewer_ViewWindow::Repaint(bool theUpdateTrihedron)
426 {
427   if (theUpdateTrihedron) onAdjustTrihedron();
428   myRenderWindow->update();
429 }
430
431 /*!Get scale of transformation filter.*/
432 void VTKViewer_ViewWindow::GetScale( double theScale[3] ) {
433   myTransform->GetScale( theScale );
434 }
435
436 /*!Set scale of transformation filter and repaint window.*/
437 void VTKViewer_ViewWindow::SetScale( double theScale[3] ) {
438   myTransform->SetMatrixScale( theScale[0], theScale[1], theScale[2] );
439   myRWInteractor->Render();
440   Repaint();
441 }
442
443 /*!Calculation trihedron size.*/
444 void VTKViewer_ViewWindow::onAdjustTrihedron(){   
445   if( !isTrihedronDisplayed() ) 
446     return;
447   int aVisibleNum = myTrihedron->GetVisibleActorCount(myRenderer);
448   if(aVisibleNum){
449     // calculating diagonal of visible props of the renderer
450     vtkFloatingPointType bnd[6];
451     myTrihedron->VisibilityOff();
452     ::ComputeVisiblePropBounds(myRenderer,bnd);
453     myTrihedron->VisibilityOn();
454     vtkFloatingPointType aLength = 0;
455     static bool CalcByDiag = false;
456     if(CalcByDiag){
457       aLength = sqrt((bnd[1]-bnd[0])*(bnd[1]-bnd[0])+
458                      (bnd[3]-bnd[2])*(bnd[3]-bnd[2])+
459                      (bnd[5]-bnd[4])*(bnd[5]-bnd[4]));
460     }else{
461       aLength = bnd[1]-bnd[0];
462       aLength = qMax((bnd[3]-bnd[2]),aLength);
463       aLength = qMax((bnd[5]-bnd[4]),aLength);
464     }
465    
466     static vtkFloatingPointType aSizeInPercents = 105;
467     QString aSetting;// = SUIT_CONFIG->getSetting("Viewer:TrihedronSize");
468     if(!aSetting.isEmpty()) aSizeInPercents = aSetting.toFloat();
469
470     static vtkFloatingPointType EPS_SIZE = 5.0E-3;
471     vtkFloatingPointType aSize = myTrihedron->GetSize();
472     vtkFloatingPointType aNewSize = aLength*aSizeInPercents/100.0;
473     // if the new trihedron size have sufficient difference, then apply the value
474     if(fabs(aNewSize-aSize) > aSize*EPS_SIZE || fabs(aNewSize-aSize) > aNewSize*EPS_SIZE){
475       myTrihedron->SetSize(aNewSize);
476     }
477   }
478   ::ResetCameraClippingRange(myRenderer);
479 }
480
481 /*!Emit key pressed.*/
482 void VTKViewer_ViewWindow::onKeyPressed(QKeyEvent* event)
483 {
484   emit keyPressed( this, event );
485 }
486
487 /*!Emit key released.*/
488 void VTKViewer_ViewWindow::onKeyReleased(QKeyEvent* event)
489 {
490   emit keyReleased( this, event );
491 }
492
493 /*!Emit key pressed.*/
494 void VTKViewer_ViewWindow::onMousePressed(QMouseEvent* event)
495 {
496   emit mousePressed(this, event);
497 }
498
499 /*!Emit mouse released.*/
500 void VTKViewer_ViewWindow::onMouseReleased(QMouseEvent* event)
501 {
502   emit mouseReleased( this, event );
503 }
504
505 /*!Emit mouse moving.*/
506 void VTKViewer_ViewWindow::onMouseMoving(QMouseEvent* event)
507 {
508   emit mouseMoving( this, event );
509 }
510
511 /*!Emit mouse double clicked.*/
512 void VTKViewer_ViewWindow::onMouseDoubleClicked( QMouseEvent* event )
513 {
514   emit mouseDoubleClicked( this, event );
515 }
516
517 /*!Insert actor to renderer and transformation filter.
518  *Move Internal actors, if \a theMoveInternalActors is true.
519  */
520 void VTKViewer_ViewWindow::InsertActor( VTKViewer_Actor* theActor, bool theMoveInternalActors ){
521   theActor->AddToRender(myRenderer);
522   theActor->SetTransform(myTransform);
523   if(theMoveInternalActors) 
524     myRWInteractor->MoveInternalActors();
525 }
526
527 /*!Add actor.Repaint window if \a theUpdate is true.
528  *@see InsertActor( VTKViewer_Actor* theActor, bool theMoveInternalActors )
529  */
530 void VTKViewer_ViewWindow::AddActor( VTKViewer_Actor* theActor, bool theUpdate /*=false*/ ){
531   InsertActor(theActor);
532   if(theUpdate) 
533     Repaint();
534 }
535
536 /*!Remove \a theActor from renderer and pepaint, if \a theUpdate is true.*/
537 void VTKViewer_ViewWindow::RemoveActor( VTKViewer_Actor* theActor, bool theUpdate /*=false*/ ){
538   theActor->RemoveFromRender(myRenderer);
539   if(theUpdate) 
540     Repaint();
541 }
542
543 /*!@see RemoveActor() and InsertActor().*/
544 void VTKViewer_ViewWindow::MoveActor( VTKViewer_Actor* theActor)
545 {
546   RemoveActor(theActor);
547   InsertActor(theActor,true);
548 }
549
550 /*!On trihedron show slot.*/
551 void VTKViewer_ViewWindow::onTrihedronShow()
552 {
553   if (isTrihedronDisplayed())
554     myTrihedron->VisibilityOff();
555   else
556     myTrihedron->VisibilityOn();
557   myRenderWindow->update();
558 }
559
560 /*!Dump view.*/
561 QImage VTKViewer_ViewWindow::dumpView()
562 {
563   QPixmap px = QPixmap::grabWindow( myRenderWindow->winId() );
564   return px.toImage();
565 }
566
567 /*! The method returns the visual parameters of this view as a formated string
568  */
569 QString VTKViewer_ViewWindow::getVisualParameters()
570 {
571   double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
572
573   vtkCamera* camera = myRenderer->GetActiveCamera();
574   camera->GetPosition( pos );
575   camera->GetFocalPoint( focalPnt );
576   camera->GetViewUp( viewUp );
577   parScale = camera->GetParallelScale();
578   GetScale( scale );
579
580   QString retStr;
581   retStr.sprintf( "%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e", 
582                   pos[0], pos[1], pos[2], focalPnt[0], focalPnt[1], focalPnt[2], viewUp[0], viewUp[1], 
583                   viewUp[2], parScale, scale[0], scale[1], scale[2] );
584   return retStr;
585 }
586
587 /*! The method restors visual parameters of this view from a formated string
588  */
589 void VTKViewer_ViewWindow::setVisualParameters( const QString& parameters )
590 {
591   QStringList paramsLst = parameters.split( '*' );
592   if ( paramsLst.size() == 13 ) {
593     double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
594     pos[0] = paramsLst[0].toDouble();
595     pos[1] = paramsLst[1].toDouble();
596     pos[2] = paramsLst[2].toDouble();
597     focalPnt[0] = paramsLst[3].toDouble();
598     focalPnt[1] = paramsLst[4].toDouble();
599     focalPnt[2] = paramsLst[5].toDouble();
600     viewUp[0] = paramsLst[6].toDouble();
601     viewUp[1] = paramsLst[7].toDouble();
602     viewUp[2] = paramsLst[8].toDouble();
603     parScale = paramsLst[9].toDouble();
604     scale[0] = paramsLst[10].toDouble();
605     scale[1] = paramsLst[11].toDouble();
606     scale[2] = paramsLst[12].toDouble();
607
608     vtkCamera* camera = myRenderer->GetActiveCamera();
609     camera->SetPosition( pos );
610     camera->SetFocalPoint( focalPnt );
611     camera->SetViewUp( viewUp );
612     camera->SetParallelScale( parScale );
613     myTransform->SetMatrixScale( scale[0], scale[1], scale[2] );
614     myRWInteractor->Render();
615   }
616 }