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"), // title (language-dependant)
177 QString( "VTKViewerViewOperations" ), // name (language-independant)
178 false ); // disable floatable toolbar
180 myRecordingToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_RECORD_LABEL"), // title (language-dependant)
181 QString( "VTKRecordingOperations" ), // name (language-independant)
182 false ); // disable floatable toolbar
184 createActions( SUIT_Session::session()->resourceMgr() );
187 SetEventDispatcher(myInteractor->GetDevice());
188 myInteractor->setBackgroundRole( QPalette::NoRole );//NoBackground
189 myInteractor->setFocusPolicy(Qt::StrongFocus);
190 myInteractor->setFocus();
191 setFocusProxy(myInteractor);
193 myUpdateRateDlg = new SVTK_UpdateRateDlg( getAction( UpdateRate ), this, "SVTK_UpdateRateDlg" );
194 myNonIsometricDlg = new SVTK_NonIsometricDlg( getAction( NonIsometric ), this, "SVTK_NonIsometricDlg" );
195 myCubeAxesDlg = new SVTK_CubeAxesDlg( getAction( GraduatedAxes ), this, "SVTK_CubeAxesDlg" );
196 myCubeAxesDlg->initialize();
197 mySetRotationPointDlg = new SVTK_SetRotationPointDlg
198 ( getAction( ChangeRotationPointId ), this, "SVTK_SetRotationPointDlg" );
199 myViewParameterDlg = new SVTK_ViewParameterDlg
200 ( getAction( ViewParametersId ), this, "SVTK_ViewParameterDlg" );
202 myDefaultInteractorStyle = SVTK_InteractorStyle::New();
203 myInteractor->PushInteractorStyle(myDefaultInteractorStyle);
204 myDefaultInteractorStyle->Delete();
206 myRecorder = SVTK_Recorder::New();
208 myRecorder->SetNbFPS( 17.3 );
209 myRecorder->SetQuality( 100 );
210 myRecorder->SetProgressiveMode( true );
211 myRecorder->SetUseSkippedFrames( true );
212 myRecorder->SetRenderWindow( myInteractor->getRenderWindow() );
214 setCentralWidget(myInteractor);
216 myAxesWidget = vtkPVAxesWidget::New();
217 myAxesWidget->SetParentRenderer(aRenderer->GetDevice());
218 myAxesWidget->SetViewport(0, 0, 0.25, 0.25);
219 myAxesWidget->SetInteractor(myInteractor->GetDevice());
220 myAxesWidget->SetEnabled(1);
221 myAxesWidget->SetInteractive(0);
223 vtkPVAxesActor* anAxesActor = myAxesWidget->GetAxesActor();
224 anAxesActor->GetXAxisTipProperty()->SetColor( 1.0, 0.0, 0.0 );
225 anAxesActor->GetXAxisShaftProperty()->SetColor( 1.0, 0.0, 0.0 );
226 anAxesActor->GetXAxisLabelProperty()->SetColor( 1.0, 0.0, 0.0 );
227 anAxesActor->GetYAxisTipProperty()->SetColor( 0.0, 1.0, 0.0 );
228 anAxesActor->GetYAxisShaftProperty()->SetColor( 0.0, 1.0, 0.0 );
229 anAxesActor->GetYAxisLabelProperty()->SetColor( 0.0, 1.0, 0.0 );
230 anAxesActor->GetZAxisTipProperty()->SetColor( 0.0, 0.0, 1.0 );
231 anAxesActor->GetZAxisShaftProperty()->SetColor( 0.0, 0.0, 1.0 );
232 anAxesActor->GetZAxisLabelProperty()->SetColor( 0.0, 0.0, 1.0 );
234 myView = new SVTK_View(this);
235 Initialize(myView,theModel);
238 myEventCallbackCommand->SetClientData(this);
239 myEventCallbackCommand->SetCallback(SVTK_ViewWindow::ProcessEvents);
240 myEventCallbackCommand->Delete();
242 GetInteractor()->GetInteractorStyle()->AddObserver(SVTK::OperationFinished,
243 myEventCallbackCommand.GetPointer(), 0.0);
244 myKeyFreeInteractorStyle->AddObserver(SVTK::OperationFinished,
245 myEventCallbackCommand.GetPointer(), 0.0);
249 myInteractor->getRenderWindow()->Render();
250 setBackground( Qtx::BackgroundData( Qt::black ) ); // set default background
255 To initialize #SVTK_ViewWindow instance
257 void SVTK_ViewWindow::Initialize(SVTK_View* theView,
258 SVTK_ViewModelBase* theModel)
260 connect(theView,SIGNAL(KeyPressed(QKeyEvent*)),
261 this,SLOT(onKeyPressed(QKeyEvent*)) );
262 connect(theView,SIGNAL(KeyReleased(QKeyEvent*)),
263 this,SLOT(onKeyReleased(QKeyEvent*)));
264 connect(theView,SIGNAL(MouseButtonPressed(QMouseEvent*)),
265 this,SLOT(onMousePressed(QMouseEvent*)));
266 connect(theView,SIGNAL(MouseButtonReleased(QMouseEvent*)),
267 this,SLOT(onMouseReleased(QMouseEvent*)));
268 connect(theView,SIGNAL(MouseDoubleClicked(QMouseEvent*)),
269 this,SLOT(onMouseDoubleClicked(QMouseEvent*)));
270 connect(theView,SIGNAL(MouseMove(QMouseEvent*)),
271 this,SLOT(onMouseMoving(QMouseEvent*)));
272 connect(theView,SIGNAL(contextMenuRequested(QContextMenuEvent*)),
273 this,SIGNAL(contextMenuRequested(QContextMenuEvent *)));
274 connect(theView,SIGNAL(selectionChanged()),
275 theModel,SLOT(onSelectionChanged()));
277 connect( this, SIGNAL( transformed( SVTK_ViewWindow* ) ), SLOT( emitViewModified() ) );
283 SVTK_ViewWindow::~SVTK_ViewWindow()
285 myRecorder->Delete();
286 myAxesWidget->Delete();
291 \return corresponding view
293 SVTK_View* SVTK_ViewWindow::getView()
299 \return corresponding vtk render window
301 vtkRenderWindow* SVTK_ViewWindow::getRenderWindow()
303 return GetInteractor()->getRenderWindow();
307 \return corresponding vtk render window interactor
309 SVTK_RenderWindowInteractor* SVTK_ViewWindow::GetInteractor() const
315 \return corresponding vtk render window interactor
317 vtkRenderWindowInteractor* SVTK_ViewWindow::getInteractor() const
319 return myInteractor->GetDevice();
323 \return corresponding vtk renderer
325 vtkRenderer* SVTK_ViewWindow::getRenderer() const
327 return GetInteractor()->getRenderer();
331 Redirect the request to SVTK_RenderWindowInteractor::GetRenderer
333 SVTK_Renderer* SVTK_ViewWindow::GetRenderer() const
335 return GetInteractor()->GetRenderer();
339 \return corresponding vtk selector
341 SVTK_Selector* SVTK_ViewWindow::GetSelector() const
343 return GetInteractor()->GetSelector();
347 Processes transformation "front view"
349 void SVTK_ViewWindow::onFrontView()
351 GetRenderer()->OnFrontView();
353 emit transformed( this );
357 Processes transformation "back view"
359 void SVTK_ViewWindow::onBackView()
361 GetRenderer()->OnBackView();
363 emit transformed( this );
367 Processes transformation "top view"
369 void SVTK_ViewWindow::onTopView()
371 GetRenderer()->OnTopView();
373 emit transformed( this );
377 Processes transformation "bottom view"
379 void SVTK_ViewWindow::onBottomView()
381 GetRenderer()->OnBottomView();
383 emit transformed( this );
387 Processes transformation "left view"
389 void SVTK_ViewWindow::onLeftView()
391 GetRenderer()->OnLeftView();
393 emit transformed( this );
397 Processes transformation "right view"
399 void SVTK_ViewWindow::onRightView()
401 GetRenderer()->OnRightView();
403 emit transformed( this );
407 \brief Rotate view 90 degrees clockwise
409 void SVTK_ViewWindow::onClockWiseView()
411 GetRenderer()->onClockWiseView();
413 emit transformed( this );
417 \brief Rotate view 90 degrees conterclockwise
419 void SVTK_ViewWindow::onAntiClockWiseView()
421 GetRenderer()->onAntiClockWiseView();
423 emit transformed( this );
427 Processes transformation "reset view": sets default orientation of viewport camera
429 void SVTK_ViewWindow::onResetView()
431 GetRenderer()->OnResetView();
433 emit transformed( this );
437 Processes transformation "fit all"
439 void SVTK_ViewWindow::onFitAll()
441 GetRenderer()->OnFitAll();
443 emit transformed( this );
447 SLOT: called if selection is changed
449 void SVTK_ViewWindow::onSelectionChanged()
451 myView->onSelectionChanged();
455 Change selection mode
456 \param theMode - new selection mode
458 void SVTK_ViewWindow::SetSelectionMode(Selection_Mode theMode)
460 GetSelector()->SetSelectionMode(theMode);
464 \return selection mode
466 Selection_Mode SVTK_ViewWindow::SelectionMode() const
468 return GetSelector()->SelectionMode();
472 Unhilights all objects in viewer
474 void SVTK_ViewWindow::unHighlightAll()
476 myView->unHighlightAll();
480 Hilights/unhilights object in viewer
481 \param theIO - object to be updated
482 \param theIsHighlight - if it is true, object will be hilighted, otherwise it will be unhilighted
483 \param theIsUpdate - update current viewer
485 void SVTK_ViewWindow::highlight(const Handle(SALOME_InteractiveObject)& theIO,
489 myView->highlight( theIO, theIsHighlight, theIsUpdate );
493 \return true if object is in viewer or in collector
494 \param theIO - object to be checked
496 bool SVTK_ViewWindow::isInViewer( const Handle(SALOME_InteractiveObject)& theIO )
498 return myView->isInViewer( theIO );
502 \return true if object is displayed in viewer
503 \param theIO - object to be checked
505 bool SVTK_ViewWindow::isVisible( const Handle(SALOME_InteractiveObject)& theIO )
507 return myView->isVisible( theIO );
512 \param theEntry - entry that corresponds to intractive objects
514 Handle(SALOME_InteractiveObject) SVTK_ViewWindow::FindIObject(const char* theEntry)
516 return myView->FindIObject(theEntry);
521 \param theIO - object
522 \param theImmediatly - update viewer
524 void SVTK_ViewWindow::Display(const Handle(SALOME_InteractiveObject)& theIO,
527 myView->Display(theIO,theImmediatly);
532 \param theIO - object
533 \param theImmediatly - update viewer
535 void SVTK_ViewWindow::Erase(const Handle(SALOME_InteractiveObject)& theIO,
538 myView->Erase(theIO,theImmediatly);
542 Display only passed object
543 \param theIO - object
545 void SVTK_ViewWindow::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIO)
547 myView->DisplayOnly(theIO);
551 Display all objects in view
553 void SVTK_ViewWindow::DisplayAll()
555 myView->DisplayAll();
559 Erase all objects in view
561 void SVTK_ViewWindow::EraseAll()
567 Sets background color [obsolete]
568 \param color - new background color
570 void SVTK_ViewWindow::setBackgroundColor( const QColor& c )
572 Qtx::BackgroundData bg = background();
578 \return background color of viewer [obsolete]
580 QColor SVTK_ViewWindow::backgroundColor() const
582 return background().color();
587 \param bgData - new background data
589 void SVTK_ViewWindow::setBackground( const Qtx::BackgroundData& bgData )
593 if ( bgData.isValid() ) {
594 switch ( bgData.mode() ) {
595 case Qtx::ColorBackground:
597 QColor c = bgData.color();
599 // show solid-colored background
600 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
601 getRenderer()->SetGradientBackground( false ); // cancel gradient mode
602 getRenderer()->SetBackground( c.red()/255.0,
604 c.blue()/255.0 ); // set background color
609 case Qtx::SimpleGradientBackground:
612 int type = bgData.gradient( c1, c2 );
618 // show two-color gradient background
619 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
620 getRenderer()->SetGradientBackground( true ); // switch to gradient mode
622 VTKViewer_OpenGLRenderer* aRenderer =
623 VTKViewer_OpenGLRenderer::SafeDownCast( getRenderer() );
626 aRenderer->SetGradientType( type );
627 aRenderer->SetBackground( c1.redF(), c1.greenF(), c1.blueF() );
628 aRenderer->SetBackground2( c2.redF(), c2.greenF(), c2.blueF() );
634 case Qtx::CustomGradientBackground:
636 // NOT IMPLEMENTED YET
637 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
638 getRenderer()->SetGradientBackground( false ); // cancel gradient mode
645 if ( bgData.isTextureShown() ) {
647 int textureMode = bgData.texture( fileName );
648 QFileInfo fi( fileName );
649 if ( !fileName.isEmpty() && fi.exists() ) {
650 // read texture from file
651 QString extension = fi.suffix().toLower();
652 vtkImageReader2* aReader = 0;
653 if ( extension == "jpg" || extension == "jpeg" )
654 aReader = vtkJPEGReader::New();
655 else if ( extension == "bmp" )
656 aReader = vtkBMPReader::New();
657 else if ( extension == "tif" || extension == "tiff" )
658 aReader = vtkTIFFReader::New();
659 else if ( extension == "png" )
660 aReader = vtkPNGReader::New();
661 else if ( extension == "mhd" || extension == "mha" )
662 aReader = vtkMetaImageReader::New();
665 aReader->SetFileName( fi.absoluteFilePath().toLatin1().constData() );
667 VTKViewer_Texture* aTexture = VTKViewer_Texture::New();
668 vtkImageMapToColors* aMap = 0;
669 vtkAlgorithmOutput* anOutput;
671 // special processing for BMP reader
672 vtkBMPReader* aBMPReader = (vtkBMPReader*)aReader;
674 // Special processing for BMP file
675 aBMPReader->SetAllow8BitBMP(1);
677 aMap = vtkImageMapToColors::New();
678 aMap->SetInputConnection( aBMPReader->GetOutputPort() );
679 aMap->SetLookupTable( (vtkScalarsToColors*)aBMPReader->GetLookupTable() );
680 aMap->SetOutputFormatToRGB();
682 anOutput = aMap->GetOutputPort();
687 anOutput = aReader->GetOutputPort( 0 );
688 aTexture->SetInputConnection( anOutput );
690 // VSR: Currently, VTK only supports Stretch mode, so below code will give
691 // the same results for all modes
692 switch ( textureMode ) {
693 case Qtx::TileTexture:
694 aTexture->SetPosition((int)VTKViewer_Texture::Tiled);
696 case Qtx::StretchTexture:
697 aTexture->SetPosition((int)VTKViewer_Texture::Stretched);
699 case Qtx::CenterTexture:
700 aTexture->SetPosition((int)VTKViewer_Texture::Centered);
704 // show textured background
705 getRenderer()->SetTexturedBackground( true );
706 getRenderer()->SetBackgroundTexture( aTexture );
708 // clean-up resources
719 myBackground = bgData;
723 \return background data of viewer
725 Qtx::BackgroundData SVTK_ViewWindow::background() const
732 Redirect the request to SVTK_RenderWindowInteractor::GetInteractorStyle
734 vtkInteractorStyle* SVTK_ViewWindow::GetInteractorStyle() const
736 return GetInteractor()->GetInteractorStyle();
740 Redirect the request to SVTK_RenderWindowInteractor::PushInteractorStyle
742 void SVTK_ViewWindow::PushInteractorStyle(vtkInteractorStyle* theStyle)
744 GetInteractor()->PushInteractorStyle(theStyle);
748 Redirect the request to SVTK_RenderWindowInteractor::PopInteractorStyle
750 void SVTK_ViewWindow::PopInteractorStyle()
752 GetInteractor()->PopInteractorStyle();
756 Updates current viewer
758 void SVTK_ViewWindow::Repaint(bool theUpdateTrihedron)
760 if(theUpdateTrihedron)
761 GetRenderer()->OnAdjustTrihedron();
763 GetInteractor()->update();
765 SVTK_InteractorStyle* aStyle = (SVTK_InteractorStyle*)getInteractor()->GetInteractorStyle();
771 Redirect the request to #SVTK_Renderer::GetScale
773 void SVTK_ViewWindow::GetScale( double theScale[3] )
775 GetRenderer()->GetScale( theScale );
779 Redirect the request to #SVTK_Renderer::SetScale
781 void SVTK_ViewWindow::SetScale( double theScale[3] )
783 GetRenderer()->SetScale( theScale );
785 emit transformed( this );
789 Redirect the request to #SVTK_Renderer::IsTrihedronDisplayed
791 bool SVTK_ViewWindow::isTrihedronDisplayed()
793 return GetRenderer()->IsTrihedronDisplayed();
797 Redirect the request to #SVTK_Renderer::IsCubeAxesDisplayed
799 bool SVTK_ViewWindow::isCubeAxesDisplayed()
801 return GetRenderer()->IsCubeAxesDisplayed();
805 Redirect the request to #SVTK_Renderer::OnViewTrihedron
807 void SVTK_ViewWindow::onViewTrihedron(bool show)
809 GetRenderer()->SetTrihedronVisibility(show);
814 Redirect the request to #SVTK_Renderer::OnViewCubeAxes
816 void SVTK_ViewWindow::onViewCubeAxes()
818 GetRenderer()->OnViewCubeAxes();
823 Redirect the request to #SVTK_Renderer::GetTrihedron
825 VTKViewer_Trihedron* SVTK_ViewWindow::GetTrihedron()
827 return GetRenderer()->GetTrihedron();
831 Redirect the request to #SVTK_Renderer::GetCubeAxes
833 SVTK_CubeAxesActor2D* SVTK_ViewWindow::GetCubeAxes()
835 return GetRenderer()->GetCubeAxes();
839 \return trihedron size
841 double SVTK_ViewWindow::GetTrihedronSize() const
843 return GetRenderer()->GetTrihedronSize();
848 \param theMode - projection mode ( 0 - orthogonal, 1 - perspective )
850 void SVTK_ViewWindow::SetProjectionMode(const int theMode)
852 activateProjectionMode( theMode );
857 Set the gravity center as a focal point
859 void SVTK_ViewWindow::activateSetFocalPointGravity()
861 myEventDispatcher->InvokeEvent(SVTK::SetFocalPointGravity, 0);
865 Set the selected point as a focal point
867 void SVTK_ViewWindow::activateSetFocalPointSelected()
869 myEventDispatcher->InvokeEvent(SVTK::SetFocalPointSelected, 0);
873 Set the point selected by user as a focal point
875 void SVTK_ViewWindow::activateStartFocalPointSelection()
877 myEventDispatcher->InvokeEvent(SVTK::StartFocalPointSelection,0);
880 void SVTK_ViewWindow::activateProjectionMode(int theMode)
883 toolMgr()->action( ProjectionModeId )->setChecked( true );
885 toolMgr()->action( ParallelModeId )->setChecked( true );
889 Sets actual interaction style
890 \param theStyle - type of interaction style ( 0 - standard, 1 - keyboard free )
892 void SVTK_ViewWindow::SetInteractionStyle(const int theStyle)
894 onSwitchInteractionStyle( theStyle==1 );
898 Sets actual zooming style
899 \param theStyle - type of zooming style ( 0 - standard, 1 - advanced (at cursor) )
901 void SVTK_ViewWindow::SetZoomingStyle(const int theStyle)
903 onSwitchZoomingStyle( theStyle==1 );
907 Set preselection mode.
908 \param theMode the mode to set (standard, dynamic or disabled)
910 void SVTK_ViewWindow::SetPreSelectionMode( Preselection_Mode theMode )
912 onSwitchPreSelectionMode( theMode );
916 Enables/disables selection.
917 \param theEnable if true - selection will be enabled
919 void SVTK_ViewWindow::SetSelectionEnabled( bool theEnable )
921 GetSelector()->SetSelectionEnabled( theEnable );
922 QtxAction* a = getAction( EnableSelectionId );
923 if ( a->isChecked() != theEnable)
924 a->setChecked( theEnable );
925 QtxActionGroup* aPreselectionGroup =
926 dynamic_cast<QtxActionGroup*>( getAction( PreselectionId ) );
927 if ( aPreselectionGroup )
928 aPreselectionGroup->setEnabled( theEnable );
932 Switches "keyboard free" interaction style on/off
934 void SVTK_ViewWindow::onSwitchInteractionStyle(bool theOn)
937 // check if style is already set
938 if ( GetInteractorStyle() != myKeyFreeInteractorStyle.GetPointer() )
940 // keep the same style extensions
941 SVTK_InteractorStyle* aStyle = (SVTK_InteractorStyle*)GetInteractorStyle();
943 myKeyFreeInteractorStyle->SetControllerIncrement(aStyle->ControllerIncrement());
944 myKeyFreeInteractorStyle->SetControllerOnKeyDown(aStyle->ControllerOnKeyDown());
947 PushInteractorStyle(myKeyFreeInteractorStyle.GetPointer());
951 // pop only key free style
952 if ( GetInteractorStyle() == myKeyFreeInteractorStyle.GetPointer() )
953 PopInteractorStyle();
956 // update action state if method is called outside
957 QtxAction* a = getAction( SwitchInteractionStyleId );
958 if ( a->isChecked() != theOn ) a->setChecked( theOn );
962 Toogles advanced zooming style (relatively to the cursor position) on/off
964 void SVTK_ViewWindow::onSwitchZoomingStyle( bool theOn )
966 if( myDefaultInteractorStyle.GetPointer() )
967 myDefaultInteractorStyle->SetAdvancedZoomingEnabled( theOn );
968 if( myKeyFreeInteractorStyle.GetPointer() )
969 myKeyFreeInteractorStyle->SetAdvancedZoomingEnabled( theOn );
971 // update action state if method is called outside
972 QtxAction* a = getAction( SwitchZoomingStyleId );
973 if ( a->isChecked() != theOn )
974 a->setChecked( theOn );
978 Switch preselection mode.
979 \param theMode the preselection mode
981 void SVTK_ViewWindow::onSwitchPreSelectionMode( int theMode )
983 GetSelector()->SetDynamicPreSelection( theMode == Dynamic_Preselection );
984 GetSelector()->SetPreSelectionEnabled( theMode != Preselection_Disabled );
986 // update action state if method is called outside
987 QtxAction* a = getAction( StandardPreselectionId + theMode );
988 if ( a && !a->isChecked() )
989 a->setChecked( true );
993 Enables/disables selection.
994 \param theOn if true - selection will be enabled
996 void SVTK_ViewWindow::onEnableSelection( bool on )
998 SVTK_Viewer* aViewer = dynamic_cast<SVTK_Viewer*>(myModel);
1000 aViewer->enableSelection(on);
1004 Sets incremental speed
1005 \param theValue - new incremental speed
1006 \param theMode - modification mode
1008 void SVTK_ViewWindow::SetIncrementalSpeed(const int theValue, const int theMode)
1010 if ( (SVTK_InteractorStyle*)GetInteractorStyle() )
1011 ((SVTK_InteractorStyle*)GetInteractorStyle())->SetIncrementSpeed(theValue, theMode);
1015 Sets spacemouse buttons for the functions
1016 \param theBtn1 - spacemouse button for the "decrease speed increment"
1017 \param theBtn2 - spacemouse button for the "increase speed increment"
1018 \param theBtn3 - spacemouse button for the "dominant combined switch"
1020 void SVTK_ViewWindow::SetSpacemouseButtons(const int theBtn1,
1025 myEventDispatcher->InvokeEvent(SVTK::SetSMDecreaseSpeedEvent, &val);
1027 myEventDispatcher->InvokeEvent(SVTK::SetSMIncreaseSpeedEvent, &val);
1029 myEventDispatcher->InvokeEvent(SVTK::SetSMDominantCombinedSwitchEvent, &val);
1034 \param theSize - new trihedron size
1035 \param theRelative - trihedron relativeness
1037 void SVTK_ViewWindow::SetTrihedronSize(const double theSize, const bool theRelative)
1039 GetRenderer()->SetTrihedronSize(theSize, theRelative);
1043 /*! If parameter theIsForcedUpdate is true, recalculate parameters for
1044 * trihedron and cube axes, even if trihedron and cube axes is invisible.
1046 void SVTK_ViewWindow::AdjustTrihedrons(const bool theIsForcedUpdate)
1048 GetRenderer()->AdjustActors();
1053 Redirect the request to #SVTK_Renderer::OnAdjustTrihedron
1055 void SVTK_ViewWindow::onAdjustTrihedron()
1057 GetRenderer()->OnAdjustTrihedron();
1061 Redirect the request to #SVTK_Renderer::OnAdjustCubeAxes
1063 void SVTK_ViewWindow::onAdjustCubeAxes()
1065 GetRenderer()->OnAdjustCubeAxes();
1068 void SVTK_ViewWindow::synchronize(SVTK_ViewWindow* otherViewWindow )
1070 if ( otherViewWindow ) {
1071 bool blocked = blockSignals( true );
1072 doSetVisualParameters( otherViewWindow->getVisualParameters(), true );
1073 blockSignals( blocked );
1080 void SVTK_ViewWindow::onKeyPressed(QKeyEvent* event)
1082 emit keyPressed( this, event );
1088 void SVTK_ViewWindow::onKeyReleased(QKeyEvent* event)
1090 emit keyReleased( this, event );
1096 void SVTK_ViewWindow::onMousePressed(QMouseEvent* event)
1098 emit mousePressed(this, event);
1102 Emits mouse released
1104 void SVTK_ViewWindow::onMouseReleased(QMouseEvent* event)
1106 emit mouseReleased( this, event );
1112 void SVTK_ViewWindow::onMouseMoving(QMouseEvent* event)
1114 emit mouseMoving( this, event );
1118 Emits mouse double clicked
1120 void SVTK_ViewWindow::onMouseDoubleClicked( QMouseEvent* event )
1122 emit mouseDoubleClicked( this, event );
1126 Redirect the request to #SVTK_Renderer::AddActor
1128 void SVTK_ViewWindow::AddActor( VTKViewer_Actor* theActor,
1130 bool theIsAdjustActors )
1132 GetRenderer()->AddActor(theActor, theIsAdjustActors);
1135 emit actorAdded(theActor);
1139 Redirect the request to #SVTK_Renderer::RemoveActor
1141 void SVTK_ViewWindow::RemoveActor( VTKViewer_Actor* theActor,
1143 bool theIsAdjustActors )
1145 GetRenderer()->RemoveActor(theActor, theIsAdjustActors);
1146 if ( myDefaultInteractorStyle )
1147 myDefaultInteractorStyle->FreeActors();
1148 if ( myKeyFreeInteractorStyle )
1149 myKeyFreeInteractorStyle->FreeActors();
1152 emit actorRemoved(theActor);
1155 QImage SVTK_ViewWindow::dumpViewContent()
1157 vtkRenderWindow* aWindow = getRenderWindow();
1158 int* aSize = aWindow->GetSize();
1159 int aWidth = aSize[0];
1160 int aHeight = aSize[1];
1162 OpenGLUtils_FrameBuffer aFrameBuffer;
1163 if( aFrameBuffer.init( aWidth, aHeight ) )
1165 glPushAttrib( GL_VIEWPORT_BIT );
1166 glViewport( 0, 0, aWidth, aHeight );
1167 aFrameBuffer.bind();
1172 aFrameBuffer.unbind();
1175 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
1177 aFrameBuffer.bind();
1178 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
1179 aFrameBuffer.unbind();
1181 anImage = anImage.rgbSwapped();
1182 anImage = anImage.mirrored();
1186 // if frame buffers are unsupported, use old functionality
1187 unsigned char *aData =
1188 aWindow->GetRGBACharPixelData( 0, 0, aWidth-1, aHeight-1, 0 );
1190 QImage anImage( aData, aWidth, aHeight, QImage::Format_ARGB32 );
1192 anImage = anImage.rgbSwapped();
1193 anImage = anImage.mirrored();
1198 \return QImage, containing all scene rendering in window
1200 QImage SVTK_ViewWindow::dumpView()
1202 if( myDumpImage.isNull() )
1203 return dumpViewContent();
1209 QString SVTK_ViewWindow::filter() const
1211 return tr( "SVTK_IMAGE_FILES" );
1214 bool SVTK_ViewWindow::dumpViewToFormat( const QImage& img, const QString& fileName, const QString& format )
1216 if ( format != "PS" && format != "EPS" && format != "PDF" )
1217 return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
1219 SUIT_OverrideCursor wc;
1221 vtkGL2PSExporter *anExporter = vtkGL2PSExporter::New();
1222 anExporter->SetRenderWindow(getRenderWindow());
1224 if ( format == "PS" ) {
1225 anExporter->SetFileFormatToPS();
1226 anExporter->CompressOff();
1229 if ( format == "EPS" ) {
1230 anExporter->SetFileFormatToEPS();
1231 anExporter->CompressOff();
1234 if ( format == "PDF" ) {
1235 anExporter->SetFileFormatToPDF();
1238 QString aFilePrefix(fileName);
1239 QString anExtension(SUIT_Tools::extension(fileName));
1240 aFilePrefix.truncate(aFilePrefix.length() - 1 - anExtension.length());
1241 anExporter->SetFilePrefix(aFilePrefix.toLatin1().data());
1242 anExporter->Write();
1243 anExporter->Delete();
1249 \refresh QImage, containing all scene rendering in window
1251 void SVTK_ViewWindow::RefreshDumpImage()
1253 myDumpImage = dumpViewContent();
1257 Redirect the request to #SVTK_Renderer::SetSelectionProp
1259 void SVTK_ViewWindow::SetSelectionProp(const double& theRed,
1260 const double& theGreen,
1261 const double& theBlue,
1262 const int& theWidth)
1264 myView->SetSelectionProp(theRed,theGreen,theBlue,theWidth);
1268 Redirect the request to #SVTK_Renderer::SetSelectionProp
1270 void SVTK_ViewWindow::SetPreselectionProp(const double& theRed,
1271 const double& theGreen,
1272 const double& theBlue,
1273 const int& theWidth)
1275 myView->SetPreselectionProp(theRed,theGreen,theBlue,theWidth);
1279 Redirect the request to #SVTK_Renderer::SetSelectionTolerance
1281 void SVTK_ViewWindow::SetSelectionTolerance(const double& theTolNodes,
1282 const double& theTolItems,
1283 const double& theTolObjects)
1285 myView->SetSelectionTolerance(theTolNodes, theTolItems, theTolObjects);
1289 Get visibility status of the static trihedron
1291 bool SVTK_ViewWindow::IsStaticTrihedronVisible() const
1293 return (bool)myAxesWidget->GetEnabled();
1297 Set visibility status of the static trihedron
1299 void SVTK_ViewWindow::SetStaticTrihedronVisible( const bool theIsVisible )
1301 myAxesWidget->SetEnabled( (int)theIsVisible );
1306 \param accelAction - action
1308 bool SVTK_ViewWindow::action( const int accelAction )
1310 if ( accelAction == SUIT_Accel::ZoomFit )
1313 int anEvent = SVTK::convertAction( accelAction );
1314 GetInteractor()->InvokeEvent(anEvent, 0);
1320 \return action by it's id
1322 QtxAction* SVTK_ViewWindow::getAction( int id ) const
1324 return dynamic_cast<QtxAction*>( toolMgr()->action( id ) );
1328 // old visual parameters had 13 values. New format added additional
1329 // 76 values for graduated axes, so both numbers are processed.
1330 const int nNormalParams = 13; // number of view windows parameters excluding graduated axes params
1331 const int nGradAxisParams = 25; // number of parameters of ONE graduated axis (X, Y, or Z)
1332 const int nTrihedronParams = 3; // number of parameters for Trihedron
1333 const int nAllParams = nNormalParams + 3*nGradAxisParams + nTrihedronParams + 1; // number of all visual parameters
1335 /*! The method returns visual parameters of a graduated axis actor (x,y,z axis of graduated axes)
1337 void getGradAxisVisualParams( QXmlStreamWriter& writer, vtkAxisActor2D* actor, QString theAxis )
1344 bool isVisible = actor->GetTitleVisibility();
1345 QString title ( actor->GetTitle() );
1347 int font = VTK_ARIAL;
1352 vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1355 txtProp->GetColor( color );
1356 font = txtProp->GetFontFamily();
1357 bold = txtProp->GetBold();
1358 italic = txtProp->GetItalic();
1359 shadow = txtProp->GetShadow();
1361 writer.writeStartElement("GraduatedAxis");
1362 writer.writeAttribute("Axis", theAxis);
1364 writer.writeStartElement("Title");
1365 writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1366 writer.writeAttribute("Text", title);
1367 writer.writeAttribute("Font", QString("%1").arg(font));
1368 writer.writeAttribute("Bold", QString("%1").arg(bold));
1369 writer.writeAttribute("Italic", QString("%1").arg(italic));
1370 writer.writeAttribute("Shadow", QString("%1").arg(shadow));
1372 writer.writeStartElement("Color");
1373 writer.writeAttribute("R", QString("%1").arg(color[0]));
1374 writer.writeAttribute("G", QString("%1").arg(color[1]));
1375 writer.writeAttribute("B", QString("%1").arg(color[2]));
1376 writer.writeEndElement();
1377 writer.writeEndElement();
1379 //params.sprintf( "* Graduated Axis: * Name *%u*%s*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible,
1380 // title.toLatin1().data(), color[0], color[1], color[2], font, bold, italic, shadow );
1383 isVisible = actor->GetLabelVisibility();
1384 int labels = actor->GetNumberOfLabels();
1385 int offset = actor->GetTickOffset();
1391 txtProp = actor->GetLabelTextProperty();
1394 txtProp->GetColor( color );
1395 font = txtProp->GetFontFamily();
1396 bold = txtProp->GetBold();
1397 italic = txtProp->GetItalic();
1398 shadow = txtProp->GetShadow();
1401 writer.writeStartElement("Labels");
1402 writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1403 writer.writeAttribute("Number", QString("%1").arg(labels));
1404 writer.writeAttribute("Offset", QString("%1").arg(offset));
1405 writer.writeAttribute("Font", QString("%1").arg(font));
1406 writer.writeAttribute("Bold", QString("%1").arg(bold));
1407 writer.writeAttribute("Italic", QString("%1").arg(italic));
1408 writer.writeAttribute("Shadow", QString("%1").arg(shadow));
1410 writer.writeStartElement("Color");
1411 writer.writeAttribute("R", QString("%1").arg(color[0]));
1412 writer.writeAttribute("G", QString("%1").arg(color[1]));
1413 writer.writeAttribute("B", QString("%1").arg(color[2]));
1414 writer.writeEndElement();
1415 writer.writeEndElement();
1416 // params += QString().sprintf( "* Labels *%u*%u*%u*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible, labels, offset,
1417 // color[0], color[1], color[2], font, bold, italic, shadow );
1420 isVisible = actor->GetTickVisibility();
1421 int length = actor->GetTickLength();
1422 writer.writeStartElement("TickMarks");
1423 writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1424 writer.writeAttribute("Length", QString("%1").arg(length));
1425 writer.writeEndElement();
1427 //params += QString().sprintf( "* Tick marks *%u*%u", isVisible, length );
1429 writer.writeEndElement();
1433 void setGradAxisVisualParams(QXmlStreamReader& reader, vtkAxisActor2D* actor)
1440 } while (!reader.isStartElement());
1442 // Read title params
1443 QXmlStreamAttributes aAttr = reader.attributes();
1444 bool isVisible = aAttr.value("isVisible").toString().toUShort();
1445 QString title = aAttr.value("Text").toString();
1446 int font = aAttr.value("Font").toString().toInt();
1447 int bold = aAttr.value("Bold").toString().toInt();
1448 int italic = aAttr.value("Italic").toString().toInt();
1449 int shadow = aAttr.value("Shadow").toString().toInt();
1451 //printf("#### TITLE: %i, %s, %i, %i, %i, %i\n", isVisible, qPrintable(title), font, bold, italic, shadow);
1455 } while (!reader.isStartElement());
1458 aAttr = reader.attributes();
1461 color[0] = aAttr.value("R").toString().toDouble();
1462 color[1] = aAttr.value("G").toString().toDouble();
1463 color[2] = aAttr.value("B").toString().toDouble();
1464 //printf("#### Color: %f, %f, %f\n", color[0], color[1], color[2]);
1466 actor->SetTitleVisibility( isVisible );
1467 actor->SetTitle( title.toLatin1() );
1468 vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1470 txtProp->SetColor( color );
1471 txtProp->SetFontFamily( font );
1472 txtProp->SetBold( bold );
1473 txtProp->SetItalic( italic );
1474 txtProp->SetShadow( shadow );
1481 } while (!reader.isStartElement());
1483 aAttr = reader.attributes();
1484 isVisible = aAttr.value("isVisible").toString().toUShort();
1485 int labels = aAttr.value("Number").toString().toInt();
1486 int offset = aAttr.value("Offset").toString().toInt();
1487 font = aAttr.value("Font").toString().toInt();
1488 bold = aAttr.value("Bold").toString().toInt();
1489 italic = aAttr.value("Italic").toString().toInt();
1490 shadow = aAttr.value("Shadow").toString().toInt();
1494 } while (!reader.isStartElement());
1496 aAttr = reader.attributes();
1498 color[0] = aAttr.value("R").toString().toDouble();
1499 color[1] = aAttr.value("G").toString().toDouble();
1500 color[2] = aAttr.value("B").toString().toDouble();
1502 actor->SetLabelVisibility( isVisible );
1503 actor->SetNumberOfLabels( labels );
1504 actor->SetTickOffset( offset );
1505 txtProp = actor->GetLabelTextProperty();
1507 txtProp->SetColor( color );
1508 txtProp->SetFontFamily( font );
1509 txtProp->SetBold( bold );
1510 txtProp->SetItalic( italic );
1511 txtProp->SetShadow( shadow );
1517 } while (!reader.isStartElement());
1518 aAttr = reader.attributes();
1520 // retrieve and set tick marks properties
1521 isVisible = aAttr.value("isVisible").toString().toUShort();
1522 int length = aAttr.value("Length").toString().toInt();
1524 actor->SetTickVisibility( isVisible );
1525 actor->SetTickLength( length );
1528 /*! The method restores visual parameters of a graduated axis actor (x,y,z axis)
1530 void setGradAxisVisualParams( vtkAxisActor2D* actor, const QString& params )
1535 QStringList paramsLst = params.split( '*' );
1537 if ( paramsLst.size() == nGradAxisParams ) { // altogether name, lable, ticks parameters make up 25 values
1539 // retrieve and set name parameters
1540 bool isVisible = paramsLst[2].toUShort();
1541 QString title = paramsLst[3];
1543 color[0] = paramsLst[4].toDouble();
1544 color[1] = paramsLst[5].toDouble();
1545 color[2] = paramsLst[6].toDouble();
1546 int font = paramsLst[7].toInt();
1547 int bold = paramsLst[8].toInt();
1548 int italic = paramsLst[9].toInt();
1549 int shadow = paramsLst[10].toInt();
1551 actor->SetTitleVisibility( isVisible );
1552 actor->SetTitle( title.toLatin1() );
1553 vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1555 txtProp->SetColor( color );
1556 txtProp->SetFontFamily( font );
1557 txtProp->SetBold( bold );
1558 txtProp->SetItalic( italic );
1559 txtProp->SetShadow( shadow );
1562 // retrieve and set lable parameters
1563 isVisible = paramsLst[12].toUShort();
1564 int labels = paramsLst[13].toInt();
1565 int offset = paramsLst[14].toInt();
1566 color[0] = paramsLst[15].toDouble();
1567 color[1] = paramsLst[16].toDouble();
1568 color[2] = paramsLst[17].toDouble();
1569 font = paramsLst[18].toInt();
1570 bold = paramsLst[19].toInt();
1571 italic = paramsLst[20].toInt();
1572 shadow = paramsLst[21].toInt();
1574 actor->SetLabelVisibility( isVisible );
1575 actor->SetNumberOfLabels( labels );
1576 actor->SetTickOffset( offset );
1577 txtProp = actor->GetLabelTextProperty();
1579 txtProp->SetColor( color );
1580 txtProp->SetFontFamily( font );
1581 txtProp->SetBold( bold );
1582 txtProp->SetItalic( italic );
1583 txtProp->SetShadow( shadow );
1586 // retrieve and set tick marks properties
1587 isVisible = paramsLst[23].toUShort();
1588 int length = paramsLst[24].toInt();
1590 actor->SetTickVisibility( isVisible );
1591 actor->SetTickLength( length );
1595 /*! The method returns the visual parameters of this view as a formated string
1597 QString SVTK_ViewWindow::getVisualParameters()
1599 double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
1601 // save position, focal point, viewUp, scale
1602 vtkCamera* camera = getRenderer()->GetActiveCamera();
1603 camera->GetPosition( pos );
1604 camera->GetFocalPoint( focalPnt );
1605 camera->GetViewUp( viewUp );
1606 parScale = camera->GetParallelScale();
1609 // Parameters are given in the following format:view position (3 digits), focal point position (3 digits)
1610 // view up values (3 digits), parallel scale (1 digit), scale (3 digits,
1611 // Graduated axes parameters (X, Y, Z axes parameters)
1613 QXmlStreamWriter aWriter(&retStr);
1614 aWriter.setAutoFormatting(true);
1616 aWriter.writeStartDocument();
1617 aWriter.writeStartElement("ViewState");
1619 aWriter.writeStartElement("Position");
1620 aWriter.writeAttribute("X", QString("%1").arg(pos[0]));
1621 aWriter.writeAttribute("Y", QString("%1").arg(pos[1]));
1622 aWriter.writeAttribute("Z", QString("%1").arg(pos[2]));
1623 aWriter.writeEndElement();
1625 aWriter.writeStartElement("FocalPoint");
1626 aWriter.writeAttribute("X", QString::number(focalPnt[0]));
1627 aWriter.writeAttribute("Y", QString::number(focalPnt[1]));
1628 aWriter.writeAttribute("Z", QString::number(focalPnt[2]));
1629 aWriter.writeEndElement();
1631 aWriter.writeStartElement("ViewUp");
1632 aWriter.writeAttribute("X", QString::number(viewUp[0]));
1633 aWriter.writeAttribute("Y", QString::number(viewUp[1]));
1634 aWriter.writeAttribute("Z", QString::number(viewUp[2]));
1635 aWriter.writeEndElement();
1637 aWriter.writeStartElement("ViewScale");
1638 aWriter.writeAttribute("Parallel", QString::number(parScale));
1639 aWriter.writeAttribute("X", QString::number(scale[0]));
1640 aWriter.writeAttribute("Y", QString::number(scale[1]));
1641 aWriter.writeAttribute("Z", QString::number(scale[2]));
1642 aWriter.writeEndElement();
1644 if ( SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes() ) {
1645 aWriter.writeStartElement("DisplayCubeAxis");
1646 aWriter.writeAttribute("Show", QString( "%1" ).arg( GetRenderer()->IsCubeAxesDisplayed()));
1647 aWriter.writeEndElement();
1649 getGradAxisVisualParams(aWriter, gradAxesActor->GetXAxisActor2D(), "X");
1650 getGradAxisVisualParams(aWriter, gradAxesActor->GetYAxisActor2D(), "Y");
1651 getGradAxisVisualParams(aWriter, gradAxesActor->GetZAxisActor2D(), "Z");
1654 aWriter.writeStartElement("Trihedron");
1655 aWriter.writeAttribute("isShown", QString( "%1" ).arg( isTrihedronDisplayed()));
1656 aWriter.writeAttribute("Size", QString::number(GetTrihedronSize()));
1657 aWriter.writeEndElement();
1659 aWriter.writeStartElement("Background");
1660 aWriter.writeAttribute("Value", QString( "%1" ).arg( Qtx::backgroundToString(background()) ));
1661 aWriter.writeEndElement();
1663 aWriter.writeEndElement();
1664 aWriter.writeEndDocument();
1670 The method restores visual parameters of this view or postpones it untill the view is shown
1672 void SVTK_ViewWindow::setVisualParameters( const QString& parameters )
1674 //printf("#### %s\n", qPrintable(parameters));
1675 SVTK_RenderWindowInteractor* anInteractor = GetInteractor();
1676 if ( anInteractor->isVisible() ) {
1677 doSetVisualParameters( parameters );
1680 myVisualParams = parameters;
1681 anInteractor->installEventFilter(this);
1686 The method restores visual parameters of this view from a formated string
1688 void SVTK_ViewWindow::doSetVisualParameters( const QString& parameters, bool baseParamsOnly )
1691 double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
1693 QXmlStreamReader aReader(parameters);
1694 SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes();
1696 while(!aReader.atEnd()) {
1698 if (aReader.isStartElement()) {
1699 QXmlStreamAttributes aAttr = aReader.attributes();
1700 //printf("### Name = %s\n", qPrintable(aReader.name().toString()));
1701 if (aReader.name() == "Position") {
1702 pos[0] = aAttr.value("X").toString().toDouble();
1703 pos[1] = aAttr.value("Y").toString().toDouble();
1704 pos[2] = aAttr.value("Z").toString().toDouble();
1705 //printf("#### Position %f; %f; %f\n", pos[0], pos[1], pos[2]);
1707 else if (aReader.name() == "FocalPoint") {
1708 focalPnt[0] = aAttr.value("X").toString().toDouble();
1709 focalPnt[1] = aAttr.value("Y").toString().toDouble();
1710 focalPnt[2] = aAttr.value("Z").toString().toDouble();
1711 //printf("#### FocalPoint %f; %f; %f\n", focalPnt[0], focalPnt[1], focalPnt[2]);
1713 else if (aReader.name() == "ViewUp") {
1714 viewUp[0] = aAttr.value("X").toString().toDouble();
1715 viewUp[1] = aAttr.value("Y").toString().toDouble();
1716 viewUp[2] = aAttr.value("Z").toString().toDouble();
1717 //printf("#### ViewUp %f; %f; %f\n", viewUp[0], viewUp[1], viewUp[2]);
1719 else if (aReader.name() == "ViewScale") {
1720 parScale = aAttr.value("Parallel").toString().toDouble();
1721 scale[0] = aAttr.value("X").toString().toDouble();
1722 scale[1] = aAttr.value("Y").toString().toDouble();
1723 scale[2] = aAttr.value("Z").toString().toDouble();
1724 //printf("#### ViewScale %f; %f; %f\n", scale[0], scale[1], scale[2]);
1726 else if (aReader.name() == "DisplayCubeAxis") {
1727 if ( !baseParamsOnly ) {
1728 if (aAttr.value("Show") == "0")
1729 gradAxesActor->VisibilityOff();
1731 gradAxesActor->VisibilityOn();
1734 else if (aReader.name() == "GraduatedAxis") {
1735 if ( !baseParamsOnly ) {
1736 if(aAttr.value("Axis") == "X")
1737 setGradAxisVisualParams(aReader, gradAxesActor->GetXAxisActor2D());
1738 else if(aAttr.value("Axis") == "Y")
1739 setGradAxisVisualParams(aReader, gradAxesActor->GetYAxisActor2D());
1740 else if(aAttr.value("Axis") == "Z")
1741 setGradAxisVisualParams(aReader, gradAxesActor->GetZAxisActor2D());
1744 else if (aReader.name() == "Trihedron") {
1745 if ( !baseParamsOnly ) {
1746 if (aAttr.value("isShown") == "0")
1747 GetTrihedron()->VisibilityOff();
1749 GetTrihedron()->VisibilityOn();
1750 SetTrihedronSize(aAttr.value("Size").toString().toDouble());
1753 else if (aReader.name() == "Background") {
1754 if ( !baseParamsOnly ) {
1755 setBackground( Qtx::stringToBackground( aAttr.value("Value").toString() ) );
1760 if (!aReader.hasError()) {
1761 vtkCamera* camera = getRenderer()->GetActiveCamera();
1762 camera->SetPosition( pos );
1763 camera->SetFocalPoint( focalPnt );
1764 camera->SetViewUp( viewUp );
1765 camera->SetParallelScale( parScale );
1766 GetRenderer()->SetScale( scale );
1767 //SetScale( scale );
1770 QStringList paramsLst = parameters.split( '*' );
1771 if ( paramsLst.size() >= nNormalParams ) {
1772 // 'reading' list of parameters
1773 pos[0] = paramsLst[0].toDouble();
1774 pos[1] = paramsLst[1].toDouble();
1775 pos[2] = paramsLst[2].toDouble();
1776 focalPnt[0] = paramsLst[3].toDouble();
1777 focalPnt[1] = paramsLst[4].toDouble();
1778 focalPnt[2] = paramsLst[5].toDouble();
1779 viewUp[0] = paramsLst[6].toDouble();
1780 viewUp[1] = paramsLst[7].toDouble();
1781 viewUp[2] = paramsLst[8].toDouble();
1782 parScale = paramsLst[9].toDouble();
1783 scale[0] = paramsLst[10].toDouble();
1784 scale[1] = paramsLst[11].toDouble();
1785 scale[2] = paramsLst[12].toDouble();
1787 // applying parameters
1788 vtkCamera* camera = getRenderer()->GetActiveCamera();
1789 camera->SetPosition( pos );
1790 camera->SetFocalPoint( focalPnt );
1791 camera->SetViewUp( viewUp );
1792 camera->SetParallelScale( parScale );
1793 GetRenderer()->SetScale( scale );
1794 //SetScale( scale );
1796 // apply graduated axes parameters
1797 if ( !baseParamsOnly ) {
1798 SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes();
1799 if ( gradAxesActor && paramsLst.size() == nAllParams ) {
1800 int i = nNormalParams+1, j = i + nGradAxisParams - 1;
1801 ::setGradAxisVisualParams( gradAxesActor->GetXAxisActor2D(), parameters.section( '*', i, j ) );
1802 i = j + 1; j += nGradAxisParams;
1803 ::setGradAxisVisualParams( gradAxesActor->GetYAxisActor2D(), parameters.section( '*', i, j ) );
1804 i = j + 1; j += nGradAxisParams;
1805 ::setGradAxisVisualParams( gradAxesActor->GetZAxisActor2D(), parameters.section( '*', i, j ) );
1807 if ( paramsLst[13].toUShort() )
1808 gradAxesActor->VisibilityOn();
1810 gradAxesActor->VisibilityOff();
1812 else if ( paramsLst.size() == nAllParams ) {
1813 if ( paramsLst[90].toUShort() )
1814 GetTrihedron()->VisibilityOn();
1816 GetTrihedron()->VisibilityOff();
1818 SetTrihedronSize(paramsLst[91].toDouble());
1828 Delayed setVisualParameters
1830 bool SVTK_ViewWindow::eventFilter( QObject* theWatched, QEvent* theEvent )
1832 if ( theEvent->type() == QEvent::Show && theWatched->inherits( "SVTK_RenderWindowInteractor" ) ) {
1833 SVTK_RenderWindowInteractor* anInteractor = (SVTK_RenderWindowInteractor*)theWatched;
1834 if ( anInteractor->isVisible() ) {
1835 doSetVisualParameters( myVisualParams );
1836 anInteractor->removeEventFilter( this ); // theWatched = RenderWindowInteractor
1839 return SUIT_ViewWindow::eventFilter( theWatched, theEvent );
1844 Change rotation point
1846 void SVTK_ViewWindow::onChangeRotationPoint(bool theIsActivate)
1849 mySetRotationPointDlg->addObserver();
1850 if ( mySetRotationPointDlg->IsFirstShown() )
1851 activateSetRotationGravity();
1852 mySetRotationPointDlg->show();
1854 mySetRotationPointDlg->hide();
1858 Set the gravity center as a rotation point
1860 void SVTK_ViewWindow::activateSetRotationGravity()
1862 myEventDispatcher->InvokeEvent(SVTK::SetRotateGravity,0);
1866 Set the selected point as a rotation point
1868 void SVTK_ViewWindow::activateSetRotationSelected(void* theData)
1870 myEventDispatcher->InvokeEvent(SVTK::ChangeRotationPoint,theData);
1874 Set the gravity center of element selected by user as a rotation point
1876 void SVTK_ViewWindow::activateStartPointSelection( Selection_Mode theSelectionMode )
1878 SetSelectionMode( theSelectionMode );
1879 myEventDispatcher->InvokeEvent(SVTK::StartPointSelection,0);
1883 Set the view projection mode: orthogonal or perspective
1885 void SVTK_ViewWindow::onPerspectiveMode()
1887 bool anIsParallelMode = toolMgr()->action( ParallelModeId )->isChecked();
1889 // advanced zooming is not available in perspective mode
1890 if( QtxAction* anAction = getAction( SwitchZoomingStyleId ) )
1891 anAction->setEnabled( anIsParallelMode );
1893 vtkCamera* aCamera = getRenderer()->GetActiveCamera();
1894 aCamera->SetParallelProjection(anIsParallelMode);
1895 GetInteractor()->GetDevice()->CreateTimer(VTKI_TIMER_FIRST);
1897 emit transformed( this );
1900 void SVTK_ViewWindow::SetEventDispatcher(vtkObject* theDispatcher)
1902 myEventDispatcher = theDispatcher;
1906 Creates all actions of svtk main window
1908 void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
1910 QtxAction* anAction;
1911 QtxActionToolMgr* mgr = toolMgr();
1914 anAction = new QtxAction(tr("MNU_DUMP_VIEW"),
1915 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
1916 tr( "MNU_DUMP_VIEW" ), 0, this);
1917 anAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1918 connect(anAction, SIGNAL(activated()), this, SLOT(onDumpView()));
1919 mgr->registerAction( anAction, DumpId );
1922 anAction = new QtxAction(tr("MNU_FITALL"),
1923 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
1924 tr( "MNU_FITALL" ), 0, this);
1925 anAction->setStatusTip(tr("DSC_FITALL"));
1926 connect(anAction, SIGNAL(activated()), this, SLOT(onFitAll()));
1927 mgr->registerAction( anAction, FitAllId );
1930 anAction = new QtxAction(tr("MNU_FITRECT"),
1931 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
1932 tr( "MNU_FITRECT" ), 0, this);
1933 anAction->setStatusTip(tr("DSC_FITRECT"));
1934 connect(anAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
1935 mgr->registerAction( anAction, FitRectId );
1938 anAction = new QtxAction(tr("MNU_ZOOM_VIEW"),
1939 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
1940 tr( "MNU_ZOOM_VIEW" ), 0, this);
1941 anAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1942 connect(anAction, SIGNAL(activated()), this, SLOT(activateZoom()));
1943 mgr->registerAction( anAction, ZoomId );
1946 anAction = new QtxAction(tr("MNU_PAN_VIEW"),
1947 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
1948 tr( "MNU_PAN_VIEW" ), 0, this);
1949 anAction->setStatusTip(tr("DSC_PAN_VIEW"));
1950 connect(anAction, SIGNAL(activated()), this, SLOT(activatePanning()));
1951 mgr->registerAction( anAction, PanId );
1954 anAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"),
1955 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
1956 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1957 anAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1958 connect(anAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
1959 mgr->registerAction( anAction, GlobalPanId );
1961 // Change rotation point
1962 anAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"),
1963 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_ROTATION_POINT" ) ),
1964 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1965 anAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1966 anAction->setCheckable(true);
1967 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onChangeRotationPoint(bool)));
1968 mgr->registerAction( anAction, ChangeRotationPointId );
1971 anAction = new QtxAction(tr("MNU_ROTATE_VIEW"),
1972 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
1973 tr( "MNU_ROTATE_VIEW" ), 0, this);
1974 anAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1975 connect(anAction, SIGNAL(activated()), this, SLOT(activateRotation()));
1976 mgr->registerAction( anAction, RotationId );
1979 anAction = new QtxAction(tr("MNU_FRONT_VIEW"),
1980 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
1981 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1982 anAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1983 connect(anAction, SIGNAL(activated()), this, SLOT(onFrontView()));
1984 this->addAction(anAction);
1985 mgr->registerAction( anAction, FrontId );
1987 anAction = new QtxAction(tr("MNU_BACK_VIEW"),
1988 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
1989 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1990 anAction->setStatusTip(tr("DSC_BACK_VIEW"));
1991 connect(anAction, SIGNAL(activated()), this, SLOT(onBackView()));
1992 this->addAction(anAction);
1993 mgr->registerAction( anAction, BackId );
1995 anAction = new QtxAction(tr("MNU_TOP_VIEW"),
1996 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
1997 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1998 anAction->setStatusTip(tr("DSC_TOP_VIEW"));
1999 connect(anAction, SIGNAL(activated()), this, SLOT(onTopView()));
2000 this->addAction(anAction);
2001 mgr->registerAction( anAction, TopId );
2003 anAction = new QtxAction(tr("MNU_BOTTOM_VIEW"),
2004 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
2005 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
2006 anAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
2007 connect(anAction, SIGNAL(activated()), this, SLOT(onBottomView()));
2008 this->addAction(anAction);
2009 mgr->registerAction( anAction, BottomId );
2011 anAction = new QtxAction(tr("MNU_LEFT_VIEW"),
2012 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
2013 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
2014 anAction->setStatusTip(tr("DSC_LEFT_VIEW"));
2015 connect(anAction, SIGNAL(activated()), this, SLOT(onLeftView()));
2016 this->addAction(anAction);
2017 mgr->registerAction( anAction, LeftId );
2019 anAction = new QtxAction(tr("MNU_RIGHT_VIEW"),
2020 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
2021 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
2022 anAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
2023 connect(anAction, SIGNAL(activated()), this, SLOT(onRightView()));
2024 this->addAction(anAction);
2025 mgr->registerAction( anAction, RightId );
2027 // rotate anticlockwise
2028 anAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"),
2029 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ANTICLOCKWISE" ) ),
2030 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
2031 anAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
2032 connect(anAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
2033 this->addAction(anAction);
2034 mgr->registerAction( anAction, AntiClockWiseId );
2037 anAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"),
2038 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_CLOCKWISE" ) ),
2039 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
2040 anAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
2041 connect(anAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
2042 this->addAction(anAction);
2043 mgr->registerAction( anAction, ClockWiseId );
2046 anAction = new QtxAction(tr("MNU_RESET_VIEW"),
2047 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
2048 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
2049 anAction->setStatusTip(tr("DSC_RESET_VIEW"));
2050 connect(anAction, SIGNAL(activated()), this, SLOT(onResetView()));
2051 this->addAction(anAction);
2052 mgr->registerAction( anAction, ResetId );
2054 // onViewTrihedron: Shows - Hides Trihedron
2055 anAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"),
2056 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ),
2057 tr( "MNU_SHOW_TRIHEDRON" ), 0, this);
2058 anAction->setCheckable( true );
2059 anAction->setChecked( true );
2061 anAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON"));
2062 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onViewTrihedron(bool)));
2063 mgr->registerAction( anAction, ViewTrihedronId );
2065 // onNonIsometric: Manage non-isometric params
2066 anAction = new QtxAction(tr("MNU_SVTK_SCALING"),
2067 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SCALING" ) ),
2068 tr( "MNU_SVTK_SCALING" ), 0, this);
2069 anAction->setStatusTip(tr("DSC_SVTK_SCALING"));
2070 anAction->setCheckable(true);
2071 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onNonIsometric(bool)));
2072 mgr->registerAction( anAction, NonIsometric );
2074 // onGraduatedAxes: Manage graduated axes params
2075 anAction = new QtxAction(tr("MNU_SVTK_GRADUATED_AXES"),
2076 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_GRADUATED_AXES" ) ),
2077 tr( "MNU_SVTK_GRADUATED_AXES" ), 0, this);
2078 anAction->setStatusTip(tr("DSC_SVTK_GRADUATED_AXES"));
2079 anAction->setCheckable(true);
2080 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onGraduatedAxes(bool)));
2081 mgr->registerAction( anAction, GraduatedAxes );
2083 // onGraduatedAxes: Manage graduated axes params
2084 anAction = new QtxAction(tr("MNU_SVTK_UPDATE_RATE"),
2085 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_UPDATE_RATE" ) ),
2086 tr( "MNU_SVTK_UPDATE_RATE" ), 0, this);
2087 anAction->setStatusTip(tr("DSC_SVTK_UPDATE_RATE"));
2088 anAction->setCheckable(true);
2089 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onUpdateRate(bool)));
2090 mgr->registerAction( anAction, UpdateRate );
2092 // Set perspective mode group
2093 anAction = new QtxAction(tr("MNU_SVTK_PARALLEL_MODE"),
2094 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARALLEL" ) ),
2095 tr( "MNU_SVTK_PARALLEL_MODE" ), 0, this);
2096 anAction->setStatusTip(tr("DSC_SVTK_PARALLEL_MODE"));
2097 anAction->setCheckable(true);
2098 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onPerspectiveMode()));
2099 mgr->registerAction( anAction, ParallelModeId );
2101 anAction = new QtxAction(tr("MNU_SVTK_PERSPECTIVE_MODE"),
2102 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PERSPECTIVE" ) ),
2103 tr( "MNU_SVTK_PERSPECTIVE_MODE" ), 0, this);
2104 anAction->setStatusTip(tr("DSC_SVTK_PERSPECTIVE_MODE"));
2105 anAction->setCheckable(true);
2106 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onPerspectiveMode()));
2107 mgr->registerAction( anAction, ProjectionModeId );
2109 QActionGroup* aPerspectiveGroup = new QActionGroup( this );
2110 aPerspectiveGroup->addAction( mgr->action( ParallelModeId ) );
2111 aPerspectiveGroup->addAction( mgr->action( ProjectionModeId ) );
2114 anAction = new QtxAction(tr("MNU_VIEWPARAMETERS_VIEW"),
2115 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARAMETERS" ) ),
2116 tr( "MNU_VIEWPARAMETERS_VIEW" ), 0, this);
2117 anAction->setStatusTip(tr("DSC_VIEWPARAMETERS_VIEW"));
2118 anAction->setCheckable(true);
2119 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onViewParameters(bool)));
2120 mgr->registerAction( anAction, ViewParametersId );
2123 mgr->registerAction( synchronizeAction(), SynchronizeId );
2125 // Switch between interaction styles
2126 anAction = new QtxAction(tr("MNU_SVTK_STYLE_SWITCH"),
2127 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_STYLE_SWITCH" ) ),
2128 tr( "MNU_SVTK_STYLE_SWITCH" ), 0, this);
2129 anAction->setStatusTip(tr("DSC_SVTK_STYLE_SWITCH"));
2130 anAction->setCheckable(true);
2131 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
2132 mgr->registerAction( anAction, SwitchInteractionStyleId );
2134 // Switch between zooming styles
2135 anAction = new QtxAction(tr("MNU_SVTK_ZOOMING_STYLE_SWITCH"),
2136 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_ZOOMING_STYLE_SWITCH" ) ),
2137 tr( "MNU_SVTK_ZOOMING_STYLE_SWITCH" ), 0, this);
2138 anAction->setStatusTip(tr("DSC_SVTK_ZOOMING_STYLE_SWITCH"));
2139 anAction->setCheckable(true);
2140 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
2141 mgr->registerAction( anAction, SwitchZoomingStyleId );
2144 QSignalMapper* aSignalMapper = new QSignalMapper( this );
2145 connect(aSignalMapper, SIGNAL(mapped(int)), this, SLOT(onSwitchPreSelectionMode(int)));
2147 anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_STANDARD"),
2148 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_STANDARD" ) ),
2149 tr( "MNU_SVTK_PRESELECTION_STANDARD" ), 0, this);
2150 anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_STANDARD"));
2151 anAction->setCheckable(true);
2152 connect(anAction, SIGNAL(activated()), aSignalMapper, SLOT(map()));
2153 aSignalMapper->setMapping( anAction, Standard_Preselection );
2154 mgr->registerAction( anAction, StandardPreselectionId );
2156 anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_DYNAMIC"),
2157 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_DYNAMIC" ) ),
2158 tr( "MNU_SVTK_PRESELECTION_DYNAMIC" ), 0, this);
2159 anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_DYNAMIC"));
2160 anAction->setCheckable(true);
2161 connect(anAction, SIGNAL(activated()), aSignalMapper, SLOT(map()));
2162 aSignalMapper->setMapping( anAction, Dynamic_Preselection );
2163 mgr->registerAction( anAction, DynamicPreselectionId );
2165 anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_DISABLED"),
2166 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_DISABLED" ) ),
2167 tr( "MNU_SVTK_PRESELECTION_DISABLED" ), 0, this);
2168 anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_DISABLED"));
2169 anAction->setCheckable(true);
2170 connect(anAction, SIGNAL(activated()), aSignalMapper, SLOT(map()));
2171 aSignalMapper->setMapping( anAction, Preselection_Disabled );
2172 mgr->registerAction( anAction, DisablePreselectionId );
2174 QtxActionGroup* aPreselectionAction = new QtxActionGroup( this, true );
2175 aPreselectionAction->add( getAction( StandardPreselectionId ) );
2176 aPreselectionAction->add( getAction( DynamicPreselectionId ) );
2177 aPreselectionAction->add( getAction( DisablePreselectionId ) );
2178 mgr->registerAction( aPreselectionAction, PreselectionId );
2181 anAction = new QtxAction(tr("MNU_SVTK_ENABLE_SELECTION"),
2182 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SELECTION" ) ),
2183 tr( "MNU_SVTK_ENABLE_SELECTION" ), 0, this);
2184 anAction->setStatusTip(tr("DSC_SVTK_ENABLE_SELECTION"));
2185 anAction->setCheckable(true);
2186 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onEnableSelection(bool)));
2187 mgr->registerAction( anAction, EnableSelectionId );
2190 myStartAction = new QtxAction(tr("MNU_SVTK_RECORDING_START"),
2191 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_START" ) ),
2192 tr( "MNU_SVTK_RECORDING_START" ), 0, this);
2193 myStartAction->setStatusTip(tr("DSC_SVTK_RECORDING_START"));
2194 connect( myStartAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStartRecording() ) );
2195 mgr->registerAction( myStartAction, StartRecordingId );
2198 myPlayAction = new QtxAction(tr("MNU_SVTK_RECORDING_PLAY"),
2199 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PLAY" ) ),
2200 tr( "MNU_SVTK_RECORDING_PLAY" ), 0, this);
2201 myPlayAction->setStatusTip(tr("DSC_SVTK_RECORDING_PLAY"));
2202 myPlayAction->setEnabled( false );
2203 connect( myPlayAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPlayRecording() ) );
2204 mgr->registerAction( myPlayAction, PlayRecordingId );
2207 myPauseAction = new QtxAction(tr("MNU_SVTK_RECORDING_PAUSE"),
2208 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PAUSE" ) ),
2209 tr( "MNU_SVTK_RECORDING_PAUSE" ), 0, this);
2210 myPauseAction->setStatusTip(tr("DSC_SVTK_RECORDING_PAUSE"));
2211 myPauseAction->setEnabled( false );
2212 connect( myPauseAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPauseRecording() ) );
2213 mgr->registerAction( myPauseAction, PauseRecordingId );
2216 myStopAction = new QtxAction(tr("MNU_SVTK_RECORDING_STOP"),
2217 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_STOP" ) ),
2218 tr( "MNU_SVTK_RECORDING_STOP" ), 0, this);
2219 myStopAction->setStatusTip(tr("DSC_SVTK_RECORDING_STOP"));
2220 myStopAction->setEnabled( false );
2221 connect( myStopAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStopRecording() ) );
2222 mgr->registerAction( myStopAction, StopRecordingId );
2226 Creates toolbar of svtk main window
2228 void SVTK_ViewWindow::createToolBar()
2230 QtxActionToolMgr* mgr = toolMgr();
2232 mgr->append( DumpId, myToolBar );
2233 mgr->append( SwitchInteractionStyleId, myToolBar );
2234 mgr->append( SwitchZoomingStyleId, myToolBar );
2236 mgr->append( mgr->separator(), myToolBar );
2238 mgr->append( PreselectionId, myToolBar );
2239 mgr->append( EnableSelectionId, myToolBar );
2241 mgr->append( mgr->separator(), myToolBar );
2243 mgr->append( ViewTrihedronId, myToolBar );
2245 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
2246 aScaleAction->insertAction( getAction( FitAllId ) );
2247 aScaleAction->insertAction( getAction( FitRectId ) );
2248 aScaleAction->insertAction( getAction( ZoomId ) );
2249 mgr->append( aScaleAction, myToolBar );
2251 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
2252 aPanningAction->insertAction( getAction( PanId ) );
2253 aPanningAction->insertAction( getAction( GlobalPanId ) );
2254 mgr->append( aPanningAction, myToolBar );
2256 mgr->append( ChangeRotationPointId, myToolBar );
2258 mgr->append( RotationId, myToolBar );
2260 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
2261 aViewsAction->insertAction( getAction( FrontId ) );
2262 aViewsAction->insertAction( getAction( BackId ) );
2263 aViewsAction->insertAction( getAction( TopId ) );
2264 aViewsAction->insertAction( getAction( BottomId ) );
2265 aViewsAction->insertAction( getAction( LeftId ) );
2266 aViewsAction->insertAction( getAction( RightId ) );
2267 mgr->append( aViewsAction, myToolBar );
2269 mgr->append( AntiClockWiseId, myToolBar );
2270 mgr->append( ClockWiseId, myToolBar );
2272 mgr->append( ResetId, myToolBar );
2274 mgr->append( UpdateRate, myToolBar );
2275 mgr->append( NonIsometric, myToolBar );
2276 mgr->append( GraduatedAxes, myToolBar );
2278 mgr->append( ViewParametersId, myToolBar );
2279 mgr->append( SynchronizeId, myToolBar );
2281 mgr->append( toolMgr()->separator(), myToolBar );
2283 mgr->append( ParallelModeId, myToolBar );
2284 mgr->append( ProjectionModeId, myToolBar );
2286 mgr->append( StartRecordingId, myRecordingToolBar );
2287 mgr->append( PlayRecordingId, myRecordingToolBar );
2288 mgr->append( PauseRecordingId, myRecordingToolBar );
2289 mgr->append( StopRecordingId, myRecordingToolBar );
2292 void SVTK_ViewWindow::onUpdateRate(bool theIsActivate)
2295 myUpdateRateDlg->Update();
2296 myUpdateRateDlg->show();
2298 myUpdateRateDlg->hide();
2301 void SVTK_ViewWindow::onNonIsometric(bool theIsActivate)
2304 myNonIsometricDlg->Update();
2305 myNonIsometricDlg->show();
2307 myNonIsometricDlg->hide();
2310 void SVTK_ViewWindow::onGraduatedAxes(bool theIsActivate)
2313 myCubeAxesDlg->Update();
2314 myCubeAxesDlg->show();
2316 myCubeAxesDlg->hide();
2320 Starts rotation transformation
2322 void SVTK_ViewWindow::activateRotation()
2324 myEventDispatcher->InvokeEvent(SVTK::StartRotate,0);
2329 Starts panning transformation
2331 void SVTK_ViewWindow::activatePanning()
2333 myEventDispatcher->InvokeEvent(SVTK::StartPan,0);
2337 Starts zoom transformation
2339 void SVTK_ViewWindow::activateZoom()
2341 myEventDispatcher->InvokeEvent(SVTK::StartZoom,0);
2345 Starts window fit transformation
2347 void SVTK_ViewWindow::activateWindowFit()
2349 myEventDispatcher->InvokeEvent(SVTK::StartFitArea,0);
2353 Starts global panning transformation
2355 void SVTK_ViewWindow::activateGlobalPanning()
2357 myEventDispatcher->InvokeEvent(SVTK::StartGlobalPan,0);
2360 void SVTK_ViewWindow::onStartRecording()
2362 myRecorder->CheckExistAVIMaker();
2363 if (myRecorder->ErrorStatus()) {
2364 SUIT_MessageBox::warning(this, tr("ERROR"), tr("MSG_NO_AVI_MAKER") );
2367 SVTK_RecorderDlg* aRecorderDlg = new SVTK_RecorderDlg( this, myRecorder );
2369 if( !aRecorderDlg->exec() )
2372 myStartAction->setEnabled( false );
2373 myPlayAction->setEnabled( false );
2374 myPauseAction->setEnabled( true );
2375 myStopAction->setEnabled( true );
2377 // to prevent resizing the window while recording
2378 myPreRecordingMinSize = minimumSize();
2379 myPreRecordingMaxSize = maximumSize();
2380 setFixedSize( size() );
2382 myRecorder->Record();
2386 void SVTK_ViewWindow::onPlayRecording()
2388 myStartAction->setEnabled( false );
2389 myPlayAction->setEnabled( false );
2390 myPauseAction->setEnabled( true );
2391 myStopAction->setEnabled( true );
2393 myRecorder->Pause();
2396 void SVTK_ViewWindow::onPauseRecording()
2398 myStartAction->setEnabled( false );
2399 myPlayAction->setEnabled( true );
2400 myPauseAction->setEnabled( false );
2401 myStopAction->setEnabled( true );
2403 myRecorder->Pause();
2406 void SVTK_ViewWindow::onStopRecording()
2408 myStartAction->setEnabled( true );
2409 myPlayAction->setEnabled( false );
2410 myPauseAction->setEnabled( false );
2411 myStopAction->setEnabled( false );
2415 setMinimumSize( myPreRecordingMinSize );
2416 setMaximumSize( myPreRecordingMaxSize );
2420 To invoke a VTK event on SVTK_RenderWindowInteractor instance
2422 void SVTK_ViewWindow::InvokeEvent(unsigned long theEvent, void* theCallData)
2424 GetInteractor()->InvokeEvent(theEvent,theCallData);
2428 Modify view parameters
2430 void SVTK_ViewWindow::onViewParameters(bool theIsActivate)
2433 myViewParameterDlg->addObserver();
2434 myViewParameterDlg->show();
2436 myViewParameterDlg->hide();
2440 Custom show event handler
2442 void SVTK_ViewWindow::showEvent( QShowEvent * theEvent )
2444 emit Show( theEvent );
2448 Custom hide event handler
2450 void SVTK_ViewWindow::hideEvent( QHideEvent * theEvent )
2452 emit Hide( theEvent );
2456 Emit transformed signal.
2458 void SVTK_ViewWindow::emitTransformed() {
2465 void SVTK_ViewWindow::ProcessEvents(vtkObject* vtkNotUsed(theObject),
2466 unsigned long theEvent,
2467 void* theClientData,
2470 SVTK_ViewWindow* self = reinterpret_cast<SVTK_ViewWindow*>(theClientData);
2472 self->emitTransformed();
2476 Get camera properties for the SVTK view window.
2477 \return shared pointer on camera properties.
2479 SUIT_CameraProperties SVTK_ViewWindow::cameraProperties()
2481 SUIT_CameraProperties aProps;
2484 vtkCamera* aCamera = getRenderer()->GetActiveCamera();
2488 aProps.setDimension( SUIT_CameraProperties::Dim3D );
2489 if ( toolMgr()->action( ParallelModeId ) ) {
2490 if ( toolMgr()->action( ParallelModeId )->isChecked() )
2491 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
2493 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
2496 double aFocalPoint[3];
2497 double aPosition[3];
2499 double anAxialScale[3];
2501 aCamera->OrthogonalizeViewUp();
2502 aCamera->GetFocalPoint( aFocalPoint );
2503 aCamera->GetPosition( aPosition );
2504 aCamera->GetViewUp( aViewUp );
2506 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2507 aProps.setPosition( aPosition[0], aPosition[1], aPosition[2] );
2508 aProps.setViewUp( aViewUp[0], aViewUp[1], aViewUp[2] );
2509 aProps.setMappingScale( aCamera->GetParallelScale() * 2.0 );
2511 if ( aProps.getProjection() == SUIT_CameraProperties::PrjPerspective )
2513 aProps.setViewAngle( aCamera->GetViewAngle() );
2516 GetRenderer()->GetScale( anAxialScale );
2517 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2524 This implementation synchronizes camera propreties.
2526 void SVTK_ViewWindow::synchronize( SUIT_ViewWindow* theView )
2528 bool blocked = blockSignals( true );
2530 SUIT_CameraProperties aProps = theView->cameraProperties();
2531 if ( !cameraProperties().isCompatible( aProps ) ) {
2532 // other view, this one is being currently synchronized to, seems has become incompatible
2533 // we have to break synchronization
2539 vtkCamera* aCamera = getRenderer()->GetActiveCamera();
2541 double aFocalPoint[3];
2542 double aPosition[3];
2544 double anAxialScale[3];
2546 // get common properties
2547 aProps.getViewUp( aViewUp[0], aViewUp[1], aViewUp[2] );
2548 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
2549 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2550 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2552 // restore properties to the camera
2553 aCamera->SetViewUp( aViewUp );
2554 aCamera->SetPosition( aPosition );
2555 aCamera->SetFocalPoint( aFocalPoint );
2556 aCamera->SetParallelScale( aProps.getMappingScale() / 2.0 );
2558 if ( aProps.getProjection() == SUIT_CameraProperties::PrjPerspective )
2560 aCamera->SetViewAngle( aProps.getViewAngle() );
2563 GetRenderer()->SetScale( anAxialScale );
2565 getRenderer()->ResetCameraClippingRange();
2568 blockSignals( blocked );