1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "SVTK_NonIsometricDlg.h"
24 #include "SVTK_UpdateRateDlg.h"
25 #include "SVTK_CubeAxesDlg.h"
26 #include "SVTK_PsOptionsDlg.h"
27 #include "SVTK_SetRotationPointDlg.h"
28 #include "SVTK_ViewParameterDlg.h"
29 #include "SVTK_ViewModel.h"
30 #include "VTKViewer_Texture.h"
31 #include "VTKViewer_OpenGLRenderer.h"
33 #include "SALOME_Actor.h"
40 #include <QSignalMapper>
41 #include <QXmlStreamWriter>
42 #include <QXmlStreamReader>
43 #include <QXmlStreamAttributes>
45 #include <vtkTextProperty.h>
46 #include <vtkActorCollection.h>
47 #include <vtkRenderWindow.h>
48 #include <vtkRenderer.h>
49 #include <vtkCamera.h>
50 #include <vtkPointPicker.h>
51 #include <vtkCellPicker.h>
52 #include <vtkAxisActor2D.h>
53 #include <vtkGL2PSExporter.h>
54 #include <vtkInteractorStyle.h>
55 #include <vtkProperty.h>
56 #include <vtkCallbackCommand.h>
57 #include <vtkJPEGReader.h>
58 #include <vtkBMPReader.h>
59 #include <vtkTIFFReader.h>
60 #include <vtkPNGReader.h>
61 #include <vtkMetaImageReader.h>
62 #include <vtkImageMapToColors.h>
63 #include <vtkTexture.h>
65 #include "QtxAction.h"
67 #include "SUIT_Session.h"
68 #include "SUIT_MessageBox.h"
69 #include "SUIT_Accel.h"
70 #include "SUIT_Tools.h"
71 #include "SUIT_ResourceMgr.h"
72 #include "SUIT_Accel.h"
73 #include "SUIT_OverrideCursor.h"
74 #include "SUIT_ViewManager.h"
75 #include "QtxActionToolMgr.h"
76 #include "QtxMultiAction.h"
77 #include "QtxActionGroup.h"
79 #include "VTKViewer_Utilities.h"
80 #include "VTKViewer_Trihedron.h"
81 #include "VTKViewer_Actor.h"
83 #include "SVTK_View.h"
84 #include "SVTK_Selector.h"
86 #include "SVTK_Event.h"
87 #include "SVTK_Renderer.h"
88 #include "SVTK_ViewWindow.h"
89 #include "SVTK_InteractorStyle.h"
90 #include "SVTK_RenderWindowInteractor.h"
91 #include "SVTK_GenericRenderWindowInteractor.h"
92 #include "SVTK_CubeAxesActor2D.h"
93 #include "SVTK_ComboAction.h"
94 #include "SVTK_KeyFreeInteractorStyle.h"
95 #include "SVTK_Selector.h"
96 #include "SVTK_Recorder.h"
97 #include "SVTK_RecorderDlg.h"
99 #include "salomevtkPVAxesWidget.h"
100 #include "salomevtkPVAxesActor.h"
102 #include "SALOME_ListIO.hxx"
104 #include "VTKViewer_Algorithm.h"
105 #include "SVTK_Functor.h"
107 #include <OpenGLUtils_FrameBuffer.h>
110 #include <OpenGL/gl.h>
115 // Use workaround for rendering transparent object over MESA
116 #define USE_WORKAROUND_FOR_MESA
120 int convertAction( const int accelAction )
122 switch ( accelAction ) {
123 case SUIT_Accel::PanLeft : return SVTK::PanLeftEvent;
124 case SUIT_Accel::PanRight : return SVTK::PanRightEvent;
125 case SUIT_Accel::PanUp : return SVTK::PanUpEvent;
126 case SUIT_Accel::PanDown : return SVTK::PanDownEvent;
127 case SUIT_Accel::ZoomIn : return SVTK::ZoomInEvent;
128 case SUIT_Accel::ZoomOut : return SVTK::ZoomOutEvent;
129 case SUIT_Accel::RotateLeft : return SVTK::RotateLeftEvent;
130 case SUIT_Accel::RotateRight : return SVTK::RotateRightEvent;
131 case SUIT_Accel::RotateUp : return SVTK::RotateUpEvent;
132 case SUIT_Accel::RotateDown : return SVTK::RotateDownEvent;
141 SVTK_ViewWindow::SVTK_ViewWindow(SUIT_Desktop* theDesktop):
142 SUIT_ViewWindow(theDesktop),
144 myKeyFreeInteractorStyle(SVTK_KeyFreeInteractorStyle::New()),
145 myEventCallbackCommand(vtkCallbackCommand::New()),
146 myDumpImage(QImage())
148 setWindowFlags( windowFlags() & ~Qt::Window );
149 // specific of vtkSmartPointer
150 myKeyFreeInteractorStyle->Delete();
154 To initialize #SVTK_ViewWindow instance
156 void SVTK_ViewWindow::Initialize(SVTK_ViewModelBase* theModel)
159 myInteractor = new SVTK_RenderWindowInteractor(this,"SVTK_RenderWindowInteractor");
161 SVTK_Selector* aSelector = SVTK_Selector::New();
162 int aPreselectionMode = SUIT_Session::session()->resourceMgr()->
163 integerValue( "VTKViewer", "preselection", Standard_Preselection );
164 aSelector->SetDynamicPreSelection( aPreselectionMode == Dynamic_Preselection );
165 aSelector->SetPreSelectionEnabled( aPreselectionMode != Preselection_Disabled );
166 bool isSelectionEnabled = SUIT_Session::session()->resourceMgr()->
167 booleanValue( "VTKViewer", "enable_selection", true );
168 aSelector->SetSelectionEnabled( isSelectionEnabled );
170 SVTK_GenericRenderWindowInteractor* aDevice = SVTK_GenericRenderWindowInteractor::New();
171 aDevice->SetRenderWidget(myInteractor);
172 aDevice->SetSelector(aSelector);
174 SVTK_Renderer* aRenderer = SVTK_Renderer::New();
175 aRenderer->Initialize(aDevice,aSelector);
177 myInteractor->Initialize(aDevice,aRenderer,aSelector);
183 myToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_LABEL"), // title (language-dependant)
184 QString( "VTKViewerViewOperations" ), // name (language-independant)
185 false ); // disable floatable toolbar
187 myRecordingToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_RECORD_LABEL"), // title (language-dependant)
188 QString( "VTKRecordingOperations" ), // name (language-independant)
189 false ); // disable floatable toolbar
191 createActions( SUIT_Session::session()->resourceMgr() );
194 SetEventDispatcher(myInteractor->GetDevice());
195 myInteractor->setBackgroundRole( QPalette::NoRole );//NoBackground
196 myInteractor->setFocusPolicy(Qt::StrongFocus);
197 myInteractor->setFocus();
198 bool isSupportQuadBuffer = SUIT_Session::session()->resourceMgr()->
199 booleanValue( "VTKViewer", "enable_quad_buffer_support", false );
200 myInteractor->getRenderWindow()->SetStereoCapableWindow((int)isSupportQuadBuffer);
201 setFocusProxy(myInteractor);
203 myUpdateRateDlg = new SVTK_UpdateRateDlg( getAction( UpdateRate ), this, "SVTK_UpdateRateDlg" );
204 myNonIsometricDlg = new SVTK_NonIsometricDlg( getAction( NonIsometric ), this, "SVTK_NonIsometricDlg" );
205 myCubeAxesDlg = new SVTK_CubeAxesDlg( getAction( GraduatedAxes ), this, "SVTK_CubeAxesDlg" );
206 myCubeAxesDlg->initialize();
207 mySetRotationPointDlg = new SVTK_SetRotationPointDlg
208 ( getAction( ChangeRotationPointId ), this, "SVTK_SetRotationPointDlg" );
209 myViewParameterDlg = new SVTK_ViewParameterDlg
210 ( getAction( ViewParametersId ), this, "SVTK_ViewParameterDlg" );
212 myDefaultInteractorStyle = SVTK_InteractorStyle::New();
213 myInteractor->PushInteractorStyle(myDefaultInteractorStyle);
214 myDefaultInteractorStyle->Delete();
216 myRecorder = SVTK_Recorder::New();
218 myRecorder->SetNbFPS( 17.3 );
219 myRecorder->SetQuality( 100 );
220 myRecorder->SetProgressiveMode( true );
221 myRecorder->SetUseSkippedFrames( true );
222 myRecorder->SetRenderWindow( myInteractor->getRenderWindow() );
224 setCentralWidget(myInteractor);
226 myAxesWidget = salomevtk::vtkPVAxesWidget::New();
227 myAxesWidget->SetParentRenderer(aRenderer->GetDevice());
228 myAxesWidget->SetViewport(0, 0, 0.25, 0.25);
229 myAxesWidget->SetInteractor(myInteractor->GetDevice());
230 myAxesWidget->SetEnabled(1);
231 myAxesWidget->SetInteractive(0);
233 salomevtk::vtkPVAxesActor* anAxesActor = myAxesWidget->GetAxesActor();
234 anAxesActor->GetXAxisTipProperty()->SetColor( 1.0, 0.0, 0.0 );
235 anAxesActor->GetXAxisShaftProperty()->SetColor( 1.0, 0.0, 0.0 );
236 anAxesActor->GetXAxisLabelProperty()->SetColor( 1.0, 0.0, 0.0 );
237 anAxesActor->GetYAxisTipProperty()->SetColor( 0.0, 1.0, 0.0 );
238 anAxesActor->GetYAxisShaftProperty()->SetColor( 0.0, 1.0, 0.0 );
239 anAxesActor->GetYAxisLabelProperty()->SetColor( 0.0, 1.0, 0.0 );
240 anAxesActor->GetZAxisTipProperty()->SetColor( 0.0, 0.0, 1.0 );
241 anAxesActor->GetZAxisShaftProperty()->SetColor( 0.0, 0.0, 1.0 );
242 anAxesActor->GetZAxisLabelProperty()->SetColor( 0.0, 0.0, 1.0 );
244 myView = new SVTK_View(this);
245 Initialize(myView,theModel);
248 myEventCallbackCommand->SetClientData(this);
249 myEventCallbackCommand->SetCallback(SVTK_ViewWindow::ProcessEvents);
250 myEventCallbackCommand->Delete();
252 GetInteractor()->GetInteractorStyle()->AddObserver(SVTK::OperationFinished,
253 myEventCallbackCommand.GetPointer(), 0.0);
254 myKeyFreeInteractorStyle->AddObserver(SVTK::OperationFinished,
255 myEventCallbackCommand.GetPointer(), 0.0);
257 #ifdef USE_WORKAROUND_FOR_MESA
258 char *mesavar = getenv("SALOME_USE_MESA");
260 getRenderer()->SetUseDepthPeeling(1);
261 #endif //USE_WORKAROUND_FOR_MESA
263 getRenderer()->SetBackgroundAlpha(1.0);
264 myInteractor->getRenderWindow()->SetMultiSamples(0);
265 myInteractor->getRenderWindow()->Render();
266 setBackground( Qtx::BackgroundData( Qt::black ) ); // set default background
271 To initialize #SVTK_ViewWindow instance
273 void SVTK_ViewWindow::Initialize(SVTK_View* theView,
274 SVTK_ViewModelBase* theModel)
276 connect(theView,SIGNAL(KeyPressed(QKeyEvent*)),
277 this,SLOT(onKeyPressed(QKeyEvent*)) );
278 connect(theView,SIGNAL(KeyReleased(QKeyEvent*)),
279 this,SLOT(onKeyReleased(QKeyEvent*)));
280 connect(theView,SIGNAL(MouseButtonPressed(QMouseEvent*)),
281 this,SLOT(onMousePressed(QMouseEvent*)));
282 connect(theView,SIGNAL(MouseButtonReleased(QMouseEvent*)),
283 this,SLOT(onMouseReleased(QMouseEvent*)));
284 connect(theView,SIGNAL(MouseDoubleClicked(QMouseEvent*)),
285 this,SLOT(onMouseDoubleClicked(QMouseEvent*)));
286 connect(theView,SIGNAL(MouseMove(QMouseEvent*)),
287 this,SLOT(onMouseMoving(QMouseEvent*)));
288 connect(theView,SIGNAL(contextMenuRequested(QContextMenuEvent*)),
289 this,SIGNAL(contextMenuRequested(QContextMenuEvent *)));
290 connect(theView,SIGNAL(selectionChanged()),
291 theModel,SLOT(onSelectionChanged()));
293 connect( this, SIGNAL( transformed( SVTK_ViewWindow* ) ), SLOT( emitViewModified() ) );
299 SVTK_ViewWindow::~SVTK_ViewWindow()
301 myRecorder->Delete();
302 myAxesWidget->Delete();
307 \return corresponding view
309 SVTK_View* SVTK_ViewWindow::getView()
315 \return corresponding vtk render window
317 vtkRenderWindow* SVTK_ViewWindow::getRenderWindow()
319 return GetInteractor()->getRenderWindow();
323 \return corresponding vtk render window interactor
325 SVTK_RenderWindowInteractor* SVTK_ViewWindow::GetInteractor() const
331 \return corresponding vtk render window interactor
333 vtkRenderWindowInteractor* SVTK_ViewWindow::getInteractor() const
335 return myInteractor->GetDevice();
339 \return corresponding vtk renderer
341 vtkRenderer* SVTK_ViewWindow::getRenderer() const
343 return GetInteractor()->getRenderer();
347 Redirect the request to SVTK_RenderWindowInteractor::GetRenderer
349 SVTK_Renderer* SVTK_ViewWindow::GetRenderer() const
351 return GetInteractor()->GetRenderer();
355 \return corresponding vtk selector
357 SVTK_Selector* SVTK_ViewWindow::GetSelector() const
359 return GetInteractor()->GetSelector();
363 Processes transformation "front view"
365 void SVTK_ViewWindow::onFrontView()
367 GetRenderer()->OnFrontView();
369 emit transformed( this );
373 Processes transformation "back view"
375 void SVTK_ViewWindow::onBackView()
377 GetRenderer()->OnBackView();
379 emit transformed( this );
383 Processes transformation "top view"
385 void SVTK_ViewWindow::onTopView()
387 GetRenderer()->OnTopView();
389 emit transformed( this );
393 Processes transformation "bottom view"
395 void SVTK_ViewWindow::onBottomView()
397 GetRenderer()->OnBottomView();
399 emit transformed( this );
403 Processes transformation "left view"
405 void SVTK_ViewWindow::onLeftView()
407 GetRenderer()->OnLeftView();
409 emit transformed( this );
413 Processes transformation "right view"
415 void SVTK_ViewWindow::onRightView()
417 GetRenderer()->OnRightView();
419 emit transformed( this );
423 \brief Rotate view 90 degrees clockwise
425 void SVTK_ViewWindow::onClockWiseView()
427 GetRenderer()->onClockWiseView();
429 emit transformed( this );
433 \brief Rotate view 90 degrees conterclockwise
435 void SVTK_ViewWindow::onAntiClockWiseView()
437 GetRenderer()->onAntiClockWiseView();
439 emit transformed( this );
443 Processes transformation "reset view": sets default orientation of viewport camera
445 void SVTK_ViewWindow::onResetView()
447 GetRenderer()->OnResetView();
449 emit transformed( this );
453 Processes transformation "fit all"
455 void SVTK_ViewWindow::onFitAll()
457 GetRenderer()->OnFitAll();
459 emit transformed( this );
463 Processes transformation "fit selection"
465 void SVTK_ViewWindow::onFitSelection()
467 GetRenderer()->onFitSelection();
469 emit transformed( this );
473 Processes transformation "fit given objects"
475 void SVTK_ViewWindow::onFitIObjects(const SALOME_ListIO& objects)
477 GetRenderer()->OnFitIObjects(objects);
479 emit transformed( this );
483 SLOT: called if selection is changed
485 void SVTK_ViewWindow::onSelectionChanged()
487 myView->onSelectionChanged();
491 Change selection mode
492 \param theMode - new selection mode
494 void SVTK_ViewWindow::SetSelectionMode(Selection_Mode theMode)
496 GetSelector()->SetSelectionMode(theMode);
500 \return selection mode
502 Selection_Mode SVTK_ViewWindow::SelectionMode() const
504 return GetSelector()->SelectionMode();
508 Unhilights all objects in viewer
510 void SVTK_ViewWindow::unHighlightAll()
512 myView->unHighlightAll();
516 Hilights/unhilights object in viewer
517 \param theIO - object to be updated
518 \param theIsHighlight - if it is true, object will be hilighted, otherwise it will be unhilighted
519 \param theIsUpdate - update current viewer
521 void SVTK_ViewWindow::highlight(const Handle(SALOME_InteractiveObject)& theIO,
525 myView->highlight( theIO, theIsHighlight, theIsUpdate );
529 \return true if object is in viewer or in collector
530 \param theIO - object to be checked
532 bool SVTK_ViewWindow::isInViewer( const Handle(SALOME_InteractiveObject)& theIO )
534 return myView->isInViewer( theIO );
538 \return true if object is displayed in viewer
539 \param theIO - object to be checked
541 bool SVTK_ViewWindow::isVisible( const Handle(SALOME_InteractiveObject)& theIO )
543 return myView->isVisible( theIO );
548 \param theEntry - entry that corresponds to intractive objects
550 Handle(SALOME_InteractiveObject) SVTK_ViewWindow::FindIObject(const char* theEntry)
552 return myView->FindIObject(theEntry);
557 \param theIO - object
558 \param theImmediatly - update viewer
560 void SVTK_ViewWindow::Display(const Handle(SALOME_InteractiveObject)& theIO,
563 myView->Display(theIO,theImmediatly);
568 \param theIO - object
569 \param theImmediatly - update viewer
571 void SVTK_ViewWindow::Erase(const Handle(SALOME_InteractiveObject)& theIO,
574 myView->Erase(theIO,theImmediatly);
578 Display only passed object
579 \param theIO - object
581 void SVTK_ViewWindow::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIO)
583 myView->DisplayOnly(theIO);
587 Display all objects in view
589 void SVTK_ViewWindow::DisplayAll()
591 myView->DisplayAll();
595 Erase all objects in view
597 void SVTK_ViewWindow::EraseAll()
603 Sets background color [obsolete]
604 \param color - new background color
606 void SVTK_ViewWindow::setBackgroundColor( const QColor& c )
608 Qtx::BackgroundData bg = background();
614 \return background color of viewer [obsolete]
616 QColor SVTK_ViewWindow::backgroundColor() const
618 return background().color();
623 \param bgData - new background data
625 void SVTK_ViewWindow::setBackground( const Qtx::BackgroundData& bgData )
629 if ( bgData.isValid() ) {
630 switch ( bgData.mode() ) {
631 case Qtx::ColorBackground:
633 QColor c = bgData.color();
635 // show solid-colored background
636 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
637 getRenderer()->SetGradientBackground( false ); // cancel gradient mode
638 getRenderer()->SetBackground( c.red()/255.0,
640 c.blue()/255.0 ); // set background color
645 case Qtx::SimpleGradientBackground:
648 int type = bgData.gradient( c1, c2 );
654 // show two-color gradient background
655 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
656 getRenderer()->SetGradientBackground( true ); // switch to gradient mode
658 VTKViewer_OpenGLRenderer* aRenderer =
659 VTKViewer_OpenGLRenderer::SafeDownCast( getRenderer() );
662 aRenderer->SetGradientType( type );
663 aRenderer->SetBackground( c1.redF(), c1.greenF(), c1.blueF() );
664 aRenderer->SetBackground2( c2.redF(), c2.greenF(), c2.blueF() );
670 case Qtx::CustomGradientBackground:
672 // NOT IMPLEMENTED YET
673 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
674 getRenderer()->SetGradientBackground( false ); // cancel gradient mode
681 if ( bgData.isTextureShown() ) {
683 int textureMode = bgData.texture( fileName );
684 QFileInfo fi( fileName );
685 if ( !fileName.isEmpty() && fi.exists() ) {
686 // read texture from file
687 QString extension = fi.suffix().toLower();
688 vtkImageReader2* aReader = 0;
689 if ( extension == "jpg" || extension == "jpeg" )
690 aReader = vtkJPEGReader::New();
691 else if ( extension == "bmp" )
692 aReader = vtkBMPReader::New();
693 else if ( extension == "tif" || extension == "tiff" )
694 aReader = vtkTIFFReader::New();
695 else if ( extension == "png" )
696 aReader = vtkPNGReader::New();
697 else if ( extension == "mhd" || extension == "mha" )
698 aReader = vtkMetaImageReader::New();
701 aReader->SetFileName( fi.absoluteFilePath().toUtf8().constData() );
703 VTKViewer_Texture* aTexture = VTKViewer_Texture::New();
704 vtkImageMapToColors* aMap = 0;
705 vtkAlgorithmOutput* anOutput;
707 // special processing for BMP reader
708 vtkBMPReader* aBMPReader = (vtkBMPReader*)aReader;
710 // Special processing for BMP file
711 aBMPReader->SetAllow8BitBMP(1);
713 aMap = vtkImageMapToColors::New();
714 aMap->SetInputConnection( aBMPReader->GetOutputPort() );
715 aMap->SetLookupTable( (vtkScalarsToColors*)aBMPReader->GetLookupTable() );
716 aMap->SetOutputFormatToRGB();
718 anOutput = aMap->GetOutputPort();
723 anOutput = aReader->GetOutputPort( 0 );
724 aTexture->SetInputConnection( anOutput );
726 // VSR: Currently, VTK only supports Stretch mode, so below code will give
727 // the same results for all modes
728 switch ( textureMode ) {
729 case Qtx::TileTexture:
730 aTexture->SetPosition((int)VTKViewer_Texture::Tiled);
732 case Qtx::StretchTexture:
733 aTexture->SetPosition((int)VTKViewer_Texture::Stretched);
735 case Qtx::CenterTexture:
736 aTexture->SetPosition((int)VTKViewer_Texture::Centered);
740 // show textured background
741 getRenderer()->SetTexturedBackground( true );
742 getRenderer()->SetBackgroundTexture( aTexture );
744 // clean-up resources
755 myBackground = bgData;
759 \return background data of viewer
761 Qtx::BackgroundData SVTK_ViewWindow::background() const
768 Redirect the request to SVTK_RenderWindowInteractor::GetInteractorStyle
770 vtkInteractorStyle* SVTK_ViewWindow::GetInteractorStyle() const
772 return GetInteractor()->GetInteractorStyle();
776 Redirect the request to SVTK_RenderWindowInteractor::PushInteractorStyle
778 void SVTK_ViewWindow::PushInteractorStyle(vtkInteractorStyle* theStyle)
780 GetInteractor()->PushInteractorStyle(theStyle);
784 Redirect the request to SVTK_RenderWindowInteractor::PopInteractorStyle
786 void SVTK_ViewWindow::PopInteractorStyle()
788 GetInteractor()->PopInteractorStyle();
792 Updates current viewer
794 void SVTK_ViewWindow::Repaint(bool theUpdateTrihedron)
796 if(theUpdateTrihedron)
797 GetRenderer()->OnAdjustTrihedron();
799 GetInteractor()->update();
801 SVTK_InteractorStyle* aStyle = (SVTK_InteractorStyle*)getInteractor()->GetInteractorStyle();
803 #ifdef VGL_WORKAROUND
804 if ( aStyle->GetCurrentRenderer() == nullptr ) {
805 if( GetRenderer() ) {
806 aStyle->SetCurrentRenderer(GetRenderer()->GetDevice());
815 Redirect the request to #SVTK_Renderer::GetScale
817 void SVTK_ViewWindow::GetScale( double theScale[3] )
819 GetRenderer()->GetScale( theScale );
823 Redirect the request to #SVTK_Renderer::SetScale
825 void SVTK_ViewWindow::SetScale( double theScale[3] )
827 GetRenderer()->SetScale( theScale );
829 emit transformed( this );
833 Redirect the request to #SVTK_Renderer::IsTrihedronDisplayed
835 bool SVTK_ViewWindow::isTrihedronDisplayed()
837 return GetRenderer()->IsTrihedronDisplayed();
841 Redirect the request to #SVTK_Renderer::IsCubeAxesDisplayed
843 bool SVTK_ViewWindow::isCubeAxesDisplayed()
845 return GetRenderer()->IsCubeAxesDisplayed();
849 Redirect the request to #SVTK_Renderer::OnViewTrihedron
851 void SVTK_ViewWindow::onViewTrihedron(bool show)
853 GetRenderer()->SetTrihedronVisibility(show);
858 Redirect the request to #SVTK_Renderer::OnViewCubeAxes
860 void SVTK_ViewWindow::onViewCubeAxes()
862 GetRenderer()->OnViewCubeAxes();
867 Redirect the request to #SVTK_Renderer::GetTrihedron
869 VTKViewer_Trihedron* SVTK_ViewWindow::GetTrihedron()
871 return GetRenderer()->GetTrihedron();
875 Redirect the request to #SVTK_Renderer::GetCubeAxes
877 SVTK_CubeAxesActor2D* SVTK_ViewWindow::GetCubeAxes()
879 return GetRenderer()->GetCubeAxes();
883 \return trihedron size
885 double SVTK_ViewWindow::GetTrihedronSize() const
887 return GetRenderer()->GetTrihedronSize();
892 \param theMode - projection mode ( 0 - orthogonal, 1 - perspective, 2 - stereo )
894 void SVTK_ViewWindow::SetProjectionMode(const int theMode)
896 QtxAction* aParallelAction = dynamic_cast<QtxAction*>( toolMgr()->action( ParallelModeId ) );
897 QtxAction* aProjectionAction = dynamic_cast<QtxAction*>( toolMgr()->action( ProjectionModeId ) );
898 QtxAction* aStereoAction = dynamic_cast<QtxAction*>( toolMgr()->action( StereoModeId ) );
902 onProjectionMode( aParallelAction );
905 onProjectionMode( aProjectionAction );
908 onStereoMode( true );
912 // update action state if method is called outside
913 SVTK_Viewer* aViewer = dynamic_cast<SVTK_Viewer*>(myModel);
914 QtxAction* aSwitchZoomingStyle = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
915 if ( theMode == Parallel && !aParallelAction->isChecked() ) {
916 aParallelAction->setChecked( true );
917 aSwitchZoomingStyle->setEnabled(true);
918 aStereoAction->setChecked( false );
920 if ( theMode == Projection && !aProjectionAction->isChecked() ) {
921 aProjectionAction->setChecked( true );
922 aSwitchZoomingStyle->setEnabled(false);
924 if ( theMode == Stereo ) {
925 aStereoAction->setChecked( true );
926 if ( aParallelAction->isEnabled() ) {
927 aParallelAction->setEnabled( false );
928 aParallelAction->setChecked( false );
929 aStereoAction->setChecked( false );
932 aParallelAction->setEnabled( true );
933 aStereoAction->setChecked( false );
934 aParallelAction->setChecked( aViewer->projectionMode() == Parallel );
936 if ( aProjectionAction->isEnabled() ) {
937 aProjectionAction->setEnabled( false );
938 aProjectionAction->setChecked( true );
939 if ( getRenderWindow()->GetStereoCapableWindow() == 1 && !isOpenGlStereoSupport() &&
940 strcmp( "CrystalEyes", getRenderWindow()->GetStereoTypeAsString() ) == 0 &&
941 toolMgr()->action( StereoModeId )->isChecked() ) {
942 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
946 aProjectionAction->setEnabled( true );
947 aStereoAction->setChecked( false );
948 aProjectionAction->setChecked( aViewer->projectionMode() == Projection );
953 if ( !aParallelAction->isEnabled() )
954 aParallelAction->setEnabled( true );
955 if ( !aProjectionAction->isEnabled() )
956 aProjectionAction->setEnabled( true );
962 \param theType - stereo type
964 void SVTK_ViewWindow::SetStereoType(const int theType)
966 vtkRenderWindow* aWindow = getRenderWindow();
969 aWindow->SetStereoTypeToCrystalEyes();
972 aWindow->SetStereoTypeToRedBlue();
975 aWindow->SetStereoTypeToInterlaced();
978 aWindow->SetStereoTypeToLeft();
981 aWindow->SetStereoTypeToRight();
984 aWindow->SetStereoTypeToDresden();
987 aWindow->SetStereoTypeToAnaglyph();
990 aWindow->SetStereoTypeToCheckerboard();
992 case SplitViewPortHorizontal:
993 aWindow->SetStereoTypeToSplitViewportHorizontal();
1000 \param theFilter - anaglyph filter
1002 void SVTK_ViewWindow::SetAnaglyphFilter(const int theFilter)
1004 vtkRenderWindow* aWindow = getRenderWindow();
1005 switch (theFilter ) {
1007 aWindow->SetAnaglyphColorMask(4,3);
1010 aWindow->SetAnaglyphColorMask(6,1);
1013 aWindow->SetAnaglyphColorMask(2,5);
1019 Set support quad-buffered stereo
1020 \param theEnable - enable/disable support quad-buffered stereo
1022 void SVTK_ViewWindow::SetQuadBufferSupport(const bool theEnable)
1024 vtkRenderWindow* aWindow = getRenderWindow();
1025 aWindow->SetStereoCapableWindow((int)theEnable);
1029 \return OpenGl stereo support
1031 bool SVTK_ViewWindow::isOpenGlStereoSupport() const
1033 GLboolean support[1];
1034 glGetBooleanv (GL_STEREO, support);
1041 Set the gravity center as a focal point
1043 void SVTK_ViewWindow::activateSetFocalPointGravity()
1045 myEventDispatcher->InvokeEvent(SVTK::SetFocalPointGravity, 0);
1049 Set the selected point as a focal point
1051 void SVTK_ViewWindow::activateSetFocalPointSelected()
1053 myEventDispatcher->InvokeEvent(SVTK::SetFocalPointSelected, 0);
1057 Set the point selected by user as a focal point
1059 void SVTK_ViewWindow::activateStartFocalPointSelection()
1061 myEventDispatcher->InvokeEvent(SVTK::StartFocalPointSelection,0);
1064 void SVTK_ViewWindow::activateProjectionMode(int theMode)
1066 QtxAction* aParallelAction = dynamic_cast<QtxAction*>( toolMgr()->action( ParallelModeId ) );
1067 QtxAction* aProjectionAction = dynamic_cast<QtxAction*>( toolMgr()->action( ProjectionModeId ) );
1069 aParallelAction->setChecked( true );
1071 aProjectionAction->setChecked( true );
1073 if ( !aParallelAction->isEnabled() )
1074 aParallelAction->setEnabled( true );
1075 if ( !aProjectionAction->isEnabled() )
1076 aProjectionAction->setEnabled( true );
1080 Sets actual interaction style
1081 \param theStyle - type of interaction style ( 0 - standard, 1 - keyboard free )
1083 void SVTK_ViewWindow::SetInteractionStyle(const int theStyle)
1085 onSwitchInteractionStyle( theStyle==1 );
1089 Sets actual zooming style
1090 \param theStyle - type of zooming style ( 0 - standard, 1 - advanced (at cursor) )
1092 void SVTK_ViewWindow::SetZoomingStyle(const int theStyle)
1094 onSwitchZoomingStyle( theStyle==1 );
1098 Set preselection mode.
1099 \param theMode the mode to set (standard, dynamic or disabled)
1101 void SVTK_ViewWindow::SetPreSelectionMode( Preselection_Mode theMode )
1103 onSwitchPreSelectionMode( theMode );
1107 Enables/disables selection.
1108 \param theEnable if true - selection will be enabled
1110 void SVTK_ViewWindow::SetSelectionEnabled( bool theEnable )
1112 GetSelector()->SetSelectionEnabled( theEnable );
1113 QtxAction* a = getAction( EnableSelectionId );
1114 if ( a->isChecked() != theEnable)
1115 a->setChecked( theEnable );
1116 QtxActionGroup* aPreselectionGroup =
1117 dynamic_cast<QtxActionGroup*>( getAction( PreselectionId ) );
1118 if ( aPreselectionGroup )
1119 aPreselectionGroup->setEnabled( theEnable );
1122 vtkActorCollection *actors = getRenderer()->GetActors();
1123 for (int i = 0; i < actors->GetNumberOfItems(); ++i )
1124 if (VTKViewer_Actor *actor = dynamic_cast<VTKViewer_Actor*>(actors->GetItemAsObject(i)))
1126 actor->EnableSelection( theEnable );
1131 Switches "keyboard free" interaction style on/off
1133 void SVTK_ViewWindow::onSwitchInteractionStyle(bool theOn)
1136 // check if style is already set
1137 if ( GetInteractorStyle() != myKeyFreeInteractorStyle.GetPointer() )
1139 // keep the same style extensions
1140 SVTK_InteractorStyle* aStyle = (SVTK_InteractorStyle*)GetInteractorStyle();
1142 myKeyFreeInteractorStyle->SetControllerIncrement(aStyle->ControllerIncrement());
1143 myKeyFreeInteractorStyle->SetControllerOnKeyDown(aStyle->ControllerOnKeyDown());
1146 PushInteractorStyle(myKeyFreeInteractorStyle.GetPointer());
1150 // pop only key free style
1151 if ( GetInteractorStyle() == myKeyFreeInteractorStyle.GetPointer() )
1152 PopInteractorStyle();
1155 // update action state if method is called outside
1156 QtxAction* a = getAction( SwitchInteractionStyleId );
1157 if ( a->isChecked() != theOn ) a->setChecked( theOn );
1161 Toogles advanced zooming style (relatively to the cursor position) on/off
1163 void SVTK_ViewWindow::onSwitchZoomingStyle( bool theOn )
1165 if( myDefaultInteractorStyle.GetPointer() )
1166 myDefaultInteractorStyle->SetAdvancedZoomingEnabled( theOn );
1167 if( myKeyFreeInteractorStyle.GetPointer() )
1168 myKeyFreeInteractorStyle->SetAdvancedZoomingEnabled( theOn );
1170 // update action state if method is called outside
1171 QtxAction* a = getAction( SwitchZoomingStyleId );
1172 if ( a->isChecked() != theOn )
1173 a->setChecked( theOn );
1177 Switch preselection mode.
1178 \param theMode the preselection mode
1180 void SVTK_ViewWindow::onSwitchPreSelectionMode( int theMode )
1182 GetSelector()->SetDynamicPreSelection( theMode == Dynamic_Preselection );
1183 GetSelector()->SetPreSelectionEnabled( theMode != Preselection_Disabled );
1185 // update action state if method is called outside
1186 QtxAction* a = getAction( StandardPreselectionId + theMode );
1187 if ( a && !a->isChecked() )
1188 a->setChecked( true );
1192 Enables/disables selection.
1193 \param theOn if true - selection will be enabled
1195 void SVTK_ViewWindow::onEnableSelection( bool on )
1197 SVTK_Viewer* aViewer = dynamic_cast<SVTK_Viewer*>(myModel);
1199 aViewer->enableSelection(on);
1203 Sets incremental speed
1204 \param theValue - new incremental speed
1205 \param theMode - modification mode
1207 void SVTK_ViewWindow::SetIncrementalSpeed(const int theValue, const int theMode)
1209 if ( (SVTK_InteractorStyle*)GetInteractorStyle() )
1210 ((SVTK_InteractorStyle*)GetInteractorStyle())->SetIncrementSpeed(theValue, theMode);
1214 Sets spacemouse buttons for the functions
1215 \param theBtn1 - spacemouse button for the "decrease speed increment"
1216 \param theBtn2 - spacemouse button for the "increase speed increment"
1217 \param theBtn3 - spacemouse button for the "dominant combined switch"
1219 void SVTK_ViewWindow::SetSpacemouseButtons(const int theBtn1,
1224 myEventDispatcher->InvokeEvent(SVTK::SetSMDecreaseSpeedEvent, &val);
1226 myEventDispatcher->InvokeEvent(SVTK::SetSMIncreaseSpeedEvent, &val);
1228 myEventDispatcher->InvokeEvent(SVTK::SetSMDominantCombinedSwitchEvent, &val);
1233 \param theSize - new trihedron size
1234 \param theRelative - trihedron relativeness
1236 void SVTK_ViewWindow::SetTrihedronSize(const double theSize, const bool theRelative)
1238 GetRenderer()->SetTrihedronSize(theSize, theRelative);
1242 /*! If parameter theIsForcedUpdate is true, recalculate parameters for
1243 * trihedron and cube axes, even if trihedron and cube axes is invisible.
1245 void SVTK_ViewWindow::AdjustTrihedrons(const bool /*theIsForcedUpdate*/)
1247 GetRenderer()->AdjustActors();
1252 Redirect the request to #SVTK_Renderer::OnAdjustTrihedron
1254 void SVTK_ViewWindow::onAdjustTrihedron()
1256 GetRenderer()->OnAdjustTrihedron();
1260 Redirect the request to #SVTK_Renderer::OnAdjustCubeAxes
1262 void SVTK_ViewWindow::onAdjustCubeAxes()
1264 GetRenderer()->OnAdjustCubeAxes();
1267 void SVTK_ViewWindow::synchronize(SVTK_ViewWindow* otherViewWindow )
1269 if ( otherViewWindow ) {
1270 bool blocked = blockSignals( true );
1271 doSetVisualParameters( otherViewWindow->getVisualParameters(), true );
1272 blockSignals( blocked );
1279 void SVTK_ViewWindow::onKeyPressed(QKeyEvent* event)
1281 emit keyPressed( this, event );
1287 void SVTK_ViewWindow::onKeyReleased(QKeyEvent* event)
1289 emit keyReleased( this, event );
1295 void SVTK_ViewWindow::onMousePressed(QMouseEvent* event)
1297 emit mousePressed(this, event);
1301 Emits mouse released
1303 void SVTK_ViewWindow::onMouseReleased(QMouseEvent* event)
1305 emit mouseReleased( this, event );
1311 void SVTK_ViewWindow::onMouseMoving(QMouseEvent* event)
1313 emit mouseMoving( this, event );
1317 Emits mouse double clicked
1319 void SVTK_ViewWindow::onMouseDoubleClicked( QMouseEvent* event )
1321 emit mouseDoubleClicked( this, event );
1325 Redirect the request to #SVTK_Renderer::AddActor
1327 void SVTK_ViewWindow::AddActor( VTKViewer_Actor* theActor,
1329 bool theIsAdjustActors )
1331 GetRenderer()->AddActor(theActor, theIsAdjustActors);
1334 emit actorAdded(theActor);
1338 Redirect the request to #SVTK_Renderer::RemoveActor
1340 void SVTK_ViewWindow::RemoveActor( VTKViewer_Actor* theActor,
1342 bool theIsAdjustActors )
1344 GetRenderer()->RemoveActor(theActor, theIsAdjustActors);
1345 if ( myDefaultInteractorStyle )
1346 myDefaultInteractorStyle->FreeActors();
1347 if ( myKeyFreeInteractorStyle )
1348 myKeyFreeInteractorStyle->FreeActors();
1351 emit actorRemoved(theActor);
1354 QImage SVTK_ViewWindow::dumpViewContent()
1356 vtkRenderWindow* aWindow = getRenderWindow();
1357 int* aSize = aWindow->GetSize();
1358 int aWidth = aSize[0];
1359 int aHeight = aSize[1];
1361 #ifndef DISABLE_GLVIEWER
1362 OpenGLUtils_FrameBuffer aFrameBuffer;
1363 if( aFrameBuffer.init( aWidth, aHeight ) )
1365 glPushAttrib( GL_VIEWPORT_BIT );
1366 glViewport( 0, 0, aWidth, aHeight );
1367 aFrameBuffer.bind();
1372 //aFrameBuffer.unbind();
1375 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
1376 //aFrameBuffer.bind();
1378 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
1379 aFrameBuffer.unbind();
1381 anImage = anImage.rgbSwapped();
1382 anImage = anImage.mirrored();
1387 // if frame buffers are unsupported, use old functionality
1388 unsigned char *aData =
1389 aWindow->GetRGBACharPixelData( 0, 0, aWidth-1, aHeight-1, 0 );
1391 QImage anImage( aData, aWidth, aHeight, QImage::Format_ARGB32 );
1393 anImage = anImage.rgbSwapped();
1394 anImage = anImage.mirrored();
1399 \return QImage, containing all scene rendering in window
1401 QImage SVTK_ViewWindow::dumpView()
1403 if( myDumpImage.isNull() )
1404 return dumpViewContent();
1410 QString SVTK_ViewWindow::filter() const
1412 return tr( "SVTK_IMAGE_FILES" );
1415 bool SVTK_ViewWindow::dumpViewToFormat( const QImage& img, const QString& fileName, const QString& format )
1417 if ( format != "PS" && format != "EPS" && format != "PDF" )
1418 return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
1420 SVTK_PsOptionsDlg* optionsDlg = new SVTK_PsOptionsDlg(this);
1421 if ( optionsDlg->exec() == QDialog::Accepted ) {
1422 SUIT_OverrideCursor wc;
1424 vtkGL2PSExporter *anExporter = vtkGL2PSExporter::New();
1425 anExporter->SetRenderWindow(getRenderWindow());
1428 anExporter->SetLineWidthFactor(optionsDlg->getLineFactor());
1429 anExporter->SetPointSizeFactor(optionsDlg->getPointFactor());
1430 anExporter->SetSort((vtkGL2PSExporter::SortScheme)optionsDlg->getSortType());
1431 anExporter->SetWrite3DPropsAsRasterImage((int)optionsDlg->isRasterize3D());
1432 anExporter->SetPS3Shading((int)optionsDlg->isPs3Shading());
1434 if ( format == "PS" ) {
1435 anExporter->SetFileFormatToPS();
1436 anExporter->CompressOff();
1439 if ( format == "EPS" ) {
1440 anExporter->SetFileFormatToEPS();
1441 anExporter->CompressOff();
1444 if ( format == "PDF" ) {
1445 anExporter->SetFileFormatToPDF();
1448 QString aFilePrefix(fileName);
1449 QString anExtension(SUIT_Tools::extension(fileName));
1450 aFilePrefix.truncate(aFilePrefix.length() - 1 - anExtension.length());
1451 anExporter->SetFilePrefix(aFilePrefix.toUtf8().data());
1452 anExporter->Write();
1453 anExporter->Delete();
1460 \refresh QImage, containing all scene rendering in window
1462 void SVTK_ViewWindow::RefreshDumpImage()
1464 myDumpImage = dumpViewContent();
1468 Redirect the request to #SVTK_Renderer::SetSelectionProp
1470 void SVTK_ViewWindow::SetSelectionProp(const double& theRed,
1471 const double& theGreen,
1472 const double& theBlue,
1473 const int& theWidth)
1475 myView->SetSelectionProp(theRed,theGreen,theBlue,theWidth);
1479 Redirect the request to #SVTK_Renderer::SetSelectionProp
1481 void SVTK_ViewWindow::SetPreselectionProp(const double& theRed,
1482 const double& theGreen,
1483 const double& theBlue,
1484 const int& theWidth)
1486 myView->SetPreselectionProp(theRed,theGreen,theBlue,theWidth);
1490 Redirect the request to #SVTK_Renderer::SetSelectionTolerance
1492 void SVTK_ViewWindow::SetSelectionTolerance(const double& theTolNodes,
1493 const double& theTolItems,
1494 const double& theTolObjects)
1496 myView->SetSelectionTolerance(theTolNodes, theTolItems, theTolObjects);
1500 Get visibility status of the static trihedron
1502 bool SVTK_ViewWindow::IsStaticTrihedronVisible() const
1504 return (bool)myAxesWidget->GetEnabled();
1508 Set visibility status of the static trihedron
1510 void SVTK_ViewWindow::SetStaticTrihedronVisible( const bool theIsVisible )
1512 myAxesWidget->SetEnabled( (int)theIsVisible );
1517 \param accelAction - action
1519 bool SVTK_ViewWindow::action( const int accelAction )
1521 if ( accelAction == SUIT_Accel::ZoomFit )
1524 int anEvent = SVTK::convertAction( accelAction );
1525 GetInteractor()->InvokeEvent(anEvent, 0);
1531 \return action by it's id
1533 QtxAction* SVTK_ViewWindow::getAction( int id ) const
1535 return dynamic_cast<QtxAction*>( toolMgr()->action( id ) );
1539 // old visual parameters had 13 values. New format added additional
1540 // 76 values for graduated axes, so both numbers are processed.
1541 const int nNormalParams = 13; // number of view windows parameters excluding graduated axes params
1542 const int nGradAxisParams = 25; // number of parameters of ONE graduated axis (X, Y, or Z)
1543 const int nTrihedronParams = 3; // number of parameters for Trihedron
1544 const int nAllParams = nNormalParams + 3*nGradAxisParams + nTrihedronParams + 1; // number of all visual parameters
1546 /*! The method returns visual parameters of a graduated axis actor (x,y,z axis of graduated axes)
1548 void getGradAxisVisualParams( QXmlStreamWriter& writer, vtkAxisActor2D* actor, QString theAxis )
1555 bool isVisible = actor->GetTitleVisibility();
1556 QString title ( actor->GetTitle() );
1558 int font = VTK_ARIAL;
1563 vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1566 txtProp->GetColor( color );
1567 font = txtProp->GetFontFamily();
1568 bold = txtProp->GetBold();
1569 italic = txtProp->GetItalic();
1570 shadow = txtProp->GetShadow();
1572 writer.writeStartElement("GraduatedAxis");
1573 writer.writeAttribute("Axis", theAxis);
1575 writer.writeStartElement("Title");
1576 writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1577 writer.writeAttribute("Text", title);
1578 writer.writeAttribute("Font", QString("%1").arg(font));
1579 writer.writeAttribute("Bold", QString("%1").arg(bold));
1580 writer.writeAttribute("Italic", QString("%1").arg(italic));
1581 writer.writeAttribute("Shadow", QString("%1").arg(shadow));
1583 writer.writeStartElement("Color");
1584 writer.writeAttribute("R", QString("%1").arg(color[0]));
1585 writer.writeAttribute("G", QString("%1").arg(color[1]));
1586 writer.writeAttribute("B", QString("%1").arg(color[2]));
1587 writer.writeEndElement();
1588 writer.writeEndElement();
1590 //params.sprintf( "* Graduated Axis: * Name *%u*%s*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible,
1591 // title.toLatin1().data(), color[0], color[1], color[2], font, bold, italic, shadow );
1594 isVisible = actor->GetLabelVisibility();
1595 int labels = actor->GetNumberOfLabels();
1596 int offset = actor->GetTickOffset();
1602 txtProp = actor->GetLabelTextProperty();
1605 txtProp->GetColor( color );
1606 font = txtProp->GetFontFamily();
1607 bold = txtProp->GetBold();
1608 italic = txtProp->GetItalic();
1609 shadow = txtProp->GetShadow();
1612 writer.writeStartElement("Labels");
1613 writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1614 writer.writeAttribute("Number", QString("%1").arg(labels));
1615 writer.writeAttribute("Offset", QString("%1").arg(offset));
1616 writer.writeAttribute("Font", QString("%1").arg(font));
1617 writer.writeAttribute("Bold", QString("%1").arg(bold));
1618 writer.writeAttribute("Italic", QString("%1").arg(italic));
1619 writer.writeAttribute("Shadow", QString("%1").arg(shadow));
1621 writer.writeStartElement("Color");
1622 writer.writeAttribute("R", QString("%1").arg(color[0]));
1623 writer.writeAttribute("G", QString("%1").arg(color[1]));
1624 writer.writeAttribute("B", QString("%1").arg(color[2]));
1625 writer.writeEndElement();
1626 writer.writeEndElement();
1627 // params += QString().sprintf( "* Labels *%u*%u*%u*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible, labels, offset,
1628 // color[0], color[1], color[2], font, bold, italic, shadow );
1631 isVisible = actor->GetTickVisibility();
1632 int length = actor->GetTickLength();
1633 writer.writeStartElement("TickMarks");
1634 writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1635 writer.writeAttribute("Length", QString("%1").arg(length));
1636 writer.writeEndElement();
1638 //params += QString().sprintf( "* Tick marks *%u*%u", isVisible, length );
1640 writer.writeEndElement();
1644 void setGradAxisVisualParams(QXmlStreamReader& reader, vtkAxisActor2D* actor)
1651 } while (!reader.isStartElement());
1653 // Read title params
1654 QXmlStreamAttributes aAttr = reader.attributes();
1655 bool isVisible = aAttr.value("isVisible").toString().toUShort();
1656 QString title = aAttr.value("Text").toString();
1657 int font = aAttr.value("Font").toString().toInt();
1658 int bold = aAttr.value("Bold").toString().toInt();
1659 int italic = aAttr.value("Italic").toString().toInt();
1660 int shadow = aAttr.value("Shadow").toString().toInt();
1662 //printf("#### TITLE: %i, %s, %i, %i, %i, %i\n", isVisible, qPrintable(title), font, bold, italic, shadow);
1666 } while (!reader.isStartElement());
1669 aAttr = reader.attributes();
1672 color[0] = aAttr.value("R").toString().toDouble();
1673 color[1] = aAttr.value("G").toString().toDouble();
1674 color[2] = aAttr.value("B").toString().toDouble();
1675 //printf("#### Color: %f, %f, %f\n", color[0], color[1], color[2]);
1677 actor->SetTitleVisibility( isVisible );
1678 actor->SetTitle( title.toUtf8() );
1679 vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1681 txtProp->SetColor( color );
1682 txtProp->SetFontFamily( font );
1683 txtProp->SetBold( bold );
1684 txtProp->SetItalic( italic );
1685 txtProp->SetShadow( shadow );
1692 } while (!reader.isStartElement());
1694 aAttr = reader.attributes();
1695 isVisible = aAttr.value("isVisible").toString().toUShort();
1696 int labels = aAttr.value("Number").toString().toInt();
1697 int offset = aAttr.value("Offset").toString().toInt();
1698 font = aAttr.value("Font").toString().toInt();
1699 bold = aAttr.value("Bold").toString().toInt();
1700 italic = aAttr.value("Italic").toString().toInt();
1701 shadow = aAttr.value("Shadow").toString().toInt();
1705 } while (!reader.isStartElement());
1707 aAttr = reader.attributes();
1709 color[0] = aAttr.value("R").toString().toDouble();
1710 color[1] = aAttr.value("G").toString().toDouble();
1711 color[2] = aAttr.value("B").toString().toDouble();
1713 actor->SetLabelVisibility( isVisible );
1714 actor->SetNumberOfLabels( labels );
1715 actor->SetTickOffset( offset );
1716 txtProp = actor->GetLabelTextProperty();
1718 txtProp->SetColor( color );
1719 txtProp->SetFontFamily( font );
1720 txtProp->SetBold( bold );
1721 txtProp->SetItalic( italic );
1722 txtProp->SetShadow( shadow );
1728 } while (!reader.isStartElement());
1729 aAttr = reader.attributes();
1731 // retrieve and set tick marks properties
1732 isVisible = aAttr.value("isVisible").toString().toUShort();
1733 int length = aAttr.value("Length").toString().toInt();
1735 actor->SetTickVisibility( isVisible );
1736 actor->SetTickLength( length );
1739 /*! The method restores visual parameters of a graduated axis actor (x,y,z axis)
1741 void setGradAxisVisualParams( vtkAxisActor2D* actor, const QString& params )
1746 QStringList paramsLst = params.split( '*' );
1748 if ( paramsLst.size() == nGradAxisParams ) { // altogether name, lable, ticks parameters make up 25 values
1750 // retrieve and set name parameters
1751 bool isVisible = paramsLst[2].toUShort();
1752 QString title = paramsLst[3];
1754 color[0] = paramsLst[4].toDouble();
1755 color[1] = paramsLst[5].toDouble();
1756 color[2] = paramsLst[6].toDouble();
1757 int font = paramsLst[7].toInt();
1758 int bold = paramsLst[8].toInt();
1759 int italic = paramsLst[9].toInt();
1760 int shadow = paramsLst[10].toInt();
1762 actor->SetTitleVisibility( isVisible );
1763 actor->SetTitle( title.toUtf8() );
1764 vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1766 txtProp->SetColor( color );
1767 txtProp->SetFontFamily( font );
1768 txtProp->SetBold( bold );
1769 txtProp->SetItalic( italic );
1770 txtProp->SetShadow( shadow );
1773 // retrieve and set lable parameters
1774 isVisible = paramsLst[12].toUShort();
1775 int labels = paramsLst[13].toInt();
1776 int offset = paramsLst[14].toInt();
1777 color[0] = paramsLst[15].toDouble();
1778 color[1] = paramsLst[16].toDouble();
1779 color[2] = paramsLst[17].toDouble();
1780 font = paramsLst[18].toInt();
1781 bold = paramsLst[19].toInt();
1782 italic = paramsLst[20].toInt();
1783 shadow = paramsLst[21].toInt();
1785 actor->SetLabelVisibility( isVisible );
1786 actor->SetNumberOfLabels( labels );
1787 actor->SetTickOffset( offset );
1788 txtProp = actor->GetLabelTextProperty();
1790 txtProp->SetColor( color );
1791 txtProp->SetFontFamily( font );
1792 txtProp->SetBold( bold );
1793 txtProp->SetItalic( italic );
1794 txtProp->SetShadow( shadow );
1797 // retrieve and set tick marks properties
1798 isVisible = paramsLst[23].toUShort();
1799 int length = paramsLst[24].toInt();
1801 actor->SetTickVisibility( isVisible );
1802 actor->SetTickLength( length );
1806 /*! The method returns the visual parameters of this view as a formated string
1808 QString SVTK_ViewWindow::getVisualParameters()
1810 double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
1812 // save position, focal point, viewUp, scale
1813 vtkCamera* camera = getRenderer()->GetActiveCamera();
1814 camera->GetPosition( pos );
1815 camera->GetFocalPoint( focalPnt );
1816 camera->GetViewUp( viewUp );
1817 parScale = camera->GetParallelScale();
1820 // Parameters are given in the following format:view position (3 digits), focal point position (3 digits)
1821 // view up values (3 digits), parallel scale (1 digit), scale (3 digits,
1822 // Graduated axes parameters (X, Y, Z axes parameters)
1824 QXmlStreamWriter aWriter(&retStr);
1825 aWriter.setAutoFormatting(true);
1827 aWriter.writeStartDocument();
1828 aWriter.writeStartElement("ViewState");
1830 aWriter.writeStartElement("Position");
1831 aWriter.writeAttribute("X", QString("%1").arg(pos[0]));
1832 aWriter.writeAttribute("Y", QString("%1").arg(pos[1]));
1833 aWriter.writeAttribute("Z", QString("%1").arg(pos[2]));
1834 aWriter.writeEndElement();
1836 aWriter.writeStartElement("FocalPoint");
1837 aWriter.writeAttribute("X", QString::number(focalPnt[0]));
1838 aWriter.writeAttribute("Y", QString::number(focalPnt[1]));
1839 aWriter.writeAttribute("Z", QString::number(focalPnt[2]));
1840 aWriter.writeEndElement();
1842 aWriter.writeStartElement("ViewUp");
1843 aWriter.writeAttribute("X", QString::number(viewUp[0]));
1844 aWriter.writeAttribute("Y", QString::number(viewUp[1]));
1845 aWriter.writeAttribute("Z", QString::number(viewUp[2]));
1846 aWriter.writeEndElement();
1848 aWriter.writeStartElement("ViewScale");
1849 aWriter.writeAttribute("Parallel", QString::number(parScale));
1850 aWriter.writeAttribute("X", QString::number(scale[0]));
1851 aWriter.writeAttribute("Y", QString::number(scale[1]));
1852 aWriter.writeAttribute("Z", QString::number(scale[2]));
1853 aWriter.writeEndElement();
1855 if ( SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes() ) {
1856 aWriter.writeStartElement("DisplayCubeAxis");
1857 aWriter.writeAttribute("Show", QString( "%1" ).arg( GetRenderer()->IsCubeAxesDisplayed()));
1858 aWriter.writeEndElement();
1860 getGradAxisVisualParams(aWriter, gradAxesActor->GetXAxisActor2D(), "X");
1861 getGradAxisVisualParams(aWriter, gradAxesActor->GetYAxisActor2D(), "Y");
1862 getGradAxisVisualParams(aWriter, gradAxesActor->GetZAxisActor2D(), "Z");
1865 aWriter.writeStartElement("Trihedron");
1866 aWriter.writeAttribute("isShown", QString( "%1" ).arg( isTrihedronDisplayed()));
1867 aWriter.writeAttribute("Size", QString::number(GetTrihedronSize()));
1868 aWriter.writeEndElement();
1870 aWriter.writeStartElement("Background");
1871 aWriter.writeAttribute("Value", QString( "%1" ).arg( Qtx::backgroundToString(background()) ));
1872 aWriter.writeEndElement();
1874 aWriter.writeEndElement();
1875 aWriter.writeEndDocument();
1881 The method restores visual parameters of this view or postpones it untill the view is shown
1883 void SVTK_ViewWindow::setVisualParameters( const QString& parameters )
1885 //printf("#### %s\n", qPrintable(parameters));
1886 SVTK_RenderWindowInteractor* anInteractor = GetInteractor();
1887 if ( anInteractor->isVisible() ) {
1888 doSetVisualParameters( parameters );
1891 myVisualParams = parameters;
1892 anInteractor->installEventFilter(this);
1897 The method restores visual parameters of this view from a formated string
1899 void SVTK_ViewWindow::doSetVisualParameters( const QString& parameters, bool baseParamsOnly )
1902 double pos[3], focalPnt[3], viewUp[3], parScale = 1.0, scale[3];
1904 QXmlStreamReader aReader(parameters);
1905 SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes();
1907 while(!aReader.atEnd()) {
1909 if (aReader.isStartElement()) {
1910 QXmlStreamAttributes aAttr = aReader.attributes();
1911 //printf("### Name = %s\n", qPrintable(aReader.name().toString()));
1912 if (aReader.name() == "Position") {
1913 pos[0] = aAttr.value("X").toString().toDouble();
1914 pos[1] = aAttr.value("Y").toString().toDouble();
1915 pos[2] = aAttr.value("Z").toString().toDouble();
1916 //printf("#### Position %f; %f; %f\n", pos[0], pos[1], pos[2]);
1918 else if (aReader.name() == "FocalPoint") {
1919 focalPnt[0] = aAttr.value("X").toString().toDouble();
1920 focalPnt[1] = aAttr.value("Y").toString().toDouble();
1921 focalPnt[2] = aAttr.value("Z").toString().toDouble();
1922 //printf("#### FocalPoint %f; %f; %f\n", focalPnt[0], focalPnt[1], focalPnt[2]);
1924 else if (aReader.name() == "ViewUp") {
1925 viewUp[0] = aAttr.value("X").toString().toDouble();
1926 viewUp[1] = aAttr.value("Y").toString().toDouble();
1927 viewUp[2] = aAttr.value("Z").toString().toDouble();
1928 //printf("#### ViewUp %f; %f; %f\n", viewUp[0], viewUp[1], viewUp[2]);
1930 else if (aReader.name() == "ViewScale") {
1931 parScale = aAttr.value("Parallel").toString().toDouble();
1932 scale[0] = aAttr.value("X").toString().toDouble();
1933 scale[1] = aAttr.value("Y").toString().toDouble();
1934 scale[2] = aAttr.value("Z").toString().toDouble();
1935 //printf("#### ViewScale %f; %f; %f\n", scale[0], scale[1], scale[2]);
1937 else if (aReader.name() == "DisplayCubeAxis") {
1938 if ( !baseParamsOnly ) {
1939 if (aAttr.value("Show") == "0")
1940 gradAxesActor->VisibilityOff();
1942 gradAxesActor->VisibilityOn();
1945 else if (aReader.name() == "GraduatedAxis") {
1946 if ( !baseParamsOnly ) {
1947 if(aAttr.value("Axis") == "X")
1948 setGradAxisVisualParams(aReader, gradAxesActor->GetXAxisActor2D());
1949 else if(aAttr.value("Axis") == "Y")
1950 setGradAxisVisualParams(aReader, gradAxesActor->GetYAxisActor2D());
1951 else if(aAttr.value("Axis") == "Z")
1952 setGradAxisVisualParams(aReader, gradAxesActor->GetZAxisActor2D());
1955 else if (aReader.name() == "Trihedron") {
1956 if ( !baseParamsOnly ) {
1957 if (aAttr.value("isShown") == "0")
1958 GetTrihedron()->VisibilityOff();
1960 GetTrihedron()->VisibilityOn();
1961 SetTrihedronSize(aAttr.value("Size").toString().toDouble());
1964 else if (aReader.name() == "Background") {
1965 if ( !baseParamsOnly ) {
1966 setBackground( Qtx::stringToBackground( aAttr.value("Value").toString() ) );
1971 if (!aReader.hasError()) {
1972 vtkCamera* camera = getRenderer()->GetActiveCamera();
1973 camera->SetPosition( pos );
1974 camera->SetFocalPoint( focalPnt );
1975 camera->SetViewUp( viewUp );
1976 camera->SetParallelScale( parScale );
1977 GetRenderer()->SetScale( scale );
1978 //SetScale( scale );
1981 QStringList paramsLst = parameters.split( '*' );
1982 if ( paramsLst.size() >= nNormalParams ) {
1983 // 'reading' list of parameters
1984 pos[0] = paramsLst[0].toDouble();
1985 pos[1] = paramsLst[1].toDouble();
1986 pos[2] = paramsLst[2].toDouble();
1987 focalPnt[0] = paramsLst[3].toDouble();
1988 focalPnt[1] = paramsLst[4].toDouble();
1989 focalPnt[2] = paramsLst[5].toDouble();
1990 viewUp[0] = paramsLst[6].toDouble();
1991 viewUp[1] = paramsLst[7].toDouble();
1992 viewUp[2] = paramsLst[8].toDouble();
1993 parScale = paramsLst[9].toDouble();
1994 scale[0] = paramsLst[10].toDouble();
1995 scale[1] = paramsLst[11].toDouble();
1996 scale[2] = paramsLst[12].toDouble();
1998 // applying parameters
1999 vtkCamera* camera = getRenderer()->GetActiveCamera();
2000 camera->SetPosition( pos );
2001 camera->SetFocalPoint( focalPnt );
2002 camera->SetViewUp( viewUp );
2003 camera->SetParallelScale( parScale );
2004 GetRenderer()->SetScale( scale );
2005 //SetScale( scale );
2007 // apply graduated axes parameters
2008 if ( !baseParamsOnly ) {
2009 SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes();
2010 if ( gradAxesActor && paramsLst.size() == nAllParams ) {
2011 int i = nNormalParams+1, j = i + nGradAxisParams - 1;
2012 ::setGradAxisVisualParams( gradAxesActor->GetXAxisActor2D(), parameters.section( '*', i, j ) );
2013 i = j + 1; j += nGradAxisParams;
2014 ::setGradAxisVisualParams( gradAxesActor->GetYAxisActor2D(), parameters.section( '*', i, j ) );
2015 i = j + 1; j += nGradAxisParams;
2016 ::setGradAxisVisualParams( gradAxesActor->GetZAxisActor2D(), parameters.section( '*', i, j ) );
2018 if ( paramsLst[13].toUShort() )
2019 gradAxesActor->VisibilityOn();
2021 gradAxesActor->VisibilityOff();
2023 else if ( paramsLst.size() == nAllParams ) {
2024 if ( paramsLst[90].toUShort() )
2025 GetTrihedron()->VisibilityOn();
2027 GetTrihedron()->VisibilityOff();
2029 SetTrihedronSize(paramsLst[91].toDouble());
2039 Delayed setVisualParameters
2041 bool SVTK_ViewWindow::eventFilter( QObject* theWatched, QEvent* theEvent )
2043 if ( theEvent->type() == QEvent::Show && theWatched->inherits( "SVTK_RenderWindowInteractor" ) ) {
2044 SVTK_RenderWindowInteractor* anInteractor = (SVTK_RenderWindowInteractor*)theWatched;
2045 if ( anInteractor->isVisible() ) {
2046 doSetVisualParameters( myVisualParams );
2047 anInteractor->removeEventFilter( this ); // theWatched = RenderWindowInteractor
2050 return SUIT_ViewWindow::eventFilter( theWatched, theEvent );
2055 Change rotation point
2057 void SVTK_ViewWindow::onChangeRotationPoint(bool theIsActivate)
2060 mySetRotationPointDlg->addObserver();
2061 if ( mySetRotationPointDlg->IsFirstShown() )
2062 activateSetRotationGravity();
2063 mySetRotationPointDlg->show();
2065 mySetRotationPointDlg->hide();
2069 Set the gravity center as a rotation point
2071 void SVTK_ViewWindow::activateSetRotationGravity()
2073 myEventDispatcher->InvokeEvent(SVTK::SetRotateGravity,0);
2077 Set the selected point as a rotation point
2079 void SVTK_ViewWindow::activateSetRotationSelected(void* theData)
2081 myEventDispatcher->InvokeEvent(SVTK::ChangeRotationPoint,theData);
2085 Set the gravity center of element selected by user as a rotation point
2087 void SVTK_ViewWindow::activateStartPointSelection( Selection_Mode theSelectionMode )
2089 SetSelectionMode( theSelectionMode );
2090 myEventDispatcher->InvokeEvent(SVTK::StartPointSelection,0);
2094 \brief Set the given projection mode.
2096 Set the given projection mode: Orthographic or Perspective.
2098 void SVTK_ViewWindow::onProjectionMode( QAction* theAction )
2100 int aMode = Parallel;
2101 if (theAction == toolMgr()->action( ProjectionModeId ))
2103 SVTK_Viewer* aViewer = dynamic_cast<SVTK_Viewer*>(myModel);
2104 aViewer->setProjectionMode(aMode);
2105 bool anIsParallelMode = (aMode == Parallel);
2106 vtkCamera* aCamera = getRenderer()->GetActiveCamera();
2107 aCamera->SetParallelProjection(anIsParallelMode);
2108 GetInteractor()->GetDevice()->CreateTimer(VTKI_TIMER_FIRST);
2109 getRenderWindow()->SetStereoRender(0);
2114 \brief Sets Stereo projection mode.
2116 Sets Stereo projection mode.
2118 void SVTK_ViewWindow::onStereoMode( bool activate )
2121 toolMgr()->action( ProjectionModeId )->setChecked(true);
2122 vtkCamera* aCamera = getRenderer()->GetActiveCamera();
2123 aCamera->SetParallelProjection(false);
2124 toolMgr()->action( ProjectionModeId )->actionGroup()->setEnabled(false);
2125 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
2126 SetStereoType( aResMgr->integerValue( "VTKViewer", "stereo_type", 0 ) );
2127 getRenderWindow()->SetStereoRender(1);
2131 toolMgr()->action( ProjectionModeId )->actionGroup()->setEnabled(true);
2132 SVTK_Viewer* aViewer = dynamic_cast<SVTK_Viewer*>(myModel);
2133 if (aViewer->projectionMode() == Parallel) {
2134 toolMgr()->action( ParallelModeId )->setChecked(true);
2135 onProjectionMode(toolMgr()->action( ParallelModeId ));
2137 else if (aViewer->projectionMode() == Projection) {
2138 toolMgr()->action( ProjectionModeId )->setChecked(true);
2139 onProjectionMode(toolMgr()->action( ProjectionModeId ));
2142 if ( getRenderWindow()->GetStereoCapableWindow() == 1 && !isOpenGlStereoSupport() &&
2143 strcmp( "CrystalEyes", getRenderWindow()->GetStereoTypeAsString() ) == 0 &&
2144 toolMgr()->action( StereoModeId )->isChecked() )
2145 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
2149 Set the view projection mode: orthogonal or perspective
2151 void SVTK_ViewWindow::onProjectionMode()
2153 if (toolMgr()->action( ParallelModeId )->isChecked())
2154 SetProjectionMode( Parallel);
2155 if (toolMgr()->action( ProjectionModeId )->isChecked())
2156 SetProjectionMode( Projection);
2157 if (toolMgr()->action( StereoModeId )->isChecked())
2158 SetProjectionMode( Stereo);
2159 emit transformed( this );
2162 void SVTK_ViewWindow::SetEventDispatcher(vtkObject* theDispatcher)
2164 myEventDispatcher = theDispatcher;
2168 Creates all actions of svtk main window
2170 void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
2172 QtxAction* anAction;
2173 QtxActionToolMgr* mgr = toolMgr();
2176 anAction = new QtxAction(tr("MNU_DUMP_VIEW"),
2177 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
2178 tr( "MNU_DUMP_VIEW" ), 0, this);
2179 anAction->setStatusTip(tr("DSC_DUMP_VIEW"));
2180 connect(anAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
2181 mgr->registerAction( anAction, DumpId );
2184 anAction = new QtxAction(tr("MNU_FITALL"),
2185 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
2186 tr( "MNU_FITALL" ), 0, this);
2187 anAction->setStatusTip(tr("DSC_FITALL"));
2188 connect(anAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
2189 mgr->registerAction( anAction, FitAllId );
2192 anAction = new QtxAction(tr("MNU_FITRECT"),
2193 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
2194 tr( "MNU_FITRECT" ), 0, this);
2195 anAction->setStatusTip(tr("DSC_FITRECT"));
2196 connect(anAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
2197 mgr->registerAction( anAction, FitRectId );
2200 anAction = new QtxAction(tr("MNU_FITSELECTION"),
2201 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITSELECTION" ) ),
2202 tr( "MNU_FITSELECTION" ), 0, this);
2203 anAction->setStatusTip(tr("DSC_FITSELECTION"));
2204 connect(anAction, SIGNAL(triggered()), this, SLOT(onFitSelection()));
2205 mgr->registerAction( anAction, FitSelectionId );
2208 anAction = new QtxAction(tr("MNU_ZOOM_VIEW"),
2209 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
2210 tr( "MNU_ZOOM_VIEW" ), 0, this);
2211 anAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
2212 connect(anAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
2213 mgr->registerAction( anAction, ZoomId );
2216 anAction = new QtxAction(tr("MNU_PAN_VIEW"),
2217 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
2218 tr( "MNU_PAN_VIEW" ), 0, this);
2219 anAction->setStatusTip(tr("DSC_PAN_VIEW"));
2220 connect(anAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
2221 mgr->registerAction( anAction, PanId );
2224 anAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"),
2225 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
2226 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
2227 anAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
2228 connect(anAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
2229 mgr->registerAction( anAction, GlobalPanId );
2231 // Change rotation point
2232 anAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"),
2233 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_ROTATION_POINT" ) ),
2234 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
2235 anAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
2236 anAction->setCheckable(true);
2237 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onChangeRotationPoint(bool)));
2238 mgr->registerAction( anAction, ChangeRotationPointId );
2241 anAction = new QtxAction(tr("MNU_ROTATE_VIEW"),
2242 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
2243 tr( "MNU_ROTATE_VIEW" ), 0, this);
2244 anAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
2245 connect(anAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
2246 mgr->registerAction( anAction, RotationId );
2249 anAction = new QtxAction(tr("MNU_FRONT_VIEW"),
2250 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
2251 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
2252 anAction->setStatusTip(tr("DSC_FRONT_VIEW"));
2253 connect(anAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
2254 this->addAction(anAction);
2255 mgr->registerAction( anAction, FrontId );
2257 anAction = new QtxAction(tr("MNU_BACK_VIEW"),
2258 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
2259 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
2260 anAction->setStatusTip(tr("DSC_BACK_VIEW"));
2261 connect(anAction, SIGNAL(triggered()), this, SLOT(onBackView()));
2262 this->addAction(anAction);
2263 mgr->registerAction( anAction, BackId );
2265 anAction = new QtxAction(tr("MNU_TOP_VIEW"),
2266 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
2267 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
2268 anAction->setStatusTip(tr("DSC_TOP_VIEW"));
2269 connect(anAction, SIGNAL(triggered()), this, SLOT(onTopView()));
2270 this->addAction(anAction);
2271 mgr->registerAction( anAction, TopId );
2273 anAction = new QtxAction(tr("MNU_BOTTOM_VIEW"),
2274 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
2275 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
2276 anAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
2277 connect(anAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
2278 this->addAction(anAction);
2279 mgr->registerAction( anAction, BottomId );
2281 anAction = new QtxAction(tr("MNU_LEFT_VIEW"),
2282 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
2283 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
2284 anAction->setStatusTip(tr("DSC_LEFT_VIEW"));
2285 connect(anAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
2286 this->addAction(anAction);
2287 mgr->registerAction( anAction, LeftId );
2289 anAction = new QtxAction(tr("MNU_RIGHT_VIEW"),
2290 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
2291 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
2292 anAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
2293 connect(anAction, SIGNAL(triggered()), this, SLOT(onRightView()));
2294 this->addAction(anAction);
2295 mgr->registerAction( anAction, RightId );
2297 // rotate anticlockwise
2298 anAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"),
2299 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ANTICLOCKWISE" ) ),
2300 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
2301 anAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
2302 connect(anAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
2303 this->addAction(anAction);
2304 mgr->registerAction( anAction, AntiClockWiseId );
2307 anAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"),
2308 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_CLOCKWISE" ) ),
2309 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
2310 anAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
2311 connect(anAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
2312 this->addAction(anAction);
2313 mgr->registerAction( anAction, ClockWiseId );
2316 anAction = new QtxAction(tr("MNU_RESET_VIEW"),
2317 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
2318 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
2319 anAction->setStatusTip(tr("DSC_RESET_VIEW"));
2320 connect(anAction, SIGNAL(triggered()), this, SLOT(onResetView()));
2321 this->addAction(anAction);
2322 mgr->registerAction( anAction, ResetId );
2324 // onViewTrihedron: Shows - Hides Trihedron
2325 anAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"),
2326 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ),
2327 tr( "MNU_SHOW_TRIHEDRON" ), 0, this);
2328 anAction->setCheckable( true );
2329 anAction->setChecked( true );
2331 anAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON"));
2332 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onViewTrihedron(bool)));
2333 mgr->registerAction( anAction, ViewTrihedronId );
2335 // onNonIsometric: Manage non-isometric params
2336 anAction = new QtxAction(tr("MNU_SVTK_SCALING"),
2337 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SCALING" ) ),
2338 tr( "MNU_SVTK_SCALING" ), 0, this);
2339 anAction->setStatusTip(tr("DSC_SVTK_SCALING"));
2340 anAction->setCheckable(true);
2341 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onNonIsometric(bool)));
2342 mgr->registerAction( anAction, NonIsometric );
2344 // onGraduatedAxes: Manage graduated axes params
2345 anAction = new QtxAction(tr("MNU_SVTK_GRADUATED_AXES"),
2346 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_GRADUATED_AXES" ) ),
2347 tr( "MNU_SVTK_GRADUATED_AXES" ), 0, this);
2348 anAction->setStatusTip(tr("DSC_SVTK_GRADUATED_AXES"));
2349 anAction->setCheckable(true);
2350 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onGraduatedAxes(bool)));
2351 mgr->registerAction( anAction, GraduatedAxes );
2353 // onGraduatedAxes: Manage graduated axes params
2354 anAction = new QtxAction(tr("MNU_SVTK_UPDATE_RATE"),
2355 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_UPDATE_RATE" ) ),
2356 tr( "MNU_SVTK_UPDATE_RATE" ), 0, this);
2357 anAction->setStatusTip(tr("DSC_SVTK_UPDATE_RATE"));
2358 anAction->setCheckable(true);
2359 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onUpdateRate(bool)));
2360 mgr->registerAction( anAction, UpdateRate );
2362 // Set perspective mode group
2363 anAction = new QtxAction(tr("MNU_SVTK_PARALLEL_MODE"),
2364 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARALLEL" ) ),
2365 tr( "MNU_SVTK_PARALLEL_MODE" ), 0, this);
2366 anAction->setStatusTip(tr("DSC_SVTK_PARALLEL_MODE"));
2367 anAction->setCheckable(true);
2368 mgr->registerAction( anAction, ParallelModeId );
2370 anAction = new QtxAction(tr("MNU_SVTK_PERSPECTIVE_MODE"),
2371 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PERSPECTIVE" ) ),
2372 tr( "MNU_SVTK_PERSPECTIVE_MODE" ), 0, this);
2373 anAction->setStatusTip(tr("DSC_SVTK_PERSPECTIVE_MODE"));
2374 anAction->setCheckable(true);
2375 mgr->registerAction( anAction, ProjectionModeId );
2377 anAction = new QtxAction(tr("MNU_SVTK_STEREO_MODE"),
2378 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_STEREO" ) ),
2379 tr( "MNU_SVTK_STEREO_MODE" ), 0, this);
2380 anAction->setStatusTip(tr("DSC_SVTK_STEREO_MODE"));
2381 anAction->setCheckable(true);
2382 connect(anAction, SIGNAL(triggered(bool)), this, SLOT(onStereoMode(bool)));
2383 mgr->registerAction( anAction, StereoModeId );
2385 QActionGroup* aPerspectiveGroup = new QActionGroup( this );
2386 aPerspectiveGroup->addAction( mgr->action( ParallelModeId ) );
2387 aPerspectiveGroup->addAction( mgr->action( ProjectionModeId ) );
2388 connect(aPerspectiveGroup, SIGNAL(triggered(QAction*)), this, SLOT(onProjectionMode(QAction*)));
2391 anAction = new QtxAction(tr("MNU_VIEWPARAMETERS_VIEW"),
2392 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARAMETERS" ) ),
2393 tr( "MNU_VIEWPARAMETERS_VIEW" ), 0, this);
2394 anAction->setStatusTip(tr("DSC_VIEWPARAMETERS_VIEW"));
2395 anAction->setCheckable(true);
2396 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onViewParameters(bool)));
2397 mgr->registerAction( anAction, ViewParametersId );
2400 mgr->registerAction( synchronizeAction(), SynchronizeId );
2402 // Switch between interaction styles
2403 anAction = new QtxAction(tr("MNU_SVTK_STYLE_SWITCH"),
2404 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_STYLE_SWITCH" ) ),
2405 tr( "MNU_SVTK_STYLE_SWITCH" ), 0, this);
2406 anAction->setStatusTip(tr("DSC_SVTK_STYLE_SWITCH"));
2407 anAction->setCheckable(true);
2408 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
2409 mgr->registerAction( anAction, SwitchInteractionStyleId );
2411 // Switch between zooming styles
2412 anAction = new QtxAction(tr("MNU_SVTK_ZOOMING_STYLE_SWITCH"),
2413 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_ZOOMING_STYLE_SWITCH" ) ),
2414 tr( "MNU_SVTK_ZOOMING_STYLE_SWITCH" ), 0, this);
2415 anAction->setStatusTip(tr("DSC_SVTK_ZOOMING_STYLE_SWITCH"));
2416 anAction->setCheckable(true);
2417 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
2418 mgr->registerAction( anAction, SwitchZoomingStyleId );
2421 QSignalMapper* aSignalMapper = new QSignalMapper( this );
2422 connect(aSignalMapper, SIGNAL(mapped(int)), this, SLOT(onSwitchPreSelectionMode(int)));
2424 anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_STANDARD"),
2425 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_STANDARD" ) ),
2426 tr( "MNU_SVTK_PRESELECTION_STANDARD" ), 0, this);
2427 anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_STANDARD"));
2428 anAction->setCheckable(true);
2429 connect(anAction, SIGNAL(triggered()), aSignalMapper, SLOT(map()));
2430 aSignalMapper->setMapping( anAction, Standard_Preselection );
2431 mgr->registerAction( anAction, StandardPreselectionId );
2433 anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_DYNAMIC"),
2434 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_DYNAMIC" ) ),
2435 tr( "MNU_SVTK_PRESELECTION_DYNAMIC" ), 0, this);
2436 anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_DYNAMIC"));
2437 anAction->setCheckable(true);
2438 connect(anAction, SIGNAL(triggered()), aSignalMapper, SLOT(map()));
2439 aSignalMapper->setMapping( anAction, Dynamic_Preselection );
2440 mgr->registerAction( anAction, DynamicPreselectionId );
2442 anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_DISABLED"),
2443 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_DISABLED" ) ),
2444 tr( "MNU_SVTK_PRESELECTION_DISABLED" ), 0, this);
2445 anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_DISABLED"));
2446 anAction->setCheckable(true);
2447 connect(anAction, SIGNAL(triggered()), aSignalMapper, SLOT(map()));
2448 aSignalMapper->setMapping( anAction, Preselection_Disabled );
2449 mgr->registerAction( anAction, DisablePreselectionId );
2451 QtxActionGroup* aPreselectionAction = new QtxActionGroup( this, true );
2452 aPreselectionAction->add( getAction( StandardPreselectionId ) );
2453 aPreselectionAction->add( getAction( DynamicPreselectionId ) );
2454 aPreselectionAction->add( getAction( DisablePreselectionId ) );
2455 mgr->registerAction( aPreselectionAction, PreselectionId );
2458 anAction = new QtxAction(tr("MNU_SVTK_ENABLE_SELECTION"),
2459 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SELECTION" ) ),
2460 tr( "MNU_SVTK_ENABLE_SELECTION" ), 0, this);
2461 anAction->setStatusTip(tr("DSC_SVTK_ENABLE_SELECTION"));
2462 anAction->setCheckable(true);
2463 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onEnableSelection(bool)));
2464 mgr->registerAction( anAction, EnableSelectionId );
2467 myStartAction = new QtxAction(tr("MNU_SVTK_RECORDING_START"),
2468 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_START" ) ),
2469 tr( "MNU_SVTK_RECORDING_START" ), 0, this);
2470 myStartAction->setStatusTip(tr("DSC_SVTK_RECORDING_START"));
2471 connect( myStartAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStartRecording() ) );
2472 mgr->registerAction( myStartAction, StartRecordingId );
2475 myPlayAction = new QtxAction(tr("MNU_SVTK_RECORDING_PLAY"),
2476 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PLAY" ) ),
2477 tr( "MNU_SVTK_RECORDING_PLAY" ), 0, this);
2478 myPlayAction->setStatusTip(tr("DSC_SVTK_RECORDING_PLAY"));
2479 myPlayAction->setEnabled( false );
2480 connect( myPlayAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPlayRecording() ) );
2481 mgr->registerAction( myPlayAction, PlayRecordingId );
2484 myPauseAction = new QtxAction(tr("MNU_SVTK_RECORDING_PAUSE"),
2485 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PAUSE" ) ),
2486 tr( "MNU_SVTK_RECORDING_PAUSE" ), 0, this);
2487 myPauseAction->setStatusTip(tr("DSC_SVTK_RECORDING_PAUSE"));
2488 myPauseAction->setEnabled( false );
2489 connect( myPauseAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPauseRecording() ) );
2490 mgr->registerAction( myPauseAction, PauseRecordingId );
2493 myStopAction = new QtxAction(tr("MNU_SVTK_RECORDING_STOP"),
2494 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_STOP" ) ),
2495 tr( "MNU_SVTK_RECORDING_STOP" ), 0, this);
2496 myStopAction->setStatusTip(tr("DSC_SVTK_RECORDING_STOP"));
2497 myStopAction->setEnabled( false );
2498 connect( myStopAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStopRecording() ) );
2499 mgr->registerAction( myStopAction, StopRecordingId );
2503 Creates toolbar of svtk main window
2505 void SVTK_ViewWindow::createToolBar()
2507 QtxActionToolMgr* mgr = toolMgr();
2509 mgr->append( DumpId, myToolBar );
2510 mgr->append( SwitchInteractionStyleId, myToolBar );
2511 mgr->append( SwitchZoomingStyleId, myToolBar );
2513 mgr->append( mgr->separator(), myToolBar );
2515 mgr->append( PreselectionId, myToolBar );
2516 mgr->append( EnableSelectionId, myToolBar );
2518 mgr->append( mgr->separator(), myToolBar );
2520 mgr->append( ViewTrihedronId, myToolBar );
2522 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
2523 aScaleAction->insertAction( getAction( FitAllId ) );
2524 aScaleAction->insertAction( getAction( FitRectId ) );
2525 aScaleAction->insertAction( getAction( FitSelectionId ) );
2526 aScaleAction->insertAction( getAction( ZoomId ) );
2527 mgr->append( aScaleAction, myToolBar );
2529 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
2530 aPanningAction->insertAction( getAction( PanId ) );
2531 aPanningAction->insertAction( getAction( GlobalPanId ) );
2532 mgr->append( aPanningAction, myToolBar );
2534 mgr->append( ChangeRotationPointId, myToolBar );
2536 mgr->append( RotationId, myToolBar );
2538 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
2539 aViewsAction->insertAction( getAction( FrontId ) );
2540 aViewsAction->insertAction( getAction( BackId ) );
2541 aViewsAction->insertAction( getAction( TopId ) );
2542 aViewsAction->insertAction( getAction( BottomId ) );
2543 aViewsAction->insertAction( getAction( LeftId ) );
2544 aViewsAction->insertAction( getAction( RightId ) );
2545 mgr->append( aViewsAction, myToolBar );
2547 mgr->append( AntiClockWiseId, myToolBar );
2548 mgr->append( ClockWiseId, myToolBar );
2550 mgr->append( ResetId, myToolBar );
2552 mgr->append( UpdateRate, myToolBar );
2553 mgr->append( NonIsometric, myToolBar );
2554 mgr->append( GraduatedAxes, myToolBar );
2556 mgr->append( ViewParametersId, myToolBar );
2557 mgr->append( SynchronizeId, myToolBar );
2559 mgr->append( toolMgr()->separator(), myToolBar );
2561 mgr->append( ParallelModeId, myToolBar );
2562 mgr->append( ProjectionModeId, myToolBar );
2563 mgr->append( StereoModeId, myToolBar );
2565 mgr->append( StartRecordingId, myRecordingToolBar );
2566 mgr->append( PlayRecordingId, myRecordingToolBar );
2567 mgr->append( PauseRecordingId, myRecordingToolBar );
2568 mgr->append( StopRecordingId, myRecordingToolBar );
2571 void SVTK_ViewWindow::onUpdateRate(bool theIsActivate)
2574 myUpdateRateDlg->Update();
2575 myUpdateRateDlg->show();
2577 myUpdateRateDlg->hide();
2580 void SVTK_ViewWindow::onNonIsometric(bool theIsActivate)
2583 myNonIsometricDlg->Update();
2584 myNonIsometricDlg->show();
2586 myNonIsometricDlg->hide();
2589 void SVTK_ViewWindow::onGraduatedAxes(bool theIsActivate)
2592 myCubeAxesDlg->Update();
2593 myCubeAxesDlg->show();
2595 myCubeAxesDlg->hide();
2599 Starts rotation transformation
2601 void SVTK_ViewWindow::activateRotation()
2603 myEventDispatcher->InvokeEvent(SVTK::StartRotate,0);
2608 Starts panning transformation
2610 void SVTK_ViewWindow::activatePanning()
2612 myEventDispatcher->InvokeEvent(SVTK::StartPan,0);
2616 Starts zoom transformation
2618 void SVTK_ViewWindow::activateZoom()
2620 myEventDispatcher->InvokeEvent(SVTK::StartZoom,0);
2624 Starts window fit transformation
2626 void SVTK_ViewWindow::activateWindowFit()
2628 myEventDispatcher->InvokeEvent(SVTK::StartFitArea,0);
2632 Starts global panning transformation
2634 void SVTK_ViewWindow::activateGlobalPanning()
2636 myEventDispatcher->InvokeEvent(SVTK::StartGlobalPan,0);
2639 void SVTK_ViewWindow::onStartRecording()
2641 myRecorder->CheckExistAVIMaker();
2642 if (myRecorder->ErrorStatus()) {
2643 SUIT_MessageBox::warning(this, tr("ERROR"), tr("MSG_NO_AVI_MAKER") );
2646 SVTK_RecorderDlg* aRecorderDlg = new SVTK_RecorderDlg( this, myRecorder );
2648 if( !aRecorderDlg->exec() )
2651 myStartAction->setEnabled( false );
2652 myPlayAction->setEnabled( false );
2653 myPauseAction->setEnabled( true );
2654 myStopAction->setEnabled( true );
2656 // to prevent resizing the window while recording
2657 myPreRecordingMinSize = minimumSize();
2658 myPreRecordingMaxSize = maximumSize();
2659 setFixedSize( size() );
2661 myRecorder->Record();
2665 void SVTK_ViewWindow::onPlayRecording()
2667 myStartAction->setEnabled( false );
2668 myPlayAction->setEnabled( false );
2669 myPauseAction->setEnabled( true );
2670 myStopAction->setEnabled( true );
2672 myRecorder->Pause();
2675 void SVTK_ViewWindow::onPauseRecording()
2677 myStartAction->setEnabled( false );
2678 myPlayAction->setEnabled( true );
2679 myPauseAction->setEnabled( false );
2680 myStopAction->setEnabled( true );
2682 myRecorder->Pause();
2685 void SVTK_ViewWindow::onStopRecording()
2687 myStartAction->setEnabled( true );
2688 myPlayAction->setEnabled( false );
2689 myPauseAction->setEnabled( false );
2690 myStopAction->setEnabled( false );
2694 setMinimumSize( myPreRecordingMinSize );
2695 setMaximumSize( myPreRecordingMaxSize );
2699 To invoke a VTK event on SVTK_RenderWindowInteractor instance
2701 void SVTK_ViewWindow::InvokeEvent(unsigned long theEvent, void* theCallData)
2703 GetInteractor()->InvokeEvent(theEvent,theCallData);
2707 Modify view parameters
2709 void SVTK_ViewWindow::onViewParameters(bool theIsActivate)
2712 myViewParameterDlg->addObserver();
2713 myViewParameterDlg->show();
2715 myViewParameterDlg->hide();
2719 Custom show event handler
2721 void SVTK_ViewWindow::showEvent( QShowEvent * theEvent )
2723 emit Show( theEvent );
2727 Custom hide event handler
2729 void SVTK_ViewWindow::hideEvent( QHideEvent * theEvent )
2731 emit Hide( theEvent );
2735 Emit transformed signal.
2737 void SVTK_ViewWindow::emitTransformed() {
2744 void SVTK_ViewWindow::ProcessEvents(vtkObject* vtkNotUsed(theObject),
2745 unsigned long /*theEvent*/,
2746 void* theClientData,
2747 void* /*theCallData*/)
2749 SVTK_ViewWindow* self = reinterpret_cast<SVTK_ViewWindow*>(theClientData);
2751 self->emitTransformed();
2755 Get camera properties for the SVTK view window.
2756 \return shared pointer on camera properties.
2758 SUIT_CameraProperties SVTK_ViewWindow::cameraProperties()
2760 SUIT_CameraProperties aProps;
2763 vtkCamera* aCamera = getRenderer()->GetActiveCamera();
2767 aProps.setDimension( SUIT_CameraProperties::Dim3D );
2768 if ( toolMgr()->action( ParallelModeId ) ) {
2769 if ( toolMgr()->action( ParallelModeId )->isChecked() )
2770 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
2772 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
2775 double aFocalPoint[3];
2776 double aPosition[3];
2778 double anAxialScale[3];
2780 aCamera->OrthogonalizeViewUp();
2781 aCamera->GetFocalPoint( aFocalPoint );
2782 aCamera->GetPosition( aPosition );
2783 aCamera->GetViewUp( aViewUp );
2785 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2786 aProps.setPosition( aPosition[0], aPosition[1], aPosition[2] );
2787 aProps.setViewUp( aViewUp[0], aViewUp[1], aViewUp[2] );
2788 aProps.setMappingScale( aCamera->GetParallelScale() * 2.0 );
2790 if ( aProps.getProjection() == SUIT_CameraProperties::PrjPerspective )
2792 aProps.setViewAngle( aCamera->GetViewAngle() );
2795 GetRenderer()->GetScale( anAxialScale );
2796 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2803 This implementation synchronizes camera propreties.
2805 void SVTK_ViewWindow::synchronize( SUIT_ViewWindow* theView )
2807 bool blocked = blockSignals( true );
2809 SUIT_CameraProperties aProps = theView->cameraProperties();
2810 if ( !cameraProperties().isCompatible( aProps ) ) {
2811 // other view, this one is being currently synchronized to, seems has become incompatible
2812 // we have to break synchronization
2818 vtkCamera* aCamera = getRenderer()->GetActiveCamera();
2820 double aFocalPoint[3];
2821 double aPosition[3];
2823 double anAxialScale[3];
2825 // get common properties
2826 aProps.getViewUp( aViewUp[0], aViewUp[1], aViewUp[2] );
2827 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
2828 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2829 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2831 // restore properties to the camera
2832 aCamera->SetViewUp( aViewUp );
2833 aCamera->SetPosition( aPosition );
2834 aCamera->SetFocalPoint( aFocalPoint );
2835 aCamera->SetParallelScale( aProps.getMappingScale() / 2.0 );
2837 if ( aProps.getProjection() == SUIT_CameraProperties::PrjPerspective )
2839 aCamera->SetViewAngle( aProps.getViewAngle() );
2842 GetRenderer()->SetScale( anAxialScale );
2844 getRenderer()->ResetCameraClippingRange();
2847 blockSignals( blocked );
2850 void SVTK_ViewWindow::resizeEvent( QResizeEvent* theEvent )
2852 #ifdef VGL_WORKAROUND