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