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