1 // Copyright (C) 2007-2015 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_SetRotationPointDlg.h"
27 #include "SVTK_ViewParameterDlg.h"
28 #include "SVTK_ViewModel.h"
29 #include "VTKViewer_Texture.h"
30 #include "VTKViewer_OpenGLRenderer.h"
32 #include "SALOME_Actor.h"
38 #include <QSignalMapper>
39 #include <QXmlStreamWriter>
40 #include <QXmlStreamReader>
41 #include <QXmlStreamAttributes>
43 #include <vtkTextProperty.h>
44 #include <vtkActorCollection.h>
45 #include <vtkRenderWindow.h>
46 #include <vtkRenderer.h>
47 #include <vtkCamera.h>
48 #include <vtkPointPicker.h>
49 #include <vtkCellPicker.h>
50 #include <vtkAxisActor2D.h>
51 #include <vtkGL2PSExporter.h>
52 #include <vtkInteractorStyle.h>
53 #include <vtkProperty.h>
54 #include <vtkCallbackCommand.h>
55 #include <vtkJPEGReader.h>
56 #include <vtkBMPReader.h>
57 #include <vtkTIFFReader.h>
58 #include <vtkPNGReader.h>
59 #include <vtkMetaImageReader.h>
60 #include <vtkImageMapToColors.h>
61 #include <vtkTexture.h>
63 #include "QtxAction.h"
65 #include "SUIT_Session.h"
66 #include "SUIT_MessageBox.h"
67 #include "SUIT_Accel.h"
68 #include "SUIT_Tools.h"
69 #include "SUIT_ResourceMgr.h"
70 #include "SUIT_Accel.h"
71 #include "SUIT_OverrideCursor.h"
72 #include "SUIT_ViewManager.h"
73 #include "QtxActionToolMgr.h"
74 #include "QtxMultiAction.h"
75 #include "QtxActionGroup.h"
77 #include "VTKViewer_Utilities.h"
78 #include "VTKViewer_Trihedron.h"
80 #include "SVTK_View.h"
81 #include "SVTK_Selector.h"
83 #include "SVTK_Event.h"
84 #include "SVTK_Renderer.h"
85 #include "SVTK_ViewWindow.h"
86 #include "SVTK_InteractorStyle.h"
87 #include "SVTK_RenderWindowInteractor.h"
88 #include "SVTK_GenericRenderWindowInteractor.h"
89 #include "SVTK_CubeAxesActor2D.h"
90 #include "SVTK_ComboAction.h"
91 #include "SVTK_KeyFreeInteractorStyle.h"
92 #include "SVTK_Selector.h"
93 #include "SVTK_Recorder.h"
94 #include "SVTK_RecorderDlg.h"
96 #include "salomevtkPVAxesWidget.h"
97 #include "salomevtkPVAxesActor.h"
99 #include "SALOME_ListIO.hxx"
101 #include "VTKViewer_Algorithm.h"
102 #include "SVTK_Functor.h"
104 #ifndef DISABLE_GLVIEWER
105 #include <OpenGLUtils_FrameBuffer.h>
111 int convertAction( const int accelAction )
113 switch ( accelAction ) {
114 case SUIT_Accel::PanLeft : return SVTK::PanLeftEvent;
115 case SUIT_Accel::PanRight : return SVTK::PanRightEvent;
116 case SUIT_Accel::PanUp : return SVTK::PanUpEvent;
117 case SUIT_Accel::PanDown : return SVTK::PanDownEvent;
118 case SUIT_Accel::ZoomIn : return SVTK::ZoomInEvent;
119 case SUIT_Accel::ZoomOut : return SVTK::ZoomOutEvent;
120 case SUIT_Accel::RotateLeft : return SVTK::RotateLeftEvent;
121 case SUIT_Accel::RotateRight : return SVTK::RotateRightEvent;
122 case SUIT_Accel::RotateUp : return SVTK::RotateUpEvent;
123 case SUIT_Accel::RotateDown : return SVTK::RotateDownEvent;
136 SVTK_ViewWindow::SVTK_ViewWindow(SUIT_Desktop* theDesktop):
137 SUIT_ViewWindow(theDesktop),
139 myDumpImage(QImage()),
140 myKeyFreeInteractorStyle(SVTK_KeyFreeInteractorStyle::New()),
141 myEventCallbackCommand(vtkCallbackCommand::New())
143 setWindowFlags( windowFlags() & ~Qt::Window );
144 // specific of vtkSmartPointer
145 myKeyFreeInteractorStyle->Delete();
149 To initialize #SVTK_ViewWindow instance
151 void SVTK_ViewWindow::Initialize(SVTK_ViewModelBase* theModel)
154 myInteractor = new SVTK_RenderWindowInteractor(this,"SVTK_RenderWindowInteractor");
156 SVTK_Selector* aSelector = SVTK_Selector::New();
157 int aPreselectionMode = SUIT_Session::session()->resourceMgr()->
158 integerValue( "VTKViewer", "preselection", Standard_Preselection );
159 aSelector->SetDynamicPreSelection( aPreselectionMode == Dynamic_Preselection );
160 aSelector->SetPreSelectionEnabled( aPreselectionMode != Preselection_Disabled );
161 bool isSelectionEnabled = SUIT_Session::session()->resourceMgr()->
162 booleanValue( "VTKViewer", "enable_selection", true );
163 aSelector->SetSelectionEnabled( isSelectionEnabled );
165 SVTK_GenericRenderWindowInteractor* aDevice = SVTK_GenericRenderWindowInteractor::New();
166 aDevice->SetRenderWidget(myInteractor);
167 aDevice->SetSelector(aSelector);
169 SVTK_Renderer* aRenderer = SVTK_Renderer::New();
170 aRenderer->Initialize(aDevice,aSelector);
172 myInteractor->Initialize(aDevice,aRenderer,aSelector);
178 myToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_LABEL"), // title (language-dependant)
179 QString( "VTKViewerViewOperations" ), // name (language-independant)
180 false ); // disable floatable toolbar
182 myRecordingToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_RECORD_LABEL"), // title (language-dependant)
183 QString( "VTKRecordingOperations" ), // name (language-independant)
184 false ); // disable floatable toolbar
186 createActions( SUIT_Session::session()->resourceMgr() );
189 SetEventDispatcher(myInteractor->GetDevice());
190 myInteractor->setBackgroundRole( QPalette::NoRole );//NoBackground
191 myInteractor->setFocusPolicy(Qt::StrongFocus);
192 myInteractor->setFocus();
193 setFocusProxy(myInteractor);
195 myUpdateRateDlg = new SVTK_UpdateRateDlg( getAction( UpdateRate ), this, "SVTK_UpdateRateDlg" );
196 myNonIsometricDlg = new SVTK_NonIsometricDlg( getAction( NonIsometric ), this, "SVTK_NonIsometricDlg" );
197 myCubeAxesDlg = new SVTK_CubeAxesDlg( getAction( GraduatedAxes ), this, "SVTK_CubeAxesDlg" );
198 myCubeAxesDlg->initialize();
199 mySetRotationPointDlg = new SVTK_SetRotationPointDlg
200 ( getAction( ChangeRotationPointId ), this, "SVTK_SetRotationPointDlg" );
201 myViewParameterDlg = new SVTK_ViewParameterDlg
202 ( getAction( ViewParametersId ), this, "SVTK_ViewParameterDlg" );
204 myDefaultInteractorStyle = SVTK_InteractorStyle::New();
205 myInteractor->PushInteractorStyle(myDefaultInteractorStyle);
206 myDefaultInteractorStyle->Delete();
208 myRecorder = SVTK_Recorder::New();
210 myRecorder->SetNbFPS( 17.3 );
211 myRecorder->SetQuality( 100 );
212 myRecorder->SetProgressiveMode( true );
213 myRecorder->SetUseSkippedFrames( true );
214 myRecorder->SetRenderWindow( myInteractor->getRenderWindow() );
216 setCentralWidget(myInteractor);
218 myAxesWidget = salomevtk::vtkPVAxesWidget::New();
219 myAxesWidget->SetParentRenderer(aRenderer->GetDevice());
220 myAxesWidget->SetViewport(0, 0, 0.25, 0.25);
221 myAxesWidget->SetInteractor(myInteractor->GetDevice());
222 myAxesWidget->SetEnabled(1);
223 myAxesWidget->SetInteractive(0);
225 salomevtk::vtkPVAxesActor* anAxesActor = myAxesWidget->GetAxesActor();
226 anAxesActor->GetXAxisTipProperty()->SetColor( 1.0, 0.0, 0.0 );
227 anAxesActor->GetXAxisShaftProperty()->SetColor( 1.0, 0.0, 0.0 );
228 anAxesActor->GetXAxisLabelProperty()->SetColor( 1.0, 0.0, 0.0 );
229 anAxesActor->GetYAxisTipProperty()->SetColor( 0.0, 1.0, 0.0 );
230 anAxesActor->GetYAxisShaftProperty()->SetColor( 0.0, 1.0, 0.0 );
231 anAxesActor->GetYAxisLabelProperty()->SetColor( 0.0, 1.0, 0.0 );
232 anAxesActor->GetZAxisTipProperty()->SetColor( 0.0, 0.0, 1.0 );
233 anAxesActor->GetZAxisShaftProperty()->SetColor( 0.0, 0.0, 1.0 );
234 anAxesActor->GetZAxisLabelProperty()->SetColor( 0.0, 0.0, 1.0 );
236 myView = new SVTK_View(this);
237 Initialize(myView,theModel);
240 myEventCallbackCommand->SetClientData(this);
241 myEventCallbackCommand->SetCallback(SVTK_ViewWindow::ProcessEvents);
242 myEventCallbackCommand->Delete();
244 GetInteractor()->GetInteractorStyle()->AddObserver(SVTK::OperationFinished,
245 myEventCallbackCommand.GetPointer(), 0.0);
246 myKeyFreeInteractorStyle->AddObserver(SVTK::OperationFinished,
247 myEventCallbackCommand.GetPointer(), 0.0);
251 myInteractor->getRenderWindow()->Render();
252 setBackground( Qtx::BackgroundData( Qt::black ) ); // set default background
257 To initialize #SVTK_ViewWindow instance
259 void SVTK_ViewWindow::Initialize(SVTK_View* theView,
260 SVTK_ViewModelBase* theModel)
262 connect(theView,SIGNAL(KeyPressed(QKeyEvent*)),
263 this,SLOT(onKeyPressed(QKeyEvent*)) );
264 connect(theView,SIGNAL(KeyReleased(QKeyEvent*)),
265 this,SLOT(onKeyReleased(QKeyEvent*)));
266 connect(theView,SIGNAL(MouseButtonPressed(QMouseEvent*)),
267 this,SLOT(onMousePressed(QMouseEvent*)));
268 connect(theView,SIGNAL(MouseButtonReleased(QMouseEvent*)),
269 this,SLOT(onMouseReleased(QMouseEvent*)));
270 connect(theView,SIGNAL(MouseDoubleClicked(QMouseEvent*)),
271 this,SLOT(onMouseDoubleClicked(QMouseEvent*)));
272 connect(theView,SIGNAL(MouseMove(QMouseEvent*)),
273 this,SLOT(onMouseMoving(QMouseEvent*)));
274 connect(theView,SIGNAL(contextMenuRequested(QContextMenuEvent*)),
275 this,SIGNAL(contextMenuRequested(QContextMenuEvent *)));
276 connect(theView,SIGNAL(selectionChanged()),
277 theModel,SLOT(onSelectionChanged()));
279 connect( this, SIGNAL( transformed( SVTK_ViewWindow* ) ), SLOT( emitViewModified() ) );
285 SVTK_ViewWindow::~SVTK_ViewWindow()
287 myRecorder->Delete();
288 myAxesWidget->Delete();
293 \return corresponding view
295 SVTK_View* SVTK_ViewWindow::getView()
301 \return corresponding vtk render window
303 vtkRenderWindow* SVTK_ViewWindow::getRenderWindow()
305 return GetInteractor()->getRenderWindow();
309 \return corresponding vtk render window interactor
311 SVTK_RenderWindowInteractor* SVTK_ViewWindow::GetInteractor() const
317 \return corresponding vtk render window interactor
319 vtkRenderWindowInteractor* SVTK_ViewWindow::getInteractor() const
321 return myInteractor->GetDevice();
325 \return corresponding vtk renderer
327 vtkRenderer* SVTK_ViewWindow::getRenderer() const
329 return GetInteractor()->getRenderer();
333 Redirect the request to SVTK_RenderWindowInteractor::GetRenderer
335 SVTK_Renderer* SVTK_ViewWindow::GetRenderer() const
337 return GetInteractor()->GetRenderer();
341 \return corresponding vtk selector
343 SVTK_Selector* SVTK_ViewWindow::GetSelector() const
345 return GetInteractor()->GetSelector();
349 Processes transformation "front view"
351 void SVTK_ViewWindow::onFrontView()
353 GetRenderer()->OnFrontView();
355 emit transformed( this );
359 Processes transformation "back view"
361 void SVTK_ViewWindow::onBackView()
363 GetRenderer()->OnBackView();
365 emit transformed( this );
369 Processes transformation "top view"
371 void SVTK_ViewWindow::onTopView()
373 GetRenderer()->OnTopView();
375 emit transformed( this );
379 Processes transformation "bottom view"
381 void SVTK_ViewWindow::onBottomView()
383 GetRenderer()->OnBottomView();
385 emit transformed( this );
389 Processes transformation "left view"
391 void SVTK_ViewWindow::onLeftView()
393 GetRenderer()->OnLeftView();
395 emit transformed( this );
399 Processes transformation "right view"
401 void SVTK_ViewWindow::onRightView()
403 GetRenderer()->OnRightView();
405 emit transformed( this );
409 \brief Rotate view 90 degrees clockwise
411 void SVTK_ViewWindow::onClockWiseView()
413 GetRenderer()->onClockWiseView();
415 emit transformed( this );
419 \brief Rotate view 90 degrees conterclockwise
421 void SVTK_ViewWindow::onAntiClockWiseView()
423 GetRenderer()->onAntiClockWiseView();
425 emit transformed( this );
429 Processes transformation "reset view": sets default orientation of viewport camera
431 void SVTK_ViewWindow::onResetView()
433 GetRenderer()->OnResetView();
435 emit transformed( this );
439 Processes transformation "fit all"
441 void SVTK_ViewWindow::onFitAll()
443 GetRenderer()->OnFitAll();
445 emit transformed( this );
449 Processes transformation "fit selection"
451 void SVTK_ViewWindow::onFitSelection()
453 GetRenderer()->onFitSelection();
455 emit transformed( this );
459 SLOT: called if selection is changed
461 void SVTK_ViewWindow::onSelectionChanged()
463 myView->onSelectionChanged();
467 Change selection mode
468 \param theMode - new selection mode
470 void SVTK_ViewWindow::SetSelectionMode(Selection_Mode theMode)
472 GetSelector()->SetSelectionMode(theMode);
476 \return selection mode
478 Selection_Mode SVTK_ViewWindow::SelectionMode() const
480 return GetSelector()->SelectionMode();
484 Unhilights all objects in viewer
486 void SVTK_ViewWindow::unHighlightAll()
488 myView->unHighlightAll();
492 Hilights/unhilights object in viewer
493 \param theIO - object to be updated
494 \param theIsHighlight - if it is true, object will be hilighted, otherwise it will be unhilighted
495 \param theIsUpdate - update current viewer
497 void SVTK_ViewWindow::highlight(const Handle(SALOME_InteractiveObject)& theIO,
501 myView->highlight( theIO, theIsHighlight, theIsUpdate );
505 \return true if object is in viewer or in collector
506 \param theIO - object to be checked
508 bool SVTK_ViewWindow::isInViewer( const Handle(SALOME_InteractiveObject)& theIO )
510 return myView->isInViewer( theIO );
514 \return true if object is displayed in viewer
515 \param theIO - object to be checked
517 bool SVTK_ViewWindow::isVisible( const Handle(SALOME_InteractiveObject)& theIO )
519 return myView->isVisible( theIO );
524 \param theEntry - entry that corresponds to intractive objects
526 Handle(SALOME_InteractiveObject) SVTK_ViewWindow::FindIObject(const char* theEntry)
528 return myView->FindIObject(theEntry);
533 \param theIO - object
534 \param theImmediatly - update viewer
536 void SVTK_ViewWindow::Display(const Handle(SALOME_InteractiveObject)& theIO,
539 myView->Display(theIO,theImmediatly);
544 \param theIO - object
545 \param theImmediatly - update viewer
547 void SVTK_ViewWindow::Erase(const Handle(SALOME_InteractiveObject)& theIO,
550 myView->Erase(theIO,theImmediatly);
554 Display only passed object
555 \param theIO - object
557 void SVTK_ViewWindow::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIO)
559 myView->DisplayOnly(theIO);
563 Display all objects in view
565 void SVTK_ViewWindow::DisplayAll()
567 myView->DisplayAll();
571 Erase all objects in view
573 void SVTK_ViewWindow::EraseAll()
579 Sets background color [obsolete]
580 \param color - new background color
582 void SVTK_ViewWindow::setBackgroundColor( const QColor& c )
584 Qtx::BackgroundData bg = background();
590 \return background color of viewer [obsolete]
592 QColor SVTK_ViewWindow::backgroundColor() const
594 return background().color();
599 \param bgData - new background data
601 void SVTK_ViewWindow::setBackground( const Qtx::BackgroundData& bgData )
605 if ( bgData.isValid() ) {
606 switch ( bgData.mode() ) {
607 case Qtx::ColorBackground:
609 QColor c = bgData.color();
611 // show solid-colored background
612 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
613 getRenderer()->SetGradientBackground( false ); // cancel gradient mode
614 getRenderer()->SetBackground( c.red()/255.0,
616 c.blue()/255.0 ); // set background color
621 case Qtx::SimpleGradientBackground:
624 int type = bgData.gradient( c1, c2 );
630 // show two-color gradient background
631 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
632 getRenderer()->SetGradientBackground( true ); // switch to gradient mode
634 VTKViewer_OpenGLRenderer* aRenderer =
635 VTKViewer_OpenGLRenderer::SafeDownCast( getRenderer() );
638 aRenderer->SetGradientType( type );
639 aRenderer->SetBackground( c1.redF(), c1.greenF(), c1.blueF() );
640 aRenderer->SetBackground2( c2.redF(), c2.greenF(), c2.blueF() );
646 case Qtx::CustomGradientBackground:
648 // NOT IMPLEMENTED YET
649 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
650 getRenderer()->SetGradientBackground( false ); // cancel gradient mode
657 if ( bgData.isTextureShown() ) {
659 int textureMode = bgData.texture( fileName );
660 QFileInfo fi( fileName );
661 if ( !fileName.isEmpty() && fi.exists() ) {
662 // read texture from file
663 QString extension = fi.suffix().toLower();
664 vtkImageReader2* aReader = 0;
665 if ( extension == "jpg" || extension == "jpeg" )
666 aReader = vtkJPEGReader::New();
667 else if ( extension == "bmp" )
668 aReader = vtkBMPReader::New();
669 else if ( extension == "tif" || extension == "tiff" )
670 aReader = vtkTIFFReader::New();
671 else if ( extension == "png" )
672 aReader = vtkPNGReader::New();
673 else if ( extension == "mhd" || extension == "mha" )
674 aReader = vtkMetaImageReader::New();
677 aReader->SetFileName( fi.absoluteFilePath().toLatin1().constData() );
679 VTKViewer_Texture* aTexture = VTKViewer_Texture::New();
680 vtkImageMapToColors* aMap = 0;
681 vtkAlgorithmOutput* anOutput;
683 // special processing for BMP reader
684 vtkBMPReader* aBMPReader = (vtkBMPReader*)aReader;
686 // Special processing for BMP file
687 aBMPReader->SetAllow8BitBMP(1);
689 aMap = vtkImageMapToColors::New();
690 aMap->SetInputConnection( aBMPReader->GetOutputPort() );
691 aMap->SetLookupTable( (vtkScalarsToColors*)aBMPReader->GetLookupTable() );
692 aMap->SetOutputFormatToRGB();
694 anOutput = aMap->GetOutputPort();
699 anOutput = aReader->GetOutputPort( 0 );
700 aTexture->SetInputConnection( anOutput );
702 // VSR: Currently, VTK only supports Stretch mode, so below code will give
703 // the same results for all modes
704 switch ( textureMode ) {
705 case Qtx::TileTexture:
706 aTexture->SetPosition((int)VTKViewer_Texture::Tiled);
708 case Qtx::StretchTexture:
709 aTexture->SetPosition((int)VTKViewer_Texture::Stretched);
711 case Qtx::CenterTexture:
712 aTexture->SetPosition((int)VTKViewer_Texture::Centered);
716 // show textured background
717 getRenderer()->SetTexturedBackground( true );
718 getRenderer()->SetBackgroundTexture( aTexture );
720 // clean-up resources
731 myBackground = bgData;
735 \return background data of viewer
737 Qtx::BackgroundData SVTK_ViewWindow::background() const
744 Redirect the request to SVTK_RenderWindowInteractor::GetInteractorStyle
746 vtkInteractorStyle* SVTK_ViewWindow::GetInteractorStyle() const
748 return GetInteractor()->GetInteractorStyle();
752 Redirect the request to SVTK_RenderWindowInteractor::PushInteractorStyle
754 void SVTK_ViewWindow::PushInteractorStyle(vtkInteractorStyle* theStyle)
756 GetInteractor()->PushInteractorStyle(theStyle);
760 Redirect the request to SVTK_RenderWindowInteractor::PopInteractorStyle
762 void SVTK_ViewWindow::PopInteractorStyle()
764 GetInteractor()->PopInteractorStyle();
768 Updates current viewer
770 void SVTK_ViewWindow::Repaint(bool theUpdateTrihedron)
772 if(theUpdateTrihedron)
773 GetRenderer()->OnAdjustTrihedron();
775 GetInteractor()->update();
777 SVTK_InteractorStyle* aStyle = (SVTK_InteractorStyle*)getInteractor()->GetInteractorStyle();
783 Redirect the request to #SVTK_Renderer::GetScale
785 void SVTK_ViewWindow::GetScale( double theScale[3] )
787 GetRenderer()->GetScale( theScale );
791 Redirect the request to #SVTK_Renderer::SetScale
793 void SVTK_ViewWindow::SetScale( double theScale[3] )
795 GetRenderer()->SetScale( theScale );
797 emit transformed( this );
801 Redirect the request to #SVTK_Renderer::IsTrihedronDisplayed
803 bool SVTK_ViewWindow::isTrihedronDisplayed()
805 return GetRenderer()->IsTrihedronDisplayed();
809 Redirect the request to #SVTK_Renderer::IsCubeAxesDisplayed
811 bool SVTK_ViewWindow::isCubeAxesDisplayed()
813 return GetRenderer()->IsCubeAxesDisplayed();
817 Redirect the request to #SVTK_Renderer::OnViewTrihedron
819 void SVTK_ViewWindow::onViewTrihedron(bool show)
821 GetRenderer()->SetTrihedronVisibility(show);
826 Redirect the request to #SVTK_Renderer::OnViewCubeAxes
828 void SVTK_ViewWindow::onViewCubeAxes()
830 GetRenderer()->OnViewCubeAxes();
835 Redirect the request to #SVTK_Renderer::GetTrihedron
837 VTKViewer_Trihedron* SVTK_ViewWindow::GetTrihedron()
839 return GetRenderer()->GetTrihedron();
843 Redirect the request to #SVTK_Renderer::GetCubeAxes
845 SVTK_CubeAxesActor2D* SVTK_ViewWindow::GetCubeAxes()
847 return GetRenderer()->GetCubeAxes();
851 \return trihedron size
853 double SVTK_ViewWindow::GetTrihedronSize() const
855 return GetRenderer()->GetTrihedronSize();
860 \param theMode - projection mode ( 0 - orthogonal, 1 - perspective )
862 void SVTK_ViewWindow::SetProjectionMode(const int theMode)
864 activateProjectionMode( theMode );
869 Set the gravity center as a focal point
871 void SVTK_ViewWindow::activateSetFocalPointGravity()
873 myEventDispatcher->InvokeEvent(SVTK::SetFocalPointGravity, 0);
877 Set the selected point as a focal point
879 void SVTK_ViewWindow::activateSetFocalPointSelected()
881 myEventDispatcher->InvokeEvent(SVTK::SetFocalPointSelected, 0);
885 Set the point selected by user as a focal point
887 void SVTK_ViewWindow::activateStartFocalPointSelection()
889 myEventDispatcher->InvokeEvent(SVTK::StartFocalPointSelection,0);
892 void SVTK_ViewWindow::activateProjectionMode(int theMode)
895 toolMgr()->action( ProjectionModeId )->setChecked( true );
897 toolMgr()->action( ParallelModeId )->setChecked( true );
901 Sets actual interaction style
902 \param theStyle - type of interaction style ( 0 - standard, 1 - keyboard free )
904 void SVTK_ViewWindow::SetInteractionStyle(const int theStyle)
906 onSwitchInteractionStyle( theStyle==1 );
910 Sets actual zooming style
911 \param theStyle - type of zooming style ( 0 - standard, 1 - advanced (at cursor) )
913 void SVTK_ViewWindow::SetZoomingStyle(const int theStyle)
915 onSwitchZoomingStyle( theStyle==1 );
919 Set preselection mode.
920 \param theMode the mode to set (standard, dynamic or disabled)
922 void SVTK_ViewWindow::SetPreSelectionMode( Preselection_Mode theMode )
924 onSwitchPreSelectionMode( theMode );
928 Enables/disables selection.
929 \param theEnable if true - selection will be enabled
931 void SVTK_ViewWindow::SetSelectionEnabled( bool theEnable )
933 GetSelector()->SetSelectionEnabled( theEnable );
934 QtxAction* a = getAction( EnableSelectionId );
935 if ( a->isChecked() != theEnable)
936 a->setChecked( theEnable );
937 QtxActionGroup* aPreselectionGroup =
938 dynamic_cast<QtxActionGroup*>( getAction( PreselectionId ) );
939 if ( aPreselectionGroup )
940 aPreselectionGroup->setEnabled( theEnable );
944 Switches "keyboard free" interaction style on/off
946 void SVTK_ViewWindow::onSwitchInteractionStyle(bool theOn)
949 // check if style is already set
950 if ( GetInteractorStyle() != myKeyFreeInteractorStyle.GetPointer() )
952 // keep the same style extensions
953 SVTK_InteractorStyle* aStyle = (SVTK_InteractorStyle*)GetInteractorStyle();
955 myKeyFreeInteractorStyle->SetControllerIncrement(aStyle->ControllerIncrement());
956 myKeyFreeInteractorStyle->SetControllerOnKeyDown(aStyle->ControllerOnKeyDown());
959 PushInteractorStyle(myKeyFreeInteractorStyle.GetPointer());
963 // pop only key free style
964 if ( GetInteractorStyle() == myKeyFreeInteractorStyle.GetPointer() )
965 PopInteractorStyle();
968 // update action state if method is called outside
969 QtxAction* a = getAction( SwitchInteractionStyleId );
970 if ( a->isChecked() != theOn ) a->setChecked( theOn );
974 Toogles advanced zooming style (relatively to the cursor position) on/off
976 void SVTK_ViewWindow::onSwitchZoomingStyle( bool theOn )
978 if( myDefaultInteractorStyle.GetPointer() )
979 myDefaultInteractorStyle->SetAdvancedZoomingEnabled( theOn );
980 if( myKeyFreeInteractorStyle.GetPointer() )
981 myKeyFreeInteractorStyle->SetAdvancedZoomingEnabled( theOn );
983 // update action state if method is called outside
984 QtxAction* a = getAction( SwitchZoomingStyleId );
985 if ( a->isChecked() != theOn )
986 a->setChecked( theOn );
990 Switch preselection mode.
991 \param theMode the preselection mode
993 void SVTK_ViewWindow::onSwitchPreSelectionMode( int theMode )
995 GetSelector()->SetDynamicPreSelection( theMode == Dynamic_Preselection );
996 GetSelector()->SetPreSelectionEnabled( theMode != Preselection_Disabled );
998 // update action state if method is called outside
999 QtxAction* a = getAction( StandardPreselectionId + theMode );
1000 if ( a && !a->isChecked() )
1001 a->setChecked( true );
1005 Enables/disables selection.
1006 \param theOn if true - selection will be enabled
1008 void SVTK_ViewWindow::onEnableSelection( bool on )
1010 SVTK_Viewer* aViewer = dynamic_cast<SVTK_Viewer*>(myModel);
1012 aViewer->enableSelection(on);
1016 Sets incremental speed
1017 \param theValue - new incremental speed
1018 \param theMode - modification mode
1020 void SVTK_ViewWindow::SetIncrementalSpeed(const int theValue, const int theMode)
1022 if ( (SVTK_InteractorStyle*)GetInteractorStyle() )
1023 ((SVTK_InteractorStyle*)GetInteractorStyle())->SetIncrementSpeed(theValue, theMode);
1027 Sets spacemouse buttons for the functions
1028 \param theBtn1 - spacemouse button for the "decrease speed increment"
1029 \param theBtn2 - spacemouse button for the "increase speed increment"
1030 \param theBtn3 - spacemouse button for the "dominant combined switch"
1032 void SVTK_ViewWindow::SetSpacemouseButtons(const int theBtn1,
1037 myEventDispatcher->InvokeEvent(SVTK::SetSMDecreaseSpeedEvent, &val);
1039 myEventDispatcher->InvokeEvent(SVTK::SetSMIncreaseSpeedEvent, &val);
1041 myEventDispatcher->InvokeEvent(SVTK::SetSMDominantCombinedSwitchEvent, &val);
1046 \param theSize - new trihedron size
1047 \param theRelative - trihedron relativeness
1049 void SVTK_ViewWindow::SetTrihedronSize(const double theSize, const bool theRelative)
1051 GetRenderer()->SetTrihedronSize(theSize, theRelative);
1055 /*! If parameter theIsForcedUpdate is true, recalculate parameters for
1056 * trihedron and cube axes, even if trihedron and cube axes is invisible.
1058 void SVTK_ViewWindow::AdjustTrihedrons(const bool theIsForcedUpdate)
1060 GetRenderer()->AdjustActors();
1065 Redirect the request to #SVTK_Renderer::OnAdjustTrihedron
1067 void SVTK_ViewWindow::onAdjustTrihedron()
1069 GetRenderer()->OnAdjustTrihedron();
1073 Redirect the request to #SVTK_Renderer::OnAdjustCubeAxes
1075 void SVTK_ViewWindow::onAdjustCubeAxes()
1077 GetRenderer()->OnAdjustCubeAxes();
1080 void SVTK_ViewWindow::synchronize(SVTK_ViewWindow* otherViewWindow )
1082 if ( otherViewWindow ) {
1083 bool blocked = blockSignals( true );
1084 doSetVisualParameters( otherViewWindow->getVisualParameters(), true );
1085 blockSignals( blocked );
1092 void SVTK_ViewWindow::onKeyPressed(QKeyEvent* event)
1094 emit keyPressed( this, event );
1100 void SVTK_ViewWindow::onKeyReleased(QKeyEvent* event)
1102 emit keyReleased( this, event );
1108 void SVTK_ViewWindow::onMousePressed(QMouseEvent* event)
1110 emit mousePressed(this, event);
1114 Emits mouse released
1116 void SVTK_ViewWindow::onMouseReleased(QMouseEvent* event)
1118 emit mouseReleased( this, event );
1124 void SVTK_ViewWindow::onMouseMoving(QMouseEvent* event)
1126 emit mouseMoving( this, event );
1130 Emits mouse double clicked
1132 void SVTK_ViewWindow::onMouseDoubleClicked( QMouseEvent* event )
1134 emit mouseDoubleClicked( this, event );
1138 Redirect the request to #SVTK_Renderer::AddActor
1140 void SVTK_ViewWindow::AddActor( VTKViewer_Actor* theActor,
1142 bool theIsAdjustActors )
1144 GetRenderer()->AddActor(theActor, theIsAdjustActors);
1147 emit actorAdded(theActor);
1151 Redirect the request to #SVTK_Renderer::RemoveActor
1153 void SVTK_ViewWindow::RemoveActor( VTKViewer_Actor* theActor,
1155 bool theIsAdjustActors )
1157 GetRenderer()->RemoveActor(theActor, theIsAdjustActors);
1158 if ( myDefaultInteractorStyle )
1159 myDefaultInteractorStyle->FreeActors();
1160 if ( myKeyFreeInteractorStyle )
1161 myKeyFreeInteractorStyle->FreeActors();
1164 emit actorRemoved(theActor);
1167 QImage SVTK_ViewWindow::dumpViewContent()
1169 vtkRenderWindow* aWindow = getRenderWindow();
1170 int* aSize = aWindow->GetSize();
1171 int aWidth = aSize[0];
1172 int aHeight = aSize[1];
1174 #ifndef DISABLE_GLVIEWER
1175 OpenGLUtils_FrameBuffer aFrameBuffer;
1176 if( aFrameBuffer.init( aWidth, aHeight ) )
1178 glPushAttrib( GL_VIEWPORT_BIT );
1179 glViewport( 0, 0, aWidth, aHeight );
1180 aFrameBuffer.bind();
1185 aFrameBuffer.unbind();
1188 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
1190 aFrameBuffer.bind();
1191 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
1192 aFrameBuffer.unbind();
1194 anImage = anImage.rgbSwapped();
1195 anImage = anImage.mirrored();
1200 // if frame buffers are unsupported, use old functionality
1201 unsigned char *aData =
1202 aWindow->GetRGBACharPixelData( 0, 0, aWidth-1, aHeight-1, 0 );
1204 QImage anImage( aData, aWidth, aHeight, QImage::Format_ARGB32 );
1206 anImage = anImage.rgbSwapped();
1207 anImage = anImage.mirrored();
1212 \return QImage, containing all scene rendering in window
1214 QImage SVTK_ViewWindow::dumpView()
1216 if( myDumpImage.isNull() )
1217 return dumpViewContent();
1223 QString SVTK_ViewWindow::filter() const
1225 return tr( "SVTK_IMAGE_FILES" );
1228 bool SVTK_ViewWindow::dumpViewToFormat( const QImage& img, const QString& fileName, const QString& format )
1230 if ( format != "PS" && format != "EPS" && format != "PDF" )
1231 return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
1233 SUIT_OverrideCursor wc;
1235 vtkGL2PSExporter *anExporter = vtkGL2PSExporter::New();
1236 anExporter->SetRenderWindow(getRenderWindow());
1238 if ( format == "PS" ) {
1239 anExporter->SetFileFormatToPS();
1240 anExporter->CompressOff();
1243 if ( format == "EPS" ) {
1244 anExporter->SetFileFormatToEPS();
1245 anExporter->CompressOff();
1248 if ( format == "PDF" ) {
1249 anExporter->SetFileFormatToPDF();
1252 QString aFilePrefix(fileName);
1253 QString anExtension(SUIT_Tools::extension(fileName));
1254 aFilePrefix.truncate(aFilePrefix.length() - 1 - anExtension.length());
1255 anExporter->SetFilePrefix(aFilePrefix.toLatin1().data());
1256 anExporter->Write();
1257 anExporter->Delete();
1263 \refresh QImage, containing all scene rendering in window
1265 void SVTK_ViewWindow::RefreshDumpImage()
1267 myDumpImage = dumpViewContent();
1271 Redirect the request to #SVTK_Renderer::SetSelectionProp
1273 void SVTK_ViewWindow::SetSelectionProp(const double& theRed,
1274 const double& theGreen,
1275 const double& theBlue,
1276 const int& theWidth)
1278 myView->SetSelectionProp(theRed,theGreen,theBlue,theWidth);
1282 Redirect the request to #SVTK_Renderer::SetSelectionProp
1284 void SVTK_ViewWindow::SetPreselectionProp(const double& theRed,
1285 const double& theGreen,
1286 const double& theBlue,
1287 const int& theWidth)
1289 myView->SetPreselectionProp(theRed,theGreen,theBlue,theWidth);
1293 Redirect the request to #SVTK_Renderer::SetSelectionTolerance
1295 void SVTK_ViewWindow::SetSelectionTolerance(const double& theTolNodes,
1296 const double& theTolItems,
1297 const double& theTolObjects)
1299 myView->SetSelectionTolerance(theTolNodes, theTolItems, theTolObjects);
1303 Get visibility status of the static trihedron
1305 bool SVTK_ViewWindow::IsStaticTrihedronVisible() const
1307 return (bool)myAxesWidget->GetEnabled();
1311 Set visibility status of the static trihedron
1313 void SVTK_ViewWindow::SetStaticTrihedronVisible( const bool theIsVisible )
1315 myAxesWidget->SetEnabled( (int)theIsVisible );
1320 \param accelAction - action
1322 bool SVTK_ViewWindow::action( const int accelAction )
1324 if ( accelAction == SUIT_Accel::ZoomFit )
1327 int anEvent = SVTK::convertAction( accelAction );
1328 GetInteractor()->InvokeEvent(anEvent, 0);
1334 \return action by it's id
1336 QtxAction* SVTK_ViewWindow::getAction( int id ) const
1338 return dynamic_cast<QtxAction*>( toolMgr()->action( id ) );
1342 // old visual parameters had 13 values. New format added additional
1343 // 76 values for graduated axes, so both numbers are processed.
1344 const int nNormalParams = 13; // number of view windows parameters excluding graduated axes params
1345 const int nGradAxisParams = 25; // number of parameters of ONE graduated axis (X, Y, or Z)
1346 const int nTrihedronParams = 3; // number of parameters for Trihedron
1347 const int nAllParams = nNormalParams + 3*nGradAxisParams + nTrihedronParams + 1; // number of all visual parameters
1349 /*! The method returns visual parameters of a graduated axis actor (x,y,z axis of graduated axes)
1351 void getGradAxisVisualParams( QXmlStreamWriter& writer, vtkAxisActor2D* actor, QString theAxis )
1358 bool isVisible = actor->GetTitleVisibility();
1359 QString title ( actor->GetTitle() );
1361 int font = VTK_ARIAL;
1366 vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1369 txtProp->GetColor( color );
1370 font = txtProp->GetFontFamily();
1371 bold = txtProp->GetBold();
1372 italic = txtProp->GetItalic();
1373 shadow = txtProp->GetShadow();
1375 writer.writeStartElement("GraduatedAxis");
1376 writer.writeAttribute("Axis", theAxis);
1378 writer.writeStartElement("Title");
1379 writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1380 writer.writeAttribute("Text", title);
1381 writer.writeAttribute("Font", QString("%1").arg(font));
1382 writer.writeAttribute("Bold", QString("%1").arg(bold));
1383 writer.writeAttribute("Italic", QString("%1").arg(italic));
1384 writer.writeAttribute("Shadow", QString("%1").arg(shadow));
1386 writer.writeStartElement("Color");
1387 writer.writeAttribute("R", QString("%1").arg(color[0]));
1388 writer.writeAttribute("G", QString("%1").arg(color[1]));
1389 writer.writeAttribute("B", QString("%1").arg(color[2]));
1390 writer.writeEndElement();
1391 writer.writeEndElement();
1393 //params.sprintf( "* Graduated Axis: * Name *%u*%s*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible,
1394 // title.toLatin1().data(), color[0], color[1], color[2], font, bold, italic, shadow );
1397 isVisible = actor->GetLabelVisibility();
1398 int labels = actor->GetNumberOfLabels();
1399 int offset = actor->GetTickOffset();
1405 txtProp = actor->GetLabelTextProperty();
1408 txtProp->GetColor( color );
1409 font = txtProp->GetFontFamily();
1410 bold = txtProp->GetBold();
1411 italic = txtProp->GetItalic();
1412 shadow = txtProp->GetShadow();
1415 writer.writeStartElement("Labels");
1416 writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1417 writer.writeAttribute("Number", QString("%1").arg(labels));
1418 writer.writeAttribute("Offset", QString("%1").arg(offset));
1419 writer.writeAttribute("Font", QString("%1").arg(font));
1420 writer.writeAttribute("Bold", QString("%1").arg(bold));
1421 writer.writeAttribute("Italic", QString("%1").arg(italic));
1422 writer.writeAttribute("Shadow", QString("%1").arg(shadow));
1424 writer.writeStartElement("Color");
1425 writer.writeAttribute("R", QString("%1").arg(color[0]));
1426 writer.writeAttribute("G", QString("%1").arg(color[1]));
1427 writer.writeAttribute("B", QString("%1").arg(color[2]));
1428 writer.writeEndElement();
1429 writer.writeEndElement();
1430 // params += QString().sprintf( "* Labels *%u*%u*%u*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible, labels, offset,
1431 // color[0], color[1], color[2], font, bold, italic, shadow );
1434 isVisible = actor->GetTickVisibility();
1435 int length = actor->GetTickLength();
1436 writer.writeStartElement("TickMarks");
1437 writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1438 writer.writeAttribute("Length", QString("%1").arg(length));
1439 writer.writeEndElement();
1441 //params += QString().sprintf( "* Tick marks *%u*%u", isVisible, length );
1443 writer.writeEndElement();
1447 void setGradAxisVisualParams(QXmlStreamReader& reader, vtkAxisActor2D* actor)
1454 } while (!reader.isStartElement());
1456 // Read title params
1457 QXmlStreamAttributes aAttr = reader.attributes();
1458 bool isVisible = aAttr.value("isVisible").toString().toUShort();
1459 QString title = aAttr.value("Text").toString();
1460 int font = aAttr.value("Font").toString().toInt();
1461 int bold = aAttr.value("Bold").toString().toInt();
1462 int italic = aAttr.value("Italic").toString().toInt();
1463 int shadow = aAttr.value("Shadow").toString().toInt();
1465 //printf("#### TITLE: %i, %s, %i, %i, %i, %i\n", isVisible, qPrintable(title), font, bold, italic, shadow);
1469 } while (!reader.isStartElement());
1472 aAttr = reader.attributes();
1475 color[0] = aAttr.value("R").toString().toDouble();
1476 color[1] = aAttr.value("G").toString().toDouble();
1477 color[2] = aAttr.value("B").toString().toDouble();
1478 //printf("#### Color: %f, %f, %f\n", color[0], color[1], color[2]);
1480 actor->SetTitleVisibility( isVisible );
1481 actor->SetTitle( title.toLatin1() );
1482 vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1484 txtProp->SetColor( color );
1485 txtProp->SetFontFamily( font );
1486 txtProp->SetBold( bold );
1487 txtProp->SetItalic( italic );
1488 txtProp->SetShadow( shadow );
1495 } while (!reader.isStartElement());
1497 aAttr = reader.attributes();
1498 isVisible = aAttr.value("isVisible").toString().toUShort();
1499 int labels = aAttr.value("Number").toString().toInt();
1500 int offset = aAttr.value("Offset").toString().toInt();
1501 font = aAttr.value("Font").toString().toInt();
1502 bold = aAttr.value("Bold").toString().toInt();
1503 italic = aAttr.value("Italic").toString().toInt();
1504 shadow = aAttr.value("Shadow").toString().toInt();
1508 } while (!reader.isStartElement());
1510 aAttr = reader.attributes();
1512 color[0] = aAttr.value("R").toString().toDouble();
1513 color[1] = aAttr.value("G").toString().toDouble();
1514 color[2] = aAttr.value("B").toString().toDouble();
1516 actor->SetLabelVisibility( isVisible );
1517 actor->SetNumberOfLabels( labels );
1518 actor->SetTickOffset( offset );
1519 txtProp = actor->GetLabelTextProperty();
1521 txtProp->SetColor( color );
1522 txtProp->SetFontFamily( font );
1523 txtProp->SetBold( bold );
1524 txtProp->SetItalic( italic );
1525 txtProp->SetShadow( shadow );
1531 } while (!reader.isStartElement());
1532 aAttr = reader.attributes();
1534 // retrieve and set tick marks properties
1535 isVisible = aAttr.value("isVisible").toString().toUShort();
1536 int length = aAttr.value("Length").toString().toInt();
1538 actor->SetTickVisibility( isVisible );
1539 actor->SetTickLength( length );
1542 /*! The method restores visual parameters of a graduated axis actor (x,y,z axis)
1544 void setGradAxisVisualParams( vtkAxisActor2D* actor, const QString& params )
1549 QStringList paramsLst = params.split( '*' );
1551 if ( paramsLst.size() == nGradAxisParams ) { // altogether name, lable, ticks parameters make up 25 values
1553 // retrieve and set name parameters
1554 bool isVisible = paramsLst[2].toUShort();
1555 QString title = paramsLst[3];
1557 color[0] = paramsLst[4].toDouble();
1558 color[1] = paramsLst[5].toDouble();
1559 color[2] = paramsLst[6].toDouble();
1560 int font = paramsLst[7].toInt();
1561 int bold = paramsLst[8].toInt();
1562 int italic = paramsLst[9].toInt();
1563 int shadow = paramsLst[10].toInt();
1565 actor->SetTitleVisibility( isVisible );
1566 actor->SetTitle( title.toLatin1() );
1567 vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1569 txtProp->SetColor( color );
1570 txtProp->SetFontFamily( font );
1571 txtProp->SetBold( bold );
1572 txtProp->SetItalic( italic );
1573 txtProp->SetShadow( shadow );
1576 // retrieve and set lable parameters
1577 isVisible = paramsLst[12].toUShort();
1578 int labels = paramsLst[13].toInt();
1579 int offset = paramsLst[14].toInt();
1580 color[0] = paramsLst[15].toDouble();
1581 color[1] = paramsLst[16].toDouble();
1582 color[2] = paramsLst[17].toDouble();
1583 font = paramsLst[18].toInt();
1584 bold = paramsLst[19].toInt();
1585 italic = paramsLst[20].toInt();
1586 shadow = paramsLst[21].toInt();
1588 actor->SetLabelVisibility( isVisible );
1589 actor->SetNumberOfLabels( labels );
1590 actor->SetTickOffset( offset );
1591 txtProp = actor->GetLabelTextProperty();
1593 txtProp->SetColor( color );
1594 txtProp->SetFontFamily( font );
1595 txtProp->SetBold( bold );
1596 txtProp->SetItalic( italic );
1597 txtProp->SetShadow( shadow );
1600 // retrieve and set tick marks properties
1601 isVisible = paramsLst[23].toUShort();
1602 int length = paramsLst[24].toInt();
1604 actor->SetTickVisibility( isVisible );
1605 actor->SetTickLength( length );
1609 /*! The method returns the visual parameters of this view as a formated string
1611 QString SVTK_ViewWindow::getVisualParameters()
1613 double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
1615 // save position, focal point, viewUp, scale
1616 vtkCamera* camera = getRenderer()->GetActiveCamera();
1617 camera->GetPosition( pos );
1618 camera->GetFocalPoint( focalPnt );
1619 camera->GetViewUp( viewUp );
1620 parScale = camera->GetParallelScale();
1623 // Parameters are given in the following format:view position (3 digits), focal point position (3 digits)
1624 // view up values (3 digits), parallel scale (1 digit), scale (3 digits,
1625 // Graduated axes parameters (X, Y, Z axes parameters)
1627 QXmlStreamWriter aWriter(&retStr);
1628 aWriter.setAutoFormatting(true);
1630 aWriter.writeStartDocument();
1631 aWriter.writeStartElement("ViewState");
1633 aWriter.writeStartElement("Position");
1634 aWriter.writeAttribute("X", QString("%1").arg(pos[0]));
1635 aWriter.writeAttribute("Y", QString("%1").arg(pos[1]));
1636 aWriter.writeAttribute("Z", QString("%1").arg(pos[2]));
1637 aWriter.writeEndElement();
1639 aWriter.writeStartElement("FocalPoint");
1640 aWriter.writeAttribute("X", QString::number(focalPnt[0]));
1641 aWriter.writeAttribute("Y", QString::number(focalPnt[1]));
1642 aWriter.writeAttribute("Z", QString::number(focalPnt[2]));
1643 aWriter.writeEndElement();
1645 aWriter.writeStartElement("ViewUp");
1646 aWriter.writeAttribute("X", QString::number(viewUp[0]));
1647 aWriter.writeAttribute("Y", QString::number(viewUp[1]));
1648 aWriter.writeAttribute("Z", QString::number(viewUp[2]));
1649 aWriter.writeEndElement();
1651 aWriter.writeStartElement("ViewScale");
1652 aWriter.writeAttribute("Parallel", QString::number(parScale));
1653 aWriter.writeAttribute("X", QString::number(scale[0]));
1654 aWriter.writeAttribute("Y", QString::number(scale[1]));
1655 aWriter.writeAttribute("Z", QString::number(scale[2]));
1656 aWriter.writeEndElement();
1658 if ( SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes() ) {
1659 aWriter.writeStartElement("DisplayCubeAxis");
1660 aWriter.writeAttribute("Show", QString( "%1" ).arg( GetRenderer()->IsCubeAxesDisplayed()));
1661 aWriter.writeEndElement();
1663 getGradAxisVisualParams(aWriter, gradAxesActor->GetXAxisActor2D(), "X");
1664 getGradAxisVisualParams(aWriter, gradAxesActor->GetYAxisActor2D(), "Y");
1665 getGradAxisVisualParams(aWriter, gradAxesActor->GetZAxisActor2D(), "Z");
1668 aWriter.writeStartElement("Trihedron");
1669 aWriter.writeAttribute("isShown", QString( "%1" ).arg( isTrihedronDisplayed()));
1670 aWriter.writeAttribute("Size", QString::number(GetTrihedronSize()));
1671 aWriter.writeEndElement();
1673 aWriter.writeStartElement("Background");
1674 aWriter.writeAttribute("Value", QString( "%1" ).arg( Qtx::backgroundToString(background()) ));
1675 aWriter.writeEndElement();
1677 aWriter.writeEndElement();
1678 aWriter.writeEndDocument();
1684 The method restores visual parameters of this view or postpones it untill the view is shown
1686 void SVTK_ViewWindow::setVisualParameters( const QString& parameters )
1688 //printf("#### %s\n", qPrintable(parameters));
1689 SVTK_RenderWindowInteractor* anInteractor = GetInteractor();
1690 if ( anInteractor->isVisible() ) {
1691 doSetVisualParameters( parameters );
1694 myVisualParams = parameters;
1695 anInteractor->installEventFilter(this);
1700 The method restores visual parameters of this view from a formated string
1702 void SVTK_ViewWindow::doSetVisualParameters( const QString& parameters, bool baseParamsOnly )
1705 double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
1707 QXmlStreamReader aReader(parameters);
1708 SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes();
1710 while(!aReader.atEnd()) {
1712 if (aReader.isStartElement()) {
1713 QXmlStreamAttributes aAttr = aReader.attributes();
1714 //printf("### Name = %s\n", qPrintable(aReader.name().toString()));
1715 if (aReader.name() == "Position") {
1716 pos[0] = aAttr.value("X").toString().toDouble();
1717 pos[1] = aAttr.value("Y").toString().toDouble();
1718 pos[2] = aAttr.value("Z").toString().toDouble();
1719 //printf("#### Position %f; %f; %f\n", pos[0], pos[1], pos[2]);
1721 else if (aReader.name() == "FocalPoint") {
1722 focalPnt[0] = aAttr.value("X").toString().toDouble();
1723 focalPnt[1] = aAttr.value("Y").toString().toDouble();
1724 focalPnt[2] = aAttr.value("Z").toString().toDouble();
1725 //printf("#### FocalPoint %f; %f; %f\n", focalPnt[0], focalPnt[1], focalPnt[2]);
1727 else if (aReader.name() == "ViewUp") {
1728 viewUp[0] = aAttr.value("X").toString().toDouble();
1729 viewUp[1] = aAttr.value("Y").toString().toDouble();
1730 viewUp[2] = aAttr.value("Z").toString().toDouble();
1731 //printf("#### ViewUp %f; %f; %f\n", viewUp[0], viewUp[1], viewUp[2]);
1733 else if (aReader.name() == "ViewScale") {
1734 parScale = aAttr.value("Parallel").toString().toDouble();
1735 scale[0] = aAttr.value("X").toString().toDouble();
1736 scale[1] = aAttr.value("Y").toString().toDouble();
1737 scale[2] = aAttr.value("Z").toString().toDouble();
1738 //printf("#### ViewScale %f; %f; %f\n", scale[0], scale[1], scale[2]);
1740 else if (aReader.name() == "DisplayCubeAxis") {
1741 if ( !baseParamsOnly ) {
1742 if (aAttr.value("Show") == "0")
1743 gradAxesActor->VisibilityOff();
1745 gradAxesActor->VisibilityOn();
1748 else if (aReader.name() == "GraduatedAxis") {
1749 if ( !baseParamsOnly ) {
1750 if(aAttr.value("Axis") == "X")
1751 setGradAxisVisualParams(aReader, gradAxesActor->GetXAxisActor2D());
1752 else if(aAttr.value("Axis") == "Y")
1753 setGradAxisVisualParams(aReader, gradAxesActor->GetYAxisActor2D());
1754 else if(aAttr.value("Axis") == "Z")
1755 setGradAxisVisualParams(aReader, gradAxesActor->GetZAxisActor2D());
1758 else if (aReader.name() == "Trihedron") {
1759 if ( !baseParamsOnly ) {
1760 if (aAttr.value("isShown") == "0")
1761 GetTrihedron()->VisibilityOff();
1763 GetTrihedron()->VisibilityOn();
1764 SetTrihedronSize(aAttr.value("Size").toString().toDouble());
1767 else if (aReader.name() == "Background") {
1768 if ( !baseParamsOnly ) {
1769 setBackground( Qtx::stringToBackground( aAttr.value("Value").toString() ) );
1774 if (!aReader.hasError()) {
1775 vtkCamera* camera = getRenderer()->GetActiveCamera();
1776 camera->SetPosition( pos );
1777 camera->SetFocalPoint( focalPnt );
1778 camera->SetViewUp( viewUp );
1779 camera->SetParallelScale( parScale );
1780 GetRenderer()->SetScale( scale );
1781 //SetScale( scale );
1784 QStringList paramsLst = parameters.split( '*' );
1785 if ( paramsLst.size() >= nNormalParams ) {
1786 // 'reading' list of parameters
1787 pos[0] = paramsLst[0].toDouble();
1788 pos[1] = paramsLst[1].toDouble();
1789 pos[2] = paramsLst[2].toDouble();
1790 focalPnt[0] = paramsLst[3].toDouble();
1791 focalPnt[1] = paramsLst[4].toDouble();
1792 focalPnt[2] = paramsLst[5].toDouble();
1793 viewUp[0] = paramsLst[6].toDouble();
1794 viewUp[1] = paramsLst[7].toDouble();
1795 viewUp[2] = paramsLst[8].toDouble();
1796 parScale = paramsLst[9].toDouble();
1797 scale[0] = paramsLst[10].toDouble();
1798 scale[1] = paramsLst[11].toDouble();
1799 scale[2] = paramsLst[12].toDouble();
1801 // applying parameters
1802 vtkCamera* camera = getRenderer()->GetActiveCamera();
1803 camera->SetPosition( pos );
1804 camera->SetFocalPoint( focalPnt );
1805 camera->SetViewUp( viewUp );
1806 camera->SetParallelScale( parScale );
1807 GetRenderer()->SetScale( scale );
1808 //SetScale( scale );
1810 // apply graduated axes parameters
1811 if ( !baseParamsOnly ) {
1812 SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes();
1813 if ( gradAxesActor && paramsLst.size() == nAllParams ) {
1814 int i = nNormalParams+1, j = i + nGradAxisParams - 1;
1815 ::setGradAxisVisualParams( gradAxesActor->GetXAxisActor2D(), parameters.section( '*', i, j ) );
1816 i = j + 1; j += nGradAxisParams;
1817 ::setGradAxisVisualParams( gradAxesActor->GetYAxisActor2D(), parameters.section( '*', i, j ) );
1818 i = j + 1; j += nGradAxisParams;
1819 ::setGradAxisVisualParams( gradAxesActor->GetZAxisActor2D(), parameters.section( '*', i, j ) );
1821 if ( paramsLst[13].toUShort() )
1822 gradAxesActor->VisibilityOn();
1824 gradAxesActor->VisibilityOff();
1826 else if ( paramsLst.size() == nAllParams ) {
1827 if ( paramsLst[90].toUShort() )
1828 GetTrihedron()->VisibilityOn();
1830 GetTrihedron()->VisibilityOff();
1832 SetTrihedronSize(paramsLst[91].toDouble());
1842 Delayed setVisualParameters
1844 bool SVTK_ViewWindow::eventFilter( QObject* theWatched, QEvent* theEvent )
1846 if ( theEvent->type() == QEvent::Show && theWatched->inherits( "SVTK_RenderWindowInteractor" ) ) {
1847 SVTK_RenderWindowInteractor* anInteractor = (SVTK_RenderWindowInteractor*)theWatched;
1848 if ( anInteractor->isVisible() ) {
1849 doSetVisualParameters( myVisualParams );
1850 anInteractor->removeEventFilter( this ); // theWatched = RenderWindowInteractor
1853 return SUIT_ViewWindow::eventFilter( theWatched, theEvent );
1858 Change rotation point
1860 void SVTK_ViewWindow::onChangeRotationPoint(bool theIsActivate)
1863 mySetRotationPointDlg->addObserver();
1864 if ( mySetRotationPointDlg->IsFirstShown() )
1865 activateSetRotationGravity();
1866 mySetRotationPointDlg->show();
1868 mySetRotationPointDlg->hide();
1872 Set the gravity center as a rotation point
1874 void SVTK_ViewWindow::activateSetRotationGravity()
1876 myEventDispatcher->InvokeEvent(SVTK::SetRotateGravity,0);
1880 Set the selected point as a rotation point
1882 void SVTK_ViewWindow::activateSetRotationSelected(void* theData)
1884 myEventDispatcher->InvokeEvent(SVTK::ChangeRotationPoint,theData);
1888 Set the gravity center of element selected by user as a rotation point
1890 void SVTK_ViewWindow::activateStartPointSelection( Selection_Mode theSelectionMode )
1892 SetSelectionMode( theSelectionMode );
1893 myEventDispatcher->InvokeEvent(SVTK::StartPointSelection,0);
1897 Set the view projection mode: orthogonal or perspective
1899 void SVTK_ViewWindow::onPerspectiveMode()
1901 bool anIsParallelMode = toolMgr()->action( ParallelModeId )->isChecked();
1903 // advanced zooming is not available in perspective mode
1904 if( QtxAction* anAction = getAction( SwitchZoomingStyleId ) )
1905 anAction->setEnabled( anIsParallelMode );
1907 vtkCamera* aCamera = getRenderer()->GetActiveCamera();
1908 aCamera->SetParallelProjection(anIsParallelMode);
1909 GetInteractor()->GetDevice()->CreateTimer(VTKI_TIMER_FIRST);
1911 emit transformed( this );
1914 void SVTK_ViewWindow::SetEventDispatcher(vtkObject* theDispatcher)
1916 myEventDispatcher = theDispatcher;
1920 Creates all actions of svtk main window
1922 void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
1924 QtxAction* anAction;
1925 QtxActionToolMgr* mgr = toolMgr();
1928 anAction = new QtxAction(tr("MNU_DUMP_VIEW"),
1929 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
1930 tr( "MNU_DUMP_VIEW" ), 0, this);
1931 anAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1932 connect(anAction, SIGNAL(activated()), this, SLOT(onDumpView()));
1933 mgr->registerAction( anAction, DumpId );
1936 anAction = new QtxAction(tr("MNU_FITALL"),
1937 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
1938 tr( "MNU_FITALL" ), 0, this);
1939 anAction->setStatusTip(tr("DSC_FITALL"));
1940 connect(anAction, SIGNAL(activated()), this, SLOT(onFitAll()));
1941 mgr->registerAction( anAction, FitAllId );
1944 anAction = new QtxAction(tr("MNU_FITRECT"),
1945 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
1946 tr( "MNU_FITRECT" ), 0, this);
1947 anAction->setStatusTip(tr("DSC_FITRECT"));
1948 connect(anAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
1949 mgr->registerAction( anAction, FitRectId );
1952 anAction = new QtxAction(tr("MNU_FITSELECTION"),
1953 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITSELECTION" ) ),
1954 tr( "MNU_FITSELECTION" ), 0, this);
1955 anAction->setStatusTip(tr("DSC_FITSELECTION"));
1956 connect(anAction, SIGNAL(activated()), this, SLOT(onFitSelection()));
1957 mgr->registerAction( anAction, FitSelectionId );
1960 anAction = new QtxAction(tr("MNU_ZOOM_VIEW"),
1961 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
1962 tr( "MNU_ZOOM_VIEW" ), 0, this);
1963 anAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1964 connect(anAction, SIGNAL(activated()), this, SLOT(activateZoom()));
1965 mgr->registerAction( anAction, ZoomId );
1968 anAction = new QtxAction(tr("MNU_PAN_VIEW"),
1969 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
1970 tr( "MNU_PAN_VIEW" ), 0, this);
1971 anAction->setStatusTip(tr("DSC_PAN_VIEW"));
1972 connect(anAction, SIGNAL(activated()), this, SLOT(activatePanning()));
1973 mgr->registerAction( anAction, PanId );
1976 anAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"),
1977 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
1978 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1979 anAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1980 connect(anAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
1981 mgr->registerAction( anAction, GlobalPanId );
1983 // Change rotation point
1984 anAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"),
1985 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_ROTATION_POINT" ) ),
1986 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1987 anAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1988 anAction->setCheckable(true);
1989 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onChangeRotationPoint(bool)));
1990 mgr->registerAction( anAction, ChangeRotationPointId );
1993 anAction = new QtxAction(tr("MNU_ROTATE_VIEW"),
1994 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
1995 tr( "MNU_ROTATE_VIEW" ), 0, this);
1996 anAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1997 connect(anAction, SIGNAL(activated()), this, SLOT(activateRotation()));
1998 mgr->registerAction( anAction, RotationId );
2001 anAction = new QtxAction(tr("MNU_FRONT_VIEW"),
2002 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
2003 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
2004 anAction->setStatusTip(tr("DSC_FRONT_VIEW"));
2005 connect(anAction, SIGNAL(activated()), this, SLOT(onFrontView()));
2006 this->addAction(anAction);
2007 mgr->registerAction( anAction, FrontId );
2009 anAction = new QtxAction(tr("MNU_BACK_VIEW"),
2010 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
2011 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
2012 anAction->setStatusTip(tr("DSC_BACK_VIEW"));
2013 connect(anAction, SIGNAL(activated()), this, SLOT(onBackView()));
2014 this->addAction(anAction);
2015 mgr->registerAction( anAction, BackId );
2017 anAction = new QtxAction(tr("MNU_TOP_VIEW"),
2018 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
2019 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
2020 anAction->setStatusTip(tr("DSC_TOP_VIEW"));
2021 connect(anAction, SIGNAL(activated()), this, SLOT(onTopView()));
2022 this->addAction(anAction);
2023 mgr->registerAction( anAction, TopId );
2025 anAction = new QtxAction(tr("MNU_BOTTOM_VIEW"),
2026 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
2027 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
2028 anAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
2029 connect(anAction, SIGNAL(activated()), this, SLOT(onBottomView()));
2030 this->addAction(anAction);
2031 mgr->registerAction( anAction, BottomId );
2033 anAction = new QtxAction(tr("MNU_LEFT_VIEW"),
2034 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
2035 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
2036 anAction->setStatusTip(tr("DSC_LEFT_VIEW"));
2037 connect(anAction, SIGNAL(activated()), this, SLOT(onLeftView()));
2038 this->addAction(anAction);
2039 mgr->registerAction( anAction, LeftId );
2041 anAction = new QtxAction(tr("MNU_RIGHT_VIEW"),
2042 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
2043 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
2044 anAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
2045 connect(anAction, SIGNAL(activated()), this, SLOT(onRightView()));
2046 this->addAction(anAction);
2047 mgr->registerAction( anAction, RightId );
2049 // rotate anticlockwise
2050 anAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"),
2051 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ANTICLOCKWISE" ) ),
2052 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
2053 anAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
2054 connect(anAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
2055 this->addAction(anAction);
2056 mgr->registerAction( anAction, AntiClockWiseId );
2059 anAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"),
2060 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_CLOCKWISE" ) ),
2061 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
2062 anAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
2063 connect(anAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
2064 this->addAction(anAction);
2065 mgr->registerAction( anAction, ClockWiseId );
2068 anAction = new QtxAction(tr("MNU_RESET_VIEW"),
2069 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
2070 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
2071 anAction->setStatusTip(tr("DSC_RESET_VIEW"));
2072 connect(anAction, SIGNAL(activated()), this, SLOT(onResetView()));
2073 this->addAction(anAction);
2074 mgr->registerAction( anAction, ResetId );
2076 // onViewTrihedron: Shows - Hides Trihedron
2077 anAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"),
2078 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ),
2079 tr( "MNU_SHOW_TRIHEDRON" ), 0, this);
2080 anAction->setCheckable( true );
2081 anAction->setChecked( true );
2083 anAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON"));
2084 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onViewTrihedron(bool)));
2085 mgr->registerAction( anAction, ViewTrihedronId );
2087 // onNonIsometric: Manage non-isometric params
2088 anAction = new QtxAction(tr("MNU_SVTK_SCALING"),
2089 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SCALING" ) ),
2090 tr( "MNU_SVTK_SCALING" ), 0, this);
2091 anAction->setStatusTip(tr("DSC_SVTK_SCALING"));
2092 anAction->setCheckable(true);
2093 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onNonIsometric(bool)));
2094 mgr->registerAction( anAction, NonIsometric );
2096 // onGraduatedAxes: Manage graduated axes params
2097 anAction = new QtxAction(tr("MNU_SVTK_GRADUATED_AXES"),
2098 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_GRADUATED_AXES" ) ),
2099 tr( "MNU_SVTK_GRADUATED_AXES" ), 0, this);
2100 anAction->setStatusTip(tr("DSC_SVTK_GRADUATED_AXES"));
2101 anAction->setCheckable(true);
2102 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onGraduatedAxes(bool)));
2103 mgr->registerAction( anAction, GraduatedAxes );
2105 // onGraduatedAxes: Manage graduated axes params
2106 anAction = new QtxAction(tr("MNU_SVTK_UPDATE_RATE"),
2107 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_UPDATE_RATE" ) ),
2108 tr( "MNU_SVTK_UPDATE_RATE" ), 0, this);
2109 anAction->setStatusTip(tr("DSC_SVTK_UPDATE_RATE"));
2110 anAction->setCheckable(true);
2111 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onUpdateRate(bool)));
2112 mgr->registerAction( anAction, UpdateRate );
2114 // Set perspective mode group
2115 anAction = new QtxAction(tr("MNU_SVTK_PARALLEL_MODE"),
2116 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARALLEL" ) ),
2117 tr( "MNU_SVTK_PARALLEL_MODE" ), 0, this);
2118 anAction->setStatusTip(tr("DSC_SVTK_PARALLEL_MODE"));
2119 anAction->setCheckable(true);
2120 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onPerspectiveMode()));
2121 mgr->registerAction( anAction, ParallelModeId );
2123 anAction = new QtxAction(tr("MNU_SVTK_PERSPECTIVE_MODE"),
2124 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PERSPECTIVE" ) ),
2125 tr( "MNU_SVTK_PERSPECTIVE_MODE" ), 0, this);
2126 anAction->setStatusTip(tr("DSC_SVTK_PERSPECTIVE_MODE"));
2127 anAction->setCheckable(true);
2128 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onPerspectiveMode()));
2129 mgr->registerAction( anAction, ProjectionModeId );
2131 QActionGroup* aPerspectiveGroup = new QActionGroup( this );
2132 aPerspectiveGroup->addAction( mgr->action( ParallelModeId ) );
2133 aPerspectiveGroup->addAction( mgr->action( ProjectionModeId ) );
2136 anAction = new QtxAction(tr("MNU_VIEWPARAMETERS_VIEW"),
2137 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARAMETERS" ) ),
2138 tr( "MNU_VIEWPARAMETERS_VIEW" ), 0, this);
2139 anAction->setStatusTip(tr("DSC_VIEWPARAMETERS_VIEW"));
2140 anAction->setCheckable(true);
2141 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onViewParameters(bool)));
2142 mgr->registerAction( anAction, ViewParametersId );
2145 mgr->registerAction( synchronizeAction(), SynchronizeId );
2147 // Switch between interaction styles
2148 anAction = new QtxAction(tr("MNU_SVTK_STYLE_SWITCH"),
2149 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_STYLE_SWITCH" ) ),
2150 tr( "MNU_SVTK_STYLE_SWITCH" ), 0, this);
2151 anAction->setStatusTip(tr("DSC_SVTK_STYLE_SWITCH"));
2152 anAction->setCheckable(true);
2153 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
2154 mgr->registerAction( anAction, SwitchInteractionStyleId );
2156 // Switch between zooming styles
2157 anAction = new QtxAction(tr("MNU_SVTK_ZOOMING_STYLE_SWITCH"),
2158 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_ZOOMING_STYLE_SWITCH" ) ),
2159 tr( "MNU_SVTK_ZOOMING_STYLE_SWITCH" ), 0, this);
2160 anAction->setStatusTip(tr("DSC_SVTK_ZOOMING_STYLE_SWITCH"));
2161 anAction->setCheckable(true);
2162 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
2163 mgr->registerAction( anAction, SwitchZoomingStyleId );
2166 QSignalMapper* aSignalMapper = new QSignalMapper( this );
2167 connect(aSignalMapper, SIGNAL(mapped(int)), this, SLOT(onSwitchPreSelectionMode(int)));
2169 anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_STANDARD"),
2170 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_STANDARD" ) ),
2171 tr( "MNU_SVTK_PRESELECTION_STANDARD" ), 0, this);
2172 anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_STANDARD"));
2173 anAction->setCheckable(true);
2174 connect(anAction, SIGNAL(activated()), aSignalMapper, SLOT(map()));
2175 aSignalMapper->setMapping( anAction, Standard_Preselection );
2176 mgr->registerAction( anAction, StandardPreselectionId );
2178 anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_DYNAMIC"),
2179 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_DYNAMIC" ) ),
2180 tr( "MNU_SVTK_PRESELECTION_DYNAMIC" ), 0, this);
2181 anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_DYNAMIC"));
2182 anAction->setCheckable(true);
2183 connect(anAction, SIGNAL(activated()), aSignalMapper, SLOT(map()));
2184 aSignalMapper->setMapping( anAction, Dynamic_Preselection );
2185 mgr->registerAction( anAction, DynamicPreselectionId );
2187 anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_DISABLED"),
2188 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_DISABLED" ) ),
2189 tr( "MNU_SVTK_PRESELECTION_DISABLED" ), 0, this);
2190 anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_DISABLED"));
2191 anAction->setCheckable(true);
2192 connect(anAction, SIGNAL(activated()), aSignalMapper, SLOT(map()));
2193 aSignalMapper->setMapping( anAction, Preselection_Disabled );
2194 mgr->registerAction( anAction, DisablePreselectionId );
2196 QtxActionGroup* aPreselectionAction = new QtxActionGroup( this, true );
2197 aPreselectionAction->add( getAction( StandardPreselectionId ) );
2198 aPreselectionAction->add( getAction( DynamicPreselectionId ) );
2199 aPreselectionAction->add( getAction( DisablePreselectionId ) );
2200 mgr->registerAction( aPreselectionAction, PreselectionId );
2203 anAction = new QtxAction(tr("MNU_SVTK_ENABLE_SELECTION"),
2204 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SELECTION" ) ),
2205 tr( "MNU_SVTK_ENABLE_SELECTION" ), 0, this);
2206 anAction->setStatusTip(tr("DSC_SVTK_ENABLE_SELECTION"));
2207 anAction->setCheckable(true);
2208 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onEnableSelection(bool)));
2209 mgr->registerAction( anAction, EnableSelectionId );
2212 myStartAction = new QtxAction(tr("MNU_SVTK_RECORDING_START"),
2213 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_START" ) ),
2214 tr( "MNU_SVTK_RECORDING_START" ), 0, this);
2215 myStartAction->setStatusTip(tr("DSC_SVTK_RECORDING_START"));
2216 connect( myStartAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStartRecording() ) );
2217 mgr->registerAction( myStartAction, StartRecordingId );
2220 myPlayAction = new QtxAction(tr("MNU_SVTK_RECORDING_PLAY"),
2221 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PLAY" ) ),
2222 tr( "MNU_SVTK_RECORDING_PLAY" ), 0, this);
2223 myPlayAction->setStatusTip(tr("DSC_SVTK_RECORDING_PLAY"));
2224 myPlayAction->setEnabled( false );
2225 connect( myPlayAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPlayRecording() ) );
2226 mgr->registerAction( myPlayAction, PlayRecordingId );
2229 myPauseAction = new QtxAction(tr("MNU_SVTK_RECORDING_PAUSE"),
2230 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PAUSE" ) ),
2231 tr( "MNU_SVTK_RECORDING_PAUSE" ), 0, this);
2232 myPauseAction->setStatusTip(tr("DSC_SVTK_RECORDING_PAUSE"));
2233 myPauseAction->setEnabled( false );
2234 connect( myPauseAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPauseRecording() ) );
2235 mgr->registerAction( myPauseAction, PauseRecordingId );
2238 myStopAction = new QtxAction(tr("MNU_SVTK_RECORDING_STOP"),
2239 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_STOP" ) ),
2240 tr( "MNU_SVTK_RECORDING_STOP" ), 0, this);
2241 myStopAction->setStatusTip(tr("DSC_SVTK_RECORDING_STOP"));
2242 myStopAction->setEnabled( false );
2243 connect( myStopAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStopRecording() ) );
2244 mgr->registerAction( myStopAction, StopRecordingId );
2248 Creates toolbar of svtk main window
2250 void SVTK_ViewWindow::createToolBar()
2252 QtxActionToolMgr* mgr = toolMgr();
2254 mgr->append( DumpId, myToolBar );
2255 mgr->append( SwitchInteractionStyleId, myToolBar );
2256 mgr->append( SwitchZoomingStyleId, myToolBar );
2258 mgr->append( mgr->separator(), myToolBar );
2260 mgr->append( PreselectionId, myToolBar );
2261 mgr->append( EnableSelectionId, myToolBar );
2263 mgr->append( mgr->separator(), myToolBar );
2265 mgr->append( ViewTrihedronId, myToolBar );
2267 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
2268 aScaleAction->insertAction( getAction( FitAllId ) );
2269 aScaleAction->insertAction( getAction( FitRectId ) );
2270 aScaleAction->insertAction( getAction( FitSelectionId ) );
2271 aScaleAction->insertAction( getAction( ZoomId ) );
2272 mgr->append( aScaleAction, myToolBar );
2274 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
2275 aPanningAction->insertAction( getAction( PanId ) );
2276 aPanningAction->insertAction( getAction( GlobalPanId ) );
2277 mgr->append( aPanningAction, myToolBar );
2279 mgr->append( ChangeRotationPointId, myToolBar );
2281 mgr->append( RotationId, myToolBar );
2283 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
2284 aViewsAction->insertAction( getAction( FrontId ) );
2285 aViewsAction->insertAction( getAction( BackId ) );
2286 aViewsAction->insertAction( getAction( TopId ) );
2287 aViewsAction->insertAction( getAction( BottomId ) );
2288 aViewsAction->insertAction( getAction( LeftId ) );
2289 aViewsAction->insertAction( getAction( RightId ) );
2290 mgr->append( aViewsAction, myToolBar );
2292 mgr->append( AntiClockWiseId, myToolBar );
2293 mgr->append( ClockWiseId, myToolBar );
2295 mgr->append( ResetId, myToolBar );
2297 mgr->append( UpdateRate, myToolBar );
2298 mgr->append( NonIsometric, myToolBar );
2299 mgr->append( GraduatedAxes, myToolBar );
2301 mgr->append( ViewParametersId, myToolBar );
2302 mgr->append( SynchronizeId, myToolBar );
2304 mgr->append( toolMgr()->separator(), myToolBar );
2306 mgr->append( ParallelModeId, myToolBar );
2307 mgr->append( ProjectionModeId, myToolBar );
2309 mgr->append( StartRecordingId, myRecordingToolBar );
2310 mgr->append( PlayRecordingId, myRecordingToolBar );
2311 mgr->append( PauseRecordingId, myRecordingToolBar );
2312 mgr->append( StopRecordingId, myRecordingToolBar );
2315 void SVTK_ViewWindow::onUpdateRate(bool theIsActivate)
2318 myUpdateRateDlg->Update();
2319 myUpdateRateDlg->show();
2321 myUpdateRateDlg->hide();
2324 void SVTK_ViewWindow::onNonIsometric(bool theIsActivate)
2327 myNonIsometricDlg->Update();
2328 myNonIsometricDlg->show();
2330 myNonIsometricDlg->hide();
2333 void SVTK_ViewWindow::onGraduatedAxes(bool theIsActivate)
2336 myCubeAxesDlg->Update();
2337 myCubeAxesDlg->show();
2339 myCubeAxesDlg->hide();
2343 Starts rotation transformation
2345 void SVTK_ViewWindow::activateRotation()
2347 myEventDispatcher->InvokeEvent(SVTK::StartRotate,0);
2352 Starts panning transformation
2354 void SVTK_ViewWindow::activatePanning()
2356 myEventDispatcher->InvokeEvent(SVTK::StartPan,0);
2360 Starts zoom transformation
2362 void SVTK_ViewWindow::activateZoom()
2364 myEventDispatcher->InvokeEvent(SVTK::StartZoom,0);
2368 Starts window fit transformation
2370 void SVTK_ViewWindow::activateWindowFit()
2372 myEventDispatcher->InvokeEvent(SVTK::StartFitArea,0);
2376 Starts global panning transformation
2378 void SVTK_ViewWindow::activateGlobalPanning()
2380 myEventDispatcher->InvokeEvent(SVTK::StartGlobalPan,0);
2383 void SVTK_ViewWindow::onStartRecording()
2385 myRecorder->CheckExistAVIMaker();
2386 if (myRecorder->ErrorStatus()) {
2387 SUIT_MessageBox::warning(this, tr("ERROR"), tr("MSG_NO_AVI_MAKER") );
2390 SVTK_RecorderDlg* aRecorderDlg = new SVTK_RecorderDlg( this, myRecorder );
2392 if( !aRecorderDlg->exec() )
2395 myStartAction->setEnabled( false );
2396 myPlayAction->setEnabled( false );
2397 myPauseAction->setEnabled( true );
2398 myStopAction->setEnabled( true );
2400 // to prevent resizing the window while recording
2401 myPreRecordingMinSize = minimumSize();
2402 myPreRecordingMaxSize = maximumSize();
2403 setFixedSize( size() );
2405 myRecorder->Record();
2409 void SVTK_ViewWindow::onPlayRecording()
2411 myStartAction->setEnabled( false );
2412 myPlayAction->setEnabled( false );
2413 myPauseAction->setEnabled( true );
2414 myStopAction->setEnabled( true );
2416 myRecorder->Pause();
2419 void SVTK_ViewWindow::onPauseRecording()
2421 myStartAction->setEnabled( false );
2422 myPlayAction->setEnabled( true );
2423 myPauseAction->setEnabled( false );
2424 myStopAction->setEnabled( true );
2426 myRecorder->Pause();
2429 void SVTK_ViewWindow::onStopRecording()
2431 myStartAction->setEnabled( true );
2432 myPlayAction->setEnabled( false );
2433 myPauseAction->setEnabled( false );
2434 myStopAction->setEnabled( false );
2438 setMinimumSize( myPreRecordingMinSize );
2439 setMaximumSize( myPreRecordingMaxSize );
2443 To invoke a VTK event on SVTK_RenderWindowInteractor instance
2445 void SVTK_ViewWindow::InvokeEvent(unsigned long theEvent, void* theCallData)
2447 GetInteractor()->InvokeEvent(theEvent,theCallData);
2451 Modify view parameters
2453 void SVTK_ViewWindow::onViewParameters(bool theIsActivate)
2456 myViewParameterDlg->addObserver();
2457 myViewParameterDlg->show();
2459 myViewParameterDlg->hide();
2463 Custom show event handler
2465 void SVTK_ViewWindow::showEvent( QShowEvent * theEvent )
2467 emit Show( theEvent );
2471 Custom hide event handler
2473 void SVTK_ViewWindow::hideEvent( QHideEvent * theEvent )
2475 emit Hide( theEvent );
2479 Emit transformed signal.
2481 void SVTK_ViewWindow::emitTransformed() {
2488 void SVTK_ViewWindow::ProcessEvents(vtkObject* vtkNotUsed(theObject),
2489 unsigned long theEvent,
2490 void* theClientData,
2493 SVTK_ViewWindow* self = reinterpret_cast<SVTK_ViewWindow*>(theClientData);
2495 self->emitTransformed();
2499 Get camera properties for the SVTK view window.
2500 \return shared pointer on camera properties.
2502 SUIT_CameraProperties SVTK_ViewWindow::cameraProperties()
2504 SUIT_CameraProperties aProps;
2507 vtkCamera* aCamera = getRenderer()->GetActiveCamera();
2511 aProps.setDimension( SUIT_CameraProperties::Dim3D );
2512 if ( toolMgr()->action( ParallelModeId ) ) {
2513 if ( toolMgr()->action( ParallelModeId )->isChecked() )
2514 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
2516 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
2519 double aFocalPoint[3];
2520 double aPosition[3];
2522 double anAxialScale[3];
2524 aCamera->OrthogonalizeViewUp();
2525 aCamera->GetFocalPoint( aFocalPoint );
2526 aCamera->GetPosition( aPosition );
2527 aCamera->GetViewUp( aViewUp );
2529 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2530 aProps.setPosition( aPosition[0], aPosition[1], aPosition[2] );
2531 aProps.setViewUp( aViewUp[0], aViewUp[1], aViewUp[2] );
2532 aProps.setMappingScale( aCamera->GetParallelScale() * 2.0 );
2534 if ( aProps.getProjection() == SUIT_CameraProperties::PrjPerspective )
2536 aProps.setViewAngle( aCamera->GetViewAngle() );
2539 GetRenderer()->GetScale( anAxialScale );
2540 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2547 This implementation synchronizes camera propreties.
2549 void SVTK_ViewWindow::synchronize( SUIT_ViewWindow* theView )
2551 bool blocked = blockSignals( true );
2553 SUIT_CameraProperties aProps = theView->cameraProperties();
2554 if ( !cameraProperties().isCompatible( aProps ) ) {
2555 // other view, this one is being currently synchronized to, seems has become incompatible
2556 // we have to break synchronization
2562 vtkCamera* aCamera = getRenderer()->GetActiveCamera();
2564 double aFocalPoint[3];
2565 double aPosition[3];
2567 double anAxialScale[3];
2569 // get common properties
2570 aProps.getViewUp( aViewUp[0], aViewUp[1], aViewUp[2] );
2571 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
2572 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2573 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2575 // restore properties to the camera
2576 aCamera->SetViewUp( aViewUp );
2577 aCamera->SetPosition( aPosition );
2578 aCamera->SetFocalPoint( aFocalPoint );
2579 aCamera->SetParallelScale( aProps.getMappingScale() / 2.0 );
2581 if ( aProps.getProjection() == SUIT_CameraProperties::PrjPerspective )
2583 aCamera->SetViewAngle( aProps.getViewAngle() );
2586 GetRenderer()->SetScale( anAxialScale );
2588 getRenderer()->ResetCameraClippingRange();
2591 blockSignals( blocked );