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