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