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