1 // Copyright (C) 2007-2014 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 "vtkPVAxesWidget.h"
97 #include "vtkPVAxesActor.h"
99 #include "SALOME_ListIteratorOfListIO.hxx"
101 #include "VTKViewer_Algorithm.h"
102 #include "SVTK_Functor.h"
104 #include <OpenGLUtils_FrameBuffer.h>
109 int convertAction( const int accelAction )
111 switch ( accelAction ) {
112 case SUIT_Accel::PanLeft : return SVTK::PanLeftEvent;
113 case SUIT_Accel::PanRight : return SVTK::PanRightEvent;
114 case SUIT_Accel::PanUp : return SVTK::PanUpEvent;
115 case SUIT_Accel::PanDown : return SVTK::PanDownEvent;
116 case SUIT_Accel::ZoomIn : return SVTK::ZoomInEvent;
117 case SUIT_Accel::ZoomOut : return SVTK::ZoomOutEvent;
118 case SUIT_Accel::RotateLeft : return SVTK::RotateLeftEvent;
119 case SUIT_Accel::RotateRight : return SVTK::RotateRightEvent;
120 case SUIT_Accel::RotateUp : return SVTK::RotateUpEvent;
121 case SUIT_Accel::RotateDown : return SVTK::RotateDownEvent;
134 SVTK_ViewWindow::SVTK_ViewWindow(SUIT_Desktop* theDesktop):
135 SUIT_ViewWindow(theDesktop),
137 myDumpImage(QImage()),
138 myKeyFreeInteractorStyle(SVTK_KeyFreeInteractorStyle::New()),
139 myEventCallbackCommand(vtkCallbackCommand::New())
141 setWindowFlags( windowFlags() & ~Qt::Window );
142 // specific of vtkSmartPointer
143 myKeyFreeInteractorStyle->Delete();
147 To initialize #SVTK_ViewWindow instance
149 void SVTK_ViewWindow::Initialize(SVTK_ViewModelBase* theModel)
152 myInteractor = new SVTK_RenderWindowInteractor(this,"SVTK_RenderWindowInteractor");
154 SVTK_Selector* aSelector = SVTK_Selector::New();
155 int aPreselectionMode = SUIT_Session::session()->resourceMgr()->
156 integerValue( "VTKViewer", "preselection", Standard_Preselection );
157 aSelector->SetDynamicPreSelection( aPreselectionMode == Dynamic_Preselection );
158 aSelector->SetPreSelectionEnabled( aPreselectionMode != Preselection_Disabled );
159 bool isSelectionEnabled = SUIT_Session::session()->resourceMgr()->
160 booleanValue( "VTKViewer", "enable_selection", true );
161 aSelector->SetSelectionEnabled( isSelectionEnabled );
163 SVTK_GenericRenderWindowInteractor* aDevice = SVTK_GenericRenderWindowInteractor::New();
164 aDevice->SetRenderWidget(myInteractor);
165 aDevice->SetSelector(aSelector);
167 SVTK_Renderer* aRenderer = SVTK_Renderer::New();
168 aRenderer->Initialize(aDevice,aSelector);
170 myInteractor->Initialize(aDevice,aRenderer,aSelector);
176 myToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_LABEL"), false, Qt::AllToolBarAreas, -1, this );
177 myRecordingToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_RECORD_LABEL"), false, Qt::AllToolBarAreas, -1, this );
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 = 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 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 SLOT: called if selection is changed
444 void SVTK_ViewWindow::onSelectionChanged()
446 myView->onSelectionChanged();
450 Change selection mode
451 \param theMode - new selection mode
453 void SVTK_ViewWindow::SetSelectionMode(Selection_Mode theMode)
455 GetSelector()->SetSelectionMode(theMode);
459 \return selection mode
461 Selection_Mode SVTK_ViewWindow::SelectionMode() const
463 return GetSelector()->SelectionMode();
467 Unhilights all objects in viewer
469 void SVTK_ViewWindow::unHighlightAll()
471 myView->unHighlightAll();
475 Hilights/unhilights object in viewer
476 \param theIO - object to be updated
477 \param theIsHighlight - if it is true, object will be hilighted, otherwise it will be unhilighted
478 \param theIsUpdate - update current viewer
480 void SVTK_ViewWindow::highlight(const Handle(SALOME_InteractiveObject)& theIO,
484 myView->highlight( theIO, theIsHighlight, theIsUpdate );
488 \return true if object is in viewer or in collector
489 \param theIO - object to be checked
491 bool SVTK_ViewWindow::isInViewer( const Handle(SALOME_InteractiveObject)& theIO )
493 return myView->isInViewer( theIO );
497 \return true if object is displayed in viewer
498 \param theIO - object to be checked
500 bool SVTK_ViewWindow::isVisible( const Handle(SALOME_InteractiveObject)& theIO )
502 return myView->isVisible( theIO );
507 \param theEntry - entry that corresponds to intractive objects
509 Handle(SALOME_InteractiveObject) SVTK_ViewWindow::FindIObject(const char* theEntry)
511 return myView->FindIObject(theEntry);
516 \param theIO - object
517 \param theImmediatly - update viewer
519 void SVTK_ViewWindow::Display(const Handle(SALOME_InteractiveObject)& theIO,
522 myView->Display(theIO,theImmediatly);
527 \param theIO - object
528 \param theImmediatly - update viewer
530 void SVTK_ViewWindow::Erase(const Handle(SALOME_InteractiveObject)& theIO,
533 myView->Erase(theIO,theImmediatly);
537 Display only passed object
538 \param theIO - object
540 void SVTK_ViewWindow::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIO)
542 myView->DisplayOnly(theIO);
546 Display all objects in view
548 void SVTK_ViewWindow::DisplayAll()
550 myView->DisplayAll();
554 Erase all objects in view
556 void SVTK_ViewWindow::EraseAll()
562 Sets background color [obsolete]
563 \param color - new background color
565 void SVTK_ViewWindow::setBackgroundColor( const QColor& c )
567 Qtx::BackgroundData bg = background();
573 \return background color of viewer [obsolete]
575 QColor SVTK_ViewWindow::backgroundColor() const
577 return background().color();
582 \param bgData - new background data
584 void SVTK_ViewWindow::setBackground( const Qtx::BackgroundData& bgData )
588 if ( bgData.isValid() ) {
589 switch ( bgData.mode() ) {
590 case Qtx::ColorBackground:
592 QColor c = bgData.color();
594 // show solid-colored background
595 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
596 getRenderer()->SetGradientBackground( false ); // cancel gradient mode
597 getRenderer()->SetBackground( c.red()/255.0,
599 c.blue()/255.0 ); // set background color
604 case Qtx::SimpleGradientBackground:
607 int type = bgData.gradient( c1, c2 );
613 // show two-color gradient background
614 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
615 getRenderer()->SetGradientBackground( true ); // switch to gradient mode
617 VTKViewer_OpenGLRenderer* aRenderer =
618 VTKViewer_OpenGLRenderer::SafeDownCast( getRenderer() );
621 aRenderer->SetGradientType( type );
622 aRenderer->SetBackground( c1.redF(), c1.greenF(), c1.blueF() );
623 aRenderer->SetBackground2( c2.redF(), c2.greenF(), c2.blueF() );
629 case Qtx::CustomGradientBackground:
631 // NOT IMPLEMENTED YET
632 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
633 getRenderer()->SetGradientBackground( false ); // cancel gradient mode
640 if ( bgData.isTextureShown() ) {
642 int textureMode = bgData.texture( fileName );
643 QFileInfo fi( fileName );
644 if ( !fileName.isEmpty() && fi.exists() ) {
645 // read texture from file
646 QString extension = fi.suffix().toLower();
647 vtkImageReader2* aReader = 0;
648 if ( extension == "jpg" || extension == "jpeg" )
649 aReader = vtkJPEGReader::New();
650 else if ( extension == "bmp" )
651 aReader = vtkBMPReader::New();
652 else if ( extension == "tif" || extension == "tiff" )
653 aReader = vtkTIFFReader::New();
654 else if ( extension == "png" )
655 aReader = vtkPNGReader::New();
656 else if ( extension == "mhd" || extension == "mha" )
657 aReader = vtkMetaImageReader::New();
660 aReader->SetFileName( fi.absoluteFilePath().toLatin1().constData() );
662 VTKViewer_Texture* aTexture = VTKViewer_Texture::New();
663 vtkImageMapToColors* aMap = 0;
664 vtkAlgorithmOutput* anOutput;
666 // special processing for BMP reader
667 vtkBMPReader* aBMPReader = (vtkBMPReader*)aReader;
669 // Special processing for BMP file
670 aBMPReader->SetAllow8BitBMP(1);
672 aMap = vtkImageMapToColors::New();
673 aMap->SetInputConnection( aBMPReader->GetOutputPort() );
674 aMap->SetLookupTable( (vtkScalarsToColors*)aBMPReader->GetLookupTable() );
675 aMap->SetOutputFormatToRGB();
677 anOutput = aMap->GetOutputPort();
682 anOutput = aReader->GetOutputPort( 0 );
683 aTexture->SetInputConnection( anOutput );
685 // VSR: Currently, VTK only supports Stretch mode, so below code will give
686 // the same results for all modes
687 switch ( textureMode ) {
688 case Qtx::TileTexture:
689 aTexture->SetPosition((int)VTKViewer_Texture::Tiled);
691 case Qtx::StretchTexture:
692 aTexture->SetPosition((int)VTKViewer_Texture::Stretched);
694 case Qtx::CenterTexture:
695 aTexture->SetPosition((int)VTKViewer_Texture::Centered);
699 // show textured background
700 getRenderer()->SetTexturedBackground( true );
701 getRenderer()->SetBackgroundTexture( aTexture );
703 // clean-up resources
714 myBackground = bgData;
718 \return background data of viewer
720 Qtx::BackgroundData SVTK_ViewWindow::background() const
727 Redirect the request to SVTK_RenderWindowInteractor::GetInteractorStyle
729 vtkInteractorStyle* SVTK_ViewWindow::GetInteractorStyle() const
731 return GetInteractor()->GetInteractorStyle();
735 Redirect the request to SVTK_RenderWindowInteractor::PushInteractorStyle
737 void SVTK_ViewWindow::PushInteractorStyle(vtkInteractorStyle* theStyle)
739 GetInteractor()->PushInteractorStyle(theStyle);
743 Redirect the request to SVTK_RenderWindowInteractor::PopInteractorStyle
745 void SVTK_ViewWindow::PopInteractorStyle()
747 GetInteractor()->PopInteractorStyle();
751 Updates current viewer
753 void SVTK_ViewWindow::Repaint(bool theUpdateTrihedron)
755 if(theUpdateTrihedron)
756 GetRenderer()->OnAdjustTrihedron();
758 GetInteractor()->update();
760 SVTK_InteractorStyle* aStyle = (SVTK_InteractorStyle*)getInteractor()->GetInteractorStyle();
766 Redirect the request to #SVTK_Renderer::GetScale
768 void SVTK_ViewWindow::GetScale( double theScale[3] )
770 GetRenderer()->GetScale( theScale );
774 Redirect the request to #SVTK_Renderer::SetScale
776 void SVTK_ViewWindow::SetScale( double theScale[3] )
778 GetRenderer()->SetScale( theScale );
780 emit transformed( this );
784 Redirect the request to #SVTK_Renderer::IsTrihedronDisplayed
786 bool SVTK_ViewWindow::isTrihedronDisplayed()
788 return GetRenderer()->IsTrihedronDisplayed();
792 Redirect the request to #SVTK_Renderer::IsCubeAxesDisplayed
794 bool SVTK_ViewWindow::isCubeAxesDisplayed()
796 return GetRenderer()->IsCubeAxesDisplayed();
800 Redirect the request to #SVTK_Renderer::OnViewTrihedron
802 void SVTK_ViewWindow::onViewTrihedron()
804 GetRenderer()->OnViewTrihedron();
809 Redirect the request to #SVTK_Renderer::OnViewCubeAxes
811 void SVTK_ViewWindow::onViewCubeAxes()
813 GetRenderer()->OnViewCubeAxes();
818 Redirect the request to #SVTK_Renderer::GetTrihedron
820 VTKViewer_Trihedron* SVTK_ViewWindow::GetTrihedron()
822 return GetRenderer()->GetTrihedron();
826 Redirect the request to #SVTK_Renderer::GetCubeAxes
828 SVTK_CubeAxesActor2D* SVTK_ViewWindow::GetCubeAxes()
830 return GetRenderer()->GetCubeAxes();
834 \return trihedron size
836 double SVTK_ViewWindow::GetTrihedronSize() const
838 return GetRenderer()->GetTrihedronSize();
843 \param theMode - projection mode ( 0 - orthogonal, 1 - perspective )
845 void SVTK_ViewWindow::SetProjectionMode(const int theMode)
847 activateProjectionMode( theMode );
852 Set the gravity center as a focal point
854 void SVTK_ViewWindow::activateSetFocalPointGravity()
856 myEventDispatcher->InvokeEvent(SVTK::SetFocalPointGravity, 0);
860 Set the selected point as a focal point
862 void SVTK_ViewWindow::activateSetFocalPointSelected()
864 myEventDispatcher->InvokeEvent(SVTK::SetFocalPointSelected, 0);
868 Set the point selected by user as a focal point
870 void SVTK_ViewWindow::activateStartFocalPointSelection()
872 myEventDispatcher->InvokeEvent(SVTK::StartFocalPointSelection,0);
875 void SVTK_ViewWindow::activateProjectionMode(int theMode)
878 toolMgr()->action( ProjectionModeId )->setChecked( true );
880 toolMgr()->action( ParallelModeId )->setChecked( true );
884 Sets actual interaction style
885 \param theStyle - type of interaction style ( 0 - standard, 1 - keyboard free )
887 void SVTK_ViewWindow::SetInteractionStyle(const int theStyle)
889 onSwitchInteractionStyle( theStyle==1 );
893 Sets actual zooming style
894 \param theStyle - type of zooming style ( 0 - standard, 1 - advanced (at cursor) )
896 void SVTK_ViewWindow::SetZoomingStyle(const int theStyle)
898 onSwitchZoomingStyle( theStyle==1 );
902 Set preselection mode.
903 \param theMode the mode to set (standard, dynamic or disabled)
905 void SVTK_ViewWindow::SetPreSelectionMode( Preselection_Mode theMode )
907 onSwitchPreSelectionMode( theMode );
911 Enables/disables selection.
912 \param theEnable if true - selection will be enabled
914 void SVTK_ViewWindow::SetSelectionEnabled( bool theEnable )
916 GetSelector()->SetSelectionEnabled( theEnable );
917 QtxAction* a = getAction( EnableSelectionId );
918 if ( a->isChecked() != theEnable)
919 a->setChecked( theEnable );
920 QtxActionGroup* aPreselectionGroup =
921 dynamic_cast<QtxActionGroup*>( getAction( PreselectionId ) );
922 if ( aPreselectionGroup )
923 aPreselectionGroup->setEnabled( theEnable );
927 Switches "keyboard free" interaction style on/off
929 void SVTK_ViewWindow::onSwitchInteractionStyle(bool theOn)
932 // check if style is already set
933 if ( GetInteractorStyle() != myKeyFreeInteractorStyle.GetPointer() )
935 // keep the same style extensions
936 SVTK_InteractorStyle* aStyle = (SVTK_InteractorStyle*)GetInteractorStyle();
938 myKeyFreeInteractorStyle->SetControllerIncrement(aStyle->ControllerIncrement());
939 myKeyFreeInteractorStyle->SetControllerOnKeyDown(aStyle->ControllerOnKeyDown());
942 PushInteractorStyle(myKeyFreeInteractorStyle.GetPointer());
946 // pop only key free style
947 if ( GetInteractorStyle() == myKeyFreeInteractorStyle.GetPointer() )
948 PopInteractorStyle();
951 // update action state if method is called outside
952 QtxAction* a = getAction( SwitchInteractionStyleId );
953 if ( a->isChecked() != theOn ) a->setChecked( theOn );
957 Toogles advanced zooming style (relatively to the cursor position) on/off
959 void SVTK_ViewWindow::onSwitchZoomingStyle( bool theOn )
961 if( myDefaultInteractorStyle.GetPointer() )
962 myDefaultInteractorStyle->SetAdvancedZoomingEnabled( theOn );
963 if( myKeyFreeInteractorStyle.GetPointer() )
964 myKeyFreeInteractorStyle->SetAdvancedZoomingEnabled( theOn );
966 // update action state if method is called outside
967 QtxAction* a = getAction( SwitchZoomingStyleId );
968 if ( a->isChecked() != theOn )
969 a->setChecked( theOn );
973 Switch preselection mode.
974 \param theMode the preselection mode
976 void SVTK_ViewWindow::onSwitchPreSelectionMode( int theMode )
978 GetSelector()->SetDynamicPreSelection( theMode == Dynamic_Preselection );
979 GetSelector()->SetPreSelectionEnabled( theMode != Preselection_Disabled );
981 // update action state if method is called outside
982 QtxAction* a = getAction( StandardPreselectionId + theMode );
983 if ( a && !a->isChecked() )
984 a->setChecked( true );
988 Enables/disables selection.
989 \param theOn if true - selection will be enabled
991 void SVTK_ViewWindow::onEnableSelection( bool on )
993 SVTK_Viewer* aViewer = dynamic_cast<SVTK_Viewer*>(myModel);
995 aViewer->enableSelection(on);
999 Sets incremental speed
1000 \param theValue - new incremental speed
1001 \param theMode - modification mode
1003 void SVTK_ViewWindow::SetIncrementalSpeed(const int theValue, const int theMode)
1005 if ( (SVTK_InteractorStyle*)GetInteractorStyle() )
1006 ((SVTK_InteractorStyle*)GetInteractorStyle())->SetIncrementSpeed(theValue, theMode);
1010 Sets spacemouse buttons for the functions
1011 \param theBtn1 - spacemouse button for the "decrease speed increment"
1012 \param theBtn2 - spacemouse button for the "increase speed increment"
1013 \param theBtn3 - spacemouse button for the "dominant combined switch"
1015 void SVTK_ViewWindow::SetSpacemouseButtons(const int theBtn1,
1020 myEventDispatcher->InvokeEvent(SVTK::SetSMDecreaseSpeedEvent, &val);
1022 myEventDispatcher->InvokeEvent(SVTK::SetSMIncreaseSpeedEvent, &val);
1024 myEventDispatcher->InvokeEvent(SVTK::SetSMDominantCombinedSwitchEvent, &val);
1029 \param theSize - new trihedron size
1030 \param theRelative - trihedron relativeness
1032 void SVTK_ViewWindow::SetTrihedronSize(const double theSize, const bool theRelative)
1034 GetRenderer()->SetTrihedronSize(theSize, theRelative);
1038 /*! If parameter theIsForcedUpdate is true, recalculate parameters for
1039 * trihedron and cube axes, even if trihedron and cube axes is invisible.
1041 void SVTK_ViewWindow::AdjustTrihedrons(const bool theIsForcedUpdate)
1043 GetRenderer()->AdjustActors();
1048 Redirect the request to #SVTK_Renderer::OnAdjustTrihedron
1050 void SVTK_ViewWindow::onAdjustTrihedron()
1052 GetRenderer()->OnAdjustTrihedron();
1056 Redirect the request to #SVTK_Renderer::OnAdjustCubeAxes
1058 void SVTK_ViewWindow::onAdjustCubeAxes()
1060 GetRenderer()->OnAdjustCubeAxes();
1063 void SVTK_ViewWindow::synchronize(SVTK_ViewWindow* otherViewWindow )
1065 if ( otherViewWindow ) {
1066 bool blocked = blockSignals( true );
1067 doSetVisualParameters( otherViewWindow->getVisualParameters(), true );
1068 blockSignals( blocked );
1075 void SVTK_ViewWindow::onKeyPressed(QKeyEvent* event)
1077 emit keyPressed( this, event );
1083 void SVTK_ViewWindow::onKeyReleased(QKeyEvent* event)
1085 emit keyReleased( this, event );
1091 void SVTK_ViewWindow::onMousePressed(QMouseEvent* event)
1093 emit mousePressed(this, event);
1097 Emits mouse released
1099 void SVTK_ViewWindow::onMouseReleased(QMouseEvent* event)
1101 emit mouseReleased( this, event );
1107 void SVTK_ViewWindow::onMouseMoving(QMouseEvent* event)
1109 emit mouseMoving( this, event );
1113 Emits mouse double clicked
1115 void SVTK_ViewWindow::onMouseDoubleClicked( QMouseEvent* event )
1117 emit mouseDoubleClicked( this, event );
1121 Redirect the request to #SVTK_Renderer::AddActor
1123 void SVTK_ViewWindow::AddActor( VTKViewer_Actor* theActor,
1125 bool theIsAdjustActors )
1127 GetRenderer()->AddActor(theActor, theIsAdjustActors);
1130 emit actorAdded(theActor);
1134 Redirect the request to #SVTK_Renderer::RemoveActor
1136 void SVTK_ViewWindow::RemoveActor( VTKViewer_Actor* theActor,
1138 bool theIsAdjustActors )
1140 GetRenderer()->RemoveActor(theActor, theIsAdjustActors);
1141 if ( myDefaultInteractorStyle )
1142 myDefaultInteractorStyle->FreeActors();
1143 if ( myKeyFreeInteractorStyle )
1144 myKeyFreeInteractorStyle->FreeActors();
1147 emit actorRemoved(theActor);
1150 QImage SVTK_ViewWindow::dumpViewContent()
1152 vtkRenderWindow* aWindow = getRenderWindow();
1153 int* aSize = aWindow->GetSize();
1154 int aWidth = aSize[0];
1155 int aHeight = aSize[1];
1157 OpenGLUtils_FrameBuffer aFrameBuffer;
1158 if( aFrameBuffer.init( aWidth, aHeight ) )
1160 glPushAttrib( GL_VIEWPORT_BIT );
1161 glViewport( 0, 0, aWidth, aHeight );
1162 aFrameBuffer.bind();
1167 aFrameBuffer.unbind();
1170 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
1172 aFrameBuffer.bind();
1173 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
1174 aFrameBuffer.unbind();
1176 anImage = anImage.rgbSwapped();
1177 anImage = anImage.mirrored();
1181 // if frame buffers are unsupported, use old functionality
1182 unsigned char *aData =
1183 aWindow->GetRGBACharPixelData( 0, 0, aWidth-1, aHeight-1, 0 );
1185 QImage anImage( aData, aWidth, aHeight, QImage::Format_ARGB32 );
1187 anImage = anImage.rgbSwapped();
1188 anImage = anImage.mirrored();
1193 \return QImage, containing all scene rendering in window
1195 QImage SVTK_ViewWindow::dumpView()
1197 if( myDumpImage.isNull() )
1198 return dumpViewContent();
1204 QString SVTK_ViewWindow::filter() const
1206 return tr( "SVTK_IMAGE_FILES" );
1209 bool SVTK_ViewWindow::dumpViewToFormat( const QImage& img, const QString& fileName, const QString& format )
1211 if ( format != "PS" && format != "EPS" && format != "PDF" )
1212 return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
1214 SUIT_OverrideCursor wc;
1216 vtkGL2PSExporter *anExporter = vtkGL2PSExporter::New();
1217 anExporter->SetRenderWindow(getRenderWindow());
1219 if ( format == "PS" ) {
1220 anExporter->SetFileFormatToPS();
1221 anExporter->CompressOff();
1224 if ( format == "EPS" ) {
1225 anExporter->SetFileFormatToEPS();
1226 anExporter->CompressOff();
1229 if ( format == "PDF" ) {
1230 anExporter->SetFileFormatToPDF();
1233 QString aFilePrefix(fileName);
1234 QString anExtension(SUIT_Tools::extension(fileName));
1235 aFilePrefix.truncate(aFilePrefix.length() - 1 - anExtension.length());
1236 anExporter->SetFilePrefix(aFilePrefix.toLatin1().data());
1237 anExporter->Write();
1238 anExporter->Delete();
1244 \refresh QImage, containing all scene rendering in window
1246 void SVTK_ViewWindow::RefreshDumpImage()
1248 myDumpImage = dumpViewContent();
1252 Redirect the request to #SVTK_Renderer::SetSelectionProp
1254 void SVTK_ViewWindow::SetSelectionProp(const double& theRed,
1255 const double& theGreen,
1256 const double& theBlue,
1257 const int& theWidth)
1259 myView->SetSelectionProp(theRed,theGreen,theBlue,theWidth);
1263 Redirect the request to #SVTK_Renderer::SetSelectionProp
1265 void SVTK_ViewWindow::SetPreselectionProp(const double& theRed,
1266 const double& theGreen,
1267 const double& theBlue,
1268 const int& theWidth)
1270 myView->SetPreselectionProp(theRed,theGreen,theBlue,theWidth);
1274 Redirect the request to #SVTK_Renderer::SetSelectionTolerance
1276 void SVTK_ViewWindow::SetSelectionTolerance(const double& theTolNodes,
1277 const double& theTolItems,
1278 const double& theTolObjects)
1280 myView->SetSelectionTolerance(theTolNodes, theTolItems, theTolObjects);
1284 Get visibility status of the static trihedron
1286 bool SVTK_ViewWindow::IsStaticTrihedronVisible() const
1288 return (bool)myAxesWidget->GetEnabled();
1292 Set visibility status of the static trihedron
1294 void SVTK_ViewWindow::SetStaticTrihedronVisible( const bool theIsVisible )
1296 myAxesWidget->SetEnabled( (int)theIsVisible );
1301 \param accelAction - action
1303 bool SVTK_ViewWindow::action( const int accelAction )
1305 if ( accelAction == SUIT_Accel::ZoomFit )
1308 int anEvent = SVTK::convertAction( accelAction );
1309 GetInteractor()->InvokeEvent(anEvent, 0);
1315 \return action by it's id
1317 QtxAction* SVTK_ViewWindow::getAction( int id ) const
1319 return dynamic_cast<QtxAction*>( toolMgr()->action( id ) );
1323 // old visual parameters had 13 values. New format added additional
1324 // 76 values for graduated axes, so both numbers are processed.
1325 const int nNormalParams = 13; // number of view windows parameters excluding graduated axes params
1326 const int nGradAxisParams = 25; // number of parameters of ONE graduated axis (X, Y, or Z)
1327 const int nTrihedronParams = 3; // number of parameters for Trihedron
1328 const int nAllParams = nNormalParams + 3*nGradAxisParams + nTrihedronParams + 1; // number of all visual parameters
1330 /*! The method returns visual parameters of a graduated axis actor (x,y,z axis of graduated axes)
1332 void getGradAxisVisualParams( QXmlStreamWriter& writer, vtkAxisActor2D* actor, QString theAxis )
1339 bool isVisible = actor->GetTitleVisibility();
1340 QString title ( actor->GetTitle() );
1342 int font = VTK_ARIAL;
1347 vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1350 txtProp->GetColor( color );
1351 font = txtProp->GetFontFamily();
1352 bold = txtProp->GetBold();
1353 italic = txtProp->GetItalic();
1354 shadow = txtProp->GetShadow();
1356 writer.writeStartElement("GraduatedAxis");
1357 writer.writeAttribute("Axis", theAxis);
1359 writer.writeStartElement("Title");
1360 writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1361 writer.writeAttribute("Text", title);
1362 writer.writeAttribute("Font", QString("%1").arg(font));
1363 writer.writeAttribute("Bold", QString("%1").arg(bold));
1364 writer.writeAttribute("Italic", QString("%1").arg(italic));
1365 writer.writeAttribute("Shadow", QString("%1").arg(shadow));
1367 writer.writeStartElement("Color");
1368 writer.writeAttribute("R", QString("%1").arg(color[0]));
1369 writer.writeAttribute("G", QString("%1").arg(color[1]));
1370 writer.writeAttribute("B", QString("%1").arg(color[2]));
1371 writer.writeEndElement();
1372 writer.writeEndElement();
1374 //params.sprintf( "* Graduated Axis: * Name *%u*%s*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible,
1375 // title.toLatin1().data(), color[0], color[1], color[2], font, bold, italic, shadow );
1378 isVisible = actor->GetLabelVisibility();
1379 int labels = actor->GetNumberOfLabels();
1380 int offset = actor->GetTickOffset();
1386 txtProp = actor->GetLabelTextProperty();
1389 txtProp->GetColor( color );
1390 font = txtProp->GetFontFamily();
1391 bold = txtProp->GetBold();
1392 italic = txtProp->GetItalic();
1393 shadow = txtProp->GetShadow();
1396 writer.writeStartElement("Labels");
1397 writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1398 writer.writeAttribute("Number", QString("%1").arg(labels));
1399 writer.writeAttribute("Offset", QString("%1").arg(offset));
1400 writer.writeAttribute("Font", QString("%1").arg(font));
1401 writer.writeAttribute("Bold", QString("%1").arg(bold));
1402 writer.writeAttribute("Italic", QString("%1").arg(italic));
1403 writer.writeAttribute("Shadow", QString("%1").arg(shadow));
1405 writer.writeStartElement("Color");
1406 writer.writeAttribute("R", QString("%1").arg(color[0]));
1407 writer.writeAttribute("G", QString("%1").arg(color[1]));
1408 writer.writeAttribute("B", QString("%1").arg(color[2]));
1409 writer.writeEndElement();
1410 writer.writeEndElement();
1411 // params += QString().sprintf( "* Labels *%u*%u*%u*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible, labels, offset,
1412 // color[0], color[1], color[2], font, bold, italic, shadow );
1415 isVisible = actor->GetTickVisibility();
1416 int length = actor->GetTickLength();
1417 writer.writeStartElement("TickMarks");
1418 writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1419 writer.writeAttribute("Length", QString("%1").arg(length));
1420 writer.writeEndElement();
1422 //params += QString().sprintf( "* Tick marks *%u*%u", isVisible, length );
1424 writer.writeEndElement();
1428 void setGradAxisVisualParams(QXmlStreamReader& reader, vtkAxisActor2D* actor)
1435 } while (!reader.isStartElement());
1437 // Read title params
1438 QXmlStreamAttributes aAttr = reader.attributes();
1439 bool isVisible = aAttr.value("isVisible").toString().toUShort();
1440 QString title = aAttr.value("Text").toString();
1441 int font = aAttr.value("Font").toString().toInt();
1442 int bold = aAttr.value("Bold").toString().toInt();
1443 int italic = aAttr.value("Italic").toString().toInt();
1444 int shadow = aAttr.value("Shadow").toString().toInt();
1446 //printf("#### TITLE: %i, %s, %i, %i, %i, %i\n", isVisible, qPrintable(title), font, bold, italic, shadow);
1450 } while (!reader.isStartElement());
1453 aAttr = reader.attributes();
1456 color[0] = aAttr.value("R").toString().toDouble();
1457 color[1] = aAttr.value("G").toString().toDouble();
1458 color[2] = aAttr.value("B").toString().toDouble();
1459 //printf("#### Color: %f, %f, %f\n", color[0], color[1], color[2]);
1461 actor->SetTitleVisibility( isVisible );
1462 actor->SetTitle( title.toLatin1() );
1463 vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1465 txtProp->SetColor( color );
1466 txtProp->SetFontFamily( font );
1467 txtProp->SetBold( bold );
1468 txtProp->SetItalic( italic );
1469 txtProp->SetShadow( shadow );
1476 } while (!reader.isStartElement());
1478 aAttr = reader.attributes();
1479 isVisible = aAttr.value("isVisible").toString().toUShort();
1480 int labels = aAttr.value("Number").toString().toInt();
1481 int offset = aAttr.value("Offset").toString().toInt();
1482 font = aAttr.value("Font").toString().toInt();
1483 bold = aAttr.value("Bold").toString().toInt();
1484 italic = aAttr.value("Italic").toString().toInt();
1485 shadow = aAttr.value("Shadow").toString().toInt();
1489 } while (!reader.isStartElement());
1491 aAttr = reader.attributes();
1493 color[0] = aAttr.value("R").toString().toDouble();
1494 color[1] = aAttr.value("G").toString().toDouble();
1495 color[2] = aAttr.value("B").toString().toDouble();
1497 actor->SetLabelVisibility( isVisible );
1498 actor->SetNumberOfLabels( labels );
1499 actor->SetTickOffset( offset );
1500 txtProp = actor->GetLabelTextProperty();
1502 txtProp->SetColor( color );
1503 txtProp->SetFontFamily( font );
1504 txtProp->SetBold( bold );
1505 txtProp->SetItalic( italic );
1506 txtProp->SetShadow( shadow );
1512 } while (!reader.isStartElement());
1513 aAttr = reader.attributes();
1515 // retrieve and set tick marks properties
1516 isVisible = aAttr.value("isVisible").toString().toUShort();
1517 int length = aAttr.value("Length").toString().toInt();
1519 actor->SetTickVisibility( isVisible );
1520 actor->SetTickLength( length );
1523 /*! The method restores visual parameters of a graduated axis actor (x,y,z axis)
1525 void setGradAxisVisualParams( vtkAxisActor2D* actor, const QString& params )
1530 QStringList paramsLst = params.split( '*' );
1532 if ( paramsLst.size() == nGradAxisParams ) { // altogether name, lable, ticks parameters make up 25 values
1534 // retrieve and set name parameters
1535 bool isVisible = paramsLst[2].toUShort();
1536 QString title = paramsLst[3];
1538 color[0] = paramsLst[4].toDouble();
1539 color[1] = paramsLst[5].toDouble();
1540 color[2] = paramsLst[6].toDouble();
1541 int font = paramsLst[7].toInt();
1542 int bold = paramsLst[8].toInt();
1543 int italic = paramsLst[9].toInt();
1544 int shadow = paramsLst[10].toInt();
1546 actor->SetTitleVisibility( isVisible );
1547 actor->SetTitle( title.toLatin1() );
1548 vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1550 txtProp->SetColor( color );
1551 txtProp->SetFontFamily( font );
1552 txtProp->SetBold( bold );
1553 txtProp->SetItalic( italic );
1554 txtProp->SetShadow( shadow );
1557 // retrieve and set lable parameters
1558 isVisible = paramsLst[12].toUShort();
1559 int labels = paramsLst[13].toInt();
1560 int offset = paramsLst[14].toInt();
1561 color[0] = paramsLst[15].toDouble();
1562 color[1] = paramsLst[16].toDouble();
1563 color[2] = paramsLst[17].toDouble();
1564 font = paramsLst[18].toInt();
1565 bold = paramsLst[19].toInt();
1566 italic = paramsLst[20].toInt();
1567 shadow = paramsLst[21].toInt();
1569 actor->SetLabelVisibility( isVisible );
1570 actor->SetNumberOfLabels( labels );
1571 actor->SetTickOffset( offset );
1572 txtProp = actor->GetLabelTextProperty();
1574 txtProp->SetColor( color );
1575 txtProp->SetFontFamily( font );
1576 txtProp->SetBold( bold );
1577 txtProp->SetItalic( italic );
1578 txtProp->SetShadow( shadow );
1581 // retrieve and set tick marks properties
1582 isVisible = paramsLst[23].toUShort();
1583 int length = paramsLst[24].toInt();
1585 actor->SetTickVisibility( isVisible );
1586 actor->SetTickLength( length );
1590 /*! The method returns the visual parameters of this view as a formated string
1592 QString SVTK_ViewWindow::getVisualParameters()
1594 double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
1596 // save position, focal point, viewUp, scale
1597 vtkCamera* camera = getRenderer()->GetActiveCamera();
1598 camera->GetPosition( pos );
1599 camera->GetFocalPoint( focalPnt );
1600 camera->GetViewUp( viewUp );
1601 parScale = camera->GetParallelScale();
1604 // Parameters are given in the following format:view position (3 digits), focal point position (3 digits)
1605 // view up values (3 digits), parallel scale (1 digit), scale (3 digits,
1606 // Graduated axes parameters (X, Y, Z axes parameters)
1608 QXmlStreamWriter aWriter(&retStr);
1609 aWriter.setAutoFormatting(true);
1611 aWriter.writeStartDocument();
1612 aWriter.writeStartElement("ViewState");
1614 aWriter.writeStartElement("Position");
1615 aWriter.writeAttribute("X", QString("%1").arg(pos[0]));
1616 aWriter.writeAttribute("Y", QString("%1").arg(pos[1]));
1617 aWriter.writeAttribute("Z", QString("%1").arg(pos[2]));
1618 aWriter.writeEndElement();
1620 aWriter.writeStartElement("FocalPoint");
1621 aWriter.writeAttribute("X", QString::number(focalPnt[0]));
1622 aWriter.writeAttribute("Y", QString::number(focalPnt[1]));
1623 aWriter.writeAttribute("Z", QString::number(focalPnt[2]));
1624 aWriter.writeEndElement();
1626 aWriter.writeStartElement("ViewUp");
1627 aWriter.writeAttribute("X", QString::number(viewUp[0]));
1628 aWriter.writeAttribute("Y", QString::number(viewUp[1]));
1629 aWriter.writeAttribute("Z", QString::number(viewUp[2]));
1630 aWriter.writeEndElement();
1632 aWriter.writeStartElement("ViewScale");
1633 aWriter.writeAttribute("Parallel", QString::number(parScale));
1634 aWriter.writeAttribute("X", QString::number(scale[0]));
1635 aWriter.writeAttribute("Y", QString::number(scale[1]));
1636 aWriter.writeAttribute("Z", QString::number(scale[2]));
1637 aWriter.writeEndElement();
1639 if ( SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes() ) {
1640 aWriter.writeStartElement("DisplayCubeAxis");
1641 aWriter.writeAttribute("Show", QString( "%1" ).arg( GetRenderer()->IsCubeAxesDisplayed()));
1642 aWriter.writeEndElement();
1644 getGradAxisVisualParams(aWriter, gradAxesActor->GetXAxisActor2D(), "X");
1645 getGradAxisVisualParams(aWriter, gradAxesActor->GetYAxisActor2D(), "Y");
1646 getGradAxisVisualParams(aWriter, gradAxesActor->GetZAxisActor2D(), "Z");
1649 aWriter.writeStartElement("Trihedron");
1650 aWriter.writeAttribute("isShown", QString( "%1" ).arg( isTrihedronDisplayed()));
1651 aWriter.writeAttribute("Size", QString::number(GetTrihedronSize()));
1652 aWriter.writeEndElement();
1654 aWriter.writeStartElement("Background");
1655 aWriter.writeAttribute("Value", QString( "%1" ).arg( Qtx::backgroundToString(background()) ));
1656 aWriter.writeEndElement();
1658 aWriter.writeEndElement();
1659 aWriter.writeEndDocument();
1665 The method restores visual parameters of this view or postpones it untill the view is shown
1667 void SVTK_ViewWindow::setVisualParameters( const QString& parameters )
1669 //printf("#### %s\n", qPrintable(parameters));
1670 SVTK_RenderWindowInteractor* anInteractor = GetInteractor();
1671 if ( anInteractor->isVisible() ) {
1672 doSetVisualParameters( parameters );
1675 myVisualParams = parameters;
1676 anInteractor->installEventFilter(this);
1681 The method restores visual parameters of this view from a formated string
1683 void SVTK_ViewWindow::doSetVisualParameters( const QString& parameters, bool baseParamsOnly )
1686 double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
1688 QXmlStreamReader aReader(parameters);
1689 SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes();
1691 while(!aReader.atEnd()) {
1693 if (aReader.isStartElement()) {
1694 QXmlStreamAttributes aAttr = aReader.attributes();
1695 //printf("### Name = %s\n", qPrintable(aReader.name().toString()));
1696 if (aReader.name() == "Position") {
1697 pos[0] = aAttr.value("X").toString().toDouble();
1698 pos[1] = aAttr.value("Y").toString().toDouble();
1699 pos[2] = aAttr.value("Z").toString().toDouble();
1700 //printf("#### Position %f; %f; %f\n", pos[0], pos[1], pos[2]);
1702 else if (aReader.name() == "FocalPoint") {
1703 focalPnt[0] = aAttr.value("X").toString().toDouble();
1704 focalPnt[1] = aAttr.value("Y").toString().toDouble();
1705 focalPnt[2] = aAttr.value("Z").toString().toDouble();
1706 //printf("#### FocalPoint %f; %f; %f\n", focalPnt[0], focalPnt[1], focalPnt[2]);
1708 else if (aReader.name() == "ViewUp") {
1709 viewUp[0] = aAttr.value("X").toString().toDouble();
1710 viewUp[1] = aAttr.value("Y").toString().toDouble();
1711 viewUp[2] = aAttr.value("Z").toString().toDouble();
1712 //printf("#### ViewUp %f; %f; %f\n", viewUp[0], viewUp[1], viewUp[2]);
1714 else if (aReader.name() == "ViewScale") {
1715 parScale = aAttr.value("Parallel").toString().toDouble();
1716 scale[0] = aAttr.value("X").toString().toDouble();
1717 scale[1] = aAttr.value("Y").toString().toDouble();
1718 scale[2] = aAttr.value("Z").toString().toDouble();
1719 //printf("#### ViewScale %f; %f; %f\n", scale[0], scale[1], scale[2]);
1721 else if (aReader.name() == "DisplayCubeAxis") {
1722 if ( !baseParamsOnly ) {
1723 if (aAttr.value("Show") == "0")
1724 gradAxesActor->VisibilityOff();
1726 gradAxesActor->VisibilityOn();
1729 else if (aReader.name() == "GraduatedAxis") {
1730 if ( !baseParamsOnly ) {
1731 if(aAttr.value("Axis") == "X")
1732 setGradAxisVisualParams(aReader, gradAxesActor->GetXAxisActor2D());
1733 else if(aAttr.value("Axis") == "Y")
1734 setGradAxisVisualParams(aReader, gradAxesActor->GetYAxisActor2D());
1735 else if(aAttr.value("Axis") == "Z")
1736 setGradAxisVisualParams(aReader, gradAxesActor->GetZAxisActor2D());
1739 else if (aReader.name() == "Trihedron") {
1740 if ( !baseParamsOnly ) {
1741 if (aAttr.value("isShown") == "0")
1742 GetTrihedron()->VisibilityOff();
1744 GetTrihedron()->VisibilityOn();
1745 SetTrihedronSize(aAttr.value("Size").toString().toDouble());
1748 else if (aReader.name() == "Background") {
1749 if ( !baseParamsOnly ) {
1750 setBackground( Qtx::stringToBackground( aAttr.value("Value").toString() ) );
1755 if (!aReader.hasError()) {
1756 vtkCamera* camera = getRenderer()->GetActiveCamera();
1757 camera->SetPosition( pos );
1758 camera->SetFocalPoint( focalPnt );
1759 camera->SetViewUp( viewUp );
1760 camera->SetParallelScale( parScale );
1761 GetRenderer()->SetScale( scale );
1762 //SetScale( scale );
1765 QStringList paramsLst = parameters.split( '*' );
1766 if ( paramsLst.size() >= nNormalParams ) {
1767 // 'reading' list of parameters
1768 pos[0] = paramsLst[0].toDouble();
1769 pos[1] = paramsLst[1].toDouble();
1770 pos[2] = paramsLst[2].toDouble();
1771 focalPnt[0] = paramsLst[3].toDouble();
1772 focalPnt[1] = paramsLst[4].toDouble();
1773 focalPnt[2] = paramsLst[5].toDouble();
1774 viewUp[0] = paramsLst[6].toDouble();
1775 viewUp[1] = paramsLst[7].toDouble();
1776 viewUp[2] = paramsLst[8].toDouble();
1777 parScale = paramsLst[9].toDouble();
1778 scale[0] = paramsLst[10].toDouble();
1779 scale[1] = paramsLst[11].toDouble();
1780 scale[2] = paramsLst[12].toDouble();
1782 // applying parameters
1783 vtkCamera* camera = getRenderer()->GetActiveCamera();
1784 camera->SetPosition( pos );
1785 camera->SetFocalPoint( focalPnt );
1786 camera->SetViewUp( viewUp );
1787 camera->SetParallelScale( parScale );
1788 GetRenderer()->SetScale( scale );
1789 //SetScale( scale );
1791 // apply graduated axes parameters
1792 if ( !baseParamsOnly ) {
1793 SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes();
1794 if ( gradAxesActor && paramsLst.size() == nAllParams ) {
1795 int i = nNormalParams+1, j = i + nGradAxisParams - 1;
1796 ::setGradAxisVisualParams( gradAxesActor->GetXAxisActor2D(), parameters.section( '*', i, j ) );
1797 i = j + 1; j += nGradAxisParams;
1798 ::setGradAxisVisualParams( gradAxesActor->GetYAxisActor2D(), parameters.section( '*', i, j ) );
1799 i = j + 1; j += nGradAxisParams;
1800 ::setGradAxisVisualParams( gradAxesActor->GetZAxisActor2D(), parameters.section( '*', i, j ) );
1802 if ( paramsLst[13].toUShort() )
1803 gradAxesActor->VisibilityOn();
1805 gradAxesActor->VisibilityOff();
1807 else if ( paramsLst.size() == nAllParams ) {
1808 if ( paramsLst[90].toUShort() )
1809 GetTrihedron()->VisibilityOn();
1811 GetTrihedron()->VisibilityOff();
1813 SetTrihedronSize(paramsLst[91].toDouble());
1823 Delayed setVisualParameters
1825 bool SVTK_ViewWindow::eventFilter( QObject* theWatched, QEvent* theEvent )
1827 if ( theEvent->type() == QEvent::Show && theWatched->inherits( "SVTK_RenderWindowInteractor" ) ) {
1828 SVTK_RenderWindowInteractor* anInteractor = (SVTK_RenderWindowInteractor*)theWatched;
1829 if ( anInteractor->isVisible() ) {
1830 doSetVisualParameters( myVisualParams );
1831 anInteractor->removeEventFilter( this ); // theWatched = RenderWindowInteractor
1834 return SUIT_ViewWindow::eventFilter( theWatched, theEvent );
1839 Change rotation point
1841 void SVTK_ViewWindow::onChangeRotationPoint(bool theIsActivate)
1844 mySetRotationPointDlg->addObserver();
1845 if ( mySetRotationPointDlg->IsFirstShown() )
1846 activateSetRotationGravity();
1847 mySetRotationPointDlg->show();
1849 mySetRotationPointDlg->hide();
1853 Set the gravity center as a rotation point
1855 void SVTK_ViewWindow::activateSetRotationGravity()
1857 myEventDispatcher->InvokeEvent(SVTK::SetRotateGravity,0);
1861 Set the selected point as a rotation point
1863 void SVTK_ViewWindow::activateSetRotationSelected(void* theData)
1865 myEventDispatcher->InvokeEvent(SVTK::ChangeRotationPoint,theData);
1869 Set the gravity center of element selected by user as a rotation point
1871 void SVTK_ViewWindow::activateStartPointSelection( Selection_Mode theSelectionMode )
1873 SetSelectionMode( theSelectionMode );
1874 myEventDispatcher->InvokeEvent(SVTK::StartPointSelection,0);
1878 Set the view projection mode: orthogonal or perspective
1880 void SVTK_ViewWindow::onPerspectiveMode()
1882 bool anIsParallelMode = toolMgr()->action( ParallelModeId )->isChecked();
1884 // advanced zooming is not available in perspective mode
1885 if( QtxAction* anAction = getAction( SwitchZoomingStyleId ) )
1886 anAction->setEnabled( anIsParallelMode );
1888 vtkCamera* aCamera = getRenderer()->GetActiveCamera();
1889 aCamera->SetParallelProjection(anIsParallelMode);
1890 GetInteractor()->GetDevice()->CreateTimer(VTKI_TIMER_FIRST);
1892 emit transformed( this );
1895 void SVTK_ViewWindow::SetEventDispatcher(vtkObject* theDispatcher)
1897 myEventDispatcher = theDispatcher;
1901 Creates all actions of svtk main window
1903 void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
1905 QtxAction* anAction;
1906 QtxActionToolMgr* mgr = toolMgr();
1909 anAction = new QtxAction(tr("MNU_DUMP_VIEW"),
1910 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
1911 tr( "MNU_DUMP_VIEW" ), 0, this);
1912 anAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1913 connect(anAction, SIGNAL(activated()), this, SLOT(onDumpView()));
1914 mgr->registerAction( anAction, DumpId );
1917 anAction = new QtxAction(tr("MNU_FITALL"),
1918 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
1919 tr( "MNU_FITALL" ), 0, this);
1920 anAction->setStatusTip(tr("DSC_FITALL"));
1921 connect(anAction, SIGNAL(activated()), this, SLOT(onFitAll()));
1922 mgr->registerAction( anAction, FitAllId );
1925 anAction = new QtxAction(tr("MNU_FITRECT"),
1926 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
1927 tr( "MNU_FITRECT" ), 0, this);
1928 anAction->setStatusTip(tr("DSC_FITRECT"));
1929 connect(anAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
1930 mgr->registerAction( anAction, FitRectId );
1933 anAction = new QtxAction(tr("MNU_ZOOM_VIEW"),
1934 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
1935 tr( "MNU_ZOOM_VIEW" ), 0, this);
1936 anAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1937 connect(anAction, SIGNAL(activated()), this, SLOT(activateZoom()));
1938 mgr->registerAction( anAction, ZoomId );
1941 anAction = new QtxAction(tr("MNU_PAN_VIEW"),
1942 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
1943 tr( "MNU_PAN_VIEW" ), 0, this);
1944 anAction->setStatusTip(tr("DSC_PAN_VIEW"));
1945 connect(anAction, SIGNAL(activated()), this, SLOT(activatePanning()));
1946 mgr->registerAction( anAction, PanId );
1949 anAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"),
1950 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
1951 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1952 anAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1953 connect(anAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
1954 mgr->registerAction( anAction, GlobalPanId );
1956 // Change rotation point
1957 anAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"),
1958 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_ROTATION_POINT" ) ),
1959 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1960 anAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1961 anAction->setCheckable(true);
1962 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onChangeRotationPoint(bool)));
1963 mgr->registerAction( anAction, ChangeRotationPointId );
1966 anAction = new QtxAction(tr("MNU_ROTATE_VIEW"),
1967 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
1968 tr( "MNU_ROTATE_VIEW" ), 0, this);
1969 anAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1970 connect(anAction, SIGNAL(activated()), this, SLOT(activateRotation()));
1971 mgr->registerAction( anAction, RotationId );
1974 anAction = new QtxAction(tr("MNU_FRONT_VIEW"),
1975 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
1976 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1977 anAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1978 connect(anAction, SIGNAL(activated()), this, SLOT(onFrontView()));
1979 this->addAction(anAction);
1980 mgr->registerAction( anAction, FrontId );
1982 anAction = new QtxAction(tr("MNU_BACK_VIEW"),
1983 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
1984 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1985 anAction->setStatusTip(tr("DSC_BACK_VIEW"));
1986 connect(anAction, SIGNAL(activated()), this, SLOT(onBackView()));
1987 this->addAction(anAction);
1988 mgr->registerAction( anAction, BackId );
1990 anAction = new QtxAction(tr("MNU_TOP_VIEW"),
1991 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
1992 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1993 anAction->setStatusTip(tr("DSC_TOP_VIEW"));
1994 connect(anAction, SIGNAL(activated()), this, SLOT(onTopView()));
1995 this->addAction(anAction);
1996 mgr->registerAction( anAction, TopId );
1998 anAction = new QtxAction(tr("MNU_BOTTOM_VIEW"),
1999 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
2000 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
2001 anAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
2002 connect(anAction, SIGNAL(activated()), this, SLOT(onBottomView()));
2003 this->addAction(anAction);
2004 mgr->registerAction( anAction, BottomId );
2006 anAction = new QtxAction(tr("MNU_LEFT_VIEW"),
2007 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
2008 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
2009 anAction->setStatusTip(tr("DSC_LEFT_VIEW"));
2010 connect(anAction, SIGNAL(activated()), this, SLOT(onLeftView()));
2011 this->addAction(anAction);
2012 mgr->registerAction( anAction, LeftId );
2014 anAction = new QtxAction(tr("MNU_RIGHT_VIEW"),
2015 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
2016 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
2017 anAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
2018 connect(anAction, SIGNAL(activated()), this, SLOT(onRightView()));
2019 this->addAction(anAction);
2020 mgr->registerAction( anAction, RightId );
2022 // rotate anticlockwise
2023 anAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"),
2024 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ANTICLOCKWISE" ) ),
2025 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
2026 anAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
2027 connect(anAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
2028 this->addAction(anAction);
2029 mgr->registerAction( anAction, AntiClockWiseId );
2032 anAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"),
2033 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_CLOCKWISE" ) ),
2034 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
2035 anAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
2036 connect(anAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
2037 this->addAction(anAction);
2038 mgr->registerAction( anAction, ClockWiseId );
2041 anAction = new QtxAction(tr("MNU_RESET_VIEW"),
2042 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
2043 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
2044 anAction->setStatusTip(tr("DSC_RESET_VIEW"));
2045 connect(anAction, SIGNAL(activated()), this, SLOT(onResetView()));
2046 this->addAction(anAction);
2047 mgr->registerAction( anAction, ResetId );
2049 // onViewTrihedron: Shows - Hides Trihedron
2050 anAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"),
2051 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ),
2052 tr( "MNU_SHOW_TRIHEDRON" ), 0, this);
2053 anAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON"));
2054 connect(anAction, SIGNAL(activated()), this, SLOT(onViewTrihedron()));
2055 mgr->registerAction( anAction, ViewTrihedronId );
2057 // onNonIsometric: Manage non-isometric params
2058 anAction = new QtxAction(tr("MNU_SVTK_SCALING"),
2059 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SCALING" ) ),
2060 tr( "MNU_SVTK_SCALING" ), 0, this);
2061 anAction->setStatusTip(tr("DSC_SVTK_SCALING"));
2062 anAction->setCheckable(true);
2063 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onNonIsometric(bool)));
2064 mgr->registerAction( anAction, NonIsometric );
2066 // onGraduatedAxes: Manage graduated axes params
2067 anAction = new QtxAction(tr("MNU_SVTK_GRADUATED_AXES"),
2068 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_GRADUATED_AXES" ) ),
2069 tr( "MNU_SVTK_GRADUATED_AXES" ), 0, this);
2070 anAction->setStatusTip(tr("DSC_SVTK_GRADUATED_AXES"));
2071 anAction->setCheckable(true);
2072 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onGraduatedAxes(bool)));
2073 mgr->registerAction( anAction, GraduatedAxes );
2075 // onGraduatedAxes: Manage graduated axes params
2076 anAction = new QtxAction(tr("MNU_SVTK_UPDATE_RATE"),
2077 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_UPDATE_RATE" ) ),
2078 tr( "MNU_SVTK_UPDATE_RATE" ), 0, this);
2079 anAction->setStatusTip(tr("DSC_SVTK_UPDATE_RATE"));
2080 anAction->setCheckable(true);
2081 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onUpdateRate(bool)));
2082 mgr->registerAction( anAction, UpdateRate );
2084 // Set perspective mode group
2085 anAction = new QtxAction(tr("MNU_SVTK_PARALLEL_MODE"),
2086 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARALLEL" ) ),
2087 tr( "MNU_SVTK_PARALLEL_MODE" ), 0, this);
2088 anAction->setStatusTip(tr("DSC_SVTK_PARALLEL_MODE"));
2089 anAction->setCheckable(true);
2090 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onPerspectiveMode()));
2091 mgr->registerAction( anAction, ParallelModeId );
2093 anAction = new QtxAction(tr("MNU_SVTK_PERSPECTIVE_MODE"),
2094 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PERSPECTIVE" ) ),
2095 tr( "MNU_SVTK_PERSPECTIVE_MODE" ), 0, this);
2096 anAction->setStatusTip(tr("DSC_SVTK_PERSPECTIVE_MODE"));
2097 anAction->setCheckable(true);
2098 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onPerspectiveMode()));
2099 mgr->registerAction( anAction, ProjectionModeId );
2101 QActionGroup* aPerspectiveGroup = new QActionGroup( this );
2102 aPerspectiveGroup->addAction( mgr->action( ParallelModeId ) );
2103 aPerspectiveGroup->addAction( mgr->action( ProjectionModeId ) );
2106 anAction = new QtxAction(tr("MNU_VIEWPARAMETERS_VIEW"),
2107 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARAMETERS" ) ),
2108 tr( "MNU_VIEWPARAMETERS_VIEW" ), 0, this);
2109 anAction->setStatusTip(tr("DSC_VIEWPARAMETERS_VIEW"));
2110 anAction->setCheckable(true);
2111 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onViewParameters(bool)));
2112 mgr->registerAction( anAction, ViewParametersId );
2115 mgr->registerAction( synchronizeAction(), SynchronizeId );
2117 // Switch between interaction styles
2118 anAction = new QtxAction(tr("MNU_SVTK_STYLE_SWITCH"),
2119 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_STYLE_SWITCH" ) ),
2120 tr( "MNU_SVTK_STYLE_SWITCH" ), 0, this);
2121 anAction->setStatusTip(tr("DSC_SVTK_STYLE_SWITCH"));
2122 anAction->setCheckable(true);
2123 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
2124 mgr->registerAction( anAction, SwitchInteractionStyleId );
2126 // Switch between zooming styles
2127 anAction = new QtxAction(tr("MNU_SVTK_ZOOMING_STYLE_SWITCH"),
2128 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_ZOOMING_STYLE_SWITCH" ) ),
2129 tr( "MNU_SVTK_ZOOMING_STYLE_SWITCH" ), 0, this);
2130 anAction->setStatusTip(tr("DSC_SVTK_ZOOMING_STYLE_SWITCH"));
2131 anAction->setCheckable(true);
2132 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
2133 mgr->registerAction( anAction, SwitchZoomingStyleId );
2136 QSignalMapper* aSignalMapper = new QSignalMapper( this );
2137 connect(aSignalMapper, SIGNAL(mapped(int)), this, SLOT(onSwitchPreSelectionMode(int)));
2139 anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_STANDARD"),
2140 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_STANDARD" ) ),
2141 tr( "MNU_SVTK_PRESELECTION_STANDARD" ), 0, this);
2142 anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_STANDARD"));
2143 anAction->setCheckable(true);
2144 connect(anAction, SIGNAL(activated()), aSignalMapper, SLOT(map()));
2145 aSignalMapper->setMapping( anAction, Standard_Preselection );
2146 mgr->registerAction( anAction, StandardPreselectionId );
2148 anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_DYNAMIC"),
2149 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_DYNAMIC" ) ),
2150 tr( "MNU_SVTK_PRESELECTION_DYNAMIC" ), 0, this);
2151 anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_DYNAMIC"));
2152 anAction->setCheckable(true);
2153 connect(anAction, SIGNAL(activated()), aSignalMapper, SLOT(map()));
2154 aSignalMapper->setMapping( anAction, Dynamic_Preselection );
2155 mgr->registerAction( anAction, DynamicPreselectionId );
2157 anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_DISABLED"),
2158 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_DISABLED" ) ),
2159 tr( "MNU_SVTK_PRESELECTION_DISABLED" ), 0, this);
2160 anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_DISABLED"));
2161 anAction->setCheckable(true);
2162 connect(anAction, SIGNAL(activated()), aSignalMapper, SLOT(map()));
2163 aSignalMapper->setMapping( anAction, Preselection_Disabled );
2164 mgr->registerAction( anAction, DisablePreselectionId );
2166 QtxActionGroup* aPreselectionAction = new QtxActionGroup( this, true );
2167 aPreselectionAction->add( getAction( StandardPreselectionId ) );
2168 aPreselectionAction->add( getAction( DynamicPreselectionId ) );
2169 aPreselectionAction->add( getAction( DisablePreselectionId ) );
2170 mgr->registerAction( aPreselectionAction, PreselectionId );
2173 anAction = new QtxAction(tr("MNU_SVTK_ENABLE_SELECTION"),
2174 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SELECTION" ) ),
2175 tr( "MNU_SVTK_ENABLE_SELECTION" ), 0, this);
2176 anAction->setStatusTip(tr("DSC_SVTK_ENABLE_SELECTION"));
2177 anAction->setCheckable(true);
2178 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onEnableSelection(bool)));
2179 mgr->registerAction( anAction, EnableSelectionId );
2182 myStartAction = new QtxAction(tr("MNU_SVTK_RECORDING_START"),
2183 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_START" ) ),
2184 tr( "MNU_SVTK_RECORDING_START" ), 0, this);
2185 myStartAction->setStatusTip(tr("DSC_SVTK_RECORDING_START"));
2186 connect( myStartAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStartRecording() ) );
2187 mgr->registerAction( myStartAction, StartRecordingId );
2190 myPlayAction = new QtxAction(tr("MNU_SVTK_RECORDING_PLAY"),
2191 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PLAY" ) ),
2192 tr( "MNU_SVTK_RECORDING_PLAY" ), 0, this);
2193 myPlayAction->setStatusTip(tr("DSC_SVTK_RECORDING_PLAY"));
2194 myPlayAction->setEnabled( false );
2195 connect( myPlayAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPlayRecording() ) );
2196 mgr->registerAction( myPlayAction, PlayRecordingId );
2199 myPauseAction = new QtxAction(tr("MNU_SVTK_RECORDING_PAUSE"),
2200 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PAUSE" ) ),
2201 tr( "MNU_SVTK_RECORDING_PAUSE" ), 0, this);
2202 myPauseAction->setStatusTip(tr("DSC_SVTK_RECORDING_PAUSE"));
2203 myPauseAction->setEnabled( false );
2204 connect( myPauseAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPauseRecording() ) );
2205 mgr->registerAction( myPauseAction, PauseRecordingId );
2208 myStopAction = new QtxAction(tr("MNU_SVTK_RECORDING_STOP"),
2209 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_STOP" ) ),
2210 tr( "MNU_SVTK_RECORDING_STOP" ), 0, this);
2211 myStopAction->setStatusTip(tr("DSC_SVTK_RECORDING_STOP"));
2212 myStopAction->setEnabled( false );
2213 connect( myStopAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStopRecording() ) );
2214 mgr->registerAction( myStopAction, StopRecordingId );
2218 Creates toolbar of svtk main window
2220 void SVTK_ViewWindow::createToolBar()
2222 QtxActionToolMgr* mgr = toolMgr();
2224 mgr->append( DumpId, myToolBar );
2225 mgr->append( SwitchInteractionStyleId, myToolBar );
2226 mgr->append( SwitchZoomingStyleId, myToolBar );
2228 mgr->append( mgr->separator(), myToolBar );
2230 mgr->append( PreselectionId, myToolBar );
2231 mgr->append( EnableSelectionId, myToolBar );
2233 mgr->append( mgr->separator(), myToolBar );
2235 mgr->append( ViewTrihedronId, myToolBar );
2237 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
2238 aScaleAction->insertAction( getAction( FitAllId ) );
2239 aScaleAction->insertAction( getAction( FitRectId ) );
2240 aScaleAction->insertAction( getAction( ZoomId ) );
2241 mgr->append( aScaleAction, myToolBar );
2243 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
2244 aPanningAction->insertAction( getAction( PanId ) );
2245 aPanningAction->insertAction( getAction( GlobalPanId ) );
2246 mgr->append( aPanningAction, myToolBar );
2248 mgr->append( ChangeRotationPointId, myToolBar );
2250 mgr->append( RotationId, myToolBar );
2252 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
2253 aViewsAction->insertAction( getAction( FrontId ) );
2254 aViewsAction->insertAction( getAction( BackId ) );
2255 aViewsAction->insertAction( getAction( TopId ) );
2256 aViewsAction->insertAction( getAction( BottomId ) );
2257 aViewsAction->insertAction( getAction( LeftId ) );
2258 aViewsAction->insertAction( getAction( RightId ) );
2259 mgr->append( aViewsAction, myToolBar );
2261 mgr->append( AntiClockWiseId, myToolBar );
2262 mgr->append( ClockWiseId, myToolBar );
2264 mgr->append( ResetId, myToolBar );
2266 mgr->append( UpdateRate, myToolBar );
2267 mgr->append( NonIsometric, myToolBar );
2268 mgr->append( GraduatedAxes, myToolBar );
2270 mgr->append( ViewParametersId, myToolBar );
2271 mgr->append( SynchronizeId, myToolBar );
2273 mgr->append( toolMgr()->separator(), myToolBar );
2275 mgr->append( ParallelModeId, myToolBar );
2276 mgr->append( ProjectionModeId, myToolBar );
2278 mgr->append( StartRecordingId, myRecordingToolBar );
2279 mgr->append( PlayRecordingId, myRecordingToolBar );
2280 mgr->append( PauseRecordingId, myRecordingToolBar );
2281 mgr->append( StopRecordingId, myRecordingToolBar );
2284 void SVTK_ViewWindow::onUpdateRate(bool theIsActivate)
2287 myUpdateRateDlg->Update();
2288 myUpdateRateDlg->show();
2290 myUpdateRateDlg->hide();
2293 void SVTK_ViewWindow::onNonIsometric(bool theIsActivate)
2296 myNonIsometricDlg->Update();
2297 myNonIsometricDlg->show();
2299 myNonIsometricDlg->hide();
2302 void SVTK_ViewWindow::onGraduatedAxes(bool theIsActivate)
2305 myCubeAxesDlg->Update();
2306 myCubeAxesDlg->show();
2308 myCubeAxesDlg->hide();
2312 Starts rotation transformation
2314 void SVTK_ViewWindow::activateRotation()
2316 myEventDispatcher->InvokeEvent(SVTK::StartRotate,0);
2321 Starts panning transformation
2323 void SVTK_ViewWindow::activatePanning()
2325 myEventDispatcher->InvokeEvent(SVTK::StartPan,0);
2329 Starts zoom transformation
2331 void SVTK_ViewWindow::activateZoom()
2333 myEventDispatcher->InvokeEvent(SVTK::StartZoom,0);
2337 Starts window fit transformation
2339 void SVTK_ViewWindow::activateWindowFit()
2341 myEventDispatcher->InvokeEvent(SVTK::StartFitArea,0);
2345 Starts global panning transformation
2347 void SVTK_ViewWindow::activateGlobalPanning()
2349 myEventDispatcher->InvokeEvent(SVTK::StartGlobalPan,0);
2352 void SVTK_ViewWindow::onStartRecording()
2354 myRecorder->CheckExistAVIMaker();
2355 if (myRecorder->ErrorStatus()) {
2356 SUIT_MessageBox::warning(this, tr("ERROR"), tr("MSG_NO_AVI_MAKER") );
2359 SVTK_RecorderDlg* aRecorderDlg = new SVTK_RecorderDlg( this, myRecorder );
2361 if( !aRecorderDlg->exec() )
2364 myStartAction->setEnabled( false );
2365 myPlayAction->setEnabled( false );
2366 myPauseAction->setEnabled( true );
2367 myStopAction->setEnabled( true );
2369 // to prevent resizing the window while recording
2370 myPreRecordingMinSize = minimumSize();
2371 myPreRecordingMaxSize = maximumSize();
2372 setFixedSize( size() );
2374 myRecorder->Record();
2378 void SVTK_ViewWindow::onPlayRecording()
2380 myStartAction->setEnabled( false );
2381 myPlayAction->setEnabled( false );
2382 myPauseAction->setEnabled( true );
2383 myStopAction->setEnabled( true );
2385 myRecorder->Pause();
2388 void SVTK_ViewWindow::onPauseRecording()
2390 myStartAction->setEnabled( false );
2391 myPlayAction->setEnabled( true );
2392 myPauseAction->setEnabled( false );
2393 myStopAction->setEnabled( true );
2395 myRecorder->Pause();
2398 void SVTK_ViewWindow::onStopRecording()
2400 myStartAction->setEnabled( true );
2401 myPlayAction->setEnabled( false );
2402 myPauseAction->setEnabled( false );
2403 myStopAction->setEnabled( false );
2407 setMinimumSize( myPreRecordingMinSize );
2408 setMaximumSize( myPreRecordingMaxSize );
2412 To invoke a VTK event on SVTK_RenderWindowInteractor instance
2414 void SVTK_ViewWindow::InvokeEvent(unsigned long theEvent, void* theCallData)
2416 GetInteractor()->InvokeEvent(theEvent,theCallData);
2420 Modify view parameters
2422 void SVTK_ViewWindow::onViewParameters(bool theIsActivate)
2425 myViewParameterDlg->addObserver();
2426 myViewParameterDlg->show();
2428 myViewParameterDlg->hide();
2432 Custom show event handler
2434 void SVTK_ViewWindow::showEvent( QShowEvent * theEvent )
2436 emit Show( theEvent );
2440 Custom hide event handler
2442 void SVTK_ViewWindow::hideEvent( QHideEvent * theEvent )
2444 emit Hide( theEvent );
2448 Emit transformed signal.
2450 void SVTK_ViewWindow::emitTransformed() {
2457 void SVTK_ViewWindow::ProcessEvents(vtkObject* vtkNotUsed(theObject),
2458 unsigned long theEvent,
2459 void* theClientData,
2462 SVTK_ViewWindow* self = reinterpret_cast<SVTK_ViewWindow*>(theClientData);
2464 self->emitTransformed();
2468 Get camera properties for the SVTK view window.
2469 \return shared pointer on camera properties.
2471 SUIT_CameraProperties SVTK_ViewWindow::cameraProperties()
2473 SUIT_CameraProperties aProps;
2476 vtkCamera* aCamera = getRenderer()->GetActiveCamera();
2480 aProps.setDimension( SUIT_CameraProperties::Dim3D );
2481 if ( toolMgr()->action( ParallelModeId ) ) {
2482 if ( toolMgr()->action( ParallelModeId )->isChecked() )
2483 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
2485 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
2488 double aFocalPoint[3];
2489 double aPosition[3];
2491 double anAxialScale[3];
2493 aCamera->OrthogonalizeViewUp();
2494 aCamera->GetFocalPoint( aFocalPoint );
2495 aCamera->GetPosition( aPosition );
2496 aCamera->GetViewUp( aViewUp );
2498 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2499 aProps.setPosition( aPosition[0], aPosition[1], aPosition[2] );
2500 aProps.setViewUp( aViewUp[0], aViewUp[1], aViewUp[2] );
2501 aProps.setMappingScale( aCamera->GetParallelScale() * 2.0 );
2503 if ( aProps.getProjection() == SUIT_CameraProperties::PrjPerspective )
2505 aProps.setViewAngle( aCamera->GetViewAngle() );
2508 GetRenderer()->GetScale( anAxialScale );
2509 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2516 This implementation synchronizes camera propreties.
2518 void SVTK_ViewWindow::synchronize( SUIT_ViewWindow* theView )
2520 bool blocked = blockSignals( true );
2522 SUIT_CameraProperties aProps = theView->cameraProperties();
2523 if ( !cameraProperties().isCompatible( aProps ) ) {
2524 // other view, this one is being currently synchronized to, seems has become incompatible
2525 // we have to break synchronization
2531 vtkCamera* aCamera = getRenderer()->GetActiveCamera();
2533 double aFocalPoint[3];
2534 double aPosition[3];
2536 double anAxialScale[3];
2538 // get common properties
2539 aProps.getViewUp( aViewUp[0], aViewUp[1], aViewUp[2] );
2540 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
2541 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2542 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2544 // restore properties to the camera
2545 aCamera->SetViewUp( aViewUp );
2546 aCamera->SetPosition( aPosition );
2547 aCamera->SetFocalPoint( aFocalPoint );
2548 aCamera->SetParallelScale( aProps.getMappingScale() / 2.0 );
2550 if ( aProps.getProjection() == SUIT_CameraProperties::PrjPerspective )
2552 aCamera->SetViewAngle( aProps.getViewAngle() );
2555 GetRenderer()->SetScale( anAxialScale );
2557 getRenderer()->ResetCameraClippingRange();
2560 blockSignals( blocked );