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