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