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