1 // Copyright (C) 2007-2013 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.
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)
151 myInteractor = new SVTK_RenderWindowInteractor(this,"SVTK_RenderWindowInteractor");
153 SVTK_Selector* aSelector = SVTK_Selector::New();
154 int aPreselectionMode = SUIT_Session::session()->resourceMgr()->
155 integerValue( "VTKViewer", "preselection", Standard_Preselection );
156 aSelector->SetDynamicPreSelection( aPreselectionMode == Dynamic_Preselection );
157 aSelector->SetPreSelectionEnabled( aPreselectionMode != Preselection_Disabled );
158 bool isSelectionEnabled = SUIT_Session::session()->resourceMgr()->
159 booleanValue( "VTKViewer", "enable_selection", true );
160 aSelector->SetSelectionEnabled( isSelectionEnabled );
162 SVTK_GenericRenderWindowInteractor* aDevice = SVTK_GenericRenderWindowInteractor::New();
163 aDevice->SetRenderWidget(myInteractor);
164 aDevice->SetSelector(aSelector);
166 SVTK_Renderer* aRenderer = SVTK_Renderer::New();
167 aRenderer->Initialize(aDevice,aSelector);
169 myInteractor->Initialize(aDevice,aRenderer,aSelector);
175 myToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_LABEL"), false, Qt::AllToolBarAreas, -1, this );
176 myRecordingToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_RECORD_LABEL"), false, Qt::AllToolBarAreas, -1, this );
178 createActions( SUIT_Session::session()->resourceMgr() );
181 SetEventDispatcher(myInteractor->GetDevice());
182 myInteractor->setBackgroundRole( QPalette::NoRole );//NoBackground
183 myInteractor->setFocusPolicy(Qt::StrongFocus);
184 myInteractor->setFocus();
185 setFocusProxy(myInteractor);
187 myUpdateRateDlg = new SVTK_UpdateRateDlg( getAction( UpdateRate ), this, "SVTK_UpdateRateDlg" );
188 myNonIsometricDlg = new SVTK_NonIsometricDlg( getAction( NonIsometric ), this, "SVTK_NonIsometricDlg" );
189 myCubeAxesDlg = new SVTK_CubeAxesDlg( getAction( GraduatedAxes ), this, "SVTK_CubeAxesDlg" );
190 myCubeAxesDlg->initialize();
191 mySetRotationPointDlg = new SVTK_SetRotationPointDlg
192 ( getAction( ChangeRotationPointId ), this, "SVTK_SetRotationPointDlg" );
193 myViewParameterDlg = new SVTK_ViewParameterDlg
194 ( getAction( ViewParametersId ), this, "SVTK_ViewParameterDlg" );
196 myDefaultInteractorStyle = SVTK_InteractorStyle::New();
197 myInteractor->PushInteractorStyle(myDefaultInteractorStyle);
198 myDefaultInteractorStyle->Delete();
200 myRecorder = SVTK_Recorder::New();
202 myRecorder->SetNbFPS( 17.3 );
203 myRecorder->SetQuality( 100 );
204 myRecorder->SetProgressiveMode( true );
205 myRecorder->SetUseSkippedFrames( true );
206 myRecorder->SetRenderWindow( myInteractor->getRenderWindow() );
208 setCentralWidget(myInteractor);
210 myAxesWidget = vtkPVAxesWidget::New();
211 myAxesWidget->SetParentRenderer(aRenderer->GetDevice());
212 myAxesWidget->SetViewport(0, 0, 0.25, 0.25);
213 myAxesWidget->SetInteractor(myInteractor->GetDevice());
214 myAxesWidget->SetEnabled(1);
215 myAxesWidget->SetInteractive(0);
217 vtkPVAxesActor* anAxesActor = myAxesWidget->GetAxesActor();
218 anAxesActor->GetXAxisTipProperty()->SetColor( 1.0, 0.0, 0.0 );
219 anAxesActor->GetXAxisShaftProperty()->SetColor( 1.0, 0.0, 0.0 );
220 anAxesActor->GetXAxisLabelProperty()->SetColor( 1.0, 0.0, 0.0 );
221 anAxesActor->GetYAxisTipProperty()->SetColor( 0.0, 1.0, 0.0 );
222 anAxesActor->GetYAxisShaftProperty()->SetColor( 0.0, 1.0, 0.0 );
223 anAxesActor->GetYAxisLabelProperty()->SetColor( 0.0, 1.0, 0.0 );
224 anAxesActor->GetZAxisTipProperty()->SetColor( 0.0, 0.0, 1.0 );
225 anAxesActor->GetZAxisShaftProperty()->SetColor( 0.0, 0.0, 1.0 );
226 anAxesActor->GetZAxisLabelProperty()->SetColor( 0.0, 0.0, 1.0 );
228 myView = new SVTK_View(this);
229 Initialize(myView,theModel);
232 myEventCallbackCommand->SetClientData(this);
233 myEventCallbackCommand->SetCallback(SVTK_ViewWindow::ProcessEvents);
234 myEventCallbackCommand->Delete();
236 GetInteractor()->GetInteractorStyle()->AddObserver(SVTK::OperationFinished,
237 myEventCallbackCommand.GetPointer(), 0.0);
238 myKeyFreeInteractorStyle->AddObserver(SVTK::OperationFinished,
239 myEventCallbackCommand.GetPointer(), 0.0);
243 myInteractor->getRenderWindow()->Render();
244 setBackground( Qtx::BackgroundData( Qt::black ) ); // set default background
249 To initialize #SVTK_ViewWindow instance
251 void SVTK_ViewWindow::Initialize(SVTK_View* theView,
252 SVTK_ViewModelBase* theModel)
254 connect(theView,SIGNAL(KeyPressed(QKeyEvent*)),
255 this,SLOT(onKeyPressed(QKeyEvent*)) );
256 connect(theView,SIGNAL(KeyReleased(QKeyEvent*)),
257 this,SLOT(onKeyReleased(QKeyEvent*)));
258 connect(theView,SIGNAL(MouseButtonPressed(QMouseEvent*)),
259 this,SLOT(onMousePressed(QMouseEvent*)));
260 connect(theView,SIGNAL(MouseButtonReleased(QMouseEvent*)),
261 this,SLOT(onMouseReleased(QMouseEvent*)));
262 connect(theView,SIGNAL(MouseDoubleClicked(QMouseEvent*)),
263 this,SLOT(onMouseDoubleClicked(QMouseEvent*)));
264 connect(theView,SIGNAL(MouseMove(QMouseEvent*)),
265 this,SLOT(onMouseMoving(QMouseEvent*)));
266 connect(theView,SIGNAL(contextMenuRequested(QContextMenuEvent*)),
267 this,SIGNAL(contextMenuRequested(QContextMenuEvent *)));
268 connect(theView,SIGNAL(selectionChanged()),
269 theModel,SLOT(onSelectionChanged()));
271 connect( this, SIGNAL( transformed( SVTK_ViewWindow* ) ), SLOT( emitViewModified() ) );
277 SVTK_ViewWindow::~SVTK_ViewWindow()
279 myRecorder->Delete();
280 myAxesWidget->Delete();
285 \return corresponding view
287 SVTK_View* SVTK_ViewWindow::getView()
293 \return corresponding vtk render window
295 vtkRenderWindow* SVTK_ViewWindow::getRenderWindow()
297 return GetInteractor()->getRenderWindow();
301 \return corresponding vtk render window interactor
303 SVTK_RenderWindowInteractor* SVTK_ViewWindow::GetInteractor() const
309 \return corresponding vtk render window interactor
311 vtkRenderWindowInteractor* SVTK_ViewWindow::getInteractor() const
313 return myInteractor->GetDevice();
317 \return corresponding vtk renderer
319 vtkRenderer* SVTK_ViewWindow::getRenderer() const
321 return GetInteractor()->getRenderer();
325 Redirect the request to SVTK_RenderWindowInteractor::GetRenderer
327 SVTK_Renderer* SVTK_ViewWindow::GetRenderer() const
329 return GetInteractor()->GetRenderer();
333 \return corresponding vtk selector
335 SVTK_Selector* SVTK_ViewWindow::GetSelector() const
337 return GetInteractor()->GetSelector();
341 Processes transformation "front view"
343 void SVTK_ViewWindow::onFrontView()
345 GetRenderer()->OnFrontView();
347 emit transformed( this );
351 Processes transformation "back view"
353 void SVTK_ViewWindow::onBackView()
355 GetRenderer()->OnBackView();
357 emit transformed( this );
361 Processes transformation "top view"
363 void SVTK_ViewWindow::onTopView()
365 GetRenderer()->OnTopView();
367 emit transformed( this );
371 Processes transformation "bottom view"
373 void SVTK_ViewWindow::onBottomView()
375 GetRenderer()->OnBottomView();
377 emit transformed( this );
381 Processes transformation "left view"
383 void SVTK_ViewWindow::onLeftView()
385 GetRenderer()->OnLeftView();
387 emit transformed( this );
391 Processes transformation "right view"
393 void SVTK_ViewWindow::onRightView()
395 GetRenderer()->OnRightView();
397 emit transformed( this );
401 \brief Rotate view 90 degrees clockwise
403 void SVTK_ViewWindow::onClockWiseView()
405 GetRenderer()->onClockWiseView();
407 emit transformed( this );
411 \brief Rotate view 90 degrees conterclockwise
413 void SVTK_ViewWindow::onAntiClockWiseView()
415 GetRenderer()->onAntiClockWiseView();
417 emit transformed( this );
421 Processes transformation "reset view": sets default orientation of viewport camera
423 void SVTK_ViewWindow::onResetView()
425 GetRenderer()->OnResetView();
427 emit transformed( this );
431 Processes transformation "fit all"
433 void SVTK_ViewWindow::onFitAll()
435 GetRenderer()->OnFitAll();
437 emit transformed( this );
441 SLOT: called if selection is changed
443 void SVTK_ViewWindow::onSelectionChanged()
445 myView->onSelectionChanged();
449 Change selection mode
450 \param theMode - new selection mode
452 void SVTK_ViewWindow::SetSelectionMode(Selection_Mode theMode)
454 GetSelector()->SetSelectionMode(theMode);
458 \return selection mode
460 Selection_Mode SVTK_ViewWindow::SelectionMode() const
462 return GetSelector()->SelectionMode();
466 Unhilights all objects in viewer
468 void SVTK_ViewWindow::unHighlightAll()
470 myView->unHighlightAll();
474 Hilights/unhilights object in viewer
475 \param theIO - object to be updated
476 \param theIsHighlight - if it is true, object will be hilighted, otherwise it will be unhilighted
477 \param theIsUpdate - update current viewer
479 void SVTK_ViewWindow::highlight(const Handle(SALOME_InteractiveObject)& theIO,
483 myView->highlight( theIO, theIsHighlight, theIsUpdate );
487 \return true if object is in viewer or in collector
488 \param theIO - object to be checked
490 bool SVTK_ViewWindow::isInViewer( const Handle(SALOME_InteractiveObject)& theIO )
492 return myView->isInViewer( theIO );
496 \return true if object is displayed in viewer
497 \param theIO - object to be checked
499 bool SVTK_ViewWindow::isVisible( const Handle(SALOME_InteractiveObject)& theIO )
501 return myView->isVisible( theIO );
506 \param theEntry - entry that corresponds to intractive objects
508 Handle(SALOME_InteractiveObject) SVTK_ViewWindow::FindIObject(const char* theEntry)
510 return myView->FindIObject(theEntry);
515 \param theIO - object
516 \param theImmediatly - update viewer
518 void SVTK_ViewWindow::Display(const Handle(SALOME_InteractiveObject)& theIO,
521 myView->Display(theIO,theImmediatly);
526 \param theIO - object
527 \param theImmediatly - update viewer
529 void SVTK_ViewWindow::Erase(const Handle(SALOME_InteractiveObject)& theIO,
532 myView->Erase(theIO,theImmediatly);
536 Display only passed object
537 \param theIO - object
539 void SVTK_ViewWindow::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIO)
541 myView->DisplayOnly(theIO);
545 Display all objects in view
547 void SVTK_ViewWindow::DisplayAll()
549 myView->DisplayAll();
553 Erase all objects in view
555 void SVTK_ViewWindow::EraseAll()
561 Sets background color [obsolete]
562 \param color - new background color
564 void SVTK_ViewWindow::setBackgroundColor( const QColor& c )
566 Qtx::BackgroundData bg = background();
572 \return background color of viewer [obsolete]
574 QColor SVTK_ViewWindow::backgroundColor() const
576 return background().color();
581 \param bgData - new background data
583 void SVTK_ViewWindow::setBackground( const Qtx::BackgroundData& bgData )
587 if ( bgData.isValid() ) {
588 switch ( bgData.mode() ) {
589 case Qtx::ColorBackground:
591 QColor c = bgData.color();
593 // show solid-colored background
594 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
595 getRenderer()->SetGradientBackground( false ); // cancel gradient mode
596 getRenderer()->SetBackground( c.red()/255.0,
598 c.blue()/255.0 ); // set background color
603 case Qtx::SimpleGradientBackground:
606 int type = bgData.gradient( c1, c2 );
612 // show two-color gradient background
613 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
614 getRenderer()->SetGradientBackground( true ); // switch to gradient mode
616 VTKViewer_OpenGLRenderer* aRenderer =
617 VTKViewer_OpenGLRenderer::SafeDownCast( getRenderer() );
620 aRenderer->SetGradientType( type );
621 aRenderer->SetBackground( c1.redF(), c1.greenF(), c1.blueF() );
622 aRenderer->SetBackground2( c2.redF(), c2.greenF(), c2.blueF() );
628 case Qtx::CustomGradientBackground:
630 // NOT IMPLEMENTED YET
631 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
632 getRenderer()->SetGradientBackground( false ); // cancel gradient mode
639 if ( bgData.isTextureShown() ) {
641 int textureMode = bgData.texture( fileName );
642 QFileInfo fi( fileName );
643 if ( !fileName.isEmpty() && fi.exists() ) {
644 // read texture from file
645 QString extension = fi.suffix().toLower();
646 vtkImageReader2* aReader = 0;
647 if ( extension == "jpg" || extension == "jpeg" )
648 aReader = vtkJPEGReader::New();
649 else if ( extension == "bmp" )
650 aReader = vtkBMPReader::New();
651 else if ( extension == "tif" || extension == "tiff" )
652 aReader = vtkTIFFReader::New();
653 else if ( extension == "png" )
654 aReader = vtkPNGReader::New();
655 else if ( extension == "mhd" || extension == "mha" )
656 aReader = vtkMetaImageReader::New();
659 aReader->SetFileName( fi.absoluteFilePath().toLatin1().constData() );
661 VTKViewer_Texture* aTexture = VTKViewer_Texture::New();
662 vtkImageMapToColors* aMap = 0;
663 vtkAlgorithmOutput* anOutput;
665 // special processing for BMP reader
666 vtkBMPReader* aBMPReader = (vtkBMPReader*)aReader;
668 // Special processing for BMP file
669 aBMPReader->SetAllow8BitBMP(1);
671 aMap = vtkImageMapToColors::New();
672 aMap->SetInputConnection( aBMPReader->GetOutputPort() );
673 aMap->SetLookupTable( (vtkScalarsToColors*)aBMPReader->GetLookupTable() );
674 aMap->SetOutputFormatToRGB();
676 anOutput = aMap->GetOutputPort();
681 anOutput = aReader->GetOutputPort( 0 );
682 aTexture->SetInputConnection( anOutput );
684 // VSR: Currently, VTK only supports Stretch mode, so below code will give
685 // the same results for all modes
686 switch ( textureMode ) {
687 case Qtx::TileTexture:
688 aTexture->SetPosition((int)VTKViewer_Texture::Tiled);
690 case Qtx::StretchTexture:
691 aTexture->SetPosition((int)VTKViewer_Texture::Stretched);
693 case Qtx::CenterTexture:
694 aTexture->SetPosition((int)VTKViewer_Texture::Centered);
698 // show textured background
699 getRenderer()->SetTexturedBackground( true );
700 getRenderer()->SetBackgroundTexture( aTexture );
702 // clean-up resources
713 myBackground = bgData;
717 \return background data of viewer
719 Qtx::BackgroundData SVTK_ViewWindow::background() const
726 Redirect the request to SVTK_RenderWindowInteractor::GetInteractorStyle
728 vtkInteractorStyle* SVTK_ViewWindow::GetInteractorStyle() const
730 return GetInteractor()->GetInteractorStyle();
734 Redirect the request to SVTK_RenderWindowInteractor::PushInteractorStyle
736 void SVTK_ViewWindow::PushInteractorStyle(vtkInteractorStyle* theStyle)
738 GetInteractor()->PushInteractorStyle(theStyle);
742 Redirect the request to SVTK_RenderWindowInteractor::PopInteractorStyle
744 void SVTK_ViewWindow::PopInteractorStyle()
746 GetInteractor()->PopInteractorStyle();
750 Updates current viewer
752 void SVTK_ViewWindow::Repaint(bool theUpdateTrihedron)
754 if(theUpdateTrihedron)
755 GetRenderer()->OnAdjustTrihedron();
757 GetInteractor()->update();
759 SVTK_InteractorStyle* aStyle = (SVTK_InteractorStyle*)getInteractor()->GetInteractorStyle();
765 Redirect the request to #SVTK_Renderer::GetScale
767 void SVTK_ViewWindow::GetScale( double theScale[3] )
769 GetRenderer()->GetScale( theScale );
773 Redirect the request to #SVTK_Renderer::SetScale
775 void SVTK_ViewWindow::SetScale( double theScale[3] )
777 GetRenderer()->SetScale( theScale );
779 emit transformed( this );
783 Redirect the request to #SVTK_Renderer::IsTrihedronDisplayed
785 bool SVTK_ViewWindow::isTrihedronDisplayed()
787 return GetRenderer()->IsTrihedronDisplayed();
791 Redirect the request to #SVTK_Renderer::IsCubeAxesDisplayed
793 bool SVTK_ViewWindow::isCubeAxesDisplayed()
795 return GetRenderer()->IsCubeAxesDisplayed();
799 Redirect the request to #SVTK_Renderer::OnViewTrihedron
801 void SVTK_ViewWindow::onViewTrihedron()
803 GetRenderer()->OnViewTrihedron();
808 Redirect the request to #SVTK_Renderer::OnViewCubeAxes
810 void SVTK_ViewWindow::onViewCubeAxes()
812 GetRenderer()->OnViewCubeAxes();
817 Redirect the request to #SVTK_Renderer::GetTrihedron
819 VTKViewer_Trihedron* SVTK_ViewWindow::GetTrihedron()
821 return GetRenderer()->GetTrihedron();
825 Redirect the request to #SVTK_Renderer::GetCubeAxes
827 SVTK_CubeAxesActor2D* SVTK_ViewWindow::GetCubeAxes()
829 return GetRenderer()->GetCubeAxes();
833 \return trihedron size
835 double SVTK_ViewWindow::GetTrihedronSize() const
837 return GetRenderer()->GetTrihedronSize();
842 \param theMode - projection mode ( 0 - orthogonal, 1 - perspective )
844 void SVTK_ViewWindow::SetProjectionMode(const int theMode)
846 activateProjectionMode( theMode );
851 Set the gravity center as a focal point
853 void SVTK_ViewWindow::activateSetFocalPointGravity()
855 myEventDispatcher->InvokeEvent(SVTK::SetFocalPointGravity, 0);
859 Set the selected point as a focal point
861 void SVTK_ViewWindow::activateSetFocalPointSelected()
863 myEventDispatcher->InvokeEvent(SVTK::SetFocalPointSelected, 0);
867 Set the point selected by user as a focal point
869 void SVTK_ViewWindow::activateStartFocalPointSelection()
871 myEventDispatcher->InvokeEvent(SVTK::StartFocalPointSelection,0);
874 void SVTK_ViewWindow::activateProjectionMode(int theMode)
877 toolMgr()->action( ProjectionModeId )->setChecked( true );
879 toolMgr()->action( ParallelModeId )->setChecked( true );
883 Sets actual interaction style
884 \param theStyle - type of interaction style ( 0 - standard, 1 - keyboard free )
886 void SVTK_ViewWindow::SetInteractionStyle(const int theStyle)
888 onSwitchInteractionStyle( theStyle==1 );
892 Sets actual zooming style
893 \param theStyle - type of zooming style ( 0 - standard, 1 - advanced (at cursor) )
895 void SVTK_ViewWindow::SetZoomingStyle(const int theStyle)
897 onSwitchZoomingStyle( theStyle==1 );
901 Set preselection mode.
902 \param theMode the mode to set (standard, dynamic or disabled)
904 void SVTK_ViewWindow::SetPreSelectionMode( Preselection_Mode theMode )
906 onSwitchPreSelectionMode( theMode );
910 Enables/disables selection.
911 \param theEnable if true - selection will be enabled
913 void SVTK_ViewWindow::SetSelectionEnabled( bool theEnable )
915 onEnableSelection( theEnable );
919 Switches "keyboard free" interaction style on/off
921 void SVTK_ViewWindow::onSwitchInteractionStyle(bool theOn)
924 // check if style is already set
925 if ( GetInteractorStyle() != myKeyFreeInteractorStyle.GetPointer() )
927 // keep the same style extensions
928 SVTK_InteractorStyle* aStyle = (SVTK_InteractorStyle*)GetInteractorStyle();
930 myKeyFreeInteractorStyle->SetControllerIncrement(aStyle->ControllerIncrement());
931 myKeyFreeInteractorStyle->SetControllerOnKeyDown(aStyle->ControllerOnKeyDown());
934 PushInteractorStyle(myKeyFreeInteractorStyle.GetPointer());
938 // pop only key free style
939 if ( GetInteractorStyle() == myKeyFreeInteractorStyle.GetPointer() )
940 PopInteractorStyle();
943 // update action state if method is called outside
944 QtxAction* a = getAction( SwitchInteractionStyleId );
945 if ( a->isChecked() != theOn ) a->setChecked( theOn );
949 Toogles advanced zooming style (relatively to the cursor position) on/off
951 void SVTK_ViewWindow::onSwitchZoomingStyle( bool theOn )
953 if( myDefaultInteractorStyle.GetPointer() )
954 myDefaultInteractorStyle->SetAdvancedZoomingEnabled( theOn );
955 if( myKeyFreeInteractorStyle.GetPointer() )
956 myKeyFreeInteractorStyle->SetAdvancedZoomingEnabled( theOn );
958 // update action state if method is called outside
959 QtxAction* a = getAction( SwitchZoomingStyleId );
960 if ( a->isChecked() != theOn )
961 a->setChecked( theOn );
965 Switch preselection mode.
966 \param theMode the preselection mode
968 void SVTK_ViewWindow::onSwitchPreSelectionMode( int theMode )
970 GetSelector()->SetDynamicPreSelection( theMode == Dynamic_Preselection );
971 GetSelector()->SetPreSelectionEnabled( theMode != Preselection_Disabled );
973 // update action state if method is called outside
974 QtxAction* a = getAction( StandardPreselectionId + theMode );
975 if ( a && !a->isChecked() )
976 a->setChecked( true );
980 Enables/disables selection.
981 \param theOn if true - selection will be enabled
983 void SVTK_ViewWindow::onEnableSelection( bool on )
985 GetSelector()->SetSelectionEnabled( on );
987 // update action state if method is called outside
988 QtxAction* a = getAction( EnableSelectionId );
989 if ( a->isChecked() != on )
991 QtxActionGroup* aPreselectionGroup =
992 dynamic_cast<QtxActionGroup*>( getAction( PreselectionId ) );
993 if ( aPreselectionGroup )
994 aPreselectionGroup->setEnabled( on );
998 Sets incremental speed
999 \param theValue - new incremental speed
1000 \param theMode - modification mode
1002 void SVTK_ViewWindow::SetIncrementalSpeed(const int theValue, const int theMode)
1004 if ( (SVTK_InteractorStyle*)GetInteractorStyle() )
1005 ((SVTK_InteractorStyle*)GetInteractorStyle())->SetIncrementSpeed(theValue, theMode);
1009 Sets spacemouse buttons for the functions
1010 \param theBtn1 - spacemouse button for the "decrease speed increment"
1011 \param theBtn2 - spacemouse button for the "increase speed increment"
1012 \param theBtn3 - spacemouse button for the "dominant combined switch"
1014 void SVTK_ViewWindow::SetSpacemouseButtons(const int theBtn1,
1019 myEventDispatcher->InvokeEvent(SVTK::SetSMDecreaseSpeedEvent, &val);
1021 myEventDispatcher->InvokeEvent(SVTK::SetSMIncreaseSpeedEvent, &val);
1023 myEventDispatcher->InvokeEvent(SVTK::SetSMDominantCombinedSwitchEvent, &val);
1028 \param theSize - new trihedron size
1029 \param theRelative - trihedron relativeness
1031 void SVTK_ViewWindow::SetTrihedronSize(const double theSize, const bool theRelative)
1033 GetRenderer()->SetTrihedronSize(theSize, theRelative);
1037 /*! If parameter theIsForcedUpdate is true, recalculate parameters for
1038 * trihedron and cube axes, even if trihedron and cube axes is invisible.
1040 void SVTK_ViewWindow::AdjustTrihedrons(const bool theIsForcedUpdate)
1042 GetRenderer()->AdjustActors();
1047 Redirect the request to #SVTK_Renderer::OnAdjustTrihedron
1049 void SVTK_ViewWindow::onAdjustTrihedron()
1051 GetRenderer()->OnAdjustTrihedron();
1055 Redirect the request to #SVTK_Renderer::OnAdjustCubeAxes
1057 void SVTK_ViewWindow::onAdjustCubeAxes()
1059 GetRenderer()->OnAdjustCubeAxes();
1062 void SVTK_ViewWindow::synchronize(SVTK_ViewWindow* otherViewWindow )
1064 if ( otherViewWindow ) {
1065 bool blocked = blockSignals( true );
1066 doSetVisualParameters( otherViewWindow->getVisualParameters(), true );
1067 blockSignals( blocked );
1074 void SVTK_ViewWindow::onKeyPressed(QKeyEvent* event)
1076 emit keyPressed( this, event );
1082 void SVTK_ViewWindow::onKeyReleased(QKeyEvent* event)
1084 emit keyReleased( this, event );
1090 void SVTK_ViewWindow::onMousePressed(QMouseEvent* event)
1092 emit mousePressed(this, event);
1096 Emits mouse released
1098 void SVTK_ViewWindow::onMouseReleased(QMouseEvent* event)
1100 emit mouseReleased( this, event );
1106 void SVTK_ViewWindow::onMouseMoving(QMouseEvent* event)
1108 emit mouseMoving( this, event );
1112 Emits mouse double clicked
1114 void SVTK_ViewWindow::onMouseDoubleClicked( QMouseEvent* event )
1116 emit mouseDoubleClicked( this, event );
1120 Redirect the request to #SVTK_Renderer::AddActor
1122 void SVTK_ViewWindow::AddActor( VTKViewer_Actor* theActor,
1124 bool theIsAdjustActors )
1126 GetRenderer()->AddActor(theActor, theIsAdjustActors);
1129 emit actorAdded(theActor);
1133 Redirect the request to #SVTK_Renderer::RemoveActor
1135 void SVTK_ViewWindow::RemoveActor( VTKViewer_Actor* theActor,
1137 bool theIsAdjustActors )
1139 GetRenderer()->RemoveActor(theActor, theIsAdjustActors);
1140 if ( myDefaultInteractorStyle )
1141 myDefaultInteractorStyle->FreeActors();
1142 if ( myKeyFreeInteractorStyle )
1143 myKeyFreeInteractorStyle->FreeActors();
1146 emit actorRemoved(theActor);
1149 QImage SVTK_ViewWindow::dumpViewContent()
1151 vtkRenderWindow* aWindow = getRenderWindow();
1152 int* aSize = aWindow->GetSize();
1153 int aWidth = aSize[0];
1154 int aHeight = aSize[1];
1156 OpenGLUtils_FrameBuffer aFrameBuffer;
1157 if( aFrameBuffer.init( aWidth, aHeight ) )
1159 glPushAttrib( GL_VIEWPORT_BIT );
1160 glViewport( 0, 0, aWidth, aHeight );
1161 aFrameBuffer.bind();
1166 aFrameBuffer.unbind();
1169 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
1171 aFrameBuffer.bind();
1172 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
1173 aFrameBuffer.unbind();
1175 anImage = anImage.rgbSwapped();
1176 anImage = anImage.mirrored();
1180 // if frame buffers are unsupported, use old functionality
1181 unsigned char *aData =
1182 aWindow->GetRGBACharPixelData( 0, 0, aWidth-1, aHeight-1, 0 );
1184 QImage anImage( aData, aWidth, aHeight, QImage::Format_ARGB32 );
1186 anImage = anImage.rgbSwapped();
1187 anImage = anImage.mirrored();
1192 \return QImage, containing all scene rendering in window
1194 QImage SVTK_ViewWindow::dumpView()
1196 if( myDumpImage.isNull() )
1197 return dumpViewContent();
1203 QString SVTK_ViewWindow::filter() const
1205 return tr( "SVTK_IMAGE_FILES" );
1208 bool SVTK_ViewWindow::dumpViewToFormat( const QImage& img, const QString& fileName, const QString& format )
1210 if ( format != "PS" && format != "EPS" && format != "PDF" )
1211 return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
1213 SUIT_OverrideCursor wc;
1215 vtkGL2PSExporter *anExporter = vtkGL2PSExporter::New();
1216 anExporter->SetRenderWindow(getRenderWindow());
1218 if ( format == "PS" ) {
1219 anExporter->SetFileFormatToPS();
1220 anExporter->CompressOff();
1223 if ( format == "EPS" ) {
1224 anExporter->SetFileFormatToEPS();
1225 anExporter->CompressOff();
1228 if ( format == "PDF" ) {
1229 anExporter->SetFileFormatToPDF();
1232 QString aFilePrefix(fileName);
1233 QString anExtension(SUIT_Tools::extension(fileName));
1234 aFilePrefix.truncate(aFilePrefix.length() - 1 - anExtension.length());
1235 anExporter->SetFilePrefix(aFilePrefix.toLatin1().data());
1236 anExporter->Write();
1237 anExporter->Delete();
1243 \refresh QImage, containing all scene rendering in window
1245 void SVTK_ViewWindow::RefreshDumpImage()
1247 myDumpImage = dumpViewContent();
1251 Redirect the request to #SVTK_Renderer::SetSelectionProp
1253 void SVTK_ViewWindow::SetSelectionProp(const double& theRed,
1254 const double& theGreen,
1255 const double& theBlue,
1256 const int& theWidth)
1258 myView->SetSelectionProp(theRed,theGreen,theBlue,theWidth);
1262 Redirect the request to #SVTK_Renderer::SetSelectionProp
1264 void SVTK_ViewWindow::SetPreselectionProp(const double& theRed,
1265 const double& theGreen,
1266 const double& theBlue,
1267 const int& theWidth)
1269 myView->SetPreselectionProp(theRed,theGreen,theBlue,theWidth);
1273 Redirect the request to #SVTK_Renderer::SetSelectionTolerance
1275 void SVTK_ViewWindow::SetSelectionTolerance(const double& theTolNodes,
1276 const double& theTolItems,
1277 const double& theTolObjects)
1279 myView->SetSelectionTolerance(theTolNodes, theTolItems, theTolObjects);
1283 Get visibility status of the static trihedron
1285 bool SVTK_ViewWindow::IsStaticTrihedronVisible() const
1287 return (bool)myAxesWidget->GetEnabled();
1291 Set visibility status of the static trihedron
1293 void SVTK_ViewWindow::SetStaticTrihedronVisible( const bool theIsVisible )
1295 myAxesWidget->SetEnabled( (int)theIsVisible );
1300 \param accelAction - action
1302 bool SVTK_ViewWindow::action( const int accelAction )
1304 if ( accelAction == SUIT_Accel::ZoomFit )
1307 int anEvent = SVTK::convertAction( accelAction );
1308 GetInteractor()->InvokeEvent(anEvent, 0);
1314 \return action by it's id
1316 QtxAction* SVTK_ViewWindow::getAction( int id ) const
1318 return dynamic_cast<QtxAction*>( toolMgr()->action( id ) );
1322 // old visual parameters had 13 values. New format added additional
1323 // 76 values for graduated axes, so both numbers are processed.
1324 const int nNormalParams = 13; // number of view windows parameters excluding graduated axes params
1325 const int nGradAxisParams = 25; // number of parameters of ONE graduated axis (X, Y, or Z)
1326 const int nTrihedronParams = 3; // number of parameters for Trihedron
1327 const int nAllParams = nNormalParams + 3*nGradAxisParams + nTrihedronParams + 1; // number of all visual parameters
1329 /*! The method returns visual parameters of a graduated axis actor (x,y,z axis of graduated axes)
1331 void getGradAxisVisualParams( QXmlStreamWriter& writer, vtkAxisActor2D* actor, QString theAxis )
1338 bool isVisible = actor->GetTitleVisibility();
1339 QString title ( actor->GetTitle() );
1341 int font = VTK_ARIAL;
1346 vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1349 txtProp->GetColor( color );
1350 font = txtProp->GetFontFamily();
1351 bold = txtProp->GetBold();
1352 italic = txtProp->GetItalic();
1353 shadow = txtProp->GetShadow();
1355 writer.writeStartElement("GraduatedAxis");
1356 writer.writeAttribute("Axis", theAxis);
1358 writer.writeStartElement("Title");
1359 writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1360 writer.writeAttribute("Text", title);
1361 writer.writeAttribute("Font", QString("%1").arg(font));
1362 writer.writeAttribute("Bold", QString("%1").arg(bold));
1363 writer.writeAttribute("Italic", QString("%1").arg(italic));
1364 writer.writeAttribute("Shadow", QString("%1").arg(shadow));
1366 writer.writeStartElement("Color");
1367 writer.writeAttribute("R", QString("%1").arg(color[0]));
1368 writer.writeAttribute("G", QString("%1").arg(color[1]));
1369 writer.writeAttribute("B", QString("%1").arg(color[2]));
1370 writer.writeEndElement();
1371 writer.writeEndElement();
1373 //params.sprintf( "* Graduated Axis: * Name *%u*%s*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible,
1374 // title.toLatin1().data(), color[0], color[1], color[2], font, bold, italic, shadow );
1377 isVisible = actor->GetLabelVisibility();
1378 int labels = actor->GetNumberOfLabels();
1379 int offset = actor->GetTickOffset();
1385 txtProp = actor->GetLabelTextProperty();
1388 txtProp->GetColor( color );
1389 font = txtProp->GetFontFamily();
1390 bold = txtProp->GetBold();
1391 italic = txtProp->GetItalic();
1392 shadow = txtProp->GetShadow();
1395 writer.writeStartElement("Labels");
1396 writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1397 writer.writeAttribute("Number", QString("%1").arg(labels));
1398 writer.writeAttribute("Offset", QString("%1").arg(offset));
1399 writer.writeAttribute("Font", QString("%1").arg(font));
1400 writer.writeAttribute("Bold", QString("%1").arg(bold));
1401 writer.writeAttribute("Italic", QString("%1").arg(italic));
1402 writer.writeAttribute("Shadow", QString("%1").arg(shadow));
1404 writer.writeStartElement("Color");
1405 writer.writeAttribute("R", QString("%1").arg(color[0]));
1406 writer.writeAttribute("G", QString("%1").arg(color[1]));
1407 writer.writeAttribute("B", QString("%1").arg(color[2]));
1408 writer.writeEndElement();
1409 writer.writeEndElement();
1410 // params += QString().sprintf( "* Labels *%u*%u*%u*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible, labels, offset,
1411 // color[0], color[1], color[2], font, bold, italic, shadow );
1414 isVisible = actor->GetTickVisibility();
1415 int length = actor->GetTickLength();
1416 writer.writeStartElement("TickMarks");
1417 writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1418 writer.writeAttribute("Length", QString("%1").arg(length));
1419 writer.writeEndElement();
1421 //params += QString().sprintf( "* Tick marks *%u*%u", isVisible, length );
1423 writer.writeEndElement();
1427 void setGradAxisVisualParams(QXmlStreamReader& reader, vtkAxisActor2D* actor)
1434 } while (!reader.isStartElement());
1436 // Read title params
1437 QXmlStreamAttributes aAttr = reader.attributes();
1438 bool isVisible = aAttr.value("isVisible").toString().toUShort();
1439 QString title = aAttr.value("Text").toString();
1440 int font = aAttr.value("Font").toString().toInt();
1441 int bold = aAttr.value("Bold").toString().toInt();
1442 int italic = aAttr.value("Italic").toString().toInt();
1443 int shadow = aAttr.value("Shadow").toString().toInt();
1445 //printf("#### TITLE: %i, %s, %i, %i, %i, %i\n", isVisible, qPrintable(title), font, bold, italic, shadow);
1449 } while (!reader.isStartElement());
1452 aAttr = reader.attributes();
1455 color[0] = aAttr.value("R").toString().toDouble();
1456 color[1] = aAttr.value("G").toString().toDouble();
1457 color[2] = aAttr.value("B").toString().toDouble();
1458 //printf("#### Color: %f, %f, %f\n", color[0], color[1], color[2]);
1460 actor->SetTitleVisibility( isVisible );
1461 actor->SetTitle( title.toLatin1() );
1462 vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1464 txtProp->SetColor( color );
1465 txtProp->SetFontFamily( font );
1466 txtProp->SetBold( bold );
1467 txtProp->SetItalic( italic );
1468 txtProp->SetShadow( shadow );
1475 } while (!reader.isStartElement());
1477 aAttr = reader.attributes();
1478 isVisible = aAttr.value("isVisible").toString().toUShort();
1479 int labels = aAttr.value("Number").toString().toInt();
1480 int offset = aAttr.value("Offset").toString().toInt();
1481 font = aAttr.value("Font").toString().toInt();
1482 bold = aAttr.value("Bold").toString().toInt();
1483 italic = aAttr.value("Italic").toString().toInt();
1484 shadow = aAttr.value("Shadow").toString().toInt();
1488 } while (!reader.isStartElement());
1490 aAttr = reader.attributes();
1492 color[0] = aAttr.value("R").toString().toDouble();
1493 color[1] = aAttr.value("G").toString().toDouble();
1494 color[2] = aAttr.value("B").toString().toDouble();
1496 actor->SetLabelVisibility( isVisible );
1497 actor->SetNumberOfLabels( labels );
1498 actor->SetTickOffset( offset );
1499 txtProp = actor->GetLabelTextProperty();
1501 txtProp->SetColor( color );
1502 txtProp->SetFontFamily( font );
1503 txtProp->SetBold( bold );
1504 txtProp->SetItalic( italic );
1505 txtProp->SetShadow( shadow );
1511 } while (!reader.isStartElement());
1512 aAttr = reader.attributes();
1514 // retrieve and set tick marks properties
1515 isVisible = aAttr.value("isVisible").toString().toUShort();
1516 int length = aAttr.value("Length").toString().toInt();
1518 actor->SetTickVisibility( isVisible );
1519 actor->SetTickLength( length );
1522 /*! The method restores visual parameters of a graduated axis actor (x,y,z axis)
1524 void setGradAxisVisualParams( vtkAxisActor2D* actor, const QString& params )
1529 QStringList paramsLst = params.split( '*' );
1531 if ( paramsLst.size() == nGradAxisParams ) { // altogether name, lable, ticks parameters make up 25 values
1533 // retrieve and set name parameters
1534 bool isVisible = paramsLst[2].toUShort();
1535 QString title = paramsLst[3];
1537 color[0] = paramsLst[4].toDouble();
1538 color[1] = paramsLst[5].toDouble();
1539 color[2] = paramsLst[6].toDouble();
1540 int font = paramsLst[7].toInt();
1541 int bold = paramsLst[8].toInt();
1542 int italic = paramsLst[9].toInt();
1543 int shadow = paramsLst[10].toInt();
1545 actor->SetTitleVisibility( isVisible );
1546 actor->SetTitle( title.toLatin1() );
1547 vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1549 txtProp->SetColor( color );
1550 txtProp->SetFontFamily( font );
1551 txtProp->SetBold( bold );
1552 txtProp->SetItalic( italic );
1553 txtProp->SetShadow( shadow );
1556 // retrieve and set lable parameters
1557 isVisible = paramsLst[12].toUShort();
1558 int labels = paramsLst[13].toInt();
1559 int offset = paramsLst[14].toInt();
1560 color[0] = paramsLst[15].toDouble();
1561 color[1] = paramsLst[16].toDouble();
1562 color[2] = paramsLst[17].toDouble();
1563 font = paramsLst[18].toInt();
1564 bold = paramsLst[19].toInt();
1565 italic = paramsLst[20].toInt();
1566 shadow = paramsLst[21].toInt();
1568 actor->SetLabelVisibility( isVisible );
1569 actor->SetNumberOfLabels( labels );
1570 actor->SetTickOffset( offset );
1571 txtProp = actor->GetLabelTextProperty();
1573 txtProp->SetColor( color );
1574 txtProp->SetFontFamily( font );
1575 txtProp->SetBold( bold );
1576 txtProp->SetItalic( italic );
1577 txtProp->SetShadow( shadow );
1580 // retrieve and set tick marks properties
1581 isVisible = paramsLst[23].toUShort();
1582 int length = paramsLst[24].toInt();
1584 actor->SetTickVisibility( isVisible );
1585 actor->SetTickLength( length );
1589 /*! The method returns the visual parameters of this view as a formated string
1591 QString SVTK_ViewWindow::getVisualParameters()
1593 double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
1595 // save position, focal point, viewUp, scale
1596 vtkCamera* camera = getRenderer()->GetActiveCamera();
1597 camera->GetPosition( pos );
1598 camera->GetFocalPoint( focalPnt );
1599 camera->GetViewUp( viewUp );
1600 parScale = camera->GetParallelScale();
1603 // Parameters are given in the following format:view position (3 digits), focal point position (3 digits)
1604 // view up values (3 digits), parallel scale (1 digit), scale (3 digits,
1605 // Graduated axes parameters (X, Y, Z axes parameters)
1607 QXmlStreamWriter aWriter(&retStr);
1608 aWriter.setAutoFormatting(true);
1610 aWriter.writeStartDocument();
1611 aWriter.writeStartElement("ViewState");
1613 aWriter.writeStartElement("Position");
1614 aWriter.writeAttribute("X", QString("%1").arg(pos[0]));
1615 aWriter.writeAttribute("Y", QString("%1").arg(pos[1]));
1616 aWriter.writeAttribute("Z", QString("%1").arg(pos[2]));
1617 aWriter.writeEndElement();
1619 aWriter.writeStartElement("FocalPoint");
1620 aWriter.writeAttribute("X", QString::number(focalPnt[0]));
1621 aWriter.writeAttribute("Y", QString::number(focalPnt[1]));
1622 aWriter.writeAttribute("Z", QString::number(focalPnt[2]));
1623 aWriter.writeEndElement();
1625 aWriter.writeStartElement("ViewUp");
1626 aWriter.writeAttribute("X", QString::number(viewUp[0]));
1627 aWriter.writeAttribute("Y", QString::number(viewUp[1]));
1628 aWriter.writeAttribute("Z", QString::number(viewUp[2]));
1629 aWriter.writeEndElement();
1631 aWriter.writeStartElement("ViewScale");
1632 aWriter.writeAttribute("Parallel", QString::number(parScale));
1633 aWriter.writeAttribute("X", QString::number(scale[0]));
1634 aWriter.writeAttribute("Y", QString::number(scale[1]));
1635 aWriter.writeAttribute("Z", QString::number(scale[2]));
1636 aWriter.writeEndElement();
1638 if ( SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes() ) {
1639 aWriter.writeStartElement("DisplayCubeAxis");
1640 aWriter.writeAttribute("Show", QString( "%1" ).arg( GetRenderer()->IsCubeAxesDisplayed()));
1641 aWriter.writeEndElement();
1643 getGradAxisVisualParams(aWriter, gradAxesActor->GetXAxisActor2D(), "X");
1644 getGradAxisVisualParams(aWriter, gradAxesActor->GetYAxisActor2D(), "Y");
1645 getGradAxisVisualParams(aWriter, gradAxesActor->GetZAxisActor2D(), "Z");
1648 aWriter.writeStartElement("Trihedron");
1649 aWriter.writeAttribute("isShown", QString( "%1" ).arg( isTrihedronDisplayed()));
1650 aWriter.writeAttribute("Size", QString::number(GetTrihedronSize()));
1651 aWriter.writeEndElement();
1653 aWriter.writeStartElement("Background");
1654 aWriter.writeAttribute("Value", QString( "%1" ).arg( Qtx::backgroundToString(background()) ));
1655 aWriter.writeEndElement();
1657 aWriter.writeEndElement();
1658 aWriter.writeEndDocument();
1664 The method restores visual parameters of this view or postpones it untill the view is shown
1666 void SVTK_ViewWindow::setVisualParameters( const QString& parameters )
1668 //printf("#### %s\n", qPrintable(parameters));
1669 SVTK_RenderWindowInteractor* anInteractor = GetInteractor();
1670 if ( anInteractor->isVisible() ) {
1671 doSetVisualParameters( parameters );
1674 myVisualParams = parameters;
1675 anInteractor->installEventFilter(this);
1680 The method restores visual parameters of this view from a formated string
1682 void SVTK_ViewWindow::doSetVisualParameters( const QString& parameters, bool baseParamsOnly )
1685 double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
1687 QXmlStreamReader aReader(parameters);
1688 SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes();
1690 while(!aReader.atEnd()) {
1692 if (aReader.isStartElement()) {
1693 QXmlStreamAttributes aAttr = aReader.attributes();
1694 //printf("### Name = %s\n", qPrintable(aReader.name().toString()));
1695 if (aReader.name() == "Position") {
1696 pos[0] = aAttr.value("X").toString().toDouble();
1697 pos[1] = aAttr.value("Y").toString().toDouble();
1698 pos[2] = aAttr.value("Z").toString().toDouble();
1699 //printf("#### Position %f; %f; %f\n", pos[0], pos[1], pos[2]);
1701 else if (aReader.name() == "FocalPoint") {
1702 focalPnt[0] = aAttr.value("X").toString().toDouble();
1703 focalPnt[1] = aAttr.value("Y").toString().toDouble();
1704 focalPnt[2] = aAttr.value("Z").toString().toDouble();
1705 //printf("#### FocalPoint %f; %f; %f\n", focalPnt[0], focalPnt[1], focalPnt[2]);
1707 else if (aReader.name() == "ViewUp") {
1708 viewUp[0] = aAttr.value("X").toString().toDouble();
1709 viewUp[1] = aAttr.value("Y").toString().toDouble();
1710 viewUp[2] = aAttr.value("Z").toString().toDouble();
1711 //printf("#### ViewUp %f; %f; %f\n", viewUp[0], viewUp[1], viewUp[2]);
1713 else if (aReader.name() == "ViewScale") {
1714 parScale = aAttr.value("Parallel").toString().toDouble();
1715 scale[0] = aAttr.value("X").toString().toDouble();
1716 scale[1] = aAttr.value("Y").toString().toDouble();
1717 scale[2] = aAttr.value("Z").toString().toDouble();
1718 //printf("#### ViewScale %f; %f; %f\n", scale[0], scale[1], scale[2]);
1720 else if (aReader.name() == "DisplayCubeAxis") {
1721 if ( !baseParamsOnly ) {
1722 if (aAttr.value("Show") == "0")
1723 gradAxesActor->VisibilityOff();
1725 gradAxesActor->VisibilityOn();
1728 else if (aReader.name() == "GraduatedAxis") {
1729 if ( !baseParamsOnly ) {
1730 if(aAttr.value("Axis") == "X")
1731 setGradAxisVisualParams(aReader, gradAxesActor->GetXAxisActor2D());
1732 else if(aAttr.value("Axis") == "Y")
1733 setGradAxisVisualParams(aReader, gradAxesActor->GetYAxisActor2D());
1734 else if(aAttr.value("Axis") == "Z")
1735 setGradAxisVisualParams(aReader, gradAxesActor->GetZAxisActor2D());
1738 else if (aReader.name() == "Trihedron") {
1739 if ( !baseParamsOnly ) {
1740 if (aAttr.value("isShown") == "0")
1741 GetTrihedron()->VisibilityOff();
1743 GetTrihedron()->VisibilityOn();
1744 SetTrihedronSize(aAttr.value("Size").toString().toDouble());
1747 else if (aReader.name() == "Background") {
1748 if ( !baseParamsOnly ) {
1749 setBackground( Qtx::stringToBackground( aAttr.value("Value").toString() ) );
1754 if (!aReader.hasError()) {
1755 vtkCamera* camera = getRenderer()->GetActiveCamera();
1756 camera->SetPosition( pos );
1757 camera->SetFocalPoint( focalPnt );
1758 camera->SetViewUp( viewUp );
1759 camera->SetParallelScale( parScale );
1760 GetRenderer()->SetScale( scale );
1761 //SetScale( scale );
1764 QStringList paramsLst = parameters.split( '*' );
1765 if ( paramsLst.size() >= nNormalParams ) {
1766 // 'reading' list of parameters
1767 pos[0] = paramsLst[0].toDouble();
1768 pos[1] = paramsLst[1].toDouble();
1769 pos[2] = paramsLst[2].toDouble();
1770 focalPnt[0] = paramsLst[3].toDouble();
1771 focalPnt[1] = paramsLst[4].toDouble();
1772 focalPnt[2] = paramsLst[5].toDouble();
1773 viewUp[0] = paramsLst[6].toDouble();
1774 viewUp[1] = paramsLst[7].toDouble();
1775 viewUp[2] = paramsLst[8].toDouble();
1776 parScale = paramsLst[9].toDouble();
1777 scale[0] = paramsLst[10].toDouble();
1778 scale[1] = paramsLst[11].toDouble();
1779 scale[2] = paramsLst[12].toDouble();
1781 // applying parameters
1782 vtkCamera* camera = getRenderer()->GetActiveCamera();
1783 camera->SetPosition( pos );
1784 camera->SetFocalPoint( focalPnt );
1785 camera->SetViewUp( viewUp );
1786 camera->SetParallelScale( parScale );
1787 GetRenderer()->SetScale( scale );
1788 //SetScale( scale );
1790 // apply graduated axes parameters
1791 if ( !baseParamsOnly ) {
1792 SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes();
1793 if ( gradAxesActor && paramsLst.size() == nAllParams ) {
1794 int i = nNormalParams+1, j = i + nGradAxisParams - 1;
1795 ::setGradAxisVisualParams( gradAxesActor->GetXAxisActor2D(), parameters.section( '*', i, j ) );
1796 i = j + 1; j += nGradAxisParams;
1797 ::setGradAxisVisualParams( gradAxesActor->GetYAxisActor2D(), parameters.section( '*', i, j ) );
1798 i = j + 1; j += nGradAxisParams;
1799 ::setGradAxisVisualParams( gradAxesActor->GetZAxisActor2D(), parameters.section( '*', i, j ) );
1801 if ( paramsLst[13].toUShort() )
1802 gradAxesActor->VisibilityOn();
1804 gradAxesActor->VisibilityOff();
1806 else if ( paramsLst.size() == nAllParams ) {
1807 if ( paramsLst[90].toUShort() )
1808 GetTrihedron()->VisibilityOn();
1810 GetTrihedron()->VisibilityOff();
1812 SetTrihedronSize(paramsLst[91].toDouble());
1822 Delayed setVisualParameters
1824 bool SVTK_ViewWindow::eventFilter( QObject* theWatched, QEvent* theEvent )
1826 if ( theEvent->type() == QEvent::Show && theWatched->inherits( "SVTK_RenderWindowInteractor" ) ) {
1827 SVTK_RenderWindowInteractor* anInteractor = (SVTK_RenderWindowInteractor*)theWatched;
1828 if ( anInteractor->isVisible() ) {
1829 doSetVisualParameters( myVisualParams );
1830 anInteractor->removeEventFilter( this ); // theWatched = RenderWindowInteractor
1833 return SUIT_ViewWindow::eventFilter( theWatched, theEvent );
1838 Change rotation point
1840 void SVTK_ViewWindow::onChangeRotationPoint(bool theIsActivate)
1843 mySetRotationPointDlg->addObserver();
1844 if ( mySetRotationPointDlg->IsFirstShown() )
1845 activateSetRotationGravity();
1846 mySetRotationPointDlg->show();
1848 mySetRotationPointDlg->hide();
1852 Set the gravity center as a rotation point
1854 void SVTK_ViewWindow::activateSetRotationGravity()
1856 myEventDispatcher->InvokeEvent(SVTK::SetRotateGravity,0);
1860 Set the selected point as a rotation point
1862 void SVTK_ViewWindow::activateSetRotationSelected(void* theData)
1864 myEventDispatcher->InvokeEvent(SVTK::ChangeRotationPoint,theData);
1868 Set the point selected by user as a rotation point
1870 void SVTK_ViewWindow::activateStartPointSelection()
1872 myEventDispatcher->InvokeEvent(SVTK::StartPointSelection,0);
1876 Set the view projection mode: orthogonal or perspective
1878 void SVTK_ViewWindow::onPerspectiveMode()
1880 bool anIsParallelMode = toolMgr()->action( ParallelModeId )->isChecked();
1882 // advanced zooming is not available in perspective mode
1883 if( QtxAction* anAction = getAction( SwitchZoomingStyleId ) )
1884 anAction->setEnabled( anIsParallelMode );
1886 vtkCamera* aCamera = getRenderer()->GetActiveCamera();
1887 aCamera->SetParallelProjection(anIsParallelMode);
1888 GetInteractor()->GetDevice()->CreateTimer(VTKI_TIMER_FIRST);
1890 emit transformed( this );
1893 void SVTK_ViewWindow::SetEventDispatcher(vtkObject* theDispatcher)
1895 myEventDispatcher = theDispatcher;
1899 Creates all actions of svtk main window
1901 void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
1903 QtxAction* anAction;
1904 QtxActionToolMgr* mgr = toolMgr();
1907 anAction = new QtxAction(tr("MNU_DUMP_VIEW"),
1908 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
1909 tr( "MNU_DUMP_VIEW" ), 0, this);
1910 anAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1911 connect(anAction, SIGNAL(activated()), this, SLOT(onDumpView()));
1912 mgr->registerAction( anAction, DumpId );
1915 anAction = new QtxAction(tr("MNU_FITALL"),
1916 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
1917 tr( "MNU_FITALL" ), 0, this);
1918 anAction->setStatusTip(tr("DSC_FITALL"));
1919 connect(anAction, SIGNAL(activated()), this, SLOT(onFitAll()));
1920 mgr->registerAction( anAction, FitAllId );
1923 anAction = new QtxAction(tr("MNU_FITRECT"),
1924 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
1925 tr( "MNU_FITRECT" ), 0, this);
1926 anAction->setStatusTip(tr("DSC_FITRECT"));
1927 connect(anAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
1928 mgr->registerAction( anAction, FitRectId );
1931 anAction = new QtxAction(tr("MNU_ZOOM_VIEW"),
1932 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
1933 tr( "MNU_ZOOM_VIEW" ), 0, this);
1934 anAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1935 connect(anAction, SIGNAL(activated()), this, SLOT(activateZoom()));
1936 mgr->registerAction( anAction, ZoomId );
1939 anAction = new QtxAction(tr("MNU_PAN_VIEW"),
1940 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
1941 tr( "MNU_PAN_VIEW" ), 0, this);
1942 anAction->setStatusTip(tr("DSC_PAN_VIEW"));
1943 connect(anAction, SIGNAL(activated()), this, SLOT(activatePanning()));
1944 mgr->registerAction( anAction, PanId );
1947 anAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"),
1948 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
1949 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1950 anAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1951 connect(anAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
1952 mgr->registerAction( anAction, GlobalPanId );
1954 // Change rotation point
1955 anAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"),
1956 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_ROTATION_POINT" ) ),
1957 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1958 anAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1959 anAction->setCheckable(true);
1960 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onChangeRotationPoint(bool)));
1961 mgr->registerAction( anAction, ChangeRotationPointId );
1964 anAction = new QtxAction(tr("MNU_ROTATE_VIEW"),
1965 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
1966 tr( "MNU_ROTATE_VIEW" ), 0, this);
1967 anAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1968 connect(anAction, SIGNAL(activated()), this, SLOT(activateRotation()));
1969 mgr->registerAction( anAction, RotationId );
1972 anAction = new QtxAction(tr("MNU_FRONT_VIEW"),
1973 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
1974 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1975 anAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1976 connect(anAction, SIGNAL(activated()), this, SLOT(onFrontView()));
1977 this->addAction(anAction);
1978 mgr->registerAction( anAction, FrontId );
1980 anAction = new QtxAction(tr("MNU_BACK_VIEW"),
1981 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
1982 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1983 anAction->setStatusTip(tr("DSC_BACK_VIEW"));
1984 connect(anAction, SIGNAL(activated()), this, SLOT(onBackView()));
1985 this->addAction(anAction);
1986 mgr->registerAction( anAction, BackId );
1988 anAction = new QtxAction(tr("MNU_TOP_VIEW"),
1989 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
1990 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1991 anAction->setStatusTip(tr("DSC_TOP_VIEW"));
1992 connect(anAction, SIGNAL(activated()), this, SLOT(onTopView()));
1993 this->addAction(anAction);
1994 mgr->registerAction( anAction, TopId );
1996 anAction = new QtxAction(tr("MNU_BOTTOM_VIEW"),
1997 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
1998 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1999 anAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
2000 connect(anAction, SIGNAL(activated()), this, SLOT(onBottomView()));
2001 this->addAction(anAction);
2002 mgr->registerAction( anAction, BottomId );
2004 anAction = new QtxAction(tr("MNU_LEFT_VIEW"),
2005 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
2006 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
2007 anAction->setStatusTip(tr("DSC_LEFT_VIEW"));
2008 connect(anAction, SIGNAL(activated()), this, SLOT(onLeftView()));
2009 this->addAction(anAction);
2010 mgr->registerAction( anAction, LeftId );
2012 anAction = new QtxAction(tr("MNU_RIGHT_VIEW"),
2013 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
2014 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
2015 anAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
2016 connect(anAction, SIGNAL(activated()), this, SLOT(onRightView()));
2017 this->addAction(anAction);
2018 mgr->registerAction( anAction, RightId );
2020 // rotate anticlockwise
2021 anAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"),
2022 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ANTICLOCKWISE" ) ),
2023 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
2024 anAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
2025 connect(anAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
2026 this->addAction(anAction);
2027 mgr->registerAction( anAction, AntiClockWiseId );
2030 anAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"),
2031 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_CLOCKWISE" ) ),
2032 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
2033 anAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
2034 connect(anAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
2035 this->addAction(anAction);
2036 mgr->registerAction( anAction, ClockWiseId );
2039 anAction = new QtxAction(tr("MNU_RESET_VIEW"),
2040 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
2041 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
2042 anAction->setStatusTip(tr("DSC_RESET_VIEW"));
2043 connect(anAction, SIGNAL(activated()), this, SLOT(onResetView()));
2044 this->addAction(anAction);
2045 mgr->registerAction( anAction, ResetId );
2047 // onViewTrihedron: Shows - Hides Trihedron
2048 anAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"),
2049 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ),
2050 tr( "MNU_SHOW_TRIHEDRON" ), 0, this);
2051 anAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON"));
2052 connect(anAction, SIGNAL(activated()), this, SLOT(onViewTrihedron()));
2053 mgr->registerAction( anAction, ViewTrihedronId );
2055 // onNonIsometric: Manage non-isometric params
2056 anAction = new QtxAction(tr("MNU_SVTK_SCALING"),
2057 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SCALING" ) ),
2058 tr( "MNU_SVTK_SCALING" ), 0, this);
2059 anAction->setStatusTip(tr("DSC_SVTK_SCALING"));
2060 anAction->setCheckable(true);
2061 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onNonIsometric(bool)));
2062 mgr->registerAction( anAction, NonIsometric );
2064 // onGraduatedAxes: Manage graduated axes params
2065 anAction = new QtxAction(tr("MNU_SVTK_GRADUATED_AXES"),
2066 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_GRADUATED_AXES" ) ),
2067 tr( "MNU_SVTK_GRADUATED_AXES" ), 0, this);
2068 anAction->setStatusTip(tr("DSC_SVTK_GRADUATED_AXES"));
2069 anAction->setCheckable(true);
2070 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onGraduatedAxes(bool)));
2071 mgr->registerAction( anAction, GraduatedAxes );
2073 // onGraduatedAxes: Manage graduated axes params
2074 anAction = new QtxAction(tr("MNU_SVTK_UPDATE_RATE"),
2075 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_UPDATE_RATE" ) ),
2076 tr( "MNU_SVTK_UPDATE_RATE" ), 0, this);
2077 anAction->setStatusTip(tr("DSC_SVTK_UPDATE_RATE"));
2078 anAction->setCheckable(true);
2079 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onUpdateRate(bool)));
2080 mgr->registerAction( anAction, UpdateRate );
2082 // Set perspective mode group
2083 anAction = new QtxAction(tr("MNU_SVTK_PARALLEL_MODE"),
2084 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARALLEL" ) ),
2085 tr( "MNU_SVTK_PARALLEL_MODE" ), 0, this);
2086 anAction->setStatusTip(tr("DSC_SVTK_PARALLEL_MODE"));
2087 anAction->setCheckable(true);
2088 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onPerspectiveMode()));
2089 mgr->registerAction( anAction, ParallelModeId );
2091 anAction = new QtxAction(tr("MNU_SVTK_PERSPECTIVE_MODE"),
2092 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PERSPECTIVE" ) ),
2093 tr( "MNU_SVTK_PERSPECTIVE_MODE" ), 0, this);
2094 anAction->setStatusTip(tr("DSC_SVTK_PERSPECTIVE_MODE"));
2095 anAction->setCheckable(true);
2096 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onPerspectiveMode()));
2097 mgr->registerAction( anAction, ProjectionModeId );
2099 QActionGroup* aPerspectiveGroup = new QActionGroup( this );
2100 aPerspectiveGroup->addAction( mgr->action( ParallelModeId ) );
2101 aPerspectiveGroup->addAction( mgr->action( ProjectionModeId ) );
2104 anAction = new QtxAction(tr("MNU_VIEWPARAMETERS_VIEW"),
2105 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARAMETERS" ) ),
2106 tr( "MNU_VIEWPARAMETERS_VIEW" ), 0, this);
2107 anAction->setStatusTip(tr("DSC_VIEWPARAMETERS_VIEW"));
2108 anAction->setCheckable(true);
2109 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onViewParameters(bool)));
2110 mgr->registerAction( anAction, ViewParametersId );
2113 mgr->registerAction( synchronizeAction(), SynchronizeId );
2115 // Switch between interaction styles
2116 anAction = new QtxAction(tr("MNU_SVTK_STYLE_SWITCH"),
2117 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_STYLE_SWITCH" ) ),
2118 tr( "MNU_SVTK_STYLE_SWITCH" ), 0, this);
2119 anAction->setStatusTip(tr("DSC_SVTK_STYLE_SWITCH"));
2120 anAction->setCheckable(true);
2121 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
2122 mgr->registerAction( anAction, SwitchInteractionStyleId );
2124 // Switch between zooming styles
2125 anAction = new QtxAction(tr("MNU_SVTK_ZOOMING_STYLE_SWITCH"),
2126 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_ZOOMING_STYLE_SWITCH" ) ),
2127 tr( "MNU_SVTK_ZOOMING_STYLE_SWITCH" ), 0, this);
2128 anAction->setStatusTip(tr("DSC_SVTK_ZOOMING_STYLE_SWITCH"));
2129 anAction->setCheckable(true);
2130 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
2131 mgr->registerAction( anAction, SwitchZoomingStyleId );
2134 QSignalMapper* aSignalMapper = new QSignalMapper( this );
2135 connect(aSignalMapper, SIGNAL(mapped(int)), this, SLOT(onSwitchPreSelectionMode(int)));
2137 anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_STANDARD"),
2138 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_STANDARD" ) ),
2139 tr( "MNU_SVTK_PRESELECTION_STANDARD" ), 0, this);
2140 anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_STANDARD"));
2141 anAction->setCheckable(true);
2142 connect(anAction, SIGNAL(activated()), aSignalMapper, SLOT(map()));
2143 aSignalMapper->setMapping( anAction, Standard_Preselection );
2144 mgr->registerAction( anAction, StandardPreselectionId );
2146 anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_DYNAMIC"),
2147 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_DYNAMIC" ) ),
2148 tr( "MNU_SVTK_PRESELECTION_DYNAMIC" ), 0, this);
2149 anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_DYNAMIC"));
2150 anAction->setCheckable(true);
2151 connect(anAction, SIGNAL(activated()), aSignalMapper, SLOT(map()));
2152 aSignalMapper->setMapping( anAction, Dynamic_Preselection );
2153 mgr->registerAction( anAction, DynamicPreselectionId );
2155 anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_DISABLED"),
2156 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_DISABLED" ) ),
2157 tr( "MNU_SVTK_PRESELECTION_DISABLED" ), 0, this);
2158 anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_DISABLED"));
2159 anAction->setCheckable(true);
2160 connect(anAction, SIGNAL(activated()), aSignalMapper, SLOT(map()));
2161 aSignalMapper->setMapping( anAction, Preselection_Disabled );
2162 mgr->registerAction( anAction, DisablePreselectionId );
2164 QtxActionGroup* aPreselectionAction = new QtxActionGroup( this, true );
2165 aPreselectionAction->add( getAction( StandardPreselectionId ) );
2166 aPreselectionAction->add( getAction( DynamicPreselectionId ) );
2167 aPreselectionAction->add( getAction( DisablePreselectionId ) );
2168 mgr->registerAction( aPreselectionAction, PreselectionId );
2171 anAction = new QtxAction(tr("MNU_SVTK_ENABLE_SELECTION"),
2172 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SELECTION" ) ),
2173 tr( "MNU_SVTK_ENABLE_SELECTION" ), 0, this);
2174 anAction->setStatusTip(tr("DSC_SVTK_ENABLE_SELECTION"));
2175 anAction->setCheckable(true);
2176 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onEnableSelection(bool)));
2177 mgr->registerAction( anAction, EnableSelectionId );
2180 myStartAction = new QtxAction(tr("MNU_SVTK_RECORDING_START"),
2181 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_START" ) ),
2182 tr( "MNU_SVTK_RECORDING_START" ), 0, this);
2183 myStartAction->setStatusTip(tr("DSC_SVTK_RECORDING_START"));
2184 connect( myStartAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStartRecording() ) );
2185 mgr->registerAction( myStartAction, StartRecordingId );
2188 myPlayAction = new QtxAction(tr("MNU_SVTK_RECORDING_PLAY"),
2189 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PLAY" ) ),
2190 tr( "MNU_SVTK_RECORDING_PLAY" ), 0, this);
2191 myPlayAction->setStatusTip(tr("DSC_SVTK_RECORDING_PLAY"));
2192 myPlayAction->setEnabled( false );
2193 connect( myPlayAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPlayRecording() ) );
2194 mgr->registerAction( myPlayAction, PlayRecordingId );
2197 myPauseAction = new QtxAction(tr("MNU_SVTK_RECORDING_PAUSE"),
2198 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PAUSE" ) ),
2199 tr( "MNU_SVTK_RECORDING_PAUSE" ), 0, this);
2200 myPauseAction->setStatusTip(tr("DSC_SVTK_RECORDING_PAUSE"));
2201 myPauseAction->setEnabled( false );
2202 connect( myPauseAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPauseRecording() ) );
2203 mgr->registerAction( myPauseAction, PauseRecordingId );
2206 myStopAction = new QtxAction(tr("MNU_SVTK_RECORDING_STOP"),
2207 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_STOP" ) ),
2208 tr( "MNU_SVTK_RECORDING_STOP" ), 0, this);
2209 myStopAction->setStatusTip(tr("DSC_SVTK_RECORDING_STOP"));
2210 myStopAction->setEnabled( false );
2211 connect( myStopAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStopRecording() ) );
2212 mgr->registerAction( myStopAction, StopRecordingId );
2216 Creates toolbar of svtk main window
2218 void SVTK_ViewWindow::createToolBar()
2220 QtxActionToolMgr* mgr = toolMgr();
2222 mgr->append( DumpId, myToolBar );
2223 mgr->append( SwitchInteractionStyleId, myToolBar );
2224 mgr->append( SwitchZoomingStyleId, myToolBar );
2226 mgr->append( mgr->separator(), myToolBar );
2228 mgr->append( PreselectionId, myToolBar );
2229 mgr->append( EnableSelectionId, myToolBar );
2231 mgr->append( mgr->separator(), myToolBar );
2233 mgr->append( ViewTrihedronId, myToolBar );
2235 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
2236 aScaleAction->insertAction( getAction( FitAllId ) );
2237 aScaleAction->insertAction( getAction( FitRectId ) );
2238 aScaleAction->insertAction( getAction( ZoomId ) );
2239 mgr->append( aScaleAction, myToolBar );
2241 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
2242 aPanningAction->insertAction( getAction( PanId ) );
2243 aPanningAction->insertAction( getAction( GlobalPanId ) );
2244 mgr->append( aPanningAction, myToolBar );
2246 mgr->append( ChangeRotationPointId, myToolBar );
2248 mgr->append( RotationId, myToolBar );
2250 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
2251 aViewsAction->insertAction( getAction( FrontId ) );
2252 aViewsAction->insertAction( getAction( BackId ) );
2253 aViewsAction->insertAction( getAction( TopId ) );
2254 aViewsAction->insertAction( getAction( BottomId ) );
2255 aViewsAction->insertAction( getAction( LeftId ) );
2256 aViewsAction->insertAction( getAction( RightId ) );
2257 mgr->append( aViewsAction, myToolBar );
2259 mgr->append( AntiClockWiseId, myToolBar );
2260 mgr->append( ClockWiseId, myToolBar );
2262 mgr->append( ResetId, myToolBar );
2264 mgr->append( UpdateRate, myToolBar );
2265 mgr->append( NonIsometric, myToolBar );
2266 mgr->append( GraduatedAxes, myToolBar );
2268 mgr->append( ViewParametersId, myToolBar );
2269 mgr->append( SynchronizeId, myToolBar );
2271 mgr->append( toolMgr()->separator(), myToolBar );
2273 mgr->append( ParallelModeId, myToolBar );
2274 mgr->append( ProjectionModeId, myToolBar );
2276 mgr->append( StartRecordingId, myRecordingToolBar );
2277 mgr->append( PlayRecordingId, myRecordingToolBar );
2278 mgr->append( PauseRecordingId, myRecordingToolBar );
2279 mgr->append( StopRecordingId, myRecordingToolBar );
2282 void SVTK_ViewWindow::onUpdateRate(bool theIsActivate)
2285 myUpdateRateDlg->Update();
2286 myUpdateRateDlg->show();
2288 myUpdateRateDlg->hide();
2291 void SVTK_ViewWindow::onNonIsometric(bool theIsActivate)
2294 myNonIsometricDlg->Update();
2295 myNonIsometricDlg->show();
2297 myNonIsometricDlg->hide();
2300 void SVTK_ViewWindow::onGraduatedAxes(bool theIsActivate)
2303 myCubeAxesDlg->Update();
2304 myCubeAxesDlg->show();
2306 myCubeAxesDlg->hide();
2310 Starts rotation transformation
2312 void SVTK_ViewWindow::activateRotation()
2314 myEventDispatcher->InvokeEvent(SVTK::StartRotate,0);
2319 Starts panning transformation
2321 void SVTK_ViewWindow::activatePanning()
2323 myEventDispatcher->InvokeEvent(SVTK::StartPan,0);
2327 Starts zoom transformation
2329 void SVTK_ViewWindow::activateZoom()
2331 myEventDispatcher->InvokeEvent(SVTK::StartZoom,0);
2335 Starts window fit transformation
2337 void SVTK_ViewWindow::activateWindowFit()
2339 myEventDispatcher->InvokeEvent(SVTK::StartFitArea,0);
2343 Starts global panning transformation
2345 void SVTK_ViewWindow::activateGlobalPanning()
2347 myEventDispatcher->InvokeEvent(SVTK::StartGlobalPan,0);
2350 void SVTK_ViewWindow::onStartRecording()
2352 myRecorder->CheckExistAVIMaker();
2353 if (myRecorder->ErrorStatus()) {
2354 SUIT_MessageBox::warning(this, tr("ERROR"), tr("MSG_NO_AVI_MAKER") );
2357 SVTK_RecorderDlg* aRecorderDlg = new SVTK_RecorderDlg( this, myRecorder );
2359 if( !aRecorderDlg->exec() )
2362 myStartAction->setEnabled( false );
2363 myPlayAction->setEnabled( false );
2364 myPauseAction->setEnabled( true );
2365 myStopAction->setEnabled( true );
2367 // to prevent resizing the window while recording
2368 myPreRecordingMinSize = minimumSize();
2369 myPreRecordingMaxSize = maximumSize();
2370 setFixedSize( size() );
2372 myRecorder->Record();
2376 void SVTK_ViewWindow::onPlayRecording()
2378 myStartAction->setEnabled( false );
2379 myPlayAction->setEnabled( false );
2380 myPauseAction->setEnabled( true );
2381 myStopAction->setEnabled( true );
2383 myRecorder->Pause();
2386 void SVTK_ViewWindow::onPauseRecording()
2388 myStartAction->setEnabled( false );
2389 myPlayAction->setEnabled( true );
2390 myPauseAction->setEnabled( false );
2391 myStopAction->setEnabled( true );
2393 myRecorder->Pause();
2396 void SVTK_ViewWindow::onStopRecording()
2398 myStartAction->setEnabled( true );
2399 myPlayAction->setEnabled( false );
2400 myPauseAction->setEnabled( false );
2401 myStopAction->setEnabled( false );
2405 setMinimumSize( myPreRecordingMinSize );
2406 setMaximumSize( myPreRecordingMaxSize );
2410 To invoke a VTK event on SVTK_RenderWindowInteractor instance
2412 void SVTK_ViewWindow::InvokeEvent(unsigned long theEvent, void* theCallData)
2414 GetInteractor()->InvokeEvent(theEvent,theCallData);
2418 Modify view parameters
2420 void SVTK_ViewWindow::onViewParameters(bool theIsActivate)
2423 myViewParameterDlg->addObserver();
2424 myViewParameterDlg->show();
2426 myViewParameterDlg->hide();
2430 Custom show event handler
2432 void SVTK_ViewWindow::showEvent( QShowEvent * theEvent )
2434 emit Show( theEvent );
2438 Custom hide event handler
2440 void SVTK_ViewWindow::hideEvent( QHideEvent * theEvent )
2442 emit Hide( theEvent );
2446 Emit transformed signal.
2448 void SVTK_ViewWindow::emitTransformed() {
2455 void SVTK_ViewWindow::ProcessEvents(vtkObject* vtkNotUsed(theObject),
2456 unsigned long theEvent,
2457 void* theClientData,
2460 SVTK_ViewWindow* self = reinterpret_cast<SVTK_ViewWindow*>(theClientData);
2462 self->emitTransformed();
2466 Get camera properties for the SVTK view window.
2467 \return shared pointer on camera properties.
2469 SUIT_CameraProperties SVTK_ViewWindow::cameraProperties()
2471 SUIT_CameraProperties aProps;
2474 vtkCamera* aCamera = getRenderer()->GetActiveCamera();
2478 aProps.setDimension( SUIT_CameraProperties::Dim3D );
2479 if ( toolMgr()->action( ParallelModeId ) ) {
2480 if ( toolMgr()->action( ParallelModeId )->isChecked() )
2481 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
2483 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
2486 double aFocalPoint[3];
2487 double aPosition[3];
2489 double anAxialScale[3];
2491 aCamera->OrthogonalizeViewUp();
2492 aCamera->GetFocalPoint(aFocalPoint);
2493 aCamera->GetPosition(aPosition);
2494 aCamera->GetViewUp(aViewUp);
2496 aProps.setFocalPoint(aFocalPoint[0], aFocalPoint[1], aFocalPoint[2]);
2497 aProps.setPosition(aPosition[0], aPosition[1], aPosition[2]);
2498 aProps.setViewUp(aViewUp[0], aViewUp[1], aViewUp[2]);
2499 aProps.setMappingScale(aCamera->GetParallelScale());
2501 if (aProps.getProjection() == SUIT_CameraProperties::PrjPerspective)
2503 aProps.setViewAngle(aCamera->GetViewAngle());
2506 GetRenderer()->GetScale(anAxialScale);
2507 aProps.setAxialScale(anAxialScale[0], anAxialScale[1], anAxialScale[2]);
2514 This implementation synchronizes camera propreties.
2516 void SVTK_ViewWindow::synchronize( SUIT_ViewWindow* theView )
2518 bool blocked = blockSignals( true );
2520 SUIT_CameraProperties aProps = theView->cameraProperties();
2521 if ( !cameraProperties().isCompatible( aProps ) ) {
2522 // other view, this one is being currently synchronized to, seems has become incompatible
2523 // we have to break synchronization
2529 vtkCamera* aCamera = getRenderer()->GetActiveCamera();
2531 double aFocalPoint[3];
2532 double aPosition[3];
2534 double anAxialScale[3];
2536 // get common properties
2537 aProps.getViewUp(aViewUp[0], aViewUp[1], aViewUp[2]);
2538 aProps.getPosition(aPosition[0], aPosition[1], aPosition[2]);
2539 aProps.getFocalPoint(aFocalPoint[0], aFocalPoint[1], aFocalPoint[2]);
2540 aProps.getAxialScale(anAxialScale[0], anAxialScale[1], anAxialScale[2]);
2542 // restore properties to the camera
2543 aCamera->SetViewUp(aViewUp);
2544 aCamera->SetPosition(aPosition);
2545 aCamera->SetFocalPoint(aFocalPoint);
2546 aCamera->SetParallelScale(aProps.getMappingScale());
2548 if (aProps.getProjection() == SUIT_CameraProperties::PrjPerspective)
2550 aCamera->SetViewAngle(aProps.getViewAngle());
2553 GetRenderer()->SetScale(anAxialScale);
2555 getRenderer()->ResetCameraClippingRange();
2558 blockSignals( blocked );