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