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