Salome HOME
Bug: mesh is not destructed (leaks) after element selection.
[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 ( myDefaultInteractorStyle )
1105     myDefaultInteractorStyle->FreeActors();
1106   if ( myKeyFreeInteractorStyle )
1107     myKeyFreeInteractorStyle->FreeActors();
1108   if(theUpdate) 
1109     Repaint();
1110   emit actorRemoved(theActor);
1111 }
1112
1113 QImage SVTK_ViewWindow::dumpViewContent()
1114 {
1115   vtkRenderWindow* aWindow = getRenderWindow();
1116   int* aSize = aWindow->GetSize();
1117   int aWidth = aSize[0];
1118   int aHeight = aSize[1];
1119   
1120   OpenGLUtils_FrameBuffer aFrameBuffer;
1121   if( aFrameBuffer.init( aWidth, aHeight ) )
1122   {
1123     glPushAttrib( GL_VIEWPORT_BIT );
1124     glViewport( 0, 0, aWidth, aHeight );
1125     aFrameBuffer.bind();
1126
1127     // draw scene
1128     aWindow->Render();
1129
1130     aFrameBuffer.unbind();
1131     glPopAttrib();
1132
1133     QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
1134
1135     aFrameBuffer.bind();
1136     glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
1137     aFrameBuffer.unbind();
1138
1139     anImage = anImage.rgbSwapped();
1140     anImage = anImage.mirrored();
1141     return anImage;
1142   }
1143
1144   // if frame buffers are unsupported, use old functionality
1145   unsigned char *aData = 
1146     aWindow->GetRGBACharPixelData( 0, 0, aWidth-1, aHeight-1, 0 );
1147   
1148   QImage anImage( aData, aWidth, aHeight, QImage::Format_ARGB32 );
1149
1150   anImage = anImage.rgbSwapped();
1151   anImage = anImage.mirrored();
1152   return anImage;
1153 }
1154
1155 /*!
1156   \return QImage, containing all scene rendering in window
1157 */
1158 QImage SVTK_ViewWindow::dumpView()
1159 {
1160   if( myDumpImage.isNull() )
1161     return dumpViewContent();
1162   
1163   RefreshDumpImage();
1164   return myDumpImage;
1165 }
1166
1167 QString SVTK_ViewWindow::filter() const
1168 {
1169   return tr( "SVTK_IMAGE_FILES" );
1170 }
1171
1172 bool SVTK_ViewWindow::dumpViewToFormat( const QImage& img, const QString& fileName, const QString& format )
1173 {
1174   if ( format != "PS" && format != "EPS" && format != "PDF" )
1175     return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
1176
1177   SUIT_OverrideCursor wc;
1178
1179   vtkGL2PSExporter *anExporter = vtkGL2PSExporter::New();
1180   anExporter->SetRenderWindow(getRenderWindow());
1181
1182   if ( format == "PS" ) {
1183     anExporter->SetFileFormatToPS();
1184     anExporter->CompressOff();
1185   }
1186
1187   if ( format == "EPS" ) {
1188     anExporter->SetFileFormatToEPS();
1189     anExporter->CompressOff();
1190   }
1191
1192   if ( format == "PDF" ) {
1193     anExporter->SetFileFormatToPDF();
1194   }
1195
1196   QString aFilePrefix(fileName);
1197   QString anExtension(SUIT_Tools::extension(fileName));
1198   aFilePrefix.truncate(aFilePrefix.length() - 1 - anExtension.length());
1199   anExporter->SetFilePrefix(aFilePrefix.toLatin1().data());
1200   anExporter->Write();
1201   anExporter->Delete();
1202
1203   return true;
1204 }
1205
1206 /*!
1207   \refresh QImage, containing all scene rendering in window
1208 */
1209 void SVTK_ViewWindow::RefreshDumpImage()
1210 {
1211   myDumpImage = dumpViewContent();
1212 }
1213
1214 /*!
1215   Redirect the request to #SVTK_Renderer::SetSelectionProp
1216 */
1217 void SVTK_ViewWindow::SetSelectionProp(const double& theRed, 
1218                                        const double& theGreen, 
1219                                        const double& theBlue, 
1220                                        const int& theWidth) 
1221 {
1222   myView->SetSelectionProp(theRed,theGreen,theBlue,theWidth);
1223 }
1224
1225 /*!
1226   Redirect the request to #SVTK_Renderer::SetSelectionProp
1227 */
1228 void SVTK_ViewWindow::SetPreselectionProp(const double& theRed, 
1229                                           const double& theGreen, 
1230                                           const double& theBlue, 
1231                                           const int& theWidth) 
1232 {
1233   myView->SetPreselectionProp(theRed,theGreen,theBlue,theWidth);
1234 }
1235
1236 /*!
1237   Redirect the request to #SVTK_Renderer::SetSelectionTolerance
1238 */
1239 void SVTK_ViewWindow::SetSelectionTolerance(const double& theTolNodes, 
1240                                             const double& theTolItems,
1241                                             const double& theTolObjects)
1242 {
1243   myView->SetSelectionTolerance(theTolNodes, theTolItems, theTolObjects);
1244 }
1245
1246 /*!
1247   Get visibility status of the static trihedron
1248 */
1249 bool SVTK_ViewWindow::IsStaticTrihedronVisible() const
1250 {
1251   return (bool)myAxesWidget->GetEnabled();
1252 }
1253
1254 /*!
1255   Set visibility status of the static trihedron
1256 */
1257 void SVTK_ViewWindow::SetStaticTrihedronVisible( const bool theIsVisible )
1258 {
1259   myAxesWidget->SetEnabled( (int)theIsVisible );
1260 }
1261
1262 /*!
1263   Performs action
1264   \param accelAction - action
1265 */
1266 bool SVTK_ViewWindow::action( const int accelAction  )
1267 {
1268   if ( accelAction == SUIT_Accel::ZoomFit )
1269     onFitAll();
1270   else {
1271     int anEvent = SVTK::convertAction( accelAction );
1272     GetInteractor()->InvokeEvent(anEvent, 0);
1273   }
1274   return true;
1275 }
1276
1277 /*!
1278   \return action by it's id
1279 */
1280 QtxAction* SVTK_ViewWindow::getAction( int id ) const
1281 {
1282   return dynamic_cast<QtxAction*>( toolMgr()->action( id ) );
1283 }
1284
1285
1286 // old visual parameters had 13 values.  New format added additional 
1287 // 76 values for graduated axes, so both numbers are processed.
1288 const int nNormalParams = 13;   // number of view windows parameters excluding graduated axes params
1289 const int nGradAxisParams = 25; // number of parameters of ONE graduated axis (X, Y, or Z)
1290 const int nTrihedronParams = 3; // number of parameters for Trihedron
1291 const int nAllParams = nNormalParams + 3*nGradAxisParams + nTrihedronParams + 1; // number of all visual parameters
1292
1293 /*! The method returns visual parameters of a graduated axis actor (x,y,z axis of graduated axes)
1294  */
1295 void getGradAxisVisualParams( QXmlStreamWriter& writer, vtkAxisActor2D* actor, QString theAxis )
1296 {
1297   //QString params;
1298   if ( !actor )
1299     return ;//params;
1300
1301   // Name
1302   bool isVisible = actor->GetTitleVisibility();
1303   QString title ( actor->GetTitle() );
1304   double color[ 3 ];
1305   int font = VTK_ARIAL;
1306   int bold = 0;
1307   int italic = 0;
1308   int shadow = 0;
1309
1310   vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1311   if ( txtProp )
1312   {
1313     txtProp->GetColor( color );
1314     font = txtProp->GetFontFamily();
1315     bold = txtProp->GetBold();
1316     italic = txtProp->GetItalic();
1317     shadow = txtProp->GetShadow();
1318   }
1319   writer.writeStartElement("GraduatedAxis");
1320   writer.writeAttribute("Axis", theAxis);
1321
1322   writer.writeStartElement("Title");
1323   writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1324   writer.writeAttribute("Text", title);
1325   writer.writeAttribute("Font", QString("%1").arg(font));
1326   writer.writeAttribute("Bold", QString("%1").arg(bold));
1327   writer.writeAttribute("Italic", QString("%1").arg(italic));
1328   writer.writeAttribute("Shadow", QString("%1").arg(shadow));
1329
1330   writer.writeStartElement("Color");
1331   writer.writeAttribute("R", QString("%1").arg(color[0]));
1332   writer.writeAttribute("G", QString("%1").arg(color[1]));
1333   writer.writeAttribute("B", QString("%1").arg(color[2]));
1334   writer.writeEndElement();
1335   writer.writeEndElement();
1336
1337   //params.sprintf( "* Graduated Axis: * Name *%u*%s*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible, 
1338   //              title.toLatin1().data(), color[0], color[1], color[2], font, bold, italic, shadow );
1339
1340   // Labels
1341   isVisible = actor->GetLabelVisibility();
1342   int labels = actor->GetNumberOfLabels();
1343   int offset = actor->GetTickOffset();
1344   font = VTK_ARIAL;
1345   bold = false;
1346   italic = false;
1347   shadow = false;
1348
1349   txtProp = actor->GetLabelTextProperty();
1350   if ( txtProp )
1351   {
1352     txtProp->GetColor( color );
1353     font = txtProp->GetFontFamily();
1354     bold = txtProp->GetBold();
1355     italic = txtProp->GetItalic();
1356     shadow = txtProp->GetShadow();
1357   }
1358
1359   writer.writeStartElement("Labels");
1360   writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1361   writer.writeAttribute("Number", QString("%1").arg(labels));
1362   writer.writeAttribute("Offset", QString("%1").arg(offset));
1363   writer.writeAttribute("Font", QString("%1").arg(font));
1364   writer.writeAttribute("Bold", QString("%1").arg(bold));
1365   writer.writeAttribute("Italic", QString("%1").arg(italic));
1366   writer.writeAttribute("Shadow", QString("%1").arg(shadow));
1367
1368   writer.writeStartElement("Color");
1369   writer.writeAttribute("R", QString("%1").arg(color[0]));
1370   writer.writeAttribute("G", QString("%1").arg(color[1]));
1371   writer.writeAttribute("B", QString("%1").arg(color[2]));
1372   writer.writeEndElement();
1373   writer.writeEndElement();
1374   //  params += QString().sprintf( "* Labels *%u*%u*%u*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible, labels, offset,  
1375   //                           color[0], color[1], color[2], font, bold, italic, shadow );
1376
1377   // Tick marks
1378   isVisible = actor->GetTickVisibility();
1379   int length = actor->GetTickLength();
1380   writer.writeStartElement("TickMarks");
1381   writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1382   writer.writeAttribute("Length", QString("%1").arg(length));
1383   writer.writeEndElement();
1384   
1385   //params += QString().sprintf( "* Tick marks *%u*%u", isVisible, length );
1386   
1387   writer.writeEndElement();
1388   //return params;
1389 }
1390
1391 void setGradAxisVisualParams(QXmlStreamReader& reader, vtkAxisActor2D* actor)
1392 {
1393   if ( !actor )
1394     return;
1395
1396   do {
1397     reader.readNext();
1398   } while (!reader.isStartElement());
1399
1400   // Read title params
1401   QXmlStreamAttributes aAttr = reader.attributes();
1402   bool isVisible = aAttr.value("isVisible").toString().toUShort();
1403   QString title = aAttr.value("Text").toString();
1404   int font = aAttr.value("Font").toString().toInt();
1405   int bold = aAttr.value("Bold").toString().toInt();
1406   int italic = aAttr.value("Italic").toString().toInt();
1407   int shadow = aAttr.value("Shadow").toString().toInt();
1408
1409   //printf("#### TITLE: %i, %s, %i, %i, %i, %i\n", isVisible, qPrintable(title), font, bold, italic, shadow);
1410
1411   do {
1412     reader.readNext();
1413   } while (!reader.isStartElement());
1414   
1415   // Read title color
1416   aAttr = reader.attributes();
1417
1418   double color[3];
1419   color[0] = aAttr.value("R").toString().toDouble();
1420   color[1] = aAttr.value("G").toString().toDouble();
1421   color[2] = aAttr.value("B").toString().toDouble();
1422   //printf("#### Color: %f, %f, %f\n", color[0], color[1], color[2]);
1423
1424   actor->SetTitleVisibility( isVisible );
1425   actor->SetTitle( title.toLatin1() );
1426   vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1427   if ( txtProp ) {
1428     txtProp->SetColor( color );
1429     txtProp->SetFontFamily( font );
1430     txtProp->SetBold( bold );
1431     txtProp->SetItalic( italic );
1432     txtProp->SetShadow( shadow );
1433   }
1434
1435   // Labels
1436
1437   do {
1438     reader.readNext();
1439   } while (!reader.isStartElement()); 
1440   // Read labels
1441   aAttr = reader.attributes();
1442   isVisible = aAttr.value("isVisible").toString().toUShort();
1443   int labels = aAttr.value("Number").toString().toInt();
1444   int offset = aAttr.value("Offset").toString().toInt();
1445   font = aAttr.value("Font").toString().toInt();
1446   bold = aAttr.value("Bold").toString().toInt();
1447   italic = aAttr.value("Italic").toString().toInt();
1448   shadow = aAttr.value("Shadow").toString().toInt();
1449
1450   do {
1451     reader.readNext();
1452   } while (!reader.isStartElement()); 
1453   // Read Color
1454   aAttr = reader.attributes();
1455
1456   color[0] = aAttr.value("R").toString().toDouble();
1457   color[1] = aAttr.value("G").toString().toDouble();
1458   color[2] = aAttr.value("B").toString().toDouble();
1459
1460   actor->SetLabelVisibility( isVisible );
1461   actor->SetNumberOfLabels( labels );
1462   actor->SetTickOffset( offset );
1463   txtProp = actor->GetLabelTextProperty();
1464   if ( txtProp ) {
1465     txtProp->SetColor( color );
1466     txtProp->SetFontFamily( font );
1467     txtProp->SetBold( bold );
1468     txtProp->SetItalic( italic );
1469     txtProp->SetShadow( shadow );
1470   }
1471
1472   // Tick Marks
1473   do {
1474     reader.readNext();
1475   } while (!reader.isStartElement()); 
1476   aAttr = reader.attributes();
1477
1478   // retrieve and set tick marks properties
1479   isVisible = aAttr.value("isVisible").toString().toUShort();
1480   int length = aAttr.value("Length").toString().toInt();
1481   
1482   actor->SetTickVisibility( isVisible );
1483   actor->SetTickLength( length );
1484 }
1485
1486 /*! The method restores visual parameters of a graduated axis actor (x,y,z axis)
1487  */
1488 void setGradAxisVisualParams( vtkAxisActor2D* actor, const QString& params )
1489 {
1490   if ( !actor )
1491     return;
1492
1493   QStringList paramsLst = params.split( '*' );
1494
1495   if ( paramsLst.size() == nGradAxisParams ) { // altogether name, lable, ticks parameters make up 25 values
1496
1497     // retrieve and set name parameters
1498     bool isVisible = paramsLst[2].toUShort();
1499     QString title = paramsLst[3];
1500     double color[3];
1501     color[0] = paramsLst[4].toDouble();
1502     color[1] = paramsLst[5].toDouble();
1503     color[2] = paramsLst[6].toDouble();
1504     int font = paramsLst[7].toInt();
1505     int bold = paramsLst[8].toInt();
1506     int italic = paramsLst[9].toInt();
1507     int shadow = paramsLst[10].toInt();
1508
1509     actor->SetTitleVisibility( isVisible );
1510     actor->SetTitle( title.toLatin1() );
1511     vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1512     if ( txtProp ) {
1513       txtProp->SetColor( color );
1514       txtProp->SetFontFamily( font );
1515       txtProp->SetBold( bold );
1516       txtProp->SetItalic( italic );
1517       txtProp->SetShadow( shadow );
1518     }
1519
1520     // retrieve and set lable parameters
1521     isVisible = paramsLst[12].toUShort();
1522     int labels = paramsLst[13].toInt();
1523     int offset = paramsLst[14].toInt();
1524     color[0] = paramsLst[15].toDouble();
1525     color[1] = paramsLst[16].toDouble();
1526     color[2] = paramsLst[17].toDouble();
1527     font = paramsLst[18].toInt();
1528     bold = paramsLst[19].toInt();
1529     italic = paramsLst[20].toInt();
1530     shadow = paramsLst[21].toInt();
1531
1532     actor->SetLabelVisibility( isVisible );
1533     actor->SetNumberOfLabels( labels );
1534     actor->SetTickOffset( offset );
1535     txtProp = actor->GetLabelTextProperty();
1536     if ( txtProp ) {
1537       txtProp->SetColor( color );
1538       txtProp->SetFontFamily( font );
1539       txtProp->SetBold( bold );
1540       txtProp->SetItalic( italic );
1541       txtProp->SetShadow( shadow );
1542     }
1543
1544     // retrieve and set tick marks properties
1545     isVisible = paramsLst[23].toUShort();
1546     int length = paramsLst[24].toInt();
1547
1548     actor->SetTickVisibility( isVisible );
1549     actor->SetTickLength( length );
1550   }
1551 }
1552
1553 /*! The method returns the visual parameters of this view as a formated string
1554  */
1555 QString SVTK_ViewWindow::getVisualParameters()
1556 {
1557   double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
1558   
1559   // save position, focal point, viewUp, scale
1560   vtkCamera* camera = getRenderer()->GetActiveCamera();
1561   camera->GetPosition( pos );
1562   camera->GetFocalPoint( focalPnt );
1563   camera->GetViewUp( viewUp );
1564   parScale = camera->GetParallelScale();
1565   GetScale( scale );
1566
1567   // Parameters are given in the following format:view position (3 digits), focal point position (3 digits)
1568   // view up values (3 digits), parallel scale (1 digit), scale (3 digits, 
1569   // Graduated axes parameters (X, Y, Z axes parameters)
1570   QString retStr;
1571   QXmlStreamWriter aWriter(&retStr);
1572   aWriter.setAutoFormatting(true);
1573
1574   aWriter.writeStartDocument();
1575   aWriter.writeStartElement("ViewState");
1576
1577   aWriter.writeStartElement("Position");
1578   aWriter.writeAttribute("X", QString("%1").arg(pos[0]));
1579   aWriter.writeAttribute("Y", QString("%1").arg(pos[1]));
1580   aWriter.writeAttribute("Z", QString("%1").arg(pos[2]));
1581   aWriter.writeEndElement();
1582
1583   aWriter.writeStartElement("FocalPoint");
1584   aWriter.writeAttribute("X", QString::number(focalPnt[0]));
1585   aWriter.writeAttribute("Y", QString::number(focalPnt[1]));
1586   aWriter.writeAttribute("Z", QString::number(focalPnt[2]));
1587   aWriter.writeEndElement();
1588
1589   aWriter.writeStartElement("ViewUp");
1590   aWriter.writeAttribute("X", QString::number(viewUp[0]));
1591   aWriter.writeAttribute("Y", QString::number(viewUp[1]));
1592   aWriter.writeAttribute("Z", QString::number(viewUp[2]));
1593   aWriter.writeEndElement();
1594
1595   aWriter.writeStartElement("ViewScale");
1596   aWriter.writeAttribute("Parallel", QString::number(parScale));
1597   aWriter.writeAttribute("X", QString::number(scale[0]));
1598   aWriter.writeAttribute("Y", QString::number(scale[1]));
1599   aWriter.writeAttribute("Z", QString::number(scale[2]));
1600   aWriter.writeEndElement();
1601
1602   if ( SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes() ) {
1603     aWriter.writeStartElement("DisplayCubeAxis");
1604     aWriter.writeAttribute("Show", QString( "%1" ).arg( GetRenderer()->IsCubeAxesDisplayed()));
1605     aWriter.writeEndElement();
1606
1607     getGradAxisVisualParams(aWriter, gradAxesActor->GetXAxisActor2D(), "X");
1608     getGradAxisVisualParams(aWriter, gradAxesActor->GetYAxisActor2D(), "Y");
1609     getGradAxisVisualParams(aWriter, gradAxesActor->GetZAxisActor2D(), "Z");
1610   }
1611
1612   aWriter.writeStartElement("Trihedron");
1613   aWriter.writeAttribute("isShown",  QString( "%1" ).arg( isTrihedronDisplayed()));
1614   aWriter.writeAttribute("Size", QString::number(GetTrihedronSize()));
1615   aWriter.writeEndElement();
1616
1617   aWriter.writeStartElement("Background");
1618   aWriter.writeAttribute("Value",  QString( "%1" ).arg( Qtx::backgroundToString(background()) ));
1619   aWriter.writeEndElement();
1620
1621   aWriter.writeEndElement();
1622   aWriter.writeEndDocument();
1623
1624   return retStr;
1625 }
1626
1627 /*!
1628   The method restores visual parameters of this view or postpones it untill the view is shown
1629 */ 
1630 void SVTK_ViewWindow::setVisualParameters( const QString& parameters )
1631 {
1632   //printf("#### %s\n", qPrintable(parameters));
1633   SVTK_RenderWindowInteractor* anInteractor = GetInteractor();
1634   if ( anInteractor->isVisible() ) {
1635     doSetVisualParameters( parameters ); 
1636   }
1637   else {
1638     myVisualParams = parameters;
1639     anInteractor->installEventFilter(this);
1640   }
1641 }
1642
1643 /*!
1644   The method restores visual parameters of this view from a formated string
1645 */
1646 void SVTK_ViewWindow::doSetVisualParameters( const QString& parameters, bool baseParamsOnly )
1647 {
1648   
1649   double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
1650
1651   QXmlStreamReader aReader(parameters);
1652   SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes();
1653
1654   while(!aReader.atEnd()) {
1655     aReader.readNext();
1656     if (aReader.isStartElement()) {
1657       QXmlStreamAttributes aAttr = aReader.attributes();
1658       //printf("### Name = %s\n", qPrintable(aReader.name().toString()));
1659       if (aReader.name() == "Position") {       
1660         pos[0] = aAttr.value("X").toString().toDouble();
1661         pos[1] = aAttr.value("Y").toString().toDouble();
1662         pos[2] = aAttr.value("Z").toString().toDouble();
1663         //printf("#### Position %f; %f; %f\n", pos[0], pos[1], pos[2]);
1664       }
1665       else if (aReader.name() == "FocalPoint") {
1666         focalPnt[0] = aAttr.value("X").toString().toDouble();
1667         focalPnt[1] = aAttr.value("Y").toString().toDouble();
1668         focalPnt[2] = aAttr.value("Z").toString().toDouble();
1669         //printf("#### FocalPoint %f; %f; %f\n", focalPnt[0], focalPnt[1], focalPnt[2]);
1670       }
1671       else if (aReader.name() == "ViewUp") {
1672         viewUp[0] = aAttr.value("X").toString().toDouble();
1673         viewUp[1] = aAttr.value("Y").toString().toDouble();
1674         viewUp[2] = aAttr.value("Z").toString().toDouble();
1675         //printf("#### ViewUp %f; %f; %f\n", viewUp[0], viewUp[1], viewUp[2]);
1676       }
1677       else if (aReader.name() == "ViewScale") {
1678         parScale = aAttr.value("Parallel").toString().toDouble();
1679         scale[0] = aAttr.value("X").toString().toDouble();
1680         scale[1] = aAttr.value("Y").toString().toDouble();
1681         scale[2] = aAttr.value("Z").toString().toDouble();
1682         //printf("#### ViewScale %f; %f; %f\n", scale[0], scale[1], scale[2]);
1683       } 
1684       else if (aReader.name() == "DisplayCubeAxis") {
1685         if ( !baseParamsOnly ) {
1686           if (aAttr.value("Show") == "0")
1687             gradAxesActor->VisibilityOff();
1688           else
1689             gradAxesActor->VisibilityOn();
1690         }
1691       }
1692       else if (aReader.name() == "GraduatedAxis") {
1693         if ( !baseParamsOnly ) {
1694           if(aAttr.value("Axis") == "X") 
1695             setGradAxisVisualParams(aReader, gradAxesActor->GetXAxisActor2D());
1696           else if(aAttr.value("Axis") == "Y")
1697             setGradAxisVisualParams(aReader, gradAxesActor->GetYAxisActor2D());
1698           else if(aAttr.value("Axis") == "Z")
1699             setGradAxisVisualParams(aReader, gradAxesActor->GetZAxisActor2D());
1700         }
1701       } 
1702       else if (aReader.name() == "Trihedron") {
1703         if ( !baseParamsOnly ) {
1704           if (aAttr.value("isShown") == "0")
1705             GetTrihedron()->VisibilityOff();
1706           else
1707             GetTrihedron()->VisibilityOn();
1708           SetTrihedronSize(aAttr.value("Size").toString().toDouble());
1709         }
1710       }
1711       else if (aReader.name() == "Background") {
1712         if ( !baseParamsOnly ) {
1713           setBackground( Qtx::stringToBackground( aAttr.value("Value").toString() ) );
1714         }
1715       }
1716     }
1717   }
1718   if (!aReader.hasError()) {
1719     vtkCamera* camera = getRenderer()->GetActiveCamera();
1720     camera->SetPosition( pos );
1721     camera->SetFocalPoint( focalPnt );
1722     camera->SetViewUp( viewUp );
1723     camera->SetParallelScale( parScale );
1724     GetRenderer()->SetScale( scale );
1725     //SetScale( scale );
1726   }
1727   else {
1728     QStringList paramsLst = parameters.split( '*' );
1729     if ( paramsLst.size() >= nNormalParams ) {
1730       // 'reading' list of parameters
1731       pos[0] = paramsLst[0].toDouble();
1732       pos[1] = paramsLst[1].toDouble();
1733       pos[2] = paramsLst[2].toDouble();
1734       focalPnt[0] = paramsLst[3].toDouble();
1735       focalPnt[1] = paramsLst[4].toDouble();
1736       focalPnt[2] = paramsLst[5].toDouble();
1737       viewUp[0] = paramsLst[6].toDouble();
1738       viewUp[1] = paramsLst[7].toDouble();
1739       viewUp[2] = paramsLst[8].toDouble();
1740       parScale = paramsLst[9].toDouble();
1741       scale[0] = paramsLst[10].toDouble();
1742       scale[1] = paramsLst[11].toDouble();
1743       scale[2] = paramsLst[12].toDouble();
1744       
1745       // applying parameters
1746       vtkCamera* camera = getRenderer()->GetActiveCamera();
1747       camera->SetPosition( pos );
1748       camera->SetFocalPoint( focalPnt );
1749       camera->SetViewUp( viewUp );
1750       camera->SetParallelScale( parScale );
1751       GetRenderer()->SetScale( scale );
1752       //SetScale( scale );
1753       
1754       // apply graduated axes parameters
1755       if ( !baseParamsOnly ) {
1756         SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes();
1757         if ( gradAxesActor && paramsLst.size() == nAllParams ) {
1758           int i = nNormalParams+1, j = i + nGradAxisParams - 1;
1759           ::setGradAxisVisualParams( gradAxesActor->GetXAxisActor2D(), parameters.section( '*', i, j ) ); 
1760           i = j + 1; j += nGradAxisParams;
1761           ::setGradAxisVisualParams( gradAxesActor->GetYAxisActor2D(), parameters.section( '*', i, j ) ); 
1762           i = j + 1; j += nGradAxisParams;
1763           ::setGradAxisVisualParams( gradAxesActor->GetZAxisActor2D(), parameters.section( '*', i, j ) ); 
1764         
1765           if ( paramsLst[13].toUShort() )
1766             gradAxesActor->VisibilityOn();
1767           else
1768             gradAxesActor->VisibilityOff();
1769         }
1770         else if ( paramsLst.size() == nAllParams ) {
1771           if ( paramsLst[90].toUShort() )
1772             GetTrihedron()->VisibilityOn();
1773           else
1774             GetTrihedron()->VisibilityOff();
1775         
1776           SetTrihedronSize(paramsLst[91].toDouble());
1777         }
1778       }
1779     }
1780   }
1781   Repaint();
1782 }
1783
1784
1785 /*!
1786   Delayed setVisualParameters
1787 */
1788 bool SVTK_ViewWindow::eventFilter( QObject* theWatched, QEvent* theEvent )
1789 {
1790   if ( theEvent->type() == QEvent::Show && theWatched->inherits( "SVTK_RenderWindowInteractor" ) ) {
1791     SVTK_RenderWindowInteractor* anInteractor = (SVTK_RenderWindowInteractor*)theWatched;
1792     if ( anInteractor->isVisible() ) {
1793       doSetVisualParameters( myVisualParams );
1794       anInteractor->removeEventFilter( this ); // theWatched = RenderWindowInteractor
1795     }
1796   }
1797   return SUIT_ViewWindow::eventFilter( theWatched, theEvent );
1798 }
1799
1800
1801 /*!
1802   Change rotation point
1803 */
1804 void SVTK_ViewWindow::onChangeRotationPoint(bool theIsActivate)
1805 {
1806   if(theIsActivate){
1807     mySetRotationPointDlg->addObserver();
1808     if ( mySetRotationPointDlg->IsFirstShown() )
1809       activateSetRotationGravity();
1810     mySetRotationPointDlg->show();
1811   }else
1812     mySetRotationPointDlg->hide();
1813 }
1814
1815 /*!
1816   Set the gravity center as a rotation point
1817 */
1818 void SVTK_ViewWindow::activateSetRotationGravity()
1819 {
1820   myEventDispatcher->InvokeEvent(SVTK::SetRotateGravity,0);
1821 }
1822
1823 /*!
1824   Set the selected point as a rotation point
1825 */
1826 void SVTK_ViewWindow::activateSetRotationSelected(void* theData)
1827 {
1828   myEventDispatcher->InvokeEvent(SVTK::ChangeRotationPoint,theData);
1829 }
1830
1831 /*!
1832   Set the point selected by user as a rotation point
1833 */
1834 void SVTK_ViewWindow::activateStartPointSelection()
1835 {
1836   myEventDispatcher->InvokeEvent(SVTK::StartPointSelection,0);
1837 }
1838
1839 /*!
1840   Set the view projection mode: orthogonal or perspective
1841 */
1842 void SVTK_ViewWindow::onPerspectiveMode()
1843 {
1844   bool anIsParallelMode = toolMgr()->action( ParallelModeId )->isChecked();
1845
1846   // advanced zooming is not available in perspective mode
1847   if( QtxAction* anAction = getAction( SwitchZoomingStyleId ) )
1848     anAction->setEnabled( anIsParallelMode );
1849
1850   vtkCamera* aCamera = getRenderer()->GetActiveCamera();
1851   aCamera->SetParallelProjection(anIsParallelMode);
1852   GetInteractor()->GetDevice()->CreateTimer(VTKI_TIMER_FIRST);
1853
1854   emit transformed( this );
1855 }
1856
1857 void SVTK_ViewWindow::SetEventDispatcher(vtkObject* theDispatcher)
1858 {
1859   myEventDispatcher = theDispatcher;
1860 }
1861
1862 /*!
1863   Creates all actions of svtk main window
1864 */
1865 void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
1866 {
1867   QtxAction* anAction;
1868   QtxActionToolMgr* mgr = toolMgr();
1869
1870   // Dump view
1871   anAction = new QtxAction(tr("MNU_DUMP_VIEW"), 
1872                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
1873                            tr( "MNU_DUMP_VIEW" ), 0, this);
1874   anAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1875   connect(anAction, SIGNAL(activated()), this, SLOT(onDumpView()));
1876   mgr->registerAction( anAction, DumpId );
1877
1878   // FitAll
1879   anAction = new QtxAction(tr("MNU_FITALL"), 
1880                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
1881                            tr( "MNU_FITALL" ), 0, this);
1882   anAction->setStatusTip(tr("DSC_FITALL"));
1883   connect(anAction, SIGNAL(activated()), this, SLOT(onFitAll()));
1884   mgr->registerAction( anAction, FitAllId );
1885
1886   // FitRect
1887   anAction = new QtxAction(tr("MNU_FITRECT"), 
1888                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
1889                            tr( "MNU_FITRECT" ), 0, this);
1890   anAction->setStatusTip(tr("DSC_FITRECT"));
1891   connect(anAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
1892   mgr->registerAction( anAction, FitRectId );
1893
1894   // Zoom
1895   anAction = new QtxAction(tr("MNU_ZOOM_VIEW"), 
1896                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
1897                            tr( "MNU_ZOOM_VIEW" ), 0, this);
1898   anAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1899   connect(anAction, SIGNAL(activated()), this, SLOT(activateZoom()));
1900   mgr->registerAction( anAction, ZoomId );
1901
1902   // Panning
1903   anAction = new QtxAction(tr("MNU_PAN_VIEW"), 
1904                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
1905                            tr( "MNU_PAN_VIEW" ), 0, this);
1906   anAction->setStatusTip(tr("DSC_PAN_VIEW"));
1907   connect(anAction, SIGNAL(activated()), this, SLOT(activatePanning()));
1908   mgr->registerAction( anAction, PanId );
1909
1910   // Global Panning
1911   anAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), 
1912                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
1913                            tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1914   anAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1915   connect(anAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
1916   mgr->registerAction( anAction, GlobalPanId );
1917
1918   // Change rotation point
1919   anAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), 
1920                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_ROTATION_POINT" ) ),
1921                            tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1922   anAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1923   anAction->setCheckable(true);
1924   connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onChangeRotationPoint(bool)));
1925   mgr->registerAction( anAction, ChangeRotationPointId );
1926
1927   // Rotation
1928   anAction = new QtxAction(tr("MNU_ROTATE_VIEW"), 
1929                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
1930                            tr( "MNU_ROTATE_VIEW" ), 0, this);
1931   anAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1932   connect(anAction, SIGNAL(activated()), this, SLOT(activateRotation()));
1933   mgr->registerAction( anAction, RotationId );
1934
1935   // Projections
1936   anAction = new QtxAction(tr("MNU_FRONT_VIEW"), 
1937                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
1938                            tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1939   anAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1940   connect(anAction, SIGNAL(activated()), this, SLOT(onFrontView()));
1941   this->addAction(anAction);
1942   mgr->registerAction( anAction, FrontId );
1943
1944   anAction = new QtxAction(tr("MNU_BACK_VIEW"), 
1945                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
1946                            tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1947   anAction->setStatusTip(tr("DSC_BACK_VIEW"));
1948   connect(anAction, SIGNAL(activated()), this, SLOT(onBackView()));
1949   this->addAction(anAction);
1950   mgr->registerAction( anAction, BackId );
1951
1952   anAction = new QtxAction(tr("MNU_TOP_VIEW"), 
1953                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
1954                            tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1955   anAction->setStatusTip(tr("DSC_TOP_VIEW"));
1956   connect(anAction, SIGNAL(activated()), this, SLOT(onTopView()));
1957   this->addAction(anAction);
1958   mgr->registerAction( anAction, TopId );
1959
1960   anAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), 
1961                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
1962                            tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1963   anAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1964   connect(anAction, SIGNAL(activated()), this, SLOT(onBottomView()));
1965   this->addAction(anAction);
1966   mgr->registerAction( anAction, BottomId );
1967
1968   anAction = new QtxAction(tr("MNU_LEFT_VIEW"), 
1969                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
1970                            tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1971   anAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1972   connect(anAction, SIGNAL(activated()), this, SLOT(onLeftView()));
1973   this->addAction(anAction);
1974   mgr->registerAction( anAction, LeftId );
1975
1976   anAction = new QtxAction(tr("MNU_RIGHT_VIEW"), 
1977                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
1978                            tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1979   anAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1980   connect(anAction, SIGNAL(activated()), this, SLOT(onRightView()));
1981   this->addAction(anAction);
1982   mgr->registerAction( anAction, RightId );
1983
1984   // rotate anticlockwise
1985   anAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"),
1986                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ANTICLOCKWISE" ) ),
1987                            tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1988   anAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1989   connect(anAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1990   this->addAction(anAction);
1991   mgr->registerAction( anAction, AntiClockWiseId );
1992
1993   // rotate clockwise
1994   anAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"),
1995                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_CLOCKWISE" ) ),
1996                            tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1997   anAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1998   connect(anAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1999   this->addAction(anAction);
2000   mgr->registerAction( anAction, ClockWiseId );
2001
2002   // Reset
2003   anAction = new QtxAction(tr("MNU_RESET_VIEW"), 
2004                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
2005                            tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
2006   anAction->setStatusTip(tr("DSC_RESET_VIEW"));
2007   connect(anAction, SIGNAL(activated()), this, SLOT(onResetView()));
2008   this->addAction(anAction);
2009   mgr->registerAction( anAction, ResetId );
2010
2011   // onViewTrihedron: Shows - Hides Trihedron
2012   anAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"), 
2013                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ),
2014                            tr( "MNU_SHOW_TRIHEDRON" ), 0, this);
2015   anAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON"));
2016   connect(anAction, SIGNAL(activated()), this, SLOT(onViewTrihedron()));
2017   mgr->registerAction( anAction, ViewTrihedronId );
2018
2019   // onNonIsometric: Manage non-isometric params
2020   anAction = new QtxAction(tr("MNU_SVTK_SCALING"), 
2021                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SCALING" ) ),
2022                            tr( "MNU_SVTK_SCALING" ), 0, this);
2023   anAction->setStatusTip(tr("DSC_SVTK_SCALING"));
2024   anAction->setCheckable(true);
2025   connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onNonIsometric(bool)));
2026   mgr->registerAction( anAction, NonIsometric );
2027
2028   // onGraduatedAxes: Manage graduated axes params
2029   anAction = new QtxAction(tr("MNU_SVTK_GRADUATED_AXES"), 
2030                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_GRADUATED_AXES" ) ),
2031                            tr( "MNU_SVTK_GRADUATED_AXES" ), 0, this);
2032   anAction->setStatusTip(tr("DSC_SVTK_GRADUATED_AXES"));
2033   anAction->setCheckable(true);
2034   connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onGraduatedAxes(bool)));
2035   mgr->registerAction( anAction, GraduatedAxes );
2036
2037   // onGraduatedAxes: Manage graduated axes params
2038   anAction = new QtxAction(tr("MNU_SVTK_UPDATE_RATE"), 
2039                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_UPDATE_RATE" ) ),
2040                            tr( "MNU_SVTK_UPDATE_RATE" ), 0, this);
2041   anAction->setStatusTip(tr("DSC_SVTK_UPDATE_RATE"));
2042   anAction->setCheckable(true);
2043   connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onUpdateRate(bool)));
2044   mgr->registerAction( anAction, UpdateRate );
2045
2046   // Set perspective mode group
2047   anAction = new QtxAction(tr("MNU_SVTK_PARALLEL_MODE"), 
2048                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARALLEL" ) ),
2049                            tr( "MNU_SVTK_PARALLEL_MODE" ), 0, this);
2050   anAction->setStatusTip(tr("DSC_SVTK_PARALLEL_MODE"));
2051   anAction->setCheckable(true);
2052   connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onPerspectiveMode()));
2053   mgr->registerAction( anAction, ParallelModeId );
2054
2055   anAction = new QtxAction(tr("MNU_SVTK_PERSPECTIVE_MODE"), 
2056                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PERSPECTIVE" ) ),
2057                            tr( "MNU_SVTK_PERSPECTIVE_MODE" ), 0, this);
2058   anAction->setStatusTip(tr("DSC_SVTK_PERSPECTIVE_MODE"));
2059   anAction->setCheckable(true);
2060   connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onPerspectiveMode()));
2061   mgr->registerAction( anAction, ProjectionModeId );
2062
2063   QActionGroup* aPerspectiveGroup = new QActionGroup( this );
2064   aPerspectiveGroup->addAction( mgr->action( ParallelModeId ) );
2065   aPerspectiveGroup->addAction( mgr->action( ProjectionModeId ) );
2066
2067   // View Parameters
2068   anAction = new QtxAction(tr("MNU_VIEWPARAMETERS_VIEW"), 
2069                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARAMETERS" ) ),
2070                            tr( "MNU_VIEWPARAMETERS_VIEW" ), 0, this);
2071   anAction->setStatusTip(tr("DSC_VIEWPARAMETERS_VIEW"));
2072   anAction->setCheckable(true);
2073   connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onViewParameters(bool)));
2074   mgr->registerAction( anAction, ViewParametersId );
2075
2076   // Synchronize View 
2077   mgr->registerAction( synchronizeAction(), SynchronizeId );
2078
2079   // Switch between interaction styles
2080   anAction = new QtxAction(tr("MNU_SVTK_STYLE_SWITCH"), 
2081                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_STYLE_SWITCH" ) ),
2082                            tr( "MNU_SVTK_STYLE_SWITCH" ), 0, this);
2083   anAction->setStatusTip(tr("DSC_SVTK_STYLE_SWITCH"));
2084   anAction->setCheckable(true);
2085   connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
2086   mgr->registerAction( anAction, SwitchInteractionStyleId );
2087
2088   // Switch between zooming styles
2089   anAction = new QtxAction(tr("MNU_SVTK_ZOOMING_STYLE_SWITCH"), 
2090                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_ZOOMING_STYLE_SWITCH" ) ),
2091                            tr( "MNU_SVTK_ZOOMING_STYLE_SWITCH" ), 0, this);
2092   anAction->setStatusTip(tr("DSC_SVTK_ZOOMING_STYLE_SWITCH"));
2093   anAction->setCheckable(true);
2094   connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
2095   mgr->registerAction( anAction, SwitchZoomingStyleId );
2096
2097   // Turn on/off dynamic pre-selection
2098   anAction = new QtxAction(tr("MNU_SVTK_DYNAMIC_PRESLECTION_SWITCH"), 
2099                            theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_DYNAMIC_PRESLECTION_SWITCH" ) ),
2100                            tr( "MNU_SVTK_DYNAMIC_PRESLECTION_SWITCH" ), 0, this);
2101   anAction->setStatusTip(tr("DSC_SVTK_DYNAMIC_PRESLECTION_SWITCH"));
2102   anAction->setCheckable(true);
2103   connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchDynamicPreSelection(bool)));
2104   mgr->registerAction( anAction, SwitchDynamicPreselectionId );
2105
2106   // Start recording
2107   myStartAction = new QtxAction(tr("MNU_SVTK_RECORDING_START"), 
2108                                 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_START" ) ),
2109                                 tr( "MNU_SVTK_RECORDING_START" ), 0, this);
2110   myStartAction->setStatusTip(tr("DSC_SVTK_RECORDING_START"));
2111   connect( myStartAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStartRecording() ) );
2112   mgr->registerAction( myStartAction, StartRecordingId );
2113
2114   // Play recording
2115   myPlayAction = new QtxAction(tr("MNU_SVTK_RECORDING_PLAY"), 
2116                                theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PLAY" ) ),
2117                                tr( "MNU_SVTK_RECORDING_PLAY" ), 0, this);
2118   myPlayAction->setStatusTip(tr("DSC_SVTK_RECORDING_PLAY"));
2119   myPlayAction->setEnabled( false );
2120   connect( myPlayAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPlayRecording() ) );
2121   mgr->registerAction( myPlayAction, PlayRecordingId );
2122
2123   // Pause recording
2124   myPauseAction = new QtxAction(tr("MNU_SVTK_RECORDING_PAUSE"), 
2125                                 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PAUSE" ) ),
2126                                 tr( "MNU_SVTK_RECORDING_PAUSE" ), 0, this);
2127   myPauseAction->setStatusTip(tr("DSC_SVTK_RECORDING_PAUSE"));
2128   myPauseAction->setEnabled( false );
2129   connect( myPauseAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPauseRecording() ) );
2130   mgr->registerAction( myPauseAction, PauseRecordingId );
2131
2132   // Stop recording
2133   myStopAction = new QtxAction(tr("MNU_SVTK_RECORDING_STOP"), 
2134                                theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_STOP" ) ),
2135                                tr( "MNU_SVTK_RECORDING_STOP" ), 0, this);
2136   myStopAction->setStatusTip(tr("DSC_SVTK_RECORDING_STOP"));
2137   myStopAction->setEnabled( false );
2138   connect( myStopAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStopRecording() ) );
2139   mgr->registerAction( myStopAction, StopRecordingId );
2140 }
2141
2142 /*!
2143   Creates toolbar of svtk main window
2144 */
2145 void SVTK_ViewWindow::createToolBar()
2146 {
2147   QtxActionToolMgr* mgr = toolMgr();
2148   
2149   mgr->append( DumpId, myToolBar );
2150   mgr->append( SwitchInteractionStyleId, myToolBar );
2151   mgr->append( SwitchZoomingStyleId, myToolBar );
2152   mgr->append( SwitchDynamicPreselectionId, myToolBar );
2153   mgr->append( ViewTrihedronId, myToolBar );
2154
2155   QtxMultiAction* aScaleAction = new QtxMultiAction( this );
2156   aScaleAction->insertAction( getAction( FitAllId ) );
2157   aScaleAction->insertAction( getAction( FitRectId ) );
2158   aScaleAction->insertAction( getAction( ZoomId ) );
2159   mgr->append( aScaleAction, myToolBar );
2160
2161   QtxMultiAction* aPanningAction = new QtxMultiAction( this );
2162   aPanningAction->insertAction( getAction( PanId ) );
2163   aPanningAction->insertAction( getAction( GlobalPanId ) );
2164   mgr->append( aPanningAction, myToolBar );
2165
2166   mgr->append( ChangeRotationPointId, myToolBar );
2167
2168   mgr->append( RotationId, myToolBar );
2169
2170   QtxMultiAction* aViewsAction = new QtxMultiAction( this );
2171   aViewsAction->insertAction( getAction( FrontId ) );
2172   aViewsAction->insertAction( getAction( BackId ) );
2173   aViewsAction->insertAction( getAction( TopId ) );
2174   aViewsAction->insertAction( getAction( BottomId ) );
2175   aViewsAction->insertAction( getAction( LeftId ) );
2176   aViewsAction->insertAction( getAction( RightId ) );
2177   mgr->append( aViewsAction, myToolBar );
2178
2179   mgr->append( AntiClockWiseId, myToolBar );
2180   mgr->append( ClockWiseId, myToolBar );
2181
2182   mgr->append( ResetId, myToolBar );
2183
2184   mgr->append( UpdateRate, myToolBar );
2185   mgr->append( NonIsometric, myToolBar );
2186   mgr->append( GraduatedAxes, myToolBar );
2187
2188   mgr->append( ViewParametersId, myToolBar );
2189   mgr->append( SynchronizeId, myToolBar );
2190
2191   mgr->append( toolMgr()->separator(), myToolBar );
2192
2193   mgr->append( ParallelModeId, myToolBar );
2194   mgr->append( ProjectionModeId, myToolBar );
2195
2196   mgr->append( StartRecordingId, myRecordingToolBar );
2197   mgr->append( PlayRecordingId, myRecordingToolBar );
2198   mgr->append( PauseRecordingId, myRecordingToolBar );
2199   mgr->append( StopRecordingId, myRecordingToolBar );
2200 }
2201
2202 void SVTK_ViewWindow::onUpdateRate(bool theIsActivate)
2203 {
2204   if(theIsActivate){
2205     myUpdateRateDlg->Update();
2206     myUpdateRateDlg->show();
2207   }else
2208     myUpdateRateDlg->hide();
2209 }
2210
2211 void SVTK_ViewWindow::onNonIsometric(bool theIsActivate)
2212 {
2213   if(theIsActivate){
2214     myNonIsometricDlg->Update();
2215     myNonIsometricDlg->show();
2216   }else
2217     myNonIsometricDlg->hide();
2218 }
2219
2220 void SVTK_ViewWindow::onGraduatedAxes(bool theIsActivate)
2221 {
2222   if(theIsActivate){
2223     myCubeAxesDlg->Update();
2224     myCubeAxesDlg->show();
2225   }else
2226     myCubeAxesDlg->hide();
2227 }
2228
2229 /*!
2230   Starts rotation transformation
2231 */
2232 void SVTK_ViewWindow::activateRotation()
2233 {
2234   myEventDispatcher->InvokeEvent(SVTK::StartRotate,0);
2235 }
2236
2237
2238 /*!
2239   Starts panning transformation
2240 */
2241 void SVTK_ViewWindow::activatePanning()
2242 {
2243   myEventDispatcher->InvokeEvent(SVTK::StartPan,0);
2244 }
2245
2246 /*!
2247   Starts zoom transformation
2248 */
2249 void SVTK_ViewWindow::activateZoom()
2250 {
2251   myEventDispatcher->InvokeEvent(SVTK::StartZoom,0);
2252 }
2253
2254 /*!
2255   Starts window fit transformation
2256 */
2257 void SVTK_ViewWindow::activateWindowFit()
2258 {
2259   myEventDispatcher->InvokeEvent(SVTK::StartFitArea,0);
2260 }
2261
2262 /*!
2263   Starts global panning transformation
2264 */
2265 void SVTK_ViewWindow::activateGlobalPanning()
2266 {
2267   myEventDispatcher->InvokeEvent(SVTK::StartGlobalPan,0);
2268 }
2269
2270 void SVTK_ViewWindow::onStartRecording()
2271 {
2272   myRecorder->CheckExistAVIMaker();
2273   if (myRecorder->ErrorStatus()) {
2274     SUIT_MessageBox::warning(this, tr("ERROR"), tr("MSG_NO_AVI_MAKER") );
2275   }
2276   else {
2277     SVTK_RecorderDlg* aRecorderDlg = new SVTK_RecorderDlg( this, myRecorder );
2278
2279     if( !aRecorderDlg->exec() )
2280       return;
2281
2282     myStartAction->setEnabled( false );
2283     myPlayAction->setEnabled( false );
2284     myPauseAction->setEnabled( true );
2285     myStopAction->setEnabled( true );
2286
2287     // to prevent resizing the window while recording
2288     myPreRecordingMinSize = minimumSize();
2289     myPreRecordingMaxSize = maximumSize();
2290     setFixedSize( size() );
2291
2292     myRecorder->Record();
2293   }
2294 }
2295
2296 void SVTK_ViewWindow::onPlayRecording()
2297 {
2298   myStartAction->setEnabled( false );
2299   myPlayAction->setEnabled( false );
2300   myPauseAction->setEnabled( true );
2301   myStopAction->setEnabled( true );
2302
2303   myRecorder->Pause();
2304 }
2305
2306 void SVTK_ViewWindow::onPauseRecording()
2307 {
2308   myStartAction->setEnabled( false );
2309   myPlayAction->setEnabled( true );
2310   myPauseAction->setEnabled( false );
2311   myStopAction->setEnabled( true );
2312
2313   myRecorder->Pause();
2314 }
2315
2316 void SVTK_ViewWindow::onStopRecording()
2317 {
2318   myStartAction->setEnabled( true );
2319   myPlayAction->setEnabled( false );
2320   myPauseAction->setEnabled( false );
2321   myStopAction->setEnabled( false );
2322
2323   myRecorder->Stop();
2324
2325   setMinimumSize( myPreRecordingMinSize );
2326   setMaximumSize( myPreRecordingMaxSize );
2327 }
2328
2329 /*!
2330   To invoke a VTK event on SVTK_RenderWindowInteractor instance
2331 */
2332 void SVTK_ViewWindow::InvokeEvent(unsigned long theEvent, void* theCallData)
2333 {
2334   GetInteractor()->InvokeEvent(theEvent,theCallData);
2335 }
2336
2337 /*!
2338   Modify view parameters
2339 */
2340 void SVTK_ViewWindow::onViewParameters(bool theIsActivate)
2341 {
2342   if(theIsActivate){
2343     myViewParameterDlg->addObserver();
2344     myViewParameterDlg->show();
2345   }else
2346     myViewParameterDlg->hide();
2347 }
2348
2349 /*!
2350   Custom show event handler
2351 */
2352 void SVTK_ViewWindow::showEvent( QShowEvent * theEvent ) 
2353 {
2354   emit Show( theEvent );
2355 }
2356
2357 /*!
2358   Custom hide event handler
2359 */
2360 void SVTK_ViewWindow::hideEvent( QHideEvent * theEvent ) 
2361 {
2362   emit Hide( theEvent );
2363 }
2364
2365 /*!
2366   Emit transformed signal.
2367 */
2368 void SVTK_ViewWindow::emitTransformed() {
2369   transformed(this);
2370 }
2371
2372 /*!
2373   Processes events
2374 */
2375 void SVTK_ViewWindow::ProcessEvents(vtkObject* vtkNotUsed(theObject),
2376                                     unsigned long theEvent,
2377                                     void* theClientData,
2378                                     void* theCallData)
2379 {
2380   SVTK_ViewWindow* self = reinterpret_cast<SVTK_ViewWindow*>(theClientData);
2381   if(self)
2382     self->emitTransformed();
2383 }
2384
2385 /*!
2386   Get camera properties for the SVTK view window.
2387   \return shared pointer on camera properties.
2388 */
2389 SUIT_CameraProperties SVTK_ViewWindow::cameraProperties()
2390 {
2391   SUIT_CameraProperties aProps;
2392
2393   // get vtk camera
2394   vtkCamera* aCamera = getRenderer()->GetActiveCamera();
2395   if ( !aCamera )
2396     return aProps;
2397   
2398   aProps.setDimension( SUIT_CameraProperties::Dim3D );
2399   if ( toolMgr()->action( ParallelModeId ) ) {
2400     if ( toolMgr()->action( ParallelModeId )->isChecked() )
2401       aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
2402     else
2403       aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
2404   }
2405
2406   double aFocalPoint[3];
2407   double aPosition[3];
2408   double aViewUp[3];
2409   double anAxialScale[3];
2410
2411   aCamera->OrthogonalizeViewUp();
2412   aCamera->GetFocalPoint(aFocalPoint);
2413   aCamera->GetPosition(aPosition);
2414   aCamera->GetViewUp(aViewUp);
2415   
2416   aProps.setFocalPoint(aFocalPoint[0], aFocalPoint[1], aFocalPoint[2]);
2417   aProps.setPosition(aPosition[0], aPosition[1], aPosition[2]);
2418   aProps.setViewUp(aViewUp[0], aViewUp[1], aViewUp[2]);
2419   aProps.setMappingScale(aCamera->GetParallelScale());
2420
2421   if (aProps.getProjection() == SUIT_CameraProperties::PrjPerspective)
2422   {
2423     aProps.setViewAngle(aCamera->GetViewAngle());
2424   }
2425
2426   GetRenderer()->GetScale(anAxialScale);
2427   aProps.setAxialScale(anAxialScale[0], anAxialScale[1], anAxialScale[2]);
2428   
2429   return aProps;
2430 }
2431
2432 /*!
2433   Synchronize views.
2434   This implementation synchronizes camera propreties.
2435 */
2436 void SVTK_ViewWindow::synchronize( SUIT_ViewWindow* theView )
2437 {
2438   bool blocked = blockSignals( true );
2439
2440   SUIT_CameraProperties aProps = theView->cameraProperties();
2441   if ( !cameraProperties().isCompatible( aProps ) ) {
2442     // other view, this one is being currently synchronized to, seems has become incompatible
2443     // we have to break synchronization
2444     updateSyncViews();
2445     return;
2446   }
2447
2448   // get camera
2449   vtkCamera* aCamera = getRenderer()->GetActiveCamera();
2450   
2451   double aFocalPoint[3];
2452   double aPosition[3];
2453   double aViewUp[3];
2454   double anAxialScale[3];
2455
2456   // get common properties
2457   aProps.getViewUp(aViewUp[0], aViewUp[1], aViewUp[2]);
2458   aProps.getPosition(aPosition[0], aPosition[1], aPosition[2]);
2459   aProps.getFocalPoint(aFocalPoint[0], aFocalPoint[1], aFocalPoint[2]);
2460   aProps.getAxialScale(anAxialScale[0], anAxialScale[1], anAxialScale[2]);
2461   
2462   // restore properties to the camera
2463   aCamera->SetViewUp(aViewUp);
2464   aCamera->SetPosition(aPosition);
2465   aCamera->SetFocalPoint(aFocalPoint);
2466   aCamera->SetParallelScale(aProps.getMappingScale());
2467
2468   if (aProps.getProjection() == SUIT_CameraProperties::PrjPerspective)
2469   {
2470     aCamera->SetViewAngle(aProps.getViewAngle());
2471   }
2472
2473   GetRenderer()->SetScale(anAxialScale);
2474
2475   getRenderer()->ResetCameraClippingRange();
2476   Repaint(false);
2477
2478   blockSignals( blocked );
2479 }