1 // Copyright (C) 2007-2012 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 <QXmlStreamWriter>
39 #include <QXmlStreamReader>
40 #include <QXmlStreamAttributes>
42 #include <vtkTextProperty.h>
43 #include <vtkActorCollection.h>
44 #include <vtkRenderWindow.h>
45 #include <vtkRenderer.h>
46 #include <vtkCamera.h>
47 #include <vtkPointPicker.h>
48 #include <vtkCellPicker.h>
49 #include <vtkAxisActor2D.h>
50 #include <vtkGL2PSExporter.h>
51 #include <vtkInteractorStyle.h>
52 #include <vtkProperty.h>
53 #include <vtkCallbackCommand.h>
54 #include <vtkJPEGReader.h>
55 #include <vtkBMPReader.h>
56 #include <vtkTIFFReader.h>
57 #include <vtkPNGReader.h>
58 #include <vtkMetaImageReader.h>
59 #include <vtkImageMapToColors.h>
60 #include <vtkTexture.h>
62 #include "QtxAction.h"
64 #include "SUIT_Session.h"
65 #include "SUIT_MessageBox.h"
66 #include "SUIT_Accel.h"
67 #include "SUIT_Tools.h"
68 #include "SUIT_ResourceMgr.h"
69 #include "SUIT_Accel.h"
70 #include "SUIT_OverrideCursor.h"
71 #include "SUIT_ViewManager.h"
72 #include "QtxActionToolMgr.h"
73 #include "QtxMultiAction.h"
75 #include "VTKViewer_Utilities.h"
76 #include "VTKViewer_Trihedron.h"
78 #include "SVTK_View.h"
79 //#include "SVTK_MainWindow.h"
80 #include "SVTK_Selector.h"
82 #include "SVTK_Event.h"
83 #include "SVTK_Renderer.h"
84 #include "SVTK_ViewWindow.h"
85 #include "SVTK_InteractorStyle.h"
86 #include "SVTK_RenderWindowInteractor.h"
87 #include "SVTK_GenericRenderWindowInteractor.h"
88 #include "SVTK_CubeAxesActor2D.h"
89 #include "SVTK_ComboAction.h"
90 #include "SVTK_KeyFreeInteractorStyle.h"
91 #include "SVTK_Selector.h"
92 #include "SVTK_Recorder.h"
93 #include "SVTK_RecorderDlg.h"
95 #include "vtkPVAxesWidget.h"
96 #include "vtkPVAxesActor.h"
98 #include "SALOME_ListIteratorOfListIO.hxx"
100 #include "VTKViewer_Algorithm.h"
101 #include "SVTK_Functor.h"
103 #include <OpenGLUtils_FrameBuffer.h>
108 int convertAction( const int accelAction )
110 switch ( accelAction ) {
111 case SUIT_Accel::PanLeft : return SVTK::PanLeftEvent;
112 case SUIT_Accel::PanRight : return SVTK::PanRightEvent;
113 case SUIT_Accel::PanUp : return SVTK::PanUpEvent;
114 case SUIT_Accel::PanDown : return SVTK::PanDownEvent;
115 case SUIT_Accel::ZoomIn : return SVTK::ZoomInEvent;
116 case SUIT_Accel::ZoomOut : return SVTK::ZoomOutEvent;
117 case SUIT_Accel::RotateLeft : return SVTK::RotateLeftEvent;
118 case SUIT_Accel::RotateRight : return SVTK::RotateRightEvent;
119 case SUIT_Accel::RotateUp : return SVTK::RotateUpEvent;
120 case SUIT_Accel::RotateDown : return SVTK::RotateDownEvent;
133 SVTK_ViewWindow::SVTK_ViewWindow(SUIT_Desktop* theDesktop):
134 SUIT_ViewWindow(theDesktop),
136 myDumpImage(QImage()),
137 myKeyFreeInteractorStyle(SVTK_KeyFreeInteractorStyle::New()),
138 myEventCallbackCommand(vtkCallbackCommand::New())
140 setWindowFlags( windowFlags() & ~Qt::Window );
141 // specific of vtkSmartPointer
142 myKeyFreeInteractorStyle->Delete();
146 To initialize #SVTK_ViewWindow instance
148 void SVTK_ViewWindow::Initialize(SVTK_ViewModelBase* theModel)
150 myInteractor = new SVTK_RenderWindowInteractor(this,"SVTK_RenderWindowInteractor");
152 SVTK_Selector* aSelector = SVTK_Selector::New();
153 aSelector->SetDynamicPreSelection( SUIT_Session::session()->resourceMgr()->
154 booleanValue( "VTKViewer", "dynamic_preselection", true ) );
156 SVTK_GenericRenderWindowInteractor* aDevice = SVTK_GenericRenderWindowInteractor::New();
157 aDevice->SetRenderWidget(myInteractor);
158 aDevice->SetSelector(aSelector);
160 SVTK_Renderer* aRenderer = SVTK_Renderer::New();
161 aRenderer->Initialize(aDevice,aSelector);
163 myInteractor->Initialize(aDevice,aRenderer,aSelector);
169 myToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_LABEL"), false, Qt::AllToolBarAreas, -1, this );
170 myRecordingToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_RECORD_LABEL"), false, Qt::AllToolBarAreas, -1, this );
172 createActions( SUIT_Session::session()->resourceMgr() );
175 SetEventDispatcher(myInteractor->GetDevice());
176 myInteractor->setBackgroundRole( QPalette::NoRole );//NoBackground
177 myInteractor->setFocusPolicy(Qt::StrongFocus);
178 myInteractor->setFocus();
179 setFocusProxy(myInteractor);
181 myUpdateRateDlg = new SVTK_UpdateRateDlg( getAction( UpdateRate ), this, "SVTK_UpdateRateDlg" );
182 myNonIsometricDlg = new SVTK_NonIsometricDlg( getAction( NonIsometric ), this, "SVTK_NonIsometricDlg" );
183 myCubeAxesDlg = new SVTK_CubeAxesDlg( getAction( GraduatedAxes ), this, "SVTK_CubeAxesDlg" );
184 myCubeAxesDlg->initialize();
185 mySetRotationPointDlg = new SVTK_SetRotationPointDlg
186 ( getAction( ChangeRotationPointId ), this, "SVTK_SetRotationPointDlg" );
187 myViewParameterDlg = new SVTK_ViewParameterDlg
188 ( getAction( ViewParametersId ), this, "SVTK_ViewParameterDlg" );
190 myDefaultInteractorStyle = SVTK_InteractorStyle::New();
191 myInteractor->PushInteractorStyle(myDefaultInteractorStyle);
192 myDefaultInteractorStyle->Delete();
194 myRecorder = SVTK_Recorder::New();
196 myRecorder->SetNbFPS( 17.3 );
197 myRecorder->SetQuality( 100 );
198 myRecorder->SetProgressiveMode( true );
199 myRecorder->SetUseSkippedFrames( true );
200 myRecorder->SetRenderWindow( myInteractor->getRenderWindow() );
202 setCentralWidget(myInteractor);
204 myAxesWidget = vtkPVAxesWidget::New();
205 myAxesWidget->SetParentRenderer(aRenderer->GetDevice());
206 myAxesWidget->SetViewport(0, 0, 0.25, 0.25);
207 myAxesWidget->SetInteractor(myInteractor->GetDevice());
208 myAxesWidget->SetEnabled(1);
209 myAxesWidget->SetInteractive(0);
211 vtkPVAxesActor* anAxesActor = myAxesWidget->GetAxesActor();
212 anAxesActor->GetXAxisTipProperty()->SetColor( 1.0, 0.0, 0.0 );
213 anAxesActor->GetXAxisShaftProperty()->SetColor( 1.0, 0.0, 0.0 );
214 anAxesActor->GetXAxisLabelProperty()->SetColor( 1.0, 0.0, 0.0 );
215 anAxesActor->GetYAxisTipProperty()->SetColor( 0.0, 1.0, 0.0 );
216 anAxesActor->GetYAxisShaftProperty()->SetColor( 0.0, 1.0, 0.0 );
217 anAxesActor->GetYAxisLabelProperty()->SetColor( 0.0, 1.0, 0.0 );
218 anAxesActor->GetZAxisTipProperty()->SetColor( 0.0, 0.0, 1.0 );
219 anAxesActor->GetZAxisShaftProperty()->SetColor( 0.0, 0.0, 1.0 );
220 anAxesActor->GetZAxisLabelProperty()->SetColor( 0.0, 0.0, 1.0 );
222 myView = new SVTK_View(this);
223 Initialize(myView,theModel);
226 myEventCallbackCommand->SetClientData(this);
227 myEventCallbackCommand->SetCallback(SVTK_ViewWindow::ProcessEvents);
228 myEventCallbackCommand->Delete();
230 GetInteractor()->GetInteractorStyle()->AddObserver(SVTK::OperationFinished,
231 myEventCallbackCommand.GetPointer(), 0.0);
235 myInteractor->getRenderWindow()->Render();
236 setBackground( Qtx::BackgroundData( Qt::black ) ); // set default background
241 To initialize #SVTK_ViewWindow instance
243 void SVTK_ViewWindow::Initialize(SVTK_View* theView,
244 SVTK_ViewModelBase* theModel)
246 connect(theView,SIGNAL(KeyPressed(QKeyEvent*)),
247 this,SLOT(onKeyPressed(QKeyEvent*)) );
248 connect(theView,SIGNAL(KeyReleased(QKeyEvent*)),
249 this,SLOT(onKeyReleased(QKeyEvent*)));
250 connect(theView,SIGNAL(MouseButtonPressed(QMouseEvent*)),
251 this,SLOT(onMousePressed(QMouseEvent*)));
252 connect(theView,SIGNAL(MouseButtonReleased(QMouseEvent*)),
253 this,SLOT(onMouseReleased(QMouseEvent*)));
254 connect(theView,SIGNAL(MouseDoubleClicked(QMouseEvent*)),
255 this,SLOT(onMouseDoubleClicked(QMouseEvent*)));
256 connect(theView,SIGNAL(MouseMove(QMouseEvent*)),
257 this,SLOT(onMouseMoving(QMouseEvent*)));
258 connect(theView,SIGNAL(contextMenuRequested(QContextMenuEvent*)),
259 this,SIGNAL(contextMenuRequested(QContextMenuEvent *)));
260 connect(theView,SIGNAL(selectionChanged()),
261 theModel,SLOT(onSelectionChanged()));
267 SVTK_ViewWindow::~SVTK_ViewWindow()
269 myRecorder->Delete();
270 myAxesWidget->Delete();
275 \return corresponding view
277 SVTK_View* SVTK_ViewWindow::getView()
283 \return corresponding vtk render window
285 vtkRenderWindow* SVTK_ViewWindow::getRenderWindow()
287 return GetInteractor()->getRenderWindow();
291 \return corresponding vtk render window interactor
293 SVTK_RenderWindowInteractor* SVTK_ViewWindow::GetInteractor() const
299 \return corresponding vtk render window interactor
301 vtkRenderWindowInteractor* SVTK_ViewWindow::getInteractor() const
303 return myInteractor->GetDevice();
307 \return corresponding vtk renderer
309 vtkRenderer* SVTK_ViewWindow::getRenderer() const
311 return GetInteractor()->getRenderer();
315 Redirect the request to SVTK_RenderWindowInteractor::GetRenderer
317 SVTK_Renderer* SVTK_ViewWindow::GetRenderer() const
319 return GetInteractor()->GetRenderer();
323 \return corresponding vtk selector
325 SVTK_Selector* SVTK_ViewWindow::GetSelector() const
327 return GetInteractor()->GetSelector();
331 Processes transformation "front view"
333 void SVTK_ViewWindow::onFrontView()
335 GetRenderer()->OnFrontView();
337 emit transformed( this );
341 Processes transformation "back view"
343 void SVTK_ViewWindow::onBackView()
345 GetRenderer()->OnBackView();
347 emit transformed( this );
351 Processes transformation "top view"
353 void SVTK_ViewWindow::onTopView()
355 GetRenderer()->OnTopView();
357 emit transformed( this );
361 Processes transformation "bottom view"
363 void SVTK_ViewWindow::onBottomView()
365 GetRenderer()->OnBottomView();
367 emit transformed( this );
371 Processes transformation "left view"
373 void SVTK_ViewWindow::onLeftView()
375 GetRenderer()->OnLeftView();
377 emit transformed( this );
381 Processes transformation "right view"
383 void SVTK_ViewWindow::onRightView()
385 GetRenderer()->OnRightView();
387 emit transformed( this );
391 \brief Rotate view 90 degrees clockwise
393 void SVTK_ViewWindow::onClockWiseView()
395 GetRenderer()->onClockWiseView();
397 emit transformed( this );
401 \brief Rotate view 90 degrees conterclockwise
403 void SVTK_ViewWindow::onAntiClockWiseView()
405 GetRenderer()->onAntiClockWiseView();
407 emit transformed( this );
411 Processes transformation "reset view": sets default orientation of viewport camera
413 void SVTK_ViewWindow::onResetView()
415 GetRenderer()->OnResetView();
417 emit transformed( this );
421 Processes transformation "fit all"
423 void SVTK_ViewWindow::onFitAll()
425 GetRenderer()->OnFitAll();
427 emit transformed( this );
431 SLOT: called if selection is changed
433 void SVTK_ViewWindow::onSelectionChanged()
435 myView->onSelectionChanged();
439 Change selection mode
440 \param theMode - new selection mode
442 void SVTK_ViewWindow::SetSelectionMode(Selection_Mode theMode)
444 GetSelector()->SetSelectionMode(theMode);
448 \return selection mode
450 Selection_Mode SVTK_ViewWindow::SelectionMode() const
452 return GetSelector()->SelectionMode();
456 Unhilights all objects in viewer
458 void SVTK_ViewWindow::unHighlightAll()
460 myView->unHighlightAll();
464 Hilights/unhilights object in viewer
465 \param theIO - object to be updated
466 \param theIsHighlight - if it is true, object will be hilighted, otherwise it will be unhilighted
467 \param theIsUpdate - update current viewer
469 void SVTK_ViewWindow::highlight(const Handle(SALOME_InteractiveObject)& theIO,
473 myView->highlight( theIO, theIsHighlight, theIsUpdate );
477 \return true if object is in viewer or in collector
478 \param theIO - object to be checked
480 bool SVTK_ViewWindow::isInViewer( const Handle(SALOME_InteractiveObject)& theIO )
482 return myView->isInViewer( theIO );
486 \return true if object is displayed in viewer
487 \param theIO - object to be checked
489 bool SVTK_ViewWindow::isVisible( const Handle(SALOME_InteractiveObject)& theIO )
491 return myView->isVisible( theIO );
496 \param theEntry - entry that corresponds to intractive objects
498 Handle(SALOME_InteractiveObject) SVTK_ViewWindow::FindIObject(const char* theEntry)
500 return myView->FindIObject(theEntry);
505 \param theIO - object
506 \param theImmediatly - update viewer
508 void SVTK_ViewWindow::Display(const Handle(SALOME_InteractiveObject)& theIO,
511 myView->Display(theIO,theImmediatly);
516 \param theIO - object
517 \param theImmediatly - update viewer
519 void SVTK_ViewWindow::Erase(const Handle(SALOME_InteractiveObject)& theIO,
522 myView->Erase(theIO,theImmediatly);
526 Display only passed object
527 \param theIO - object
529 void SVTK_ViewWindow::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIO)
531 myView->DisplayOnly(theIO);
535 Display all objects in view
537 void SVTK_ViewWindow::DisplayAll()
539 myView->DisplayAll();
543 Erase all objects in view
545 void SVTK_ViewWindow::EraseAll()
551 Sets background color [obsolete]
552 \param color - new background color
554 void SVTK_ViewWindow::setBackgroundColor( const QColor& c )
556 Qtx::BackgroundData bg = background();
562 \return background color of viewer [obsolete]
564 QColor SVTK_ViewWindow::backgroundColor() const
566 return background().color();
571 \param bgData - new background data
573 void SVTK_ViewWindow::setBackground( const Qtx::BackgroundData& bgData )
577 if ( bgData.isValid() ) {
578 switch ( bgData.mode() ) {
579 case Qtx::ColorBackground:
581 QColor c = bgData.color();
583 // show solid-colored background
584 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
585 getRenderer()->SetGradientBackground( false ); // cancel gradient mode
586 getRenderer()->SetBackground( c.red()/255.0,
588 c.blue()/255.0 ); // set background color
593 case Qtx::SimpleGradientBackground:
596 int type = bgData.gradient( c1, c2 );
602 // show two-color gradient background
603 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
604 getRenderer()->SetGradientBackground( true ); // switch to gradient mode
606 VTKViewer_OpenGLRenderer* aRenderer =
607 VTKViewer_OpenGLRenderer::SafeDownCast( getRenderer() );
610 aRenderer->SetGradientType( type );
611 aRenderer->SetBackground( c1.redF(), c1.greenF(), c1.blueF() );
612 aRenderer->SetBackground2( c2.redF(), c2.greenF(), c2.blueF() );
618 case Qtx::CustomGradientBackground:
620 // NOT IMPLEMENTED YET
621 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
622 getRenderer()->SetGradientBackground( false ); // cancel gradient mode
629 if ( bgData.isTextureShown() ) {
631 int textureMode = bgData.texture( fileName );
632 QFileInfo fi( fileName );
633 if ( !fileName.isEmpty() && fi.exists() ) {
634 // read texture from file
635 QString extension = fi.suffix().toLower();
636 vtkImageReader2* aReader = 0;
637 if ( extension == "jpg" || extension == "jpeg" )
638 aReader = vtkJPEGReader::New();
639 else if ( extension == "bmp" )
640 aReader = vtkBMPReader::New();
641 else if ( extension == "tif" || extension == "tiff" )
642 aReader = vtkTIFFReader::New();
643 else if ( extension == "png" )
644 aReader = vtkPNGReader::New();
645 else if ( extension == "mhd" || extension == "mha" )
646 aReader = vtkMetaImageReader::New();
649 aReader->SetFileName( fi.absoluteFilePath().toLatin1().constData() );
651 VTKViewer_Texture* aTexture = VTKViewer_Texture::New();
652 vtkImageMapToColors* aMap = 0;
653 vtkAlgorithmOutput* anOutput;
655 // special processing for BMP reader
656 vtkBMPReader* aBMPReader = (vtkBMPReader*)aReader;
658 // Special processing for BMP file
659 aBMPReader->SetAllow8BitBMP(1);
661 aMap = vtkImageMapToColors::New();
662 aMap->SetInputConnection( aBMPReader->GetOutputPort() );
663 aMap->SetLookupTable( (vtkScalarsToColors*)aBMPReader->GetLookupTable() );
664 aMap->SetOutputFormatToRGB();
666 anOutput = aMap->GetOutputPort();
671 anOutput = aReader->GetOutputPort( 0 );
672 aTexture->SetInputConnection( anOutput );
674 // VSR: Currently, VTK only supports Stretch mode, so below code will give
675 // the same results for all modes
676 switch ( textureMode ) {
677 case Qtx::TileTexture:
678 aTexture->SetPosition((int)VTKViewer_Texture::Tiled);
680 case Qtx::StretchTexture:
681 aTexture->SetPosition((int)VTKViewer_Texture::Stretched);
683 case Qtx::CenterTexture:
684 aTexture->SetPosition((int)VTKViewer_Texture::Centered);
688 // show textured background
689 getRenderer()->SetTexturedBackground( true );
690 getRenderer()->SetBackgroundTexture( aTexture );
692 // clean-up resources
703 myBackground = bgData;
707 \return background data of viewer
709 Qtx::BackgroundData SVTK_ViewWindow::background() const
716 Redirect the request to SVTK_RenderWindowInteractor::GetInteractorStyle
718 vtkInteractorStyle* SVTK_ViewWindow::GetInteractorStyle() const
720 return GetInteractor()->GetInteractorStyle();
724 Redirect the request to SVTK_RenderWindowInteractor::PushInteractorStyle
726 void SVTK_ViewWindow::PushInteractorStyle(vtkInteractorStyle* theStyle)
728 GetInteractor()->PushInteractorStyle(theStyle);
732 Redirect the request to SVTK_RenderWindowInteractor::PopInteractorStyle
734 void SVTK_ViewWindow::PopInteractorStyle()
736 GetInteractor()->PopInteractorStyle();
740 Updates current viewer
742 void SVTK_ViewWindow::Repaint(bool theUpdateTrihedron)
744 if(theUpdateTrihedron)
745 GetRenderer()->OnAdjustTrihedron();
747 GetInteractor()->update();
749 SVTK_InteractorStyle* aStyle = (SVTK_InteractorStyle*)getInteractor()->GetInteractorStyle();
755 Redirect the request to #SVTK_Renderer::GetScale
757 void SVTK_ViewWindow::GetScale( double theScale[3] )
759 GetRenderer()->GetScale( theScale );
763 Redirect the request to #SVTK_Renderer::SetScale
765 void SVTK_ViewWindow::SetScale( double theScale[3] )
767 GetRenderer()->SetScale( theScale );
769 emit transformed( this );
773 Redirect the request to #SVTK_Renderer::IsTrihedronDisplayed
775 bool SVTK_ViewWindow::isTrihedronDisplayed()
777 return GetRenderer()->IsTrihedronDisplayed();
781 Redirect the request to #SVTK_Renderer::IsCubeAxesDisplayed
783 bool SVTK_ViewWindow::isCubeAxesDisplayed()
785 return GetRenderer()->IsCubeAxesDisplayed();
789 Redirect the request to #SVTK_Renderer::OnViewTrihedron
791 void SVTK_ViewWindow::onViewTrihedron()
793 GetRenderer()->OnViewTrihedron();
798 Redirect the request to #SVTK_Renderer::OnViewCubeAxes
800 void SVTK_ViewWindow::onViewCubeAxes()
802 GetRenderer()->OnViewCubeAxes();
807 Redirect the request to #SVTK_Renderer::GetTrihedron
809 VTKViewer_Trihedron* SVTK_ViewWindow::GetTrihedron()
811 return GetRenderer()->GetTrihedron();
815 Redirect the request to #SVTK_Renderer::GetCubeAxes
817 SVTK_CubeAxesActor2D* SVTK_ViewWindow::GetCubeAxes()
819 return GetRenderer()->GetCubeAxes();
823 \return trihedron size
825 vtkFloatingPointType SVTK_ViewWindow::GetTrihedronSize() const
827 return GetRenderer()->GetTrihedronSize();
832 \param theMode - projection mode ( 0 - orthogonal, 1 - perspective )
834 void SVTK_ViewWindow::SetProjectionMode(const int theMode)
836 activateProjectionMode( theMode );
841 Set the gravity center as a focal point
843 void SVTK_ViewWindow::activateSetFocalPointGravity()
845 myEventDispatcher->InvokeEvent(SVTK::SetFocalPointGravity, 0);
849 Set the selected point as a focal point
851 void SVTK_ViewWindow::activateSetFocalPointSelected()
853 myEventDispatcher->InvokeEvent(SVTK::SetFocalPointSelected, 0);
857 Set the point selected by user as a focal point
859 void SVTK_ViewWindow::activateStartFocalPointSelection()
861 myEventDispatcher->InvokeEvent(SVTK::StartFocalPointSelection,0);
864 void SVTK_ViewWindow::activateProjectionMode(int theMode)
867 toolMgr()->action( ProjectionModeId )->setChecked( true );
869 toolMgr()->action( ParallelModeId )->setChecked( true );
873 Sets actual interaction style
874 \param theStyle - type of interaction style ( 0 - standard, 1 - keyboard free )
876 void SVTK_ViewWindow::SetInteractionStyle(const int theStyle)
878 onSwitchInteractionStyle( theStyle==1 );
882 Sets actual zooming style
883 \param theStyle - type of zooming style ( 0 - standard, 1 - advanced (at cursor) )
885 void SVTK_ViewWindow::SetZoomingStyle(const int theStyle)
887 onSwitchZoomingStyle( theStyle==1 );
891 Switch dynamic preselection on / off
892 \param theDynPreselection - dynamic pre-selection mode
894 void SVTK_ViewWindow::SetDynamicPreSelection( bool theDynPreselection )
896 onSwitchDynamicPreSelection( theDynPreselection );
900 Switches "keyboard free" interaction style on/off
902 void SVTK_ViewWindow::onSwitchInteractionStyle(bool theOn)
905 // check if style is already set
906 if ( GetInteractorStyle() != myKeyFreeInteractorStyle.GetPointer() )
908 // keep the same style extensions
909 SVTK_InteractorStyle* aStyle = (SVTK_InteractorStyle*)GetInteractorStyle();
911 myKeyFreeInteractorStyle->SetControllerIncrement(aStyle->ControllerIncrement());
912 myKeyFreeInteractorStyle->SetControllerOnKeyDown(aStyle->ControllerOnKeyDown());
915 PushInteractorStyle(myKeyFreeInteractorStyle.GetPointer());
919 // pop only key free style
920 if ( GetInteractorStyle() == myKeyFreeInteractorStyle.GetPointer() )
921 PopInteractorStyle();
924 // update action state if method is called outside
925 QtxAction* a = getAction( SwitchInteractionStyleId );
926 if ( a->isChecked() != theOn ) a->setChecked( theOn );
930 Toogles advanced zooming style (relatively to the cursor position) on/off
932 void SVTK_ViewWindow::onSwitchZoomingStyle( bool theOn )
934 if( myDefaultInteractorStyle.GetPointer() )
935 myDefaultInteractorStyle->SetAdvancedZoomingEnabled( theOn );
936 if( myKeyFreeInteractorStyle.GetPointer() )
937 myKeyFreeInteractorStyle->SetAdvancedZoomingEnabled( theOn );
939 // update action state if method is called outside
940 QtxAction* a = getAction( SwitchZoomingStyleId );
941 if ( a->isChecked() != theOn )
942 a->setChecked( theOn );
946 Toogles dynamic preselection on/off
948 void SVTK_ViewWindow::onSwitchDynamicPreSelection( bool theOn )
950 GetSelector()->SetDynamicPreSelection( theOn );
952 // update action state if method is called outside
953 QtxAction* a = getAction( SwitchDynamicPreselectionId );
954 if ( a->isChecked() != theOn )
955 a->setChecked( theOn );
959 Sets incremental speed
960 \param theValue - new incremental speed
961 \param theMode - modification mode
963 void SVTK_ViewWindow::SetIncrementalSpeed(const int theValue, const int theMode)
965 if ( (SVTK_InteractorStyle*)GetInteractorStyle() )
966 ((SVTK_InteractorStyle*)GetInteractorStyle())->SetIncrementSpeed(theValue, theMode);
970 Sets spacemouse buttons for the functions
971 \param theBtn1 - spacemouse button for the "decrease speed increment"
972 \param theBtn2 - spacemouse button for the "increase speed increment"
973 \param theBtn3 - spacemouse button for the "dominant combined switch"
975 void SVTK_ViewWindow::SetSpacemouseButtons(const int theBtn1,
980 myEventDispatcher->InvokeEvent(SVTK::SetSMDecreaseSpeedEvent, &val);
982 myEventDispatcher->InvokeEvent(SVTK::SetSMIncreaseSpeedEvent, &val);
984 myEventDispatcher->InvokeEvent(SVTK::SetSMDominantCombinedSwitchEvent, &val);
989 \param theSize - new trihedron size
990 \param theRelative - trihedron relativeness
992 void SVTK_ViewWindow::SetTrihedronSize(const vtkFloatingPointType theSize, const bool theRelative)
994 GetRenderer()->SetTrihedronSize(theSize, theRelative);
998 /*! If parameter theIsForcedUpdate is true, recalculate parameters for
999 * trihedron and cube axes, even if trihedron and cube axes is invisible.
1001 void SVTK_ViewWindow::AdjustTrihedrons(const bool theIsForcedUpdate)
1003 GetRenderer()->AdjustActors();
1008 Redirect the request to #SVTK_Renderer::OnAdjustTrihedron
1010 void SVTK_ViewWindow::onAdjustTrihedron()
1012 GetRenderer()->OnAdjustTrihedron();
1016 Redirect the request to #SVTK_Renderer::OnAdjustCubeAxes
1018 void SVTK_ViewWindow::onAdjustCubeAxes()
1020 GetRenderer()->OnAdjustCubeAxes();
1023 void SVTK_ViewWindow::synchronize(SVTK_ViewWindow* otherViewWindow )
1025 if ( otherViewWindow ) {
1026 bool blocked = blockSignals( true );
1027 doSetVisualParameters( otherViewWindow->getVisualParameters(), true );
1028 blockSignals( blocked );
1035 void SVTK_ViewWindow::onKeyPressed(QKeyEvent* event)
1037 emit keyPressed( this, event );
1043 void SVTK_ViewWindow::onKeyReleased(QKeyEvent* event)
1045 emit keyReleased( this, event );
1051 void SVTK_ViewWindow::onMousePressed(QMouseEvent* event)
1053 emit mousePressed(this, event);
1057 Emits mouse released
1059 void SVTK_ViewWindow::onMouseReleased(QMouseEvent* event)
1061 emit mouseReleased( this, event );
1067 void SVTK_ViewWindow::onMouseMoving(QMouseEvent* event)
1069 emit mouseMoving( this, event );
1073 Emits mouse double clicked
1075 void SVTK_ViewWindow::onMouseDoubleClicked( QMouseEvent* event )
1077 emit mouseDoubleClicked( this, event );
1081 Redirect the request to #SVTK_Renderer::AddActor
1083 void SVTK_ViewWindow::AddActor( VTKViewer_Actor* theActor,
1085 bool theIsAdjustActors )
1087 GetRenderer()->AddActor(theActor, theIsAdjustActors);
1090 emit actorAdded(theActor);
1094 Redirect the request to #SVTK_Renderer::RemoveActor
1096 void SVTK_ViewWindow::RemoveActor( VTKViewer_Actor* theActor,
1098 bool theIsAdjustActors )
1100 GetRenderer()->RemoveActor(theActor, theIsAdjustActors);
1103 emit actorRemoved(theActor);
1106 QImage SVTK_ViewWindow::dumpViewContent()
1108 vtkRenderWindow* aWindow = getRenderWindow();
1109 int* aSize = aWindow->GetSize();
1110 int aWidth = aSize[0];
1111 int aHeight = aSize[1];
1113 OpenGLUtils_FrameBuffer aFrameBuffer;
1114 if( aFrameBuffer.init( aWidth, aHeight ) )
1116 glPushAttrib( GL_VIEWPORT_BIT );
1117 glViewport( 0, 0, aWidth, aHeight );
1118 aFrameBuffer.bind();
1123 aFrameBuffer.unbind();
1126 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
1128 aFrameBuffer.bind();
1129 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
1130 aFrameBuffer.unbind();
1132 anImage = anImage.rgbSwapped();
1133 anImage = anImage.mirrored();
1137 // if frame buffers are unsupported, use old functionality
1138 unsigned char *aData =
1139 aWindow->GetRGBACharPixelData( 0, 0, aWidth-1, aHeight-1, 0 );
1141 QImage anImage( aData, aWidth, aHeight, QImage::Format_ARGB32 );
1143 anImage = anImage.rgbSwapped();
1144 anImage = anImage.mirrored();
1149 \return QImage, containing all scene rendering in window
1151 QImage SVTK_ViewWindow::dumpView()
1153 if( myDumpImage.isNull() )
1154 return dumpViewContent();
1160 QString SVTK_ViewWindow::filter() const
1162 return tr( "SVTK_IMAGE_FILES" );
1165 bool SVTK_ViewWindow::dumpViewToFormat( const QImage& img, const QString& fileName, const QString& format )
1167 if ( format != "PS" && format != "EPS" && format != "PDF" )
1168 return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
1170 SUIT_OverrideCursor wc;
1172 vtkGL2PSExporter *anExporter = vtkGL2PSExporter::New();
1173 anExporter->SetRenderWindow(getRenderWindow());
1175 if ( format == "PS" ) {
1176 anExporter->SetFileFormatToPS();
1177 anExporter->CompressOff();
1180 if ( format == "EPS" ) {
1181 anExporter->SetFileFormatToEPS();
1182 anExporter->CompressOff();
1185 if ( format == "PDF" ) {
1186 anExporter->SetFileFormatToPDF();
1189 QString aFilePrefix(fileName);
1190 QString anExtension(SUIT_Tools::extension(fileName));
1191 aFilePrefix.truncate(aFilePrefix.length() - 1 - anExtension.length());
1192 anExporter->SetFilePrefix(aFilePrefix.toLatin1().data());
1193 anExporter->Write();
1194 anExporter->Delete();
1200 \refresh QImage, containing all scene rendering in window
1202 void SVTK_ViewWindow::RefreshDumpImage()
1204 myDumpImage = dumpViewContent();
1208 Redirect the request to #SVTK_Renderer::SetSelectionProp
1210 void SVTK_ViewWindow::SetSelectionProp(const double& theRed,
1211 const double& theGreen,
1212 const double& theBlue,
1213 const int& theWidth)
1215 myView->SetSelectionProp(theRed,theGreen,theBlue,theWidth);
1219 Redirect the request to #SVTK_Renderer::SetSelectionProp
1221 void SVTK_ViewWindow::SetPreselectionProp(const double& theRed,
1222 const double& theGreen,
1223 const double& theBlue,
1224 const int& theWidth)
1226 myView->SetPreselectionProp(theRed,theGreen,theBlue,theWidth);
1230 Redirect the request to #SVTK_Renderer::SetSelectionTolerance
1232 void SVTK_ViewWindow::SetSelectionTolerance(const double& theTolNodes,
1233 const double& theTolItems,
1234 const double& theTolObjects)
1236 myView->SetSelectionTolerance(theTolNodes, theTolItems, theTolObjects);
1240 Get visibility status of the static trihedron
1242 bool SVTK_ViewWindow::IsStaticTrihedronVisible() const
1244 return (bool)myAxesWidget->GetEnabled();
1248 Set visibility status of the static trihedron
1250 void SVTK_ViewWindow::SetStaticTrihedronVisible( const bool theIsVisible )
1252 myAxesWidget->SetEnabled( (int)theIsVisible );
1257 \param accelAction - action
1259 bool SVTK_ViewWindow::action( const int accelAction )
1261 if ( accelAction == SUIT_Accel::ZoomFit )
1264 int anEvent = SVTK::convertAction( accelAction );
1265 GetInteractor()->InvokeEvent(anEvent, 0);
1271 \return action by it's id
1273 QtxAction* SVTK_ViewWindow::getAction( int id ) const
1275 return dynamic_cast<QtxAction*>( toolMgr()->action( id ) );
1279 // old visual parameters had 13 values. New format added additional
1280 // 76 values for graduated axes, so both numbers are processed.
1281 const int nNormalParams = 13; // number of view windows parameters excluding graduated axes params
1282 const int nGradAxisParams = 25; // number of parameters of ONE graduated axis (X, Y, or Z)
1283 const int nTrihedronParams = 3; // number of parameters for Trihedron
1284 const int nAllParams = nNormalParams + 3*nGradAxisParams + nTrihedronParams + 1; // number of all visual parameters
1286 /*! The method returns visual parameters of a graduated axis actor (x,y,z axis of graduated axes)
1288 void getGradAxisVisualParams( QXmlStreamWriter& writer, vtkAxisActor2D* actor, QString theAxis )
1295 bool isVisible = actor->GetTitleVisibility();
1296 QString title ( actor->GetTitle() );
1297 vtkFloatingPointType color[ 3 ];
1298 int font = VTK_ARIAL;
1303 vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1306 txtProp->GetColor( color );
1307 font = txtProp->GetFontFamily();
1308 bold = txtProp->GetBold();
1309 italic = txtProp->GetItalic();
1310 shadow = txtProp->GetShadow();
1312 writer.writeStartElement("GraduatedAxis");
1313 writer.writeAttribute("Axis", theAxis);
1315 writer.writeStartElement("Title");
1316 writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1317 writer.writeAttribute("Text", title);
1318 writer.writeAttribute("Font", QString("%1").arg(font));
1319 writer.writeAttribute("Bold", QString("%1").arg(bold));
1320 writer.writeAttribute("Italic", QString("%1").arg(italic));
1321 writer.writeAttribute("Shadow", QString("%1").arg(shadow));
1323 writer.writeStartElement("Color");
1324 writer.writeAttribute("R", QString("%1").arg(color[0]));
1325 writer.writeAttribute("G", QString("%1").arg(color[1]));
1326 writer.writeAttribute("B", QString("%1").arg(color[2]));
1327 writer.writeEndElement();
1328 writer.writeEndElement();
1330 //params.sprintf( "* Graduated Axis: * Name *%u*%s*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible,
1331 // title.toLatin1().data(), color[0], color[1], color[2], font, bold, italic, shadow );
1334 isVisible = actor->GetLabelVisibility();
1335 int labels = actor->GetNumberOfLabels();
1336 int offset = actor->GetTickOffset();
1342 txtProp = actor->GetLabelTextProperty();
1345 txtProp->GetColor( color );
1346 font = txtProp->GetFontFamily();
1347 bold = txtProp->GetBold();
1348 italic = txtProp->GetItalic();
1349 shadow = txtProp->GetShadow();
1352 writer.writeStartElement("Labels");
1353 writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1354 writer.writeAttribute("Number", QString("%1").arg(labels));
1355 writer.writeAttribute("Offset", QString("%1").arg(offset));
1356 writer.writeAttribute("Font", QString("%1").arg(font));
1357 writer.writeAttribute("Bold", QString("%1").arg(bold));
1358 writer.writeAttribute("Italic", QString("%1").arg(italic));
1359 writer.writeAttribute("Shadow", QString("%1").arg(shadow));
1361 writer.writeStartElement("Color");
1362 writer.writeAttribute("R", QString("%1").arg(color[0]));
1363 writer.writeAttribute("G", QString("%1").arg(color[1]));
1364 writer.writeAttribute("B", QString("%1").arg(color[2]));
1365 writer.writeEndElement();
1366 writer.writeEndElement();
1367 // params += QString().sprintf( "* Labels *%u*%u*%u*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible, labels, offset,
1368 // color[0], color[1], color[2], font, bold, italic, shadow );
1371 isVisible = actor->GetTickVisibility();
1372 int length = actor->GetTickLength();
1373 writer.writeStartElement("TickMarks");
1374 writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1375 writer.writeAttribute("Length", QString("%1").arg(length));
1376 writer.writeEndElement();
1378 //params += QString().sprintf( "* Tick marks *%u*%u", isVisible, length );
1380 writer.writeEndElement();
1384 void setGradAxisVisualParams(QXmlStreamReader& reader, vtkAxisActor2D* actor)
1391 } while (!reader.isStartElement());
1393 // Read title params
1394 QXmlStreamAttributes aAttr = reader.attributes();
1395 bool isVisible = aAttr.value("isVisible").toString().toUShort();
1396 QString title = aAttr.value("Text").toString();
1397 int font = aAttr.value("Font").toString().toInt();
1398 int bold = aAttr.value("Bold").toString().toInt();
1399 int italic = aAttr.value("Italic").toString().toInt();
1400 int shadow = aAttr.value("Shadow").toString().toInt();
1402 //printf("#### TITLE: %i, %s, %i, %i, %i, %i\n", isVisible, qPrintable(title), font, bold, italic, shadow);
1406 } while (!reader.isStartElement());
1409 aAttr = reader.attributes();
1411 vtkFloatingPointType color[3];
1412 color[0] = aAttr.value("R").toString().toDouble();
1413 color[1] = aAttr.value("G").toString().toDouble();
1414 color[2] = aAttr.value("B").toString().toDouble();
1415 //printf("#### Color: %f, %f, %f\n", color[0], color[1], color[2]);
1417 actor->SetTitleVisibility( isVisible );
1418 actor->SetTitle( title.toLatin1() );
1419 vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1421 txtProp->SetColor( color );
1422 txtProp->SetFontFamily( font );
1423 txtProp->SetBold( bold );
1424 txtProp->SetItalic( italic );
1425 txtProp->SetShadow( shadow );
1432 } while (!reader.isStartElement());
1434 aAttr = reader.attributes();
1435 isVisible = aAttr.value("isVisible").toString().toUShort();
1436 int labels = aAttr.value("Number").toString().toInt();
1437 int offset = aAttr.value("Offset").toString().toInt();
1438 font = aAttr.value("Font").toString().toInt();
1439 bold = aAttr.value("Bold").toString().toInt();
1440 italic = aAttr.value("Italic").toString().toInt();
1441 shadow = aAttr.value("Shadow").toString().toInt();
1445 } while (!reader.isStartElement());
1447 aAttr = reader.attributes();
1449 color[0] = aAttr.value("R").toString().toDouble();
1450 color[1] = aAttr.value("G").toString().toDouble();
1451 color[2] = aAttr.value("B").toString().toDouble();
1453 actor->SetLabelVisibility( isVisible );
1454 actor->SetNumberOfLabels( labels );
1455 actor->SetTickOffset( offset );
1456 txtProp = actor->GetLabelTextProperty();
1458 txtProp->SetColor( color );
1459 txtProp->SetFontFamily( font );
1460 txtProp->SetBold( bold );
1461 txtProp->SetItalic( italic );
1462 txtProp->SetShadow( shadow );
1468 } while (!reader.isStartElement());
1469 aAttr = reader.attributes();
1471 // retrieve and set tick marks properties
1472 isVisible = aAttr.value("isVisible").toString().toUShort();
1473 int length = aAttr.value("Length").toString().toInt();
1475 actor->SetTickVisibility( isVisible );
1476 actor->SetTickLength( length );
1479 /*! The method restores visual parameters of a graduated axis actor (x,y,z axis)
1481 void setGradAxisVisualParams( vtkAxisActor2D* actor, const QString& params )
1486 QStringList paramsLst = params.split( '*' );
1488 if ( paramsLst.size() == nGradAxisParams ) { // altogether name, lable, ticks parameters make up 25 values
1490 // retrieve and set name parameters
1491 bool isVisible = paramsLst[2].toUShort();
1492 QString title = paramsLst[3];
1493 vtkFloatingPointType color[3];
1494 color[0] = paramsLst[4].toDouble();
1495 color[1] = paramsLst[5].toDouble();
1496 color[2] = paramsLst[6].toDouble();
1497 int font = paramsLst[7].toInt();
1498 int bold = paramsLst[8].toInt();
1499 int italic = paramsLst[9].toInt();
1500 int shadow = paramsLst[10].toInt();
1502 actor->SetTitleVisibility( isVisible );
1503 actor->SetTitle( title.toLatin1() );
1504 vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1506 txtProp->SetColor( color );
1507 txtProp->SetFontFamily( font );
1508 txtProp->SetBold( bold );
1509 txtProp->SetItalic( italic );
1510 txtProp->SetShadow( shadow );
1513 // retrieve and set lable parameters
1514 isVisible = paramsLst[12].toUShort();
1515 int labels = paramsLst[13].toInt();
1516 int offset = paramsLst[14].toInt();
1517 color[0] = paramsLst[15].toDouble();
1518 color[1] = paramsLst[16].toDouble();
1519 color[2] = paramsLst[17].toDouble();
1520 font = paramsLst[18].toInt();
1521 bold = paramsLst[19].toInt();
1522 italic = paramsLst[20].toInt();
1523 shadow = paramsLst[21].toInt();
1525 actor->SetLabelVisibility( isVisible );
1526 actor->SetNumberOfLabels( labels );
1527 actor->SetTickOffset( offset );
1528 txtProp = actor->GetLabelTextProperty();
1530 txtProp->SetColor( color );
1531 txtProp->SetFontFamily( font );
1532 txtProp->SetBold( bold );
1533 txtProp->SetItalic( italic );
1534 txtProp->SetShadow( shadow );
1537 // retrieve and set tick marks properties
1538 isVisible = paramsLst[23].toUShort();
1539 int length = paramsLst[24].toInt();
1541 actor->SetTickVisibility( isVisible );
1542 actor->SetTickLength( length );
1546 /*! The method returns the visual parameters of this view as a formated string
1548 QString SVTK_ViewWindow::getVisualParameters()
1550 double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
1552 // save position, focal point, viewUp, scale
1553 vtkCamera* camera = getRenderer()->GetActiveCamera();
1554 camera->GetPosition( pos );
1555 camera->GetFocalPoint( focalPnt );
1556 camera->GetViewUp( viewUp );
1557 parScale = camera->GetParallelScale();
1560 // Parameters are given in the following format:view position (3 digits), focal point position (3 digits)
1561 // view up values (3 digits), parallel scale (1 digit), scale (3 digits,
1562 // Graduated axes parameters (X, Y, Z axes parameters)
1564 QXmlStreamWriter aWriter(&retStr);
1565 aWriter.setAutoFormatting(true);
1567 aWriter.writeStartDocument();
1568 aWriter.writeStartElement("ViewState");
1570 aWriter.writeStartElement("Position");
1571 aWriter.writeAttribute("X", QString("%1").arg(pos[0]));
1572 aWriter.writeAttribute("Y", QString("%1").arg(pos[1]));
1573 aWriter.writeAttribute("Z", QString("%1").arg(pos[2]));
1574 aWriter.writeEndElement();
1576 aWriter.writeStartElement("FocalPoint");
1577 aWriter.writeAttribute("X", QString::number(focalPnt[0]));
1578 aWriter.writeAttribute("Y", QString::number(focalPnt[1]));
1579 aWriter.writeAttribute("Z", QString::number(focalPnt[2]));
1580 aWriter.writeEndElement();
1582 aWriter.writeStartElement("ViewUp");
1583 aWriter.writeAttribute("X", QString::number(viewUp[0]));
1584 aWriter.writeAttribute("Y", QString::number(viewUp[1]));
1585 aWriter.writeAttribute("Z", QString::number(viewUp[2]));
1586 aWriter.writeEndElement();
1588 aWriter.writeStartElement("ViewScale");
1589 aWriter.writeAttribute("Parallel", QString::number(parScale));
1590 aWriter.writeAttribute("X", QString::number(scale[0]));
1591 aWriter.writeAttribute("Y", QString::number(scale[1]));
1592 aWriter.writeAttribute("Z", QString::number(scale[2]));
1593 aWriter.writeEndElement();
1595 if ( SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes() ) {
1596 aWriter.writeStartElement("DisplayCubeAxis");
1597 aWriter.writeAttribute("Show", QString( "%1" ).arg( GetRenderer()->IsCubeAxesDisplayed()));
1598 aWriter.writeEndElement();
1600 getGradAxisVisualParams(aWriter, gradAxesActor->GetXAxisActor2D(), "X");
1601 getGradAxisVisualParams(aWriter, gradAxesActor->GetYAxisActor2D(), "Y");
1602 getGradAxisVisualParams(aWriter, gradAxesActor->GetZAxisActor2D(), "Z");
1605 aWriter.writeStartElement("Trihedron");
1606 aWriter.writeAttribute("isShown", QString( "%1" ).arg( isTrihedronDisplayed()));
1607 aWriter.writeAttribute("Size", QString::number(GetTrihedronSize()));
1608 aWriter.writeEndElement();
1610 aWriter.writeStartElement("Background");
1611 aWriter.writeAttribute("Value", QString( "%1" ).arg( Qtx::backgroundToString(background()) ));
1612 aWriter.writeEndElement();
1614 aWriter.writeEndElement();
1615 aWriter.writeEndDocument();
1621 The method restores visual parameters of this view or postpones it untill the view is shown
1623 void SVTK_ViewWindow::setVisualParameters( const QString& parameters )
1625 //printf("#### %s\n", qPrintable(parameters));
1626 SVTK_RenderWindowInteractor* anInteractor = GetInteractor();
1627 if ( anInteractor->isVisible() ) {
1628 doSetVisualParameters( parameters );
1631 myVisualParams = parameters;
1632 anInteractor->installEventFilter(this);
1637 The method restores visual parameters of this view from a formated string
1639 void SVTK_ViewWindow::doSetVisualParameters( const QString& parameters, bool baseParamsOnly )
1642 double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
1644 QXmlStreamReader aReader(parameters);
1645 SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes();
1647 while(!aReader.atEnd()) {
1649 if (aReader.isStartElement()) {
1650 QXmlStreamAttributes aAttr = aReader.attributes();
1651 //printf("### Name = %s\n", qPrintable(aReader.name().toString()));
1652 if (aReader.name() == "Position") {
1653 pos[0] = aAttr.value("X").toString().toDouble();
1654 pos[1] = aAttr.value("Y").toString().toDouble();
1655 pos[2] = aAttr.value("Z").toString().toDouble();
1656 //printf("#### Position %f; %f; %f\n", pos[0], pos[1], pos[2]);
1658 else if (aReader.name() == "FocalPoint") {
1659 focalPnt[0] = aAttr.value("X").toString().toDouble();
1660 focalPnt[1] = aAttr.value("Y").toString().toDouble();
1661 focalPnt[2] = aAttr.value("Z").toString().toDouble();
1662 //printf("#### FocalPoint %f; %f; %f\n", focalPnt[0], focalPnt[1], focalPnt[2]);
1664 else if (aReader.name() == "ViewUp") {
1665 viewUp[0] = aAttr.value("X").toString().toDouble();
1666 viewUp[1] = aAttr.value("Y").toString().toDouble();
1667 viewUp[2] = aAttr.value("Z").toString().toDouble();
1668 //printf("#### ViewUp %f; %f; %f\n", viewUp[0], viewUp[1], viewUp[2]);
1670 else if (aReader.name() == "ViewScale") {
1671 parScale = aAttr.value("Parallel").toString().toDouble();
1672 scale[0] = aAttr.value("X").toString().toDouble();
1673 scale[1] = aAttr.value("Y").toString().toDouble();
1674 scale[2] = aAttr.value("Z").toString().toDouble();
1675 //printf("#### ViewScale %f; %f; %f\n", scale[0], scale[1], scale[2]);
1677 else if (aReader.name() == "DisplayCubeAxis") {
1678 if ( !baseParamsOnly ) {
1679 if (aAttr.value("Show") == "0")
1680 gradAxesActor->VisibilityOff();
1682 gradAxesActor->VisibilityOn();
1685 else if (aReader.name() == "GraduatedAxis") {
1686 if ( !baseParamsOnly ) {
1687 if(aAttr.value("Axis") == "X")
1688 setGradAxisVisualParams(aReader, gradAxesActor->GetXAxisActor2D());
1689 else if(aAttr.value("Axis") == "Y")
1690 setGradAxisVisualParams(aReader, gradAxesActor->GetYAxisActor2D());
1691 else if(aAttr.value("Axis") == "Z")
1692 setGradAxisVisualParams(aReader, gradAxesActor->GetZAxisActor2D());
1695 else if (aReader.name() == "Trihedron") {
1696 if ( !baseParamsOnly ) {
1697 if (aAttr.value("isShown") == "0")
1698 GetTrihedron()->VisibilityOff();
1700 GetTrihedron()->VisibilityOn();
1701 SetTrihedronSize(aAttr.value("Size").toString().toDouble());
1704 else if (aReader.name() == "Background") {
1705 if ( !baseParamsOnly ) {
1706 setBackground( Qtx::stringToBackground( aAttr.value("Value").toString() ) );
1711 if (!aReader.hasError()) {
1712 vtkCamera* camera = getRenderer()->GetActiveCamera();
1713 camera->SetPosition( pos );
1714 camera->SetFocalPoint( focalPnt );
1715 camera->SetViewUp( viewUp );
1716 camera->SetParallelScale( parScale );
1717 GetRenderer()->SetScale( scale );
1718 //SetScale( scale );
1721 QStringList paramsLst = parameters.split( '*' );
1722 if ( paramsLst.size() >= nNormalParams ) {
1723 // 'reading' list of parameters
1724 pos[0] = paramsLst[0].toDouble();
1725 pos[1] = paramsLst[1].toDouble();
1726 pos[2] = paramsLst[2].toDouble();
1727 focalPnt[0] = paramsLst[3].toDouble();
1728 focalPnt[1] = paramsLst[4].toDouble();
1729 focalPnt[2] = paramsLst[5].toDouble();
1730 viewUp[0] = paramsLst[6].toDouble();
1731 viewUp[1] = paramsLst[7].toDouble();
1732 viewUp[2] = paramsLst[8].toDouble();
1733 parScale = paramsLst[9].toDouble();
1734 scale[0] = paramsLst[10].toDouble();
1735 scale[1] = paramsLst[11].toDouble();
1736 scale[2] = paramsLst[12].toDouble();
1738 // applying parameters
1739 vtkCamera* camera = getRenderer()->GetActiveCamera();
1740 camera->SetPosition( pos );
1741 camera->SetFocalPoint( focalPnt );
1742 camera->SetViewUp( viewUp );
1743 camera->SetParallelScale( parScale );
1744 GetRenderer()->SetScale( scale );
1745 //SetScale( scale );
1747 // apply graduated axes parameters
1748 if ( !baseParamsOnly ) {
1749 SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes();
1750 if ( gradAxesActor && paramsLst.size() == nAllParams ) {
1751 int i = nNormalParams+1, j = i + nGradAxisParams - 1;
1752 ::setGradAxisVisualParams( gradAxesActor->GetXAxisActor2D(), parameters.section( '*', i, j ) );
1753 i = j + 1; j += nGradAxisParams;
1754 ::setGradAxisVisualParams( gradAxesActor->GetYAxisActor2D(), parameters.section( '*', i, j ) );
1755 i = j + 1; j += nGradAxisParams;
1756 ::setGradAxisVisualParams( gradAxesActor->GetZAxisActor2D(), parameters.section( '*', i, j ) );
1758 if ( paramsLst[13].toUShort() )
1759 gradAxesActor->VisibilityOn();
1761 gradAxesActor->VisibilityOff();
1763 else if ( paramsLst.size() == nAllParams ) {
1764 if ( paramsLst[90].toUShort() )
1765 GetTrihedron()->VisibilityOn();
1767 GetTrihedron()->VisibilityOff();
1769 SetTrihedronSize(paramsLst[91].toDouble());
1779 Delayed setVisualParameters
1781 bool SVTK_ViewWindow::eventFilter( QObject* theWatched, QEvent* theEvent )
1783 if ( theEvent->type() == QEvent::Show && theWatched->inherits( "SVTK_RenderWindowInteractor" ) ) {
1784 SVTK_RenderWindowInteractor* anInteractor = (SVTK_RenderWindowInteractor*)theWatched;
1785 if ( anInteractor->isVisible() ) {
1786 doSetVisualParameters( myVisualParams );
1787 anInteractor->removeEventFilter( this ); // theWatched = RenderWindowInteractor
1790 return SUIT_ViewWindow::eventFilter( theWatched, theEvent );
1795 Change rotation point
1797 void SVTK_ViewWindow::onChangeRotationPoint(bool theIsActivate)
1800 mySetRotationPointDlg->addObserver();
1801 if ( mySetRotationPointDlg->IsFirstShown() )
1802 activateSetRotationGravity();
1803 mySetRotationPointDlg->show();
1805 mySetRotationPointDlg->hide();
1809 Set the gravity center as a rotation point
1811 void SVTK_ViewWindow::activateSetRotationGravity()
1813 myEventDispatcher->InvokeEvent(SVTK::SetRotateGravity,0);
1817 Set the selected point as a rotation point
1819 void SVTK_ViewWindow::activateSetRotationSelected(void* theData)
1821 myEventDispatcher->InvokeEvent(SVTK::ChangeRotationPoint,theData);
1825 Set the point selected by user as a rotation point
1827 void SVTK_ViewWindow::activateStartPointSelection()
1829 myEventDispatcher->InvokeEvent(SVTK::StartPointSelection,0);
1833 Set the view projection mode: orthogonal or perspective
1835 void SVTK_ViewWindow::onPerspectiveMode()
1837 bool anIsParallelMode = toolMgr()->action( ParallelModeId )->isChecked();
1839 // advanced zooming is not available in perspective mode
1840 if( QtxAction* anAction = getAction( SwitchZoomingStyleId ) )
1841 anAction->setEnabled( anIsParallelMode );
1843 vtkCamera* aCamera = getRenderer()->GetActiveCamera();
1844 aCamera->SetParallelProjection(anIsParallelMode);
1845 GetInteractor()->GetDevice()->CreateTimer(VTKI_TIMER_FIRST);
1848 void SVTK_ViewWindow::SetEventDispatcher(vtkObject* theDispatcher)
1850 myEventDispatcher = theDispatcher;
1854 Creates all actions of svtk main window
1856 void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
1858 QtxAction* anAction;
1859 QtxActionToolMgr* mgr = toolMgr();
1862 anAction = new QtxAction(tr("MNU_DUMP_VIEW"),
1863 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
1864 tr( "MNU_DUMP_VIEW" ), 0, this);
1865 anAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1866 connect(anAction, SIGNAL(activated()), this, SLOT(onDumpView()));
1867 mgr->registerAction( anAction, DumpId );
1870 anAction = new QtxAction(tr("MNU_FITALL"),
1871 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
1872 tr( "MNU_FITALL" ), 0, this);
1873 anAction->setStatusTip(tr("DSC_FITALL"));
1874 connect(anAction, SIGNAL(activated()), this, SLOT(onFitAll()));
1875 mgr->registerAction( anAction, FitAllId );
1878 anAction = new QtxAction(tr("MNU_FITRECT"),
1879 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
1880 tr( "MNU_FITRECT" ), 0, this);
1881 anAction->setStatusTip(tr("DSC_FITRECT"));
1882 connect(anAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
1883 mgr->registerAction( anAction, FitRectId );
1886 anAction = new QtxAction(tr("MNU_ZOOM_VIEW"),
1887 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
1888 tr( "MNU_ZOOM_VIEW" ), 0, this);
1889 anAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1890 connect(anAction, SIGNAL(activated()), this, SLOT(activateZoom()));
1891 mgr->registerAction( anAction, ZoomId );
1894 anAction = new QtxAction(tr("MNU_PAN_VIEW"),
1895 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
1896 tr( "MNU_PAN_VIEW" ), 0, this);
1897 anAction->setStatusTip(tr("DSC_PAN_VIEW"));
1898 connect(anAction, SIGNAL(activated()), this, SLOT(activatePanning()));
1899 mgr->registerAction( anAction, PanId );
1902 anAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"),
1903 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
1904 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1905 anAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1906 connect(anAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
1907 mgr->registerAction( anAction, GlobalPanId );
1909 // Change rotation point
1910 anAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"),
1911 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_ROTATION_POINT" ) ),
1912 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1913 anAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1914 anAction->setCheckable(true);
1915 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onChangeRotationPoint(bool)));
1916 mgr->registerAction( anAction, ChangeRotationPointId );
1919 anAction = new QtxAction(tr("MNU_ROTATE_VIEW"),
1920 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
1921 tr( "MNU_ROTATE_VIEW" ), 0, this);
1922 anAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1923 connect(anAction, SIGNAL(activated()), this, SLOT(activateRotation()));
1924 mgr->registerAction( anAction, RotationId );
1927 anAction = new QtxAction(tr("MNU_FRONT_VIEW"),
1928 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
1929 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1930 anAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1931 connect(anAction, SIGNAL(activated()), this, SLOT(onFrontView()));
1932 this->addAction(anAction);
1933 mgr->registerAction( anAction, FrontId );
1935 anAction = new QtxAction(tr("MNU_BACK_VIEW"),
1936 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
1937 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1938 anAction->setStatusTip(tr("DSC_BACK_VIEW"));
1939 connect(anAction, SIGNAL(activated()), this, SLOT(onBackView()));
1940 this->addAction(anAction);
1941 mgr->registerAction( anAction, BackId );
1943 anAction = new QtxAction(tr("MNU_TOP_VIEW"),
1944 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
1945 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1946 anAction->setStatusTip(tr("DSC_TOP_VIEW"));
1947 connect(anAction, SIGNAL(activated()), this, SLOT(onTopView()));
1948 this->addAction(anAction);
1949 mgr->registerAction( anAction, TopId );
1951 anAction = new QtxAction(tr("MNU_BOTTOM_VIEW"),
1952 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
1953 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1954 anAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1955 connect(anAction, SIGNAL(activated()), this, SLOT(onBottomView()));
1956 this->addAction(anAction);
1957 mgr->registerAction( anAction, BottomId );
1959 anAction = new QtxAction(tr("MNU_LEFT_VIEW"),
1960 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
1961 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1962 anAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1963 connect(anAction, SIGNAL(activated()), this, SLOT(onLeftView()));
1964 this->addAction(anAction);
1965 mgr->registerAction( anAction, LeftId );
1967 anAction = new QtxAction(tr("MNU_RIGHT_VIEW"),
1968 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
1969 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1970 anAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1971 connect(anAction, SIGNAL(activated()), this, SLOT(onRightView()));
1972 this->addAction(anAction);
1973 mgr->registerAction( anAction, RightId );
1975 // rotate anticlockwise
1976 anAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"),
1977 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ANTICLOCKWISE" ) ),
1978 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1979 anAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1980 connect(anAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1981 this->addAction(anAction);
1982 mgr->registerAction( anAction, AntiClockWiseId );
1985 anAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"),
1986 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_CLOCKWISE" ) ),
1987 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1988 anAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1989 connect(anAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1990 this->addAction(anAction);
1991 mgr->registerAction( anAction, ClockWiseId );
1994 anAction = new QtxAction(tr("MNU_RESET_VIEW"),
1995 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
1996 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
1997 anAction->setStatusTip(tr("DSC_RESET_VIEW"));
1998 connect(anAction, SIGNAL(activated()), this, SLOT(onResetView()));
1999 this->addAction(anAction);
2000 mgr->registerAction( anAction, ResetId );
2002 // onViewTrihedron: Shows - Hides Trihedron
2003 anAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"),
2004 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ),
2005 tr( "MNU_SHOW_TRIHEDRON" ), 0, this);
2006 anAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON"));
2007 connect(anAction, SIGNAL(activated()), this, SLOT(onViewTrihedron()));
2008 mgr->registerAction( anAction, ViewTrihedronId );
2010 // onNonIsometric: Manage non-isometric params
2011 anAction = new QtxAction(tr("MNU_SVTK_SCALING"),
2012 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SCALING" ) ),
2013 tr( "MNU_SVTK_SCALING" ), 0, this);
2014 anAction->setStatusTip(tr("DSC_SVTK_SCALING"));
2015 anAction->setCheckable(true);
2016 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onNonIsometric(bool)));
2017 mgr->registerAction( anAction, NonIsometric );
2019 // onGraduatedAxes: Manage graduated axes params
2020 anAction = new QtxAction(tr("MNU_SVTK_GRADUATED_AXES"),
2021 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_GRADUATED_AXES" ) ),
2022 tr( "MNU_SVTK_GRADUATED_AXES" ), 0, this);
2023 anAction->setStatusTip(tr("DSC_SVTK_GRADUATED_AXES"));
2024 anAction->setCheckable(true);
2025 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onGraduatedAxes(bool)));
2026 mgr->registerAction( anAction, GraduatedAxes );
2028 // onGraduatedAxes: Manage graduated axes params
2029 anAction = new QtxAction(tr("MNU_SVTK_UPDATE_RATE"),
2030 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_UPDATE_RATE" ) ),
2031 tr( "MNU_SVTK_UPDATE_RATE" ), 0, this);
2032 anAction->setStatusTip(tr("DSC_SVTK_UPDATE_RATE"));
2033 anAction->setCheckable(true);
2034 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onUpdateRate(bool)));
2035 mgr->registerAction( anAction, UpdateRate );
2037 // Set perspective mode group
2038 anAction = new QtxAction(tr("MNU_SVTK_PARALLEL_MODE"),
2039 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARALLEL" ) ),
2040 tr( "MNU_SVTK_PARALLEL_MODE" ), 0, this);
2041 anAction->setStatusTip(tr("DSC_SVTK_PARALLEL_MODE"));
2042 anAction->setCheckable(true);
2043 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onPerspectiveMode()));
2044 mgr->registerAction( anAction, ParallelModeId );
2046 anAction = new QtxAction(tr("MNU_SVTK_PERSPECTIVE_MODE"),
2047 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PERSPECTIVE" ) ),
2048 tr( "MNU_SVTK_PERSPECTIVE_MODE" ), 0, this);
2049 anAction->setStatusTip(tr("DSC_SVTK_PERSPECTIVE_MODE"));
2050 anAction->setCheckable(true);
2051 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onPerspectiveMode()));
2052 mgr->registerAction( anAction, ProjectionModeId );
2054 QActionGroup* aPerspectiveGroup = new QActionGroup( this );
2055 aPerspectiveGroup->addAction( mgr->action( ParallelModeId ) );
2056 aPerspectiveGroup->addAction( mgr->action( ProjectionModeId ) );
2059 anAction = new QtxAction(tr("MNU_VIEWPARAMETERS_VIEW"),
2060 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARAMETERS" ) ),
2061 tr( "MNU_VIEWPARAMETERS_VIEW" ), 0, this);
2062 anAction->setStatusTip(tr("DSC_VIEWPARAMETERS_VIEW"));
2063 anAction->setCheckable(true);
2064 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onViewParameters(bool)));
2065 mgr->registerAction( anAction, ViewParametersId );
2068 anAction = new QtxAction(tr("MNU_SYNCHRONIZE_VIEW"),
2069 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SYNCHRONIZE" ) ),
2070 tr( "MNU_SYNCHRONIZE_VIEW" ), 0, this);
2071 anAction->setStatusTip(tr("DSC_SYNCHRONIZE_VIEW"));
2072 anAction->setMenu( new QMenu( this ) );
2073 anAction->setCheckable(true);
2074 connect(anAction->menu(), SIGNAL(aboutToShow()), this, SLOT(updateSyncViews()));
2075 connect(anAction, SIGNAL(triggered(bool)), this, SLOT(onSynchronizeView(bool)));
2076 mgr->registerAction( anAction, SynchronizeId );
2078 // Switch between interaction styles
2079 anAction = new QtxAction(tr("MNU_SVTK_STYLE_SWITCH"),
2080 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_STYLE_SWITCH" ) ),
2081 tr( "MNU_SVTK_STYLE_SWITCH" ), 0, this);
2082 anAction->setStatusTip(tr("DSC_SVTK_STYLE_SWITCH"));
2083 anAction->setCheckable(true);
2084 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
2085 mgr->registerAction( anAction, SwitchInteractionStyleId );
2087 // Switch between zooming styles
2088 anAction = new QtxAction(tr("MNU_SVTK_ZOOMING_STYLE_SWITCH"),
2089 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_ZOOMING_STYLE_SWITCH" ) ),
2090 tr( "MNU_SVTK_ZOOMING_STYLE_SWITCH" ), 0, this);
2091 anAction->setStatusTip(tr("DSC_SVTK_ZOOMING_STYLE_SWITCH"));
2092 anAction->setCheckable(true);
2093 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
2094 mgr->registerAction( anAction, SwitchZoomingStyleId );
2096 // Turn on/off dynamic pre-selection
2097 anAction = new QtxAction(tr("MNU_SVTK_DYNAMIC_PRESLECTION_SWITCH"),
2098 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_DYNAMIC_PRESLECTION_SWITCH" ) ),
2099 tr( "MNU_SVTK_DYNAMIC_PRESLECTION_SWITCH" ), 0, this);
2100 anAction->setStatusTip(tr("DSC_SVTK_DYNAMIC_PRESLECTION_SWITCH"));
2101 anAction->setCheckable(true);
2102 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchDynamicPreSelection(bool)));
2103 mgr->registerAction( anAction, SwitchDynamicPreselectionId );
2106 myStartAction = new QtxAction(tr("MNU_SVTK_RECORDING_START"),
2107 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_START" ) ),
2108 tr( "MNU_SVTK_RECORDING_START" ), 0, this);
2109 myStartAction->setStatusTip(tr("DSC_SVTK_RECORDING_START"));
2110 connect( myStartAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStartRecording() ) );
2111 mgr->registerAction( myStartAction, StartRecordingId );
2114 myPlayAction = new QtxAction(tr("MNU_SVTK_RECORDING_PLAY"),
2115 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PLAY" ) ),
2116 tr( "MNU_SVTK_RECORDING_PLAY" ), 0, this);
2117 myPlayAction->setStatusTip(tr("DSC_SVTK_RECORDING_PLAY"));
2118 myPlayAction->setEnabled( false );
2119 connect( myPlayAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPlayRecording() ) );
2120 mgr->registerAction( myPlayAction, PlayRecordingId );
2123 myPauseAction = new QtxAction(tr("MNU_SVTK_RECORDING_PAUSE"),
2124 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PAUSE" ) ),
2125 tr( "MNU_SVTK_RECORDING_PAUSE" ), 0, this);
2126 myPauseAction->setStatusTip(tr("DSC_SVTK_RECORDING_PAUSE"));
2127 myPauseAction->setEnabled( false );
2128 connect( myPauseAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPauseRecording() ) );
2129 mgr->registerAction( myPauseAction, PauseRecordingId );
2132 myStopAction = new QtxAction(tr("MNU_SVTK_RECORDING_STOP"),
2133 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_STOP" ) ),
2134 tr( "MNU_SVTK_RECORDING_STOP" ), 0, this);
2135 myStopAction->setStatusTip(tr("DSC_SVTK_RECORDING_STOP"));
2136 myStopAction->setEnabled( false );
2137 connect( myStopAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStopRecording() ) );
2138 mgr->registerAction( myStopAction, StopRecordingId );
2142 Creates toolbar of svtk main window
2144 void SVTK_ViewWindow::createToolBar()
2146 QtxActionToolMgr* mgr = toolMgr();
2148 mgr->append( DumpId, myToolBar );
2149 mgr->append( SwitchInteractionStyleId, myToolBar );
2150 mgr->append( SwitchZoomingStyleId, myToolBar );
2151 mgr->append( SwitchDynamicPreselectionId, myToolBar );
2152 mgr->append( ViewTrihedronId, myToolBar );
2154 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
2155 aScaleAction->insertAction( getAction( FitAllId ) );
2156 aScaleAction->insertAction( getAction( FitRectId ) );
2157 aScaleAction->insertAction( getAction( ZoomId ) );
2158 mgr->append( aScaleAction, myToolBar );
2160 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
2161 aPanningAction->insertAction( getAction( PanId ) );
2162 aPanningAction->insertAction( getAction( GlobalPanId ) );
2163 mgr->append( aPanningAction, myToolBar );
2165 mgr->append( ChangeRotationPointId, myToolBar );
2167 mgr->append( RotationId, myToolBar );
2169 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
2170 aViewsAction->insertAction( getAction( FrontId ) );
2171 aViewsAction->insertAction( getAction( BackId ) );
2172 aViewsAction->insertAction( getAction( TopId ) );
2173 aViewsAction->insertAction( getAction( BottomId ) );
2174 aViewsAction->insertAction( getAction( LeftId ) );
2175 aViewsAction->insertAction( getAction( RightId ) );
2176 mgr->append( aViewsAction, myToolBar );
2178 mgr->append( AntiClockWiseId, myToolBar );
2179 mgr->append( ClockWiseId, myToolBar );
2181 mgr->append( ResetId, myToolBar );
2183 mgr->append( UpdateRate, myToolBar );
2184 mgr->append( NonIsometric, myToolBar );
2185 mgr->append( GraduatedAxes, myToolBar );
2187 mgr->append( ViewParametersId, myToolBar );
2188 mgr->append( SynchronizeId, myToolBar );
2190 mgr->append( toolMgr()->separator(), myToolBar );
2192 mgr->append( ParallelModeId, myToolBar );
2193 mgr->append( ProjectionModeId, myToolBar );
2195 mgr->append( StartRecordingId, myRecordingToolBar );
2196 mgr->append( PlayRecordingId, myRecordingToolBar );
2197 mgr->append( PauseRecordingId, myRecordingToolBar );
2198 mgr->append( StopRecordingId, myRecordingToolBar );
2201 void SVTK_ViewWindow::onUpdateRate(bool theIsActivate)
2204 myUpdateRateDlg->Update();
2205 myUpdateRateDlg->show();
2207 myUpdateRateDlg->hide();
2210 void SVTK_ViewWindow::onNonIsometric(bool theIsActivate)
2213 myNonIsometricDlg->Update();
2214 myNonIsometricDlg->show();
2216 myNonIsometricDlg->hide();
2219 void SVTK_ViewWindow::onGraduatedAxes(bool theIsActivate)
2222 myCubeAxesDlg->Update();
2223 myCubeAxesDlg->show();
2225 myCubeAxesDlg->hide();
2229 Starts rotation transformation
2231 void SVTK_ViewWindow::activateRotation()
2233 myEventDispatcher->InvokeEvent(SVTK::StartRotate,0);
2238 Starts panning transformation
2240 void SVTK_ViewWindow::activatePanning()
2242 myEventDispatcher->InvokeEvent(SVTK::StartPan,0);
2246 Starts zoom transformation
2248 void SVTK_ViewWindow::activateZoom()
2250 myEventDispatcher->InvokeEvent(SVTK::StartZoom,0);
2254 Starts window fit transformation
2256 void SVTK_ViewWindow::activateWindowFit()
2258 myEventDispatcher->InvokeEvent(SVTK::StartFitArea,0);
2262 Starts global panning transformation
2264 void SVTK_ViewWindow::activateGlobalPanning()
2266 myEventDispatcher->InvokeEvent(SVTK::StartGlobalPan,0);
2269 void SVTK_ViewWindow::onStartRecording()
2271 myRecorder->CheckExistAVIMaker();
2272 if (myRecorder->ErrorStatus()) {
2273 SUIT_MessageBox::warning(this, tr("ERROR"), tr("MSG_NO_AVI_MAKER") );
2276 SVTK_RecorderDlg* aRecorderDlg = new SVTK_RecorderDlg( this, myRecorder );
2278 if( !aRecorderDlg->exec() )
2281 myStartAction->setEnabled( false );
2282 myPlayAction->setEnabled( false );
2283 myPauseAction->setEnabled( true );
2284 myStopAction->setEnabled( true );
2286 // to prevent resizing the window while recording
2287 myPreRecordingMinSize = minimumSize();
2288 myPreRecordingMaxSize = maximumSize();
2289 setFixedSize( size() );
2291 myRecorder->Record();
2295 void SVTK_ViewWindow::onPlayRecording()
2297 myStartAction->setEnabled( false );
2298 myPlayAction->setEnabled( false );
2299 myPauseAction->setEnabled( true );
2300 myStopAction->setEnabled( true );
2302 myRecorder->Pause();
2305 void SVTK_ViewWindow::onPauseRecording()
2307 myStartAction->setEnabled( false );
2308 myPlayAction->setEnabled( true );
2309 myPauseAction->setEnabled( false );
2310 myStopAction->setEnabled( true );
2312 myRecorder->Pause();
2315 void SVTK_ViewWindow::onStopRecording()
2317 myStartAction->setEnabled( true );
2318 myPlayAction->setEnabled( false );
2319 myPauseAction->setEnabled( false );
2320 myStopAction->setEnabled( false );
2324 setMinimumSize( myPreRecordingMinSize );
2325 setMaximumSize( myPreRecordingMaxSize );
2329 To invoke a VTK event on SVTK_RenderWindowInteractor instance
2331 void SVTK_ViewWindow::InvokeEvent(unsigned long theEvent, void* theCallData)
2333 GetInteractor()->InvokeEvent(theEvent,theCallData);
2337 Modify view parameters
2339 void SVTK_ViewWindow::onViewParameters(bool theIsActivate)
2342 myViewParameterDlg->addObserver();
2343 myViewParameterDlg->show();
2345 myViewParameterDlg->hide();
2349 Custom show event handler
2351 void SVTK_ViewWindow::showEvent( QShowEvent * theEvent )
2353 emit Show( theEvent );
2357 Custom hide event handler
2359 void SVTK_ViewWindow::hideEvent( QHideEvent * theEvent )
2361 emit Hide( theEvent );
2364 void SVTK_ViewWindow::synchronizeView( SVTK_ViewWindow* viewWindow, int id )
2366 SVTK_ViewWindow* otherViewWindow = 0;
2367 QList<SVTK_ViewWindow*> compatibleViews;
2369 bool isSync = viewWindow->toolMgr()->action( SynchronizeId )->isChecked();
2371 int vwid = viewWindow->getId();
2373 SUIT_Application* app = SUIT_Session::session()->activeApplication();
2376 QList<SUIT_ViewManager*> wmlist;
2377 app->viewManagers( viewWindow->getViewManager()->getType(), wmlist );
2379 foreach( SUIT_ViewManager* wm, wmlist ) {
2380 QVector<SUIT_ViewWindow*> vwlist = wm->getViews();
2382 foreach( SUIT_ViewWindow* vw, vwlist ) {
2383 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( vw );
2384 if ( !vtkVW ) continue;
2385 if ( vtkVW->getId() == id )
2386 otherViewWindow = vtkVW;
2387 else if ( vtkVW != viewWindow )
2388 compatibleViews.append( vtkVW );
2392 if ( isSync && id ) {
2393 // remove all possible disconnections
2394 foreach( SVTK_ViewWindow* vw, compatibleViews ) {
2395 // disconnect target view
2396 vw->disconnect( SIGNAL( transformed( SVTK_ViewPort* ) ), viewWindow, SLOT( synchronize( SVTK_ViewPort* ) ) );
2397 viewWindow->disconnect( SIGNAL( transformed( SVTK_ViewPort* ) ), vw, SLOT( synchronize( SVTK_ViewPort* ) ) );
2398 if ( otherViewWindow ) {
2399 // disconnect source view
2400 vw->disconnect( SIGNAL( transformed( SVTK_ViewPort* ) ), otherViewWindow, SLOT( synchronize( SVTK_ViewPort* ) ) );
2401 otherViewWindow->disconnect( SIGNAL( transformed( SVTK_ViewPort* ) ), vw, SLOT( synchronize( SVTK_ViewPort* ) ) );
2403 QAction* a = vw->toolMgr()->action( SynchronizeId );
2405 int anid = a->data().toInt();
2406 if ( a->isChecked() && ( anid == id || anid == vwid ) ) {
2407 bool blocked = a->blockSignals( true );
2408 a->setChecked( false );
2409 a->blockSignals( blocked );
2413 if ( otherViewWindow ) {
2414 // reconnect source and target view
2415 otherViewWindow->disconnect( SIGNAL( transformed( SVTK_ViewWindow* ) ), viewWindow, SLOT( synchronize( SVTK_ViewWindow* ) ) );
2416 viewWindow->disconnect( SIGNAL( transformed( SVTK_ViewWindow* ) ), otherViewWindow, SLOT( synchronize( SVTK_ViewWindow* ) ) );
2417 otherViewWindow->connect( viewWindow, SIGNAL( transformed( SVTK_ViewWindow* ) ), SLOT( synchronize( SVTK_ViewWindow* ) ) );
2418 viewWindow->connect( otherViewWindow, SIGNAL( transformed( SVTK_ViewWindow* ) ), SLOT( synchronize( SVTK_ViewWindow* ) ) );
2419 // synchronize target view with source view
2420 viewWindow->doSetVisualParameters( otherViewWindow->getVisualParameters(), true );
2421 viewWindow->toolMgr()->action( SynchronizeId )->setData( otherViewWindow->getId() );
2422 otherViewWindow->toolMgr()->action( SynchronizeId )->setData( viewWindow->getId() );
2423 if ( !otherViewWindow->toolMgr()->action( SynchronizeId )->isChecked() ) {
2424 bool blocked = otherViewWindow->toolMgr()->action( SynchronizeId )->blockSignals( true );
2425 otherViewWindow->toolMgr()->action( SynchronizeId )->setChecked( true );
2426 otherViewWindow->toolMgr()->action( SynchronizeId )->blockSignals( blocked );
2430 else if ( otherViewWindow ) {
2431 // reconnect source and target view
2432 otherViewWindow->disconnect( SIGNAL( transformed( SVTK_ViewWindow* ) ), viewWindow, SLOT( synchronize( SVTK_ViewWindow* ) ) );
2433 viewWindow->disconnect( SIGNAL( transformed( SVTK_ViewWindow* ) ), otherViewWindow, SLOT( synchronize( SVTK_ViewWindow* ) ) );
2434 viewWindow->doSetVisualParameters( otherViewWindow->getVisualParameters(), true );
2435 viewWindow->toolMgr()->action( SynchronizeId )->setData( otherViewWindow->getId() );
2436 if ( otherViewWindow->toolMgr()->action( SynchronizeId )->data().toInt() == viewWindow->getId() && otherViewWindow->toolMgr()->action( SynchronizeId )->isChecked() ) {
2437 bool blocked = otherViewWindow->toolMgr()->action( SynchronizeId )->blockSignals( true );
2438 otherViewWindow->toolMgr()->action( SynchronizeId )->setChecked( false );
2439 otherViewWindow->toolMgr()->action( SynchronizeId )->blockSignals( blocked );
2445 "Synchronize View" action slot.
2447 void SVTK_ViewWindow::onSynchronizeView(bool checked)
2449 QAction* a = qobject_cast<QAction*>( sender() );
2451 synchronizeView( this, a->data().toInt() );
2456 Update list of available view for the "Synchronize View" action
2458 void SVTK_ViewWindow::updateSyncViews()
2460 QAction* anAction = toolMgr()->action( SynchronizeId );
2461 if ( anAction && anAction->menu() ) {
2462 int currentId = anAction->data().toInt();
2463 anAction->menu()->clear();
2464 SUIT_Application* app = SUIT_Session::session()->activeApplication();
2466 QList<SUIT_ViewManager*> wmlist;
2467 app->viewManagers( getViewManager()->getType(), wmlist );
2468 foreach( SUIT_ViewManager* wm, wmlist ) {
2469 QVector<SUIT_ViewWindow*> vwlist = wm->getViews();
2470 foreach ( SUIT_ViewWindow* vw, vwlist ) {
2471 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( vw );
2472 if ( !vtkVW || vtkVW == this ) continue;
2473 QAction* a = anAction->menu()->addAction( vtkVW->windowTitle() );
2474 if ( vtkVW->getId() == currentId ) {
2475 QFont f = a->font();
2479 a->setData( vtkVW->getId() );
2480 connect( a, SIGNAL( triggered(bool) ), this, SLOT( onSynchronizeView(bool) ) );
2484 if ( anAction->menu()->actions().isEmpty() ) {
2485 anAction->setData( 0 );
2486 anAction->menu()->addAction( tr( "MNU_SYNC_NO_VIEW" ) );
2493 Emit transformed signal.
2495 void SVTK_ViewWindow::emitTransformed() {
2502 void SVTK_ViewWindow::ProcessEvents(vtkObject* vtkNotUsed(theObject),
2503 unsigned long theEvent,
2504 void* theClientData,
2507 SVTK_ViewWindow* self = reinterpret_cast<SVTK_ViewWindow*>(theClientData);
2509 self->emitTransformed();