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_Selector.h"
81 #include "SVTK_Event.h"
82 #include "SVTK_Renderer.h"
83 #include "SVTK_ViewWindow.h"
84 #include "SVTK_InteractorStyle.h"
85 #include "SVTK_RenderWindowInteractor.h"
86 #include "SVTK_GenericRenderWindowInteractor.h"
87 #include "SVTK_CubeAxesActor2D.h"
88 #include "SVTK_ComboAction.h"
89 #include "SVTK_KeyFreeInteractorStyle.h"
90 #include "SVTK_Selector.h"
91 #include "SVTK_Recorder.h"
92 #include "SVTK_RecorderDlg.h"
94 #include "vtkPVAxesWidget.h"
95 #include "vtkPVAxesActor.h"
97 #include "SALOME_ListIteratorOfListIO.hxx"
99 #include "VTKViewer_Algorithm.h"
100 #include "SVTK_Functor.h"
102 #include <OpenGLUtils_FrameBuffer.h>
107 int convertAction( const int accelAction )
109 switch ( accelAction ) {
110 case SUIT_Accel::PanLeft : return SVTK::PanLeftEvent;
111 case SUIT_Accel::PanRight : return SVTK::PanRightEvent;
112 case SUIT_Accel::PanUp : return SVTK::PanUpEvent;
113 case SUIT_Accel::PanDown : return SVTK::PanDownEvent;
114 case SUIT_Accel::ZoomIn : return SVTK::ZoomInEvent;
115 case SUIT_Accel::ZoomOut : return SVTK::ZoomOutEvent;
116 case SUIT_Accel::RotateLeft : return SVTK::RotateLeftEvent;
117 case SUIT_Accel::RotateRight : return SVTK::RotateRightEvent;
118 case SUIT_Accel::RotateUp : return SVTK::RotateUpEvent;
119 case SUIT_Accel::RotateDown : return SVTK::RotateDownEvent;
132 SVTK_ViewWindow::SVTK_ViewWindow(SUIT_Desktop* theDesktop):
133 SUIT_ViewWindow(theDesktop),
135 myDumpImage(QImage()),
136 myKeyFreeInteractorStyle(SVTK_KeyFreeInteractorStyle::New()),
137 myEventCallbackCommand(vtkCallbackCommand::New())
139 setWindowFlags( windowFlags() & ~Qt::Window );
140 // specific of vtkSmartPointer
141 myKeyFreeInteractorStyle->Delete();
145 To initialize #SVTK_ViewWindow instance
147 void SVTK_ViewWindow::Initialize(SVTK_ViewModelBase* theModel)
149 myInteractor = new SVTK_RenderWindowInteractor(this,"SVTK_RenderWindowInteractor");
151 SVTK_Selector* aSelector = SVTK_Selector::New();
152 aSelector->SetDynamicPreSelection( SUIT_Session::session()->resourceMgr()->
153 booleanValue( "VTKViewer", "dynamic_preselection", true ) );
155 SVTK_GenericRenderWindowInteractor* aDevice = SVTK_GenericRenderWindowInteractor::New();
156 aDevice->SetRenderWidget(myInteractor);
157 aDevice->SetSelector(aSelector);
159 SVTK_Renderer* aRenderer = SVTK_Renderer::New();
160 aRenderer->Initialize(aDevice,aSelector);
162 myInteractor->Initialize(aDevice,aRenderer,aSelector);
168 myToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_LABEL"), false, Qt::AllToolBarAreas, -1, this );
169 myRecordingToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_RECORD_LABEL"), false, Qt::AllToolBarAreas, -1, this );
171 createActions( SUIT_Session::session()->resourceMgr() );
174 SetEventDispatcher(myInteractor->GetDevice());
175 myInteractor->setBackgroundRole( QPalette::NoRole );//NoBackground
176 myInteractor->setFocusPolicy(Qt::StrongFocus);
177 myInteractor->setFocus();
178 setFocusProxy(myInteractor);
180 myUpdateRateDlg = new SVTK_UpdateRateDlg( getAction( UpdateRate ), this, "SVTK_UpdateRateDlg" );
181 myNonIsometricDlg = new SVTK_NonIsometricDlg( getAction( NonIsometric ), this, "SVTK_NonIsometricDlg" );
182 myCubeAxesDlg = new SVTK_CubeAxesDlg( getAction( GraduatedAxes ), this, "SVTK_CubeAxesDlg" );
183 myCubeAxesDlg->initialize();
184 mySetRotationPointDlg = new SVTK_SetRotationPointDlg
185 ( getAction( ChangeRotationPointId ), this, "SVTK_SetRotationPointDlg" );
186 myViewParameterDlg = new SVTK_ViewParameterDlg
187 ( getAction( ViewParametersId ), this, "SVTK_ViewParameterDlg" );
189 myDefaultInteractorStyle = SVTK_InteractorStyle::New();
190 myInteractor->PushInteractorStyle(myDefaultInteractorStyle);
191 myDefaultInteractorStyle->Delete();
193 myRecorder = SVTK_Recorder::New();
195 myRecorder->SetNbFPS( 17.3 );
196 myRecorder->SetQuality( 100 );
197 myRecorder->SetProgressiveMode( true );
198 myRecorder->SetUseSkippedFrames( true );
199 myRecorder->SetRenderWindow( myInteractor->getRenderWindow() );
201 setCentralWidget(myInteractor);
203 myAxesWidget = vtkPVAxesWidget::New();
204 myAxesWidget->SetParentRenderer(aRenderer->GetDevice());
205 myAxesWidget->SetViewport(0, 0, 0.25, 0.25);
206 myAxesWidget->SetInteractor(myInteractor->GetDevice());
207 myAxesWidget->SetEnabled(1);
208 myAxesWidget->SetInteractive(0);
210 vtkPVAxesActor* anAxesActor = myAxesWidget->GetAxesActor();
211 anAxesActor->GetXAxisTipProperty()->SetColor( 1.0, 0.0, 0.0 );
212 anAxesActor->GetXAxisShaftProperty()->SetColor( 1.0, 0.0, 0.0 );
213 anAxesActor->GetXAxisLabelProperty()->SetColor( 1.0, 0.0, 0.0 );
214 anAxesActor->GetYAxisTipProperty()->SetColor( 0.0, 1.0, 0.0 );
215 anAxesActor->GetYAxisShaftProperty()->SetColor( 0.0, 1.0, 0.0 );
216 anAxesActor->GetYAxisLabelProperty()->SetColor( 0.0, 1.0, 0.0 );
217 anAxesActor->GetZAxisTipProperty()->SetColor( 0.0, 0.0, 1.0 );
218 anAxesActor->GetZAxisShaftProperty()->SetColor( 0.0, 0.0, 1.0 );
219 anAxesActor->GetZAxisLabelProperty()->SetColor( 0.0, 0.0, 1.0 );
221 myView = new SVTK_View(this);
222 Initialize(myView,theModel);
225 myEventCallbackCommand->SetClientData(this);
226 myEventCallbackCommand->SetCallback(SVTK_ViewWindow::ProcessEvents);
227 myEventCallbackCommand->Delete();
229 GetInteractor()->GetInteractorStyle()->AddObserver(SVTK::OperationFinished,
230 myEventCallbackCommand.GetPointer(), 0.0);
231 myKeyFreeInteractorStyle->AddObserver(SVTK::OperationFinished,
232 myEventCallbackCommand.GetPointer(), 0.0);
236 myInteractor->getRenderWindow()->Render();
237 setBackground( Qtx::BackgroundData( Qt::black ) ); // set default background
242 To initialize #SVTK_ViewWindow instance
244 void SVTK_ViewWindow::Initialize(SVTK_View* theView,
245 SVTK_ViewModelBase* theModel)
247 connect(theView,SIGNAL(KeyPressed(QKeyEvent*)),
248 this,SLOT(onKeyPressed(QKeyEvent*)) );
249 connect(theView,SIGNAL(KeyReleased(QKeyEvent*)),
250 this,SLOT(onKeyReleased(QKeyEvent*)));
251 connect(theView,SIGNAL(MouseButtonPressed(QMouseEvent*)),
252 this,SLOT(onMousePressed(QMouseEvent*)));
253 connect(theView,SIGNAL(MouseButtonReleased(QMouseEvent*)),
254 this,SLOT(onMouseReleased(QMouseEvent*)));
255 connect(theView,SIGNAL(MouseDoubleClicked(QMouseEvent*)),
256 this,SLOT(onMouseDoubleClicked(QMouseEvent*)));
257 connect(theView,SIGNAL(MouseMove(QMouseEvent*)),
258 this,SLOT(onMouseMoving(QMouseEvent*)));
259 connect(theView,SIGNAL(contextMenuRequested(QContextMenuEvent*)),
260 this,SIGNAL(contextMenuRequested(QContextMenuEvent *)));
261 connect(theView,SIGNAL(selectionChanged()),
262 theModel,SLOT(onSelectionChanged()));
264 connect( this, SIGNAL( transformed( SVTK_ViewWindow* ) ), SLOT( emitViewModified() ) );
270 SVTK_ViewWindow::~SVTK_ViewWindow()
272 myRecorder->Delete();
273 myAxesWidget->Delete();
278 \return corresponding view
280 SVTK_View* SVTK_ViewWindow::getView()
286 \return corresponding vtk render window
288 vtkRenderWindow* SVTK_ViewWindow::getRenderWindow()
290 return GetInteractor()->getRenderWindow();
294 \return corresponding vtk render window interactor
296 SVTK_RenderWindowInteractor* SVTK_ViewWindow::GetInteractor() const
302 \return corresponding vtk render window interactor
304 vtkRenderWindowInteractor* SVTK_ViewWindow::getInteractor() const
306 return myInteractor->GetDevice();
310 \return corresponding vtk renderer
312 vtkRenderer* SVTK_ViewWindow::getRenderer() const
314 return GetInteractor()->getRenderer();
318 Redirect the request to SVTK_RenderWindowInteractor::GetRenderer
320 SVTK_Renderer* SVTK_ViewWindow::GetRenderer() const
322 return GetInteractor()->GetRenderer();
326 \return corresponding vtk selector
328 SVTK_Selector* SVTK_ViewWindow::GetSelector() const
330 return GetInteractor()->GetSelector();
334 Processes transformation "front view"
336 void SVTK_ViewWindow::onFrontView()
338 GetRenderer()->OnFrontView();
340 emit transformed( this );
344 Processes transformation "back view"
346 void SVTK_ViewWindow::onBackView()
348 GetRenderer()->OnBackView();
350 emit transformed( this );
354 Processes transformation "top view"
356 void SVTK_ViewWindow::onTopView()
358 GetRenderer()->OnTopView();
360 emit transformed( this );
364 Processes transformation "bottom view"
366 void SVTK_ViewWindow::onBottomView()
368 GetRenderer()->OnBottomView();
370 emit transformed( this );
374 Processes transformation "left view"
376 void SVTK_ViewWindow::onLeftView()
378 GetRenderer()->OnLeftView();
380 emit transformed( this );
384 Processes transformation "right view"
386 void SVTK_ViewWindow::onRightView()
388 GetRenderer()->OnRightView();
390 emit transformed( this );
394 \brief Rotate view 90 degrees clockwise
396 void SVTK_ViewWindow::onClockWiseView()
398 GetRenderer()->onClockWiseView();
400 emit transformed( this );
404 \brief Rotate view 90 degrees conterclockwise
406 void SVTK_ViewWindow::onAntiClockWiseView()
408 GetRenderer()->onAntiClockWiseView();
410 emit transformed( this );
414 Processes transformation "reset view": sets default orientation of viewport camera
416 void SVTK_ViewWindow::onResetView()
418 GetRenderer()->OnResetView();
420 emit transformed( this );
424 Processes transformation "fit all"
426 void SVTK_ViewWindow::onFitAll()
428 GetRenderer()->OnFitAll();
430 emit transformed( this );
434 SLOT: called if selection is changed
436 void SVTK_ViewWindow::onSelectionChanged()
438 myView->onSelectionChanged();
442 Change selection mode
443 \param theMode - new selection mode
445 void SVTK_ViewWindow::SetSelectionMode(Selection_Mode theMode)
447 GetSelector()->SetSelectionMode(theMode);
451 \return selection mode
453 Selection_Mode SVTK_ViewWindow::SelectionMode() const
455 return GetSelector()->SelectionMode();
459 Unhilights all objects in viewer
461 void SVTK_ViewWindow::unHighlightAll()
463 myView->unHighlightAll();
467 Hilights/unhilights object in viewer
468 \param theIO - object to be updated
469 \param theIsHighlight - if it is true, object will be hilighted, otherwise it will be unhilighted
470 \param theIsUpdate - update current viewer
472 void SVTK_ViewWindow::highlight(const Handle(SALOME_InteractiveObject)& theIO,
476 myView->highlight( theIO, theIsHighlight, theIsUpdate );
480 \return true if object is in viewer or in collector
481 \param theIO - object to be checked
483 bool SVTK_ViewWindow::isInViewer( const Handle(SALOME_InteractiveObject)& theIO )
485 return myView->isInViewer( theIO );
489 \return true if object is displayed in viewer
490 \param theIO - object to be checked
492 bool SVTK_ViewWindow::isVisible( const Handle(SALOME_InteractiveObject)& theIO )
494 return myView->isVisible( theIO );
499 \param theEntry - entry that corresponds to intractive objects
501 Handle(SALOME_InteractiveObject) SVTK_ViewWindow::FindIObject(const char* theEntry)
503 return myView->FindIObject(theEntry);
508 \param theIO - object
509 \param theImmediatly - update viewer
511 void SVTK_ViewWindow::Display(const Handle(SALOME_InteractiveObject)& theIO,
514 myView->Display(theIO,theImmediatly);
519 \param theIO - object
520 \param theImmediatly - update viewer
522 void SVTK_ViewWindow::Erase(const Handle(SALOME_InteractiveObject)& theIO,
525 myView->Erase(theIO,theImmediatly);
529 Display only passed object
530 \param theIO - object
532 void SVTK_ViewWindow::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIO)
534 myView->DisplayOnly(theIO);
538 Display all objects in view
540 void SVTK_ViewWindow::DisplayAll()
542 myView->DisplayAll();
546 Erase all objects in view
548 void SVTK_ViewWindow::EraseAll()
554 Sets background color [obsolete]
555 \param color - new background color
557 void SVTK_ViewWindow::setBackgroundColor( const QColor& c )
559 Qtx::BackgroundData bg = background();
565 \return background color of viewer [obsolete]
567 QColor SVTK_ViewWindow::backgroundColor() const
569 return background().color();
574 \param bgData - new background data
576 void SVTK_ViewWindow::setBackground( const Qtx::BackgroundData& bgData )
580 if ( bgData.isValid() ) {
581 switch ( bgData.mode() ) {
582 case Qtx::ColorBackground:
584 QColor c = bgData.color();
586 // show solid-colored background
587 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
588 getRenderer()->SetGradientBackground( false ); // cancel gradient mode
589 getRenderer()->SetBackground( c.red()/255.0,
591 c.blue()/255.0 ); // set background color
596 case Qtx::SimpleGradientBackground:
599 int type = bgData.gradient( c1, c2 );
605 // show two-color gradient background
606 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
607 getRenderer()->SetGradientBackground( true ); // switch to gradient mode
609 VTKViewer_OpenGLRenderer* aRenderer =
610 VTKViewer_OpenGLRenderer::SafeDownCast( getRenderer() );
613 aRenderer->SetGradientType( type );
614 aRenderer->SetBackground( c1.redF(), c1.greenF(), c1.blueF() );
615 aRenderer->SetBackground2( c2.redF(), c2.greenF(), c2.blueF() );
621 case Qtx::CustomGradientBackground:
623 // NOT IMPLEMENTED YET
624 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
625 getRenderer()->SetGradientBackground( false ); // cancel gradient mode
632 if ( bgData.isTextureShown() ) {
634 int textureMode = bgData.texture( fileName );
635 QFileInfo fi( fileName );
636 if ( !fileName.isEmpty() && fi.exists() ) {
637 // read texture from file
638 QString extension = fi.suffix().toLower();
639 vtkImageReader2* aReader = 0;
640 if ( extension == "jpg" || extension == "jpeg" )
641 aReader = vtkJPEGReader::New();
642 else if ( extension == "bmp" )
643 aReader = vtkBMPReader::New();
644 else if ( extension == "tif" || extension == "tiff" )
645 aReader = vtkTIFFReader::New();
646 else if ( extension == "png" )
647 aReader = vtkPNGReader::New();
648 else if ( extension == "mhd" || extension == "mha" )
649 aReader = vtkMetaImageReader::New();
652 aReader->SetFileName( fi.absoluteFilePath().toLatin1().constData() );
654 VTKViewer_Texture* aTexture = VTKViewer_Texture::New();
655 vtkImageMapToColors* aMap = 0;
656 vtkAlgorithmOutput* anOutput;
658 // special processing for BMP reader
659 vtkBMPReader* aBMPReader = (vtkBMPReader*)aReader;
661 // Special processing for BMP file
662 aBMPReader->SetAllow8BitBMP(1);
664 aMap = vtkImageMapToColors::New();
665 aMap->SetInputConnection( aBMPReader->GetOutputPort() );
666 aMap->SetLookupTable( (vtkScalarsToColors*)aBMPReader->GetLookupTable() );
667 aMap->SetOutputFormatToRGB();
669 anOutput = aMap->GetOutputPort();
674 anOutput = aReader->GetOutputPort( 0 );
675 aTexture->SetInputConnection( anOutput );
677 // VSR: Currently, VTK only supports Stretch mode, so below code will give
678 // the same results for all modes
679 switch ( textureMode ) {
680 case Qtx::TileTexture:
681 aTexture->SetPosition((int)VTKViewer_Texture::Tiled);
683 case Qtx::StretchTexture:
684 aTexture->SetPosition((int)VTKViewer_Texture::Stretched);
686 case Qtx::CenterTexture:
687 aTexture->SetPosition((int)VTKViewer_Texture::Centered);
691 // show textured background
692 getRenderer()->SetTexturedBackground( true );
693 getRenderer()->SetBackgroundTexture( aTexture );
695 // clean-up resources
706 myBackground = bgData;
710 \return background data of viewer
712 Qtx::BackgroundData SVTK_ViewWindow::background() const
719 Redirect the request to SVTK_RenderWindowInteractor::GetInteractorStyle
721 vtkInteractorStyle* SVTK_ViewWindow::GetInteractorStyle() const
723 return GetInteractor()->GetInteractorStyle();
727 Redirect the request to SVTK_RenderWindowInteractor::PushInteractorStyle
729 void SVTK_ViewWindow::PushInteractorStyle(vtkInteractorStyle* theStyle)
731 GetInteractor()->PushInteractorStyle(theStyle);
735 Redirect the request to SVTK_RenderWindowInteractor::PopInteractorStyle
737 void SVTK_ViewWindow::PopInteractorStyle()
739 GetInteractor()->PopInteractorStyle();
743 Updates current viewer
745 void SVTK_ViewWindow::Repaint(bool theUpdateTrihedron)
747 if(theUpdateTrihedron)
748 GetRenderer()->OnAdjustTrihedron();
750 GetInteractor()->update();
752 SVTK_InteractorStyle* aStyle = (SVTK_InteractorStyle*)getInteractor()->GetInteractorStyle();
758 Redirect the request to #SVTK_Renderer::GetScale
760 void SVTK_ViewWindow::GetScale( double theScale[3] )
762 GetRenderer()->GetScale( theScale );
766 Redirect the request to #SVTK_Renderer::SetScale
768 void SVTK_ViewWindow::SetScale( double theScale[3] )
770 GetRenderer()->SetScale( theScale );
772 emit transformed( this );
776 Redirect the request to #SVTK_Renderer::IsTrihedronDisplayed
778 bool SVTK_ViewWindow::isTrihedronDisplayed()
780 return GetRenderer()->IsTrihedronDisplayed();
784 Redirect the request to #SVTK_Renderer::IsCubeAxesDisplayed
786 bool SVTK_ViewWindow::isCubeAxesDisplayed()
788 return GetRenderer()->IsCubeAxesDisplayed();
792 Redirect the request to #SVTK_Renderer::OnViewTrihedron
794 void SVTK_ViewWindow::onViewTrihedron()
796 GetRenderer()->OnViewTrihedron();
801 Redirect the request to #SVTK_Renderer::OnViewCubeAxes
803 void SVTK_ViewWindow::onViewCubeAxes()
805 GetRenderer()->OnViewCubeAxes();
810 Redirect the request to #SVTK_Renderer::GetTrihedron
812 VTKViewer_Trihedron* SVTK_ViewWindow::GetTrihedron()
814 return GetRenderer()->GetTrihedron();
818 Redirect the request to #SVTK_Renderer::GetCubeAxes
820 SVTK_CubeAxesActor2D* SVTK_ViewWindow::GetCubeAxes()
822 return GetRenderer()->GetCubeAxes();
826 \return trihedron size
828 vtkFloatingPointType SVTK_ViewWindow::GetTrihedronSize() const
830 return GetRenderer()->GetTrihedronSize();
835 \param theMode - projection mode ( 0 - orthogonal, 1 - perspective )
837 void SVTK_ViewWindow::SetProjectionMode(const int theMode)
839 activateProjectionMode( theMode );
844 Set the gravity center as a focal point
846 void SVTK_ViewWindow::activateSetFocalPointGravity()
848 myEventDispatcher->InvokeEvent(SVTK::SetFocalPointGravity, 0);
852 Set the selected point as a focal point
854 void SVTK_ViewWindow::activateSetFocalPointSelected()
856 myEventDispatcher->InvokeEvent(SVTK::SetFocalPointSelected, 0);
860 Set the point selected by user as a focal point
862 void SVTK_ViewWindow::activateStartFocalPointSelection()
864 myEventDispatcher->InvokeEvent(SVTK::StartFocalPointSelection,0);
867 void SVTK_ViewWindow::activateProjectionMode(int theMode)
870 toolMgr()->action( ProjectionModeId )->setChecked( true );
872 toolMgr()->action( ParallelModeId )->setChecked( true );
876 Sets actual interaction style
877 \param theStyle - type of interaction style ( 0 - standard, 1 - keyboard free )
879 void SVTK_ViewWindow::SetInteractionStyle(const int theStyle)
881 onSwitchInteractionStyle( theStyle==1 );
885 Sets actual zooming style
886 \param theStyle - type of zooming style ( 0 - standard, 1 - advanced (at cursor) )
888 void SVTK_ViewWindow::SetZoomingStyle(const int theStyle)
890 onSwitchZoomingStyle( theStyle==1 );
894 Switch dynamic preselection on / off
895 \param theDynPreselection - dynamic pre-selection mode
897 void SVTK_ViewWindow::SetDynamicPreSelection( bool theDynPreselection )
899 onSwitchDynamicPreSelection( theDynPreselection );
903 Switches "keyboard free" interaction style on/off
905 void SVTK_ViewWindow::onSwitchInteractionStyle(bool theOn)
908 // check if style is already set
909 if ( GetInteractorStyle() != myKeyFreeInteractorStyle.GetPointer() )
911 // keep the same style extensions
912 SVTK_InteractorStyle* aStyle = (SVTK_InteractorStyle*)GetInteractorStyle();
914 myKeyFreeInteractorStyle->SetControllerIncrement(aStyle->ControllerIncrement());
915 myKeyFreeInteractorStyle->SetControllerOnKeyDown(aStyle->ControllerOnKeyDown());
918 PushInteractorStyle(myKeyFreeInteractorStyle.GetPointer());
922 // pop only key free style
923 if ( GetInteractorStyle() == myKeyFreeInteractorStyle.GetPointer() )
924 PopInteractorStyle();
927 // update action state if method is called outside
928 QtxAction* a = getAction( SwitchInteractionStyleId );
929 if ( a->isChecked() != theOn ) a->setChecked( theOn );
933 Toogles advanced zooming style (relatively to the cursor position) on/off
935 void SVTK_ViewWindow::onSwitchZoomingStyle( bool theOn )
937 if( myDefaultInteractorStyle.GetPointer() )
938 myDefaultInteractorStyle->SetAdvancedZoomingEnabled( theOn );
939 if( myKeyFreeInteractorStyle.GetPointer() )
940 myKeyFreeInteractorStyle->SetAdvancedZoomingEnabled( theOn );
942 // update action state if method is called outside
943 QtxAction* a = getAction( SwitchZoomingStyleId );
944 if ( a->isChecked() != theOn )
945 a->setChecked( theOn );
949 Toogles dynamic preselection on/off
951 void SVTK_ViewWindow::onSwitchDynamicPreSelection( bool theOn )
953 GetSelector()->SetDynamicPreSelection( theOn );
955 // update action state if method is called outside
956 QtxAction* a = getAction( SwitchDynamicPreselectionId );
957 if ( a->isChecked() != theOn )
958 a->setChecked( theOn );
962 Sets incremental speed
963 \param theValue - new incremental speed
964 \param theMode - modification mode
966 void SVTK_ViewWindow::SetIncrementalSpeed(const int theValue, const int theMode)
968 if ( (SVTK_InteractorStyle*)GetInteractorStyle() )
969 ((SVTK_InteractorStyle*)GetInteractorStyle())->SetIncrementSpeed(theValue, theMode);
973 Sets spacemouse buttons for the functions
974 \param theBtn1 - spacemouse button for the "decrease speed increment"
975 \param theBtn2 - spacemouse button for the "increase speed increment"
976 \param theBtn3 - spacemouse button for the "dominant combined switch"
978 void SVTK_ViewWindow::SetSpacemouseButtons(const int theBtn1,
983 myEventDispatcher->InvokeEvent(SVTK::SetSMDecreaseSpeedEvent, &val);
985 myEventDispatcher->InvokeEvent(SVTK::SetSMIncreaseSpeedEvent, &val);
987 myEventDispatcher->InvokeEvent(SVTK::SetSMDominantCombinedSwitchEvent, &val);
992 \param theSize - new trihedron size
993 \param theRelative - trihedron relativeness
995 void SVTK_ViewWindow::SetTrihedronSize(const vtkFloatingPointType theSize, const bool theRelative)
997 GetRenderer()->SetTrihedronSize(theSize, theRelative);
1001 /*! If parameter theIsForcedUpdate is true, recalculate parameters for
1002 * trihedron and cube axes, even if trihedron and cube axes is invisible.
1004 void SVTK_ViewWindow::AdjustTrihedrons(const bool theIsForcedUpdate)
1006 GetRenderer()->AdjustActors();
1011 Redirect the request to #SVTK_Renderer::OnAdjustTrihedron
1013 void SVTK_ViewWindow::onAdjustTrihedron()
1015 GetRenderer()->OnAdjustTrihedron();
1019 Redirect the request to #SVTK_Renderer::OnAdjustCubeAxes
1021 void SVTK_ViewWindow::onAdjustCubeAxes()
1023 GetRenderer()->OnAdjustCubeAxes();
1026 void SVTK_ViewWindow::synchronize(SVTK_ViewWindow* otherViewWindow )
1028 if ( otherViewWindow ) {
1029 bool blocked = blockSignals( true );
1030 doSetVisualParameters( otherViewWindow->getVisualParameters(), true );
1031 blockSignals( blocked );
1038 void SVTK_ViewWindow::onKeyPressed(QKeyEvent* event)
1040 emit keyPressed( this, event );
1046 void SVTK_ViewWindow::onKeyReleased(QKeyEvent* event)
1048 emit keyReleased( this, event );
1054 void SVTK_ViewWindow::onMousePressed(QMouseEvent* event)
1056 emit mousePressed(this, event);
1060 Emits mouse released
1062 void SVTK_ViewWindow::onMouseReleased(QMouseEvent* event)
1064 emit mouseReleased( this, event );
1070 void SVTK_ViewWindow::onMouseMoving(QMouseEvent* event)
1072 emit mouseMoving( this, event );
1076 Emits mouse double clicked
1078 void SVTK_ViewWindow::onMouseDoubleClicked( QMouseEvent* event )
1080 emit mouseDoubleClicked( this, event );
1084 Redirect the request to #SVTK_Renderer::AddActor
1086 void SVTK_ViewWindow::AddActor( VTKViewer_Actor* theActor,
1088 bool theIsAdjustActors )
1090 GetRenderer()->AddActor(theActor, theIsAdjustActors);
1093 emit actorAdded(theActor);
1097 Redirect the request to #SVTK_Renderer::RemoveActor
1099 void SVTK_ViewWindow::RemoveActor( VTKViewer_Actor* theActor,
1101 bool theIsAdjustActors )
1103 GetRenderer()->RemoveActor(theActor, theIsAdjustActors);
1106 emit actorRemoved(theActor);
1109 QImage SVTK_ViewWindow::dumpViewContent()
1111 vtkRenderWindow* aWindow = getRenderWindow();
1112 int* aSize = aWindow->GetSize();
1113 int aWidth = aSize[0];
1114 int aHeight = aSize[1];
1116 OpenGLUtils_FrameBuffer aFrameBuffer;
1117 if( aFrameBuffer.init( aWidth, aHeight ) )
1119 glPushAttrib( GL_VIEWPORT_BIT );
1120 glViewport( 0, 0, aWidth, aHeight );
1121 aFrameBuffer.bind();
1126 aFrameBuffer.unbind();
1129 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
1131 aFrameBuffer.bind();
1132 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
1133 aFrameBuffer.unbind();
1135 anImage = anImage.rgbSwapped();
1136 anImage = anImage.mirrored();
1140 // if frame buffers are unsupported, use old functionality
1141 unsigned char *aData =
1142 aWindow->GetRGBACharPixelData( 0, 0, aWidth-1, aHeight-1, 0 );
1144 QImage anImage( aData, aWidth, aHeight, QImage::Format_ARGB32 );
1146 anImage = anImage.rgbSwapped();
1147 anImage = anImage.mirrored();
1152 \return QImage, containing all scene rendering in window
1154 QImage SVTK_ViewWindow::dumpView()
1156 if( myDumpImage.isNull() )
1157 return dumpViewContent();
1163 QString SVTK_ViewWindow::filter() const
1165 return tr( "SVTK_IMAGE_FILES" );
1168 bool SVTK_ViewWindow::dumpViewToFormat( const QImage& img, const QString& fileName, const QString& format )
1170 if ( format != "PS" && format != "EPS" && format != "PDF" )
1171 return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
1173 SUIT_OverrideCursor wc;
1175 vtkGL2PSExporter *anExporter = vtkGL2PSExporter::New();
1176 anExporter->SetRenderWindow(getRenderWindow());
1178 if ( format == "PS" ) {
1179 anExporter->SetFileFormatToPS();
1180 anExporter->CompressOff();
1183 if ( format == "EPS" ) {
1184 anExporter->SetFileFormatToEPS();
1185 anExporter->CompressOff();
1188 if ( format == "PDF" ) {
1189 anExporter->SetFileFormatToPDF();
1192 QString aFilePrefix(fileName);
1193 QString anExtension(SUIT_Tools::extension(fileName));
1194 aFilePrefix.truncate(aFilePrefix.length() - 1 - anExtension.length());
1195 anExporter->SetFilePrefix(aFilePrefix.toLatin1().data());
1196 anExporter->Write();
1197 anExporter->Delete();
1203 \refresh QImage, containing all scene rendering in window
1205 void SVTK_ViewWindow::RefreshDumpImage()
1207 myDumpImage = dumpViewContent();
1211 Redirect the request to #SVTK_Renderer::SetSelectionProp
1213 void SVTK_ViewWindow::SetSelectionProp(const double& theRed,
1214 const double& theGreen,
1215 const double& theBlue,
1216 const int& theWidth)
1218 myView->SetSelectionProp(theRed,theGreen,theBlue,theWidth);
1222 Redirect the request to #SVTK_Renderer::SetSelectionProp
1224 void SVTK_ViewWindow::SetPreselectionProp(const double& theRed,
1225 const double& theGreen,
1226 const double& theBlue,
1227 const int& theWidth)
1229 myView->SetPreselectionProp(theRed,theGreen,theBlue,theWidth);
1233 Redirect the request to #SVTK_Renderer::SetSelectionTolerance
1235 void SVTK_ViewWindow::SetSelectionTolerance(const double& theTolNodes,
1236 const double& theTolItems,
1237 const double& theTolObjects)
1239 myView->SetSelectionTolerance(theTolNodes, theTolItems, theTolObjects);
1243 Get visibility status of the static trihedron
1245 bool SVTK_ViewWindow::IsStaticTrihedronVisible() const
1247 return (bool)myAxesWidget->GetEnabled();
1251 Set visibility status of the static trihedron
1253 void SVTK_ViewWindow::SetStaticTrihedronVisible( const bool theIsVisible )
1255 myAxesWidget->SetEnabled( (int)theIsVisible );
1260 \param accelAction - action
1262 bool SVTK_ViewWindow::action( const int accelAction )
1264 if ( accelAction == SUIT_Accel::ZoomFit )
1267 int anEvent = SVTK::convertAction( accelAction );
1268 GetInteractor()->InvokeEvent(anEvent, 0);
1274 \return action by it's id
1276 QtxAction* SVTK_ViewWindow::getAction( int id ) const
1278 return dynamic_cast<QtxAction*>( toolMgr()->action( id ) );
1282 // old visual parameters had 13 values. New format added additional
1283 // 76 values for graduated axes, so both numbers are processed.
1284 const int nNormalParams = 13; // number of view windows parameters excluding graduated axes params
1285 const int nGradAxisParams = 25; // number of parameters of ONE graduated axis (X, Y, or Z)
1286 const int nTrihedronParams = 3; // number of parameters for Trihedron
1287 const int nAllParams = nNormalParams + 3*nGradAxisParams + nTrihedronParams + 1; // number of all visual parameters
1289 /*! The method returns visual parameters of a graduated axis actor (x,y,z axis of graduated axes)
1291 void getGradAxisVisualParams( QXmlStreamWriter& writer, vtkAxisActor2D* actor, QString theAxis )
1298 bool isVisible = actor->GetTitleVisibility();
1299 QString title ( actor->GetTitle() );
1300 vtkFloatingPointType color[ 3 ];
1301 int font = VTK_ARIAL;
1306 vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1309 txtProp->GetColor( color );
1310 font = txtProp->GetFontFamily();
1311 bold = txtProp->GetBold();
1312 italic = txtProp->GetItalic();
1313 shadow = txtProp->GetShadow();
1315 writer.writeStartElement("GraduatedAxis");
1316 writer.writeAttribute("Axis", theAxis);
1318 writer.writeStartElement("Title");
1319 writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1320 writer.writeAttribute("Text", title);
1321 writer.writeAttribute("Font", QString("%1").arg(font));
1322 writer.writeAttribute("Bold", QString("%1").arg(bold));
1323 writer.writeAttribute("Italic", QString("%1").arg(italic));
1324 writer.writeAttribute("Shadow", QString("%1").arg(shadow));
1326 writer.writeStartElement("Color");
1327 writer.writeAttribute("R", QString("%1").arg(color[0]));
1328 writer.writeAttribute("G", QString("%1").arg(color[1]));
1329 writer.writeAttribute("B", QString("%1").arg(color[2]));
1330 writer.writeEndElement();
1331 writer.writeEndElement();
1333 //params.sprintf( "* Graduated Axis: * Name *%u*%s*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible,
1334 // title.toLatin1().data(), color[0], color[1], color[2], font, bold, italic, shadow );
1337 isVisible = actor->GetLabelVisibility();
1338 int labels = actor->GetNumberOfLabels();
1339 int offset = actor->GetTickOffset();
1345 txtProp = actor->GetLabelTextProperty();
1348 txtProp->GetColor( color );
1349 font = txtProp->GetFontFamily();
1350 bold = txtProp->GetBold();
1351 italic = txtProp->GetItalic();
1352 shadow = txtProp->GetShadow();
1355 writer.writeStartElement("Labels");
1356 writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1357 writer.writeAttribute("Number", QString("%1").arg(labels));
1358 writer.writeAttribute("Offset", QString("%1").arg(offset));
1359 writer.writeAttribute("Font", QString("%1").arg(font));
1360 writer.writeAttribute("Bold", QString("%1").arg(bold));
1361 writer.writeAttribute("Italic", QString("%1").arg(italic));
1362 writer.writeAttribute("Shadow", QString("%1").arg(shadow));
1364 writer.writeStartElement("Color");
1365 writer.writeAttribute("R", QString("%1").arg(color[0]));
1366 writer.writeAttribute("G", QString("%1").arg(color[1]));
1367 writer.writeAttribute("B", QString("%1").arg(color[2]));
1368 writer.writeEndElement();
1369 writer.writeEndElement();
1370 // params += QString().sprintf( "* Labels *%u*%u*%u*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible, labels, offset,
1371 // color[0], color[1], color[2], font, bold, italic, shadow );
1374 isVisible = actor->GetTickVisibility();
1375 int length = actor->GetTickLength();
1376 writer.writeStartElement("TickMarks");
1377 writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1378 writer.writeAttribute("Length", QString("%1").arg(length));
1379 writer.writeEndElement();
1381 //params += QString().sprintf( "* Tick marks *%u*%u", isVisible, length );
1383 writer.writeEndElement();
1387 void setGradAxisVisualParams(QXmlStreamReader& reader, vtkAxisActor2D* actor)
1394 } while (!reader.isStartElement());
1396 // Read title params
1397 QXmlStreamAttributes aAttr = reader.attributes();
1398 bool isVisible = aAttr.value("isVisible").toString().toUShort();
1399 QString title = aAttr.value("Text").toString();
1400 int font = aAttr.value("Font").toString().toInt();
1401 int bold = aAttr.value("Bold").toString().toInt();
1402 int italic = aAttr.value("Italic").toString().toInt();
1403 int shadow = aAttr.value("Shadow").toString().toInt();
1405 //printf("#### TITLE: %i, %s, %i, %i, %i, %i\n", isVisible, qPrintable(title), font, bold, italic, shadow);
1409 } while (!reader.isStartElement());
1412 aAttr = reader.attributes();
1414 vtkFloatingPointType color[3];
1415 color[0] = aAttr.value("R").toString().toDouble();
1416 color[1] = aAttr.value("G").toString().toDouble();
1417 color[2] = aAttr.value("B").toString().toDouble();
1418 //printf("#### Color: %f, %f, %f\n", color[0], color[1], color[2]);
1420 actor->SetTitleVisibility( isVisible );
1421 actor->SetTitle( title.toLatin1() );
1422 vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1424 txtProp->SetColor( color );
1425 txtProp->SetFontFamily( font );
1426 txtProp->SetBold( bold );
1427 txtProp->SetItalic( italic );
1428 txtProp->SetShadow( shadow );
1435 } while (!reader.isStartElement());
1437 aAttr = reader.attributes();
1438 isVisible = aAttr.value("isVisible").toString().toUShort();
1439 int labels = aAttr.value("Number").toString().toInt();
1440 int offset = aAttr.value("Offset").toString().toInt();
1441 font = aAttr.value("Font").toString().toInt();
1442 bold = aAttr.value("Bold").toString().toInt();
1443 italic = aAttr.value("Italic").toString().toInt();
1444 shadow = aAttr.value("Shadow").toString().toInt();
1448 } while (!reader.isStartElement());
1450 aAttr = reader.attributes();
1452 color[0] = aAttr.value("R").toString().toDouble();
1453 color[1] = aAttr.value("G").toString().toDouble();
1454 color[2] = aAttr.value("B").toString().toDouble();
1456 actor->SetLabelVisibility( isVisible );
1457 actor->SetNumberOfLabels( labels );
1458 actor->SetTickOffset( offset );
1459 txtProp = actor->GetLabelTextProperty();
1461 txtProp->SetColor( color );
1462 txtProp->SetFontFamily( font );
1463 txtProp->SetBold( bold );
1464 txtProp->SetItalic( italic );
1465 txtProp->SetShadow( shadow );
1471 } while (!reader.isStartElement());
1472 aAttr = reader.attributes();
1474 // retrieve and set tick marks properties
1475 isVisible = aAttr.value("isVisible").toString().toUShort();
1476 int length = aAttr.value("Length").toString().toInt();
1478 actor->SetTickVisibility( isVisible );
1479 actor->SetTickLength( length );
1482 /*! The method restores visual parameters of a graduated axis actor (x,y,z axis)
1484 void setGradAxisVisualParams( vtkAxisActor2D* actor, const QString& params )
1489 QStringList paramsLst = params.split( '*' );
1491 if ( paramsLst.size() == nGradAxisParams ) { // altogether name, lable, ticks parameters make up 25 values
1493 // retrieve and set name parameters
1494 bool isVisible = paramsLst[2].toUShort();
1495 QString title = paramsLst[3];
1496 vtkFloatingPointType color[3];
1497 color[0] = paramsLst[4].toDouble();
1498 color[1] = paramsLst[5].toDouble();
1499 color[2] = paramsLst[6].toDouble();
1500 int font = paramsLst[7].toInt();
1501 int bold = paramsLst[8].toInt();
1502 int italic = paramsLst[9].toInt();
1503 int shadow = paramsLst[10].toInt();
1505 actor->SetTitleVisibility( isVisible );
1506 actor->SetTitle( title.toLatin1() );
1507 vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1509 txtProp->SetColor( color );
1510 txtProp->SetFontFamily( font );
1511 txtProp->SetBold( bold );
1512 txtProp->SetItalic( italic );
1513 txtProp->SetShadow( shadow );
1516 // retrieve and set lable parameters
1517 isVisible = paramsLst[12].toUShort();
1518 int labels = paramsLst[13].toInt();
1519 int offset = paramsLst[14].toInt();
1520 color[0] = paramsLst[15].toDouble();
1521 color[1] = paramsLst[16].toDouble();
1522 color[2] = paramsLst[17].toDouble();
1523 font = paramsLst[18].toInt();
1524 bold = paramsLst[19].toInt();
1525 italic = paramsLst[20].toInt();
1526 shadow = paramsLst[21].toInt();
1528 actor->SetLabelVisibility( isVisible );
1529 actor->SetNumberOfLabels( labels );
1530 actor->SetTickOffset( offset );
1531 txtProp = actor->GetLabelTextProperty();
1533 txtProp->SetColor( color );
1534 txtProp->SetFontFamily( font );
1535 txtProp->SetBold( bold );
1536 txtProp->SetItalic( italic );
1537 txtProp->SetShadow( shadow );
1540 // retrieve and set tick marks properties
1541 isVisible = paramsLst[23].toUShort();
1542 int length = paramsLst[24].toInt();
1544 actor->SetTickVisibility( isVisible );
1545 actor->SetTickLength( length );
1549 /*! The method returns the visual parameters of this view as a formated string
1551 QString SVTK_ViewWindow::getVisualParameters()
1553 double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
1555 // save position, focal point, viewUp, scale
1556 vtkCamera* camera = getRenderer()->GetActiveCamera();
1557 camera->GetPosition( pos );
1558 camera->GetFocalPoint( focalPnt );
1559 camera->GetViewUp( viewUp );
1560 parScale = camera->GetParallelScale();
1563 // Parameters are given in the following format:view position (3 digits), focal point position (3 digits)
1564 // view up values (3 digits), parallel scale (1 digit), scale (3 digits,
1565 // Graduated axes parameters (X, Y, Z axes parameters)
1567 QXmlStreamWriter aWriter(&retStr);
1568 aWriter.setAutoFormatting(true);
1570 aWriter.writeStartDocument();
1571 aWriter.writeStartElement("ViewState");
1573 aWriter.writeStartElement("Position");
1574 aWriter.writeAttribute("X", QString("%1").arg(pos[0]));
1575 aWriter.writeAttribute("Y", QString("%1").arg(pos[1]));
1576 aWriter.writeAttribute("Z", QString("%1").arg(pos[2]));
1577 aWriter.writeEndElement();
1579 aWriter.writeStartElement("FocalPoint");
1580 aWriter.writeAttribute("X", QString::number(focalPnt[0]));
1581 aWriter.writeAttribute("Y", QString::number(focalPnt[1]));
1582 aWriter.writeAttribute("Z", QString::number(focalPnt[2]));
1583 aWriter.writeEndElement();
1585 aWriter.writeStartElement("ViewUp");
1586 aWriter.writeAttribute("X", QString::number(viewUp[0]));
1587 aWriter.writeAttribute("Y", QString::number(viewUp[1]));
1588 aWriter.writeAttribute("Z", QString::number(viewUp[2]));
1589 aWriter.writeEndElement();
1591 aWriter.writeStartElement("ViewScale");
1592 aWriter.writeAttribute("Parallel", QString::number(parScale));
1593 aWriter.writeAttribute("X", QString::number(scale[0]));
1594 aWriter.writeAttribute("Y", QString::number(scale[1]));
1595 aWriter.writeAttribute("Z", QString::number(scale[2]));
1596 aWriter.writeEndElement();
1598 if ( SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes() ) {
1599 aWriter.writeStartElement("DisplayCubeAxis");
1600 aWriter.writeAttribute("Show", QString( "%1" ).arg( GetRenderer()->IsCubeAxesDisplayed()));
1601 aWriter.writeEndElement();
1603 getGradAxisVisualParams(aWriter, gradAxesActor->GetXAxisActor2D(), "X");
1604 getGradAxisVisualParams(aWriter, gradAxesActor->GetYAxisActor2D(), "Y");
1605 getGradAxisVisualParams(aWriter, gradAxesActor->GetZAxisActor2D(), "Z");
1608 aWriter.writeStartElement("Trihedron");
1609 aWriter.writeAttribute("isShown", QString( "%1" ).arg( isTrihedronDisplayed()));
1610 aWriter.writeAttribute("Size", QString::number(GetTrihedronSize()));
1611 aWriter.writeEndElement();
1613 aWriter.writeStartElement("Background");
1614 aWriter.writeAttribute("Value", QString( "%1" ).arg( Qtx::backgroundToString(background()) ));
1615 aWriter.writeEndElement();
1617 aWriter.writeEndElement();
1618 aWriter.writeEndDocument();
1624 The method restores visual parameters of this view or postpones it untill the view is shown
1626 void SVTK_ViewWindow::setVisualParameters( const QString& parameters )
1628 //printf("#### %s\n", qPrintable(parameters));
1629 SVTK_RenderWindowInteractor* anInteractor = GetInteractor();
1630 if ( anInteractor->isVisible() ) {
1631 doSetVisualParameters( parameters );
1634 myVisualParams = parameters;
1635 anInteractor->installEventFilter(this);
1640 The method restores visual parameters of this view from a formated string
1642 void SVTK_ViewWindow::doSetVisualParameters( const QString& parameters, bool baseParamsOnly )
1645 double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
1647 QXmlStreamReader aReader(parameters);
1648 SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes();
1650 while(!aReader.atEnd()) {
1652 if (aReader.isStartElement()) {
1653 QXmlStreamAttributes aAttr = aReader.attributes();
1654 //printf("### Name = %s\n", qPrintable(aReader.name().toString()));
1655 if (aReader.name() == "Position") {
1656 pos[0] = aAttr.value("X").toString().toDouble();
1657 pos[1] = aAttr.value("Y").toString().toDouble();
1658 pos[2] = aAttr.value("Z").toString().toDouble();
1659 //printf("#### Position %f; %f; %f\n", pos[0], pos[1], pos[2]);
1661 else if (aReader.name() == "FocalPoint") {
1662 focalPnt[0] = aAttr.value("X").toString().toDouble();
1663 focalPnt[1] = aAttr.value("Y").toString().toDouble();
1664 focalPnt[2] = aAttr.value("Z").toString().toDouble();
1665 //printf("#### FocalPoint %f; %f; %f\n", focalPnt[0], focalPnt[1], focalPnt[2]);
1667 else if (aReader.name() == "ViewUp") {
1668 viewUp[0] = aAttr.value("X").toString().toDouble();
1669 viewUp[1] = aAttr.value("Y").toString().toDouble();
1670 viewUp[2] = aAttr.value("Z").toString().toDouble();
1671 //printf("#### ViewUp %f; %f; %f\n", viewUp[0], viewUp[1], viewUp[2]);
1673 else if (aReader.name() == "ViewScale") {
1674 parScale = aAttr.value("Parallel").toString().toDouble();
1675 scale[0] = aAttr.value("X").toString().toDouble();
1676 scale[1] = aAttr.value("Y").toString().toDouble();
1677 scale[2] = aAttr.value("Z").toString().toDouble();
1678 //printf("#### ViewScale %f; %f; %f\n", scale[0], scale[1], scale[2]);
1680 else if (aReader.name() == "DisplayCubeAxis") {
1681 if ( !baseParamsOnly ) {
1682 if (aAttr.value("Show") == "0")
1683 gradAxesActor->VisibilityOff();
1685 gradAxesActor->VisibilityOn();
1688 else if (aReader.name() == "GraduatedAxis") {
1689 if ( !baseParamsOnly ) {
1690 if(aAttr.value("Axis") == "X")
1691 setGradAxisVisualParams(aReader, gradAxesActor->GetXAxisActor2D());
1692 else if(aAttr.value("Axis") == "Y")
1693 setGradAxisVisualParams(aReader, gradAxesActor->GetYAxisActor2D());
1694 else if(aAttr.value("Axis") == "Z")
1695 setGradAxisVisualParams(aReader, gradAxesActor->GetZAxisActor2D());
1698 else if (aReader.name() == "Trihedron") {
1699 if ( !baseParamsOnly ) {
1700 if (aAttr.value("isShown") == "0")
1701 GetTrihedron()->VisibilityOff();
1703 GetTrihedron()->VisibilityOn();
1704 SetTrihedronSize(aAttr.value("Size").toString().toDouble());
1707 else if (aReader.name() == "Background") {
1708 if ( !baseParamsOnly ) {
1709 setBackground( Qtx::stringToBackground( aAttr.value("Value").toString() ) );
1714 if (!aReader.hasError()) {
1715 vtkCamera* camera = getRenderer()->GetActiveCamera();
1716 camera->SetPosition( pos );
1717 camera->SetFocalPoint( focalPnt );
1718 camera->SetViewUp( viewUp );
1719 camera->SetParallelScale( parScale );
1720 GetRenderer()->SetScale( scale );
1721 //SetScale( scale );
1724 QStringList paramsLst = parameters.split( '*' );
1725 if ( paramsLst.size() >= nNormalParams ) {
1726 // 'reading' list of parameters
1727 pos[0] = paramsLst[0].toDouble();
1728 pos[1] = paramsLst[1].toDouble();
1729 pos[2] = paramsLst[2].toDouble();
1730 focalPnt[0] = paramsLst[3].toDouble();
1731 focalPnt[1] = paramsLst[4].toDouble();
1732 focalPnt[2] = paramsLst[5].toDouble();
1733 viewUp[0] = paramsLst[6].toDouble();
1734 viewUp[1] = paramsLst[7].toDouble();
1735 viewUp[2] = paramsLst[8].toDouble();
1736 parScale = paramsLst[9].toDouble();
1737 scale[0] = paramsLst[10].toDouble();
1738 scale[1] = paramsLst[11].toDouble();
1739 scale[2] = paramsLst[12].toDouble();
1741 // applying parameters
1742 vtkCamera* camera = getRenderer()->GetActiveCamera();
1743 camera->SetPosition( pos );
1744 camera->SetFocalPoint( focalPnt );
1745 camera->SetViewUp( viewUp );
1746 camera->SetParallelScale( parScale );
1747 GetRenderer()->SetScale( scale );
1748 //SetScale( scale );
1750 // apply graduated axes parameters
1751 if ( !baseParamsOnly ) {
1752 SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes();
1753 if ( gradAxesActor && paramsLst.size() == nAllParams ) {
1754 int i = nNormalParams+1, j = i + nGradAxisParams - 1;
1755 ::setGradAxisVisualParams( gradAxesActor->GetXAxisActor2D(), parameters.section( '*', i, j ) );
1756 i = j + 1; j += nGradAxisParams;
1757 ::setGradAxisVisualParams( gradAxesActor->GetYAxisActor2D(), parameters.section( '*', i, j ) );
1758 i = j + 1; j += nGradAxisParams;
1759 ::setGradAxisVisualParams( gradAxesActor->GetZAxisActor2D(), parameters.section( '*', i, j ) );
1761 if ( paramsLst[13].toUShort() )
1762 gradAxesActor->VisibilityOn();
1764 gradAxesActor->VisibilityOff();
1766 else if ( paramsLst.size() == nAllParams ) {
1767 if ( paramsLst[90].toUShort() )
1768 GetTrihedron()->VisibilityOn();
1770 GetTrihedron()->VisibilityOff();
1772 SetTrihedronSize(paramsLst[91].toDouble());
1782 Delayed setVisualParameters
1784 bool SVTK_ViewWindow::eventFilter( QObject* theWatched, QEvent* theEvent )
1786 if ( theEvent->type() == QEvent::Show && theWatched->inherits( "SVTK_RenderWindowInteractor" ) ) {
1787 SVTK_RenderWindowInteractor* anInteractor = (SVTK_RenderWindowInteractor*)theWatched;
1788 if ( anInteractor->isVisible() ) {
1789 doSetVisualParameters( myVisualParams );
1790 anInteractor->removeEventFilter( this ); // theWatched = RenderWindowInteractor
1793 return SUIT_ViewWindow::eventFilter( theWatched, theEvent );
1798 Change rotation point
1800 void SVTK_ViewWindow::onChangeRotationPoint(bool theIsActivate)
1803 mySetRotationPointDlg->addObserver();
1804 if ( mySetRotationPointDlg->IsFirstShown() )
1805 activateSetRotationGravity();
1806 mySetRotationPointDlg->show();
1808 mySetRotationPointDlg->hide();
1812 Set the gravity center as a rotation point
1814 void SVTK_ViewWindow::activateSetRotationGravity()
1816 myEventDispatcher->InvokeEvent(SVTK::SetRotateGravity,0);
1820 Set the selected point as a rotation point
1822 void SVTK_ViewWindow::activateSetRotationSelected(void* theData)
1824 myEventDispatcher->InvokeEvent(SVTK::ChangeRotationPoint,theData);
1828 Set the point selected by user as a rotation point
1830 void SVTK_ViewWindow::activateStartPointSelection()
1832 myEventDispatcher->InvokeEvent(SVTK::StartPointSelection,0);
1836 Set the view projection mode: orthogonal or perspective
1838 void SVTK_ViewWindow::onPerspectiveMode()
1840 bool anIsParallelMode = toolMgr()->action( ParallelModeId )->isChecked();
1842 // advanced zooming is not available in perspective mode
1843 if( QtxAction* anAction = getAction( SwitchZoomingStyleId ) )
1844 anAction->setEnabled( anIsParallelMode );
1846 vtkCamera* aCamera = getRenderer()->GetActiveCamera();
1847 aCamera->SetParallelProjection(anIsParallelMode);
1848 GetInteractor()->GetDevice()->CreateTimer(VTKI_TIMER_FIRST);
1850 emit transformed( this );
1853 void SVTK_ViewWindow::SetEventDispatcher(vtkObject* theDispatcher)
1855 myEventDispatcher = theDispatcher;
1859 Creates all actions of svtk main window
1861 void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
1863 QtxAction* anAction;
1864 QtxActionToolMgr* mgr = toolMgr();
1867 anAction = new QtxAction(tr("MNU_DUMP_VIEW"),
1868 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
1869 tr( "MNU_DUMP_VIEW" ), 0, this);
1870 anAction->setStatusTip(tr("DSC_DUMP_VIEW"));
1871 connect(anAction, SIGNAL(activated()), this, SLOT(onDumpView()));
1872 mgr->registerAction( anAction, DumpId );
1875 anAction = new QtxAction(tr("MNU_FITALL"),
1876 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
1877 tr( "MNU_FITALL" ), 0, this);
1878 anAction->setStatusTip(tr("DSC_FITALL"));
1879 connect(anAction, SIGNAL(activated()), this, SLOT(onFitAll()));
1880 mgr->registerAction( anAction, FitAllId );
1883 anAction = new QtxAction(tr("MNU_FITRECT"),
1884 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
1885 tr( "MNU_FITRECT" ), 0, this);
1886 anAction->setStatusTip(tr("DSC_FITRECT"));
1887 connect(anAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
1888 mgr->registerAction( anAction, FitRectId );
1891 anAction = new QtxAction(tr("MNU_ZOOM_VIEW"),
1892 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
1893 tr( "MNU_ZOOM_VIEW" ), 0, this);
1894 anAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
1895 connect(anAction, SIGNAL(activated()), this, SLOT(activateZoom()));
1896 mgr->registerAction( anAction, ZoomId );
1899 anAction = new QtxAction(tr("MNU_PAN_VIEW"),
1900 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
1901 tr( "MNU_PAN_VIEW" ), 0, this);
1902 anAction->setStatusTip(tr("DSC_PAN_VIEW"));
1903 connect(anAction, SIGNAL(activated()), this, SLOT(activatePanning()));
1904 mgr->registerAction( anAction, PanId );
1907 anAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"),
1908 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
1909 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
1910 anAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
1911 connect(anAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
1912 mgr->registerAction( anAction, GlobalPanId );
1914 // Change rotation point
1915 anAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"),
1916 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_ROTATION_POINT" ) ),
1917 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
1918 anAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
1919 anAction->setCheckable(true);
1920 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onChangeRotationPoint(bool)));
1921 mgr->registerAction( anAction, ChangeRotationPointId );
1924 anAction = new QtxAction(tr("MNU_ROTATE_VIEW"),
1925 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
1926 tr( "MNU_ROTATE_VIEW" ), 0, this);
1927 anAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
1928 connect(anAction, SIGNAL(activated()), this, SLOT(activateRotation()));
1929 mgr->registerAction( anAction, RotationId );
1932 anAction = new QtxAction(tr("MNU_FRONT_VIEW"),
1933 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
1934 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
1935 anAction->setStatusTip(tr("DSC_FRONT_VIEW"));
1936 connect(anAction, SIGNAL(activated()), this, SLOT(onFrontView()));
1937 this->addAction(anAction);
1938 mgr->registerAction( anAction, FrontId );
1940 anAction = new QtxAction(tr("MNU_BACK_VIEW"),
1941 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
1942 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
1943 anAction->setStatusTip(tr("DSC_BACK_VIEW"));
1944 connect(anAction, SIGNAL(activated()), this, SLOT(onBackView()));
1945 this->addAction(anAction);
1946 mgr->registerAction( anAction, BackId );
1948 anAction = new QtxAction(tr("MNU_TOP_VIEW"),
1949 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
1950 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
1951 anAction->setStatusTip(tr("DSC_TOP_VIEW"));
1952 connect(anAction, SIGNAL(activated()), this, SLOT(onTopView()));
1953 this->addAction(anAction);
1954 mgr->registerAction( anAction, TopId );
1956 anAction = new QtxAction(tr("MNU_BOTTOM_VIEW"),
1957 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
1958 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
1959 anAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
1960 connect(anAction, SIGNAL(activated()), this, SLOT(onBottomView()));
1961 this->addAction(anAction);
1962 mgr->registerAction( anAction, BottomId );
1964 anAction = new QtxAction(tr("MNU_LEFT_VIEW"),
1965 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
1966 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
1967 anAction->setStatusTip(tr("DSC_LEFT_VIEW"));
1968 connect(anAction, SIGNAL(activated()), this, SLOT(onLeftView()));
1969 this->addAction(anAction);
1970 mgr->registerAction( anAction, LeftId );
1972 anAction = new QtxAction(tr("MNU_RIGHT_VIEW"),
1973 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
1974 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
1975 anAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
1976 connect(anAction, SIGNAL(activated()), this, SLOT(onRightView()));
1977 this->addAction(anAction);
1978 mgr->registerAction( anAction, RightId );
1980 // rotate anticlockwise
1981 anAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"),
1982 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ANTICLOCKWISE" ) ),
1983 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
1984 anAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
1985 connect(anAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
1986 this->addAction(anAction);
1987 mgr->registerAction( anAction, AntiClockWiseId );
1990 anAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"),
1991 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_CLOCKWISE" ) ),
1992 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
1993 anAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
1994 connect(anAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
1995 this->addAction(anAction);
1996 mgr->registerAction( anAction, ClockWiseId );
1999 anAction = new QtxAction(tr("MNU_RESET_VIEW"),
2000 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
2001 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
2002 anAction->setStatusTip(tr("DSC_RESET_VIEW"));
2003 connect(anAction, SIGNAL(activated()), this, SLOT(onResetView()));
2004 this->addAction(anAction);
2005 mgr->registerAction( anAction, ResetId );
2007 // onViewTrihedron: Shows - Hides Trihedron
2008 anAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"),
2009 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ),
2010 tr( "MNU_SHOW_TRIHEDRON" ), 0, this);
2011 anAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON"));
2012 connect(anAction, SIGNAL(activated()), this, SLOT(onViewTrihedron()));
2013 mgr->registerAction( anAction, ViewTrihedronId );
2015 // onNonIsometric: Manage non-isometric params
2016 anAction = new QtxAction(tr("MNU_SVTK_SCALING"),
2017 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SCALING" ) ),
2018 tr( "MNU_SVTK_SCALING" ), 0, this);
2019 anAction->setStatusTip(tr("DSC_SVTK_SCALING"));
2020 anAction->setCheckable(true);
2021 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onNonIsometric(bool)));
2022 mgr->registerAction( anAction, NonIsometric );
2024 // onGraduatedAxes: Manage graduated axes params
2025 anAction = new QtxAction(tr("MNU_SVTK_GRADUATED_AXES"),
2026 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_GRADUATED_AXES" ) ),
2027 tr( "MNU_SVTK_GRADUATED_AXES" ), 0, this);
2028 anAction->setStatusTip(tr("DSC_SVTK_GRADUATED_AXES"));
2029 anAction->setCheckable(true);
2030 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onGraduatedAxes(bool)));
2031 mgr->registerAction( anAction, GraduatedAxes );
2033 // onGraduatedAxes: Manage graduated axes params
2034 anAction = new QtxAction(tr("MNU_SVTK_UPDATE_RATE"),
2035 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_UPDATE_RATE" ) ),
2036 tr( "MNU_SVTK_UPDATE_RATE" ), 0, this);
2037 anAction->setStatusTip(tr("DSC_SVTK_UPDATE_RATE"));
2038 anAction->setCheckable(true);
2039 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onUpdateRate(bool)));
2040 mgr->registerAction( anAction, UpdateRate );
2042 // Set perspective mode group
2043 anAction = new QtxAction(tr("MNU_SVTK_PARALLEL_MODE"),
2044 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARALLEL" ) ),
2045 tr( "MNU_SVTK_PARALLEL_MODE" ), 0, this);
2046 anAction->setStatusTip(tr("DSC_SVTK_PARALLEL_MODE"));
2047 anAction->setCheckable(true);
2048 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onPerspectiveMode()));
2049 mgr->registerAction( anAction, ParallelModeId );
2051 anAction = new QtxAction(tr("MNU_SVTK_PERSPECTIVE_MODE"),
2052 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PERSPECTIVE" ) ),
2053 tr( "MNU_SVTK_PERSPECTIVE_MODE" ), 0, this);
2054 anAction->setStatusTip(tr("DSC_SVTK_PERSPECTIVE_MODE"));
2055 anAction->setCheckable(true);
2056 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onPerspectiveMode()));
2057 mgr->registerAction( anAction, ProjectionModeId );
2059 QActionGroup* aPerspectiveGroup = new QActionGroup( this );
2060 aPerspectiveGroup->addAction( mgr->action( ParallelModeId ) );
2061 aPerspectiveGroup->addAction( mgr->action( ProjectionModeId ) );
2064 anAction = new QtxAction(tr("MNU_VIEWPARAMETERS_VIEW"),
2065 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARAMETERS" ) ),
2066 tr( "MNU_VIEWPARAMETERS_VIEW" ), 0, this);
2067 anAction->setStatusTip(tr("DSC_VIEWPARAMETERS_VIEW"));
2068 anAction->setCheckable(true);
2069 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onViewParameters(bool)));
2070 mgr->registerAction( anAction, ViewParametersId );
2073 mgr->registerAction( synchronizeAction(), SynchronizeId );
2075 // Switch between interaction styles
2076 anAction = new QtxAction(tr("MNU_SVTK_STYLE_SWITCH"),
2077 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_STYLE_SWITCH" ) ),
2078 tr( "MNU_SVTK_STYLE_SWITCH" ), 0, this);
2079 anAction->setStatusTip(tr("DSC_SVTK_STYLE_SWITCH"));
2080 anAction->setCheckable(true);
2081 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
2082 mgr->registerAction( anAction, SwitchInteractionStyleId );
2084 // Switch between zooming styles
2085 anAction = new QtxAction(tr("MNU_SVTK_ZOOMING_STYLE_SWITCH"),
2086 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_ZOOMING_STYLE_SWITCH" ) ),
2087 tr( "MNU_SVTK_ZOOMING_STYLE_SWITCH" ), 0, this);
2088 anAction->setStatusTip(tr("DSC_SVTK_ZOOMING_STYLE_SWITCH"));
2089 anAction->setCheckable(true);
2090 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
2091 mgr->registerAction( anAction, SwitchZoomingStyleId );
2093 // Turn on/off dynamic pre-selection
2094 anAction = new QtxAction(tr("MNU_SVTK_DYNAMIC_PRESLECTION_SWITCH"),
2095 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_DYNAMIC_PRESLECTION_SWITCH" ) ),
2096 tr( "MNU_SVTK_DYNAMIC_PRESLECTION_SWITCH" ), 0, this);
2097 anAction->setStatusTip(tr("DSC_SVTK_DYNAMIC_PRESLECTION_SWITCH"));
2098 anAction->setCheckable(true);
2099 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchDynamicPreSelection(bool)));
2100 mgr->registerAction( anAction, SwitchDynamicPreselectionId );
2103 myStartAction = new QtxAction(tr("MNU_SVTK_RECORDING_START"),
2104 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_START" ) ),
2105 tr( "MNU_SVTK_RECORDING_START" ), 0, this);
2106 myStartAction->setStatusTip(tr("DSC_SVTK_RECORDING_START"));
2107 connect( myStartAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStartRecording() ) );
2108 mgr->registerAction( myStartAction, StartRecordingId );
2111 myPlayAction = new QtxAction(tr("MNU_SVTK_RECORDING_PLAY"),
2112 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PLAY" ) ),
2113 tr( "MNU_SVTK_RECORDING_PLAY" ), 0, this);
2114 myPlayAction->setStatusTip(tr("DSC_SVTK_RECORDING_PLAY"));
2115 myPlayAction->setEnabled( false );
2116 connect( myPlayAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPlayRecording() ) );
2117 mgr->registerAction( myPlayAction, PlayRecordingId );
2120 myPauseAction = new QtxAction(tr("MNU_SVTK_RECORDING_PAUSE"),
2121 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PAUSE" ) ),
2122 tr( "MNU_SVTK_RECORDING_PAUSE" ), 0, this);
2123 myPauseAction->setStatusTip(tr("DSC_SVTK_RECORDING_PAUSE"));
2124 myPauseAction->setEnabled( false );
2125 connect( myPauseAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPauseRecording() ) );
2126 mgr->registerAction( myPauseAction, PauseRecordingId );
2129 myStopAction = new QtxAction(tr("MNU_SVTK_RECORDING_STOP"),
2130 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_STOP" ) ),
2131 tr( "MNU_SVTK_RECORDING_STOP" ), 0, this);
2132 myStopAction->setStatusTip(tr("DSC_SVTK_RECORDING_STOP"));
2133 myStopAction->setEnabled( false );
2134 connect( myStopAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStopRecording() ) );
2135 mgr->registerAction( myStopAction, StopRecordingId );
2139 Creates toolbar of svtk main window
2141 void SVTK_ViewWindow::createToolBar()
2143 QtxActionToolMgr* mgr = toolMgr();
2145 mgr->append( DumpId, myToolBar );
2146 mgr->append( SwitchInteractionStyleId, myToolBar );
2147 mgr->append( SwitchZoomingStyleId, myToolBar );
2148 mgr->append( SwitchDynamicPreselectionId, myToolBar );
2149 mgr->append( ViewTrihedronId, myToolBar );
2151 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
2152 aScaleAction->insertAction( getAction( FitAllId ) );
2153 aScaleAction->insertAction( getAction( FitRectId ) );
2154 aScaleAction->insertAction( getAction( ZoomId ) );
2155 mgr->append( aScaleAction, myToolBar );
2157 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
2158 aPanningAction->insertAction( getAction( PanId ) );
2159 aPanningAction->insertAction( getAction( GlobalPanId ) );
2160 mgr->append( aPanningAction, myToolBar );
2162 mgr->append( ChangeRotationPointId, myToolBar );
2164 mgr->append( RotationId, myToolBar );
2166 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
2167 aViewsAction->insertAction( getAction( FrontId ) );
2168 aViewsAction->insertAction( getAction( BackId ) );
2169 aViewsAction->insertAction( getAction( TopId ) );
2170 aViewsAction->insertAction( getAction( BottomId ) );
2171 aViewsAction->insertAction( getAction( LeftId ) );
2172 aViewsAction->insertAction( getAction( RightId ) );
2173 mgr->append( aViewsAction, myToolBar );
2175 mgr->append( AntiClockWiseId, myToolBar );
2176 mgr->append( ClockWiseId, myToolBar );
2178 mgr->append( ResetId, myToolBar );
2180 mgr->append( UpdateRate, myToolBar );
2181 mgr->append( NonIsometric, myToolBar );
2182 mgr->append( GraduatedAxes, myToolBar );
2184 mgr->append( ViewParametersId, myToolBar );
2185 mgr->append( SynchronizeId, myToolBar );
2187 mgr->append( toolMgr()->separator(), myToolBar );
2189 mgr->append( ParallelModeId, myToolBar );
2190 mgr->append( ProjectionModeId, myToolBar );
2192 mgr->append( StartRecordingId, myRecordingToolBar );
2193 mgr->append( PlayRecordingId, myRecordingToolBar );
2194 mgr->append( PauseRecordingId, myRecordingToolBar );
2195 mgr->append( StopRecordingId, myRecordingToolBar );
2198 void SVTK_ViewWindow::onUpdateRate(bool theIsActivate)
2201 myUpdateRateDlg->Update();
2202 myUpdateRateDlg->show();
2204 myUpdateRateDlg->hide();
2207 void SVTK_ViewWindow::onNonIsometric(bool theIsActivate)
2210 myNonIsometricDlg->Update();
2211 myNonIsometricDlg->show();
2213 myNonIsometricDlg->hide();
2216 void SVTK_ViewWindow::onGraduatedAxes(bool theIsActivate)
2219 myCubeAxesDlg->Update();
2220 myCubeAxesDlg->show();
2222 myCubeAxesDlg->hide();
2226 Starts rotation transformation
2228 void SVTK_ViewWindow::activateRotation()
2230 myEventDispatcher->InvokeEvent(SVTK::StartRotate,0);
2235 Starts panning transformation
2237 void SVTK_ViewWindow::activatePanning()
2239 myEventDispatcher->InvokeEvent(SVTK::StartPan,0);
2243 Starts zoom transformation
2245 void SVTK_ViewWindow::activateZoom()
2247 myEventDispatcher->InvokeEvent(SVTK::StartZoom,0);
2251 Starts window fit transformation
2253 void SVTK_ViewWindow::activateWindowFit()
2255 myEventDispatcher->InvokeEvent(SVTK::StartFitArea,0);
2259 Starts global panning transformation
2261 void SVTK_ViewWindow::activateGlobalPanning()
2263 myEventDispatcher->InvokeEvent(SVTK::StartGlobalPan,0);
2266 void SVTK_ViewWindow::onStartRecording()
2268 myRecorder->CheckExistAVIMaker();
2269 if (myRecorder->ErrorStatus()) {
2270 SUIT_MessageBox::warning(this, tr("ERROR"), tr("MSG_NO_AVI_MAKER") );
2273 SVTK_RecorderDlg* aRecorderDlg = new SVTK_RecorderDlg( this, myRecorder );
2275 if( !aRecorderDlg->exec() )
2278 myStartAction->setEnabled( false );
2279 myPlayAction->setEnabled( false );
2280 myPauseAction->setEnabled( true );
2281 myStopAction->setEnabled( true );
2283 // to prevent resizing the window while recording
2284 myPreRecordingMinSize = minimumSize();
2285 myPreRecordingMaxSize = maximumSize();
2286 setFixedSize( size() );
2288 myRecorder->Record();
2292 void SVTK_ViewWindow::onPlayRecording()
2294 myStartAction->setEnabled( false );
2295 myPlayAction->setEnabled( false );
2296 myPauseAction->setEnabled( true );
2297 myStopAction->setEnabled( true );
2299 myRecorder->Pause();
2302 void SVTK_ViewWindow::onPauseRecording()
2304 myStartAction->setEnabled( false );
2305 myPlayAction->setEnabled( true );
2306 myPauseAction->setEnabled( false );
2307 myStopAction->setEnabled( true );
2309 myRecorder->Pause();
2312 void SVTK_ViewWindow::onStopRecording()
2314 myStartAction->setEnabled( true );
2315 myPlayAction->setEnabled( false );
2316 myPauseAction->setEnabled( false );
2317 myStopAction->setEnabled( false );
2321 setMinimumSize( myPreRecordingMinSize );
2322 setMaximumSize( myPreRecordingMaxSize );
2326 To invoke a VTK event on SVTK_RenderWindowInteractor instance
2328 void SVTK_ViewWindow::InvokeEvent(unsigned long theEvent, void* theCallData)
2330 GetInteractor()->InvokeEvent(theEvent,theCallData);
2334 Modify view parameters
2336 void SVTK_ViewWindow::onViewParameters(bool theIsActivate)
2339 myViewParameterDlg->addObserver();
2340 myViewParameterDlg->show();
2342 myViewParameterDlg->hide();
2346 Custom show event handler
2348 void SVTK_ViewWindow::showEvent( QShowEvent * theEvent )
2350 emit Show( theEvent );
2354 Custom hide event handler
2356 void SVTK_ViewWindow::hideEvent( QHideEvent * theEvent )
2358 emit Hide( theEvent );
2362 Emit transformed signal.
2364 void SVTK_ViewWindow::emitTransformed() {
2371 void SVTK_ViewWindow::ProcessEvents(vtkObject* vtkNotUsed(theObject),
2372 unsigned long theEvent,
2373 void* theClientData,
2376 SVTK_ViewWindow* self = reinterpret_cast<SVTK_ViewWindow*>(theClientData);
2378 self->emitTransformed();
2382 Get camera properties for the SVTK view window.
2383 \return shared pointer on camera properties.
2385 SUIT_CameraProperties SVTK_ViewWindow::cameraProperties()
2387 SUIT_CameraProperties aProps;
2390 vtkCamera* aCamera = getRenderer()->GetActiveCamera();
2394 aProps.setDimension( SUIT_CameraProperties::Dim3D );
2395 if ( toolMgr()->action( ParallelModeId ) ) {
2396 if ( toolMgr()->action( ParallelModeId )->isChecked() )
2397 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
2399 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
2402 double aFocalPoint[3];
2403 double aPosition[3];
2405 double anAxialScale[3];
2407 aCamera->OrthogonalizeViewUp();
2408 aCamera->GetFocalPoint(aFocalPoint);
2409 aCamera->GetPosition(aPosition);
2410 aCamera->GetViewUp(aViewUp);
2412 aProps.setFocalPoint(aFocalPoint[0], aFocalPoint[1], aFocalPoint[2]);
2413 aProps.setPosition(aPosition[0], aPosition[1], aPosition[2]);
2414 aProps.setViewUp(aViewUp[0], aViewUp[1], aViewUp[2]);
2415 aProps.setMappingScale(aCamera->GetParallelScale());
2417 if (aProps.getProjection() == SUIT_CameraProperties::PrjPerspective)
2419 aProps.setViewAngle(aCamera->GetViewAngle());
2422 GetRenderer()->GetScale(anAxialScale);
2423 aProps.setAxialScale(anAxialScale[0], anAxialScale[1], anAxialScale[2]);
2430 This implementation synchronizes camera propreties.
2432 void SVTK_ViewWindow::synchronize( SUIT_ViewWindow* theView )
2434 bool blocked = blockSignals( true );
2436 SUIT_CameraProperties aProps = theView->cameraProperties();
2437 if ( !cameraProperties().isCompatible( aProps ) ) {
2438 // other view, this one is being currently synchronized to, seems has become incompatible
2439 // we have to break synchronization
2445 vtkCamera* aCamera = getRenderer()->GetActiveCamera();
2447 double aFocalPoint[3];
2448 double aPosition[3];
2450 double anAxialScale[3];
2452 // get common properties
2453 aProps.getViewUp(aViewUp[0], aViewUp[1], aViewUp[2]);
2454 aProps.getPosition(aPosition[0], aPosition[1], aPosition[2]);
2455 aProps.getFocalPoint(aFocalPoint[0], aFocalPoint[1], aFocalPoint[2]);
2456 aProps.getAxialScale(anAxialScale[0], anAxialScale[1], anAxialScale[2]);
2458 // restore properties to the camera
2459 aCamera->SetViewUp(aViewUp);
2460 aCamera->SetPosition(aPosition);
2461 aCamera->SetFocalPoint(aFocalPoint);
2462 aCamera->SetParallelScale(aProps.getMappingScale());
2464 if (aProps.getProjection() == SUIT_CameraProperties::PrjPerspective)
2466 aCamera->SetViewAngle(aProps.getViewAngle());
2469 GetRenderer()->SetScale(anAxialScale);
2471 getRenderer()->ResetCameraClippingRange();
2474 blockSignals( blocked );