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