1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "SVTK_NonIsometricDlg.h"
24 #include "SVTK_UpdateRateDlg.h"
25 #include "SVTK_CubeAxesDlg.h"
26 #include "SVTK_PsOptionsDlg.h"
27 #include "SVTK_SetRotationPointDlg.h"
28 #include "SVTK_ViewParameterDlg.h"
29 #include "SVTK_ViewModel.h"
30 #include "VTKViewer_Texture.h"
31 #include "VTKViewer_OpenGLRenderer.h"
33 #include "SALOME_Actor.h"
39 #include <QSignalMapper>
40 #include <QXmlStreamWriter>
41 #include <QXmlStreamReader>
42 #include <QXmlStreamAttributes>
44 #include <vtkTextProperty.h>
45 #include <vtkActorCollection.h>
46 #include <vtkRenderWindow.h>
47 #include <vtkRenderer.h>
48 #include <vtkCamera.h>
49 #include <vtkPointPicker.h>
50 #include <vtkCellPicker.h>
51 #include <vtkAxisActor2D.h>
52 #include <vtkGL2PSExporter.h>
53 #include <vtkInteractorStyle.h>
54 #include <vtkProperty.h>
55 #include <vtkCallbackCommand.h>
56 #include <vtkJPEGReader.h>
57 #include <vtkBMPReader.h>
58 #include <vtkTIFFReader.h>
59 #include <vtkPNGReader.h>
60 #include <vtkMetaImageReader.h>
61 #include <vtkImageMapToColors.h>
62 #include <vtkTexture.h>
64 #include "QtxAction.h"
66 #include "SUIT_Session.h"
67 #include "SUIT_MessageBox.h"
68 #include "SUIT_Accel.h"
69 #include "SUIT_Tools.h"
70 #include "SUIT_ResourceMgr.h"
71 #include "SUIT_Accel.h"
72 #include "SUIT_OverrideCursor.h"
73 #include "SUIT_ViewManager.h"
74 #include "QtxActionToolMgr.h"
75 #include "QtxMultiAction.h"
76 #include "QtxActionGroup.h"
78 #include "VTKViewer_Utilities.h"
79 #include "VTKViewer_Trihedron.h"
81 #include "SVTK_View.h"
82 #include "SVTK_Selector.h"
84 #include "SVTK_Event.h"
85 #include "SVTK_Renderer.h"
86 #include "SVTK_ViewWindow.h"
87 #include "SVTK_InteractorStyle.h"
88 #include "SVTK_RenderWindowInteractor.h"
89 #include "SVTK_GenericRenderWindowInteractor.h"
90 #include "SVTK_CubeAxesActor2D.h"
91 #include "SVTK_ComboAction.h"
92 #include "SVTK_KeyFreeInteractorStyle.h"
93 #include "SVTK_Selector.h"
94 #include "SVTK_Recorder.h"
95 #include "SVTK_RecorderDlg.h"
97 #include "salomevtkPVAxesWidget.h"
98 #include "salomevtkPVAxesActor.h"
100 #include "SALOME_ListIO.hxx"
102 #include "VTKViewer_Algorithm.h"
103 #include "SVTK_Functor.h"
105 #include <OpenGLUtils_FrameBuffer.h>
111 int convertAction( const int accelAction )
113 switch ( accelAction ) {
114 case SUIT_Accel::PanLeft : return SVTK::PanLeftEvent;
115 case SUIT_Accel::PanRight : return SVTK::PanRightEvent;
116 case SUIT_Accel::PanUp : return SVTK::PanUpEvent;
117 case SUIT_Accel::PanDown : return SVTK::PanDownEvent;
118 case SUIT_Accel::ZoomIn : return SVTK::ZoomInEvent;
119 case SUIT_Accel::ZoomOut : return SVTK::ZoomOutEvent;
120 case SUIT_Accel::RotateLeft : return SVTK::RotateLeftEvent;
121 case SUIT_Accel::RotateRight : return SVTK::RotateRightEvent;
122 case SUIT_Accel::RotateUp : return SVTK::RotateUpEvent;
123 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)
150 myInteractor = new SVTK_RenderWindowInteractor(this,"SVTK_RenderWindowInteractor");
152 SVTK_Selector* aSelector = SVTK_Selector::New();
153 int aPreselectionMode = SUIT_Session::session()->resourceMgr()->
154 integerValue( "VTKViewer", "preselection", Standard_Preselection );
155 aSelector->SetDynamicPreSelection( aPreselectionMode == Dynamic_Preselection );
156 aSelector->SetPreSelectionEnabled( aPreselectionMode != Preselection_Disabled );
157 bool isSelectionEnabled = SUIT_Session::session()->resourceMgr()->
158 booleanValue( "VTKViewer", "enable_selection", true );
159 aSelector->SetSelectionEnabled( isSelectionEnabled );
161 SVTK_GenericRenderWindowInteractor* aDevice = SVTK_GenericRenderWindowInteractor::New();
162 aDevice->SetRenderWidget(myInteractor);
163 aDevice->SetSelector(aSelector);
165 SVTK_Renderer* aRenderer = SVTK_Renderer::New();
166 aRenderer->Initialize(aDevice,aSelector);
168 myInteractor->Initialize(aDevice,aRenderer,aSelector);
174 myToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_LABEL"), // title (language-dependant)
175 QString( "VTKViewerViewOperations" ), // name (language-independant)
176 false ); // disable floatable toolbar
178 myRecordingToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_RECORD_LABEL"), // title (language-dependant)
179 QString( "VTKRecordingOperations" ), // name (language-independant)
180 false ); // disable floatable toolbar
182 createActions( SUIT_Session::session()->resourceMgr() );
185 SetEventDispatcher(myInteractor->GetDevice());
186 myInteractor->setBackgroundRole( QPalette::NoRole );//NoBackground
187 myInteractor->setFocusPolicy(Qt::StrongFocus);
188 myInteractor->setFocus();
189 bool isSupportQuadBuffer = SUIT_Session::session()->resourceMgr()->
190 booleanValue( "VTKViewer", "enable_quad_buffer_support", false );
191 myInteractor->getRenderWindow()->SetStereoCapableWindow((int)isSupportQuadBuffer);
192 setFocusProxy(myInteractor);
194 myUpdateRateDlg = new SVTK_UpdateRateDlg( getAction( UpdateRate ), this, "SVTK_UpdateRateDlg" );
195 myNonIsometricDlg = new SVTK_NonIsometricDlg( getAction( NonIsometric ), this, "SVTK_NonIsometricDlg" );
196 myCubeAxesDlg = new SVTK_CubeAxesDlg( getAction( GraduatedAxes ), this, "SVTK_CubeAxesDlg" );
197 myCubeAxesDlg->initialize();
198 mySetRotationPointDlg = new SVTK_SetRotationPointDlg
199 ( getAction( ChangeRotationPointId ), this, "SVTK_SetRotationPointDlg" );
200 myViewParameterDlg = new SVTK_ViewParameterDlg
201 ( getAction( ViewParametersId ), this, "SVTK_ViewParameterDlg" );
203 myDefaultInteractorStyle = SVTK_InteractorStyle::New();
204 myInteractor->PushInteractorStyle(myDefaultInteractorStyle);
205 myDefaultInteractorStyle->Delete();
207 myRecorder = SVTK_Recorder::New();
209 myRecorder->SetNbFPS( 17.3 );
210 myRecorder->SetQuality( 100 );
211 myRecorder->SetProgressiveMode( true );
212 myRecorder->SetUseSkippedFrames( true );
213 myRecorder->SetRenderWindow( myInteractor->getRenderWindow() );
215 setCentralWidget(myInteractor);
217 myAxesWidget = salomevtk::vtkPVAxesWidget::New();
218 myAxesWidget->SetParentRenderer(aRenderer->GetDevice());
219 myAxesWidget->SetViewport(0, 0, 0.25, 0.25);
220 myAxesWidget->SetInteractor(myInteractor->GetDevice());
221 myAxesWidget->SetEnabled(1);
222 myAxesWidget->SetInteractive(0);
224 salomevtk::vtkPVAxesActor* anAxesActor = myAxesWidget->GetAxesActor();
225 anAxesActor->GetXAxisTipProperty()->SetColor( 1.0, 0.0, 0.0 );
226 anAxesActor->GetXAxisShaftProperty()->SetColor( 1.0, 0.0, 0.0 );
227 anAxesActor->GetXAxisLabelProperty()->SetColor( 1.0, 0.0, 0.0 );
228 anAxesActor->GetYAxisTipProperty()->SetColor( 0.0, 1.0, 0.0 );
229 anAxesActor->GetYAxisShaftProperty()->SetColor( 0.0, 1.0, 0.0 );
230 anAxesActor->GetYAxisLabelProperty()->SetColor( 0.0, 1.0, 0.0 );
231 anAxesActor->GetZAxisTipProperty()->SetColor( 0.0, 0.0, 1.0 );
232 anAxesActor->GetZAxisShaftProperty()->SetColor( 0.0, 0.0, 1.0 );
233 anAxesActor->GetZAxisLabelProperty()->SetColor( 0.0, 0.0, 1.0 );
235 myView = new SVTK_View(this);
236 Initialize(myView,theModel);
239 myEventCallbackCommand->SetClientData(this);
240 myEventCallbackCommand->SetCallback(SVTK_ViewWindow::ProcessEvents);
241 myEventCallbackCommand->Delete();
243 GetInteractor()->GetInteractorStyle()->AddObserver(SVTK::OperationFinished,
244 myEventCallbackCommand.GetPointer(), 0.0);
245 myKeyFreeInteractorStyle->AddObserver(SVTK::OperationFinished,
246 myEventCallbackCommand.GetPointer(), 0.0);
250 myInteractor->getRenderWindow()->Render();
251 setBackground( Qtx::BackgroundData( Qt::black ) ); // set default background
256 To initialize #SVTK_ViewWindow instance
258 void SVTK_ViewWindow::Initialize(SVTK_View* theView,
259 SVTK_ViewModelBase* theModel)
261 connect(theView,SIGNAL(KeyPressed(QKeyEvent*)),
262 this,SLOT(onKeyPressed(QKeyEvent*)) );
263 connect(theView,SIGNAL(KeyReleased(QKeyEvent*)),
264 this,SLOT(onKeyReleased(QKeyEvent*)));
265 connect(theView,SIGNAL(MouseButtonPressed(QMouseEvent*)),
266 this,SLOT(onMousePressed(QMouseEvent*)));
267 connect(theView,SIGNAL(MouseButtonReleased(QMouseEvent*)),
268 this,SLOT(onMouseReleased(QMouseEvent*)));
269 connect(theView,SIGNAL(MouseDoubleClicked(QMouseEvent*)),
270 this,SLOT(onMouseDoubleClicked(QMouseEvent*)));
271 connect(theView,SIGNAL(MouseMove(QMouseEvent*)),
272 this,SLOT(onMouseMoving(QMouseEvent*)));
273 connect(theView,SIGNAL(contextMenuRequested(QContextMenuEvent*)),
274 this,SIGNAL(contextMenuRequested(QContextMenuEvent *)));
275 connect(theView,SIGNAL(selectionChanged()),
276 theModel,SLOT(onSelectionChanged()));
278 connect( this, SIGNAL( transformed( SVTK_ViewWindow* ) ), SLOT( emitViewModified() ) );
284 SVTK_ViewWindow::~SVTK_ViewWindow()
286 myRecorder->Delete();
287 myAxesWidget->Delete();
292 \return corresponding view
294 SVTK_View* SVTK_ViewWindow::getView()
300 \return corresponding vtk render window
302 vtkRenderWindow* SVTK_ViewWindow::getRenderWindow()
304 return GetInteractor()->getRenderWindow();
308 \return corresponding vtk render window interactor
310 SVTK_RenderWindowInteractor* SVTK_ViewWindow::GetInteractor() const
316 \return corresponding vtk render window interactor
318 vtkRenderWindowInteractor* SVTK_ViewWindow::getInteractor() const
320 return myInteractor->GetDevice();
324 \return corresponding vtk renderer
326 vtkRenderer* SVTK_ViewWindow::getRenderer() const
328 return GetInteractor()->getRenderer();
332 Redirect the request to SVTK_RenderWindowInteractor::GetRenderer
334 SVTK_Renderer* SVTK_ViewWindow::GetRenderer() const
336 return GetInteractor()->GetRenderer();
340 \return corresponding vtk selector
342 SVTK_Selector* SVTK_ViewWindow::GetSelector() const
344 return GetInteractor()->GetSelector();
348 Processes transformation "front view"
350 void SVTK_ViewWindow::onFrontView()
352 GetRenderer()->OnFrontView();
354 emit transformed( this );
358 Processes transformation "back view"
360 void SVTK_ViewWindow::onBackView()
362 GetRenderer()->OnBackView();
364 emit transformed( this );
368 Processes transformation "top view"
370 void SVTK_ViewWindow::onTopView()
372 GetRenderer()->OnTopView();
374 emit transformed( this );
378 Processes transformation "bottom view"
380 void SVTK_ViewWindow::onBottomView()
382 GetRenderer()->OnBottomView();
384 emit transformed( this );
388 Processes transformation "left view"
390 void SVTK_ViewWindow::onLeftView()
392 GetRenderer()->OnLeftView();
394 emit transformed( this );
398 Processes transformation "right view"
400 void SVTK_ViewWindow::onRightView()
402 GetRenderer()->OnRightView();
404 emit transformed( this );
408 \brief Rotate view 90 degrees clockwise
410 void SVTK_ViewWindow::onClockWiseView()
412 GetRenderer()->onClockWiseView();
414 emit transformed( this );
418 \brief Rotate view 90 degrees conterclockwise
420 void SVTK_ViewWindow::onAntiClockWiseView()
422 GetRenderer()->onAntiClockWiseView();
424 emit transformed( this );
428 Processes transformation "reset view": sets default orientation of viewport camera
430 void SVTK_ViewWindow::onResetView()
432 GetRenderer()->OnResetView();
434 emit transformed( this );
438 Processes transformation "fit all"
440 void SVTK_ViewWindow::onFitAll()
442 GetRenderer()->OnFitAll();
444 emit transformed( this );
448 Processes transformation "fit selection"
450 void SVTK_ViewWindow::onFitSelection()
452 GetRenderer()->onFitSelection();
454 emit transformed( this );
458 SLOT: called if selection is changed
460 void SVTK_ViewWindow::onSelectionChanged()
462 myView->onSelectionChanged();
466 Change selection mode
467 \param theMode - new selection mode
469 void SVTK_ViewWindow::SetSelectionMode(Selection_Mode theMode)
471 GetSelector()->SetSelectionMode(theMode);
475 \return selection mode
477 Selection_Mode SVTK_ViewWindow::SelectionMode() const
479 return GetSelector()->SelectionMode();
483 Unhilights all objects in viewer
485 void SVTK_ViewWindow::unHighlightAll()
487 myView->unHighlightAll();
491 Hilights/unhilights object in viewer
492 \param theIO - object to be updated
493 \param theIsHighlight - if it is true, object will be hilighted, otherwise it will be unhilighted
494 \param theIsUpdate - update current viewer
496 void SVTK_ViewWindow::highlight(const Handle(SALOME_InteractiveObject)& theIO,
500 myView->highlight( theIO, theIsHighlight, theIsUpdate );
504 \return true if object is in viewer or in collector
505 \param theIO - object to be checked
507 bool SVTK_ViewWindow::isInViewer( const Handle(SALOME_InteractiveObject)& theIO )
509 return myView->isInViewer( theIO );
513 \return true if object is displayed in viewer
514 \param theIO - object to be checked
516 bool SVTK_ViewWindow::isVisible( const Handle(SALOME_InteractiveObject)& theIO )
518 return myView->isVisible( theIO );
523 \param theEntry - entry that corresponds to intractive objects
525 Handle(SALOME_InteractiveObject) SVTK_ViewWindow::FindIObject(const char* theEntry)
527 return myView->FindIObject(theEntry);
532 \param theIO - object
533 \param theImmediatly - update viewer
535 void SVTK_ViewWindow::Display(const Handle(SALOME_InteractiveObject)& theIO,
538 myView->Display(theIO,theImmediatly);
543 \param theIO - object
544 \param theImmediatly - update viewer
546 void SVTK_ViewWindow::Erase(const Handle(SALOME_InteractiveObject)& theIO,
549 myView->Erase(theIO,theImmediatly);
553 Display only passed object
554 \param theIO - object
556 void SVTK_ViewWindow::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIO)
558 myView->DisplayOnly(theIO);
562 Display all objects in view
564 void SVTK_ViewWindow::DisplayAll()
566 myView->DisplayAll();
570 Erase all objects in view
572 void SVTK_ViewWindow::EraseAll()
578 Sets background color [obsolete]
579 \param color - new background color
581 void SVTK_ViewWindow::setBackgroundColor( const QColor& c )
583 Qtx::BackgroundData bg = background();
589 \return background color of viewer [obsolete]
591 QColor SVTK_ViewWindow::backgroundColor() const
593 return background().color();
598 \param bgData - new background data
600 void SVTK_ViewWindow::setBackground( const Qtx::BackgroundData& bgData )
604 if ( bgData.isValid() ) {
605 switch ( bgData.mode() ) {
606 case Qtx::ColorBackground:
608 QColor c = bgData.color();
610 // show solid-colored background
611 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
612 getRenderer()->SetGradientBackground( false ); // cancel gradient mode
613 getRenderer()->SetBackground( c.red()/255.0,
615 c.blue()/255.0 ); // set background color
620 case Qtx::SimpleGradientBackground:
623 int type = bgData.gradient( c1, c2 );
629 // show two-color gradient background
630 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
631 getRenderer()->SetGradientBackground( true ); // switch to gradient mode
633 VTKViewer_OpenGLRenderer* aRenderer =
634 VTKViewer_OpenGLRenderer::SafeDownCast( getRenderer() );
637 aRenderer->SetGradientType( type );
638 aRenderer->SetBackground( c1.redF(), c1.greenF(), c1.blueF() );
639 aRenderer->SetBackground2( c2.redF(), c2.greenF(), c2.blueF() );
645 case Qtx::CustomGradientBackground:
647 // NOT IMPLEMENTED YET
648 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
649 getRenderer()->SetGradientBackground( false ); // cancel gradient mode
656 if ( bgData.isTextureShown() ) {
658 int textureMode = bgData.texture( fileName );
659 QFileInfo fi( fileName );
660 if ( !fileName.isEmpty() && fi.exists() ) {
661 // read texture from file
662 QString extension = fi.suffix().toLower();
663 vtkImageReader2* aReader = 0;
664 if ( extension == "jpg" || extension == "jpeg" )
665 aReader = vtkJPEGReader::New();
666 else if ( extension == "bmp" )
667 aReader = vtkBMPReader::New();
668 else if ( extension == "tif" || extension == "tiff" )
669 aReader = vtkTIFFReader::New();
670 else if ( extension == "png" )
671 aReader = vtkPNGReader::New();
672 else if ( extension == "mhd" || extension == "mha" )
673 aReader = vtkMetaImageReader::New();
676 aReader->SetFileName( fi.absoluteFilePath().toLatin1().constData() );
678 VTKViewer_Texture* aTexture = VTKViewer_Texture::New();
679 vtkImageMapToColors* aMap = 0;
680 vtkAlgorithmOutput* anOutput;
682 // special processing for BMP reader
683 vtkBMPReader* aBMPReader = (vtkBMPReader*)aReader;
685 // Special processing for BMP file
686 aBMPReader->SetAllow8BitBMP(1);
688 aMap = vtkImageMapToColors::New();
689 aMap->SetInputConnection( aBMPReader->GetOutputPort() );
690 aMap->SetLookupTable( (vtkScalarsToColors*)aBMPReader->GetLookupTable() );
691 aMap->SetOutputFormatToRGB();
693 anOutput = aMap->GetOutputPort();
698 anOutput = aReader->GetOutputPort( 0 );
699 aTexture->SetInputConnection( anOutput );
701 // VSR: Currently, VTK only supports Stretch mode, so below code will give
702 // the same results for all modes
703 switch ( textureMode ) {
704 case Qtx::TileTexture:
705 aTexture->SetPosition((int)VTKViewer_Texture::Tiled);
707 case Qtx::StretchTexture:
708 aTexture->SetPosition((int)VTKViewer_Texture::Stretched);
710 case Qtx::CenterTexture:
711 aTexture->SetPosition((int)VTKViewer_Texture::Centered);
715 // show textured background
716 getRenderer()->SetTexturedBackground( true );
717 getRenderer()->SetBackgroundTexture( aTexture );
719 // clean-up resources
730 myBackground = bgData;
734 \return background data of viewer
736 Qtx::BackgroundData SVTK_ViewWindow::background() const
743 Redirect the request to SVTK_RenderWindowInteractor::GetInteractorStyle
745 vtkInteractorStyle* SVTK_ViewWindow::GetInteractorStyle() const
747 return GetInteractor()->GetInteractorStyle();
751 Redirect the request to SVTK_RenderWindowInteractor::PushInteractorStyle
753 void SVTK_ViewWindow::PushInteractorStyle(vtkInteractorStyle* theStyle)
755 GetInteractor()->PushInteractorStyle(theStyle);
759 Redirect the request to SVTK_RenderWindowInteractor::PopInteractorStyle
761 void SVTK_ViewWindow::PopInteractorStyle()
763 GetInteractor()->PopInteractorStyle();
767 Updates current viewer
769 void SVTK_ViewWindow::Repaint(bool theUpdateTrihedron)
771 if(theUpdateTrihedron)
772 GetRenderer()->OnAdjustTrihedron();
774 GetInteractor()->update();
776 SVTK_InteractorStyle* aStyle = (SVTK_InteractorStyle*)getInteractor()->GetInteractorStyle();
782 Redirect the request to #SVTK_Renderer::GetScale
784 void SVTK_ViewWindow::GetScale( double theScale[3] )
786 GetRenderer()->GetScale( theScale );
790 Redirect the request to #SVTK_Renderer::SetScale
792 void SVTK_ViewWindow::SetScale( double theScale[3] )
794 GetRenderer()->SetScale( theScale );
796 emit transformed( this );
800 Redirect the request to #SVTK_Renderer::IsTrihedronDisplayed
802 bool SVTK_ViewWindow::isTrihedronDisplayed()
804 return GetRenderer()->IsTrihedronDisplayed();
808 Redirect the request to #SVTK_Renderer::IsCubeAxesDisplayed
810 bool SVTK_ViewWindow::isCubeAxesDisplayed()
812 return GetRenderer()->IsCubeAxesDisplayed();
816 Redirect the request to #SVTK_Renderer::OnViewTrihedron
818 void SVTK_ViewWindow::onViewTrihedron(bool show)
820 GetRenderer()->SetTrihedronVisibility(show);
825 Redirect the request to #SVTK_Renderer::OnViewCubeAxes
827 void SVTK_ViewWindow::onViewCubeAxes()
829 GetRenderer()->OnViewCubeAxes();
834 Redirect the request to #SVTK_Renderer::GetTrihedron
836 VTKViewer_Trihedron* SVTK_ViewWindow::GetTrihedron()
838 return GetRenderer()->GetTrihedron();
842 Redirect the request to #SVTK_Renderer::GetCubeAxes
844 SVTK_CubeAxesActor2D* SVTK_ViewWindow::GetCubeAxes()
846 return GetRenderer()->GetCubeAxes();
850 \return trihedron size
852 double SVTK_ViewWindow::GetTrihedronSize() const
854 return GetRenderer()->GetTrihedronSize();
859 \param theMode - projection mode ( 0 - orthogonal, 1 - perspective, 2 - stereo )
861 void SVTK_ViewWindow::SetProjectionMode(const int theMode)
863 QtxAction* aParallelAction = dynamic_cast<QtxAction*>( toolMgr()->action( ParallelModeId ) );
864 QtxAction* aProjectionAction = dynamic_cast<QtxAction*>( toolMgr()->action( ProjectionModeId ) );
865 QtxAction* aStereoAction = dynamic_cast<QtxAction*>( toolMgr()->action( StereoModeId ) );
869 onProjectionMode( aParallelAction );
872 onProjectionMode( aProjectionAction );
875 onStereoMode( true );
879 // update action state if method is called outside
880 SVTK_Viewer* aViewer = dynamic_cast<SVTK_Viewer*>(myModel);
881 QtxAction* aSwitchZoomingStyle = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
882 if ( theMode == Parallel && !aParallelAction->isChecked() ) {
883 aParallelAction->setChecked( true );
884 aSwitchZoomingStyle->setEnabled(true);
885 aStereoAction->setChecked( false );
887 if ( theMode == Projection && !aProjectionAction->isChecked() ) {
888 aProjectionAction->setChecked( true );
889 aSwitchZoomingStyle->setEnabled(false);
891 if ( theMode == Stereo ) {
892 aStereoAction->setChecked( true );
893 if ( aParallelAction->isEnabled() ) {
894 aParallelAction->setEnabled( false );
895 aParallelAction->setChecked( false );
896 aStereoAction->setChecked( false );
899 aParallelAction->setEnabled( true );
900 aStereoAction->setChecked( false );
901 aParallelAction->setChecked( aViewer->projectionMode() == Parallel );
903 if ( aProjectionAction->isEnabled() ) {
904 aProjectionAction->setEnabled( false );
905 aProjectionAction->setChecked( true );
906 if ( getRenderWindow()->GetStereoCapableWindow() == 1 && !isOpenGlStereoSupport() &&
907 strcmp( "CrystalEyes", getRenderWindow()->GetStereoTypeAsString() ) == 0 &&
908 toolMgr()->action( StereoModeId )->isChecked() ) {
909 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
913 aProjectionAction->setEnabled( true );
914 aStereoAction->setChecked( false );
915 aProjectionAction->setChecked( aViewer->projectionMode() == Projection );
920 if ( !aParallelAction->isEnabled() )
921 aParallelAction->setEnabled( true );
922 if ( !aProjectionAction->isEnabled() )
923 aProjectionAction->setEnabled( true );
929 \param theType - stereo type
931 void SVTK_ViewWindow::SetStereoType(const int theType)
933 vtkRenderWindow* aWindow = getRenderWindow();
936 aWindow->SetStereoTypeToCrystalEyes();
939 aWindow->SetStereoTypeToRedBlue();
942 aWindow->SetStereoTypeToInterlaced();
945 aWindow->SetStereoTypeToLeft();
948 aWindow->SetStereoTypeToRight();
951 aWindow->SetStereoTypeToDresden();
954 aWindow->SetStereoTypeToAnaglyph();
957 aWindow->SetStereoTypeToCheckerboard();
959 case SplitViewPortHorizontal:
960 aWindow->SetStereoTypeToSplitViewportHorizontal();
967 \param theFilter - anaglyph filter
969 void SVTK_ViewWindow::SetAnaglyphFilter(const int theFilter)
971 vtkRenderWindow* aWindow = getRenderWindow();
972 switch (theFilter ) {
974 aWindow->SetAnaglyphColorMask(4,3);
977 aWindow->SetAnaglyphColorMask(6,1);
980 aWindow->SetAnaglyphColorMask(2,5);
986 Set support quad-buffered stereo
987 \param theEnable - enable/disable support quad-buffered stereo
989 void SVTK_ViewWindow::SetQuadBufferSupport(const bool theEnable)
991 vtkRenderWindow* aWindow = getRenderWindow();
992 aWindow->SetStereoCapableWindow((int)theEnable);
996 \return OpenGl stereo support
998 bool SVTK_ViewWindow::isOpenGlStereoSupport() const
1000 GLboolean support[1];
1001 glGetBooleanv (GL_STEREO, support);
1008 Set the gravity center as a focal point
1010 void SVTK_ViewWindow::activateSetFocalPointGravity()
1012 myEventDispatcher->InvokeEvent(SVTK::SetFocalPointGravity, 0);
1016 Set the selected point as a focal point
1018 void SVTK_ViewWindow::activateSetFocalPointSelected()
1020 myEventDispatcher->InvokeEvent(SVTK::SetFocalPointSelected, 0);
1024 Set the point selected by user as a focal point
1026 void SVTK_ViewWindow::activateStartFocalPointSelection()
1028 myEventDispatcher->InvokeEvent(SVTK::StartFocalPointSelection,0);
1031 void SVTK_ViewWindow::activateProjectionMode(int theMode)
1033 QtxAction* aParallelAction = dynamic_cast<QtxAction*>( toolMgr()->action( ParallelModeId ) );
1034 QtxAction* aProjectionAction = dynamic_cast<QtxAction*>( toolMgr()->action( ProjectionModeId ) );
1036 aParallelAction->setChecked( true );
1038 aProjectionAction->setChecked( true );
1040 if ( !aParallelAction->isEnabled() )
1041 aParallelAction->setEnabled( true );
1042 if ( !aProjectionAction->isEnabled() )
1043 aProjectionAction->setEnabled( true );
1047 Sets actual interaction style
1048 \param theStyle - type of interaction style ( 0 - standard, 1 - keyboard free )
1050 void SVTK_ViewWindow::SetInteractionStyle(const int theStyle)
1052 onSwitchInteractionStyle( theStyle==1 );
1056 Sets actual zooming style
1057 \param theStyle - type of zooming style ( 0 - standard, 1 - advanced (at cursor) )
1059 void SVTK_ViewWindow::SetZoomingStyle(const int theStyle)
1061 onSwitchZoomingStyle( theStyle==1 );
1065 Set preselection mode.
1066 \param theMode the mode to set (standard, dynamic or disabled)
1068 void SVTK_ViewWindow::SetPreSelectionMode( Preselection_Mode theMode )
1070 onSwitchPreSelectionMode( theMode );
1074 Enables/disables selection.
1075 \param theEnable if true - selection will be enabled
1077 void SVTK_ViewWindow::SetSelectionEnabled( bool theEnable )
1079 GetSelector()->SetSelectionEnabled( theEnable );
1080 QtxAction* a = getAction( EnableSelectionId );
1081 if ( a->isChecked() != theEnable)
1082 a->setChecked( theEnable );
1083 QtxActionGroup* aPreselectionGroup =
1084 dynamic_cast<QtxActionGroup*>( getAction( PreselectionId ) );
1085 if ( aPreselectionGroup )
1086 aPreselectionGroup->setEnabled( theEnable );
1090 Switches "keyboard free" interaction style on/off
1092 void SVTK_ViewWindow::onSwitchInteractionStyle(bool theOn)
1095 // check if style is already set
1096 if ( GetInteractorStyle() != myKeyFreeInteractorStyle.GetPointer() )
1098 // keep the same style extensions
1099 SVTK_InteractorStyle* aStyle = (SVTK_InteractorStyle*)GetInteractorStyle();
1101 myKeyFreeInteractorStyle->SetControllerIncrement(aStyle->ControllerIncrement());
1102 myKeyFreeInteractorStyle->SetControllerOnKeyDown(aStyle->ControllerOnKeyDown());
1105 PushInteractorStyle(myKeyFreeInteractorStyle.GetPointer());
1109 // pop only key free style
1110 if ( GetInteractorStyle() == myKeyFreeInteractorStyle.GetPointer() )
1111 PopInteractorStyle();
1114 // update action state if method is called outside
1115 QtxAction* a = getAction( SwitchInteractionStyleId );
1116 if ( a->isChecked() != theOn ) a->setChecked( theOn );
1120 Toogles advanced zooming style (relatively to the cursor position) on/off
1122 void SVTK_ViewWindow::onSwitchZoomingStyle( bool theOn )
1124 if( myDefaultInteractorStyle.GetPointer() )
1125 myDefaultInteractorStyle->SetAdvancedZoomingEnabled( theOn );
1126 if( myKeyFreeInteractorStyle.GetPointer() )
1127 myKeyFreeInteractorStyle->SetAdvancedZoomingEnabled( theOn );
1129 // update action state if method is called outside
1130 QtxAction* a = getAction( SwitchZoomingStyleId );
1131 if ( a->isChecked() != theOn )
1132 a->setChecked( theOn );
1136 Switch preselection mode.
1137 \param theMode the preselection mode
1139 void SVTK_ViewWindow::onSwitchPreSelectionMode( int theMode )
1141 GetSelector()->SetDynamicPreSelection( theMode == Dynamic_Preselection );
1142 GetSelector()->SetPreSelectionEnabled( theMode != Preselection_Disabled );
1144 // update action state if method is called outside
1145 QtxAction* a = getAction( StandardPreselectionId + theMode );
1146 if ( a && !a->isChecked() )
1147 a->setChecked( true );
1151 Enables/disables selection.
1152 \param theOn if true - selection will be enabled
1154 void SVTK_ViewWindow::onEnableSelection( bool on )
1156 SVTK_Viewer* aViewer = dynamic_cast<SVTK_Viewer*>(myModel);
1158 aViewer->enableSelection(on);
1162 Sets incremental speed
1163 \param theValue - new incremental speed
1164 \param theMode - modification mode
1166 void SVTK_ViewWindow::SetIncrementalSpeed(const int theValue, const int theMode)
1168 if ( (SVTK_InteractorStyle*)GetInteractorStyle() )
1169 ((SVTK_InteractorStyle*)GetInteractorStyle())->SetIncrementSpeed(theValue, theMode);
1173 Sets spacemouse buttons for the functions
1174 \param theBtn1 - spacemouse button for the "decrease speed increment"
1175 \param theBtn2 - spacemouse button for the "increase speed increment"
1176 \param theBtn3 - spacemouse button for the "dominant combined switch"
1178 void SVTK_ViewWindow::SetSpacemouseButtons(const int theBtn1,
1183 myEventDispatcher->InvokeEvent(SVTK::SetSMDecreaseSpeedEvent, &val);
1185 myEventDispatcher->InvokeEvent(SVTK::SetSMIncreaseSpeedEvent, &val);
1187 myEventDispatcher->InvokeEvent(SVTK::SetSMDominantCombinedSwitchEvent, &val);
1192 \param theSize - new trihedron size
1193 \param theRelative - trihedron relativeness
1195 void SVTK_ViewWindow::SetTrihedronSize(const double theSize, const bool theRelative)
1197 GetRenderer()->SetTrihedronSize(theSize, theRelative);
1201 /*! If parameter theIsForcedUpdate is true, recalculate parameters for
1202 * trihedron and cube axes, even if trihedron and cube axes is invisible.
1204 void SVTK_ViewWindow::AdjustTrihedrons(const bool theIsForcedUpdate)
1206 GetRenderer()->AdjustActors();
1211 Redirect the request to #SVTK_Renderer::OnAdjustTrihedron
1213 void SVTK_ViewWindow::onAdjustTrihedron()
1215 GetRenderer()->OnAdjustTrihedron();
1219 Redirect the request to #SVTK_Renderer::OnAdjustCubeAxes
1221 void SVTK_ViewWindow::onAdjustCubeAxes()
1223 GetRenderer()->OnAdjustCubeAxes();
1226 void SVTK_ViewWindow::synchronize(SVTK_ViewWindow* otherViewWindow )
1228 if ( otherViewWindow ) {
1229 bool blocked = blockSignals( true );
1230 doSetVisualParameters( otherViewWindow->getVisualParameters(), true );
1231 blockSignals( blocked );
1238 void SVTK_ViewWindow::onKeyPressed(QKeyEvent* event)
1240 emit keyPressed( this, event );
1246 void SVTK_ViewWindow::onKeyReleased(QKeyEvent* event)
1248 emit keyReleased( this, event );
1254 void SVTK_ViewWindow::onMousePressed(QMouseEvent* event)
1256 emit mousePressed(this, event);
1260 Emits mouse released
1262 void SVTK_ViewWindow::onMouseReleased(QMouseEvent* event)
1264 emit mouseReleased( this, event );
1270 void SVTK_ViewWindow::onMouseMoving(QMouseEvent* event)
1272 emit mouseMoving( this, event );
1276 Emits mouse double clicked
1278 void SVTK_ViewWindow::onMouseDoubleClicked( QMouseEvent* event )
1280 emit mouseDoubleClicked( this, event );
1284 Redirect the request to #SVTK_Renderer::AddActor
1286 void SVTK_ViewWindow::AddActor( VTKViewer_Actor* theActor,
1288 bool theIsAdjustActors )
1290 GetRenderer()->AddActor(theActor, theIsAdjustActors);
1293 emit actorAdded(theActor);
1297 Redirect the request to #SVTK_Renderer::RemoveActor
1299 void SVTK_ViewWindow::RemoveActor( VTKViewer_Actor* theActor,
1301 bool theIsAdjustActors )
1303 GetRenderer()->RemoveActor(theActor, theIsAdjustActors);
1304 if ( myDefaultInteractorStyle )
1305 myDefaultInteractorStyle->FreeActors();
1306 if ( myKeyFreeInteractorStyle )
1307 myKeyFreeInteractorStyle->FreeActors();
1310 emit actorRemoved(theActor);
1313 QImage SVTK_ViewWindow::dumpViewContent()
1315 vtkRenderWindow* aWindow = getRenderWindow();
1316 int* aSize = aWindow->GetSize();
1317 int aWidth = aSize[0];
1318 int aHeight = aSize[1];
1320 #ifndef DISABLE_GLVIEWER
1321 OpenGLUtils_FrameBuffer aFrameBuffer;
1322 if( aFrameBuffer.init( aWidth, aHeight ) )
1324 glPushAttrib( GL_VIEWPORT_BIT );
1325 glViewport( 0, 0, aWidth, aHeight );
1326 aFrameBuffer.bind();
1331 aFrameBuffer.unbind();
1334 QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
1336 aFrameBuffer.bind();
1337 glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
1338 aFrameBuffer.unbind();
1340 anImage = anImage.rgbSwapped();
1341 anImage = anImage.mirrored();
1346 // if frame buffers are unsupported, use old functionality
1347 unsigned char *aData =
1348 aWindow->GetRGBACharPixelData( 0, 0, aWidth-1, aHeight-1, 0 );
1350 QImage anImage( aData, aWidth, aHeight, QImage::Format_ARGB32 );
1352 anImage = anImage.rgbSwapped();
1353 anImage = anImage.mirrored();
1358 \return QImage, containing all scene rendering in window
1360 QImage SVTK_ViewWindow::dumpView()
1362 if( myDumpImage.isNull() )
1363 return dumpViewContent();
1369 QString SVTK_ViewWindow::filter() const
1371 return tr( "SVTK_IMAGE_FILES" );
1374 bool SVTK_ViewWindow::dumpViewToFormat( const QImage& img, const QString& fileName, const QString& format )
1376 if ( format != "PS" && format != "EPS" && format != "PDF" )
1377 return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
1379 SVTK_PsOptionsDlg* optionsDlg = new SVTK_PsOptionsDlg(this);
1380 if ( optionsDlg->exec() == QDialog::Accepted ) {
1381 SUIT_OverrideCursor wc;
1383 vtkGL2PSExporter *anExporter = vtkGL2PSExporter::New();
1384 anExporter->SetRenderWindow(getRenderWindow());
1387 anExporter->SetLineWidthFactor(optionsDlg->getLineFactor());
1388 anExporter->SetPointSizeFactor(optionsDlg->getPointFactor());
1389 anExporter->SetSort((vtkGL2PSExporter::SortScheme)optionsDlg->getSortType());
1390 anExporter->SetWrite3DPropsAsRasterImage((int)optionsDlg->isRasterize3D());
1391 anExporter->SetPS3Shading((int)optionsDlg->isPs3Shading());
1393 if ( format == "PS" ) {
1394 anExporter->SetFileFormatToPS();
1395 anExporter->CompressOff();
1398 if ( format == "EPS" ) {
1399 anExporter->SetFileFormatToEPS();
1400 anExporter->CompressOff();
1403 if ( format == "PDF" ) {
1404 anExporter->SetFileFormatToPDF();
1407 QString aFilePrefix(fileName);
1408 QString anExtension(SUIT_Tools::extension(fileName));
1409 aFilePrefix.truncate(aFilePrefix.length() - 1 - anExtension.length());
1410 anExporter->SetFilePrefix(aFilePrefix.toLatin1().data());
1411 anExporter->Write();
1412 anExporter->Delete();
1419 \refresh QImage, containing all scene rendering in window
1421 void SVTK_ViewWindow::RefreshDumpImage()
1423 myDumpImage = dumpViewContent();
1427 Redirect the request to #SVTK_Renderer::SetSelectionProp
1429 void SVTK_ViewWindow::SetSelectionProp(const double& theRed,
1430 const double& theGreen,
1431 const double& theBlue,
1432 const int& theWidth)
1434 myView->SetSelectionProp(theRed,theGreen,theBlue,theWidth);
1438 Redirect the request to #SVTK_Renderer::SetSelectionProp
1440 void SVTK_ViewWindow::SetPreselectionProp(const double& theRed,
1441 const double& theGreen,
1442 const double& theBlue,
1443 const int& theWidth)
1445 myView->SetPreselectionProp(theRed,theGreen,theBlue,theWidth);
1449 Redirect the request to #SVTK_Renderer::SetSelectionTolerance
1451 void SVTK_ViewWindow::SetSelectionTolerance(const double& theTolNodes,
1452 const double& theTolItems,
1453 const double& theTolObjects)
1455 myView->SetSelectionTolerance(theTolNodes, theTolItems, theTolObjects);
1459 Get visibility status of the static trihedron
1461 bool SVTK_ViewWindow::IsStaticTrihedronVisible() const
1463 return (bool)myAxesWidget->GetEnabled();
1467 Set visibility status of the static trihedron
1469 void SVTK_ViewWindow::SetStaticTrihedronVisible( const bool theIsVisible )
1471 myAxesWidget->SetEnabled( (int)theIsVisible );
1476 \param accelAction - action
1478 bool SVTK_ViewWindow::action( const int accelAction )
1480 if ( accelAction == SUIT_Accel::ZoomFit )
1483 int anEvent = SVTK::convertAction( accelAction );
1484 GetInteractor()->InvokeEvent(anEvent, 0);
1490 \return action by it's id
1492 QtxAction* SVTK_ViewWindow::getAction( int id ) const
1494 return dynamic_cast<QtxAction*>( toolMgr()->action( id ) );
1498 // old visual parameters had 13 values. New format added additional
1499 // 76 values for graduated axes, so both numbers are processed.
1500 const int nNormalParams = 13; // number of view windows parameters excluding graduated axes params
1501 const int nGradAxisParams = 25; // number of parameters of ONE graduated axis (X, Y, or Z)
1502 const int nTrihedronParams = 3; // number of parameters for Trihedron
1503 const int nAllParams = nNormalParams + 3*nGradAxisParams + nTrihedronParams + 1; // number of all visual parameters
1505 /*! The method returns visual parameters of a graduated axis actor (x,y,z axis of graduated axes)
1507 void getGradAxisVisualParams( QXmlStreamWriter& writer, vtkAxisActor2D* actor, QString theAxis )
1514 bool isVisible = actor->GetTitleVisibility();
1515 QString title ( actor->GetTitle() );
1517 int font = VTK_ARIAL;
1522 vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1525 txtProp->GetColor( color );
1526 font = txtProp->GetFontFamily();
1527 bold = txtProp->GetBold();
1528 italic = txtProp->GetItalic();
1529 shadow = txtProp->GetShadow();
1531 writer.writeStartElement("GraduatedAxis");
1532 writer.writeAttribute("Axis", theAxis);
1534 writer.writeStartElement("Title");
1535 writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1536 writer.writeAttribute("Text", title);
1537 writer.writeAttribute("Font", QString("%1").arg(font));
1538 writer.writeAttribute("Bold", QString("%1").arg(bold));
1539 writer.writeAttribute("Italic", QString("%1").arg(italic));
1540 writer.writeAttribute("Shadow", QString("%1").arg(shadow));
1542 writer.writeStartElement("Color");
1543 writer.writeAttribute("R", QString("%1").arg(color[0]));
1544 writer.writeAttribute("G", QString("%1").arg(color[1]));
1545 writer.writeAttribute("B", QString("%1").arg(color[2]));
1546 writer.writeEndElement();
1547 writer.writeEndElement();
1549 //params.sprintf( "* Graduated Axis: * Name *%u*%s*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible,
1550 // title.toLatin1().data(), color[0], color[1], color[2], font, bold, italic, shadow );
1553 isVisible = actor->GetLabelVisibility();
1554 int labels = actor->GetNumberOfLabels();
1555 int offset = actor->GetTickOffset();
1561 txtProp = actor->GetLabelTextProperty();
1564 txtProp->GetColor( color );
1565 font = txtProp->GetFontFamily();
1566 bold = txtProp->GetBold();
1567 italic = txtProp->GetItalic();
1568 shadow = txtProp->GetShadow();
1571 writer.writeStartElement("Labels");
1572 writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1573 writer.writeAttribute("Number", QString("%1").arg(labels));
1574 writer.writeAttribute("Offset", QString("%1").arg(offset));
1575 writer.writeAttribute("Font", QString("%1").arg(font));
1576 writer.writeAttribute("Bold", QString("%1").arg(bold));
1577 writer.writeAttribute("Italic", QString("%1").arg(italic));
1578 writer.writeAttribute("Shadow", QString("%1").arg(shadow));
1580 writer.writeStartElement("Color");
1581 writer.writeAttribute("R", QString("%1").arg(color[0]));
1582 writer.writeAttribute("G", QString("%1").arg(color[1]));
1583 writer.writeAttribute("B", QString("%1").arg(color[2]));
1584 writer.writeEndElement();
1585 writer.writeEndElement();
1586 // params += QString().sprintf( "* Labels *%u*%u*%u*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible, labels, offset,
1587 // color[0], color[1], color[2], font, bold, italic, shadow );
1590 isVisible = actor->GetTickVisibility();
1591 int length = actor->GetTickLength();
1592 writer.writeStartElement("TickMarks");
1593 writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
1594 writer.writeAttribute("Length", QString("%1").arg(length));
1595 writer.writeEndElement();
1597 //params += QString().sprintf( "* Tick marks *%u*%u", isVisible, length );
1599 writer.writeEndElement();
1603 void setGradAxisVisualParams(QXmlStreamReader& reader, vtkAxisActor2D* actor)
1610 } while (!reader.isStartElement());
1612 // Read title params
1613 QXmlStreamAttributes aAttr = reader.attributes();
1614 bool isVisible = aAttr.value("isVisible").toString().toUShort();
1615 QString title = aAttr.value("Text").toString();
1616 int font = aAttr.value("Font").toString().toInt();
1617 int bold = aAttr.value("Bold").toString().toInt();
1618 int italic = aAttr.value("Italic").toString().toInt();
1619 int shadow = aAttr.value("Shadow").toString().toInt();
1621 //printf("#### TITLE: %i, %s, %i, %i, %i, %i\n", isVisible, qPrintable(title), font, bold, italic, shadow);
1625 } while (!reader.isStartElement());
1628 aAttr = reader.attributes();
1631 color[0] = aAttr.value("R").toString().toDouble();
1632 color[1] = aAttr.value("G").toString().toDouble();
1633 color[2] = aAttr.value("B").toString().toDouble();
1634 //printf("#### Color: %f, %f, %f\n", color[0], color[1], color[2]);
1636 actor->SetTitleVisibility( isVisible );
1637 actor->SetTitle( title.toLatin1() );
1638 vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1640 txtProp->SetColor( color );
1641 txtProp->SetFontFamily( font );
1642 txtProp->SetBold( bold );
1643 txtProp->SetItalic( italic );
1644 txtProp->SetShadow( shadow );
1651 } while (!reader.isStartElement());
1653 aAttr = reader.attributes();
1654 isVisible = aAttr.value("isVisible").toString().toUShort();
1655 int labels = aAttr.value("Number").toString().toInt();
1656 int offset = aAttr.value("Offset").toString().toInt();
1657 font = aAttr.value("Font").toString().toInt();
1658 bold = aAttr.value("Bold").toString().toInt();
1659 italic = aAttr.value("Italic").toString().toInt();
1660 shadow = aAttr.value("Shadow").toString().toInt();
1664 } while (!reader.isStartElement());
1666 aAttr = reader.attributes();
1668 color[0] = aAttr.value("R").toString().toDouble();
1669 color[1] = aAttr.value("G").toString().toDouble();
1670 color[2] = aAttr.value("B").toString().toDouble();
1672 actor->SetLabelVisibility( isVisible );
1673 actor->SetNumberOfLabels( labels );
1674 actor->SetTickOffset( offset );
1675 txtProp = actor->GetLabelTextProperty();
1677 txtProp->SetColor( color );
1678 txtProp->SetFontFamily( font );
1679 txtProp->SetBold( bold );
1680 txtProp->SetItalic( italic );
1681 txtProp->SetShadow( shadow );
1687 } while (!reader.isStartElement());
1688 aAttr = reader.attributes();
1690 // retrieve and set tick marks properties
1691 isVisible = aAttr.value("isVisible").toString().toUShort();
1692 int length = aAttr.value("Length").toString().toInt();
1694 actor->SetTickVisibility( isVisible );
1695 actor->SetTickLength( length );
1698 /*! The method restores visual parameters of a graduated axis actor (x,y,z axis)
1700 void setGradAxisVisualParams( vtkAxisActor2D* actor, const QString& params )
1705 QStringList paramsLst = params.split( '*' );
1707 if ( paramsLst.size() == nGradAxisParams ) { // altogether name, lable, ticks parameters make up 25 values
1709 // retrieve and set name parameters
1710 bool isVisible = paramsLst[2].toUShort();
1711 QString title = paramsLst[3];
1713 color[0] = paramsLst[4].toDouble();
1714 color[1] = paramsLst[5].toDouble();
1715 color[2] = paramsLst[6].toDouble();
1716 int font = paramsLst[7].toInt();
1717 int bold = paramsLst[8].toInt();
1718 int italic = paramsLst[9].toInt();
1719 int shadow = paramsLst[10].toInt();
1721 actor->SetTitleVisibility( isVisible );
1722 actor->SetTitle( title.toLatin1() );
1723 vtkTextProperty* txtProp = actor->GetTitleTextProperty();
1725 txtProp->SetColor( color );
1726 txtProp->SetFontFamily( font );
1727 txtProp->SetBold( bold );
1728 txtProp->SetItalic( italic );
1729 txtProp->SetShadow( shadow );
1732 // retrieve and set lable parameters
1733 isVisible = paramsLst[12].toUShort();
1734 int labels = paramsLst[13].toInt();
1735 int offset = paramsLst[14].toInt();
1736 color[0] = paramsLst[15].toDouble();
1737 color[1] = paramsLst[16].toDouble();
1738 color[2] = paramsLst[17].toDouble();
1739 font = paramsLst[18].toInt();
1740 bold = paramsLst[19].toInt();
1741 italic = paramsLst[20].toInt();
1742 shadow = paramsLst[21].toInt();
1744 actor->SetLabelVisibility( isVisible );
1745 actor->SetNumberOfLabels( labels );
1746 actor->SetTickOffset( offset );
1747 txtProp = actor->GetLabelTextProperty();
1749 txtProp->SetColor( color );
1750 txtProp->SetFontFamily( font );
1751 txtProp->SetBold( bold );
1752 txtProp->SetItalic( italic );
1753 txtProp->SetShadow( shadow );
1756 // retrieve and set tick marks properties
1757 isVisible = paramsLst[23].toUShort();
1758 int length = paramsLst[24].toInt();
1760 actor->SetTickVisibility( isVisible );
1761 actor->SetTickLength( length );
1765 /*! The method returns the visual parameters of this view as a formated string
1767 QString SVTK_ViewWindow::getVisualParameters()
1769 double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
1771 // save position, focal point, viewUp, scale
1772 vtkCamera* camera = getRenderer()->GetActiveCamera();
1773 camera->GetPosition( pos );
1774 camera->GetFocalPoint( focalPnt );
1775 camera->GetViewUp( viewUp );
1776 parScale = camera->GetParallelScale();
1779 // Parameters are given in the following format:view position (3 digits), focal point position (3 digits)
1780 // view up values (3 digits), parallel scale (1 digit), scale (3 digits,
1781 // Graduated axes parameters (X, Y, Z axes parameters)
1783 QXmlStreamWriter aWriter(&retStr);
1784 aWriter.setAutoFormatting(true);
1786 aWriter.writeStartDocument();
1787 aWriter.writeStartElement("ViewState");
1789 aWriter.writeStartElement("Position");
1790 aWriter.writeAttribute("X", QString("%1").arg(pos[0]));
1791 aWriter.writeAttribute("Y", QString("%1").arg(pos[1]));
1792 aWriter.writeAttribute("Z", QString("%1").arg(pos[2]));
1793 aWriter.writeEndElement();
1795 aWriter.writeStartElement("FocalPoint");
1796 aWriter.writeAttribute("X", QString::number(focalPnt[0]));
1797 aWriter.writeAttribute("Y", QString::number(focalPnt[1]));
1798 aWriter.writeAttribute("Z", QString::number(focalPnt[2]));
1799 aWriter.writeEndElement();
1801 aWriter.writeStartElement("ViewUp");
1802 aWriter.writeAttribute("X", QString::number(viewUp[0]));
1803 aWriter.writeAttribute("Y", QString::number(viewUp[1]));
1804 aWriter.writeAttribute("Z", QString::number(viewUp[2]));
1805 aWriter.writeEndElement();
1807 aWriter.writeStartElement("ViewScale");
1808 aWriter.writeAttribute("Parallel", QString::number(parScale));
1809 aWriter.writeAttribute("X", QString::number(scale[0]));
1810 aWriter.writeAttribute("Y", QString::number(scale[1]));
1811 aWriter.writeAttribute("Z", QString::number(scale[2]));
1812 aWriter.writeEndElement();
1814 if ( SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes() ) {
1815 aWriter.writeStartElement("DisplayCubeAxis");
1816 aWriter.writeAttribute("Show", QString( "%1" ).arg( GetRenderer()->IsCubeAxesDisplayed()));
1817 aWriter.writeEndElement();
1819 getGradAxisVisualParams(aWriter, gradAxesActor->GetXAxisActor2D(), "X");
1820 getGradAxisVisualParams(aWriter, gradAxesActor->GetYAxisActor2D(), "Y");
1821 getGradAxisVisualParams(aWriter, gradAxesActor->GetZAxisActor2D(), "Z");
1824 aWriter.writeStartElement("Trihedron");
1825 aWriter.writeAttribute("isShown", QString( "%1" ).arg( isTrihedronDisplayed()));
1826 aWriter.writeAttribute("Size", QString::number(GetTrihedronSize()));
1827 aWriter.writeEndElement();
1829 aWriter.writeStartElement("Background");
1830 aWriter.writeAttribute("Value", QString( "%1" ).arg( Qtx::backgroundToString(background()) ));
1831 aWriter.writeEndElement();
1833 aWriter.writeEndElement();
1834 aWriter.writeEndDocument();
1840 The method restores visual parameters of this view or postpones it untill the view is shown
1842 void SVTK_ViewWindow::setVisualParameters( const QString& parameters )
1844 //printf("#### %s\n", qPrintable(parameters));
1845 SVTK_RenderWindowInteractor* anInteractor = GetInteractor();
1846 if ( anInteractor->isVisible() ) {
1847 doSetVisualParameters( parameters );
1850 myVisualParams = parameters;
1851 anInteractor->installEventFilter(this);
1856 The method restores visual parameters of this view from a formated string
1858 void SVTK_ViewWindow::doSetVisualParameters( const QString& parameters, bool baseParamsOnly )
1861 double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
1863 QXmlStreamReader aReader(parameters);
1864 SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes();
1866 while(!aReader.atEnd()) {
1868 if (aReader.isStartElement()) {
1869 QXmlStreamAttributes aAttr = aReader.attributes();
1870 //printf("### Name = %s\n", qPrintable(aReader.name().toString()));
1871 if (aReader.name() == "Position") {
1872 pos[0] = aAttr.value("X").toString().toDouble();
1873 pos[1] = aAttr.value("Y").toString().toDouble();
1874 pos[2] = aAttr.value("Z").toString().toDouble();
1875 //printf("#### Position %f; %f; %f\n", pos[0], pos[1], pos[2]);
1877 else if (aReader.name() == "FocalPoint") {
1878 focalPnt[0] = aAttr.value("X").toString().toDouble();
1879 focalPnt[1] = aAttr.value("Y").toString().toDouble();
1880 focalPnt[2] = aAttr.value("Z").toString().toDouble();
1881 //printf("#### FocalPoint %f; %f; %f\n", focalPnt[0], focalPnt[1], focalPnt[2]);
1883 else if (aReader.name() == "ViewUp") {
1884 viewUp[0] = aAttr.value("X").toString().toDouble();
1885 viewUp[1] = aAttr.value("Y").toString().toDouble();
1886 viewUp[2] = aAttr.value("Z").toString().toDouble();
1887 //printf("#### ViewUp %f; %f; %f\n", viewUp[0], viewUp[1], viewUp[2]);
1889 else if (aReader.name() == "ViewScale") {
1890 parScale = aAttr.value("Parallel").toString().toDouble();
1891 scale[0] = aAttr.value("X").toString().toDouble();
1892 scale[1] = aAttr.value("Y").toString().toDouble();
1893 scale[2] = aAttr.value("Z").toString().toDouble();
1894 //printf("#### ViewScale %f; %f; %f\n", scale[0], scale[1], scale[2]);
1896 else if (aReader.name() == "DisplayCubeAxis") {
1897 if ( !baseParamsOnly ) {
1898 if (aAttr.value("Show") == "0")
1899 gradAxesActor->VisibilityOff();
1901 gradAxesActor->VisibilityOn();
1904 else if (aReader.name() == "GraduatedAxis") {
1905 if ( !baseParamsOnly ) {
1906 if(aAttr.value("Axis") == "X")
1907 setGradAxisVisualParams(aReader, gradAxesActor->GetXAxisActor2D());
1908 else if(aAttr.value("Axis") == "Y")
1909 setGradAxisVisualParams(aReader, gradAxesActor->GetYAxisActor2D());
1910 else if(aAttr.value("Axis") == "Z")
1911 setGradAxisVisualParams(aReader, gradAxesActor->GetZAxisActor2D());
1914 else if (aReader.name() == "Trihedron") {
1915 if ( !baseParamsOnly ) {
1916 if (aAttr.value("isShown") == "0")
1917 GetTrihedron()->VisibilityOff();
1919 GetTrihedron()->VisibilityOn();
1920 SetTrihedronSize(aAttr.value("Size").toString().toDouble());
1923 else if (aReader.name() == "Background") {
1924 if ( !baseParamsOnly ) {
1925 setBackground( Qtx::stringToBackground( aAttr.value("Value").toString() ) );
1930 if (!aReader.hasError()) {
1931 vtkCamera* camera = getRenderer()->GetActiveCamera();
1932 camera->SetPosition( pos );
1933 camera->SetFocalPoint( focalPnt );
1934 camera->SetViewUp( viewUp );
1935 camera->SetParallelScale( parScale );
1936 GetRenderer()->SetScale( scale );
1937 //SetScale( scale );
1940 QStringList paramsLst = parameters.split( '*' );
1941 if ( paramsLst.size() >= nNormalParams ) {
1942 // 'reading' list of parameters
1943 pos[0] = paramsLst[0].toDouble();
1944 pos[1] = paramsLst[1].toDouble();
1945 pos[2] = paramsLst[2].toDouble();
1946 focalPnt[0] = paramsLst[3].toDouble();
1947 focalPnt[1] = paramsLst[4].toDouble();
1948 focalPnt[2] = paramsLst[5].toDouble();
1949 viewUp[0] = paramsLst[6].toDouble();
1950 viewUp[1] = paramsLst[7].toDouble();
1951 viewUp[2] = paramsLst[8].toDouble();
1952 parScale = paramsLst[9].toDouble();
1953 scale[0] = paramsLst[10].toDouble();
1954 scale[1] = paramsLst[11].toDouble();
1955 scale[2] = paramsLst[12].toDouble();
1957 // applying parameters
1958 vtkCamera* camera = getRenderer()->GetActiveCamera();
1959 camera->SetPosition( pos );
1960 camera->SetFocalPoint( focalPnt );
1961 camera->SetViewUp( viewUp );
1962 camera->SetParallelScale( parScale );
1963 GetRenderer()->SetScale( scale );
1964 //SetScale( scale );
1966 // apply graduated axes parameters
1967 if ( !baseParamsOnly ) {
1968 SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes();
1969 if ( gradAxesActor && paramsLst.size() == nAllParams ) {
1970 int i = nNormalParams+1, j = i + nGradAxisParams - 1;
1971 ::setGradAxisVisualParams( gradAxesActor->GetXAxisActor2D(), parameters.section( '*', i, j ) );
1972 i = j + 1; j += nGradAxisParams;
1973 ::setGradAxisVisualParams( gradAxesActor->GetYAxisActor2D(), parameters.section( '*', i, j ) );
1974 i = j + 1; j += nGradAxisParams;
1975 ::setGradAxisVisualParams( gradAxesActor->GetZAxisActor2D(), parameters.section( '*', i, j ) );
1977 if ( paramsLst[13].toUShort() )
1978 gradAxesActor->VisibilityOn();
1980 gradAxesActor->VisibilityOff();
1982 else if ( paramsLst.size() == nAllParams ) {
1983 if ( paramsLst[90].toUShort() )
1984 GetTrihedron()->VisibilityOn();
1986 GetTrihedron()->VisibilityOff();
1988 SetTrihedronSize(paramsLst[91].toDouble());
1998 Delayed setVisualParameters
2000 bool SVTK_ViewWindow::eventFilter( QObject* theWatched, QEvent* theEvent )
2002 if ( theEvent->type() == QEvent::Show && theWatched->inherits( "SVTK_RenderWindowInteractor" ) ) {
2003 SVTK_RenderWindowInteractor* anInteractor = (SVTK_RenderWindowInteractor*)theWatched;
2004 if ( anInteractor->isVisible() ) {
2005 doSetVisualParameters( myVisualParams );
2006 anInteractor->removeEventFilter( this ); // theWatched = RenderWindowInteractor
2009 return SUIT_ViewWindow::eventFilter( theWatched, theEvent );
2014 Change rotation point
2016 void SVTK_ViewWindow::onChangeRotationPoint(bool theIsActivate)
2019 mySetRotationPointDlg->addObserver();
2020 if ( mySetRotationPointDlg->IsFirstShown() )
2021 activateSetRotationGravity();
2022 mySetRotationPointDlg->show();
2024 mySetRotationPointDlg->hide();
2028 Set the gravity center as a rotation point
2030 void SVTK_ViewWindow::activateSetRotationGravity()
2032 myEventDispatcher->InvokeEvent(SVTK::SetRotateGravity,0);
2036 Set the selected point as a rotation point
2038 void SVTK_ViewWindow::activateSetRotationSelected(void* theData)
2040 myEventDispatcher->InvokeEvent(SVTK::ChangeRotationPoint,theData);
2044 Set the gravity center of element selected by user as a rotation point
2046 void SVTK_ViewWindow::activateStartPointSelection( Selection_Mode theSelectionMode )
2048 SetSelectionMode( theSelectionMode );
2049 myEventDispatcher->InvokeEvent(SVTK::StartPointSelection,0);
2053 \brief Set the given projection mode.
2055 Set the given projection mode: Orthographic or Perspective.
2057 void SVTK_ViewWindow::onProjectionMode( QAction* theAction )
2059 int aMode = Parallel;
2060 if (theAction == toolMgr()->action( ProjectionModeId ))
2062 SVTK_Viewer* aViewer = dynamic_cast<SVTK_Viewer*>(myModel);
2063 aViewer->setProjectionMode(aMode);
2064 bool anIsParallelMode = (aMode == Parallel);
2065 vtkCamera* aCamera = getRenderer()->GetActiveCamera();
2066 aCamera->SetParallelProjection(anIsParallelMode);
2067 GetInteractor()->GetDevice()->CreateTimer(VTKI_TIMER_FIRST);
2068 getRenderWindow()->SetStereoRender(0);
2073 \brief Sets Stereo projection mode.
2075 Sets Stereo projection mode.
2077 void SVTK_ViewWindow::onStereoMode( bool activate )
2080 toolMgr()->action( ProjectionModeId )->setChecked(true);
2081 vtkCamera* aCamera = getRenderer()->GetActiveCamera();
2082 aCamera->SetParallelProjection(false);
2083 toolMgr()->action( ProjectionModeId )->actionGroup()->setEnabled(false);
2084 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
2085 SetStereoType( aResMgr->integerValue( "VTKViewer", "stereo_type", 0 ) );
2086 getRenderWindow()->SetStereoRender(1);
2090 toolMgr()->action( ProjectionModeId )->actionGroup()->setEnabled(true);
2091 SVTK_Viewer* aViewer = dynamic_cast<SVTK_Viewer*>(myModel);
2092 if (aViewer->projectionMode() == Parallel) {
2093 toolMgr()->action( ParallelModeId )->setChecked(true);
2094 onProjectionMode(toolMgr()->action( ParallelModeId ));
2096 else if (aViewer->projectionMode() == Projection) {
2097 toolMgr()->action( ProjectionModeId )->setChecked(true);
2098 onProjectionMode(toolMgr()->action( ProjectionModeId ));
2101 if ( getRenderWindow()->GetStereoCapableWindow() == 1 && !isOpenGlStereoSupport() &&
2102 strcmp( "CrystalEyes", getRenderWindow()->GetStereoTypeAsString() ) == 0 &&
2103 toolMgr()->action( StereoModeId )->isChecked() )
2104 SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) );
2108 Set the view projection mode: orthogonal or perspective
2110 void SVTK_ViewWindow::onProjectionMode()
2112 if (toolMgr()->action( ParallelModeId )->isChecked())
2113 SetProjectionMode( Parallel);
2114 if (toolMgr()->action( ProjectionModeId )->isChecked())
2115 SetProjectionMode( Projection);
2116 if (toolMgr()->action( StereoModeId )->isChecked())
2117 SetProjectionMode( Stereo);
2118 emit transformed( this );
2121 void SVTK_ViewWindow::SetEventDispatcher(vtkObject* theDispatcher)
2123 myEventDispatcher = theDispatcher;
2127 Creates all actions of svtk main window
2129 void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
2131 QtxAction* anAction;
2132 QtxActionToolMgr* mgr = toolMgr();
2135 anAction = new QtxAction(tr("MNU_DUMP_VIEW"),
2136 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
2137 tr( "MNU_DUMP_VIEW" ), 0, this);
2138 anAction->setStatusTip(tr("DSC_DUMP_VIEW"));
2139 connect(anAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
2140 mgr->registerAction( anAction, DumpId );
2143 anAction = new QtxAction(tr("MNU_FITALL"),
2144 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
2145 tr( "MNU_FITALL" ), 0, this);
2146 anAction->setStatusTip(tr("DSC_FITALL"));
2147 connect(anAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
2148 mgr->registerAction( anAction, FitAllId );
2151 anAction = new QtxAction(tr("MNU_FITRECT"),
2152 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
2153 tr( "MNU_FITRECT" ), 0, this);
2154 anAction->setStatusTip(tr("DSC_FITRECT"));
2155 connect(anAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
2156 mgr->registerAction( anAction, FitRectId );
2159 anAction = new QtxAction(tr("MNU_FITSELECTION"),
2160 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITSELECTION" ) ),
2161 tr( "MNU_FITSELECTION" ), 0, this);
2162 anAction->setStatusTip(tr("DSC_FITSELECTION"));
2163 connect(anAction, SIGNAL(triggered()), this, SLOT(onFitSelection()));
2164 mgr->registerAction( anAction, FitSelectionId );
2167 anAction = new QtxAction(tr("MNU_ZOOM_VIEW"),
2168 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
2169 tr( "MNU_ZOOM_VIEW" ), 0, this);
2170 anAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
2171 connect(anAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
2172 mgr->registerAction( anAction, ZoomId );
2175 anAction = new QtxAction(tr("MNU_PAN_VIEW"),
2176 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
2177 tr( "MNU_PAN_VIEW" ), 0, this);
2178 anAction->setStatusTip(tr("DSC_PAN_VIEW"));
2179 connect(anAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
2180 mgr->registerAction( anAction, PanId );
2183 anAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"),
2184 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
2185 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
2186 anAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
2187 connect(anAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
2188 mgr->registerAction( anAction, GlobalPanId );
2190 // Change rotation point
2191 anAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"),
2192 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_ROTATION_POINT" ) ),
2193 tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
2194 anAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
2195 anAction->setCheckable(true);
2196 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onChangeRotationPoint(bool)));
2197 mgr->registerAction( anAction, ChangeRotationPointId );
2200 anAction = new QtxAction(tr("MNU_ROTATE_VIEW"),
2201 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
2202 tr( "MNU_ROTATE_VIEW" ), 0, this);
2203 anAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
2204 connect(anAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
2205 mgr->registerAction( anAction, RotationId );
2208 anAction = new QtxAction(tr("MNU_FRONT_VIEW"),
2209 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
2210 tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
2211 anAction->setStatusTip(tr("DSC_FRONT_VIEW"));
2212 connect(anAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
2213 this->addAction(anAction);
2214 mgr->registerAction( anAction, FrontId );
2216 anAction = new QtxAction(tr("MNU_BACK_VIEW"),
2217 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
2218 tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
2219 anAction->setStatusTip(tr("DSC_BACK_VIEW"));
2220 connect(anAction, SIGNAL(triggered()), this, SLOT(onBackView()));
2221 this->addAction(anAction);
2222 mgr->registerAction( anAction, BackId );
2224 anAction = new QtxAction(tr("MNU_TOP_VIEW"),
2225 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
2226 tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
2227 anAction->setStatusTip(tr("DSC_TOP_VIEW"));
2228 connect(anAction, SIGNAL(triggered()), this, SLOT(onTopView()));
2229 this->addAction(anAction);
2230 mgr->registerAction( anAction, TopId );
2232 anAction = new QtxAction(tr("MNU_BOTTOM_VIEW"),
2233 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
2234 tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
2235 anAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
2236 connect(anAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
2237 this->addAction(anAction);
2238 mgr->registerAction( anAction, BottomId );
2240 anAction = new QtxAction(tr("MNU_LEFT_VIEW"),
2241 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
2242 tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
2243 anAction->setStatusTip(tr("DSC_LEFT_VIEW"));
2244 connect(anAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
2245 this->addAction(anAction);
2246 mgr->registerAction( anAction, LeftId );
2248 anAction = new QtxAction(tr("MNU_RIGHT_VIEW"),
2249 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
2250 tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
2251 anAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
2252 connect(anAction, SIGNAL(triggered()), this, SLOT(onRightView()));
2253 this->addAction(anAction);
2254 mgr->registerAction( anAction, RightId );
2256 // rotate anticlockwise
2257 anAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"),
2258 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ANTICLOCKWISE" ) ),
2259 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
2260 anAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
2261 connect(anAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
2262 this->addAction(anAction);
2263 mgr->registerAction( anAction, AntiClockWiseId );
2266 anAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"),
2267 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_CLOCKWISE" ) ),
2268 tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
2269 anAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
2270 connect(anAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
2271 this->addAction(anAction);
2272 mgr->registerAction( anAction, ClockWiseId );
2275 anAction = new QtxAction(tr("MNU_RESET_VIEW"),
2276 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
2277 tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
2278 anAction->setStatusTip(tr("DSC_RESET_VIEW"));
2279 connect(anAction, SIGNAL(triggered()), this, SLOT(onResetView()));
2280 this->addAction(anAction);
2281 mgr->registerAction( anAction, ResetId );
2283 // onViewTrihedron: Shows - Hides Trihedron
2284 anAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"),
2285 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ),
2286 tr( "MNU_SHOW_TRIHEDRON" ), 0, this);
2287 anAction->setCheckable( true );
2288 anAction->setChecked( true );
2290 anAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON"));
2291 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onViewTrihedron(bool)));
2292 mgr->registerAction( anAction, ViewTrihedronId );
2294 // onNonIsometric: Manage non-isometric params
2295 anAction = new QtxAction(tr("MNU_SVTK_SCALING"),
2296 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SCALING" ) ),
2297 tr( "MNU_SVTK_SCALING" ), 0, this);
2298 anAction->setStatusTip(tr("DSC_SVTK_SCALING"));
2299 anAction->setCheckable(true);
2300 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onNonIsometric(bool)));
2301 mgr->registerAction( anAction, NonIsometric );
2303 // onGraduatedAxes: Manage graduated axes params
2304 anAction = new QtxAction(tr("MNU_SVTK_GRADUATED_AXES"),
2305 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_GRADUATED_AXES" ) ),
2306 tr( "MNU_SVTK_GRADUATED_AXES" ), 0, this);
2307 anAction->setStatusTip(tr("DSC_SVTK_GRADUATED_AXES"));
2308 anAction->setCheckable(true);
2309 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onGraduatedAxes(bool)));
2310 mgr->registerAction( anAction, GraduatedAxes );
2312 // onGraduatedAxes: Manage graduated axes params
2313 anAction = new QtxAction(tr("MNU_SVTK_UPDATE_RATE"),
2314 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_UPDATE_RATE" ) ),
2315 tr( "MNU_SVTK_UPDATE_RATE" ), 0, this);
2316 anAction->setStatusTip(tr("DSC_SVTK_UPDATE_RATE"));
2317 anAction->setCheckable(true);
2318 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onUpdateRate(bool)));
2319 mgr->registerAction( anAction, UpdateRate );
2321 // Set perspective mode group
2322 anAction = new QtxAction(tr("MNU_SVTK_PARALLEL_MODE"),
2323 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARALLEL" ) ),
2324 tr( "MNU_SVTK_PARALLEL_MODE" ), 0, this);
2325 anAction->setStatusTip(tr("DSC_SVTK_PARALLEL_MODE"));
2326 anAction->setCheckable(true);
2327 mgr->registerAction( anAction, ParallelModeId );
2329 anAction = new QtxAction(tr("MNU_SVTK_PERSPECTIVE_MODE"),
2330 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PERSPECTIVE" ) ),
2331 tr( "MNU_SVTK_PERSPECTIVE_MODE" ), 0, this);
2332 anAction->setStatusTip(tr("DSC_SVTK_PERSPECTIVE_MODE"));
2333 anAction->setCheckable(true);
2334 mgr->registerAction( anAction, ProjectionModeId );
2336 anAction = new QtxAction(tr("MNU_SVTK_STEREO_MODE"),
2337 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_STEREO" ) ),
2338 tr( "MNU_SVTK_STEREO_MODE" ), 0, this);
2339 anAction->setStatusTip(tr("DSC_SVTK_STEREO_MODE"));
2340 anAction->setCheckable(true);
2341 connect(anAction, SIGNAL(triggered(bool)), this, SLOT(onStereoMode(bool)));
2342 mgr->registerAction( anAction, StereoModeId );
2344 QActionGroup* aPerspectiveGroup = new QActionGroup( this );
2345 aPerspectiveGroup->addAction( mgr->action( ParallelModeId ) );
2346 aPerspectiveGroup->addAction( mgr->action( ProjectionModeId ) );
2347 connect(aPerspectiveGroup, SIGNAL(triggered(QAction*)), this, SLOT(onProjectionMode(QAction*)));
2350 anAction = new QtxAction(tr("MNU_VIEWPARAMETERS_VIEW"),
2351 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARAMETERS" ) ),
2352 tr( "MNU_VIEWPARAMETERS_VIEW" ), 0, this);
2353 anAction->setStatusTip(tr("DSC_VIEWPARAMETERS_VIEW"));
2354 anAction->setCheckable(true);
2355 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onViewParameters(bool)));
2356 mgr->registerAction( anAction, ViewParametersId );
2359 mgr->registerAction( synchronizeAction(), SynchronizeId );
2361 // Switch between interaction styles
2362 anAction = new QtxAction(tr("MNU_SVTK_STYLE_SWITCH"),
2363 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_STYLE_SWITCH" ) ),
2364 tr( "MNU_SVTK_STYLE_SWITCH" ), 0, this);
2365 anAction->setStatusTip(tr("DSC_SVTK_STYLE_SWITCH"));
2366 anAction->setCheckable(true);
2367 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
2368 mgr->registerAction( anAction, SwitchInteractionStyleId );
2370 // Switch between zooming styles
2371 anAction = new QtxAction(tr("MNU_SVTK_ZOOMING_STYLE_SWITCH"),
2372 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_ZOOMING_STYLE_SWITCH" ) ),
2373 tr( "MNU_SVTK_ZOOMING_STYLE_SWITCH" ), 0, this);
2374 anAction->setStatusTip(tr("DSC_SVTK_ZOOMING_STYLE_SWITCH"));
2375 anAction->setCheckable(true);
2376 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
2377 mgr->registerAction( anAction, SwitchZoomingStyleId );
2380 QSignalMapper* aSignalMapper = new QSignalMapper( this );
2381 connect(aSignalMapper, SIGNAL(mapped(int)), this, SLOT(onSwitchPreSelectionMode(int)));
2383 anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_STANDARD"),
2384 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_STANDARD" ) ),
2385 tr( "MNU_SVTK_PRESELECTION_STANDARD" ), 0, this);
2386 anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_STANDARD"));
2387 anAction->setCheckable(true);
2388 connect(anAction, SIGNAL(triggered()), aSignalMapper, SLOT(map()));
2389 aSignalMapper->setMapping( anAction, Standard_Preselection );
2390 mgr->registerAction( anAction, StandardPreselectionId );
2392 anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_DYNAMIC"),
2393 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_DYNAMIC" ) ),
2394 tr( "MNU_SVTK_PRESELECTION_DYNAMIC" ), 0, this);
2395 anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_DYNAMIC"));
2396 anAction->setCheckable(true);
2397 connect(anAction, SIGNAL(triggered()), aSignalMapper, SLOT(map()));
2398 aSignalMapper->setMapping( anAction, Dynamic_Preselection );
2399 mgr->registerAction( anAction, DynamicPreselectionId );
2401 anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_DISABLED"),
2402 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_DISABLED" ) ),
2403 tr( "MNU_SVTK_PRESELECTION_DISABLED" ), 0, this);
2404 anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_DISABLED"));
2405 anAction->setCheckable(true);
2406 connect(anAction, SIGNAL(triggered()), aSignalMapper, SLOT(map()));
2407 aSignalMapper->setMapping( anAction, Preselection_Disabled );
2408 mgr->registerAction( anAction, DisablePreselectionId );
2410 QtxActionGroup* aPreselectionAction = new QtxActionGroup( this, true );
2411 aPreselectionAction->add( getAction( StandardPreselectionId ) );
2412 aPreselectionAction->add( getAction( DynamicPreselectionId ) );
2413 aPreselectionAction->add( getAction( DisablePreselectionId ) );
2414 mgr->registerAction( aPreselectionAction, PreselectionId );
2417 anAction = new QtxAction(tr("MNU_SVTK_ENABLE_SELECTION"),
2418 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SELECTION" ) ),
2419 tr( "MNU_SVTK_ENABLE_SELECTION" ), 0, this);
2420 anAction->setStatusTip(tr("DSC_SVTK_ENABLE_SELECTION"));
2421 anAction->setCheckable(true);
2422 connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onEnableSelection(bool)));
2423 mgr->registerAction( anAction, EnableSelectionId );
2426 myStartAction = new QtxAction(tr("MNU_SVTK_RECORDING_START"),
2427 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_START" ) ),
2428 tr( "MNU_SVTK_RECORDING_START" ), 0, this);
2429 myStartAction->setStatusTip(tr("DSC_SVTK_RECORDING_START"));
2430 connect( myStartAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStartRecording() ) );
2431 mgr->registerAction( myStartAction, StartRecordingId );
2434 myPlayAction = new QtxAction(tr("MNU_SVTK_RECORDING_PLAY"),
2435 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PLAY" ) ),
2436 tr( "MNU_SVTK_RECORDING_PLAY" ), 0, this);
2437 myPlayAction->setStatusTip(tr("DSC_SVTK_RECORDING_PLAY"));
2438 myPlayAction->setEnabled( false );
2439 connect( myPlayAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPlayRecording() ) );
2440 mgr->registerAction( myPlayAction, PlayRecordingId );
2443 myPauseAction = new QtxAction(tr("MNU_SVTK_RECORDING_PAUSE"),
2444 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PAUSE" ) ),
2445 tr( "MNU_SVTK_RECORDING_PAUSE" ), 0, this);
2446 myPauseAction->setStatusTip(tr("DSC_SVTK_RECORDING_PAUSE"));
2447 myPauseAction->setEnabled( false );
2448 connect( myPauseAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPauseRecording() ) );
2449 mgr->registerAction( myPauseAction, PauseRecordingId );
2452 myStopAction = new QtxAction(tr("MNU_SVTK_RECORDING_STOP"),
2453 theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_STOP" ) ),
2454 tr( "MNU_SVTK_RECORDING_STOP" ), 0, this);
2455 myStopAction->setStatusTip(tr("DSC_SVTK_RECORDING_STOP"));
2456 myStopAction->setEnabled( false );
2457 connect( myStopAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStopRecording() ) );
2458 mgr->registerAction( myStopAction, StopRecordingId );
2462 Creates toolbar of svtk main window
2464 void SVTK_ViewWindow::createToolBar()
2466 QtxActionToolMgr* mgr = toolMgr();
2468 mgr->append( DumpId, myToolBar );
2469 mgr->append( SwitchInteractionStyleId, myToolBar );
2470 mgr->append( SwitchZoomingStyleId, myToolBar );
2472 mgr->append( mgr->separator(), myToolBar );
2474 mgr->append( PreselectionId, myToolBar );
2475 mgr->append( EnableSelectionId, myToolBar );
2477 mgr->append( mgr->separator(), myToolBar );
2479 mgr->append( ViewTrihedronId, myToolBar );
2481 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
2482 aScaleAction->insertAction( getAction( FitAllId ) );
2483 aScaleAction->insertAction( getAction( FitRectId ) );
2484 aScaleAction->insertAction( getAction( FitSelectionId ) );
2485 aScaleAction->insertAction( getAction( ZoomId ) );
2486 mgr->append( aScaleAction, myToolBar );
2488 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
2489 aPanningAction->insertAction( getAction( PanId ) );
2490 aPanningAction->insertAction( getAction( GlobalPanId ) );
2491 mgr->append( aPanningAction, myToolBar );
2493 mgr->append( ChangeRotationPointId, myToolBar );
2495 mgr->append( RotationId, myToolBar );
2497 QtxMultiAction* aViewsAction = new QtxMultiAction( this );
2498 aViewsAction->insertAction( getAction( FrontId ) );
2499 aViewsAction->insertAction( getAction( BackId ) );
2500 aViewsAction->insertAction( getAction( TopId ) );
2501 aViewsAction->insertAction( getAction( BottomId ) );
2502 aViewsAction->insertAction( getAction( LeftId ) );
2503 aViewsAction->insertAction( getAction( RightId ) );
2504 mgr->append( aViewsAction, myToolBar );
2506 mgr->append( AntiClockWiseId, myToolBar );
2507 mgr->append( ClockWiseId, myToolBar );
2509 mgr->append( ResetId, myToolBar );
2511 mgr->append( UpdateRate, myToolBar );
2512 mgr->append( NonIsometric, myToolBar );
2513 mgr->append( GraduatedAxes, myToolBar );
2515 mgr->append( ViewParametersId, myToolBar );
2516 mgr->append( SynchronizeId, myToolBar );
2518 mgr->append( toolMgr()->separator(), myToolBar );
2520 mgr->append( ParallelModeId, myToolBar );
2521 mgr->append( ProjectionModeId, myToolBar );
2522 mgr->append( StereoModeId, myToolBar );
2524 mgr->append( StartRecordingId, myRecordingToolBar );
2525 mgr->append( PlayRecordingId, myRecordingToolBar );
2526 mgr->append( PauseRecordingId, myRecordingToolBar );
2527 mgr->append( StopRecordingId, myRecordingToolBar );
2530 void SVTK_ViewWindow::onUpdateRate(bool theIsActivate)
2533 myUpdateRateDlg->Update();
2534 myUpdateRateDlg->show();
2536 myUpdateRateDlg->hide();
2539 void SVTK_ViewWindow::onNonIsometric(bool theIsActivate)
2542 myNonIsometricDlg->Update();
2543 myNonIsometricDlg->show();
2545 myNonIsometricDlg->hide();
2548 void SVTK_ViewWindow::onGraduatedAxes(bool theIsActivate)
2551 myCubeAxesDlg->Update();
2552 myCubeAxesDlg->show();
2554 myCubeAxesDlg->hide();
2558 Starts rotation transformation
2560 void SVTK_ViewWindow::activateRotation()
2562 myEventDispatcher->InvokeEvent(SVTK::StartRotate,0);
2567 Starts panning transformation
2569 void SVTK_ViewWindow::activatePanning()
2571 myEventDispatcher->InvokeEvent(SVTK::StartPan,0);
2575 Starts zoom transformation
2577 void SVTK_ViewWindow::activateZoom()
2579 myEventDispatcher->InvokeEvent(SVTK::StartZoom,0);
2583 Starts window fit transformation
2585 void SVTK_ViewWindow::activateWindowFit()
2587 myEventDispatcher->InvokeEvent(SVTK::StartFitArea,0);
2591 Starts global panning transformation
2593 void SVTK_ViewWindow::activateGlobalPanning()
2595 myEventDispatcher->InvokeEvent(SVTK::StartGlobalPan,0);
2598 void SVTK_ViewWindow::onStartRecording()
2600 myRecorder->CheckExistAVIMaker();
2601 if (myRecorder->ErrorStatus()) {
2602 SUIT_MessageBox::warning(this, tr("ERROR"), tr("MSG_NO_AVI_MAKER") );
2605 SVTK_RecorderDlg* aRecorderDlg = new SVTK_RecorderDlg( this, myRecorder );
2607 if( !aRecorderDlg->exec() )
2610 myStartAction->setEnabled( false );
2611 myPlayAction->setEnabled( false );
2612 myPauseAction->setEnabled( true );
2613 myStopAction->setEnabled( true );
2615 // to prevent resizing the window while recording
2616 myPreRecordingMinSize = minimumSize();
2617 myPreRecordingMaxSize = maximumSize();
2618 setFixedSize( size() );
2620 myRecorder->Record();
2624 void SVTK_ViewWindow::onPlayRecording()
2626 myStartAction->setEnabled( false );
2627 myPlayAction->setEnabled( false );
2628 myPauseAction->setEnabled( true );
2629 myStopAction->setEnabled( true );
2631 myRecorder->Pause();
2634 void SVTK_ViewWindow::onPauseRecording()
2636 myStartAction->setEnabled( false );
2637 myPlayAction->setEnabled( true );
2638 myPauseAction->setEnabled( false );
2639 myStopAction->setEnabled( true );
2641 myRecorder->Pause();
2644 void SVTK_ViewWindow::onStopRecording()
2646 myStartAction->setEnabled( true );
2647 myPlayAction->setEnabled( false );
2648 myPauseAction->setEnabled( false );
2649 myStopAction->setEnabled( false );
2653 setMinimumSize( myPreRecordingMinSize );
2654 setMaximumSize( myPreRecordingMaxSize );
2658 To invoke a VTK event on SVTK_RenderWindowInteractor instance
2660 void SVTK_ViewWindow::InvokeEvent(unsigned long theEvent, void* theCallData)
2662 GetInteractor()->InvokeEvent(theEvent,theCallData);
2666 Modify view parameters
2668 void SVTK_ViewWindow::onViewParameters(bool theIsActivate)
2671 myViewParameterDlg->addObserver();
2672 myViewParameterDlg->show();
2674 myViewParameterDlg->hide();
2678 Custom show event handler
2680 void SVTK_ViewWindow::showEvent( QShowEvent * theEvent )
2682 emit Show( theEvent );
2686 Custom hide event handler
2688 void SVTK_ViewWindow::hideEvent( QHideEvent * theEvent )
2690 emit Hide( theEvent );
2694 Emit transformed signal.
2696 void SVTK_ViewWindow::emitTransformed() {
2703 void SVTK_ViewWindow::ProcessEvents(vtkObject* vtkNotUsed(theObject),
2704 unsigned long theEvent,
2705 void* theClientData,
2708 SVTK_ViewWindow* self = reinterpret_cast<SVTK_ViewWindow*>(theClientData);
2710 self->emitTransformed();
2714 Get camera properties for the SVTK view window.
2715 \return shared pointer on camera properties.
2717 SUIT_CameraProperties SVTK_ViewWindow::cameraProperties()
2719 SUIT_CameraProperties aProps;
2722 vtkCamera* aCamera = getRenderer()->GetActiveCamera();
2726 aProps.setDimension( SUIT_CameraProperties::Dim3D );
2727 if ( toolMgr()->action( ParallelModeId ) ) {
2728 if ( toolMgr()->action( ParallelModeId )->isChecked() )
2729 aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
2731 aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
2734 double aFocalPoint[3];
2735 double aPosition[3];
2737 double anAxialScale[3];
2739 aCamera->OrthogonalizeViewUp();
2740 aCamera->GetFocalPoint( aFocalPoint );
2741 aCamera->GetPosition( aPosition );
2742 aCamera->GetViewUp( aViewUp );
2744 aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2745 aProps.setPosition( aPosition[0], aPosition[1], aPosition[2] );
2746 aProps.setViewUp( aViewUp[0], aViewUp[1], aViewUp[2] );
2747 aProps.setMappingScale( aCamera->GetParallelScale() * 2.0 );
2749 if ( aProps.getProjection() == SUIT_CameraProperties::PrjPerspective )
2751 aProps.setViewAngle( aCamera->GetViewAngle() );
2754 GetRenderer()->GetScale( anAxialScale );
2755 aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2762 This implementation synchronizes camera propreties.
2764 void SVTK_ViewWindow::synchronize( SUIT_ViewWindow* theView )
2766 bool blocked = blockSignals( true );
2768 SUIT_CameraProperties aProps = theView->cameraProperties();
2769 if ( !cameraProperties().isCompatible( aProps ) ) {
2770 // other view, this one is being currently synchronized to, seems has become incompatible
2771 // we have to break synchronization
2777 vtkCamera* aCamera = getRenderer()->GetActiveCamera();
2779 double aFocalPoint[3];
2780 double aPosition[3];
2782 double anAxialScale[3];
2784 // get common properties
2785 aProps.getViewUp( aViewUp[0], aViewUp[1], aViewUp[2] );
2786 aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
2787 aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
2788 aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
2790 // restore properties to the camera
2791 aCamera->SetViewUp( aViewUp );
2792 aCamera->SetPosition( aPosition );
2793 aCamera->SetFocalPoint( aFocalPoint );
2794 aCamera->SetParallelScale( aProps.getMappingScale() / 2.0 );
2796 if ( aProps.getProjection() == SUIT_CameraProperties::PrjPerspective )
2798 aCamera->SetViewAngle( aProps.getViewAngle() );
2801 GetRenderer()->SetScale( anAxialScale );
2803 getRenderer()->ResetCameraClippingRange();
2806 blockSignals( blocked );