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