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