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