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