Salome HOME
Copyright update 2020
[modules/gui.git] / src / SVTK / SVTK_ViewWindow.cxx
1 // Copyright (C) 2007-2020  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, or (at your option) any later version.
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
23 #include "SVTK_NonIsometricDlg.h"
24 #include "SVTK_UpdateRateDlg.h"
25 #include "SVTK_CubeAxesDlg.h"
26 #include "SVTK_PsOptionsDlg.h"
27 #include "SVTK_SetRotationPointDlg.h"
28 #include "SVTK_ViewParameterDlg.h"
29 #include "SVTK_ViewModel.h"
30 #include "VTKViewer_Texture.h"
31 #include "VTKViewer_OpenGLRenderer.h"
32
33 #include "SALOME_Actor.h"
34
35 #include <QMenu>
36 #include <QToolBar>
37 #include <QEvent>
38 #include <QFileInfo>
39 #include <QSignalMapper>
40 #include <QXmlStreamWriter>
41 #include <QXmlStreamReader>
42 #include <QXmlStreamAttributes>
43
44 #include <vtkTextProperty.h>
45 #include <vtkActorCollection.h>
46 #include <vtkRenderWindow.h>
47 #include <vtkRenderer.h>
48 #include <vtkCamera.h>
49 #include <vtkPointPicker.h>
50 #include <vtkCellPicker.h>
51 #include <vtkAxisActor2D.h>
52 #include <vtkGL2PSExporter.h>
53 #include <vtkInteractorStyle.h>
54 #include <vtkProperty.h>
55 #include <vtkCallbackCommand.h>
56 #include <vtkJPEGReader.h>
57 #include <vtkBMPReader.h>
58 #include <vtkTIFFReader.h>
59 #include <vtkPNGReader.h>
60 #include <vtkMetaImageReader.h>
61 #include <vtkImageMapToColors.h>
62 #include <vtkTexture.h>
63
64 #include "QtxAction.h"
65
66 #include "SUIT_Session.h"
67 #include "SUIT_MessageBox.h"
68 #include "SUIT_Accel.h"
69 #include "SUIT_Tools.h"
70 #include "SUIT_ResourceMgr.h"
71 #include "SUIT_Accel.h"
72 #include "SUIT_OverrideCursor.h"
73 #include "SUIT_ViewManager.h"
74 #include "QtxActionToolMgr.h"
75 #include "QtxMultiAction.h"
76 #include "QtxActionGroup.h"
77
78 #include "VTKViewer_Utilities.h"
79 #include "VTKViewer_Trihedron.h"
80 #include "VTKViewer_Actor.h"
81
82 #include "SVTK_View.h"
83 #include "SVTK_Selector.h"
84
85 #include "SVTK_Event.h"
86 #include "SVTK_Renderer.h"
87 #include "SVTK_ViewWindow.h"
88 #include "SVTK_InteractorStyle.h"
89 #include "SVTK_RenderWindowInteractor.h"
90 #include "SVTK_GenericRenderWindowInteractor.h"
91 #include "SVTK_CubeAxesActor2D.h"
92 #include "SVTK_ComboAction.h"
93 #include "SVTK_KeyFreeInteractorStyle.h"
94 #include "SVTK_Selector.h"
95 #include "SVTK_Recorder.h"
96 #include "SVTK_RecorderDlg.h"
97
98 #include "salomevtkPVAxesWidget.h"
99 #include "salomevtkPVAxesActor.h"
100
101 #include "SALOME_ListIO.hxx"
102
103 #include "VTKViewer_Algorithm.h"
104 #include "SVTK_Functor.h"
105
106 #include <OpenGLUtils_FrameBuffer.h>
107
108 #ifdef __APPLE__
109 #include <OpenGL/gl.h>
110 #else
111 #include <GL/gl.h>
112 #endif
113
114 namespace SVTK
115 {
116   int convertAction( const int accelAction )
117   {
118     switch ( accelAction ) {
119     case SUIT_Accel::PanLeft     : return SVTK::PanLeftEvent;
120     case SUIT_Accel::PanRight    : return SVTK::PanRightEvent;
121     case SUIT_Accel::PanUp       : return SVTK::PanUpEvent;
122     case SUIT_Accel::PanDown     : return SVTK::PanDownEvent;
123     case SUIT_Accel::ZoomIn      : return SVTK::ZoomInEvent;
124     case SUIT_Accel::ZoomOut     : return SVTK::ZoomOutEvent;
125     case SUIT_Accel::RotateLeft  : return SVTK::RotateLeftEvent;
126     case SUIT_Accel::RotateRight : return SVTK::RotateRightEvent;
127     case SUIT_Accel::RotateUp    : return SVTK::RotateUpEvent;
128     case SUIT_Accel::RotateDown  : return SVTK::RotateDownEvent;  
129     }
130     return accelAction;
131   }
132 }
133
134 /*!
135   Constructor
136 */
137 SVTK_ViewWindow::SVTK_ViewWindow(SUIT_Desktop* theDesktop):
138   SUIT_ViewWindow(theDesktop),
139   myView(NULL),
140   myDumpImage(QImage()),
141   myKeyFreeInteractorStyle(SVTK_KeyFreeInteractorStyle::New()),
142   myEventCallbackCommand(vtkCallbackCommand::New())
143 {
144   setWindowFlags( windowFlags() & ~Qt::Window );
145   // specific of vtkSmartPointer
146   myKeyFreeInteractorStyle->Delete();
147 }
148
149 /*!
150   To initialize #SVTK_ViewWindow instance
151 */
152 void SVTK_ViewWindow::Initialize(SVTK_ViewModelBase* theModel)
153 {
154   myModel = theModel;
155   myInteractor = new SVTK_RenderWindowInteractor(this,"SVTK_RenderWindowInteractor");
156
157   SVTK_Selector* aSelector = SVTK_Selector::New();
158   int aPreselectionMode =  SUIT_Session::session()->resourceMgr()->
159     integerValue( "VTKViewer", "preselection", Standard_Preselection );
160   aSelector->SetDynamicPreSelection( aPreselectionMode == Dynamic_Preselection );
161   aSelector->SetPreSelectionEnabled( aPreselectionMode != Preselection_Disabled );
162   bool isSelectionEnabled = SUIT_Session::session()->resourceMgr()->
163     booleanValue( "VTKViewer", "enable_selection", true );
164   aSelector->SetSelectionEnabled( isSelectionEnabled );
165
166   SVTK_GenericRenderWindowInteractor* aDevice = SVTK_GenericRenderWindowInteractor::New();
167   aDevice->SetRenderWidget(myInteractor);
168   aDevice->SetSelector(aSelector);
169
170   SVTK_Renderer* aRenderer = SVTK_Renderer::New();
171   aRenderer->Initialize(aDevice,aSelector);
172
173   myInteractor->Initialize(aDevice,aRenderer,aSelector);
174
175   aDevice->Delete();
176   aRenderer->Delete();
177   aSelector->Delete();
178
179   myToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_LABEL"),                       // title (language-dependant)
180                                         QString( "VTKViewerViewOperations" ),          // name (language-independant)
181                                         false );                                       // disable floatable toolbar
182
183   myRecordingToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_RECORD_LABEL"),       // title (language-dependant)
184                                                  QString( "VTKRecordingOperations" ),  // name (language-independant)
185                                                  false );                              // disable floatable toolbar
186
187   createActions( SUIT_Session::session()->resourceMgr() );
188   createToolBar();
189
190   SetEventDispatcher(myInteractor->GetDevice());
191   myInteractor->setBackgroundRole( QPalette::NoRole );//NoBackground
192   myInteractor->setFocusPolicy(Qt::StrongFocus);
193   myInteractor->setFocus();
194   bool isSupportQuadBuffer = SUIT_Session::session()->resourceMgr()->
195     booleanValue( "VTKViewer", "enable_quad_buffer_support", false );
196   myInteractor->getRenderWindow()->SetStereoCapableWindow((int)isSupportQuadBuffer);
197   setFocusProxy(myInteractor);
198
199   myUpdateRateDlg = new SVTK_UpdateRateDlg( getAction( UpdateRate ), this, "SVTK_UpdateRateDlg" );
200   myNonIsometricDlg = new SVTK_NonIsometricDlg( getAction( NonIsometric ), this, "SVTK_NonIsometricDlg" );
201   myCubeAxesDlg = new SVTK_CubeAxesDlg( getAction( GraduatedAxes ), this, "SVTK_CubeAxesDlg" );
202   myCubeAxesDlg->initialize();
203   mySetRotationPointDlg = new SVTK_SetRotationPointDlg
204     ( getAction( ChangeRotationPointId ), this, "SVTK_SetRotationPointDlg" );
205   myViewParameterDlg = new SVTK_ViewParameterDlg
206     ( getAction( ViewParametersId ), this, "SVTK_ViewParameterDlg" );
207   
208   myDefaultInteractorStyle = SVTK_InteractorStyle::New();
209   myInteractor->PushInteractorStyle(myDefaultInteractorStyle);
210   myDefaultInteractorStyle->Delete();
211   
212   myRecorder = SVTK_Recorder::New();
213   
214   myRecorder->SetNbFPS( 17.3 );
215   myRecorder->SetQuality( 100 );
216   myRecorder->SetProgressiveMode( true );
217   myRecorder->SetUseSkippedFrames( true );
218   myRecorder->SetRenderWindow( myInteractor->getRenderWindow() );
219   
220   setCentralWidget(myInteractor);
221   
222   myAxesWidget = salomevtk::vtkPVAxesWidget::New();
223   myAxesWidget->SetParentRenderer(aRenderer->GetDevice());
224   myAxesWidget->SetViewport(0, 0, 0.25, 0.25);
225   myAxesWidget->SetInteractor(myInteractor->GetDevice());
226   myAxesWidget->SetEnabled(1);
227   myAxesWidget->SetInteractive(0);
228
229   salomevtk::vtkPVAxesActor* anAxesActor = myAxesWidget->GetAxesActor();
230   anAxesActor->GetXAxisTipProperty()->SetColor(   1.0, 0.0, 0.0 );
231   anAxesActor->GetXAxisShaftProperty()->SetColor( 1.0, 0.0, 0.0 );
232   anAxesActor->GetXAxisLabelProperty()->SetColor( 1.0, 0.0, 0.0 );
233   anAxesActor->GetYAxisTipProperty()->SetColor(   0.0, 1.0, 0.0 );
234   anAxesActor->GetYAxisShaftProperty()->SetColor( 0.0, 1.0, 0.0 );
235   anAxesActor->GetYAxisLabelProperty()->SetColor( 0.0, 1.0, 0.0 );
236   anAxesActor->GetZAxisTipProperty()->SetColor(   0.0, 0.0, 1.0 );
237   anAxesActor->GetZAxisShaftProperty()->SetColor( 0.0, 0.0, 1.0 );
238   anAxesActor->GetZAxisLabelProperty()->SetColor( 0.0, 0.0, 1.0 );
239
240   myView = new SVTK_View(this);
241   Initialize(myView,theModel);
242
243
244   myEventCallbackCommand->SetClientData(this);
245   myEventCallbackCommand->SetCallback(SVTK_ViewWindow::ProcessEvents);
246   myEventCallbackCommand->Delete();
247
248   GetInteractor()->GetInteractorStyle()->AddObserver(SVTK::OperationFinished,
249                                                      myEventCallbackCommand.GetPointer(), 0.0);
250   myKeyFreeInteractorStyle->AddObserver(SVTK::OperationFinished,
251                                         myEventCallbackCommand.GetPointer(), 0.0);
252
253
254
255   myInteractor->getRenderWindow()->Render();
256   setBackground( Qtx::BackgroundData( Qt::black ) ); // set default background
257   onResetView();
258 }
259
260 /*!
261   To initialize #SVTK_ViewWindow instance
262 */
263 void SVTK_ViewWindow::Initialize(SVTK_View* theView,
264                                  SVTK_ViewModelBase* theModel)
265 {
266   connect(theView,SIGNAL(KeyPressed(QKeyEvent*)),
267           this,SLOT(onKeyPressed(QKeyEvent*)) );
268   connect(theView,SIGNAL(KeyReleased(QKeyEvent*)),
269           this,SLOT(onKeyReleased(QKeyEvent*)));
270   connect(theView,SIGNAL(MouseButtonPressed(QMouseEvent*)),
271           this,SLOT(onMousePressed(QMouseEvent*)));
272   connect(theView,SIGNAL(MouseButtonReleased(QMouseEvent*)),
273           this,SLOT(onMouseReleased(QMouseEvent*)));
274   connect(theView,SIGNAL(MouseDoubleClicked(QMouseEvent*)),
275           this,SLOT(onMouseDoubleClicked(QMouseEvent*)));
276   connect(theView,SIGNAL(MouseMove(QMouseEvent*)),
277           this,SLOT(onMouseMoving(QMouseEvent*)));
278   connect(theView,SIGNAL(contextMenuRequested(QContextMenuEvent*)),
279           this,SIGNAL(contextMenuRequested(QContextMenuEvent *)));
280   connect(theView,SIGNAL(selectionChanged()),
281           theModel,SLOT(onSelectionChanged()));
282
283   connect( this, SIGNAL( transformed( SVTK_ViewWindow* ) ), SLOT( emitViewModified() ) );
284 }
285
286 /*!
287   Destructor
288 */
289 SVTK_ViewWindow::~SVTK_ViewWindow()
290 {
291   myRecorder->Delete();
292   myAxesWidget->Delete();
293 }
294
295
296 /*!
297   \return corresponding view
298 */
299 SVTK_View* SVTK_ViewWindow::getView() 
300
301   return myView; 
302 }
303
304 /*!
305   \return corresponding vtk render window
306 */
307 vtkRenderWindow* SVTK_ViewWindow::getRenderWindow()
308 {
309   return GetInteractor()->getRenderWindow();
310 }
311
312 /*!
313   \return corresponding vtk render window interactor
314 */
315 SVTK_RenderWindowInteractor* SVTK_ViewWindow::GetInteractor() const
316 {
317   return myInteractor;
318 }
319
320 /*!
321   \return corresponding vtk render window interactor
322 */
323 vtkRenderWindowInteractor* SVTK_ViewWindow::getInteractor() const
324 {
325   return myInteractor->GetDevice();
326 }
327
328 /*!
329   \return corresponding vtk renderer
330 */
331 vtkRenderer* SVTK_ViewWindow::getRenderer() const
332 {
333   return GetInteractor()->getRenderer();
334 }
335
336 /*!
337   Redirect the request to SVTK_RenderWindowInteractor::GetRenderer
338 */
339 SVTK_Renderer* SVTK_ViewWindow::GetRenderer() const
340 {
341   return GetInteractor()->GetRenderer();
342 }
343
344 /*!
345   \return corresponding vtk selector
346 */
347 SVTK_Selector* SVTK_ViewWindow::GetSelector() const
348
349   return GetInteractor()->GetSelector(); 
350 }
351
352 /*!
353   Processes transformation "front view"
354 */
355 void SVTK_ViewWindow::onFrontView()
356 {
357   GetRenderer()->OnFrontView();
358   Repaint();
359   emit transformed( this );
360 }
361
362 /*!
363   Processes transformation "back view"
364 */
365 void SVTK_ViewWindow::onBackView()
366 {
367   GetRenderer()->OnBackView();
368   Repaint();
369   emit transformed( this );
370 }
371
372 /*!
373   Processes transformation "top view"
374 */
375 void SVTK_ViewWindow::onTopView()
376 {
377   GetRenderer()->OnTopView();
378   Repaint();
379   emit transformed( this );
380 }
381
382 /*!
383   Processes transformation "bottom view"
384 */
385 void SVTK_ViewWindow::onBottomView()
386 {
387   GetRenderer()->OnBottomView();
388   Repaint();
389   emit transformed( this );
390 }
391
392 /*!
393   Processes transformation "left view"
394 */
395 void SVTK_ViewWindow::onLeftView()
396 {
397   GetRenderer()->OnLeftView();
398   Repaint();
399   emit transformed( this );
400 }
401
402 /*!
403   Processes transformation "right view"
404 */
405 void SVTK_ViewWindow::onRightView()
406 {
407   GetRenderer()->OnRightView();
408   Repaint();
409   emit transformed( this );
410 }
411
412 /*!
413   \brief Rotate view 90 degrees clockwise
414 */
415 void SVTK_ViewWindow::onClockWiseView()
416 {
417   GetRenderer()->onClockWiseView();
418   Repaint();
419   emit transformed( this );
420 }
421
422 /*!
423   \brief Rotate view 90 degrees conterclockwise
424 */
425 void SVTK_ViewWindow::onAntiClockWiseView()
426 {
427   GetRenderer()->onAntiClockWiseView();
428   Repaint();
429   emit transformed( this );
430 }
431
432 /*!
433   Processes transformation "reset view": sets default orientation of viewport camera
434 */
435 void SVTK_ViewWindow::onResetView()
436 {
437   GetRenderer()->OnResetView();
438   Repaint();
439   emit transformed( this );
440 }
441
442 /*!
443   Processes transformation "fit all"
444 */
445 void SVTK_ViewWindow::onFitAll()
446 {
447   GetRenderer()->OnFitAll();
448   Repaint();
449   emit transformed( this );
450 }
451
452 /*!
453   Processes transformation "fit selection"
454 */
455 void SVTK_ViewWindow::onFitSelection()
456 {
457   GetRenderer()->onFitSelection();
458   Repaint();
459   emit transformed( this );
460 }
461
462 /*!
463   Processes transformation "fit given objects"
464 */
465 void SVTK_ViewWindow::onFitIObjects(const SALOME_ListIO& objects)
466 {
467   GetRenderer()->OnFitIObjects(objects);
468   Repaint();
469   emit transformed( this );
470 }
471
472 /*!
473   SLOT: called if selection is changed
474 */
475 void SVTK_ViewWindow::onSelectionChanged()
476 {
477   myView->onSelectionChanged();
478 }
479
480 /*!
481   Change selection mode
482   \param theMode - new selection mode
483 */
484 void SVTK_ViewWindow::SetSelectionMode(Selection_Mode theMode)
485 {
486   GetSelector()->SetSelectionMode(theMode);
487 }
488
489 /*!
490   \return selection mode
491 */
492 Selection_Mode SVTK_ViewWindow::SelectionMode() const
493 {
494   return GetSelector()->SelectionMode();
495 }
496
497 /*!
498   Unhilights all objects in viewer
499 */
500 void SVTK_ViewWindow::unHighlightAll() 
501 {
502   myView->unHighlightAll();
503 }
504
505 /*!
506   Hilights/unhilights object in viewer
507   \param theIO - object to be updated
508   \param theIsHighlight - if it is true, object will be hilighted, otherwise it will be unhilighted
509   \param theIsUpdate - update current viewer
510 */
511 void SVTK_ViewWindow::highlight(const Handle(SALOME_InteractiveObject)& theIO, 
512                                 bool theIsHighlight, 
513                                 bool theIsUpdate ) 
514 {
515   myView->highlight( theIO, theIsHighlight, theIsUpdate );
516 }
517
518 /*!
519   \return true if object is in viewer or in collector
520   \param theIO - object to be checked
521 */
522 bool SVTK_ViewWindow::isInViewer( const Handle(SALOME_InteractiveObject)& theIO ) 
523 {
524   return myView->isInViewer( theIO );
525 }
526
527 /*!
528   \return true if object is displayed in viewer
529   \param theIO - object to be checked
530 */
531 bool SVTK_ViewWindow::isVisible( const Handle(SALOME_InteractiveObject)& theIO ) 
532 {
533   return myView->isVisible( theIO );
534 }
535
536 /*!
537   Display object
538   \param theEntry - entry that corresponds to intractive objects
539 */
540 Handle(SALOME_InteractiveObject) SVTK_ViewWindow::FindIObject(const char* theEntry) 
541 {
542   return myView->FindIObject(theEntry);
543 }
544
545 /*!
546   Display object
547   \param theIO - object
548   \param theImmediatly - update viewer
549 */
550 void SVTK_ViewWindow::Display(const Handle(SALOME_InteractiveObject)& theIO,
551                               bool theImmediatly) 
552 {
553   myView->Display(theIO,theImmediatly);
554 }
555
556 /*!
557   Erase object
558   \param theIO - object
559   \param theImmediatly - update viewer
560 */
561 void SVTK_ViewWindow::Erase(const Handle(SALOME_InteractiveObject)& theIO,
562                             bool theImmediatly) 
563 {
564   myView->Erase(theIO,theImmediatly);
565 }
566
567 /*!
568   Display only passed object
569   \param theIO - object
570 */
571 void SVTK_ViewWindow::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIO) 
572 {
573   myView->DisplayOnly(theIO);
574 }
575
576 /*!
577   Display all objects in view
578 */
579 void SVTK_ViewWindow::DisplayAll() 
580 {
581   myView->DisplayAll();
582 }
583
584 /*!
585   Erase all objects in view
586 */
587 void SVTK_ViewWindow::EraseAll() 
588 {
589   myView->EraseAll();
590 }
591
592 /*!
593   Sets background color [obsolete]
594   \param color - new background color
595 */
596 void SVTK_ViewWindow::setBackgroundColor( const QColor& c )
597 {
598   Qtx::BackgroundData bg = background();
599   bg.setColor( c );
600   setBackground( bg );
601 }
602
603 /*!
604   \return background color of viewer [obsolete]
605 */
606 QColor SVTK_ViewWindow::backgroundColor() const
607 {
608   return background().color();
609 }
610
611 /*!
612   Sets background data
613   \param bgData - new background data
614 */
615 void SVTK_ViewWindow::setBackground( const Qtx::BackgroundData& bgData )
616 {
617   bool ok = false;
618
619   if ( bgData.isValid() ) {
620     switch ( bgData.mode() ) {
621     case Qtx::ColorBackground:
622       {
623         QColor c = bgData.color();
624         if ( c.isValid() ) {
625           // show solid-colored background
626           getRenderer()->SetTexturedBackground( false );  // cancel texture mode
627           getRenderer()->SetGradientBackground( false );  // cancel gradient mode
628           getRenderer()->SetBackground( c.red()/255.0,
629                                         c.green()/255.0,
630                                         c.blue()/255.0 ); // set background color
631           ok = true;
632         }
633         break;
634       }
635     case Qtx::SimpleGradientBackground:
636       {
637         QColor c1, c2;
638         int type = bgData.gradient( c1, c2 );
639         if ( c1.isValid() )
640         {
641           if ( !c2.isValid() )
642             c2 = c1;
643
644           // show two-color gradient background
645           getRenderer()->SetTexturedBackground( false );    // cancel texture mode
646           getRenderer()->SetGradientBackground( true );     // switch to gradient mode
647
648           VTKViewer_OpenGLRenderer* aRenderer =
649             VTKViewer_OpenGLRenderer::SafeDownCast( getRenderer() );
650           if( aRenderer )
651           {
652             aRenderer->SetGradientType( type );
653             aRenderer->SetBackground( c1.redF(), c1.greenF(), c1.blueF() );
654             aRenderer->SetBackground2( c2.redF(), c2.greenF(), c2.blueF() );
655             ok = true;
656           }
657         }
658         break;
659       }
660     case Qtx::CustomGradientBackground:
661       {
662         // NOT IMPLEMENTED YET
663         getRenderer()->SetTexturedBackground( false );  // cancel texture mode
664         getRenderer()->SetGradientBackground( false );  // cancel gradient mode
665         // .........
666         break;
667       }
668     default:
669       break;
670     }
671     if ( bgData.isTextureShown() ) {
672       QString fileName;
673       int textureMode = bgData.texture( fileName );
674       QFileInfo fi( fileName );
675       if ( !fileName.isEmpty() && fi.exists() ) {
676         // read texture from file
677         QString extension = fi.suffix().toLower();
678         vtkImageReader2* aReader = 0;
679         if ( extension == "jpg" || extension == "jpeg" )
680           aReader = vtkJPEGReader::New();
681         else if ( extension == "bmp" )
682           aReader = vtkBMPReader::New();
683         else if ( extension == "tif" || extension == "tiff" )
684           aReader = vtkTIFFReader::New();
685         else if ( extension == "png" )
686           aReader = vtkPNGReader::New();
687         else if ( extension == "mhd" || extension == "mha" )
688           aReader = vtkMetaImageReader::New();
689         if ( aReader ) {
690           // create texture
691           aReader->SetFileName( fi.absoluteFilePath().toUtf8().constData() );
692           aReader->Update();
693           VTKViewer_Texture* aTexture = VTKViewer_Texture::New();
694           vtkImageMapToColors* aMap = 0;
695           vtkAlgorithmOutput* anOutput;
696           /*
697           // special processing for BMP reader
698           vtkBMPReader* aBMPReader = (vtkBMPReader*)aReader;
699           if ( aBMPReader ) {
700           // Special processing for BMP file
701           aBMPReader->SetAllow8BitBMP(1);
702
703           aMap = vtkImageMapToColors::New();
704           aMap->SetInputConnection( aBMPReader->GetOutputPort() );
705           aMap->SetLookupTable( (vtkScalarsToColors*)aBMPReader->GetLookupTable() );
706           aMap->SetOutputFormatToRGB();
707
708           anOutput = aMap->GetOutputPort();
709           }
710           else {
711           }
712           */
713           anOutput = aReader->GetOutputPort( 0 );
714           aTexture->SetInputConnection( anOutput );
715           // set texture mode
716           // VSR: Currently, VTK only supports Stretch mode, so below code will give
717           // the same results for all modes
718           switch ( textureMode ) {
719           case Qtx::TileTexture:
720             aTexture->SetPosition((int)VTKViewer_Texture::Tiled);
721             break;
722           case Qtx::StretchTexture:
723             aTexture->SetPosition((int)VTKViewer_Texture::Stretched);
724             break;
725           case Qtx::CenterTexture:
726             aTexture->SetPosition((int)VTKViewer_Texture::Centered);
727           default:
728             break;
729           }
730           // show textured background
731           getRenderer()->SetTexturedBackground( true );
732           getRenderer()->SetBackgroundTexture( aTexture );
733
734           // clean-up resources
735           if ( aMap )
736             aMap->Delete();
737           aReader->Delete();
738           aTexture->Delete();
739           ok = true;
740         }
741       }
742     }
743   }
744   if ( ok )
745     myBackground = bgData;
746 }
747
748 /*!
749   \return background data of viewer
750 */
751 Qtx::BackgroundData SVTK_ViewWindow::background() const
752 {
753   return myBackground;
754 }
755
756
757 /*!
758   Redirect the request to SVTK_RenderWindowInteractor::GetInteractorStyle
759 */
760 vtkInteractorStyle* SVTK_ViewWindow::GetInteractorStyle() const
761 {
762   return GetInteractor()->GetInteractorStyle();
763 }
764
765 /*!
766   Redirect the request to SVTK_RenderWindowInteractor::PushInteractorStyle
767 */
768 void SVTK_ViewWindow::PushInteractorStyle(vtkInteractorStyle* theStyle)
769 {
770   GetInteractor()->PushInteractorStyle(theStyle);
771 }
772
773 /*!
774   Redirect the request to SVTK_RenderWindowInteractor::PopInteractorStyle
775 */
776 void SVTK_ViewWindow::PopInteractorStyle()
777 {
778   GetInteractor()->PopInteractorStyle();
779 }
780
781 /*!
782   Updates current viewer
783 */
784 void SVTK_ViewWindow::Repaint(bool theUpdateTrihedron)
785 {
786   if(theUpdateTrihedron) 
787     GetRenderer()->OnAdjustTrihedron();
788
789   GetInteractor()->update();
790
791   SVTK_InteractorStyle* aStyle = (SVTK_InteractorStyle*)getInteractor()->GetInteractorStyle();
792   if ( aStyle )
793     aStyle->OnTimer();
794 }
795
796 /*!
797   Redirect the request to #SVTK_Renderer::GetScale
798 */
799 void SVTK_ViewWindow::GetScale( double theScale[3] ) 
800 {
801   GetRenderer()->GetScale( theScale );
802 }
803
804 /*!
805   Redirect the request to #SVTK_Renderer::SetScale
806 */
807 void SVTK_ViewWindow::SetScale( double theScale[3] ) 
808 {
809   GetRenderer()->SetScale( theScale );
810   Repaint();
811   emit transformed( this );
812 }
813
814 /*!
815   Redirect the request to #SVTK_Renderer::IsTrihedronDisplayed
816 */
817 bool SVTK_ViewWindow::isTrihedronDisplayed()
818 {
819   return GetRenderer()->IsTrihedronDisplayed();
820 }
821
822 /*!
823   Redirect the request to #SVTK_Renderer::IsCubeAxesDisplayed
824 */
825 bool SVTK_ViewWindow::isCubeAxesDisplayed()
826 {
827   return GetRenderer()->IsCubeAxesDisplayed();
828 }
829
830 /*!
831   Redirect the request to #SVTK_Renderer::OnViewTrihedron
832 */
833 void SVTK_ViewWindow::onViewTrihedron(bool show)
834 {
835   GetRenderer()->SetTrihedronVisibility(show);
836   Repaint();
837 }
838
839 /*!
840   Redirect the request to #SVTK_Renderer::OnViewCubeAxes
841 */
842 void SVTK_ViewWindow::onViewCubeAxes()
843 {
844   GetRenderer()->OnViewCubeAxes();
845   Repaint();
846 }
847
848 /*!
849   Redirect the request to #SVTK_Renderer::GetTrihedron
850 */
851 VTKViewer_Trihedron* SVTK_ViewWindow::GetTrihedron()
852 {
853   return GetRenderer()->GetTrihedron();
854 }
855
856 /*!
857   Redirect the request to #SVTK_Renderer::GetCubeAxes
858 */
859 SVTK_CubeAxesActor2D* SVTK_ViewWindow::GetCubeAxes()
860 {
861   return GetRenderer()->GetCubeAxes();
862 }
863
864 /*!
865   \return trihedron size
866 */
867 double SVTK_ViewWindow::GetTrihedronSize() const
868 {
869   return GetRenderer()->GetTrihedronSize();
870 }
871
872 /*!
873   Sets projection mode
874   \param theMode - projection mode ( 0 - orthogonal, 1 - perspective, 2 - stereo )
875 */
876 void SVTK_ViewWindow::SetProjectionMode(const int theMode)
877 {
878   QtxAction* aParallelAction = dynamic_cast<QtxAction*>( toolMgr()->action( ParallelModeId ) );
879   QtxAction* aProjectionAction = dynamic_cast<QtxAction*>( toolMgr()->action( ProjectionModeId ) );
880   QtxAction* aStereoAction = dynamic_cast<QtxAction*>( toolMgr()->action( StereoModeId ) );
881
882   switch ( theMode ) {
883     case Parallel:
884       onProjectionMode( aParallelAction );
885       break;
886     case Projection:
887       onProjectionMode( aProjectionAction );
888       break;
889     case Stereo:
890       onStereoMode( true );
891       break;
892   }
893
894   // update action state if method is called outside
895   SVTK_Viewer* aViewer = dynamic_cast<SVTK_Viewer*>(myModel);
896   QtxAction* aSwitchZoomingStyle = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
897   if ( theMode == Parallel && !aParallelAction->isChecked() ) {
898     aParallelAction->setChecked( true );
899     aSwitchZoomingStyle->setEnabled(true);
900     aStereoAction->setChecked( false );
901   }
902   if ( theMode == Projection && !aProjectionAction->isChecked() ) {
903     aProjectionAction->setChecked( true );
904     aSwitchZoomingStyle->setEnabled(false);
905   }
906   if ( theMode == Stereo ) {
907     aStereoAction->setChecked( true );
908     if ( aParallelAction->isEnabled() ) {
909       aParallelAction->setEnabled( false );
910       aParallelAction->setChecked( false );
911       aStereoAction->setChecked( false );
912     }
913     else {
914       aParallelAction->setEnabled( true );
915       aStereoAction->setChecked( false );
916       aParallelAction->setChecked( aViewer->projectionMode() == Parallel );
917     }
918     if ( aProjectionAction->isEnabled() ) {
919       aProjectionAction->setEnabled( false );
920       aProjectionAction->setChecked( true );
921       if ( getRenderWindow()->GetStereoCapableWindow() == 1 && !isOpenGlStereoSupport() &&
922            strcmp( "CrystalEyes", getRenderWindow()->GetStereoTypeAsString() ) == 0 &&
923            toolMgr()->action( StereoModeId )->isChecked() ) {
924         SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ),  tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
925       }
926     }
927     else {
928       aProjectionAction->setEnabled( true );
929       aStereoAction->setChecked( false );
930       aProjectionAction->setChecked( aViewer->projectionMode() == Projection );
931       onProjectionMode();
932     }
933   }
934   else {
935     if ( !aParallelAction->isEnabled() )
936       aParallelAction->setEnabled( true );
937     if ( !aProjectionAction->isEnabled() )
938       aProjectionAction->setEnabled( true );
939   }
940 }
941
942 /*!
943   Sets stereo type
944   \param theType - stereo type
945 */
946 void SVTK_ViewWindow::SetStereoType(const int theType)
947 {
948   vtkRenderWindow* aWindow = getRenderWindow();
949   switch (theType ) {
950   case CrystalEyes:
951     aWindow->SetStereoTypeToCrystalEyes();
952     break;
953   case RedBlue:
954     aWindow->SetStereoTypeToRedBlue();
955     break;
956   case Interlaced:
957     aWindow->SetStereoTypeToInterlaced();
958     break;
959   case Left:
960     aWindow->SetStereoTypeToLeft();
961     break;
962   case Right:
963     aWindow->SetStereoTypeToRight();
964     break;
965   case Dresden:
966     aWindow->SetStereoTypeToDresden();
967     break;
968   case Anaglyph:
969     aWindow->SetStereoTypeToAnaglyph();
970     break;
971   case Checkerboard:
972     aWindow->SetStereoTypeToCheckerboard();
973     break;
974   case SplitViewPortHorizontal:
975     aWindow->SetStereoTypeToSplitViewportHorizontal();
976     break;
977   }
978 }
979
980 /*!
981   Sets anaglyph filter
982   \param theFilter - anaglyph filter
983 */
984 void SVTK_ViewWindow::SetAnaglyphFilter(const int theFilter)
985 {
986   vtkRenderWindow* aWindow = getRenderWindow();
987   switch (theFilter ) {
988   case RedCyan:
989     aWindow->SetAnaglyphColorMask(4,3);
990     break;
991   case YellowBlue:
992     aWindow->SetAnaglyphColorMask(6,1);
993     break;
994   case GreenMagenta:
995     aWindow->SetAnaglyphColorMask(2,5);
996     break;
997   }
998 }
999
1000 /*!
1001   Set support quad-buffered stereo
1002   \param theEnable - enable/disable support quad-buffered stereo
1003 */
1004 void SVTK_ViewWindow::SetQuadBufferSupport(const bool theEnable)
1005 {
1006   vtkRenderWindow* aWindow = getRenderWindow();
1007   aWindow->SetStereoCapableWindow((int)theEnable);
1008 }
1009
1010 /*!
1011   \return OpenGl stereo support
1012 */
1013 bool SVTK_ViewWindow::isOpenGlStereoSupport() const
1014 {
1015   GLboolean support[1];
1016   glGetBooleanv (GL_STEREO, support);
1017   if ( support[0] )
1018     return true;
1019   return false;
1020 }
1021
1022 /*!
1023   Set the gravity center as a focal point
1024 */
1025 void SVTK_ViewWindow::activateSetFocalPointGravity()
1026 {
1027   myEventDispatcher->InvokeEvent(SVTK::SetFocalPointGravity, 0);
1028 }
1029
1030 /*!
1031   Set the selected point as a focal point
1032 */
1033 void SVTK_ViewWindow::activateSetFocalPointSelected()
1034 {
1035   myEventDispatcher->InvokeEvent(SVTK::SetFocalPointSelected, 0);
1036 }
1037
1038 /*!
1039   Set the point selected by user as a focal point
1040 */
1041 void SVTK_ViewWindow::activateStartFocalPointSelection()
1042 {
1043   myEventDispatcher->InvokeEvent(SVTK::StartFocalPointSelection,0);
1044 }
1045
1046 void SVTK_ViewWindow::activateProjectionMode(int theMode)
1047 {
1048   QtxAction* aParallelAction = dynamic_cast<QtxAction*>( toolMgr()->action( ParallelModeId ) );
1049   QtxAction* aProjectionAction = dynamic_cast<QtxAction*>( toolMgr()->action( ProjectionModeId ) );
1050   if (theMode)
1051     aParallelAction->setChecked( true );
1052   else
1053     aProjectionAction->setChecked( true );
1054
1055   if ( !aParallelAction->isEnabled() )
1056     aParallelAction->setEnabled( true );
1057   if ( !aProjectionAction->isEnabled() )
1058     aProjectionAction->setEnabled( true );
1059 }
1060
1061 /*!
1062   Sets actual interaction style
1063   \param theStyle - type of interaction style ( 0 - standard, 1 - keyboard free )
1064 */
1065 void SVTK_ViewWindow::SetInteractionStyle(const int theStyle)
1066 {
1067   onSwitchInteractionStyle( theStyle==1 );
1068 }
1069
1070 /*!
1071   Sets actual zooming style
1072   \param theStyle - type of zooming style ( 0 - standard, 1 - advanced (at cursor) )
1073 */
1074 void SVTK_ViewWindow::SetZoomingStyle(const int theStyle)
1075 {
1076   onSwitchZoomingStyle( theStyle==1 );
1077 }
1078
1079 /*!
1080   Set preselection mode.
1081   \param theMode the mode to set (standard, dynamic or disabled)
1082 */
1083 void SVTK_ViewWindow::SetPreSelectionMode( Preselection_Mode theMode )
1084 {
1085   onSwitchPreSelectionMode( theMode );
1086 }
1087
1088 /*!
1089   Enables/disables selection.
1090   \param theEnable if true - selection will be enabled
1091 */
1092 void SVTK_ViewWindow::SetSelectionEnabled( bool theEnable )
1093 {
1094   GetSelector()->SetSelectionEnabled( theEnable );
1095   QtxAction* a = getAction( EnableSelectionId );
1096   if ( a->isChecked() !=  theEnable)
1097     a->setChecked( theEnable );
1098   QtxActionGroup* aPreselectionGroup = 
1099     dynamic_cast<QtxActionGroup*>( getAction( PreselectionId ) );
1100   if ( aPreselectionGroup )
1101     aPreselectionGroup->setEnabled( theEnable );
1102
1103   // notify actors
1104   vtkActorCollection *actors = getRenderer()->GetActors();
1105   for (int i = 0; i < actors->GetNumberOfItems(); ++i )
1106     if (VTKViewer_Actor *actor = dynamic_cast<VTKViewer_Actor*>(actors->GetItemAsObject(i)))
1107     {
1108       actor->EnableSelection( theEnable );
1109     }
1110 }
1111
1112 /*!
1113   Switches "keyboard free" interaction style on/off
1114 */
1115 void SVTK_ViewWindow::onSwitchInteractionStyle(bool theOn)
1116 {
1117   if (theOn) {
1118     // check if style is already set
1119     if ( GetInteractorStyle() != myKeyFreeInteractorStyle.GetPointer() )
1120     {
1121       // keep the same style extensions
1122       SVTK_InteractorStyle* aStyle = (SVTK_InteractorStyle*)GetInteractorStyle();
1123       if ( aStyle ) {
1124         myKeyFreeInteractorStyle->SetControllerIncrement(aStyle->ControllerIncrement());
1125         myKeyFreeInteractorStyle->SetControllerOnKeyDown(aStyle->ControllerOnKeyDown());
1126       }
1127
1128       PushInteractorStyle(myKeyFreeInteractorStyle.GetPointer());
1129     }
1130   }
1131   else {
1132     // pop only key free  style
1133     if ( GetInteractorStyle() == myKeyFreeInteractorStyle.GetPointer() )
1134       PopInteractorStyle();
1135   }
1136
1137   // update action state if method is called outside
1138   QtxAction* a = getAction( SwitchInteractionStyleId );
1139   if ( a->isChecked() != theOn ) a->setChecked( theOn );
1140 }
1141
1142 /*!
1143   Toogles advanced zooming style (relatively to the cursor position) on/off
1144 */
1145 void SVTK_ViewWindow::onSwitchZoomingStyle( bool theOn )
1146 {
1147   if( myDefaultInteractorStyle.GetPointer() )
1148     myDefaultInteractorStyle->SetAdvancedZoomingEnabled( theOn );
1149   if( myKeyFreeInteractorStyle.GetPointer() )
1150     myKeyFreeInteractorStyle->SetAdvancedZoomingEnabled( theOn );
1151
1152   // update action state if method is called outside
1153   QtxAction* a = getAction( SwitchZoomingStyleId );
1154   if ( a->isChecked() != theOn )
1155     a->setChecked( theOn );
1156 }
1157
1158 /*!
1159   Switch preselection mode.
1160   \param theMode the preselection mode
1161 */
1162 void SVTK_ViewWindow::onSwitchPreSelectionMode( int theMode )
1163 {
1164   GetSelector()->SetDynamicPreSelection( theMode == Dynamic_Preselection );
1165   GetSelector()->SetPreSelectionEnabled( theMode != Preselection_Disabled );
1166
1167   // update action state if method is called outside
1168   QtxAction* a = getAction( StandardPreselectionId + theMode );
1169   if ( a && !a->isChecked() )
1170     a->setChecked( true );
1171 }
1172
1173 /*!
1174   Enables/disables selection.
1175   \param theOn if true - selection will be enabled
1176 */
1177 void SVTK_ViewWindow::onEnableSelection( bool on )
1178 {
1179   SVTK_Viewer* aViewer = dynamic_cast<SVTK_Viewer*>(myModel);
1180   if(aViewer)
1181     aViewer->enableSelection(on);  
1182 }
1183
1184 /*!
1185   Sets incremental speed
1186   \param theValue - new incremental speed
1187   \param theMode - modification mode
1188 */
1189 void SVTK_ViewWindow::SetIncrementalSpeed(const int theValue, const int theMode)
1190 {
1191   if ( (SVTK_InteractorStyle*)GetInteractorStyle() )
1192     ((SVTK_InteractorStyle*)GetInteractorStyle())->SetIncrementSpeed(theValue, theMode);
1193 }
1194
1195 /*!
1196   Sets spacemouse buttons for the functions
1197   \param theBtn1 - spacemouse button for the "decrease speed increment"
1198   \param theBtn2 - spacemouse button for the "increase speed increment"
1199   \param theBtn3 - spacemouse button for the "dominant combined switch"
1200 */
1201 void SVTK_ViewWindow::SetSpacemouseButtons(const int theBtn1, 
1202                                            const int theBtn2,
1203                                            const int theBtn3)
1204 {
1205   int val = theBtn1;
1206   myEventDispatcher->InvokeEvent(SVTK::SetSMDecreaseSpeedEvent, &val);
1207   val = theBtn2;
1208   myEventDispatcher->InvokeEvent(SVTK::SetSMIncreaseSpeedEvent, &val);
1209   val = theBtn3;
1210   myEventDispatcher->InvokeEvent(SVTK::SetSMDominantCombinedSwitchEvent, &val);
1211 }
1212
1213 /*!
1214   Sets trihedron size
1215   \param theSize - new trihedron size
1216   \param theRelative - trihedron relativeness
1217 */
1218 void SVTK_ViewWindow::SetTrihedronSize(const double theSize, const bool theRelative)
1219 {
1220   GetRenderer()->SetTrihedronSize(theSize, theRelative);
1221   Repaint();
1222 }
1223
1224 /*! If parameter theIsForcedUpdate is true, recalculate parameters for
1225  *  trihedron and cube axes, even if trihedron and cube axes is invisible.
1226  */
1227 void SVTK_ViewWindow::AdjustTrihedrons(const bool theIsForcedUpdate)
1228 {
1229   GetRenderer()->AdjustActors();
1230   Repaint();
1231 }
1232
1233 /*!
1234   Redirect the request to #SVTK_Renderer::OnAdjustTrihedron
1235 */
1236 void SVTK_ViewWindow::onAdjustTrihedron()
1237 {   
1238   GetRenderer()->OnAdjustTrihedron();
1239 }
1240
1241 /*!
1242   Redirect the request to #SVTK_Renderer::OnAdjustCubeAxes
1243 */
1244 void SVTK_ViewWindow::onAdjustCubeAxes()
1245 {   
1246   GetRenderer()->OnAdjustCubeAxes();
1247 }
1248
1249 void SVTK_ViewWindow::synchronize(SVTK_ViewWindow* otherViewWindow )
1250 {
1251   if ( otherViewWindow ) {
1252     bool blocked = blockSignals( true );
1253     doSetVisualParameters( otherViewWindow->getVisualParameters(), true );
1254     blockSignals( blocked );
1255   }
1256 }
1257
1258 /*!
1259   Emits key pressed
1260 */
1261 void SVTK_ViewWindow::onKeyPressed(QKeyEvent* event)
1262 {
1263   emit keyPressed( this, event );
1264 }
1265
1266 /*!
1267   Emits key released
1268 */
1269 void SVTK_ViewWindow::onKeyReleased(QKeyEvent* event)
1270 {
1271   emit keyReleased( this, event );
1272 }
1273
1274 /*!
1275   Emits mouse pressed
1276 */
1277 void SVTK_ViewWindow::onMousePressed(QMouseEvent* event)
1278 {
1279   emit mousePressed(this, event);
1280 }
1281
1282 /*!
1283   Emits mouse released
1284 */
1285 void SVTK_ViewWindow::onMouseReleased(QMouseEvent* event)
1286 {
1287   emit mouseReleased( this, event );
1288 }
1289
1290 /*!
1291   Emits mouse moving
1292 */
1293 void SVTK_ViewWindow::onMouseMoving(QMouseEvent* event)
1294 {
1295   emit mouseMoving( this, event );
1296 }
1297
1298 /*!
1299   Emits mouse double clicked
1300 */
1301 void SVTK_ViewWindow::onMouseDoubleClicked( QMouseEvent* event )
1302 {
1303   emit mouseDoubleClicked( this, event );
1304 }
1305
1306 /*!
1307   Redirect the request to #SVTK_Renderer::AddActor
1308 */
1309 void SVTK_ViewWindow::AddActor( VTKViewer_Actor* theActor, 
1310                                 bool theUpdate,
1311                                 bool theIsAdjustActors )
1312 {
1313   GetRenderer()->AddActor(theActor, theIsAdjustActors);
1314   if(theUpdate) 
1315     Repaint();
1316   emit actorAdded(theActor);
1317 }
1318
1319 /*!
1320   Redirect the request to #SVTK_Renderer::RemoveActor
1321 */
1322 void SVTK_ViewWindow::RemoveActor( VTKViewer_Actor* theActor, 
1323                                    bool theUpdate,
1324                                    bool theIsAdjustActors )
1325 {
1326   GetRenderer()->RemoveActor(theActor, theIsAdjustActors);
1327   if ( myDefaultInteractorStyle )
1328     myDefaultInteractorStyle->FreeActors();
1329   if ( myKeyFreeInteractorStyle )
1330     myKeyFreeInteractorStyle->FreeActors();
1331   if(theUpdate) 
1332     Repaint();
1333   emit actorRemoved(theActor);
1334 }
1335
1336 QImage SVTK_ViewWindow::dumpViewContent()
1337 {
1338   vtkRenderWindow* aWindow = getRenderWindow();
1339   int* aSize = aWindow->GetSize();
1340   int aWidth = aSize[0];
1341   int aHeight = aSize[1];
1342   
1343 #ifndef DISABLE_GLVIEWER
1344   OpenGLUtils_FrameBuffer aFrameBuffer;
1345   if( aFrameBuffer.init( aWidth, aHeight ) )
1346   {
1347     glPushAttrib( GL_VIEWPORT_BIT );
1348     glViewport( 0, 0, aWidth, aHeight );
1349     aFrameBuffer.bind();
1350
1351     // draw scene
1352     aWindow->Render();
1353
1354     aFrameBuffer.unbind();
1355     glPopAttrib();
1356
1357     QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
1358
1359     aFrameBuffer.bind();
1360     glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
1361     aFrameBuffer.unbind();
1362
1363     anImage = anImage.rgbSwapped();
1364     anImage = anImage.mirrored();
1365     return anImage;
1366   }
1367 #endif
1368
1369   // if frame buffers are unsupported, use old functionality
1370   unsigned char *aData = 
1371     aWindow->GetRGBACharPixelData( 0, 0, aWidth-1, aHeight-1, 0 );
1372   
1373   QImage anImage( aData, aWidth, aHeight, QImage::Format_ARGB32 );
1374
1375   anImage = anImage.rgbSwapped();
1376   anImage = anImage.mirrored();
1377   return anImage;
1378 }
1379
1380 /*!
1381   \return QImage, containing all scene rendering in window
1382 */
1383 QImage SVTK_ViewWindow::dumpView()
1384 {
1385   if( myDumpImage.isNull() )
1386     return dumpViewContent();
1387   
1388   RefreshDumpImage();
1389   return myDumpImage;
1390 }
1391
1392 QString SVTK_ViewWindow::filter() const
1393 {
1394   return tr( "SVTK_IMAGE_FILES" );
1395 }
1396
1397 bool SVTK_ViewWindow::dumpViewToFormat( const QImage& img, const QString& fileName, const QString& format )
1398 {
1399   if ( format != "PS" && format != "EPS" && format != "PDF" )
1400     return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
1401
1402   SVTK_PsOptionsDlg* optionsDlg = new SVTK_PsOptionsDlg(this);
1403   if ( optionsDlg->exec() == QDialog::Accepted ) {
1404     SUIT_OverrideCursor wc;
1405
1406     vtkGL2PSExporter *anExporter = vtkGL2PSExporter::New();
1407     anExporter->SetRenderWindow(getRenderWindow());
1408
1409     // Set options
1410     anExporter->SetLineWidthFactor(optionsDlg->getLineFactor());
1411     anExporter->SetPointSizeFactor(optionsDlg->getPointFactor());
1412     anExporter->SetSort((vtkGL2PSExporter::SortScheme)optionsDlg->getSortType());
1413     anExporter->SetWrite3DPropsAsRasterImage((int)optionsDlg->isRasterize3D());
1414     anExporter->SetPS3Shading((int)optionsDlg->isPs3Shading());
1415     
1416     if ( format == "PS" ) {
1417       anExporter->SetFileFormatToPS();
1418       anExporter->CompressOff();
1419     }
1420     
1421     if ( format == "EPS" ) {
1422       anExporter->SetFileFormatToEPS();
1423       anExporter->CompressOff();
1424     }
1425
1426     if ( format == "PDF" ) {
1427       anExporter->SetFileFormatToPDF();
1428     }
1429     
1430     QString aFilePrefix(fileName);
1431     QString anExtension(SUIT_Tools::extension(fileName));
1432     aFilePrefix.truncate(aFilePrefix.length() - 1 - anExtension.length());
1433     anExporter->SetFilePrefix(aFilePrefix.toUtf8().data());
1434     anExporter->Write();
1435     anExporter->Delete();
1436   }
1437   delete optionsDlg;
1438   return true;  
1439 }
1440
1441 /*!
1442   \refresh QImage, containing all scene rendering in window
1443 */
1444 void SVTK_ViewWindow::RefreshDumpImage()
1445 {
1446   myDumpImage = dumpViewContent();
1447 }
1448
1449 /*!
1450   Redirect the request to #SVTK_Renderer::SetSelectionProp
1451 */
1452 void SVTK_ViewWindow::SetSelectionProp(const double& theRed, 
1453                                        const double& theGreen, 
1454                                        const double& theBlue, 
1455                                        const int& theWidth) 
1456 {
1457   myView->SetSelectionProp(theRed,theGreen,theBlue,theWidth);
1458 }
1459
1460 /*!
1461   Redirect the request to #SVTK_Renderer::SetSelectionProp
1462 */
1463 void SVTK_ViewWindow::SetPreselectionProp(const double& theRed, 
1464                                           const double& theGreen, 
1465                                           const double& theBlue, 
1466                                           const int& theWidth) 
1467 {
1468   myView->SetPreselectionProp(theRed,theGreen,theBlue,theWidth);
1469 }
1470
1471 /*!
1472   Redirect the request to #SVTK_Renderer::SetSelectionTolerance
1473 */
1474 void SVTK_ViewWindow::SetSelectionTolerance(const double& theTolNodes, 
1475                                             const double& theTolItems,
1476                                             const double& theTolObjects)
1477 {
1478   myView->SetSelectionTolerance(theTolNodes, theTolItems, theTolObjects);
1479 }
1480
1481 /*!
1482   Get visibility status of the static trihedron
1483 */
1484 bool SVTK_ViewWindow::IsStaticTrihedronVisible() const
1485 {
1486   return (bool)myAxesWidget->GetEnabled();
1487 }
1488
1489 /*!
1490   Set visibility status of the static trihedron
1491 */
1492 void SVTK_ViewWindow::SetStaticTrihedronVisible( const bool theIsVisible )
1493 {
1494   myAxesWidget->SetEnabled( (int)theIsVisible );
1495 }
1496
1497 /*!
1498   Performs action
1499   \param accelAction - action
1500 */
1501 bool SVTK_ViewWindow::action( const int accelAction  )
1502 {
1503   if ( accelAction == SUIT_Accel::ZoomFit )
1504     onFitAll();
1505   else {
1506     int anEvent = SVTK::convertAction( accelAction );
1507     GetInteractor()->InvokeEvent(anEvent, 0);
1508   }
1509   return true;
1510 }
1511
1512 /*!
1513   \return action by it's id
1514 */
1515 QtxAction* SVTK_ViewWindow::getAction( int id ) const
1516 {
1517   return dynamic_cast<QtxAction*>( toolMgr()->action( id ) );
1518 }
1519
1520
1521 // old visual parameters had 13 values.  New format added additional 
1522 // 76 values for graduated axes, so both numbers are processed.
1523 const int nNormalParams = 13;   // number of view windows parameters excluding graduated axes params
1524 const int nGradAxisParams = 25; // number of parameters of ONE graduated axis (X, Y, or Z)
1525 const int nTrihedronParams = 3; // number of parameters for Trihedron
1526 const int nAllParams = nNormalParams + 3*nGradAxisParams + nTrihedronParams + 1; // number of all visual parameters
1527
1528 /*! The method returns visual parameters of a graduated axis actor (x,y,z axis of graduated axes)
1529  */
1530 void getGradAxisVisualParams( QXmlStreamWriter& writer, vtkAxisActor2D* actor, QString theAxis )
1531 {
1532   //QString params;
1533   if ( !actor )
1534     return ;//params;
1535
1536   // Name
1537   bool isVisible = actor->GetTitleVisibility();
1538   QString title ( actor->GetTitle() );
1539   double color[ 3 ];
1540   int font = VTK_ARIAL;
1541   int bold = 0;
1542   int italic = 0;
1543   int shadow = 0;
1544
1545   vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1546   if ( txtProp )
1547   {
1548     txtProp->GetColor( color );
1549     font = txtProp->GetFontFamily();
1550     bold = txtProp->GetBold();
1551     italic = txtProp->GetItalic();
1552     shadow = txtProp->GetShadow();
1553   }
1554   writer.writeStartElement("GraduatedAxis");
1555   writer.writeAttribute("Axis", theAxis);
1556
1557   writer.writeStartElement("Title");
1558   writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1559   writer.writeAttribute("Text", title);
1560   writer.writeAttribute("Font", QString("%1").arg(font));
1561   writer.writeAttribute("Bold", QString("%1").arg(bold));
1562   writer.writeAttribute("Italic", QString("%1").arg(italic));
1563   writer.writeAttribute("Shadow", QString("%1").arg(shadow));
1564
1565   writer.writeStartElement("Color");
1566   writer.writeAttribute("R", QString("%1").arg(color[0]));
1567   writer.writeAttribute("G", QString("%1").arg(color[1]));
1568   writer.writeAttribute("B", QString("%1").arg(color[2]));
1569   writer.writeEndElement();
1570   writer.writeEndElement();
1571
1572   //params.sprintf( "* Graduated Axis: * Name *%u*%s*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible, 
1573   //              title.toLatin1().data(), color[0], color[1], color[2], font, bold, italic, shadow );
1574
1575   // Labels
1576   isVisible = actor->GetLabelVisibility();
1577   int labels = actor->GetNumberOfLabels();
1578   int offset = actor->GetTickOffset();
1579   font = VTK_ARIAL;
1580   bold = false;
1581   italic = false;
1582   shadow = false;
1583
1584   txtProp = actor->GetLabelTextProperty();
1585   if ( txtProp )
1586   {
1587     txtProp->GetColor( color );
1588     font = txtProp->GetFontFamily();
1589     bold = txtProp->GetBold();
1590     italic = txtProp->GetItalic();
1591     shadow = txtProp->GetShadow();
1592   }
1593
1594   writer.writeStartElement("Labels");
1595   writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1596   writer.writeAttribute("Number", QString("%1").arg(labels));
1597   writer.writeAttribute("Offset", QString("%1").arg(offset));
1598   writer.writeAttribute("Font", QString("%1").arg(font));
1599   writer.writeAttribute("Bold", QString("%1").arg(bold));
1600   writer.writeAttribute("Italic", QString("%1").arg(italic));
1601   writer.writeAttribute("Shadow", QString("%1").arg(shadow));
1602
1603   writer.writeStartElement("Color");
1604   writer.writeAttribute("R", QString("%1").arg(color[0]));
1605   writer.writeAttribute("G", QString("%1").arg(color[1]));
1606   writer.writeAttribute("B", QString("%1").arg(color[2]));
1607   writer.writeEndElement();
1608   writer.writeEndElement();
1609   //  params += QString().sprintf( "* Labels *%u*%u*%u*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible, labels, offset,  
1610   //                           color[0], color[1], color[2], font, bold, italic, shadow );
1611
1612   // Tick marks
1613   isVisible = actor->GetTickVisibility();
1614   int length = actor->GetTickLength();
1615   writer.writeStartElement("TickMarks");
1616   writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1617   writer.writeAttribute("Length", QString("%1").arg(length));
1618   writer.writeEndElement();
1619   
1620   //params += QString().sprintf( "* Tick marks *%u*%u", isVisible, length );
1621   
1622   writer.writeEndElement();
1623   //return params;
1624 }
1625
1626 void setGradAxisVisualParams(QXmlStreamReader& reader, vtkAxisActor2D* actor)
1627 {
1628   if ( !actor )
1629     return;
1630
1631   do {
1632     reader.readNext();
1633   } while (!reader.isStartElement());
1634
1635   // Read title params
1636   QXmlStreamAttributes aAttr = reader.attributes();
1637   bool isVisible = aAttr.value("isVisible").toString().toUShort();
1638   QString title = aAttr.value("Text").toString();
1639   int font = aAttr.value("Font").toString().toInt();
1640   int bold = aAttr.value("Bold").toString().toInt();
1641   int italic = aAttr.value("Italic").toString().toInt();
1642   int shadow = aAttr.value("Shadow").toString().toInt();
1643
1644   //printf("#### TITLE: %i, %s, %i, %i, %i, %i\n", isVisible, qPrintable(title), font, bold, italic, shadow);
1645
1646   do {
1647     reader.readNext();
1648   } while (!reader.isStartElement());
1649   
1650   // Read title color
1651   aAttr = reader.attributes();
1652
1653   double color[3];
1654   color[0] = aAttr.value("R").toString().toDouble();
1655   color[1] = aAttr.value("G").toString().toDouble();
1656   color[2] = aAttr.value("B").toString().toDouble();
1657   //printf("#### Color: %f, %f, %f\n", color[0], color[1], color[2]);
1658
1659   actor->SetTitleVisibility( isVisible );
1660   actor->SetTitle( title.toUtf8() );
1661   vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1662   if ( txtProp ) {
1663     txtProp->SetColor( color );
1664     txtProp->SetFontFamily( font );
1665     txtProp->SetBold( bold );
1666     txtProp->SetItalic( italic );
1667     txtProp->SetShadow( shadow );
1668   }
1669
1670   // Labels
1671
1672   do {
1673     reader.readNext();
1674   } while (!reader.isStartElement()); 
1675   // Read labels
1676   aAttr = reader.attributes();
1677   isVisible = aAttr.value("isVisible").toString().toUShort();
1678   int labels = aAttr.value("Number").toString().toInt();
1679   int offset = aAttr.value("Offset").toString().toInt();
1680   font = aAttr.value("Font").toString().toInt();
1681   bold = aAttr.value("Bold").toString().toInt();
1682   italic = aAttr.value("Italic").toString().toInt();
1683   shadow = aAttr.value("Shadow").toString().toInt();
1684
1685   do {
1686     reader.readNext();
1687   } while (!reader.isStartElement()); 
1688   // Read Color
1689   aAttr = reader.attributes();
1690
1691   color[0] = aAttr.value("R").toString().toDouble();
1692   color[1] = aAttr.value("G").toString().toDouble();
1693   color[2] = aAttr.value("B").toString().toDouble();
1694
1695   actor->SetLabelVisibility( isVisible );
1696   actor->SetNumberOfLabels( labels );
1697   actor->SetTickOffset( offset );
1698   txtProp = actor->GetLabelTextProperty();
1699   if ( txtProp ) {
1700     txtProp->SetColor( color );
1701     txtProp->SetFontFamily( font );
1702     txtProp->SetBold( bold );
1703     txtProp->SetItalic( italic );
1704     txtProp->SetShadow( shadow );
1705   }
1706
1707   // Tick Marks
1708   do {
1709     reader.readNext();
1710   } while (!reader.isStartElement()); 
1711   aAttr = reader.attributes();
1712
1713   // retrieve and set tick marks properties
1714   isVisible = aAttr.value("isVisible").toString().toUShort();
1715   int length = aAttr.value("Length").toString().toInt();
1716   
1717   actor->SetTickVisibility( isVisible );
1718   actor->SetTickLength( length );
1719 }
1720
1721 /*! The method restores visual parameters of a graduated axis actor (x,y,z axis)
1722  */
1723 void setGradAxisVisualParams( vtkAxisActor2D* actor, const QString& params )
1724 {
1725   if ( !actor )
1726     return;
1727
1728   QStringList paramsLst = params.split( '*' );
1729
1730   if ( paramsLst.size() == nGradAxisParams ) { // altogether name, lable, ticks parameters make up 25 values
1731
1732     // retrieve and set name parameters
1733     bool isVisible = paramsLst[2].toUShort();
1734     QString title = paramsLst[3];
1735     double color[3];
1736     color[0] = paramsLst[4].toDouble();
1737     color[1] = paramsLst[5].toDouble();
1738     color[2] = paramsLst[6].toDouble();
1739     int font = paramsLst[7].toInt();
1740     int bold = paramsLst[8].toInt();
1741     int italic = paramsLst[9].toInt();
1742     int shadow = paramsLst[10].toInt();
1743
1744     actor->SetTitleVisibility( isVisible );
1745     actor->SetTitle( title.toUtf8() );
1746     vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1747     if ( txtProp ) {
1748       txtProp->SetColor( color );
1749       txtProp->SetFontFamily( font );
1750       txtProp->SetBold( bold );
1751       txtProp->SetItalic( italic );
1752       txtProp->SetShadow( shadow );
1753     }
1754
1755     // retrieve and set lable parameters
1756     isVisible = paramsLst[12].toUShort();
1757     int labels = paramsLst[13].toInt();
1758     int offset = paramsLst[14].toInt();
1759     color[0] = paramsLst[15].toDouble();
1760     color[1] = paramsLst[16].toDouble();
1761     color[2] = paramsLst[17].toDouble();
1762     font = paramsLst[18].toInt();
1763     bold = paramsLst[19].toInt();
1764     italic = paramsLst[20].toInt();
1765     shadow = paramsLst[21].toInt();
1766
1767     actor->SetLabelVisibility( isVisible );
1768     actor->SetNumberOfLabels( labels );
1769     actor->SetTickOffset( offset );
1770     txtProp = actor->GetLabelTextProperty();
1771     if ( txtProp ) {
1772       txtProp->SetColor( color );
1773       txtProp->SetFontFamily( font );
1774       txtProp->SetBold( bold );
1775       txtProp->SetItalic( italic );
1776       txtProp->SetShadow( shadow );
1777     }
1778
1779     // retrieve and set tick marks properties
1780     isVisible = paramsLst[23].toUShort();
1781     int length = paramsLst[24].toInt();
1782
1783     actor->SetTickVisibility( isVisible );
1784     actor->SetTickLength( length );
1785   }
1786 }
1787
1788 /*! The method returns the visual parameters of this view as a formated string
1789  */
1790 QString SVTK_ViewWindow::getVisualParameters()
1791 {
1792   double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
1793   
1794   // save position, focal point, viewUp, scale
1795   vtkCamera* camera = getRenderer()->GetActiveCamera();
1796   camera->GetPosition( pos );
1797   camera->GetFocalPoint( focalPnt );
1798   camera->GetViewUp( viewUp );
1799   parScale = camera->GetParallelScale();
1800   GetScale( scale );
1801
1802   // Parameters are given in the following format:view position (3 digits), focal point position (3 digits)
1803   // view up values (3 digits), parallel scale (1 digit), scale (3 digits, 
1804   // Graduated axes parameters (X, Y, Z axes parameters)
1805   QString retStr;
1806   QXmlStreamWriter aWriter(&retStr);
1807   aWriter.setAutoFormatting(true);
1808
1809   aWriter.writeStartDocument();
1810   aWriter.writeStartElement("ViewState");
1811
1812   aWriter.writeStartElement("Position");
1813   aWriter.writeAttribute("X", QString("%1").arg(pos[0]));
1814   aWriter.writeAttribute("Y", QString("%1").arg(pos[1]));
1815   aWriter.writeAttribute("Z", QString("%1").arg(pos[2]));
1816   aWriter.writeEndElement();
1817
1818   aWriter.writeStartElement("FocalPoint");
1819   aWriter.writeAttribute("X", QString::number(focalPnt[0]));
1820   aWriter.writeAttribute("Y", QString::number(focalPnt[1]));
1821   aWriter.writeAttribute("Z", QString::number(focalPnt[2]));
1822   aWriter.writeEndElement();
1823
1824   aWriter.writeStartElement("ViewUp");
1825   aWriter.writeAttribute("X", QString::number(viewUp[0]));
1826   aWriter.writeAttribute("Y", QString::number(viewUp[1]));
1827   aWriter.writeAttribute("Z", QString::number(viewUp[2]));
1828   aWriter.writeEndElement();
1829
1830   aWriter.writeStartElement("ViewScale");
1831   aWriter.writeAttribute("Parallel", QString::number(parScale));
1832   aWriter.writeAttribute("X", QString::number(scale[0]));
1833   aWriter.writeAttribute("Y", QString::number(scale[1]));
1834   aWriter.writeAttribute("Z", QString::number(scale[2]));
1835   aWriter.writeEndElement();
1836
1837   if ( SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes() ) {
1838     aWriter.writeStartElement("DisplayCubeAxis");
1839     aWriter.writeAttribute("Show", QString( "%1" ).arg( GetRenderer()->IsCubeAxesDisplayed()));
1840     aWriter.writeEndElement();
1841
1842     getGradAxisVisualParams(aWriter, gradAxesActor->GetXAxisActor2D(), "X");
1843     getGradAxisVisualParams(aWriter, gradAxesActor->GetYAxisActor2D(), "Y");
1844     getGradAxisVisualParams(aWriter, gradAxesActor->GetZAxisActor2D(), "Z");
1845   }
1846
1847   aWriter.writeStartElement("Trihedron");
1848   aWriter.writeAttribute("isShown",  QString( "%1" ).arg( isTrihedronDisplayed()));
1849   aWriter.writeAttribute("Size", QString::number(GetTrihedronSize()));
1850   aWriter.writeEndElement();
1851
1852   aWriter.writeStartElement("Background");
1853   aWriter.writeAttribute("Value",  QString( "%1" ).arg( Qtx::backgroundToString(background()) ));
1854   aWriter.writeEndElement();
1855
1856   aWriter.writeEndElement();
1857   aWriter.writeEndDocument();
1858
1859   return retStr;
1860 }
1861
1862 /*!
1863   The method restores visual parameters of this view or postpones it untill the view is shown
1864 */ 
1865 void SVTK_ViewWindow::setVisualParameters( const QString& parameters )
1866 {
1867   //printf("#### %s\n", qPrintable(parameters));
1868   SVTK_RenderWindowInteractor* anInteractor = GetInteractor();
1869   if ( anInteractor->isVisible() ) {
1870     doSetVisualParameters( parameters ); 
1871   }
1872   else {
1873     myVisualParams = parameters;
1874     anInteractor->installEventFilter(this);
1875   }
1876 }
1877
1878 /*!
1879   The method restores visual parameters of this view from a formated string
1880 */
1881 void SVTK_ViewWindow::doSetVisualParameters( const QString& parameters, bool baseParamsOnly )
1882 {
1883
1884   double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
1885
1886   QXmlStreamReader aReader(parameters);
1887   SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes();
1888
1889   while(!aReader.atEnd()) {
1890     aReader.readNext();
1891     if (aReader.isStartElement()) {
1892       QXmlStreamAttributes aAttr = aReader.attributes();
1893       //printf("### Name = %s\n", qPrintable(aReader.name().toString()));
1894       if (aReader.name() == "Position") {
1895         pos[0] = aAttr.value("X").toString().toDouble();
1896         pos[1] = aAttr.value("Y").toString().toDouble();
1897         pos[2] = aAttr.value("Z").toString().toDouble();
1898         //printf("#### Position %f; %f; %f\n", pos[0], pos[1], pos[2]);
1899       }
1900       else if (aReader.name() == "FocalPoint") {
1901         focalPnt[0] = aAttr.value("X").toString().toDouble();
1902         focalPnt[1] = aAttr.value("Y").toString().toDouble();
1903         focalPnt[2] = aAttr.value("Z").toString().toDouble();
1904         //printf("#### FocalPoint %f; %f; %f\n", focalPnt[0], focalPnt[1], focalPnt[2]);
1905       }
1906       else if (aReader.name() == "ViewUp") {
1907         viewUp[0] = aAttr.value("X").toString().toDouble();
1908         viewUp[1] = aAttr.value("Y").toString().toDouble();
1909         viewUp[2] = aAttr.value("Z").toString().toDouble();
1910         //printf("#### ViewUp %f; %f; %f\n", viewUp[0], viewUp[1], viewUp[2]);
1911       }
1912       else if (aReader.name() == "ViewScale") {
1913         parScale = aAttr.value("Parallel").toString().toDouble();
1914         scale[0] = aAttr.value("X").toString().toDouble();
1915         scale[1] = aAttr.value("Y").toString().toDouble();
1916         scale[2] = aAttr.value("Z").toString().toDouble();
1917         //printf("#### ViewScale %f; %f; %f\n", scale[0], scale[1], scale[2]);
1918       }
1919       else if (aReader.name() == "DisplayCubeAxis") {
1920         if ( !baseParamsOnly ) {
1921           if (aAttr.value("Show") == "0")
1922             gradAxesActor->VisibilityOff();
1923           else
1924             gradAxesActor->VisibilityOn();
1925         }
1926       }
1927       else if (aReader.name() == "GraduatedAxis") {
1928         if ( !baseParamsOnly ) {
1929           if(aAttr.value("Axis") == "X")
1930             setGradAxisVisualParams(aReader, gradAxesActor->GetXAxisActor2D());
1931           else if(aAttr.value("Axis") == "Y")
1932             setGradAxisVisualParams(aReader, gradAxesActor->GetYAxisActor2D());
1933           else if(aAttr.value("Axis") == "Z")
1934             setGradAxisVisualParams(aReader, gradAxesActor->GetZAxisActor2D());
1935         }
1936       }
1937       else if (aReader.name() == "Trihedron") {
1938         if ( !baseParamsOnly ) {
1939           if (aAttr.value("isShown") == "0")
1940             GetTrihedron()->VisibilityOff();
1941           else
1942             GetTrihedron()->VisibilityOn();
1943           SetTrihedronSize(aAttr.value("Size").toString().toDouble());
1944         }
1945       }
1946       else if (aReader.name() == "Background") {
1947         if ( !baseParamsOnly ) {
1948           setBackground( Qtx::stringToBackground( aAttr.value("Value").toString() ) );
1949         }
1950       }
1951     }
1952   }
1953   if (!aReader.hasError()) {
1954     vtkCamera* camera = getRenderer()->GetActiveCamera();
1955     camera->SetPosition( pos );
1956     camera->SetFocalPoint( focalPnt );
1957     camera->SetViewUp( viewUp );
1958     camera->SetParallelScale( parScale );
1959     GetRenderer()->SetScale( scale );
1960     //SetScale( scale );
1961   }
1962   else {
1963     QStringList paramsLst = parameters.split( '*' );
1964     if ( paramsLst.size() >= nNormalParams ) {
1965       // 'reading' list of parameters
1966       pos[0] = paramsLst[0].toDouble();
1967       pos[1] = paramsLst[1].toDouble();
1968       pos[2] = paramsLst[2].toDouble();
1969       focalPnt[0] = paramsLst[3].toDouble();
1970       focalPnt[1] = paramsLst[4].toDouble();
1971       focalPnt[2] = paramsLst[5].toDouble();
1972       viewUp[0] = paramsLst[6].toDouble();
1973       viewUp[1] = paramsLst[7].toDouble();
1974       viewUp[2] = paramsLst[8].toDouble();
1975       parScale = paramsLst[9].toDouble();
1976       scale[0] = paramsLst[10].toDouble();
1977       scale[1] = paramsLst[11].toDouble();
1978       scale[2] = paramsLst[12].toDouble();
1979
1980       // applying parameters
1981       vtkCamera* camera = getRenderer()->GetActiveCamera();
1982       camera->SetPosition( pos );
1983       camera->SetFocalPoint( focalPnt );
1984       camera->SetViewUp( viewUp );
1985       camera->SetParallelScale( parScale );
1986       GetRenderer()->SetScale( scale );
1987       //SetScale( scale );
1988
1989       // apply graduated axes parameters
1990       if ( !baseParamsOnly ) {
1991         SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes();
1992         if ( gradAxesActor && paramsLst.size() == nAllParams ) {
1993           int i = nNormalParams+1, j = i + nGradAxisParams - 1;
1994           ::setGradAxisVisualParams( gradAxesActor->GetXAxisActor2D(), parameters.section( '*', i, j ) );
1995           i = j + 1; j += nGradAxisParams;
1996           ::setGradAxisVisualParams( gradAxesActor->GetYAxisActor2D(), parameters.section( '*', i, j ) );
1997           i = j + 1; j += nGradAxisParams;
1998           ::setGradAxisVisualParams( gradAxesActor->GetZAxisActor2D(), parameters.section( '*', i, j ) );
1999
2000           if ( paramsLst[13].toUShort() )
2001             gradAxesActor->VisibilityOn();
2002           else
2003             gradAxesActor->VisibilityOff();
2004         }
2005         else if ( paramsLst.size() == nAllParams ) {
2006           if ( paramsLst[90].toUShort() )
2007             GetTrihedron()->VisibilityOn();
2008           else
2009             GetTrihedron()->VisibilityOff();
2010
2011           SetTrihedronSize(paramsLst[91].toDouble());
2012         }
2013       }
2014     }
2015   }
2016   Repaint();
2017 }
2018
2019
2020 /*!
2021   Delayed setVisualParameters
2022 */
2023 bool SVTK_ViewWindow::eventFilter( QObject* theWatched, QEvent* theEvent )
2024 {
2025   if ( theEvent->type() == QEvent::Show && theWatched->inherits( "SVTK_RenderWindowInteractor" ) ) {
2026     SVTK_RenderWindowInteractor* anInteractor = (SVTK_RenderWindowInteractor*)theWatched;
2027     if ( anInteractor->isVisible() ) {
2028       doSetVisualParameters( myVisualParams );
2029       anInteractor->removeEventFilter( this ); // theWatched = RenderWindowInteractor
2030     }
2031   }
2032   return SUIT_ViewWindow::eventFilter( theWatched, theEvent );
2033 }
2034
2035
2036 /*!
2037   Change rotation point
2038 */
2039 void SVTK_ViewWindow::onChangeRotationPoint(bool theIsActivate)
2040 {
2041   if(theIsActivate){
2042     mySetRotationPointDlg->addObserver();
2043     if ( mySetRotationPointDlg->IsFirstShown() )
2044       activateSetRotationGravity();
2045     mySetRotationPointDlg->show();
2046   }else
2047     mySetRotationPointDlg->hide();
2048 }
2049
2050 /*!
2051   Set the gravity center as a rotation point
2052 */
2053 void SVTK_ViewWindow::activateSetRotationGravity()
2054 {
2055   myEventDispatcher->InvokeEvent(SVTK::SetRotateGravity,0);
2056 }
2057
2058 /*!
2059   Set the selected point as a rotation point
2060 */
2061 void SVTK_ViewWindow::activateSetRotationSelected(void* theData)
2062 {
2063   myEventDispatcher->InvokeEvent(SVTK::ChangeRotationPoint,theData);
2064 }
2065
2066 /*!
2067   Set the gravity center of element selected by user as a rotation point
2068 */
2069 void SVTK_ViewWindow::activateStartPointSelection( Selection_Mode theSelectionMode )
2070 {
2071   SetSelectionMode( theSelectionMode );
2072   myEventDispatcher->InvokeEvent(SVTK::StartPointSelection,0);
2073 }
2074
2075 /*!
2076   \brief Set the given projection mode.
2077
2078   Set the given projection mode: Orthographic or Perspective.
2079 */
2080 void SVTK_ViewWindow::onProjectionMode( QAction* theAction )
2081 {
2082   int aMode = Parallel;
2083   if (theAction == toolMgr()->action( ProjectionModeId ))
2084     aMode = Projection;
2085   SVTK_Viewer* aViewer = dynamic_cast<SVTK_Viewer*>(myModel);
2086   aViewer->setProjectionMode(aMode);
2087   bool anIsParallelMode = (aMode == Parallel);
2088   vtkCamera* aCamera = getRenderer()->GetActiveCamera();
2089   aCamera->SetParallelProjection(anIsParallelMode);
2090   GetInteractor()->GetDevice()->CreateTimer(VTKI_TIMER_FIRST);
2091   getRenderWindow()->SetStereoRender(0);
2092   Repaint();
2093 }
2094
2095 /*!
2096   \brief Sets Stereo projection mode.
2097
2098   Sets Stereo projection mode.
2099 */
2100 void SVTK_ViewWindow::onStereoMode( bool activate )
2101 {
2102   if (activate) {
2103     toolMgr()->action( ProjectionModeId )->setChecked(true);
2104     vtkCamera* aCamera = getRenderer()->GetActiveCamera();
2105     aCamera->SetParallelProjection(false);
2106     toolMgr()->action( ProjectionModeId )->actionGroup()->setEnabled(false);
2107     SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
2108     SetStereoType( aResMgr->integerValue( "VTKViewer", "stereo_type", 0 ) );
2109     getRenderWindow()->SetStereoRender(1);
2110     Repaint();
2111   }
2112   else {
2113     toolMgr()->action( ProjectionModeId )->actionGroup()->setEnabled(true);
2114     SVTK_Viewer* aViewer = dynamic_cast<SVTK_Viewer*>(myModel);
2115     if (aViewer->projectionMode() == Parallel) {
2116       toolMgr()->action( ParallelModeId )->setChecked(true);
2117       onProjectionMode(toolMgr()->action( ParallelModeId ));
2118     }
2119     else if (aViewer->projectionMode() == Projection) {
2120       toolMgr()->action( ProjectionModeId )->setChecked(true);
2121       onProjectionMode(toolMgr()->action( ProjectionModeId ));
2122     }
2123   }
2124   if ( getRenderWindow()->GetStereoCapableWindow() == 1 && !isOpenGlStereoSupport() &&
2125        strcmp( "CrystalEyes", getRenderWindow()->GetStereoTypeAsString() ) == 0 &&
2126        toolMgr()->action( StereoModeId )->isChecked() )
2127     SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ),  tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
2128 }
2129
2130 /*!
2131   Set the view projection mode: orthogonal or perspective
2132 */
2133 void SVTK_ViewWindow::onProjectionMode()
2134 {
2135   if (toolMgr()->action( ParallelModeId )->isChecked())
2136     SetProjectionMode( Parallel);
2137   if (toolMgr()->action( ProjectionModeId )->isChecked())
2138     SetProjectionMode( Projection);
2139   if (toolMgr()->action( StereoModeId )->isChecked())
2140     SetProjectionMode( Stereo);
2141   emit transformed( this );
2142 }
2143
2144 void SVTK_ViewWindow::SetEventDispatcher(vtkObject* theDispatcher)
2145 {
2146   myEventDispatcher = theDispatcher;
2147 }
2148
2149 /*!
2150   Creates all actions of svtk main window
2151 */
2152 void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
2153 {
2154   QtxAction* anAction;
2155   QtxActionToolMgr* mgr = toolMgr();
2156
2157   // Dump view
2158   anAction = new QtxAction(tr("MNU_DUMP_VIEW"), 
2159                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
2160                            tr( "MNU_DUMP_VIEW" ), 0, this);
2161   anAction->setStatusTip(tr("DSC_DUMP_VIEW"));
2162   connect(anAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
2163   mgr->registerAction( anAction, DumpId );
2164
2165   // FitAll
2166   anAction = new QtxAction(tr("MNU_FITALL"), 
2167                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
2168                            tr( "MNU_FITALL" ), 0, this);
2169   anAction->setStatusTip(tr("DSC_FITALL"));
2170   connect(anAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
2171   mgr->registerAction( anAction, FitAllId );
2172
2173   // FitRect
2174   anAction = new QtxAction(tr("MNU_FITRECT"), 
2175                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
2176                            tr( "MNU_FITRECT" ), 0, this);
2177   anAction->setStatusTip(tr("DSC_FITRECT"));
2178   connect(anAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
2179   mgr->registerAction( anAction, FitRectId );
2180
2181   // FitSelection
2182   anAction = new QtxAction(tr("MNU_FITSELECTION"),
2183                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITSELECTION" ) ),
2184                            tr( "MNU_FITSELECTION" ), 0, this);
2185   anAction->setStatusTip(tr("DSC_FITSELECTION"));
2186   connect(anAction, SIGNAL(triggered()), this, SLOT(onFitSelection()));
2187   mgr->registerAction( anAction, FitSelectionId );
2188
2189   // Zoom
2190   anAction = new QtxAction(tr("MNU_ZOOM_VIEW"), 
2191                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
2192                            tr( "MNU_ZOOM_VIEW" ), 0, this);
2193   anAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
2194   connect(anAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
2195   mgr->registerAction( anAction, ZoomId );
2196
2197   // Panning
2198   anAction = new QtxAction(tr("MNU_PAN_VIEW"), 
2199                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
2200                            tr( "MNU_PAN_VIEW" ), 0, this);
2201   anAction->setStatusTip(tr("DSC_PAN_VIEW"));
2202   connect(anAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
2203   mgr->registerAction( anAction, PanId );
2204
2205   // Global Panning
2206   anAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), 
2207                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
2208                            tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
2209   anAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
2210   connect(anAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
2211   mgr->registerAction( anAction, GlobalPanId );
2212
2213   // Change rotation point
2214   anAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), 
2215                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_ROTATION_POINT" ) ),
2216                            tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
2217   anAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
2218   anAction->setCheckable(true);
2219   connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onChangeRotationPoint(bool)));
2220   mgr->registerAction( anAction, ChangeRotationPointId );
2221
2222   // Rotation
2223   anAction = new QtxAction(tr("MNU_ROTATE_VIEW"), 
2224                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
2225                            tr( "MNU_ROTATE_VIEW" ), 0, this);
2226   anAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
2227   connect(anAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
2228   mgr->registerAction( anAction, RotationId );
2229
2230   // Projections
2231   anAction = new QtxAction(tr("MNU_FRONT_VIEW"), 
2232                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
2233                            tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
2234   anAction->setStatusTip(tr("DSC_FRONT_VIEW"));
2235   connect(anAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
2236   this->addAction(anAction);
2237   mgr->registerAction( anAction, FrontId );
2238
2239   anAction = new QtxAction(tr("MNU_BACK_VIEW"),
2240                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
2241                            tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
2242   anAction->setStatusTip(tr("DSC_BACK_VIEW"));
2243   connect(anAction, SIGNAL(triggered()), this, SLOT(onBackView()));
2244   this->addAction(anAction);
2245   mgr->registerAction( anAction, BackId );
2246
2247   anAction = new QtxAction(tr("MNU_TOP_VIEW"),
2248                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
2249                            tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
2250   anAction->setStatusTip(tr("DSC_TOP_VIEW"));
2251   connect(anAction, SIGNAL(triggered()), this, SLOT(onTopView()));
2252   this->addAction(anAction);
2253   mgr->registerAction( anAction, TopId );
2254
2255   anAction = new QtxAction(tr("MNU_BOTTOM_VIEW"),
2256                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
2257                            tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
2258   anAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
2259   connect(anAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
2260   this->addAction(anAction);
2261   mgr->registerAction( anAction, BottomId );
2262
2263   anAction = new QtxAction(tr("MNU_LEFT_VIEW"),
2264                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
2265                            tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
2266   anAction->setStatusTip(tr("DSC_LEFT_VIEW"));
2267   connect(anAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
2268   this->addAction(anAction);
2269   mgr->registerAction( anAction, LeftId );
2270
2271   anAction = new QtxAction(tr("MNU_RIGHT_VIEW"),
2272                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
2273                            tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
2274   anAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
2275   connect(anAction, SIGNAL(triggered()), this, SLOT(onRightView()));
2276   this->addAction(anAction);
2277   mgr->registerAction( anAction, RightId );
2278
2279   // rotate anticlockwise
2280   anAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"),
2281                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ANTICLOCKWISE" ) ),
2282                            tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
2283   anAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
2284   connect(anAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
2285   this->addAction(anAction);
2286   mgr->registerAction( anAction, AntiClockWiseId );
2287
2288   // rotate clockwise
2289   anAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"),
2290                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_CLOCKWISE" ) ),
2291                            tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
2292   anAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
2293   connect(anAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
2294   this->addAction(anAction);
2295   mgr->registerAction( anAction, ClockWiseId );
2296
2297   // Reset
2298   anAction = new QtxAction(tr("MNU_RESET_VIEW"), 
2299                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
2300                            tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
2301   anAction->setStatusTip(tr("DSC_RESET_VIEW"));
2302   connect(anAction, SIGNAL(triggered()), this, SLOT(onResetView()));
2303   this->addAction(anAction);
2304   mgr->registerAction( anAction, ResetId );
2305
2306   // onViewTrihedron: Shows - Hides Trihedron
2307   anAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"), 
2308                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ),
2309                            tr( "MNU_SHOW_TRIHEDRON" ), 0, this);
2310   anAction->setCheckable( true );
2311   anAction->setChecked( true );
2312   
2313   anAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON"));
2314   connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onViewTrihedron(bool)));
2315   mgr->registerAction( anAction, ViewTrihedronId );
2316
2317   // onNonIsometric: Manage non-isometric params
2318   anAction = new QtxAction(tr("MNU_SVTK_SCALING"), 
2319                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SCALING" ) ),
2320                            tr( "MNU_SVTK_SCALING" ), 0, this);
2321   anAction->setStatusTip(tr("DSC_SVTK_SCALING"));
2322   anAction->setCheckable(true);
2323   connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onNonIsometric(bool)));
2324   mgr->registerAction( anAction, NonIsometric );
2325
2326   // onGraduatedAxes: Manage graduated axes params
2327   anAction = new QtxAction(tr("MNU_SVTK_GRADUATED_AXES"), 
2328                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_GRADUATED_AXES" ) ),
2329                            tr( "MNU_SVTK_GRADUATED_AXES" ), 0, this);
2330   anAction->setStatusTip(tr("DSC_SVTK_GRADUATED_AXES"));
2331   anAction->setCheckable(true);
2332   connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onGraduatedAxes(bool)));
2333   mgr->registerAction( anAction, GraduatedAxes );
2334
2335   // onGraduatedAxes: Manage graduated axes params
2336   anAction = new QtxAction(tr("MNU_SVTK_UPDATE_RATE"), 
2337                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_UPDATE_RATE" ) ),
2338                            tr( "MNU_SVTK_UPDATE_RATE" ), 0, this);
2339   anAction->setStatusTip(tr("DSC_SVTK_UPDATE_RATE"));
2340   anAction->setCheckable(true);
2341   connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onUpdateRate(bool)));
2342   mgr->registerAction( anAction, UpdateRate );
2343
2344   // Set perspective mode group
2345   anAction = new QtxAction(tr("MNU_SVTK_PARALLEL_MODE"), 
2346                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARALLEL" ) ),
2347                            tr( "MNU_SVTK_PARALLEL_MODE" ), 0, this);
2348   anAction->setStatusTip(tr("DSC_SVTK_PARALLEL_MODE"));
2349   anAction->setCheckable(true);
2350   mgr->registerAction( anAction, ParallelModeId );
2351
2352   anAction = new QtxAction(tr("MNU_SVTK_PERSPECTIVE_MODE"), 
2353                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PERSPECTIVE" ) ),
2354                            tr( "MNU_SVTK_PERSPECTIVE_MODE" ), 0, this);
2355   anAction->setStatusTip(tr("DSC_SVTK_PERSPECTIVE_MODE"));
2356   anAction->setCheckable(true);
2357   mgr->registerAction( anAction, ProjectionModeId );
2358
2359   anAction = new QtxAction(tr("MNU_SVTK_STEREO_MODE"),
2360                              theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_STEREO" ) ),
2361                              tr( "MNU_SVTK_STEREO_MODE" ), 0, this);
2362   anAction->setStatusTip(tr("DSC_SVTK_STEREO_MODE"));
2363   anAction->setCheckable(true);
2364   connect(anAction, SIGNAL(triggered(bool)), this, SLOT(onStereoMode(bool)));
2365   mgr->registerAction( anAction, StereoModeId );
2366
2367   QActionGroup* aPerspectiveGroup = new QActionGroup( this );
2368   aPerspectiveGroup->addAction( mgr->action( ParallelModeId ) );
2369   aPerspectiveGroup->addAction( mgr->action( ProjectionModeId ) );
2370   connect(aPerspectiveGroup, SIGNAL(triggered(QAction*)), this, SLOT(onProjectionMode(QAction*)));
2371
2372   // View Parameters
2373   anAction = new QtxAction(tr("MNU_VIEWPARAMETERS_VIEW"), 
2374                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARAMETERS" ) ),
2375                            tr( "MNU_VIEWPARAMETERS_VIEW" ), 0, this);
2376   anAction->setStatusTip(tr("DSC_VIEWPARAMETERS_VIEW"));
2377   anAction->setCheckable(true);
2378   connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onViewParameters(bool)));
2379   mgr->registerAction( anAction, ViewParametersId );
2380
2381   // Synchronize View 
2382   mgr->registerAction( synchronizeAction(), SynchronizeId );
2383
2384   // Switch between interaction styles
2385   anAction = new QtxAction(tr("MNU_SVTK_STYLE_SWITCH"), 
2386                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_STYLE_SWITCH" ) ),
2387                            tr( "MNU_SVTK_STYLE_SWITCH" ), 0, this);
2388   anAction->setStatusTip(tr("DSC_SVTK_STYLE_SWITCH"));
2389   anAction->setCheckable(true);
2390   connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
2391   mgr->registerAction( anAction, SwitchInteractionStyleId );
2392
2393   // Switch between zooming styles
2394   anAction = new QtxAction(tr("MNU_SVTK_ZOOMING_STYLE_SWITCH"), 
2395                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_ZOOMING_STYLE_SWITCH" ) ),
2396                            tr( "MNU_SVTK_ZOOMING_STYLE_SWITCH" ), 0, this);
2397   anAction->setStatusTip(tr("DSC_SVTK_ZOOMING_STYLE_SWITCH"));
2398   anAction->setCheckable(true);
2399   connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
2400   mgr->registerAction( anAction, SwitchZoomingStyleId );
2401
2402   // Pre-selection
2403   QSignalMapper* aSignalMapper = new QSignalMapper( this );
2404   connect(aSignalMapper, SIGNAL(mapped(int)), this, SLOT(onSwitchPreSelectionMode(int)));
2405
2406   anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_STANDARD"), 
2407                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_STANDARD" ) ),
2408                            tr( "MNU_SVTK_PRESELECTION_STANDARD" ), 0, this);
2409   anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_STANDARD"));
2410   anAction->setCheckable(true);
2411   connect(anAction, SIGNAL(triggered()), aSignalMapper, SLOT(map()));
2412   aSignalMapper->setMapping( anAction, Standard_Preselection );
2413   mgr->registerAction( anAction, StandardPreselectionId );
2414   
2415   anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_DYNAMIC"), 
2416                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_DYNAMIC" ) ),
2417                            tr( "MNU_SVTK_PRESELECTION_DYNAMIC" ), 0, this);
2418   anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_DYNAMIC"));
2419   anAction->setCheckable(true);
2420   connect(anAction, SIGNAL(triggered()), aSignalMapper, SLOT(map()));
2421   aSignalMapper->setMapping( anAction, Dynamic_Preselection );
2422   mgr->registerAction( anAction, DynamicPreselectionId );
2423
2424   anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_DISABLED"), 
2425                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_DISABLED" ) ),
2426                            tr( "MNU_SVTK_PRESELECTION_DISABLED" ), 0, this);
2427   anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_DISABLED"));
2428   anAction->setCheckable(true);
2429   connect(anAction, SIGNAL(triggered()), aSignalMapper, SLOT(map()));
2430   aSignalMapper->setMapping( anAction, Preselection_Disabled );
2431   mgr->registerAction( anAction, DisablePreselectionId );
2432
2433   QtxActionGroup* aPreselectionAction = new QtxActionGroup( this, true );
2434   aPreselectionAction->add( getAction( StandardPreselectionId ) );
2435   aPreselectionAction->add( getAction( DynamicPreselectionId ) );
2436   aPreselectionAction->add( getAction( DisablePreselectionId ) );
2437   mgr->registerAction( aPreselectionAction, PreselectionId );
2438
2439   // Selection
2440   anAction = new QtxAction(tr("MNU_SVTK_ENABLE_SELECTION"), 
2441                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SELECTION" ) ),
2442                            tr( "MNU_SVTK_ENABLE_SELECTION" ), 0, this);
2443   anAction->setStatusTip(tr("DSC_SVTK_ENABLE_SELECTION"));
2444   anAction->setCheckable(true);
2445   connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onEnableSelection(bool)));
2446   mgr->registerAction( anAction, EnableSelectionId );
2447
2448   // Start recording
2449   myStartAction = new QtxAction(tr("MNU_SVTK_RECORDING_START"), 
2450                                 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_START" ) ),
2451                                 tr( "MNU_SVTK_RECORDING_START" ), 0, this);
2452   myStartAction->setStatusTip(tr("DSC_SVTK_RECORDING_START"));
2453   connect( myStartAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStartRecording() ) );
2454   mgr->registerAction( myStartAction, StartRecordingId );
2455
2456   // Play recording
2457   myPlayAction = new QtxAction(tr("MNU_SVTK_RECORDING_PLAY"), 
2458                                theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PLAY" ) ),
2459                                tr( "MNU_SVTK_RECORDING_PLAY" ), 0, this);
2460   myPlayAction->setStatusTip(tr("DSC_SVTK_RECORDING_PLAY"));
2461   myPlayAction->setEnabled( false );
2462   connect( myPlayAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPlayRecording() ) );
2463   mgr->registerAction( myPlayAction, PlayRecordingId );
2464
2465   // Pause recording
2466   myPauseAction = new QtxAction(tr("MNU_SVTK_RECORDING_PAUSE"), 
2467                                 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PAUSE" ) ),
2468                                 tr( "MNU_SVTK_RECORDING_PAUSE" ), 0, this);
2469   myPauseAction->setStatusTip(tr("DSC_SVTK_RECORDING_PAUSE"));
2470   myPauseAction->setEnabled( false );
2471   connect( myPauseAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPauseRecording() ) );
2472   mgr->registerAction( myPauseAction, PauseRecordingId );
2473
2474   // Stop recording
2475   myStopAction = new QtxAction(tr("MNU_SVTK_RECORDING_STOP"), 
2476                                theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_STOP" ) ),
2477                                tr( "MNU_SVTK_RECORDING_STOP" ), 0, this);
2478   myStopAction->setStatusTip(tr("DSC_SVTK_RECORDING_STOP"));
2479   myStopAction->setEnabled( false );
2480   connect( myStopAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStopRecording() ) );
2481   mgr->registerAction( myStopAction, StopRecordingId );
2482 }
2483
2484 /*!
2485   Creates toolbar of svtk main window
2486 */
2487 void SVTK_ViewWindow::createToolBar()
2488 {
2489   QtxActionToolMgr* mgr = toolMgr();
2490   
2491   mgr->append( DumpId, myToolBar );
2492   mgr->append( SwitchInteractionStyleId, myToolBar );
2493   mgr->append( SwitchZoomingStyleId, myToolBar );
2494
2495   mgr->append( mgr->separator(), myToolBar );
2496  
2497   mgr->append( PreselectionId, myToolBar );
2498   mgr->append( EnableSelectionId, myToolBar );
2499
2500   mgr->append( mgr->separator(), myToolBar );
2501
2502   mgr->append( ViewTrihedronId, myToolBar );
2503
2504   QtxMultiAction* aScaleAction = new QtxMultiAction( this );
2505   aScaleAction->insertAction( getAction( FitAllId ) );
2506   aScaleAction->insertAction( getAction( FitRectId ) );
2507   aScaleAction->insertAction( getAction( FitSelectionId ) );
2508   aScaleAction->insertAction( getAction( ZoomId ) );
2509   mgr->append( aScaleAction, myToolBar );
2510
2511   QtxMultiAction* aPanningAction = new QtxMultiAction( this );
2512   aPanningAction->insertAction( getAction( PanId ) );
2513   aPanningAction->insertAction( getAction( GlobalPanId ) );
2514   mgr->append( aPanningAction, myToolBar );
2515
2516   mgr->append( ChangeRotationPointId, myToolBar );
2517
2518   mgr->append( RotationId, myToolBar );
2519
2520   QtxMultiAction* aViewsAction = new QtxMultiAction( this );
2521   aViewsAction->insertAction( getAction( FrontId ) );
2522   aViewsAction->insertAction( getAction( BackId ) );
2523   aViewsAction->insertAction( getAction( TopId ) );
2524   aViewsAction->insertAction( getAction( BottomId ) );
2525   aViewsAction->insertAction( getAction( LeftId ) );
2526   aViewsAction->insertAction( getAction( RightId ) );
2527   mgr->append( aViewsAction, myToolBar );
2528
2529   mgr->append( AntiClockWiseId, myToolBar );
2530   mgr->append( ClockWiseId, myToolBar );
2531
2532   mgr->append( ResetId, myToolBar );
2533
2534   mgr->append( UpdateRate, myToolBar );
2535   mgr->append( NonIsometric, myToolBar );
2536   mgr->append( GraduatedAxes, myToolBar );
2537
2538   mgr->append( ViewParametersId, myToolBar );
2539   mgr->append( SynchronizeId, myToolBar );
2540
2541   mgr->append( toolMgr()->separator(), myToolBar );
2542
2543   mgr->append( ParallelModeId, myToolBar );
2544   mgr->append( ProjectionModeId, myToolBar );
2545   mgr->append( StereoModeId, myToolBar );
2546
2547   mgr->append( StartRecordingId, myRecordingToolBar );
2548   mgr->append( PlayRecordingId, myRecordingToolBar );
2549   mgr->append( PauseRecordingId, myRecordingToolBar );
2550   mgr->append( StopRecordingId, myRecordingToolBar );
2551 }
2552
2553 void SVTK_ViewWindow::onUpdateRate(bool theIsActivate)
2554 {
2555   if(theIsActivate){
2556     myUpdateRateDlg->Update();
2557     myUpdateRateDlg->show();
2558   }else
2559     myUpdateRateDlg->hide();
2560 }
2561
2562 void SVTK_ViewWindow::onNonIsometric(bool theIsActivate)
2563 {
2564   if(theIsActivate){
2565     myNonIsometricDlg->Update();
2566     myNonIsometricDlg->show();
2567   }else
2568     myNonIsometricDlg->hide();
2569 }
2570
2571 void SVTK_ViewWindow::onGraduatedAxes(bool theIsActivate)
2572 {
2573   if(theIsActivate){
2574     myCubeAxesDlg->Update();
2575     myCubeAxesDlg->show();
2576   }else
2577     myCubeAxesDlg->hide();
2578 }
2579
2580 /*!
2581   Starts rotation transformation
2582 */
2583 void SVTK_ViewWindow::activateRotation()
2584 {
2585   myEventDispatcher->InvokeEvent(SVTK::StartRotate,0);
2586 }
2587
2588
2589 /*!
2590   Starts panning transformation
2591 */
2592 void SVTK_ViewWindow::activatePanning()
2593 {
2594   myEventDispatcher->InvokeEvent(SVTK::StartPan,0);
2595 }
2596
2597 /*!
2598   Starts zoom transformation
2599 */
2600 void SVTK_ViewWindow::activateZoom()
2601 {
2602   myEventDispatcher->InvokeEvent(SVTK::StartZoom,0);
2603 }
2604
2605 /*!
2606   Starts window fit transformation
2607 */
2608 void SVTK_ViewWindow::activateWindowFit()
2609 {
2610   myEventDispatcher->InvokeEvent(SVTK::StartFitArea,0);
2611 }
2612
2613 /*!
2614   Starts global panning transformation
2615 */
2616 void SVTK_ViewWindow::activateGlobalPanning()
2617 {
2618   myEventDispatcher->InvokeEvent(SVTK::StartGlobalPan,0);
2619 }
2620
2621 void SVTK_ViewWindow::onStartRecording()
2622 {
2623   myRecorder->CheckExistAVIMaker();
2624   if (myRecorder->ErrorStatus()) {
2625     SUIT_MessageBox::warning(this, tr("ERROR"), tr("MSG_NO_AVI_MAKER") );
2626   }
2627   else {
2628     SVTK_RecorderDlg* aRecorderDlg = new SVTK_RecorderDlg( this, myRecorder );
2629
2630     if( !aRecorderDlg->exec() )
2631       return;
2632
2633     myStartAction->setEnabled( false );
2634     myPlayAction->setEnabled( false );
2635     myPauseAction->setEnabled( true );
2636     myStopAction->setEnabled( true );
2637
2638     // to prevent resizing the window while recording
2639     myPreRecordingMinSize = minimumSize();
2640     myPreRecordingMaxSize = maximumSize();
2641     setFixedSize( size() );
2642
2643     myRecorder->Record();
2644   }
2645 }
2646
2647 void SVTK_ViewWindow::onPlayRecording()
2648 {
2649   myStartAction->setEnabled( false );
2650   myPlayAction->setEnabled( false );
2651   myPauseAction->setEnabled( true );
2652   myStopAction->setEnabled( true );
2653
2654   myRecorder->Pause();
2655 }
2656
2657 void SVTK_ViewWindow::onPauseRecording()
2658 {
2659   myStartAction->setEnabled( false );
2660   myPlayAction->setEnabled( true );
2661   myPauseAction->setEnabled( false );
2662   myStopAction->setEnabled( true );
2663
2664   myRecorder->Pause();
2665 }
2666
2667 void SVTK_ViewWindow::onStopRecording()
2668 {
2669   myStartAction->setEnabled( true );
2670   myPlayAction->setEnabled( false );
2671   myPauseAction->setEnabled( false );
2672   myStopAction->setEnabled( false );
2673
2674   myRecorder->Stop();
2675
2676   setMinimumSize( myPreRecordingMinSize );
2677   setMaximumSize( myPreRecordingMaxSize );
2678 }
2679
2680 /*!
2681   To invoke a VTK event on SVTK_RenderWindowInteractor instance
2682 */
2683 void SVTK_ViewWindow::InvokeEvent(unsigned long theEvent, void* theCallData)
2684 {
2685   GetInteractor()->InvokeEvent(theEvent,theCallData);
2686 }
2687
2688 /*!
2689   Modify view parameters
2690 */
2691 void SVTK_ViewWindow::onViewParameters(bool theIsActivate)
2692 {
2693   if(theIsActivate){
2694     myViewParameterDlg->addObserver();
2695     myViewParameterDlg->show();
2696   }else
2697     myViewParameterDlg->hide();
2698 }
2699
2700 /*!
2701   Custom show event handler
2702 */
2703 void SVTK_ViewWindow::showEvent( QShowEvent * theEvent ) 
2704 {
2705   emit Show( theEvent );
2706 }
2707
2708 /*!
2709   Custom hide event handler
2710 */
2711 void SVTK_ViewWindow::hideEvent( QHideEvent * theEvent ) 
2712 {
2713   emit Hide( theEvent );
2714 }
2715
2716 /*!
2717   Emit transformed signal.
2718 */
2719 void SVTK_ViewWindow::emitTransformed() {
2720   transformed(this);
2721 }
2722
2723 /*!
2724   Processes events
2725 */
2726 void SVTK_ViewWindow::ProcessEvents(vtkObject* vtkNotUsed(theObject),
2727                                     unsigned long theEvent,
2728                                     void* theClientData,
2729                                     void* theCallData)
2730 {
2731   SVTK_ViewWindow* self = reinterpret_cast<SVTK_ViewWindow*>(theClientData);
2732   if(self)
2733     self->emitTransformed();
2734 }
2735
2736 /*!
2737   Get camera properties for the SVTK view window.
2738   \return shared pointer on camera properties.
2739 */
2740 SUIT_CameraProperties SVTK_ViewWindow::cameraProperties()
2741 {
2742   SUIT_CameraProperties aProps;
2743
2744   // get vtk camera
2745   vtkCamera* aCamera = getRenderer()->GetActiveCamera();
2746   if ( !aCamera )
2747     return aProps;
2748   
2749   aProps.setDimension( SUIT_CameraProperties::Dim3D );
2750   if ( toolMgr()->action( ParallelModeId ) ) {
2751     if ( toolMgr()->action( ParallelModeId )->isChecked() )
2752       aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
2753     else
2754       aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
2755   }
2756
2757   double aFocalPoint[3];
2758   double aPosition[3];
2759   double aViewUp[3];
2760   double anAxialScale[3];
2761
2762   aCamera->OrthogonalizeViewUp();
2763   aCamera->GetFocalPoint( aFocalPoint );
2764   aCamera->GetPosition( aPosition );
2765   aCamera->GetViewUp( aViewUp );
2766   
2767   aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2768   aProps.setPosition( aPosition[0], aPosition[1], aPosition[2] );
2769   aProps.setViewUp( aViewUp[0], aViewUp[1], aViewUp[2] );
2770   aProps.setMappingScale( aCamera->GetParallelScale() * 2.0 );
2771
2772   if ( aProps.getProjection() == SUIT_CameraProperties::PrjPerspective )
2773   {
2774     aProps.setViewAngle( aCamera->GetViewAngle() );
2775   }
2776
2777   GetRenderer()->GetScale( anAxialScale );
2778   aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2779   
2780   return aProps;
2781 }
2782
2783 /*!
2784   Synchronize views.
2785   This implementation synchronizes camera propreties.
2786 */
2787 void SVTK_ViewWindow::synchronize( SUIT_ViewWindow* theView )
2788 {
2789   bool blocked = blockSignals( true );
2790
2791   SUIT_CameraProperties aProps = theView->cameraProperties();
2792   if ( !cameraProperties().isCompatible( aProps ) ) {
2793     // other view, this one is being currently synchronized to, seems has become incompatible
2794     // we have to break synchronization
2795     updateSyncViews();
2796     return;
2797   }
2798
2799   // get camera
2800   vtkCamera* aCamera = getRenderer()->GetActiveCamera();
2801   
2802   double aFocalPoint[3];
2803   double aPosition[3];
2804   double aViewUp[3];
2805   double anAxialScale[3];
2806
2807   // get common properties
2808   aProps.getViewUp( aViewUp[0], aViewUp[1], aViewUp[2] );
2809   aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
2810   aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2811   aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2812   
2813   // restore properties to the camera
2814   aCamera->SetViewUp( aViewUp );
2815   aCamera->SetPosition( aPosition );
2816   aCamera->SetFocalPoint( aFocalPoint );
2817   aCamera->SetParallelScale( aProps.getMappingScale() / 2.0 );
2818
2819   if ( aProps.getProjection() == SUIT_CameraProperties::PrjPerspective )
2820   {
2821     aCamera->SetViewAngle( aProps.getViewAngle() );
2822   }
2823
2824   GetRenderer()->SetScale( anAxialScale );
2825
2826   getRenderer()->ResetCameraClippingRange();
2827   Repaint( false );
2828
2829   blockSignals( blocked );
2830 }