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 #include <OpenGLUtils_FrameBuffer.h>
108 int convertAction( const int accelAction )
110 switch ( accelAction ) {
111 case SUIT_Accel::PanLeft : return SVTK::PanLeftEvent;
112 case SUIT_Accel::PanRight : return SVTK::PanRightEvent;
113 case SUIT_Accel::PanUp : return SVTK::PanUpEvent;
114 case SUIT_Accel::PanDown : return SVTK::PanDownEvent;
115 case SUIT_Accel::ZoomIn : return SVTK::ZoomInEvent;
116 case SUIT_Accel::ZoomOut : return SVTK::ZoomOutEvent;
117 case SUIT_Accel::RotateLeft : return SVTK::RotateLeftEvent;
118 case SUIT_Accel::RotateRight : return SVTK::RotateRightEvent;
119 case SUIT_Accel::RotateUp : return SVTK::RotateUpEvent;
120 case SUIT_Accel::RotateDown : return SVTK::RotateDownEvent;
129 SVTK_ViewWindow::SVTK_ViewWindow(SUIT_Desktop* theDesktop):
130 SUIT_ViewWindow(theDesktop),
132 myDumpImage(QImage()),
133 myKeyFreeInteractorStyle(SVTK_KeyFreeInteractorStyle::New()),
134 myEventCallbackCommand(vtkCallbackCommand::New())
136 setWindowFlags( windowFlags() & ~Qt::Window );
137 // specific of vtkSmartPointer
138 myKeyFreeInteractorStyle->Delete();
142 To initialize #SVTK_ViewWindow instance
144 void SVTK_ViewWindow::Initialize(SVTK_ViewModelBase* theModel)
147 myInteractor = new SVTK_RenderWindowInteractor(this,"SVTK_RenderWindowInteractor");
149 SVTK_Selector* aSelector = SVTK_Selector::New();
150 int aPreselectionMode = SUIT_Session::session()->resourceMgr()->
151 integerValue( "VTKViewer", "preselection", Standard_Preselection );
152 aSelector->SetDynamicPreSelection( aPreselectionMode == Dynamic_Preselection );
153 aSelector->SetPreSelectionEnabled( aPreselectionMode != Preselection_Disabled );
154 bool isSelectionEnabled = SUIT_Session::session()->resourceMgr()->
155 booleanValue( "VTKViewer", "enable_selection", true );
156 aSelector->SetSelectionEnabled( isSelectionEnabled );
158 SVTK_GenericRenderWindowInteractor* aDevice = SVTK_GenericRenderWindowInteractor::New();
159 aDevice->SetRenderWidget(myInteractor);
160 aDevice->SetSelector(aSelector);
162 SVTK_Renderer* aRenderer = SVTK_Renderer::New();
163 aRenderer->Initialize(aDevice,aSelector);
165 myInteractor->Initialize(aDevice,aRenderer,aSelector);
171 myToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_LABEL"), // title (language-dependant)
172 QString( "VTKViewerViewOperations" ), // name (language-independant)
173 false ); // disable floatable toolbar
175 myRecordingToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_RECORD_LABEL"), // title (language-dependant)
176 QString( "VTKRecordingOperations" ), // name (language-independant)
177 false ); // disable floatable toolbar
179 createActions( SUIT_Session::session()->resourceMgr() );
182 SetEventDispatcher(myInteractor->GetDevice());
183 myInteractor->setBackgroundRole( QPalette::NoRole );//NoBackground
184 myInteractor->setFocusPolicy(Qt::StrongFocus);
185 myInteractor->setFocus();
186 setFocusProxy(myInteractor);
188 myUpdateRateDlg = new SVTK_UpdateRateDlg( getAction( UpdateRate ), this, "SVTK_UpdateRateDlg" );
189 myNonIsometricDlg = new SVTK_NonIsometricDlg( getAction( NonIsometric ), this, "SVTK_NonIsometricDlg" );
190 myCubeAxesDlg = new SVTK_CubeAxesDlg( getAction( GraduatedAxes ), this, "SVTK_CubeAxesDlg" );
191 myCubeAxesDlg->initialize();
192 mySetRotationPointDlg = new SVTK_SetRotationPointDlg
193 ( getAction( ChangeRotationPointId ), this, "SVTK_SetRotationPointDlg" );
194 myViewParameterDlg = new SVTK_ViewParameterDlg
195 ( getAction( ViewParametersId ), this, "SVTK_ViewParameterDlg" );
197 myDefaultInteractorStyle = SVTK_InteractorStyle::New();
198 myInteractor->PushInteractorStyle(myDefaultInteractorStyle);
199 myDefaultInteractorStyle->Delete();
201 myRecorder = SVTK_Recorder::New();
203 myRecorder->SetNbFPS( 17.3 );
204 myRecorder->SetQuality( 100 );
205 myRecorder->SetProgressiveMode( true );
206 myRecorder->SetUseSkippedFrames( true );
207 myRecorder->SetRenderWindow( myInteractor->getRenderWindow() );
209 setCentralWidget(myInteractor);
211 myAxesWidget = salomevtk::vtkPVAxesWidget::New();
212 myAxesWidget->SetParentRenderer(aRenderer->GetDevice());
213 myAxesWidget->SetViewport(0, 0, 0.25, 0.25);
214 myAxesWidget->SetInteractor(myInteractor->GetDevice());
215 myAxesWidget->SetEnabled(1);
216 myAxesWidget->SetInteractive(0);
218 salomevtk::vtkPVAxesActor* anAxesActor = myAxesWidget->GetAxesActor();
219 anAxesActor->GetXAxisTipProperty()->SetColor( 1.0, 0.0, 0.0 );
220 anAxesActor->GetXAxisShaftProperty()->SetColor( 1.0, 0.0, 0.0 );
221 anAxesActor->GetXAxisLabelProperty()->SetColor( 1.0, 0.0, 0.0 );
222 anAxesActor->GetYAxisTipProperty()->SetColor( 0.0, 1.0, 0.0 );
223 anAxesActor->GetYAxisShaftProperty()->SetColor( 0.0, 1.0, 0.0 );
224 anAxesActor->GetYAxisLabelProperty()->SetColor( 0.0, 1.0, 0.0 );
225 anAxesActor->GetZAxisTipProperty()->SetColor( 0.0, 0.0, 1.0 );
226 anAxesActor->GetZAxisShaftProperty()->SetColor( 0.0, 0.0, 1.0 );
227 anAxesActor->GetZAxisLabelProperty()->SetColor( 0.0, 0.0, 1.0 );
229 myView = new SVTK_View(this);
230 Initialize(myView,theModel);
233 myEventCallbackCommand->SetClientData(this);
234 myEventCallbackCommand->SetCallback(SVTK_ViewWindow::ProcessEvents);
235 myEventCallbackCommand->Delete();
237 GetInteractor()->GetInteractorStyle()->AddObserver(SVTK::OperationFinished,
238 myEventCallbackCommand.GetPointer(), 0.0);
239 myKeyFreeInteractorStyle->AddObserver(SVTK::OperationFinished,
240 myEventCallbackCommand.GetPointer(), 0.0);
244 myInteractor->getRenderWindow()->Render();
245 setBackground( Qtx::BackgroundData( Qt::black ) ); // set default background
250 To initialize #SVTK_ViewWindow instance
252 void SVTK_ViewWindow::Initialize(SVTK_View* theView,
253 SVTK_ViewModelBase* theModel)
255 connect(theView,SIGNAL(KeyPressed(QKeyEvent*)),
256 this,SLOT(onKeyPressed(QKeyEvent*)) );
257 connect(theView,SIGNAL(KeyReleased(QKeyEvent*)),
258 this,SLOT(onKeyReleased(QKeyEvent*)));
259 connect(theView,SIGNAL(MouseButtonPressed(QMouseEvent*)),
260 this,SLOT(onMousePressed(QMouseEvent*)));
261 connect(theView,SIGNAL(MouseButtonReleased(QMouseEvent*)),
262 this,SLOT(onMouseReleased(QMouseEvent*)));
263 connect(theView,SIGNAL(MouseDoubleClicked(QMouseEvent*)),
264 this,SLOT(onMouseDoubleClicked(QMouseEvent*)));
265 connect(theView,SIGNAL(MouseMove(QMouseEvent*)),
266 this,SLOT(onMouseMoving(QMouseEvent*)));
267 connect(theView,SIGNAL(contextMenuRequested(QContextMenuEvent*)),
268 this,SIGNAL(contextMenuRequested(QContextMenuEvent *)));
269 connect(theView,SIGNAL(selectionChanged()),
270 theModel,SLOT(onSelectionChanged()));
272 connect( this, SIGNAL( transformed( SVTK_ViewWindow* ) ), SLOT( emitViewModified() ) );
278 SVTK_ViewWindow::~SVTK_ViewWindow()
280 myRecorder->Delete();
281 myAxesWidget->Delete();
286 \return corresponding view
288 SVTK_View* SVTK_ViewWindow::getView()
294 \return corresponding vtk render window
296 vtkRenderWindow* SVTK_ViewWindow::getRenderWindow()
298 return GetInteractor()->getRenderWindow();
302 \return corresponding vtk render window interactor
304 SVTK_RenderWindowInteractor* SVTK_ViewWindow::GetInteractor() const
310 \return corresponding vtk render window interactor
312 vtkRenderWindowInteractor* SVTK_ViewWindow::getInteractor() const
314 return myInteractor->GetDevice();
318 \return corresponding vtk renderer
320 vtkRenderer* SVTK_ViewWindow::getRenderer() const
322 return GetInteractor()->getRenderer();
326 Redirect the request to SVTK_RenderWindowInteractor::GetRenderer
328 SVTK_Renderer* SVTK_ViewWindow::GetRenderer() const
330 return GetInteractor()->GetRenderer();
334 \return corresponding vtk selector
336 SVTK_Selector* SVTK_ViewWindow::GetSelector() const
338 return GetInteractor()->GetSelector();
342 Processes transformation "front view"
344 void SVTK_ViewWindow::onFrontView()
346 GetRenderer()->OnFrontView();
348 emit transformed( this );
352 Processes transformation "back view"
354 void SVTK_ViewWindow::onBackView()
356 GetRenderer()->OnBackView();
358 emit transformed( this );
362 Processes transformation "top view"
364 void SVTK_ViewWindow::onTopView()
366 GetRenderer()->OnTopView();
368 emit transformed( this );
372 Processes transformation "bottom view"
374 void SVTK_ViewWindow::onBottomView()
376 GetRenderer()->OnBottomView();
378 emit transformed( this );
382 Processes transformation "left view"
384 void SVTK_ViewWindow::onLeftView()
386 GetRenderer()->OnLeftView();
388 emit transformed( this );
392 Processes transformation "right view"
394 void SVTK_ViewWindow::onRightView()
396 GetRenderer()->OnRightView();
398 emit transformed( this );
402 \brief Rotate view 90 degrees clockwise
404 void SVTK_ViewWindow::onClockWiseView()
406 GetRenderer()->onClockWiseView();
408 emit transformed( this );
412 \brief Rotate view 90 degrees conterclockwise
414 void SVTK_ViewWindow::onAntiClockWiseView()
416 GetRenderer()->onAntiClockWiseView();
418 emit transformed( this );
422 Processes transformation "reset view": sets default orientation of viewport camera
424 void SVTK_ViewWindow::onResetView()
426 GetRenderer()->OnResetView();
428 emit transformed( this );
432 Processes transformation "fit all"
434 void SVTK_ViewWindow::onFitAll()
436 GetRenderer()->OnFitAll();
438 emit transformed( this );
442 Processes transformation "fit selection"
444 void SVTK_ViewWindow::onFitSelection()
446 GetRenderer()->onFitSelection();
448 emit transformed( this );
452 SLOT: called if selection is changed
454 void SVTK_ViewWindow::onSelectionChanged()
456 myView->onSelectionChanged();
460 Change selection mode
461 \param theMode - new selection mode
463 void SVTK_ViewWindow::SetSelectionMode(Selection_Mode theMode)
465 GetSelector()->SetSelectionMode(theMode);
469 \return selection mode
471 Selection_Mode SVTK_ViewWindow::SelectionMode() const
473 return GetSelector()->SelectionMode();
477 Unhilights all objects in viewer
479 void SVTK_ViewWindow::unHighlightAll()
481 myView->unHighlightAll();
485 Hilights/unhilights object in viewer
486 \param theIO - object to be updated
487 \param theIsHighlight - if it is true, object will be hilighted, otherwise it will be unhilighted
488 \param theIsUpdate - update current viewer
490 void SVTK_ViewWindow::highlight(const Handle(SALOME_InteractiveObject)& theIO,
494 myView->highlight( theIO, theIsHighlight, theIsUpdate );
498 \return true if object is in viewer or in collector
499 \param theIO - object to be checked
501 bool SVTK_ViewWindow::isInViewer( const Handle(SALOME_InteractiveObject)& theIO )
503 return myView->isInViewer( theIO );
507 \return true if object is displayed in viewer
508 \param theIO - object to be checked
510 bool SVTK_ViewWindow::isVisible( const Handle(SALOME_InteractiveObject)& theIO )
512 return myView->isVisible( theIO );
517 \param theEntry - entry that corresponds to intractive objects
519 Handle(SALOME_InteractiveObject) SVTK_ViewWindow::FindIObject(const char* theEntry)
521 return myView->FindIObject(theEntry);
526 \param theIO - object
527 \param theImmediatly - update viewer
529 void SVTK_ViewWindow::Display(const Handle(SALOME_InteractiveObject)& theIO,
532 myView->Display(theIO,theImmediatly);
537 \param theIO - object
538 \param theImmediatly - update viewer
540 void SVTK_ViewWindow::Erase(const Handle(SALOME_InteractiveObject)& theIO,
543 myView->Erase(theIO,theImmediatly);
547 Display only passed object
548 \param theIO - object
550 void SVTK_ViewWindow::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIO)
552 myView->DisplayOnly(theIO);
556 Display all objects in view
558 void SVTK_ViewWindow::DisplayAll()
560 myView->DisplayAll();
564 Erase all objects in view
566 void SVTK_ViewWindow::EraseAll()
572 Sets background color [obsolete]
573 \param color - new background color
575 void SVTK_ViewWindow::setBackgroundColor( const QColor& c )
577 Qtx::BackgroundData bg = background();
583 \return background color of viewer [obsolete]
585 QColor SVTK_ViewWindow::backgroundColor() const
587 return background().color();
592 \param bgData - new background data
594 void SVTK_ViewWindow::setBackground( const Qtx::BackgroundData& bgData )
598 if ( bgData.isValid() ) {
599 switch ( bgData.mode() ) {
600 case Qtx::ColorBackground:
602 QColor c = bgData.color();
604 // show solid-colored background
605 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
606 getRenderer()->SetGradientBackground( false ); // cancel gradient mode
607 getRenderer()->SetBackground( c.red()/255.0,
609 c.blue()/255.0 ); // set background color
614 case Qtx::SimpleGradientBackground:
617 int type = bgData.gradient( c1, c2 );
623 // show two-color gradient background
624 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
625 getRenderer()->SetGradientBackground( true ); // switch to gradient mode
627 VTKViewer_OpenGLRenderer* aRenderer =
628 VTKViewer_OpenGLRenderer::SafeDownCast( getRenderer() );
631 aRenderer->SetGradientType( type );
632 aRenderer->SetBackground( c1.redF(), c1.greenF(), c1.blueF() );
633 aRenderer->SetBackground2( c2.redF(), c2.greenF(), c2.blueF() );
639 case Qtx::CustomGradientBackground:
641 // NOT IMPLEMENTED YET
642 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
643 getRenderer()->SetGradientBackground( false ); // cancel gradient mode
650 if ( bgData.isTextureShown() ) {
652 int textureMode = bgData.texture( fileName );
653 QFileInfo fi( fileName );
654 if ( !fileName.isEmpty() && fi.exists() ) {
655 // read texture from file
656 QString extension = fi.suffix().toLower();
657 vtkImageReader2* aReader = 0;
658 if ( extension == "jpg" || extension == "jpeg" )
659 aReader = vtkJPEGReader::New();
660 else if ( extension == "bmp" )
661 aReader = vtkBMPReader::New();
662 else if ( extension == "tif" || extension == "tiff" )
663 aReader = vtkTIFFReader::New();
664 else if ( extension == "png" )
665 aReader = vtkPNGReader::New();
666 else if ( extension == "mhd" || extension == "mha" )
667 aReader = vtkMetaImageReader::New();
670 aReader->SetFileName( fi.absoluteFilePath().toLatin1().constData() );
672 VTKViewer_Texture* aTexture = VTKViewer_Texture::New();
673 vtkImageMapToColors* aMap = 0;
674 vtkAlgorithmOutput* anOutput;
676 // special processing for BMP reader
677 vtkBMPReader* aBMPReader = (vtkBMPReader*)aReader;
679 // Special processing for BMP file
680 aBMPReader->SetAllow8BitBMP(1);
682 aMap = vtkImageMapToColors::New();
683 aMap->SetInputConnection( aBMPReader->GetOutputPort() );
684 aMap->SetLookupTable( (vtkScalarsToColors*)aBMPReader->GetLookupTable() );
685 aMap->SetOutputFormatToRGB();
687 anOutput = aMap->GetOutputPort();
692 anOutput = aReader->GetOutputPort( 0 );
693 aTexture->SetInputConnection( anOutput );
695 // VSR: Currently, VTK only supports Stretch mode, so below code will give
696 // the same results for all modes
697 switch ( textureMode ) {
698 case Qtx::TileTexture:
699 aTexture->SetPosition((int)VTKViewer_Texture::Tiled);
701 case Qtx::StretchTexture:
702 aTexture->SetPosition((int)VTKViewer_Texture::Stretched);
704 case Qtx::CenterTexture:
705 aTexture->SetPosition((int)VTKViewer_Texture::Centered);
709 // show textured background
710 getRenderer()->SetTexturedBackground( true );
711 getRenderer()->SetBackgroundTexture( aTexture );
713 // clean-up resources
724 myBackground = bgData;
728 \return background data of viewer
730 Qtx::BackgroundData SVTK_ViewWindow::background() const
737 Redirect the request to SVTK_RenderWindowInteractor::GetInteractorStyle
739 vtkInteractorStyle* SVTK_ViewWindow::GetInteractorStyle() const
741 return GetInteractor()->GetInteractorStyle();
745 Redirect the request to SVTK_RenderWindowInteractor::PushInteractorStyle
747 void SVTK_ViewWindow::PushInteractorStyle(vtkInteractorStyle* theStyle)
749 GetInteractor()->PushInteractorStyle(theStyle);
753 Redirect the request to SVTK_RenderWindowInteractor::PopInteractorStyle
755 void SVTK_ViewWindow::PopInteractorStyle()
757 GetInteractor()->PopInteractorStyle();
761 Updates current viewer
763 void SVTK_ViewWindow::Repaint(bool theUpdateTrihedron)
765 if(theUpdateTrihedron)
766 GetRenderer()->OnAdjustTrihedron();
768 GetInteractor()->update();
770 SVTK_InteractorStyle* aStyle = (SVTK_InteractorStyle*)getInteractor()->GetInteractorStyle();
776 Redirect the request to #SVTK_Renderer::GetScale
778 void SVTK_ViewWindow::GetScale( double theScale[3] )
780 GetRenderer()->GetScale( theScale );
784 Redirect the request to #SVTK_Renderer::SetScale
786 void SVTK_ViewWindow::SetScale( double theScale[3] )
788 GetRenderer()->SetScale( theScale );
790 emit transformed( this );
794 Redirect the request to #SVTK_Renderer::IsTrihedronDisplayed
796 bool SVTK_ViewWindow::isTrihedronDisplayed()
798 return GetRenderer()->IsTrihedronDisplayed();
802 Redirect the request to #SVTK_Renderer::IsCubeAxesDisplayed
804 bool SVTK_ViewWindow::isCubeAxesDisplayed()
806 return GetRenderer()->IsCubeAxesDisplayed();
810 Redirect the request to #SVTK_Renderer::OnViewTrihedron
812 void SVTK_ViewWindow::onViewTrihedron(bool show)
814 GetRenderer()->SetTrihedronVisibility(show);
819 Redirect the request to #SVTK_Renderer::OnViewCubeAxes
821 void SVTK_ViewWindow::onViewCubeAxes()
823 GetRenderer()->OnViewCubeAxes();
828 Redirect the request to #SVTK_Renderer::GetTrihedron
830 VTKViewer_Trihedron* SVTK_ViewWindow::GetTrihedron()
832 return GetRenderer()->GetTrihedron();
836 Redirect the request to #SVTK_Renderer::GetCubeAxes
838 SVTK_CubeAxesActor2D* SVTK_ViewWindow::GetCubeAxes()
840 return GetRenderer()->GetCubeAxes();
844 \return trihedron size
846 double SVTK_ViewWindow::GetTrihedronSize() const
848 return GetRenderer()->GetTrihedronSize();
853 \param theMode - projection mode ( 0 - orthogonal, 1 - perspective )
855 void SVTK_ViewWindow::SetProjectionMode(const int theMode)
857 activateProjectionMode( theMode );
862 Set the gravity center as a focal point
864 void SVTK_ViewWindow::activateSetFocalPointGravity()
866 myEventDispatcher->InvokeEvent(SVTK::SetFocalPointGravity, 0);
870 Set the selected point as a focal point
872 void SVTK_ViewWindow::activateSetFocalPointSelected()
874 myEventDispatcher->InvokeEvent(SVTK::SetFocalPointSelected, 0);
878 Set the point selected by user as a focal point
880 void SVTK_ViewWindow::activateStartFocalPointSelection()
882 myEventDispatcher->InvokeEvent(SVTK::StartFocalPointSelection,0);
885 void SVTK_ViewWindow::activateProjectionMode(int theMode)
888 toolMgr()->action( ProjectionModeId )->setChecked( true );
890 toolMgr()->action( ParallelModeId )->setChecked( true );
894 Sets actual interaction style
895 \param theStyle - type of interaction style ( 0 - standard, 1 - keyboard free )
897 void SVTK_ViewWindow::SetInteractionStyle(const int theStyle)
899 onSwitchInteractionStyle( theStyle==1 );
903 Sets actual zooming style
904 \param theStyle - type of zooming style ( 0 - standard, 1 - advanced (at cursor) )
906 void SVTK_ViewWindow::SetZoomingStyle(const int theStyle)
908 onSwitchZoomingStyle( theStyle==1 );
912 Set preselection mode.
913 \param theMode the mode to set (standard, dynamic or disabled)
915 void SVTK_ViewWindow::SetPreSelectionMode( Preselection_Mode theMode )
917 onSwitchPreSelectionMode( theMode );
921 Enables/disables selection.
922 \param theEnable if true - selection will be enabled
924 void SVTK_ViewWindow::SetSelectionEnabled( bool theEnable )
926 GetSelector()->SetSelectionEnabled( theEnable );
927 QtxAction* a = getAction( EnableSelectionId );
928 if ( a->isChecked() != theEnable)
929 a->setChecked( theEnable );
930 QtxActionGroup* aPreselectionGroup =
931 dynamic_cast<QtxActionGroup*>( getAction( PreselectionId ) );
932 if ( aPreselectionGroup )
933 aPreselectionGroup->setEnabled( theEnable );
937 Switches "keyboard free" interaction style on/off
939 void SVTK_ViewWindow::onSwitchInteractionStyle(bool theOn)
942 // check if style is already set
943 if ( GetInteractorStyle() != myKeyFreeInteractorStyle.GetPointer() )
945 // keep the same style extensions
946 SVTK_InteractorStyle* aStyle = (SVTK_InteractorStyle*)GetInteractorStyle();
948 myKeyFreeInteractorStyle->SetControllerIncrement(aStyle->ControllerIncrement());
949 myKeyFreeInteractorStyle->SetControllerOnKeyDown(aStyle->ControllerOnKeyDown());
952 PushInteractorStyle(myKeyFreeInteractorStyle.GetPointer());
956 // pop only key free style
957 if ( GetInteractorStyle() == myKeyFreeInteractorStyle.GetPointer() )
958 PopInteractorStyle();
961 // update action state if method is called outside
962 QtxAction* a = getAction( SwitchInteractionStyleId );
963 if ( a->isChecked() != theOn ) a->setChecked( theOn );
967 Toogles advanced zooming style (relatively to the cursor position) on/off
969 void SVTK_ViewWindow::onSwitchZoomingStyle( bool theOn )
971 if( myDefaultInteractorStyle.GetPointer() )
972 myDefaultInteractorStyle->SetAdvancedZoomingEnabled( theOn );
973 if( myKeyFreeInteractorStyle.GetPointer() )
974 myKeyFreeInteractorStyle->SetAdvancedZoomingEnabled( theOn );
976 // update action state if method is called outside
977 QtxAction* a = getAction( SwitchZoomingStyleId );
978 if ( a->isChecked() != theOn )
979 a->setChecked( theOn );
983 Switch preselection mode.
984 \param theMode the preselection mode
986 void SVTK_ViewWindow::onSwitchPreSelectionMode( int theMode )
988 GetSelector()->SetDynamicPreSelection( theMode == Dynamic_Preselection );
989 GetSelector()->SetPreSelectionEnabled( theMode != Preselection_Disabled );
991 // update action state if method is called outside
992 QtxAction* a = getAction( StandardPreselectionId + theMode );
993 if ( a && !a->isChecked() )
994 a->setChecked( true );
998 Enables/disables selection.
999 \param theOn if true - selection will be enabled
1001 void SVTK_ViewWindow::onEnableSelection( bool on )
1003 SVTK_Viewer* aViewer = dynamic_cast<SVTK_Viewer*>(myModel);
1005 aViewer->enableSelection(on);
1009 Sets incremental speed
1010 \param theValue - new incremental speed
1011 \param theMode - modification mode
1013 void SVTK_ViewWindow::SetIncrementalSpeed(const int theValue, const int theMode)
1015 if ( (SVTK_InteractorStyle*)GetInteractorStyle() )
1016 ((SVTK_InteractorStyle*)GetInteractorStyle())->SetIncrementSpeed(theValue, theMode);
1020 Sets spacemouse buttons for the functions
1021 \param theBtn1 - spacemouse button for the "decrease speed increment"
1022 \param theBtn2 - spacemouse button for the "increase speed increment"
1023 \param theBtn3 - spacemouse button for the "dominant combined switch"
1025 void SVTK_ViewWindow::SetSpacemouseButtons(const int theBtn1,
1030 myEventDispatcher->InvokeEvent(SVTK::SetSMDecreaseSpeedEvent, &val);
1032 myEventDispatcher->InvokeEvent(SVTK::SetSMIncreaseSpeedEvent, &val);
1034 myEventDispatcher->InvokeEvent(SVTK::SetSMDominantCombinedSwitchEvent, &val);
1039 \param theSize - new trihedron size
1040 \param theRelative - trihedron relativeness
1042 void SVTK_ViewWindow::SetTrihedronSize(const double theSize, const bool theRelative)
1044 GetRenderer()->SetTrihedronSize(theSize, theRelative);
1048 /*! If parameter theIsForcedUpdate is true, recalculate parameters for
1049 * trihedron and cube axes, even if trihedron and cube axes is invisible.
1051 void SVTK_ViewWindow::AdjustTrihedrons(const bool theIsForcedUpdate)
1053 GetRenderer()->AdjustActors();
1058 Redirect the request to #SVTK_Renderer::OnAdjustTrihedron
1060 void SVTK_ViewWindow::onAdjustTrihedron()
1062 GetRenderer()->OnAdjustTrihedron();
1066 Redirect the request to #SVTK_Renderer::OnAdjustCubeAxes
1068 void SVTK_ViewWindow::onAdjustCubeAxes()
1070 GetRenderer()->OnAdjustCubeAxes();
1073 void SVTK_ViewWindow::synchronize(SVTK_ViewWindow* otherViewWindow )
1075 if ( otherViewWindow ) {
1076 bool blocked = blockSignals( true );
1077 doSetVisualParameters( otherViewWindow->getVisualParameters(), true );
1078 blockSignals( blocked );
1085 void SVTK_ViewWindow::onKeyPressed(QKeyEvent* event)
1087 emit keyPressed( this, event );
1093 void SVTK_ViewWindow::onKeyReleased(QKeyEvent* event)
1095 emit keyReleased( this, event );
1101 void SVTK_ViewWindow::onMousePressed(QMouseEvent* event)
1103 emit mousePressed(this, event);
1107 Emits mouse released
1109 void SVTK_ViewWindow::onMouseReleased(QMouseEvent* event)
1111 emit mouseReleased( this, event );
1117 void SVTK_ViewWindow::onMouseMoving(QMouseEvent* event)
1119 emit mouseMoving( this, event );
1123 Emits mouse double clicked
1125 void SVTK_ViewWindow::onMouseDoubleClicked( QMouseEvent* event )
1127 emit mouseDoubleClicked( this, event );
1131 Redirect the request to #SVTK_Renderer::AddActor
1133 void SVTK_ViewWindow::AddActor( VTKViewer_Actor* theActor,
1135 bool theIsAdjustActors )
1137 GetRenderer()->AddActor(theActor, theIsAdjustActors);
1140 emit actorAdded(theActor);
1144 Redirect the request to #SVTK_Renderer::RemoveActor
1146 void SVTK_ViewWindow::RemoveActor( VTKViewer_Actor* theActor,
1148 bool theIsAdjustActors )
1150 GetRenderer()->RemoveActor(theActor, theIsAdjustActors);
1151 if ( myDefaultInteractorStyle )
1152 myDefaultInteractorStyle->FreeActors();
1153 if ( myKeyFreeInteractorStyle )
1154 myKeyFreeInteractorStyle->FreeActors();
1157 emit actorRemoved(theActor);
1160 QImage SVTK_ViewWindow::dumpViewContent()
1162 vtkRenderWindow* aWindow = getRenderWindow();
1163 int* aSize = aWindow->GetSize();
1164 int aWidth = aSize[0];
1165 int aHeight = aSize[1];
1167 #ifndef DISABLE_GLVIEWER
1168 OpenGLUtils_FrameBuffer aFrameBuffer;
1169 if( aFrameBuffer.init( aWidth, aHeight ) )
1171 glPushAttrib( GL_VIEWPORT_BIT );
1172 glViewport( 0, 0, aWidth, aHeight );
1173 aFrameBuffer.bind();
1178 aFrameBuffer.unbind();
1181 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
1183 aFrameBuffer.bind();
1184 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
1185 aFrameBuffer.unbind();
1187 anImage = anImage.rgbSwapped();
1188 anImage = anImage.mirrored();
1193 // if frame buffers are unsupported, use old functionality
1194 unsigned char *aData =
1195 aWindow->GetRGBACharPixelData( 0, 0, aWidth-1, aHeight-1, 0 );
1197 QImage anImage( aData, aWidth, aHeight, QImage::Format_ARGB32 );
1199 anImage = anImage.rgbSwapped();
1200 anImage = anImage.mirrored();
1205 \return QImage, containing all scene rendering in window
1207 QImage SVTK_ViewWindow::dumpView()
1209 if( myDumpImage.isNull() )
1210 return dumpViewContent();
1216 QString SVTK_ViewWindow::filter() const
1218 return tr( "SVTK_IMAGE_FILES" );
1221 bool SVTK_ViewWindow::dumpViewToFormat( const QImage& img, const QString& fileName, const QString& format )
1223 if ( format != "PS" && format != "EPS" && format != "PDF" )
1224 return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
1226 SUIT_OverrideCursor wc;
1228 vtkGL2PSExporter *anExporter = vtkGL2PSExporter::New();
1229 anExporter->SetRenderWindow(getRenderWindow());
1231 if ( format == "PS" ) {
1232 anExporter->SetFileFormatToPS();
1233 anExporter->CompressOff();
1236 if ( format == "EPS" ) {
1237 anExporter->SetFileFormatToEPS();
1238 anExporter->CompressOff();
1241 if ( format == "PDF" ) {
1242 anExporter->SetFileFormatToPDF();
1245 QString aFilePrefix(fileName);
1246 QString anExtension(SUIT_Tools::extension(fileName));
1247 aFilePrefix.truncate(aFilePrefix.length() - 1 - anExtension.length());
1248 anExporter->SetFilePrefix(aFilePrefix.toLatin1().data());
1249 anExporter->Write();
1250 anExporter->Delete();
1256 \refresh QImage, containing all scene rendering in window
1258 void SVTK_ViewWindow::RefreshDumpImage()
1260 myDumpImage = dumpViewContent();
1264 Redirect the request to #SVTK_Renderer::SetSelectionProp
1266 void SVTK_ViewWindow::SetSelectionProp(const double& theRed,
1267 const double& theGreen,
1268 const double& theBlue,
1269 const int& theWidth)
1271 myView->SetSelectionProp(theRed,theGreen,theBlue,theWidth);
1275 Redirect the request to #SVTK_Renderer::SetSelectionProp
1277 void SVTK_ViewWindow::SetPreselectionProp(const double& theRed,
1278 const double& theGreen,
1279 const double& theBlue,
1280 const int& theWidth)
1282 myView->SetPreselectionProp(theRed,theGreen,theBlue,theWidth);
1286 Redirect the request to #SVTK_Renderer::SetSelectionTolerance
1288 void SVTK_ViewWindow::SetSelectionTolerance(const double& theTolNodes,
1289 const double& theTolItems,
1290 const double& theTolObjects)
1292 myView->SetSelectionTolerance(theTolNodes, theTolItems, theTolObjects);
1296 Get visibility status of the static trihedron
1298 bool SVTK_ViewWindow::IsStaticTrihedronVisible() const
1300 return (bool)myAxesWidget->GetEnabled();
1304 Set visibility status of the static trihedron
1306 void SVTK_ViewWindow::SetStaticTrihedronVisible( const bool theIsVisible )
1308 myAxesWidget->SetEnabled( (int)theIsVisible );
1313 \param accelAction - action
1315 bool SVTK_ViewWindow::action( const int accelAction )
1317 if ( accelAction == SUIT_Accel::ZoomFit )
1320 int anEvent = SVTK::convertAction( accelAction );
1321 GetInteractor()->InvokeEvent(anEvent, 0);
1327 \return action by it's id
1329 QtxAction* SVTK_ViewWindow::getAction( int id ) const
1331 return dynamic_cast<QtxAction*>( toolMgr()->action( id ) );
1335 // old visual parameters had 13 values. New format added additional
1336 // 76 values for graduated axes, so both numbers are processed.
1337 const int nNormalParams = 13; // number of view windows parameters excluding graduated axes params
1338 const int nGradAxisParams = 25; // number of parameters of ONE graduated axis (X, Y, or Z)
1339 const int nTrihedronParams = 3; // number of parameters for Trihedron
1340 const int nAllParams = nNormalParams + 3*nGradAxisParams + nTrihedronParams + 1; // number of all visual parameters
1342 /*! The method returns visual parameters of a graduated axis actor (x,y,z axis of graduated axes)
1344 void getGradAxisVisualParams( QXmlStreamWriter& writer, vtkAxisActor2D* actor, QString theAxis )
1351 bool isVisible = actor->GetTitleVisibility();
1352 QString title ( actor->GetTitle() );
1354 int font = VTK_ARIAL;
1359 vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1362 txtProp->GetColor( color );
1363 font = txtProp->GetFontFamily();
1364 bold = txtProp->GetBold();
1365 italic = txtProp->GetItalic();
1366 shadow = txtProp->GetShadow();
1368 writer.writeStartElement("GraduatedAxis");
1369 writer.writeAttribute("Axis", theAxis);
1371 writer.writeStartElement("Title");
1372 writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1373 writer.writeAttribute("Text", title);
1374 writer.writeAttribute("Font", QString("%1").arg(font));
1375 writer.writeAttribute("Bold", QString("%1").arg(bold));
1376 writer.writeAttribute("Italic", QString("%1").arg(italic));
1377 writer.writeAttribute("Shadow", QString("%1").arg(shadow));
1379 writer.writeStartElement("Color");
1380 writer.writeAttribute("R", QString("%1").arg(color[0]));
1381 writer.writeAttribute("G", QString("%1").arg(color[1]));
1382 writer.writeAttribute("B", QString("%1").arg(color[2]));
1383 writer.writeEndElement();
1384 writer.writeEndElement();
1386 //params.sprintf( "* Graduated Axis: * Name *%u*%s*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible,
1387 // title.toLatin1().data(), color[0], color[1], color[2], font, bold, italic, shadow );
1390 isVisible = actor->GetLabelVisibility();
1391 int labels = actor->GetNumberOfLabels();
1392 int offset = actor->GetTickOffset();
1398 txtProp = actor->GetLabelTextProperty();
1401 txtProp->GetColor( color );
1402 font = txtProp->GetFontFamily();
1403 bold = txtProp->GetBold();
1404 italic = txtProp->GetItalic();
1405 shadow = txtProp->GetShadow();
1408 writer.writeStartElement("Labels");
1409 writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1410 writer.writeAttribute("Number", QString("%1").arg(labels));
1411 writer.writeAttribute("Offset", QString("%1").arg(offset));
1412 writer.writeAttribute("Font", QString("%1").arg(font));
1413 writer.writeAttribute("Bold", QString("%1").arg(bold));
1414 writer.writeAttribute("Italic", QString("%1").arg(italic));
1415 writer.writeAttribute("Shadow", QString("%1").arg(shadow));
1417 writer.writeStartElement("Color");
1418 writer.writeAttribute("R", QString("%1").arg(color[0]));
1419 writer.writeAttribute("G", QString("%1").arg(color[1]));
1420 writer.writeAttribute("B", QString("%1").arg(color[2]));
1421 writer.writeEndElement();
1422 writer.writeEndElement();
1423 // params += QString().sprintf( "* Labels *%u*%u*%u*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible, labels, offset,
1424 // color[0], color[1], color[2], font, bold, italic, shadow );
1427 isVisible = actor->GetTickVisibility();
1428 int length = actor->GetTickLength();
1429 writer.writeStartElement("TickMarks");
1430 writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1431 writer.writeAttribute("Length", QString("%1").arg(length));
1432 writer.writeEndElement();
1434 //params += QString().sprintf( "* Tick marks *%u*%u", isVisible, length );
1436 writer.writeEndElement();
1440 void setGradAxisVisualParams(QXmlStreamReader& reader, vtkAxisActor2D* actor)
1447 } while (!reader.isStartElement());
1449 // Read title params
1450 QXmlStreamAttributes aAttr = reader.attributes();
1451 bool isVisible = aAttr.value("isVisible").toString().toUShort();
1452 QString title = aAttr.value("Text").toString();
1453 int font = aAttr.value("Font").toString().toInt();
1454 int bold = aAttr.value("Bold").toString().toInt();
1455 int italic = aAttr.value("Italic").toString().toInt();
1456 int shadow = aAttr.value("Shadow").toString().toInt();
1458 //printf("#### TITLE: %i, %s, %i, %i, %i, %i\n", isVisible, qPrintable(title), font, bold, italic, shadow);
1462 } while (!reader.isStartElement());
1465 aAttr = reader.attributes();
1468 color[0] = aAttr.value("R").toString().toDouble();
1469 color[1] = aAttr.value("G").toString().toDouble();
1470 color[2] = aAttr.value("B").toString().toDouble();
1471 //printf("#### Color: %f, %f, %f\n", color[0], color[1], color[2]);
1473 actor->SetTitleVisibility( isVisible );
1474 actor->SetTitle( title.toLatin1() );
1475 vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1477 txtProp->SetColor( color );
1478 txtProp->SetFontFamily( font );
1479 txtProp->SetBold( bold );
1480 txtProp->SetItalic( italic );
1481 txtProp->SetShadow( shadow );
1488 } while (!reader.isStartElement());
1490 aAttr = reader.attributes();
1491 isVisible = aAttr.value("isVisible").toString().toUShort();
1492 int labels = aAttr.value("Number").toString().toInt();
1493 int offset = aAttr.value("Offset").toString().toInt();
1494 font = aAttr.value("Font").toString().toInt();
1495 bold = aAttr.value("Bold").toString().toInt();
1496 italic = aAttr.value("Italic").toString().toInt();
1497 shadow = aAttr.value("Shadow").toString().toInt();
1501 } while (!reader.isStartElement());
1503 aAttr = reader.attributes();
1505 color[0] = aAttr.value("R").toString().toDouble();
1506 color[1] = aAttr.value("G").toString().toDouble();
1507 color[2] = aAttr.value("B").toString().toDouble();
1509 actor->SetLabelVisibility( isVisible );
1510 actor->SetNumberOfLabels( labels );
1511 actor->SetTickOffset( offset );
1512 txtProp = actor->GetLabelTextProperty();
1514 txtProp->SetColor( color );
1515 txtProp->SetFontFamily( font );
1516 txtProp->SetBold( bold );
1517 txtProp->SetItalic( italic );
1518 txtProp->SetShadow( shadow );
1524 } while (!reader.isStartElement());
1525 aAttr = reader.attributes();
1527 // retrieve and set tick marks properties
1528 isVisible = aAttr.value("isVisible").toString().toUShort();
1529 int length = aAttr.value("Length").toString().toInt();
1531 actor->SetTickVisibility( isVisible );
1532 actor->SetTickLength( length );
1535 /*! The method restores visual parameters of a graduated axis actor (x,y,z axis)
1537 void setGradAxisVisualParams( vtkAxisActor2D* actor, const QString& params )
1542 QStringList paramsLst = params.split( '*' );
1544 if ( paramsLst.size() == nGradAxisParams ) { // altogether name, lable, ticks parameters make up 25 values
1546 // retrieve and set name parameters
1547 bool isVisible = paramsLst[2].toUShort();
1548 QString title = paramsLst[3];
1550 color[0] = paramsLst[4].toDouble();
1551 color[1] = paramsLst[5].toDouble();
1552 color[2] = paramsLst[6].toDouble();
1553 int font = paramsLst[7].toInt();
1554 int bold = paramsLst[8].toInt();
1555 int italic = paramsLst[9].toInt();
1556 int shadow = paramsLst[10].toInt();
1558 actor->SetTitleVisibility( isVisible );
1559 actor->SetTitle( title.toLatin1() );
1560 vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1562 txtProp->SetColor( color );
1563 txtProp->SetFontFamily( font );
1564 txtProp->SetBold( bold );
1565 txtProp->SetItalic( italic );
1566 txtProp->SetShadow( shadow );
1569 // retrieve and set lable parameters
1570 isVisible = paramsLst[12].toUShort();
1571 int labels = paramsLst[13].toInt();
1572 int offset = paramsLst[14].toInt();
1573 color[0] = paramsLst[15].toDouble();
1574 color[1] = paramsLst[16].toDouble();
1575 color[2] = paramsLst[17].toDouble();
1576 font = paramsLst[18].toInt();
1577 bold = paramsLst[19].toInt();
1578 italic = paramsLst[20].toInt();
1579 shadow = paramsLst[21].toInt();
1581 actor->SetLabelVisibility( isVisible );
1582 actor->SetNumberOfLabels( labels );
1583 actor->SetTickOffset( offset );
1584 txtProp = actor->GetLabelTextProperty();
1586 txtProp->SetColor( color );
1587 txtProp->SetFontFamily( font );
1588 txtProp->SetBold( bold );
1589 txtProp->SetItalic( italic );
1590 txtProp->SetShadow( shadow );
1593 // retrieve and set tick marks properties
1594 isVisible = paramsLst[23].toUShort();
1595 int length = paramsLst[24].toInt();
1597 actor->SetTickVisibility( isVisible );
1598 actor->SetTickLength( length );
1602 /*! The method returns the visual parameters of this view as a formated string
1604 QString SVTK_ViewWindow::getVisualParameters()
1606 double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
1608 // save position, focal point, viewUp, scale
1609 vtkCamera* camera = getRenderer()->GetActiveCamera();
1610 camera->GetPosition( pos );
1611 camera->GetFocalPoint( focalPnt );
1612 camera->GetViewUp( viewUp );
1613 parScale = camera->GetParallelScale();
1616 // Parameters are given in the following format:view position (3 digits), focal point position (3 digits)
1617 // view up values (3 digits), parallel scale (1 digit), scale (3 digits,
1618 // Graduated axes parameters (X, Y, Z axes parameters)
1620 QXmlStreamWriter aWriter(&retStr);
1621 aWriter.setAutoFormatting(true);
1623 aWriter.writeStartDocument();
1624 aWriter.writeStartElement("ViewState");
1626 aWriter.writeStartElement("Position");
1627 aWriter.writeAttribute("X", QString("%1").arg(pos[0]));
1628 aWriter.writeAttribute("Y", QString("%1").arg(pos[1]));
1629 aWriter.writeAttribute("Z", QString("%1").arg(pos[2]));
1630 aWriter.writeEndElement();
1632 aWriter.writeStartElement("FocalPoint");
1633 aWriter.writeAttribute("X", QString::number(focalPnt[0]));
1634 aWriter.writeAttribute("Y", QString::number(focalPnt[1]));
1635 aWriter.writeAttribute("Z", QString::number(focalPnt[2]));
1636 aWriter.writeEndElement();
1638 aWriter.writeStartElement("ViewUp");
1639 aWriter.writeAttribute("X", QString::number(viewUp[0]));
1640 aWriter.writeAttribute("Y", QString::number(viewUp[1]));
1641 aWriter.writeAttribute("Z", QString::number(viewUp[2]));
1642 aWriter.writeEndElement();
1644 aWriter.writeStartElement("ViewScale");
1645 aWriter.writeAttribute("Parallel", QString::number(parScale));
1646 aWriter.writeAttribute("X", QString::number(scale[0]));
1647 aWriter.writeAttribute("Y", QString::number(scale[1]));
1648 aWriter.writeAttribute("Z", QString::number(scale[2]));
1649 aWriter.writeEndElement();
1651 if ( SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes() ) {
1652 aWriter.writeStartElement("DisplayCubeAxis");
1653 aWriter.writeAttribute("Show", QString( "%1" ).arg( GetRenderer()->IsCubeAxesDisplayed()));
1654 aWriter.writeEndElement();
1656 getGradAxisVisualParams(aWriter, gradAxesActor->GetXAxisActor2D(), "X");
1657 getGradAxisVisualParams(aWriter, gradAxesActor->GetYAxisActor2D(), "Y");
1658 getGradAxisVisualParams(aWriter, gradAxesActor->GetZAxisActor2D(), "Z");
1661 aWriter.writeStartElement("Trihedron");
1662 aWriter.writeAttribute("isShown", QString( "%1" ).arg( isTrihedronDisplayed()));
1663 aWriter.writeAttribute("Size", QString::number(GetTrihedronSize()));
1664 aWriter.writeEndElement();
1666 aWriter.writeStartElement("Background");
1667 aWriter.writeAttribute("Value", QString( "%1" ).arg( Qtx::backgroundToString(background()) ));
1668 aWriter.writeEndElement();
1670 aWriter.writeEndElement();
1671 aWriter.writeEndDocument();
1677 The method restores visual parameters of this view or postpones it untill the view is shown
1679 void SVTK_ViewWindow::setVisualParameters( const QString& parameters )
1681 //printf("#### %s\n", qPrintable(parameters));
1682 SVTK_RenderWindowInteractor* anInteractor = GetInteractor();
1683 if ( anInteractor->isVisible() ) {
1684 doSetVisualParameters( parameters );
1687 myVisualParams = parameters;
1688 anInteractor->installEventFilter(this);
1693 The method restores visual parameters of this view from a formated string
1695 void SVTK_ViewWindow::doSetVisualParameters( const QString& parameters, bool baseParamsOnly )
1698 double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
1700 QXmlStreamReader aReader(parameters);
1701 SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes();
1703 while(!aReader.atEnd()) {
1705 if (aReader.isStartElement()) {
1706 QXmlStreamAttributes aAttr = aReader.attributes();
1707 //printf("### Name = %s\n", qPrintable(aReader.name().toString()));
1708 if (aReader.name() == "Position") {
1709 pos[0] = aAttr.value("X").toString().toDouble();
1710 pos[1] = aAttr.value("Y").toString().toDouble();
1711 pos[2] = aAttr.value("Z").toString().toDouble();
1712 //printf("#### Position %f; %f; %f\n", pos[0], pos[1], pos[2]);
1714 else if (aReader.name() == "FocalPoint") {
1715 focalPnt[0] = aAttr.value("X").toString().toDouble();
1716 focalPnt[1] = aAttr.value("Y").toString().toDouble();
1717 focalPnt[2] = aAttr.value("Z").toString().toDouble();
1718 //printf("#### FocalPoint %f; %f; %f\n", focalPnt[0], focalPnt[1], focalPnt[2]);
1720 else if (aReader.name() == "ViewUp") {
1721 viewUp[0] = aAttr.value("X").toString().toDouble();
1722 viewUp[1] = aAttr.value("Y").toString().toDouble();
1723 viewUp[2] = aAttr.value("Z").toString().toDouble();
1724 //printf("#### ViewUp %f; %f; %f\n", viewUp[0], viewUp[1], viewUp[2]);
1726 else if (aReader.name() == "ViewScale") {
1727 parScale = aAttr.value("Parallel").toString().toDouble();
1728 scale[0] = aAttr.value("X").toString().toDouble();
1729 scale[1] = aAttr.value("Y").toString().toDouble();
1730 scale[2] = aAttr.value("Z").toString().toDouble();
1731 //printf("#### ViewScale %f; %f; %f\n", scale[0], scale[1], scale[2]);
1733 else if (aReader.name() == "DisplayCubeAxis") {
1734 if ( !baseParamsOnly ) {
1735 if (aAttr.value("Show") == "0")
1736 gradAxesActor->VisibilityOff();
1738 gradAxesActor->VisibilityOn();
1741 else if (aReader.name() == "GraduatedAxis") {
1742 if ( !baseParamsOnly ) {
1743 if(aAttr.value("Axis") == "X")
1744 setGradAxisVisualParams(aReader, gradAxesActor->GetXAxisActor2D());
1745 else if(aAttr.value("Axis") == "Y")
1746 setGradAxisVisualParams(aReader, gradAxesActor->GetYAxisActor2D());
1747 else if(aAttr.value("Axis") == "Z")
1748 setGradAxisVisualParams(aReader, gradAxesActor->GetZAxisActor2D());
1751 else if (aReader.name() == "Trihedron") {
1752 if ( !baseParamsOnly ) {
1753 if (aAttr.value("isShown") == "0")
1754 GetTrihedron()->VisibilityOff();
1756 GetTrihedron()->VisibilityOn();
1757 SetTrihedronSize(aAttr.value("Size").toString().toDouble());
1760 else if (aReader.name() == "Background") {
1761 if ( !baseParamsOnly ) {
1762 setBackground( Qtx::stringToBackground( aAttr.value("Value").toString() ) );
1767 if (!aReader.hasError()) {
1768 vtkCamera* camera = getRenderer()->GetActiveCamera();
1769 camera->SetPosition( pos );
1770 camera->SetFocalPoint( focalPnt );
1771 camera->SetViewUp( viewUp );
1772 camera->SetParallelScale( parScale );
1773 GetRenderer()->SetScale( scale );
1774 //SetScale( scale );
1777 QStringList paramsLst = parameters.split( '*' );
1778 if ( paramsLst.size() >= nNormalParams ) {
1779 // 'reading' list of parameters
1780 pos[0] = paramsLst[0].toDouble();
1781 pos[1] = paramsLst[1].toDouble();
1782 pos[2] = paramsLst[2].toDouble();
1783 focalPnt[0] = paramsLst[3].toDouble();
1784 focalPnt[1] = paramsLst[4].toDouble();
1785 focalPnt[2] = paramsLst[5].toDouble();
1786 viewUp[0] = paramsLst[6].toDouble();
1787 viewUp[1] = paramsLst[7].toDouble();
1788 viewUp[2] = paramsLst[8].toDouble();
1789 parScale = paramsLst[9].toDouble();
1790 scale[0] = paramsLst[10].toDouble();
1791 scale[1] = paramsLst[11].toDouble();
1792 scale[2] = paramsLst[12].toDouble();
1794 // applying parameters
1795 vtkCamera* camera = getRenderer()->GetActiveCamera();
1796 camera->SetPosition( pos );
1797 camera->SetFocalPoint( focalPnt );
1798 camera->SetViewUp( viewUp );
1799 camera->SetParallelScale( parScale );
1800 GetRenderer()->SetScale( scale );
1801 //SetScale( scale );
1803 // apply graduated axes parameters
1804 if ( !baseParamsOnly ) {
1805 SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes();
1806 if ( gradAxesActor && paramsLst.size() == nAllParams ) {
1807 int i = nNormalParams+1, j = i + nGradAxisParams - 1;
1808 ::setGradAxisVisualParams( gradAxesActor->GetXAxisActor2D(), parameters.section( '*', i, j ) );
1809 i = j + 1; j += nGradAxisParams;
1810 ::setGradAxisVisualParams( gradAxesActor->GetYAxisActor2D(), parameters.section( '*', i, j ) );
1811 i = j + 1; j += nGradAxisParams;
1812 ::setGradAxisVisualParams( gradAxesActor->GetZAxisActor2D(), parameters.section( '*', i, j ) );
1814 if ( paramsLst[13].toUShort() )
1815 gradAxesActor->VisibilityOn();
1817 gradAxesActor->VisibilityOff();
1819 else if ( paramsLst.size() == nAllParams ) {
1820 if ( paramsLst[90].toUShort() )
1821 GetTrihedron()->VisibilityOn();
1823 GetTrihedron()->VisibilityOff();
1825 SetTrihedronSize(paramsLst[91].toDouble());
1835 Delayed setVisualParameters
1837 bool SVTK_ViewWindow::eventFilter( QObject* theWatched, QEvent* theEvent )
1839 if ( theEvent->type() == QEvent::Show && theWatched->inherits( "SVTK_RenderWindowInteractor" ) ) {
1840 SVTK_RenderWindowInteractor* anInteractor = (SVTK_RenderWindowInteractor*)theWatched;
1841 if ( anInteractor->isVisible() ) {
1842 doSetVisualParameters( myVisualParams );
1843 anInteractor->removeEventFilter( this ); // theWatched = RenderWindowInteractor
1846 return SUIT_ViewWindow::eventFilter( theWatched, theEvent );
1851 Change rotation point
1853 void SVTK_ViewWindow::onChangeRotationPoint(bool theIsActivate)
1856 mySetRotationPointDlg->addObserver();
1857 if ( mySetRotationPointDlg->IsFirstShown() )
1858 activateSetRotationGravity();
1859 mySetRotationPointDlg->show();
1861 mySetRotationPointDlg->hide();
1865 Set the gravity center as a rotation point
1867 void SVTK_ViewWindow::activateSetRotationGravity()
1869 myEventDispatcher->InvokeEvent(SVTK::SetRotateGravity,0);
1873 Set the selected point as a rotation point
1875 void SVTK_ViewWindow::activateSetRotationSelected(void* theData)
1877 myEventDispatcher->InvokeEvent(SVTK::ChangeRotationPoint,theData);
1881 Set the gravity center of element selected by user as a rotation point
1883 void SVTK_ViewWindow::activateStartPointSelection( Selection_Mode theSelectionMode )
1885 SetSelectionMode( theSelectionMode );
1886 myEventDispatcher->InvokeEvent(SVTK::StartPointSelection,0);
1890 Set the view projection mode: orthogonal or perspective
1892 void SVTK_ViewWindow::onPerspectiveMode()
1894 bool anIsParallelMode = toolMgr()->action( ParallelModeId )->isChecked();
1896 // advanced zooming is not available in perspective mode
1897 if( QtxAction* anAction = getAction( SwitchZoomingStyleId ) )
1898 anAction->setEnabled( anIsParallelMode );
1900 vtkCamera* aCamera = getRenderer()->GetActiveCamera();
1901 aCamera->SetParallelProjection(anIsParallelMode);
1902 GetInteractor()->GetDevice()->CreateTimer(VTKI_TIMER_FIRST);
1904 emit transformed( this );
1907 void SVTK_ViewWindow::SetEventDispatcher(vtkObject* theDispatcher)
1909 myEventDispatcher = theDispatcher;
1913 Creates all actions of svtk main window
1915 void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
1917 QtxAction* anAction;
1918 QtxActionToolMgr* mgr = toolMgr();
1921 anAction = new QtxAction(tr("MNU_DUMP_VIEW"),
1922 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
1923 tr( "MNU_DUMP_VIEW" ), 0, this);
1924 anAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1925 connect(anAction, SIGNAL(activated()), this, SLOT(onDumpView()));
1926 mgr->registerAction( anAction, DumpId );
1929 anAction = new QtxAction(tr("MNU_FITALL"),
1930 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
1931 tr( "MNU_FITALL" ), 0, this);
1932 anAction->setStatusTip(tr("DSC_FITALL"));
1933 connect(anAction, SIGNAL(activated()), this, SLOT(onFitAll()));
1934 mgr->registerAction( anAction, FitAllId );
1937 anAction = new QtxAction(tr("MNU_FITRECT"),
1938 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
1939 tr( "MNU_FITRECT" ), 0, this);
1940 anAction->setStatusTip(tr("DSC_FITRECT"));
1941 connect(anAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
1942 mgr->registerAction( anAction, FitRectId );
1945 anAction = new QtxAction(tr("MNU_FITSELECTION"),
1946 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITSELECTION" ) ),
1947 tr( "MNU_FITSELECTION" ), 0, this);
1948 anAction->setStatusTip(tr("DSC_FITSELECTION"));
1949 connect(anAction, SIGNAL(activated()), this, SLOT(onFitSelection()));
1950 mgr->registerAction( anAction, FitSelectionId );
1953 anAction = new QtxAction(tr("MNU_ZOOM_VIEW"),
1954 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
1955 tr( "MNU_ZOOM_VIEW" ), 0, this);
1956 anAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1957 connect(anAction, SIGNAL(activated()), this, SLOT(activateZoom()));
1958 mgr->registerAction( anAction, ZoomId );
1961 anAction = new QtxAction(tr("MNU_PAN_VIEW"),
1962 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
1963 tr( "MNU_PAN_VIEW" ), 0, this);
1964 anAction->setStatusTip(tr("DSC_PAN_VIEW"));
1965 connect(anAction, SIGNAL(activated()), this, SLOT(activatePanning()));
1966 mgr->registerAction( anAction, PanId );
1969 anAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"),
1970 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
1971 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1972 anAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1973 connect(anAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
1974 mgr->registerAction( anAction, GlobalPanId );
1976 // Change rotation point
1977 anAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"),
1978 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_ROTATION_POINT" ) ),
1979 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1980 anAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1981 anAction->setCheckable(true);
1982 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onChangeRotationPoint(bool)));
1983 mgr->registerAction( anAction, ChangeRotationPointId );
1986 anAction = new QtxAction(tr("MNU_ROTATE_VIEW"),
1987 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
1988 tr( "MNU_ROTATE_VIEW" ), 0, this);
1989 anAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1990 connect(anAction, SIGNAL(activated()), this, SLOT(activateRotation()));
1991 mgr->registerAction( anAction, RotationId );
1994 anAction = new QtxAction(tr("MNU_FRONT_VIEW"),
1995 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
1996 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1997 anAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1998 connect(anAction, SIGNAL(activated()), this, SLOT(onFrontView()));
1999 this->addAction(anAction);
2000 mgr->registerAction( anAction, FrontId );
2002 anAction = new QtxAction(tr("MNU_BACK_VIEW"),
2003 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
2004 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
2005 anAction->setStatusTip(tr("DSC_BACK_VIEW"));
2006 connect(anAction, SIGNAL(activated()), this, SLOT(onBackView()));
2007 this->addAction(anAction);
2008 mgr->registerAction( anAction, BackId );
2010 anAction = new QtxAction(tr("MNU_TOP_VIEW"),
2011 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
2012 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
2013 anAction->setStatusTip(tr("DSC_TOP_VIEW"));
2014 connect(anAction, SIGNAL(activated()), this, SLOT(onTopView()));
2015 this->addAction(anAction);
2016 mgr->registerAction( anAction, TopId );
2018 anAction = new QtxAction(tr("MNU_BOTTOM_VIEW"),
2019 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
2020 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
2021 anAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
2022 connect(anAction, SIGNAL(activated()), this, SLOT(onBottomView()));
2023 this->addAction(anAction);
2024 mgr->registerAction( anAction, BottomId );
2026 anAction = new QtxAction(tr("MNU_LEFT_VIEW"),
2027 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
2028 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
2029 anAction->setStatusTip(tr("DSC_LEFT_VIEW"));
2030 connect(anAction, SIGNAL(activated()), this, SLOT(onLeftView()));
2031 this->addAction(anAction);
2032 mgr->registerAction( anAction, LeftId );
2034 anAction = new QtxAction(tr("MNU_RIGHT_VIEW"),
2035 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
2036 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
2037 anAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
2038 connect(anAction, SIGNAL(activated()), this, SLOT(onRightView()));
2039 this->addAction(anAction);
2040 mgr->registerAction( anAction, RightId );
2042 // rotate anticlockwise
2043 anAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"),
2044 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ANTICLOCKWISE" ) ),
2045 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
2046 anAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
2047 connect(anAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
2048 this->addAction(anAction);
2049 mgr->registerAction( anAction, AntiClockWiseId );
2052 anAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"),
2053 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_CLOCKWISE" ) ),
2054 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
2055 anAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
2056 connect(anAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
2057 this->addAction(anAction);
2058 mgr->registerAction( anAction, ClockWiseId );
2061 anAction = new QtxAction(tr("MNU_RESET_VIEW"),
2062 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
2063 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
2064 anAction->setStatusTip(tr("DSC_RESET_VIEW"));
2065 connect(anAction, SIGNAL(activated()), this, SLOT(onResetView()));
2066 this->addAction(anAction);
2067 mgr->registerAction( anAction, ResetId );
2069 // onViewTrihedron: Shows - Hides Trihedron
2070 anAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"),
2071 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ),
2072 tr( "MNU_SHOW_TRIHEDRON" ), 0, this);
2073 anAction->setCheckable( true );
2074 anAction->setChecked( true );
2076 anAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON"));
2077 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onViewTrihedron(bool)));
2078 mgr->registerAction( anAction, ViewTrihedronId );
2080 // onNonIsometric: Manage non-isometric params
2081 anAction = new QtxAction(tr("MNU_SVTK_SCALING"),
2082 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SCALING" ) ),
2083 tr( "MNU_SVTK_SCALING" ), 0, this);
2084 anAction->setStatusTip(tr("DSC_SVTK_SCALING"));
2085 anAction->setCheckable(true);
2086 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onNonIsometric(bool)));
2087 mgr->registerAction( anAction, NonIsometric );
2089 // onGraduatedAxes: Manage graduated axes params
2090 anAction = new QtxAction(tr("MNU_SVTK_GRADUATED_AXES"),
2091 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_GRADUATED_AXES" ) ),
2092 tr( "MNU_SVTK_GRADUATED_AXES" ), 0, this);
2093 anAction->setStatusTip(tr("DSC_SVTK_GRADUATED_AXES"));
2094 anAction->setCheckable(true);
2095 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onGraduatedAxes(bool)));
2096 mgr->registerAction( anAction, GraduatedAxes );
2098 // onGraduatedAxes: Manage graduated axes params
2099 anAction = new QtxAction(tr("MNU_SVTK_UPDATE_RATE"),
2100 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_UPDATE_RATE" ) ),
2101 tr( "MNU_SVTK_UPDATE_RATE" ), 0, this);
2102 anAction->setStatusTip(tr("DSC_SVTK_UPDATE_RATE"));
2103 anAction->setCheckable(true);
2104 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onUpdateRate(bool)));
2105 mgr->registerAction( anAction, UpdateRate );
2107 // Set perspective mode group
2108 anAction = new QtxAction(tr("MNU_SVTK_PARALLEL_MODE"),
2109 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARALLEL" ) ),
2110 tr( "MNU_SVTK_PARALLEL_MODE" ), 0, this);
2111 anAction->setStatusTip(tr("DSC_SVTK_PARALLEL_MODE"));
2112 anAction->setCheckable(true);
2113 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onPerspectiveMode()));
2114 mgr->registerAction( anAction, ParallelModeId );
2116 anAction = new QtxAction(tr("MNU_SVTK_PERSPECTIVE_MODE"),
2117 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PERSPECTIVE" ) ),
2118 tr( "MNU_SVTK_PERSPECTIVE_MODE" ), 0, this);
2119 anAction->setStatusTip(tr("DSC_SVTK_PERSPECTIVE_MODE"));
2120 anAction->setCheckable(true);
2121 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onPerspectiveMode()));
2122 mgr->registerAction( anAction, ProjectionModeId );
2124 QActionGroup* aPerspectiveGroup = new QActionGroup( this );
2125 aPerspectiveGroup->addAction( mgr->action( ParallelModeId ) );
2126 aPerspectiveGroup->addAction( mgr->action( ProjectionModeId ) );
2129 anAction = new QtxAction(tr("MNU_VIEWPARAMETERS_VIEW"),
2130 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARAMETERS" ) ),
2131 tr( "MNU_VIEWPARAMETERS_VIEW" ), 0, this);
2132 anAction->setStatusTip(tr("DSC_VIEWPARAMETERS_VIEW"));
2133 anAction->setCheckable(true);
2134 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onViewParameters(bool)));
2135 mgr->registerAction( anAction, ViewParametersId );
2138 mgr->registerAction( synchronizeAction(), SynchronizeId );
2140 // Switch between interaction styles
2141 anAction = new QtxAction(tr("MNU_SVTK_STYLE_SWITCH"),
2142 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_STYLE_SWITCH" ) ),
2143 tr( "MNU_SVTK_STYLE_SWITCH" ), 0, this);
2144 anAction->setStatusTip(tr("DSC_SVTK_STYLE_SWITCH"));
2145 anAction->setCheckable(true);
2146 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
2147 mgr->registerAction( anAction, SwitchInteractionStyleId );
2149 // Switch between zooming styles
2150 anAction = new QtxAction(tr("MNU_SVTK_ZOOMING_STYLE_SWITCH"),
2151 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_ZOOMING_STYLE_SWITCH" ) ),
2152 tr( "MNU_SVTK_ZOOMING_STYLE_SWITCH" ), 0, this);
2153 anAction->setStatusTip(tr("DSC_SVTK_ZOOMING_STYLE_SWITCH"));
2154 anAction->setCheckable(true);
2155 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
2156 mgr->registerAction( anAction, SwitchZoomingStyleId );
2159 QSignalMapper* aSignalMapper = new QSignalMapper( this );
2160 connect(aSignalMapper, SIGNAL(mapped(int)), this, SLOT(onSwitchPreSelectionMode(int)));
2162 anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_STANDARD"),
2163 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_STANDARD" ) ),
2164 tr( "MNU_SVTK_PRESELECTION_STANDARD" ), 0, this);
2165 anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_STANDARD"));
2166 anAction->setCheckable(true);
2167 connect(anAction, SIGNAL(activated()), aSignalMapper, SLOT(map()));
2168 aSignalMapper->setMapping( anAction, Standard_Preselection );
2169 mgr->registerAction( anAction, StandardPreselectionId );
2171 anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_DYNAMIC"),
2172 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_DYNAMIC" ) ),
2173 tr( "MNU_SVTK_PRESELECTION_DYNAMIC" ), 0, this);
2174 anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_DYNAMIC"));
2175 anAction->setCheckable(true);
2176 connect(anAction, SIGNAL(activated()), aSignalMapper, SLOT(map()));
2177 aSignalMapper->setMapping( anAction, Dynamic_Preselection );
2178 mgr->registerAction( anAction, DynamicPreselectionId );
2180 anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_DISABLED"),
2181 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_DISABLED" ) ),
2182 tr( "MNU_SVTK_PRESELECTION_DISABLED" ), 0, this);
2183 anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_DISABLED"));
2184 anAction->setCheckable(true);
2185 connect(anAction, SIGNAL(activated()), aSignalMapper, SLOT(map()));
2186 aSignalMapper->setMapping( anAction, Preselection_Disabled );
2187 mgr->registerAction( anAction, DisablePreselectionId );
2189 QtxActionGroup* aPreselectionAction = new QtxActionGroup( this, true );
2190 aPreselectionAction->add( getAction( StandardPreselectionId ) );
2191 aPreselectionAction->add( getAction( DynamicPreselectionId ) );
2192 aPreselectionAction->add( getAction( DisablePreselectionId ) );
2193 mgr->registerAction( aPreselectionAction, PreselectionId );
2196 anAction = new QtxAction(tr("MNU_SVTK_ENABLE_SELECTION"),
2197 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SELECTION" ) ),
2198 tr( "MNU_SVTK_ENABLE_SELECTION" ), 0, this);
2199 anAction->setStatusTip(tr("DSC_SVTK_ENABLE_SELECTION"));
2200 anAction->setCheckable(true);
2201 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onEnableSelection(bool)));
2202 mgr->registerAction( anAction, EnableSelectionId );
2205 myStartAction = new QtxAction(tr("MNU_SVTK_RECORDING_START"),
2206 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_START" ) ),
2207 tr( "MNU_SVTK_RECORDING_START" ), 0, this);
2208 myStartAction->setStatusTip(tr("DSC_SVTK_RECORDING_START"));
2209 connect( myStartAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStartRecording() ) );
2210 mgr->registerAction( myStartAction, StartRecordingId );
2213 myPlayAction = new QtxAction(tr("MNU_SVTK_RECORDING_PLAY"),
2214 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PLAY" ) ),
2215 tr( "MNU_SVTK_RECORDING_PLAY" ), 0, this);
2216 myPlayAction->setStatusTip(tr("DSC_SVTK_RECORDING_PLAY"));
2217 myPlayAction->setEnabled( false );
2218 connect( myPlayAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPlayRecording() ) );
2219 mgr->registerAction( myPlayAction, PlayRecordingId );
2222 myPauseAction = new QtxAction(tr("MNU_SVTK_RECORDING_PAUSE"),
2223 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PAUSE" ) ),
2224 tr( "MNU_SVTK_RECORDING_PAUSE" ), 0, this);
2225 myPauseAction->setStatusTip(tr("DSC_SVTK_RECORDING_PAUSE"));
2226 myPauseAction->setEnabled( false );
2227 connect( myPauseAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPauseRecording() ) );
2228 mgr->registerAction( myPauseAction, PauseRecordingId );
2231 myStopAction = new QtxAction(tr("MNU_SVTK_RECORDING_STOP"),
2232 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_STOP" ) ),
2233 tr( "MNU_SVTK_RECORDING_STOP" ), 0, this);
2234 myStopAction->setStatusTip(tr("DSC_SVTK_RECORDING_STOP"));
2235 myStopAction->setEnabled( false );
2236 connect( myStopAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStopRecording() ) );
2237 mgr->registerAction( myStopAction, StopRecordingId );
2241 Creates toolbar of svtk main window
2243 void SVTK_ViewWindow::createToolBar()
2245 QtxActionToolMgr* mgr = toolMgr();
2247 mgr->append( DumpId, myToolBar );
2248 mgr->append( SwitchInteractionStyleId, myToolBar );
2249 mgr->append( SwitchZoomingStyleId, myToolBar );
2251 mgr->append( mgr->separator(), myToolBar );
2253 mgr->append( PreselectionId, myToolBar );
2254 mgr->append( EnableSelectionId, myToolBar );
2256 mgr->append( mgr->separator(), myToolBar );
2258 mgr->append( ViewTrihedronId, myToolBar );
2260 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
2261 aScaleAction->insertAction( getAction( FitAllId ) );
2262 aScaleAction->insertAction( getAction( FitRectId ) );
2263 aScaleAction->insertAction( getAction( FitSelectionId ) );
2264 aScaleAction->insertAction( getAction( ZoomId ) );
2265 mgr->append( aScaleAction, myToolBar );
2267 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
2268 aPanningAction->insertAction( getAction( PanId ) );
2269 aPanningAction->insertAction( getAction( GlobalPanId ) );
2270 mgr->append( aPanningAction, myToolBar );
2272 mgr->append( ChangeRotationPointId, myToolBar );
2274 mgr->append( RotationId, myToolBar );
2276 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
2277 aViewsAction->insertAction( getAction( FrontId ) );
2278 aViewsAction->insertAction( getAction( BackId ) );
2279 aViewsAction->insertAction( getAction( TopId ) );
2280 aViewsAction->insertAction( getAction( BottomId ) );
2281 aViewsAction->insertAction( getAction( LeftId ) );
2282 aViewsAction->insertAction( getAction( RightId ) );
2283 mgr->append( aViewsAction, myToolBar );
2285 mgr->append( AntiClockWiseId, myToolBar );
2286 mgr->append( ClockWiseId, myToolBar );
2288 mgr->append( ResetId, myToolBar );
2290 mgr->append( UpdateRate, myToolBar );
2291 mgr->append( NonIsometric, myToolBar );
2292 mgr->append( GraduatedAxes, myToolBar );
2294 mgr->append( ViewParametersId, myToolBar );
2295 mgr->append( SynchronizeId, myToolBar );
2297 mgr->append( toolMgr()->separator(), myToolBar );
2299 mgr->append( ParallelModeId, myToolBar );
2300 mgr->append( ProjectionModeId, myToolBar );
2302 mgr->append( StartRecordingId, myRecordingToolBar );
2303 mgr->append( PlayRecordingId, myRecordingToolBar );
2304 mgr->append( PauseRecordingId, myRecordingToolBar );
2305 mgr->append( StopRecordingId, myRecordingToolBar );
2308 void SVTK_ViewWindow::onUpdateRate(bool theIsActivate)
2311 myUpdateRateDlg->Update();
2312 myUpdateRateDlg->show();
2314 myUpdateRateDlg->hide();
2317 void SVTK_ViewWindow::onNonIsometric(bool theIsActivate)
2320 myNonIsometricDlg->Update();
2321 myNonIsometricDlg->show();
2323 myNonIsometricDlg->hide();
2326 void SVTK_ViewWindow::onGraduatedAxes(bool theIsActivate)
2329 myCubeAxesDlg->Update();
2330 myCubeAxesDlg->show();
2332 myCubeAxesDlg->hide();
2336 Starts rotation transformation
2338 void SVTK_ViewWindow::activateRotation()
2340 myEventDispatcher->InvokeEvent(SVTK::StartRotate,0);
2345 Starts panning transformation
2347 void SVTK_ViewWindow::activatePanning()
2349 myEventDispatcher->InvokeEvent(SVTK::StartPan,0);
2353 Starts zoom transformation
2355 void SVTK_ViewWindow::activateZoom()
2357 myEventDispatcher->InvokeEvent(SVTK::StartZoom,0);
2361 Starts window fit transformation
2363 void SVTK_ViewWindow::activateWindowFit()
2365 myEventDispatcher->InvokeEvent(SVTK::StartFitArea,0);
2369 Starts global panning transformation
2371 void SVTK_ViewWindow::activateGlobalPanning()
2373 myEventDispatcher->InvokeEvent(SVTK::StartGlobalPan,0);
2376 void SVTK_ViewWindow::onStartRecording()
2378 myRecorder->CheckExistAVIMaker();
2379 if (myRecorder->ErrorStatus()) {
2380 SUIT_MessageBox::warning(this, tr("ERROR"), tr("MSG_NO_AVI_MAKER") );
2383 SVTK_RecorderDlg* aRecorderDlg = new SVTK_RecorderDlg( this, myRecorder );
2385 if( !aRecorderDlg->exec() )
2388 myStartAction->setEnabled( false );
2389 myPlayAction->setEnabled( false );
2390 myPauseAction->setEnabled( true );
2391 myStopAction->setEnabled( true );
2393 // to prevent resizing the window while recording
2394 myPreRecordingMinSize = minimumSize();
2395 myPreRecordingMaxSize = maximumSize();
2396 setFixedSize( size() );
2398 myRecorder->Record();
2402 void SVTK_ViewWindow::onPlayRecording()
2404 myStartAction->setEnabled( false );
2405 myPlayAction->setEnabled( false );
2406 myPauseAction->setEnabled( true );
2407 myStopAction->setEnabled( true );
2409 myRecorder->Pause();
2412 void SVTK_ViewWindow::onPauseRecording()
2414 myStartAction->setEnabled( false );
2415 myPlayAction->setEnabled( true );
2416 myPauseAction->setEnabled( false );
2417 myStopAction->setEnabled( true );
2419 myRecorder->Pause();
2422 void SVTK_ViewWindow::onStopRecording()
2424 myStartAction->setEnabled( true );
2425 myPlayAction->setEnabled( false );
2426 myPauseAction->setEnabled( false );
2427 myStopAction->setEnabled( false );
2431 setMinimumSize( myPreRecordingMinSize );
2432 setMaximumSize( myPreRecordingMaxSize );
2436 To invoke a VTK event on SVTK_RenderWindowInteractor instance
2438 void SVTK_ViewWindow::InvokeEvent(unsigned long theEvent, void* theCallData)
2440 GetInteractor()->InvokeEvent(theEvent,theCallData);
2444 Modify view parameters
2446 void SVTK_ViewWindow::onViewParameters(bool theIsActivate)
2449 myViewParameterDlg->addObserver();
2450 myViewParameterDlg->show();
2452 myViewParameterDlg->hide();
2456 Custom show event handler
2458 void SVTK_ViewWindow::showEvent( QShowEvent * theEvent )
2460 emit Show( theEvent );
2464 Custom hide event handler
2466 void SVTK_ViewWindow::hideEvent( QHideEvent * theEvent )
2468 emit Hide( theEvent );
2472 Emit transformed signal.
2474 void SVTK_ViewWindow::emitTransformed() {
2481 void SVTK_ViewWindow::ProcessEvents(vtkObject* vtkNotUsed(theObject),
2482 unsigned long theEvent,
2483 void* theClientData,
2486 SVTK_ViewWindow* self = reinterpret_cast<SVTK_ViewWindow*>(theClientData);
2488 self->emitTransformed();
2492 Get camera properties for the SVTK view window.
2493 \return shared pointer on camera properties.
2495 SUIT_CameraProperties SVTK_ViewWindow::cameraProperties()
2497 SUIT_CameraProperties aProps;
2500 vtkCamera* aCamera = getRenderer()->GetActiveCamera();
2504 aProps.setDimension( SUIT_CameraProperties::Dim3D );
2505 if ( toolMgr()->action( ParallelModeId ) ) {
2506 if ( toolMgr()->action( ParallelModeId )->isChecked() )
2507 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
2509 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
2512 double aFocalPoint[3];
2513 double aPosition[3];
2515 double anAxialScale[3];
2517 aCamera->OrthogonalizeViewUp();
2518 aCamera->GetFocalPoint( aFocalPoint );
2519 aCamera->GetPosition( aPosition );
2520 aCamera->GetViewUp( aViewUp );
2522 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2523 aProps.setPosition( aPosition[0], aPosition[1], aPosition[2] );
2524 aProps.setViewUp( aViewUp[0], aViewUp[1], aViewUp[2] );
2525 aProps.setMappingScale( aCamera->GetParallelScale() * 2.0 );
2527 if ( aProps.getProjection() == SUIT_CameraProperties::PrjPerspective )
2529 aProps.setViewAngle( aCamera->GetViewAngle() );
2532 GetRenderer()->GetScale( anAxialScale );
2533 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2540 This implementation synchronizes camera propreties.
2542 void SVTK_ViewWindow::synchronize( SUIT_ViewWindow* theView )
2544 bool blocked = blockSignals( true );
2546 SUIT_CameraProperties aProps = theView->cameraProperties();
2547 if ( !cameraProperties().isCompatible( aProps ) ) {
2548 // other view, this one is being currently synchronized to, seems has become incompatible
2549 // we have to break synchronization
2555 vtkCamera* aCamera = getRenderer()->GetActiveCamera();
2557 double aFocalPoint[3];
2558 double aPosition[3];
2560 double anAxialScale[3];
2562 // get common properties
2563 aProps.getViewUp( aViewUp[0], aViewUp[1], aViewUp[2] );
2564 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
2565 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2566 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2568 // restore properties to the camera
2569 aCamera->SetViewUp( aViewUp );
2570 aCamera->SetPosition( aPosition );
2571 aCamera->SetFocalPoint( aFocalPoint );
2572 aCamera->SetParallelScale( aProps.getMappingScale() / 2.0 );
2574 if ( aProps.getProjection() == SUIT_CameraProperties::PrjPerspective )
2576 aCamera->SetViewAngle( aProps.getViewAngle() );
2579 GetRenderer()->SetScale( anAxialScale );
2581 getRenderer()->ResetCameraClippingRange();
2584 blockSignals( blocked );