Salome HOME
Updated copyright comment
[modules/gui.git] / src / SVTK / SVTK_ViewWindow.cxx
1 // Copyright (C) 2007-2024  CEA, EDF, 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   Activate interactive selection
1050 */
1051 void SVTK_ViewWindow::activateInteractiveSelection()
1052 {
1053   myEventDispatcher->InvokeEvent(SVTK::StartInteractiveSelection, 0);
1054 }
1055
1056 /*
1057   Deactivate current active operation
1058 */
1059 void SVTK_ViewWindow::deactivateCurrectOperation() {
1060   myEventDispatcher->InvokeEvent(SVTK::StopCurrentOperation, 0);
1061 }
1062
1063 /*!
1064   Set the selected point as a focal point
1065 */
1066 void SVTK_ViewWindow::activateSetFocalPointSelected()
1067 {
1068   myEventDispatcher->InvokeEvent(SVTK::SetFocalPointSelected, 0);
1069 }
1070
1071 /*!
1072   Set the point selected by user as a focal point
1073 */
1074 void SVTK_ViewWindow::activateStartFocalPointSelection()
1075 {
1076   myEventDispatcher->InvokeEvent(SVTK::StartFocalPointSelection,0);
1077 }
1078
1079 void SVTK_ViewWindow::activateProjectionMode(int theMode)
1080 {
1081   QtxAction* aParallelAction = dynamic_cast<QtxAction*>( toolMgr()->action( ParallelModeId ) );
1082   QtxAction* aProjectionAction = dynamic_cast<QtxAction*>( toolMgr()->action( ProjectionModeId ) );
1083   if (theMode)
1084     aParallelAction->setChecked( true );
1085   else
1086     aProjectionAction->setChecked( true );
1087
1088   if ( !aParallelAction->isEnabled() )
1089     aParallelAction->setEnabled( true );
1090   if ( !aProjectionAction->isEnabled() )
1091     aProjectionAction->setEnabled( true );
1092 }
1093
1094 /*!
1095   Sets actual interaction style
1096   \param theStyle - type of interaction style ( 0 - standard, 1 - keyboard free )
1097 */
1098 void SVTK_ViewWindow::SetInteractionStyle(const int theStyle)
1099 {
1100   onSwitchInteractionStyle( theStyle==1 );
1101 }
1102
1103 /*!
1104   Sets actual zooming style
1105   \param theStyle - type of zooming style ( 0 - standard, 1 - advanced (at cursor) )
1106 */
1107 void SVTK_ViewWindow::SetZoomingStyle(const int theStyle)
1108 {
1109   onSwitchZoomingStyle( theStyle==1 );
1110 }
1111
1112 /*!
1113   Set preselection mode.
1114   \param theMode the mode to set (standard, dynamic or disabled)
1115 */
1116 void SVTK_ViewWindow::SetPreSelectionMode( Preselection_Mode theMode )
1117 {
1118   onSwitchPreSelectionMode( theMode );
1119 }
1120
1121 /*!
1122   Enables/disables selection.
1123   \param theEnable if true - selection will be enabled
1124 */
1125 void SVTK_ViewWindow::SetSelectionEnabled( bool theEnable )
1126 {
1127   GetSelector()->SetSelectionEnabled( theEnable );
1128   QtxAction* a = getAction( EnableSelectionId );
1129   if ( a->isChecked() !=  theEnable)
1130     a->setChecked( theEnable );
1131   QtxActionGroup* aPreselectionGroup = 
1132     dynamic_cast<QtxActionGroup*>( getAction( PreselectionId ) );
1133   if ( aPreselectionGroup )
1134     aPreselectionGroup->setEnabled( theEnable );
1135
1136   // notify actors
1137   vtkActorCollection *actors = getRenderer()->GetActors();
1138   for (int i = 0; i < actors->GetNumberOfItems(); ++i )
1139     if (VTKViewer_Actor *actor = dynamic_cast<VTKViewer_Actor*>(actors->GetItemAsObject(i)))
1140     {
1141       actor->EnableSelection( theEnable );
1142     }
1143 }
1144
1145 /*!
1146   Switches "keyboard free" interaction style on/off
1147 */
1148 void SVTK_ViewWindow::onSwitchInteractionStyle(bool theOn)
1149 {
1150   if (theOn) {
1151     // check if style is already set
1152     if ( GetInteractorStyle() != myKeyFreeInteractorStyle.GetPointer() )
1153     {
1154       // keep the same style extensions
1155       SVTK_InteractorStyle* aStyle = (SVTK_InteractorStyle*)GetInteractorStyle();
1156       if ( aStyle ) {
1157         myKeyFreeInteractorStyle->SetControllerIncrement(aStyle->ControllerIncrement());
1158         myKeyFreeInteractorStyle->SetControllerOnKeyDown(aStyle->ControllerOnKeyDown());
1159       }
1160
1161       PushInteractorStyle(myKeyFreeInteractorStyle.GetPointer());
1162     }
1163   }
1164   else {
1165     // pop only key free  style
1166     if ( GetInteractorStyle() == myKeyFreeInteractorStyle.GetPointer() )
1167       PopInteractorStyle();
1168   }
1169
1170   // update action state if method is called outside
1171   QtxAction* a = getAction( SwitchInteractionStyleId );
1172   if ( a->isChecked() != theOn ) a->setChecked( theOn );
1173 }
1174
1175 /*!
1176   Toogles advanced zooming style (relatively to the cursor position) on/off
1177 */
1178 void SVTK_ViewWindow::onSwitchZoomingStyle( bool theOn )
1179 {
1180   if( myDefaultInteractorStyle.GetPointer() )
1181     myDefaultInteractorStyle->SetAdvancedZoomingEnabled( theOn );
1182   if( myKeyFreeInteractorStyle.GetPointer() )
1183     myKeyFreeInteractorStyle->SetAdvancedZoomingEnabled( theOn );
1184
1185   // update action state if method is called outside
1186   QtxAction* a = getAction( SwitchZoomingStyleId );
1187   if ( a->isChecked() != theOn )
1188     a->setChecked( theOn );
1189 }
1190
1191 /*!
1192   Switch preselection mode.
1193   \param theMode the preselection mode
1194 */
1195 void SVTK_ViewWindow::onSwitchPreSelectionMode( int theMode )
1196 {
1197   GetSelector()->SetDynamicPreSelection( theMode == Dynamic_Preselection );
1198   GetSelector()->SetPreSelectionEnabled( theMode != Preselection_Disabled );
1199
1200   // update action state if method is called outside
1201   QtxAction* a = getAction( StandardPreselectionId + theMode );
1202   if ( a && !a->isChecked() )
1203     a->setChecked( true );
1204 }
1205
1206 /*!
1207   Enables/disables selection.
1208   \param theOn if true - selection will be enabled
1209 */
1210 void SVTK_ViewWindow::onEnableSelection( bool on )
1211 {
1212   SVTK_Viewer* aViewer = dynamic_cast<SVTK_Viewer*>(myModel);
1213   if(aViewer)
1214     aViewer->enableSelection(on);  
1215 }
1216
1217 /*!
1218   Sets incremental speed
1219   \param theValue - new incremental speed
1220   \param theMode - modification mode
1221 */
1222 void SVTK_ViewWindow::SetIncrementalSpeed(const int theValue, const int theMode)
1223 {
1224   if ( (SVTK_InteractorStyle*)GetInteractorStyle() )
1225     ((SVTK_InteractorStyle*)GetInteractorStyle())->SetIncrementSpeed(theValue, theMode);
1226 }
1227
1228 /*!
1229   Sets spacemouse buttons for the functions
1230   \param theBtn1 - spacemouse button for the "decrease speed increment"
1231   \param theBtn2 - spacemouse button for the "increase speed increment"
1232   \param theBtn3 - spacemouse button for the "dominant combined switch"
1233 */
1234 void SVTK_ViewWindow::SetSpacemouseButtons(const int theBtn1, 
1235                                            const int theBtn2,
1236                                            const int theBtn3)
1237 {
1238   int val = theBtn1;
1239   myEventDispatcher->InvokeEvent(SVTK::SetSMDecreaseSpeedEvent, &val);
1240   val = theBtn2;
1241   myEventDispatcher->InvokeEvent(SVTK::SetSMIncreaseSpeedEvent, &val);
1242   val = theBtn3;
1243   myEventDispatcher->InvokeEvent(SVTK::SetSMDominantCombinedSwitchEvent, &val);
1244 }
1245
1246 /*!
1247   Sets trihedron size
1248   \param theSize - new trihedron size
1249   \param theRelative - trihedron relativeness
1250 */
1251 void SVTK_ViewWindow::SetTrihedronSize(const double theSize, const bool theRelative)
1252 {
1253   GetRenderer()->SetTrihedronSize(theSize, theRelative);
1254   Repaint();
1255 }
1256
1257 /*! If parameter theIsForcedUpdate is true, recalculate parameters for
1258  *  trihedron and cube axes, even if trihedron and cube axes is invisible.
1259  */
1260 void SVTK_ViewWindow::AdjustTrihedrons(const bool /*theIsForcedUpdate*/)
1261 {
1262   GetRenderer()->AdjustActors();
1263   Repaint();
1264 }
1265
1266 /*!
1267   Redirect the request to #SVTK_Renderer::OnAdjustTrihedron
1268 */
1269 void SVTK_ViewWindow::onAdjustTrihedron()
1270 {   
1271   GetRenderer()->OnAdjustTrihedron();
1272 }
1273
1274 /*!
1275   Redirect the request to #SVTK_Renderer::OnAdjustCubeAxes
1276 */
1277 void SVTK_ViewWindow::onAdjustCubeAxes()
1278 {   
1279   GetRenderer()->OnAdjustCubeAxes();
1280 }
1281
1282 void SVTK_ViewWindow::synchronize(SVTK_ViewWindow* otherViewWindow )
1283 {
1284   if ( otherViewWindow ) {
1285     bool blocked = blockSignals( true );
1286     doSetVisualParameters( otherViewWindow->getVisualParameters(), true );
1287     blockSignals( blocked );
1288   }
1289 }
1290
1291 /*!
1292   Emits key pressed
1293 */
1294 void SVTK_ViewWindow::onKeyPressed(QKeyEvent* event)
1295 {
1296   emit keyPressed( this, event );
1297 }
1298
1299 /*!
1300   Emits key released
1301 */
1302 void SVTK_ViewWindow::onKeyReleased(QKeyEvent* event)
1303 {
1304   emit keyReleased( this, event );
1305 }
1306
1307 /*!
1308   Emits mouse pressed
1309 */
1310 void SVTK_ViewWindow::onMousePressed(QMouseEvent* event)
1311 {
1312   emit mousePressed(this, event);
1313 }
1314
1315 /*!
1316   Emits mouse released
1317 */
1318 void SVTK_ViewWindow::onMouseReleased(QMouseEvent* event)
1319 {
1320   emit mouseReleased( this, event );
1321 }
1322
1323 /*!
1324   Emits mouse moving
1325 */
1326 void SVTK_ViewWindow::onMouseMoving(QMouseEvent* event)
1327 {
1328   emit mouseMoving( this, event );
1329 }
1330
1331 /*!
1332   Emits mouse double clicked
1333 */
1334 void SVTK_ViewWindow::onMouseDoubleClicked( QMouseEvent* event )
1335 {
1336   emit mouseDoubleClicked( this, event );
1337 }
1338
1339 /*!
1340   Redirect the request to #SVTK_Renderer::AddActor
1341 */
1342 void SVTK_ViewWindow::AddActor( VTKViewer_Actor* theActor, 
1343                                 bool theUpdate,
1344                                 bool theIsAdjustActors )
1345 {
1346   GetRenderer()->AddActor(theActor, theIsAdjustActors);
1347   if(theUpdate) 
1348     Repaint();
1349   emit actorAdded(theActor);
1350 }
1351
1352 /*!
1353   Redirect the request to #SVTK_Renderer::RemoveActor
1354 */
1355 void SVTK_ViewWindow::RemoveActor( VTKViewer_Actor* theActor, 
1356                                    bool theUpdate,
1357                                    bool theIsAdjustActors )
1358 {
1359   GetRenderer()->RemoveActor(theActor, theIsAdjustActors);
1360   if ( myDefaultInteractorStyle )
1361     myDefaultInteractorStyle->FreeActors();
1362   if ( myKeyFreeInteractorStyle )
1363     myKeyFreeInteractorStyle->FreeActors();
1364   if(theUpdate) 
1365     Repaint();
1366   emit actorRemoved(theActor);
1367 }
1368
1369 QImage SVTK_ViewWindow::dumpViewContent()
1370 {
1371   vtkRenderWindow* aWindow = getRenderWindow();
1372   int* aSize = aWindow->GetSize();
1373   int aWidth = aSize[0];
1374   int aHeight = aSize[1];
1375   
1376 #ifndef DISABLE_GLVIEWER
1377   OpenGLUtils_FrameBuffer aFrameBuffer;
1378   if( aFrameBuffer.init( aWidth, aHeight ) )
1379   {
1380     glPushAttrib( GL_VIEWPORT_BIT );
1381     glViewport( 0, 0, aWidth, aHeight );
1382     aFrameBuffer.bind();
1383
1384     // draw scene
1385     aWindow->Render();
1386    
1387     //aFrameBuffer.unbind();
1388     glPopAttrib();
1389
1390     QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
1391     //aFrameBuffer.bind();
1392
1393     glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
1394     aFrameBuffer.unbind();
1395
1396     anImage = anImage.rgbSwapped();
1397     anImage = anImage.mirrored();
1398     return anImage;
1399   }
1400 #endif
1401
1402   // if frame buffers are unsupported, use old functionality
1403   unsigned char *aData = 
1404     aWindow->GetRGBACharPixelData( 0, 0, aWidth-1, aHeight-1, 0 );
1405   
1406   QImage anImage( aData, aWidth, aHeight, QImage::Format_ARGB32 );
1407
1408   anImage = anImage.rgbSwapped();
1409   anImage = anImage.mirrored();
1410   return anImage;
1411 }
1412
1413 /*!
1414   \return QImage, containing all scene rendering in window
1415 */
1416 QImage SVTK_ViewWindow::dumpView()
1417 {
1418   if( myDumpImage.isNull() )
1419     return dumpViewContent();
1420   
1421   RefreshDumpImage();
1422   return myDumpImage;
1423 }
1424
1425 QString SVTK_ViewWindow::filter() const
1426 {
1427   return tr( "SVTK_IMAGE_FILES" );
1428 }
1429
1430 bool SVTK_ViewWindow::dumpViewToFormat( const QImage& img, const QString& fileName, const QString& format )
1431 {
1432   if ( format != "PS" && format != "EPS" && format != "PDF" )
1433     return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
1434
1435   SVTK_PsOptionsDlg* optionsDlg = new SVTK_PsOptionsDlg(this);
1436   if ( optionsDlg->exec() == QDialog::Accepted ) {
1437     SUIT_OverrideCursor wc;
1438
1439     vtkGL2PSExporter *anExporter = vtkGL2PSExporter::New();
1440     anExporter->SetRenderWindow(getRenderWindow());
1441
1442     // Set options
1443     anExporter->SetLineWidthFactor(optionsDlg->getLineFactor());
1444     anExporter->SetPointSizeFactor(optionsDlg->getPointFactor());
1445     anExporter->SetSort((vtkGL2PSExporter::SortScheme)optionsDlg->getSortType());
1446     anExporter->SetWrite3DPropsAsRasterImage((int)optionsDlg->isRasterize3D());
1447     anExporter->SetPS3Shading((int)optionsDlg->isPs3Shading());
1448     
1449     if ( format == "PS" ) {
1450       anExporter->SetFileFormatToPS();
1451       anExporter->CompressOff();
1452     }
1453     
1454     if ( format == "EPS" ) {
1455       anExporter->SetFileFormatToEPS();
1456       anExporter->CompressOff();
1457     }
1458
1459     if ( format == "PDF" ) {
1460       anExporter->SetFileFormatToPDF();
1461     }
1462     
1463     QString aFilePrefix(fileName);
1464     QString anExtension(SUIT_Tools::extension(fileName));
1465     aFilePrefix.truncate(aFilePrefix.length() - 1 - anExtension.length());
1466     anExporter->SetFilePrefix(aFilePrefix.toUtf8().data());
1467     anExporter->Write();
1468     anExporter->Delete();
1469   }
1470   delete optionsDlg;
1471   return true;  
1472 }
1473
1474 /*!
1475   \refresh QImage, containing all scene rendering in window
1476 */
1477 void SVTK_ViewWindow::RefreshDumpImage()
1478 {
1479   myDumpImage = dumpViewContent();
1480 }
1481
1482 /*!
1483   Redirect the request to #SVTK_Renderer::SetSelectionProp
1484 */
1485 void SVTK_ViewWindow::SetSelectionProp(const double& theRed, 
1486                                        const double& theGreen, 
1487                                        const double& theBlue, 
1488                                        const int& theWidth) 
1489 {
1490   myView->SetSelectionProp(theRed,theGreen,theBlue,theWidth);
1491 }
1492
1493 /*!
1494   Redirect the request to #SVTK_Renderer::SetSelectionProp
1495 */
1496 void SVTK_ViewWindow::SetPreselectionProp(const double& theRed, 
1497                                           const double& theGreen, 
1498                                           const double& theBlue, 
1499                                           const int& theWidth) 
1500 {
1501   myView->SetPreselectionProp(theRed,theGreen,theBlue,theWidth);
1502 }
1503
1504 /*!
1505   Redirect the request to #SVTK_Renderer::SetSelectionTolerance
1506 */
1507 void SVTK_ViewWindow::SetSelectionTolerance(const double& theTolNodes, 
1508                                             const double& theTolItems,
1509                                             const double& theTolObjects)
1510 {
1511   myView->SetSelectionTolerance(theTolNodes, theTolItems, theTolObjects);
1512 }
1513
1514 /*!
1515   Get visibility status of the static trihedron
1516 */
1517 bool SVTK_ViewWindow::IsStaticTrihedronVisible() const
1518 {
1519   return (bool)myAxesWidget->GetEnabled();
1520 }
1521
1522 /*!
1523   Set visibility status of the static trihedron
1524 */
1525 void SVTK_ViewWindow::SetStaticTrihedronVisible( const bool theIsVisible )
1526 {
1527   myAxesWidget->SetEnabled( (int)theIsVisible );
1528 }
1529
1530 /*!
1531   Performs action
1532   \param accelAction - action
1533 */
1534 bool SVTK_ViewWindow::action( const int accelAction  )
1535 {
1536   if ( accelAction == SUIT_Accel::ZoomFit )
1537     onFitAll();
1538   else {
1539     int anEvent = SVTK::convertAction( accelAction );
1540     GetInteractor()->InvokeEvent(anEvent, 0);
1541   }
1542   return true;
1543 }
1544
1545 /*!
1546   \return action by it's id
1547 */
1548 QtxAction* SVTK_ViewWindow::getAction( int id ) const
1549 {
1550   return dynamic_cast<QtxAction*>( toolMgr()->action( id ) );
1551 }
1552
1553
1554 // old visual parameters had 13 values.  New format added additional 
1555 // 76 values for graduated axes, so both numbers are processed.
1556 const int nNormalParams = 13;   // number of view windows parameters excluding graduated axes params
1557 const int nGradAxisParams = 25; // number of parameters of ONE graduated axis (X, Y, or Z)
1558 const int nTrihedronParams = 3; // number of parameters for Trihedron
1559 const int nAllParams = nNormalParams + 3*nGradAxisParams + nTrihedronParams + 1; // number of all visual parameters
1560
1561 /*! The method returns visual parameters of a graduated axis actor (x,y,z axis of graduated axes)
1562  */
1563 void getGradAxisVisualParams( QXmlStreamWriter& writer, vtkAxisActor2D* actor, QString theAxis )
1564 {
1565   //QString params;
1566   if ( !actor )
1567     return ;//params;
1568
1569   // Name
1570   bool isVisible = actor->GetTitleVisibility();
1571   QString title ( actor->GetTitle() );
1572   double color[ 3 ];
1573   int font = VTK_ARIAL;
1574   int bold = 0;
1575   int italic = 0;
1576   int shadow = 0;
1577
1578   vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1579   if ( txtProp )
1580   {
1581     txtProp->GetColor( color );
1582     font = txtProp->GetFontFamily();
1583     bold = txtProp->GetBold();
1584     italic = txtProp->GetItalic();
1585     shadow = txtProp->GetShadow();
1586   }
1587   writer.writeStartElement("GraduatedAxis");
1588   writer.writeAttribute("Axis", theAxis);
1589
1590   writer.writeStartElement("Title");
1591   writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1592   writer.writeAttribute("Text", title);
1593   writer.writeAttribute("Font", QString("%1").arg(font));
1594   writer.writeAttribute("Bold", QString("%1").arg(bold));
1595   writer.writeAttribute("Italic", QString("%1").arg(italic));
1596   writer.writeAttribute("Shadow", QString("%1").arg(shadow));
1597
1598   writer.writeStartElement("Color");
1599   writer.writeAttribute("R", QString("%1").arg(color[0]));
1600   writer.writeAttribute("G", QString("%1").arg(color[1]));
1601   writer.writeAttribute("B", QString("%1").arg(color[2]));
1602   writer.writeEndElement();
1603   writer.writeEndElement();
1604
1605   //params.sprintf( "* Graduated Axis: * Name *%u*%s*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible, 
1606   //              title.toLatin1().data(), color[0], color[1], color[2], font, bold, italic, shadow );
1607
1608   // Labels
1609   isVisible = actor->GetLabelVisibility();
1610   int labels = actor->GetNumberOfLabels();
1611   int offset = actor->GetTickOffset();
1612   font = VTK_ARIAL;
1613   bold = false;
1614   italic = false;
1615   shadow = false;
1616
1617   txtProp = actor->GetLabelTextProperty();
1618   if ( txtProp )
1619   {
1620     txtProp->GetColor( color );
1621     font = txtProp->GetFontFamily();
1622     bold = txtProp->GetBold();
1623     italic = txtProp->GetItalic();
1624     shadow = txtProp->GetShadow();
1625   }
1626
1627   writer.writeStartElement("Labels");
1628   writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1629   writer.writeAttribute("Number", QString("%1").arg(labels));
1630   writer.writeAttribute("Offset", QString("%1").arg(offset));
1631   writer.writeAttribute("Font", QString("%1").arg(font));
1632   writer.writeAttribute("Bold", QString("%1").arg(bold));
1633   writer.writeAttribute("Italic", QString("%1").arg(italic));
1634   writer.writeAttribute("Shadow", QString("%1").arg(shadow));
1635
1636   writer.writeStartElement("Color");
1637   writer.writeAttribute("R", QString("%1").arg(color[0]));
1638   writer.writeAttribute("G", QString("%1").arg(color[1]));
1639   writer.writeAttribute("B", QString("%1").arg(color[2]));
1640   writer.writeEndElement();
1641   writer.writeEndElement();
1642   //  params += QString().sprintf( "* Labels *%u*%u*%u*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible, labels, offset,  
1643   //                           color[0], color[1], color[2], font, bold, italic, shadow );
1644
1645   // Tick marks
1646   isVisible = actor->GetTickVisibility();
1647   int length = actor->GetTickLength();
1648   writer.writeStartElement("TickMarks");
1649   writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1650   writer.writeAttribute("Length", QString("%1").arg(length));
1651   writer.writeEndElement();
1652   
1653   //params += QString().sprintf( "* Tick marks *%u*%u", isVisible, length );
1654   
1655   writer.writeEndElement();
1656   //return params;
1657 }
1658
1659 void setGradAxisVisualParams(QXmlStreamReader& reader, vtkAxisActor2D* actor)
1660 {
1661   if ( !actor )
1662     return;
1663
1664   do {
1665     reader.readNext();
1666   } while (!reader.isStartElement());
1667
1668   // Read title params
1669   QXmlStreamAttributes aAttr = reader.attributes();
1670   bool isVisible = aAttr.value("isVisible").toString().toUShort();
1671   QString title = aAttr.value("Text").toString();
1672   int font = aAttr.value("Font").toString().toInt();
1673   int bold = aAttr.value("Bold").toString().toInt();
1674   int italic = aAttr.value("Italic").toString().toInt();
1675   int shadow = aAttr.value("Shadow").toString().toInt();
1676
1677   //printf("#### TITLE: %i, %s, %i, %i, %i, %i\n", isVisible, qPrintable(title), font, bold, italic, shadow);
1678
1679   do {
1680     reader.readNext();
1681   } while (!reader.isStartElement());
1682   
1683   // Read title color
1684   aAttr = reader.attributes();
1685
1686   double color[3];
1687   color[0] = aAttr.value("R").toString().toDouble();
1688   color[1] = aAttr.value("G").toString().toDouble();
1689   color[2] = aAttr.value("B").toString().toDouble();
1690   //printf("#### Color: %f, %f, %f\n", color[0], color[1], color[2]);
1691
1692   actor->SetTitleVisibility( isVisible );
1693   actor->SetTitle( title.toUtf8() );
1694   vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1695   if ( txtProp ) {
1696     txtProp->SetColor( color );
1697     txtProp->SetFontFamily( font );
1698     txtProp->SetBold( bold );
1699     txtProp->SetItalic( italic );
1700     txtProp->SetShadow( shadow );
1701   }
1702
1703   // Labels
1704
1705   do {
1706     reader.readNext();
1707   } while (!reader.isStartElement()); 
1708   // Read labels
1709   aAttr = reader.attributes();
1710   isVisible = aAttr.value("isVisible").toString().toUShort();
1711   int labels = aAttr.value("Number").toString().toInt();
1712   int offset = aAttr.value("Offset").toString().toInt();
1713   font = aAttr.value("Font").toString().toInt();
1714   bold = aAttr.value("Bold").toString().toInt();
1715   italic = aAttr.value("Italic").toString().toInt();
1716   shadow = aAttr.value("Shadow").toString().toInt();
1717
1718   do {
1719     reader.readNext();
1720   } while (!reader.isStartElement()); 
1721   // Read Color
1722   aAttr = reader.attributes();
1723
1724   color[0] = aAttr.value("R").toString().toDouble();
1725   color[1] = aAttr.value("G").toString().toDouble();
1726   color[2] = aAttr.value("B").toString().toDouble();
1727
1728   actor->SetLabelVisibility( isVisible );
1729   actor->SetNumberOfLabels( labels );
1730   actor->SetTickOffset( offset );
1731   txtProp = actor->GetLabelTextProperty();
1732   if ( txtProp ) {
1733     txtProp->SetColor( color );
1734     txtProp->SetFontFamily( font );
1735     txtProp->SetBold( bold );
1736     txtProp->SetItalic( italic );
1737     txtProp->SetShadow( shadow );
1738   }
1739
1740   // Tick Marks
1741   do {
1742     reader.readNext();
1743   } while (!reader.isStartElement()); 
1744   aAttr = reader.attributes();
1745
1746   // retrieve and set tick marks properties
1747   isVisible = aAttr.value("isVisible").toString().toUShort();
1748   int length = aAttr.value("Length").toString().toInt();
1749   
1750   actor->SetTickVisibility( isVisible );
1751   actor->SetTickLength( length );
1752 }
1753
1754 /*! The method restores visual parameters of a graduated axis actor (x,y,z axis)
1755  */
1756 void setGradAxisVisualParams( vtkAxisActor2D* actor, const QString& params )
1757 {
1758   if ( !actor )
1759     return;
1760
1761   QStringList paramsLst = params.split( '*' );
1762
1763   if ( paramsLst.size() == nGradAxisParams ) { // altogether name, lable, ticks parameters make up 25 values
1764
1765     // retrieve and set name parameters
1766     bool isVisible = paramsLst[2].toUShort();
1767     QString title = paramsLst[3];
1768     double color[3];
1769     color[0] = paramsLst[4].toDouble();
1770     color[1] = paramsLst[5].toDouble();
1771     color[2] = paramsLst[6].toDouble();
1772     int font = paramsLst[7].toInt();
1773     int bold = paramsLst[8].toInt();
1774     int italic = paramsLst[9].toInt();
1775     int shadow = paramsLst[10].toInt();
1776
1777     actor->SetTitleVisibility( isVisible );
1778     actor->SetTitle( title.toUtf8() );
1779     vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1780     if ( txtProp ) {
1781       txtProp->SetColor( color );
1782       txtProp->SetFontFamily( font );
1783       txtProp->SetBold( bold );
1784       txtProp->SetItalic( italic );
1785       txtProp->SetShadow( shadow );
1786     }
1787
1788     // retrieve and set lable parameters
1789     isVisible = paramsLst[12].toUShort();
1790     int labels = paramsLst[13].toInt();
1791     int offset = paramsLst[14].toInt();
1792     color[0] = paramsLst[15].toDouble();
1793     color[1] = paramsLst[16].toDouble();
1794     color[2] = paramsLst[17].toDouble();
1795     font = paramsLst[18].toInt();
1796     bold = paramsLst[19].toInt();
1797     italic = paramsLst[20].toInt();
1798     shadow = paramsLst[21].toInt();
1799
1800     actor->SetLabelVisibility( isVisible );
1801     actor->SetNumberOfLabels( labels );
1802     actor->SetTickOffset( offset );
1803     txtProp = actor->GetLabelTextProperty();
1804     if ( txtProp ) {
1805       txtProp->SetColor( color );
1806       txtProp->SetFontFamily( font );
1807       txtProp->SetBold( bold );
1808       txtProp->SetItalic( italic );
1809       txtProp->SetShadow( shadow );
1810     }
1811
1812     // retrieve and set tick marks properties
1813     isVisible = paramsLst[23].toUShort();
1814     int length = paramsLst[24].toInt();
1815
1816     actor->SetTickVisibility( isVisible );
1817     actor->SetTickLength( length );
1818   }
1819 }
1820
1821 /*! The method returns the visual parameters of this view as a formated string
1822  */
1823 QString SVTK_ViewWindow::getVisualParameters()
1824 {
1825   double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
1826   
1827   // save position, focal point, viewUp, scale
1828   vtkCamera* camera = getRenderer()->GetActiveCamera();
1829   camera->GetPosition( pos );
1830   camera->GetFocalPoint( focalPnt );
1831   camera->GetViewUp( viewUp );
1832   parScale = camera->GetParallelScale();
1833   GetScale( scale );
1834
1835   // Parameters are given in the following format:view position (3 digits), focal point position (3 digits)
1836   // view up values (3 digits), parallel scale (1 digit), scale (3 digits, 
1837   // Graduated axes parameters (X, Y, Z axes parameters)
1838   QString retStr;
1839   QXmlStreamWriter aWriter(&retStr);
1840   aWriter.setAutoFormatting(true);
1841
1842   aWriter.writeStartDocument();
1843   aWriter.writeStartElement("ViewState");
1844
1845   aWriter.writeStartElement("Position");
1846   aWriter.writeAttribute("X", QString("%1").arg(pos[0]));
1847   aWriter.writeAttribute("Y", QString("%1").arg(pos[1]));
1848   aWriter.writeAttribute("Z", QString("%1").arg(pos[2]));
1849   aWriter.writeEndElement();
1850
1851   aWriter.writeStartElement("FocalPoint");
1852   aWriter.writeAttribute("X", QString::number(focalPnt[0]));
1853   aWriter.writeAttribute("Y", QString::number(focalPnt[1]));
1854   aWriter.writeAttribute("Z", QString::number(focalPnt[2]));
1855   aWriter.writeEndElement();
1856
1857   aWriter.writeStartElement("ViewUp");
1858   aWriter.writeAttribute("X", QString::number(viewUp[0]));
1859   aWriter.writeAttribute("Y", QString::number(viewUp[1]));
1860   aWriter.writeAttribute("Z", QString::number(viewUp[2]));
1861   aWriter.writeEndElement();
1862
1863   aWriter.writeStartElement("ViewScale");
1864   aWriter.writeAttribute("Parallel", QString::number(parScale));
1865   aWriter.writeAttribute("X", QString::number(scale[0]));
1866   aWriter.writeAttribute("Y", QString::number(scale[1]));
1867   aWriter.writeAttribute("Z", QString::number(scale[2]));
1868   aWriter.writeEndElement();
1869
1870   if ( SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes() ) {
1871     aWriter.writeStartElement("DisplayCubeAxis");
1872     aWriter.writeAttribute("Show", QString( "%1" ).arg( GetRenderer()->IsCubeAxesDisplayed()));
1873     aWriter.writeEndElement();
1874
1875     getGradAxisVisualParams(aWriter, gradAxesActor->GetXAxisActor2D(), "X");
1876     getGradAxisVisualParams(aWriter, gradAxesActor->GetYAxisActor2D(), "Y");
1877     getGradAxisVisualParams(aWriter, gradAxesActor->GetZAxisActor2D(), "Z");
1878   }
1879
1880   aWriter.writeStartElement("Trihedron");
1881   aWriter.writeAttribute("isShown",  QString( "%1" ).arg( isTrihedronDisplayed()));
1882   aWriter.writeAttribute("Size", QString::number(GetTrihedronSize()));
1883   aWriter.writeEndElement();
1884
1885   aWriter.writeStartElement("Background");
1886   aWriter.writeAttribute("Value",  QString( "%1" ).arg( Qtx::backgroundToString(background()) ));
1887   aWriter.writeEndElement();
1888
1889   aWriter.writeEndElement();
1890   aWriter.writeEndDocument();
1891
1892   return retStr;
1893 }
1894
1895 /*!
1896   The method restores visual parameters of this view or postpones it untill the view is shown
1897 */ 
1898 void SVTK_ViewWindow::setVisualParameters( const QString& parameters )
1899 {
1900   //printf("#### %s\n", qPrintable(parameters));
1901   SVTK_RenderWindowInteractor* anInteractor = GetInteractor();
1902   if ( anInteractor->isVisible() ) {
1903     doSetVisualParameters( parameters ); 
1904   }
1905   else {
1906     myVisualParams = parameters;
1907     anInteractor->installEventFilter(this);
1908   }
1909 }
1910
1911 /*!
1912   The method restores visual parameters of this view from a formated string
1913 */
1914 void SVTK_ViewWindow::doSetVisualParameters( const QString& parameters, bool baseParamsOnly )
1915 {
1916
1917   double pos[3], focalPnt[3], viewUp[3], parScale = 1.0, scale[3];
1918
1919   QXmlStreamReader aReader(parameters);
1920   SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes();
1921
1922   while(!aReader.atEnd()) {
1923     aReader.readNext();
1924     if (aReader.isStartElement()) {
1925       QXmlStreamAttributes aAttr = aReader.attributes();
1926       //printf("### Name = %s\n", qPrintable(aReader.name().toString()));
1927       if (aReader.name() == "Position") {
1928         pos[0] = aAttr.value("X").toString().toDouble();
1929         pos[1] = aAttr.value("Y").toString().toDouble();
1930         pos[2] = aAttr.value("Z").toString().toDouble();
1931         //printf("#### Position %f; %f; %f\n", pos[0], pos[1], pos[2]);
1932       }
1933       else if (aReader.name() == "FocalPoint") {
1934         focalPnt[0] = aAttr.value("X").toString().toDouble();
1935         focalPnt[1] = aAttr.value("Y").toString().toDouble();
1936         focalPnt[2] = aAttr.value("Z").toString().toDouble();
1937         //printf("#### FocalPoint %f; %f; %f\n", focalPnt[0], focalPnt[1], focalPnt[2]);
1938       }
1939       else if (aReader.name() == "ViewUp") {
1940         viewUp[0] = aAttr.value("X").toString().toDouble();
1941         viewUp[1] = aAttr.value("Y").toString().toDouble();
1942         viewUp[2] = aAttr.value("Z").toString().toDouble();
1943         //printf("#### ViewUp %f; %f; %f\n", viewUp[0], viewUp[1], viewUp[2]);
1944       }
1945       else if (aReader.name() == "ViewScale") {
1946         parScale = aAttr.value("Parallel").toString().toDouble();
1947         scale[0] = aAttr.value("X").toString().toDouble();
1948         scale[1] = aAttr.value("Y").toString().toDouble();
1949         scale[2] = aAttr.value("Z").toString().toDouble();
1950         //printf("#### ViewScale %f; %f; %f\n", scale[0], scale[1], scale[2]);
1951       }
1952       else if (aReader.name() == "DisplayCubeAxis") {
1953         if ( !baseParamsOnly ) {
1954           if (aAttr.value("Show") == "0")
1955             gradAxesActor->VisibilityOff();
1956           else
1957             gradAxesActor->VisibilityOn();
1958         }
1959       }
1960       else if (aReader.name() == "GraduatedAxis") {
1961         if ( !baseParamsOnly ) {
1962           if(aAttr.value("Axis") == "X")
1963             setGradAxisVisualParams(aReader, gradAxesActor->GetXAxisActor2D());
1964           else if(aAttr.value("Axis") == "Y")
1965             setGradAxisVisualParams(aReader, gradAxesActor->GetYAxisActor2D());
1966           else if(aAttr.value("Axis") == "Z")
1967             setGradAxisVisualParams(aReader, gradAxesActor->GetZAxisActor2D());
1968         }
1969       }
1970       else if (aReader.name() == "Trihedron") {
1971         if ( !baseParamsOnly ) {
1972           if (aAttr.value("isShown") == "0")
1973             GetTrihedron()->VisibilityOff();
1974           else
1975             GetTrihedron()->VisibilityOn();
1976           SetTrihedronSize(aAttr.value("Size").toString().toDouble());
1977         }
1978       }
1979       else if (aReader.name() == "Background") {
1980         if ( !baseParamsOnly ) {
1981           setBackground( Qtx::stringToBackground( aAttr.value("Value").toString() ) );
1982         }
1983       }
1984     }
1985   }
1986   if (!aReader.hasError()) {
1987     vtkCamera* camera = getRenderer()->GetActiveCamera();
1988     camera->SetPosition( pos );
1989     camera->SetFocalPoint( focalPnt );
1990     camera->SetViewUp( viewUp );
1991     camera->SetParallelScale( parScale );
1992     GetRenderer()->SetScale( scale );
1993     //SetScale( scale );
1994   }
1995   else {
1996     QStringList paramsLst = parameters.split( '*' );
1997     if ( paramsLst.size() >= nNormalParams ) {
1998       // 'reading' list of parameters
1999       pos[0] = paramsLst[0].toDouble();
2000       pos[1] = paramsLst[1].toDouble();
2001       pos[2] = paramsLst[2].toDouble();
2002       focalPnt[0] = paramsLst[3].toDouble();
2003       focalPnt[1] = paramsLst[4].toDouble();
2004       focalPnt[2] = paramsLst[5].toDouble();
2005       viewUp[0] = paramsLst[6].toDouble();
2006       viewUp[1] = paramsLst[7].toDouble();
2007       viewUp[2] = paramsLst[8].toDouble();
2008       parScale = paramsLst[9].toDouble();
2009       scale[0] = paramsLst[10].toDouble();
2010       scale[1] = paramsLst[11].toDouble();
2011       scale[2] = paramsLst[12].toDouble();
2012
2013       // applying parameters
2014       vtkCamera* camera = getRenderer()->GetActiveCamera();
2015       camera->SetPosition( pos );
2016       camera->SetFocalPoint( focalPnt );
2017       camera->SetViewUp( viewUp );
2018       camera->SetParallelScale( parScale );
2019       GetRenderer()->SetScale( scale );
2020       //SetScale( scale );
2021
2022       // apply graduated axes parameters
2023       if ( !baseParamsOnly ) {
2024         SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes();
2025         if ( gradAxesActor && paramsLst.size() == nAllParams ) {
2026           int i = nNormalParams+1, j = i + nGradAxisParams - 1;
2027           ::setGradAxisVisualParams( gradAxesActor->GetXAxisActor2D(), parameters.section( '*', i, j ) );
2028           i = j + 1; j += nGradAxisParams;
2029           ::setGradAxisVisualParams( gradAxesActor->GetYAxisActor2D(), parameters.section( '*', i, j ) );
2030           i = j + 1; j += nGradAxisParams;
2031           ::setGradAxisVisualParams( gradAxesActor->GetZAxisActor2D(), parameters.section( '*', i, j ) );
2032
2033           if ( paramsLst[13].toUShort() )
2034             gradAxesActor->VisibilityOn();
2035           else
2036             gradAxesActor->VisibilityOff();
2037         }
2038         else if ( paramsLst.size() == nAllParams ) {
2039           if ( paramsLst[90].toUShort() )
2040             GetTrihedron()->VisibilityOn();
2041           else
2042             GetTrihedron()->VisibilityOff();
2043
2044           SetTrihedronSize(paramsLst[91].toDouble());
2045         }
2046       }
2047     }
2048   }
2049   Repaint();
2050 }
2051
2052
2053 /*!
2054   Delayed setVisualParameters
2055 */
2056 bool SVTK_ViewWindow::eventFilter( QObject* theWatched, QEvent* theEvent )
2057 {
2058   if ( theEvent->type() == QEvent::Show && theWatched->inherits( "SVTK_RenderWindowInteractor" ) ) {
2059     SVTK_RenderWindowInteractor* anInteractor = (SVTK_RenderWindowInteractor*)theWatched;
2060     if ( anInteractor->isVisible() ) {
2061       doSetVisualParameters( myVisualParams );
2062       anInteractor->removeEventFilter( this ); // theWatched = RenderWindowInteractor
2063     }
2064   }
2065   return SUIT_ViewWindow::eventFilter( theWatched, theEvent );
2066 }
2067
2068
2069 /*!
2070   Change rotation point
2071 */
2072 void SVTK_ViewWindow::onChangeRotationPoint(bool theIsActivate)
2073 {
2074   if(theIsActivate){
2075     mySetRotationPointDlg->addObserver();
2076     if ( mySetRotationPointDlg->IsFirstShown() )
2077       activateSetRotationGravity();
2078     mySetRotationPointDlg->show();
2079   }else
2080     mySetRotationPointDlg->hide();
2081 }
2082
2083 /*!
2084   Set the gravity center as a rotation point
2085 */
2086 void SVTK_ViewWindow::activateSetRotationGravity()
2087 {
2088   myEventDispatcher->InvokeEvent(SVTK::SetRotateGravity,0);
2089 }
2090
2091 /*!
2092   Set the selected point as a rotation point
2093 */
2094 void SVTK_ViewWindow::activateSetRotationSelected(void* theData)
2095 {
2096   myEventDispatcher->InvokeEvent(SVTK::ChangeRotationPoint,theData);
2097 }
2098
2099 /*!
2100   Set the gravity center of element selected by user as a rotation point
2101 */
2102 void SVTK_ViewWindow::activateStartPointSelection( Selection_Mode theSelectionMode )
2103 {
2104   SetSelectionMode( theSelectionMode );
2105   myEventDispatcher->InvokeEvent(SVTK::StartPointSelection,0);
2106 }
2107
2108 /*!
2109   \brief Set the given projection mode.
2110
2111   Set the given projection mode: Orthographic or Perspective.
2112 */
2113 void SVTK_ViewWindow::onProjectionMode( QAction* theAction )
2114 {
2115   int aMode = Parallel;
2116   if (theAction == toolMgr()->action( ProjectionModeId ))
2117     aMode = Projection;
2118   SVTK_Viewer* aViewer = dynamic_cast<SVTK_Viewer*>(myModel);
2119   aViewer->setProjectionMode(aMode);
2120   bool anIsParallelMode = (aMode == Parallel);
2121   vtkCamera* aCamera = getRenderer()->GetActiveCamera();
2122   aCamera->SetParallelProjection(anIsParallelMode);
2123   GetInteractor()->GetDevice()->CreateTimer(VTKI_TIMER_FIRST);
2124   getRenderWindow()->SetStereoRender(0);
2125   Repaint();
2126 }
2127
2128 /*!
2129   \brief Sets Stereo projection mode.
2130
2131   Sets Stereo projection mode.
2132 */
2133 void SVTK_ViewWindow::onStereoMode( bool activate )
2134 {
2135   if (activate) {
2136     toolMgr()->action( ProjectionModeId )->setChecked(true);
2137     vtkCamera* aCamera = getRenderer()->GetActiveCamera();
2138     aCamera->SetParallelProjection(false);
2139     toolMgr()->action( ProjectionModeId )->actionGroup()->setEnabled(false);
2140     SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
2141     SetStereoType( aResMgr->integerValue( "VTKViewer", "stereo_type", 0 ) );
2142     getRenderWindow()->SetStereoRender(1);
2143     Repaint();
2144   }
2145   else {
2146     toolMgr()->action( ProjectionModeId )->actionGroup()->setEnabled(true);
2147     SVTK_Viewer* aViewer = dynamic_cast<SVTK_Viewer*>(myModel);
2148     if (aViewer->projectionMode() == Parallel) {
2149       toolMgr()->action( ParallelModeId )->setChecked(true);
2150       onProjectionMode(toolMgr()->action( ParallelModeId ));
2151     }
2152     else if (aViewer->projectionMode() == Projection) {
2153       toolMgr()->action( ProjectionModeId )->setChecked(true);
2154       onProjectionMode(toolMgr()->action( ProjectionModeId ));
2155     }
2156   }
2157   if ( getRenderWindow()->GetStereoCapableWindow() == 1 && !isOpenGlStereoSupport() &&
2158        strcmp( "CrystalEyes", getRenderWindow()->GetStereoTypeAsString() ) == 0 &&
2159        toolMgr()->action( StereoModeId )->isChecked() )
2160     SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ),  tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
2161 }
2162
2163 /*!
2164   Set the view projection mode: orthogonal or perspective
2165 */
2166 void SVTK_ViewWindow::onProjectionMode()
2167 {
2168   if (toolMgr()->action( ParallelModeId )->isChecked())
2169     SetProjectionMode( Parallel);
2170   if (toolMgr()->action( ProjectionModeId )->isChecked())
2171     SetProjectionMode( Projection);
2172   if (toolMgr()->action( StereoModeId )->isChecked())
2173     SetProjectionMode( Stereo);
2174   emit transformed( this );
2175 }
2176
2177 void SVTK_ViewWindow::SetEventDispatcher(vtkObject* theDispatcher)
2178 {
2179   myEventDispatcher = theDispatcher;
2180 }
2181
2182 /*!
2183   Creates all actions of svtk main window
2184 */
2185 void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
2186 {
2187   QtxAction* anAction;
2188   QtxActionToolMgr* mgr = toolMgr();
2189
2190   // Dump view
2191   anAction = new QtxAction(tr("MNU_DUMP_VIEW"), 
2192                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
2193                            tr( "MNU_DUMP_VIEW" ), 0, this);
2194   anAction->setStatusTip(tr("DSC_DUMP_VIEW"));
2195   connect(anAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
2196   mgr->registerAction( anAction, DumpId );
2197
2198   // FitAll
2199   anAction = new QtxAction(tr("MNU_FITALL"), 
2200                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
2201                            tr( "MNU_FITALL" ), 0, this);
2202   anAction->setStatusTip(tr("DSC_FITALL"));
2203   connect(anAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
2204   mgr->registerAction( anAction, FitAllId );
2205
2206   // FitRect
2207   anAction = new QtxAction(tr("MNU_FITRECT"), 
2208                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
2209                            tr( "MNU_FITRECT" ), 0, this);
2210   anAction->setStatusTip(tr("DSC_FITRECT"));
2211   connect(anAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
2212   mgr->registerAction( anAction, FitRectId );
2213
2214   // FitSelection
2215   anAction = new QtxAction(tr("MNU_FITSELECTION"),
2216                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITSELECTION" ) ),
2217                            tr( "MNU_FITSELECTION" ), 0, this);
2218   anAction->setStatusTip(tr("DSC_FITSELECTION"));
2219   connect(anAction, SIGNAL(triggered()), this, SLOT(onFitSelection()));
2220   mgr->registerAction( anAction, FitSelectionId );
2221
2222   // Zoom
2223   anAction = new QtxAction(tr("MNU_ZOOM_VIEW"), 
2224                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
2225                            tr( "MNU_ZOOM_VIEW" ), 0, this);
2226   anAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
2227   connect(anAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
2228   mgr->registerAction( anAction, ZoomId );
2229
2230   // Panning
2231   anAction = new QtxAction(tr("MNU_PAN_VIEW"), 
2232                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
2233                            tr( "MNU_PAN_VIEW" ), 0, this);
2234   anAction->setStatusTip(tr("DSC_PAN_VIEW"));
2235   connect(anAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
2236   mgr->registerAction( anAction, PanId );
2237
2238   // Global Panning
2239   anAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), 
2240                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
2241                            tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
2242   anAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
2243   connect(anAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
2244   mgr->registerAction( anAction, GlobalPanId );
2245
2246   // Change rotation point
2247   anAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), 
2248                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_ROTATION_POINT" ) ),
2249                            tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
2250   anAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
2251   anAction->setCheckable(true);
2252   connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onChangeRotationPoint(bool)));
2253   mgr->registerAction( anAction, ChangeRotationPointId );
2254
2255   // Rotation
2256   anAction = new QtxAction(tr("MNU_ROTATE_VIEW"), 
2257                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
2258                            tr( "MNU_ROTATE_VIEW" ), 0, this);
2259   anAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
2260   connect(anAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
2261   mgr->registerAction( anAction, RotationId );
2262
2263   // Projections
2264   anAction = new QtxAction(tr("MNU_FRONT_VIEW"), 
2265                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
2266                            tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
2267   anAction->setStatusTip(tr("DSC_FRONT_VIEW"));
2268   connect(anAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
2269   this->addAction(anAction);
2270   mgr->registerAction( anAction, FrontId );
2271
2272   anAction = new QtxAction(tr("MNU_BACK_VIEW"),
2273                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
2274                            tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
2275   anAction->setStatusTip(tr("DSC_BACK_VIEW"));
2276   connect(anAction, SIGNAL(triggered()), this, SLOT(onBackView()));
2277   this->addAction(anAction);
2278   mgr->registerAction( anAction, BackId );
2279
2280   anAction = new QtxAction(tr("MNU_TOP_VIEW"),
2281                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
2282                            tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
2283   anAction->setStatusTip(tr("DSC_TOP_VIEW"));
2284   connect(anAction, SIGNAL(triggered()), this, SLOT(onTopView()));
2285   this->addAction(anAction);
2286   mgr->registerAction( anAction, TopId );
2287
2288   anAction = new QtxAction(tr("MNU_BOTTOM_VIEW"),
2289                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
2290                            tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
2291   anAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
2292   connect(anAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
2293   this->addAction(anAction);
2294   mgr->registerAction( anAction, BottomId );
2295
2296   anAction = new QtxAction(tr("MNU_LEFT_VIEW"),
2297                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
2298                            tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
2299   anAction->setStatusTip(tr("DSC_LEFT_VIEW"));
2300   connect(anAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
2301   this->addAction(anAction);
2302   mgr->registerAction( anAction, LeftId );
2303
2304   anAction = new QtxAction(tr("MNU_RIGHT_VIEW"),
2305                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
2306                            tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
2307   anAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
2308   connect(anAction, SIGNAL(triggered()), this, SLOT(onRightView()));
2309   this->addAction(anAction);
2310   mgr->registerAction( anAction, RightId );
2311
2312   // rotate anticlockwise
2313   anAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"),
2314                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ANTICLOCKWISE" ) ),
2315                            tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
2316   anAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
2317   connect(anAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
2318   this->addAction(anAction);
2319   mgr->registerAction( anAction, AntiClockWiseId );
2320
2321   // rotate clockwise
2322   anAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"),
2323                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_CLOCKWISE" ) ),
2324                            tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
2325   anAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
2326   connect(anAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
2327   this->addAction(anAction);
2328   mgr->registerAction( anAction, ClockWiseId );
2329
2330   // Reset
2331   anAction = new QtxAction(tr("MNU_RESET_VIEW"), 
2332                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
2333                            tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
2334   anAction->setStatusTip(tr("DSC_RESET_VIEW"));
2335   connect(anAction, SIGNAL(triggered()), this, SLOT(onResetView()));
2336   this->addAction(anAction);
2337   mgr->registerAction( anAction, ResetId );
2338
2339   // onViewTrihedron: Shows - Hides Trihedron
2340   anAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"), 
2341                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ),
2342                            tr( "MNU_SHOW_TRIHEDRON" ), 0, this);
2343   anAction->setCheckable( true );
2344   anAction->setChecked( true );
2345   
2346   anAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON"));
2347   connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onViewTrihedron(bool)));
2348   mgr->registerAction( anAction, ViewTrihedronId );
2349
2350   // onNonIsometric: Manage non-isometric params
2351   anAction = new QtxAction(tr("MNU_SVTK_SCALING"), 
2352                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SCALING" ) ),
2353                            tr( "MNU_SVTK_SCALING" ), 0, this);
2354   anAction->setStatusTip(tr("DSC_SVTK_SCALING"));
2355   anAction->setCheckable(true);
2356   connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onNonIsometric(bool)));
2357   mgr->registerAction( anAction, NonIsometric );
2358
2359   // onGraduatedAxes: Manage graduated axes params
2360   anAction = new QtxAction(tr("MNU_SVTK_GRADUATED_AXES"), 
2361                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_GRADUATED_AXES" ) ),
2362                            tr( "MNU_SVTK_GRADUATED_AXES" ), 0, this);
2363   anAction->setStatusTip(tr("DSC_SVTK_GRADUATED_AXES"));
2364   anAction->setCheckable(true);
2365   connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onGraduatedAxes(bool)));
2366   mgr->registerAction( anAction, GraduatedAxes );
2367
2368   // onGraduatedAxes: Manage graduated axes params
2369   anAction = new QtxAction(tr("MNU_SVTK_UPDATE_RATE"), 
2370                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_UPDATE_RATE" ) ),
2371                            tr( "MNU_SVTK_UPDATE_RATE" ), 0, this);
2372   anAction->setStatusTip(tr("DSC_SVTK_UPDATE_RATE"));
2373   anAction->setCheckable(true);
2374   connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onUpdateRate(bool)));
2375   mgr->registerAction( anAction, UpdateRate );
2376
2377   // Set perspective mode group
2378   anAction = new QtxAction(tr("MNU_SVTK_PARALLEL_MODE"), 
2379                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARALLEL" ) ),
2380                            tr( "MNU_SVTK_PARALLEL_MODE" ), 0, this);
2381   anAction->setStatusTip(tr("DSC_SVTK_PARALLEL_MODE"));
2382   anAction->setCheckable(true);
2383   mgr->registerAction( anAction, ParallelModeId );
2384
2385   anAction = new QtxAction(tr("MNU_SVTK_PERSPECTIVE_MODE"), 
2386                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PERSPECTIVE" ) ),
2387                            tr( "MNU_SVTK_PERSPECTIVE_MODE" ), 0, this);
2388   anAction->setStatusTip(tr("DSC_SVTK_PERSPECTIVE_MODE"));
2389   anAction->setCheckable(true);
2390   mgr->registerAction( anAction, ProjectionModeId );
2391
2392   anAction = new QtxAction(tr("MNU_SVTK_STEREO_MODE"),
2393                              theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_STEREO" ) ),
2394                              tr( "MNU_SVTK_STEREO_MODE" ), 0, this);
2395   anAction->setStatusTip(tr("DSC_SVTK_STEREO_MODE"));
2396   anAction->setCheckable(true);
2397   connect(anAction, SIGNAL(triggered(bool)), this, SLOT(onStereoMode(bool)));
2398   mgr->registerAction( anAction, StereoModeId );
2399
2400   QActionGroup* aPerspectiveGroup = new QActionGroup( this );
2401   aPerspectiveGroup->addAction( mgr->action( ParallelModeId ) );
2402   aPerspectiveGroup->addAction( mgr->action( ProjectionModeId ) );
2403   connect(aPerspectiveGroup, SIGNAL(triggered(QAction*)), this, SLOT(onProjectionMode(QAction*)));
2404
2405   // View Parameters
2406   anAction = new QtxAction(tr("MNU_VIEWPARAMETERS_VIEW"), 
2407                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARAMETERS" ) ),
2408                            tr( "MNU_VIEWPARAMETERS_VIEW" ), 0, this);
2409   anAction->setStatusTip(tr("DSC_VIEWPARAMETERS_VIEW"));
2410   anAction->setCheckable(true);
2411   connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onViewParameters(bool)));
2412   mgr->registerAction( anAction, ViewParametersId );
2413
2414   // Synchronize View 
2415   mgr->registerAction( synchronizeAction(), SynchronizeId );
2416
2417   // Switch between interaction styles
2418   anAction = new QtxAction(tr("MNU_SVTK_STYLE_SWITCH"), 
2419                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_STYLE_SWITCH" ) ),
2420                            tr( "MNU_SVTK_STYLE_SWITCH" ), 0, this);
2421   anAction->setStatusTip(tr("DSC_SVTK_STYLE_SWITCH"));
2422   anAction->setCheckable(true);
2423   connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
2424   mgr->registerAction( anAction, SwitchInteractionStyleId );
2425
2426   // Switch between zooming styles
2427   anAction = new QtxAction(tr("MNU_SVTK_ZOOMING_STYLE_SWITCH"), 
2428                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_ZOOMING_STYLE_SWITCH" ) ),
2429                            tr( "MNU_SVTK_ZOOMING_STYLE_SWITCH" ), 0, this);
2430   anAction->setStatusTip(tr("DSC_SVTK_ZOOMING_STYLE_SWITCH"));
2431   anAction->setCheckable(true);
2432   connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
2433   mgr->registerAction( anAction, SwitchZoomingStyleId );
2434
2435   // Pre-selection
2436   QSignalMapper* aSignalMapper = new QSignalMapper( this );
2437   connect(aSignalMapper, SIGNAL(mapped(int)), this, SLOT(onSwitchPreSelectionMode(int)));
2438
2439   anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_STANDARD"), 
2440                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_STANDARD" ) ),
2441                            tr( "MNU_SVTK_PRESELECTION_STANDARD" ), 0, this);
2442   anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_STANDARD"));
2443   anAction->setCheckable(true);
2444   connect(anAction, SIGNAL(triggered()), aSignalMapper, SLOT(map()));
2445   aSignalMapper->setMapping( anAction, Standard_Preselection );
2446   mgr->registerAction( anAction, StandardPreselectionId );
2447   
2448   anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_DYNAMIC"), 
2449                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_DYNAMIC" ) ),
2450                            tr( "MNU_SVTK_PRESELECTION_DYNAMIC" ), 0, this);
2451   anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_DYNAMIC"));
2452   anAction->setCheckable(true);
2453   connect(anAction, SIGNAL(triggered()), aSignalMapper, SLOT(map()));
2454   aSignalMapper->setMapping( anAction, Dynamic_Preselection );
2455   mgr->registerAction( anAction, DynamicPreselectionId );
2456
2457   anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_DISABLED"), 
2458                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_DISABLED" ) ),
2459                            tr( "MNU_SVTK_PRESELECTION_DISABLED" ), 0, this);
2460   anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_DISABLED"));
2461   anAction->setCheckable(true);
2462   connect(anAction, SIGNAL(triggered()), aSignalMapper, SLOT(map()));
2463   aSignalMapper->setMapping( anAction, Preselection_Disabled );
2464   mgr->registerAction( anAction, DisablePreselectionId );
2465
2466   QtxActionGroup* aPreselectionAction = new QtxActionGroup( this, true );
2467   aPreselectionAction->add( getAction( StandardPreselectionId ) );
2468   aPreselectionAction->add( getAction( DynamicPreselectionId ) );
2469   aPreselectionAction->add( getAction( DisablePreselectionId ) );
2470   mgr->registerAction( aPreselectionAction, PreselectionId );
2471
2472   // Selection
2473   anAction = new QtxAction(tr("MNU_SVTK_ENABLE_SELECTION"), 
2474                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SELECTION" ) ),
2475                            tr( "MNU_SVTK_ENABLE_SELECTION" ), 0, this);
2476   anAction->setStatusTip(tr("DSC_SVTK_ENABLE_SELECTION"));
2477   anAction->setCheckable(true);
2478   connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onEnableSelection(bool)));
2479   mgr->registerAction( anAction, EnableSelectionId );
2480
2481   // Start recording
2482   myStartAction = new QtxAction(tr("MNU_SVTK_RECORDING_START"), 
2483                                 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_START" ) ),
2484                                 tr( "MNU_SVTK_RECORDING_START" ), 0, this);
2485   myStartAction->setStatusTip(tr("DSC_SVTK_RECORDING_START"));
2486   connect( myStartAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStartRecording() ) );
2487   mgr->registerAction( myStartAction, StartRecordingId );
2488
2489   // Play recording
2490   myPlayAction = new QtxAction(tr("MNU_SVTK_RECORDING_PLAY"), 
2491                                theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PLAY" ) ),
2492                                tr( "MNU_SVTK_RECORDING_PLAY" ), 0, this);
2493   myPlayAction->setStatusTip(tr("DSC_SVTK_RECORDING_PLAY"));
2494   myPlayAction->setEnabled( false );
2495   connect( myPlayAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPlayRecording() ) );
2496   mgr->registerAction( myPlayAction, PlayRecordingId );
2497
2498   // Pause recording
2499   myPauseAction = new QtxAction(tr("MNU_SVTK_RECORDING_PAUSE"), 
2500                                 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PAUSE" ) ),
2501                                 tr( "MNU_SVTK_RECORDING_PAUSE" ), 0, this);
2502   myPauseAction->setStatusTip(tr("DSC_SVTK_RECORDING_PAUSE"));
2503   myPauseAction->setEnabled( false );
2504   connect( myPauseAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPauseRecording() ) );
2505   mgr->registerAction( myPauseAction, PauseRecordingId );
2506
2507   // Stop recording
2508   myStopAction = new QtxAction(tr("MNU_SVTK_RECORDING_STOP"), 
2509                                theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_STOP" ) ),
2510                                tr( "MNU_SVTK_RECORDING_STOP" ), 0, this);
2511   myStopAction->setStatusTip(tr("DSC_SVTK_RECORDING_STOP"));
2512   myStopAction->setEnabled( false );
2513   connect( myStopAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStopRecording() ) );
2514   mgr->registerAction( myStopAction, StopRecordingId );
2515 }
2516
2517 /*!
2518   Creates toolbar of svtk main window
2519 */
2520 void SVTK_ViewWindow::createToolBar()
2521 {
2522   QtxActionToolMgr* mgr = toolMgr();
2523   
2524   mgr->append( DumpId, myToolBar );
2525   mgr->append( SwitchInteractionStyleId, myToolBar );
2526   mgr->append( SwitchZoomingStyleId, myToolBar );
2527
2528   mgr->append( mgr->separator(), myToolBar );
2529  
2530   mgr->append( PreselectionId, myToolBar );
2531   mgr->append( EnableSelectionId, myToolBar );
2532
2533   mgr->append( mgr->separator(), myToolBar );
2534
2535   mgr->append( ViewTrihedronId, myToolBar );
2536
2537   QtxMultiAction* aScaleAction = new QtxMultiAction( this );
2538   aScaleAction->insertAction( getAction( FitAllId ) );
2539   aScaleAction->insertAction( getAction( FitRectId ) );
2540   aScaleAction->insertAction( getAction( FitSelectionId ) );
2541   aScaleAction->insertAction( getAction( ZoomId ) );
2542   mgr->append( aScaleAction, myToolBar );
2543
2544   QtxMultiAction* aPanningAction = new QtxMultiAction( this );
2545   aPanningAction->insertAction( getAction( PanId ) );
2546   aPanningAction->insertAction( getAction( GlobalPanId ) );
2547   mgr->append( aPanningAction, myToolBar );
2548
2549   mgr->append( ChangeRotationPointId, myToolBar );
2550
2551   mgr->append( RotationId, myToolBar );
2552
2553   QtxMultiAction* aViewsAction = new QtxMultiAction( this );
2554   aViewsAction->insertAction( getAction( FrontId ) );
2555   aViewsAction->insertAction( getAction( BackId ) );
2556   aViewsAction->insertAction( getAction( TopId ) );
2557   aViewsAction->insertAction( getAction( BottomId ) );
2558   aViewsAction->insertAction( getAction( LeftId ) );
2559   aViewsAction->insertAction( getAction( RightId ) );
2560   mgr->append( aViewsAction, myToolBar );
2561
2562   mgr->append( AntiClockWiseId, myToolBar );
2563   mgr->append( ClockWiseId, myToolBar );
2564
2565   mgr->append( ResetId, myToolBar );
2566
2567   mgr->append( UpdateRate, myToolBar );
2568   mgr->append( NonIsometric, myToolBar );
2569   mgr->append( GraduatedAxes, myToolBar );
2570
2571   mgr->append( ViewParametersId, myToolBar );
2572   mgr->append( SynchronizeId, myToolBar );
2573
2574   mgr->append( toolMgr()->separator(), myToolBar );
2575
2576   mgr->append( ParallelModeId, myToolBar );
2577   mgr->append( ProjectionModeId, myToolBar );
2578   mgr->append( StereoModeId, myToolBar );
2579
2580   mgr->append( StartRecordingId, myRecordingToolBar );
2581   mgr->append( PlayRecordingId, myRecordingToolBar );
2582   mgr->append( PauseRecordingId, myRecordingToolBar );
2583   mgr->append( StopRecordingId, myRecordingToolBar );
2584 }
2585
2586 void SVTK_ViewWindow::onUpdateRate(bool theIsActivate)
2587 {
2588   if(theIsActivate){
2589     myUpdateRateDlg->Update();
2590     myUpdateRateDlg->show();
2591   }else
2592     myUpdateRateDlg->hide();
2593 }
2594
2595 void SVTK_ViewWindow::onNonIsometric(bool theIsActivate)
2596 {
2597   if(theIsActivate){
2598     myNonIsometricDlg->Update();
2599     myNonIsometricDlg->show();
2600   }else
2601     myNonIsometricDlg->hide();
2602 }
2603
2604 void SVTK_ViewWindow::onGraduatedAxes(bool theIsActivate)
2605 {
2606   if(theIsActivate){
2607     myCubeAxesDlg->Update();
2608     myCubeAxesDlg->show();
2609   }else
2610     myCubeAxesDlg->hide();
2611 }
2612
2613 /*!
2614   Starts rotation transformation
2615 */
2616 void SVTK_ViewWindow::activateRotation()
2617 {
2618   myEventDispatcher->InvokeEvent(SVTK::StartRotate,0);
2619 }
2620
2621
2622 /*!
2623   Starts panning transformation
2624 */
2625 void SVTK_ViewWindow::activatePanning()
2626 {
2627   myEventDispatcher->InvokeEvent(SVTK::StartPan,0);
2628 }
2629
2630 /*!
2631   Starts zoom transformation
2632 */
2633 void SVTK_ViewWindow::activateZoom()
2634 {
2635   myEventDispatcher->InvokeEvent(SVTK::StartZoom,0);
2636 }
2637
2638 /*!
2639   Starts window fit transformation
2640 */
2641 void SVTK_ViewWindow::activateWindowFit()
2642 {
2643   myEventDispatcher->InvokeEvent(SVTK::StartFitArea,0);
2644 }
2645
2646 /*!
2647   Starts global panning transformation
2648 */
2649 void SVTK_ViewWindow::activateGlobalPanning()
2650 {
2651   myEventDispatcher->InvokeEvent(SVTK::StartGlobalPan,0);
2652 }
2653
2654 void SVTK_ViewWindow::onStartRecording()
2655 {
2656   myRecorder->CheckExistAVIMaker();
2657   if (myRecorder->ErrorStatus()) {
2658     SUIT_MessageBox::warning(this, tr("ERROR"), tr("MSG_NO_AVI_MAKER") );
2659   }
2660   else {
2661     SVTK_RecorderDlg* aRecorderDlg = new SVTK_RecorderDlg( this, myRecorder );
2662
2663     if( !aRecorderDlg->exec() )
2664       return;
2665
2666     myStartAction->setEnabled( false );
2667     myPlayAction->setEnabled( false );
2668     myPauseAction->setEnabled( true );
2669     myStopAction->setEnabled( true );
2670
2671     // to prevent resizing the window while recording
2672     myPreRecordingMinSize = minimumSize();
2673     myPreRecordingMaxSize = maximumSize();
2674     setFixedSize( size() );
2675
2676     myRecorder->Record();
2677   }
2678 }
2679
2680 void SVTK_ViewWindow::onPlayRecording()
2681 {
2682   myStartAction->setEnabled( false );
2683   myPlayAction->setEnabled( false );
2684   myPauseAction->setEnabled( true );
2685   myStopAction->setEnabled( true );
2686
2687   myRecorder->Pause();
2688 }
2689
2690 void SVTK_ViewWindow::onPauseRecording()
2691 {
2692   myStartAction->setEnabled( false );
2693   myPlayAction->setEnabled( true );
2694   myPauseAction->setEnabled( false );
2695   myStopAction->setEnabled( true );
2696
2697   myRecorder->Pause();
2698 }
2699
2700 void SVTK_ViewWindow::onStopRecording()
2701 {
2702   myStartAction->setEnabled( true );
2703   myPlayAction->setEnabled( false );
2704   myPauseAction->setEnabled( false );
2705   myStopAction->setEnabled( false );
2706
2707   myRecorder->Stop();
2708
2709   setMinimumSize( myPreRecordingMinSize );
2710   setMaximumSize( myPreRecordingMaxSize );
2711 }
2712
2713 /*!
2714   To invoke a VTK event on SVTK_RenderWindowInteractor instance
2715 */
2716 void SVTK_ViewWindow::InvokeEvent(unsigned long theEvent, void* theCallData)
2717 {
2718   GetInteractor()->InvokeEvent(theEvent,theCallData);
2719 }
2720
2721 /*!
2722   Modify view parameters
2723 */
2724 void SVTK_ViewWindow::onViewParameters(bool theIsActivate)
2725 {
2726   if(theIsActivate){
2727     myViewParameterDlg->addObserver();
2728     myViewParameterDlg->show();
2729   }else
2730     myViewParameterDlg->hide();
2731 }
2732
2733 /*!
2734   Custom show event handler
2735 */
2736 void SVTK_ViewWindow::showEvent( QShowEvent * theEvent ) 
2737 {
2738   emit Show( theEvent );
2739 }
2740
2741 /*!
2742   Custom hide event handler
2743 */
2744 void SVTK_ViewWindow::hideEvent( QHideEvent * theEvent ) 
2745 {
2746   emit Hide( theEvent );
2747 }
2748
2749 /*!
2750   Emit transformed signal.
2751 */
2752 void SVTK_ViewWindow::emitTransformed() {
2753   transformed(this);
2754 }
2755
2756 /*!
2757   Processes events
2758 */
2759 void SVTK_ViewWindow::ProcessEvents(vtkObject* vtkNotUsed(theObject),
2760                                     unsigned long /*theEvent*/,
2761                                     void* theClientData,
2762                                     void* /*theCallData*/)
2763 {
2764   SVTK_ViewWindow* self = reinterpret_cast<SVTK_ViewWindow*>(theClientData);
2765   if(self)
2766     self->emitTransformed();
2767 }
2768
2769 /*!
2770   Get camera properties for the SVTK view window.
2771   \return shared pointer on camera properties.
2772 */
2773 SUIT_CameraProperties SVTK_ViewWindow::cameraProperties()
2774 {
2775   SUIT_CameraProperties aProps;
2776
2777   // get vtk camera
2778   vtkCamera* aCamera = getRenderer()->GetActiveCamera();
2779   if ( !aCamera )
2780     return aProps;
2781   
2782   aProps.setDimension( SUIT_CameraProperties::Dim3D );
2783   if ( toolMgr()->action( ParallelModeId ) ) {
2784     if ( toolMgr()->action( ParallelModeId )->isChecked() )
2785       aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
2786     else
2787       aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
2788   }
2789
2790   double aFocalPoint[3];
2791   double aPosition[3];
2792   double aViewUp[3];
2793   double anAxialScale[3];
2794
2795   aCamera->OrthogonalizeViewUp();
2796   aCamera->GetFocalPoint( aFocalPoint );
2797   aCamera->GetPosition( aPosition );
2798   aCamera->GetViewUp( aViewUp );
2799   
2800   aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2801   aProps.setPosition( aPosition[0], aPosition[1], aPosition[2] );
2802   aProps.setViewUp( aViewUp[0], aViewUp[1], aViewUp[2] );
2803   aProps.setMappingScale( aCamera->GetParallelScale() * 2.0 );
2804
2805   if ( aProps.getProjection() == SUIT_CameraProperties::PrjPerspective )
2806   {
2807     aProps.setViewAngle( aCamera->GetViewAngle() );
2808   }
2809
2810   GetRenderer()->GetScale( anAxialScale );
2811   aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2812   
2813   return aProps;
2814 }
2815
2816 /*!
2817   Synchronize views.
2818   This implementation synchronizes camera propreties.
2819 */
2820 void SVTK_ViewWindow::synchronize( SUIT_ViewWindow* theView )
2821 {
2822   bool blocked = blockSignals( true );
2823
2824   SUIT_CameraProperties aProps = theView->cameraProperties();
2825   if ( !cameraProperties().isCompatible( aProps ) ) {
2826     // other view, this one is being currently synchronized to, seems has become incompatible
2827     // we have to break synchronization
2828     updateSyncViews();
2829     return;
2830   }
2831
2832   // get camera
2833   vtkCamera* aCamera = getRenderer()->GetActiveCamera();
2834   
2835   double aFocalPoint[3];
2836   double aPosition[3];
2837   double aViewUp[3];
2838   double anAxialScale[3];
2839
2840   // get common properties
2841   aProps.getViewUp( aViewUp[0], aViewUp[1], aViewUp[2] );
2842   aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
2843   aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2844   aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2845   
2846   // restore properties to the camera
2847   aCamera->SetViewUp( aViewUp );
2848   aCamera->SetPosition( aPosition );
2849   aCamera->SetFocalPoint( aFocalPoint );
2850   aCamera->SetParallelScale( aProps.getMappingScale() / 2.0 );
2851
2852   if ( aProps.getProjection() == SUIT_CameraProperties::PrjPerspective )
2853   {
2854     aCamera->SetViewAngle( aProps.getViewAngle() );
2855   }
2856
2857   GetRenderer()->SetScale( anAxialScale );
2858
2859   getRenderer()->ResetCameraClippingRange();
2860   Repaint( false );
2861
2862   blockSignals( blocked );
2863 }
2864
2865 void SVTK_ViewWindow::resizeEvent( QResizeEvent* theEvent )
2866 {
2867 #ifdef VGL_WORKAROUND
2868   Repaint();
2869 #endif
2870 }