X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSVTK%2FSVTK_ViewWindow.cxx;h=d13911d460eea075006e46f335365169f52bdb1a;hb=refs%2Fheads%2Fngr%2Fpython3_dev_pv5.4;hp=b5b67ddc70039a84d004374bd5053e0e0758fa06;hpb=1c889394b028b786898a995d38c07c8f3d564837;p=modules%2Fgui.git diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index b5b67ddc7..d13911d46 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -1,34 +1,42 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE // -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. // -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + #include "SVTK_NonIsometricDlg.h" #include "SVTK_UpdateRateDlg.h" #include "SVTK_CubeAxesDlg.h" +#include "SVTK_PsOptionsDlg.h" #include "SVTK_SetRotationPointDlg.h" #include "SVTK_ViewParameterDlg.h" +#include "SVTK_ViewModel.h" +#include "VTKViewer_Texture.h" +#include "VTKViewer_OpenGLRenderer.h" #include "SALOME_Actor.h" +#include #include #include +#include +#include #include #include #include @@ -43,6 +51,15 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "QtxAction.h" @@ -53,20 +70,21 @@ #include "SUIT_ResourceMgr.h" #include "SUIT_Accel.h" #include "SUIT_OverrideCursor.h" +#include "SUIT_ViewManager.h" #include "QtxActionToolMgr.h" #include "QtxMultiAction.h" +#include "QtxActionGroup.h" #include "VTKViewer_Utilities.h" #include "VTKViewer_Trihedron.h" +#include "VTKViewer_Actor.h" #include "SVTK_View.h" -//#include "SVTK_MainWindow.h" #include "SVTK_Selector.h" #include "SVTK_Event.h" #include "SVTK_Renderer.h" #include "SVTK_ViewWindow.h" -#include "SVTK_ViewModelBase.h" #include "SVTK_InteractorStyle.h" #include "SVTK_RenderWindowInteractor.h" #include "SVTK_GenericRenderWindowInteractor.h" @@ -77,11 +95,21 @@ #include "SVTK_Recorder.h" #include "SVTK_RecorderDlg.h" -#include "SALOME_ListIteratorOfListIO.hxx" +#include "salomevtkPVAxesWidget.h" +#include "salomevtkPVAxesActor.h" + +#include "SALOME_ListIO.hxx" #include "VTKViewer_Algorithm.h" #include "SVTK_Functor.h" +#include + +#ifdef __APPLE__ +#include +#else +#include +#endif namespace SVTK { @@ -103,10 +131,6 @@ namespace SVTK } } - - - - /*! Constructor */ @@ -114,7 +138,8 @@ SVTK_ViewWindow::SVTK_ViewWindow(SUIT_Desktop* theDesktop): SUIT_ViewWindow(theDesktop), myView(NULL), myDumpImage(QImage()), - myKeyFreeInteractorStyle(SVTK_KeyFreeInteractorStyle::New()) + myKeyFreeInteractorStyle(SVTK_KeyFreeInteractorStyle::New()), + myEventCallbackCommand(vtkCallbackCommand::New()) { setWindowFlags( windowFlags() & ~Qt::Window ); // specific of vtkSmartPointer @@ -126,10 +151,18 @@ SVTK_ViewWindow::SVTK_ViewWindow(SUIT_Desktop* theDesktop): */ void SVTK_ViewWindow::Initialize(SVTK_ViewModelBase* theModel) { + myModel = theModel; myInteractor = new SVTK_RenderWindowInteractor(this,"SVTK_RenderWindowInteractor"); SVTK_Selector* aSelector = SVTK_Selector::New(); - + int aPreselectionMode = SUIT_Session::session()->resourceMgr()-> + integerValue( "VTKViewer", "preselection", Standard_Preselection ); + aSelector->SetDynamicPreSelection( aPreselectionMode == Dynamic_Preselection ); + aSelector->SetPreSelectionEnabled( aPreselectionMode != Preselection_Disabled ); + bool isSelectionEnabled = SUIT_Session::session()->resourceMgr()-> + booleanValue( "VTKViewer", "enable_selection", true ); + aSelector->SetSelectionEnabled( isSelectionEnabled ); + SVTK_GenericRenderWindowInteractor* aDevice = SVTK_GenericRenderWindowInteractor::New(); aDevice->SetRenderWidget(myInteractor); aDevice->SetSelector(aSelector); @@ -143,29 +176,38 @@ void SVTK_ViewWindow::Initialize(SVTK_ViewModelBase* theModel) aRenderer->Delete(); aSelector->Delete(); - myToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_LABEL"), -1, this ); - myRecordingToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_RECORD_LABEL"), -1, this ); + myToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_LABEL"), // title (language-dependant) + QString( "VTKViewerViewOperations" ), // name (language-independant) + false ); // disable floatable toolbar + + myRecordingToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_RECORD_LABEL"), // title (language-dependant) + QString( "VTKRecordingOperations" ), // name (language-independant) + false ); // disable floatable toolbar - createActions( SUIT_Session::session()->activeApplication()->resourceMgr() ); + createActions( SUIT_Session::session()->resourceMgr() ); createToolBar(); SetEventDispatcher(myInteractor->GetDevice()); myInteractor->setBackgroundRole( QPalette::NoRole );//NoBackground myInteractor->setFocusPolicy(Qt::StrongFocus); myInteractor->setFocus(); + bool isSupportQuadBuffer = SUIT_Session::session()->resourceMgr()-> + booleanValue( "VTKViewer", "enable_quad_buffer_support", false ); + myInteractor->getRenderWindow()->SetStereoCapableWindow((int)isSupportQuadBuffer); setFocusProxy(myInteractor); myUpdateRateDlg = new SVTK_UpdateRateDlg( getAction( UpdateRate ), this, "SVTK_UpdateRateDlg" ); myNonIsometricDlg = new SVTK_NonIsometricDlg( getAction( NonIsometric ), this, "SVTK_NonIsometricDlg" ); myCubeAxesDlg = new SVTK_CubeAxesDlg( getAction( GraduatedAxes ), this, "SVTK_CubeAxesDlg" ); + myCubeAxesDlg->initialize(); mySetRotationPointDlg = new SVTK_SetRotationPointDlg ( getAction( ChangeRotationPointId ), this, "SVTK_SetRotationPointDlg" ); myViewParameterDlg = new SVTK_ViewParameterDlg ( getAction( ViewParametersId ), this, "SVTK_ViewParameterDlg" ); - SVTK_InteractorStyle* aStyle = SVTK_InteractorStyle::New(); - myInteractor->PushInteractorStyle(aStyle); - aStyle->Delete(); + myDefaultInteractorStyle = SVTK_InteractorStyle::New(); + myInteractor->PushInteractorStyle(myDefaultInteractorStyle); + myDefaultInteractorStyle->Delete(); myRecorder = SVTK_Recorder::New(); @@ -177,10 +219,41 @@ void SVTK_ViewWindow::Initialize(SVTK_ViewModelBase* theModel) setCentralWidget(myInteractor); + myAxesWidget = salomevtk::vtkPVAxesWidget::New(); + myAxesWidget->SetParentRenderer(aRenderer->GetDevice()); + myAxesWidget->SetViewport(0, 0, 0.25, 0.25); + myAxesWidget->SetInteractor(myInteractor->GetDevice()); + myAxesWidget->SetEnabled(1); + myAxesWidget->SetInteractive(0); + + salomevtk::vtkPVAxesActor* anAxesActor = myAxesWidget->GetAxesActor(); + anAxesActor->GetXAxisTipProperty()->SetColor( 1.0, 0.0, 0.0 ); + anAxesActor->GetXAxisShaftProperty()->SetColor( 1.0, 0.0, 0.0 ); + anAxesActor->GetXAxisLabelProperty()->SetColor( 1.0, 0.0, 0.0 ); + anAxesActor->GetYAxisTipProperty()->SetColor( 0.0, 1.0, 0.0 ); + anAxesActor->GetYAxisShaftProperty()->SetColor( 0.0, 1.0, 0.0 ); + anAxesActor->GetYAxisLabelProperty()->SetColor( 0.0, 1.0, 0.0 ); + anAxesActor->GetZAxisTipProperty()->SetColor( 0.0, 0.0, 1.0 ); + anAxesActor->GetZAxisShaftProperty()->SetColor( 0.0, 0.0, 1.0 ); + anAxesActor->GetZAxisLabelProperty()->SetColor( 0.0, 0.0, 1.0 ); + myView = new SVTK_View(this); Initialize(myView,theModel); + + + myEventCallbackCommand->SetClientData(this); + myEventCallbackCommand->SetCallback(SVTK_ViewWindow::ProcessEvents); + myEventCallbackCommand->Delete(); + + GetInteractor()->GetInteractorStyle()->AddObserver(SVTK::OperationFinished, + myEventCallbackCommand.GetPointer(), 0.0); + myKeyFreeInteractorStyle->AddObserver(SVTK::OperationFinished, + myEventCallbackCommand.GetPointer(), 0.0); + + myInteractor->getRenderWindow()->Render(); + setBackground( Qtx::BackgroundData( Qt::black ) ); // set default background onResetView(); } @@ -188,7 +261,7 @@ void SVTK_ViewWindow::Initialize(SVTK_ViewModelBase* theModel) To initialize #SVTK_ViewWindow instance */ void SVTK_ViewWindow::Initialize(SVTK_View* theView, - SVTK_ViewModelBase* theModel) + SVTK_ViewModelBase* theModel) { connect(theView,SIGNAL(KeyPressed(QKeyEvent*)), this,SLOT(onKeyPressed(QKeyEvent*)) ); @@ -205,14 +278,19 @@ void SVTK_ViewWindow::Initialize(SVTK_View* theView, connect(theView,SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,SIGNAL(contextMenuRequested(QContextMenuEvent *))); connect(theView,SIGNAL(selectionChanged()), - theModel,SLOT(onSelectionChanged())); + theModel,SLOT(onSelectionChanged())); + + connect( this, SIGNAL( transformed( SVTK_ViewWindow* ) ), SLOT( emitViewModified() ) ); } /*! Destructor */ SVTK_ViewWindow::~SVTK_ViewWindow() -{} +{ + myRecorder->Delete(); + myAxesWidget->Delete(); +} /*! @@ -278,6 +356,7 @@ void SVTK_ViewWindow::onFrontView() { GetRenderer()->OnFrontView(); Repaint(); + emit transformed( this ); } /*! @@ -287,6 +366,7 @@ void SVTK_ViewWindow::onBackView() { GetRenderer()->OnBackView(); Repaint(); + emit transformed( this ); } /*! @@ -296,6 +376,7 @@ void SVTK_ViewWindow::onTopView() { GetRenderer()->OnTopView(); Repaint(); + emit transformed( this ); } /*! @@ -305,6 +386,7 @@ void SVTK_ViewWindow::onBottomView() { GetRenderer()->OnBottomView(); Repaint(); + emit transformed( this ); } /*! @@ -314,6 +396,7 @@ void SVTK_ViewWindow::onLeftView() { GetRenderer()->OnLeftView(); Repaint(); + emit transformed( this ); } /*! @@ -323,6 +406,27 @@ void SVTK_ViewWindow::onRightView() { GetRenderer()->OnRightView(); Repaint(); + emit transformed( this ); +} + +/*! + \brief Rotate view 90 degrees clockwise +*/ +void SVTK_ViewWindow::onClockWiseView() +{ + GetRenderer()->onClockWiseView(); + Repaint(); + emit transformed( this ); +} + +/*! + \brief Rotate view 90 degrees conterclockwise +*/ +void SVTK_ViewWindow::onAntiClockWiseView() +{ + GetRenderer()->onAntiClockWiseView(); + Repaint(); + emit transformed( this ); } /*! @@ -332,6 +436,7 @@ void SVTK_ViewWindow::onResetView() { GetRenderer()->OnResetView(); Repaint(); + emit transformed( this ); } /*! @@ -341,6 +446,17 @@ void SVTK_ViewWindow::onFitAll() { GetRenderer()->OnFitAll(); Repaint(); + emit transformed( this ); +} + +/*! + Processes transformation "fit selection" +*/ +void SVTK_ViewWindow::onFitSelection() +{ + GetRenderer()->onFitSelection(); + Repaint(); + emit transformed( this ); } /*! @@ -383,8 +499,8 @@ void SVTK_ViewWindow::unHighlightAll() \param theIsUpdate - update current viewer */ void SVTK_ViewWindow::highlight(const Handle(SALOME_InteractiveObject)& theIO, - bool theIsHighlight, - bool theIsUpdate ) + bool theIsHighlight, + bool theIsUpdate ) { myView->highlight( theIO, theIsHighlight, theIsUpdate ); } @@ -422,7 +538,7 @@ Handle(SALOME_InteractiveObject) SVTK_ViewWindow::FindIObject(const char* theEnt \param theImmediatly - update viewer */ void SVTK_ViewWindow::Display(const Handle(SALOME_InteractiveObject)& theIO, - bool theImmediatly) + bool theImmediatly) { myView->Display(theIO,theImmediatly); } @@ -433,7 +549,7 @@ void SVTK_ViewWindow::Display(const Handle(SALOME_InteractiveObject)& theIO, \param theImmediatly - update viewer */ void SVTK_ViewWindow::Erase(const Handle(SALOME_InteractiveObject)& theIO, - bool theImmediatly) + bool theImmediatly) { myView->Erase(theIO,theImmediatly); } @@ -464,26 +580,167 @@ void SVTK_ViewWindow::EraseAll() } /*! - Sets background color + Sets background color [obsolete] \param color - new background color */ -void SVTK_ViewWindow::setBackgroundColor( const QColor& theColor ) +void SVTK_ViewWindow::setBackgroundColor( const QColor& c ) { - getRenderer()->SetBackground(theColor.red()/255.0, - theColor.green()/255.0, - theColor.blue()/255.0); + Qtx::BackgroundData bg = background(); + bg.setColor( c ); + setBackground( bg ); } /*! - \return background color of viewer + \return background color of viewer [obsolete] */ QColor SVTK_ViewWindow::backgroundColor() const { - vtkFloatingPointType aBackgroundColor[3]; - getRenderer()->GetBackground(aBackgroundColor); - return QColor(int(aBackgroundColor[0]*255), - int(aBackgroundColor[1]*255), - int(aBackgroundColor[2]*255)); + return background().color(); +} + +/*! + Sets background data + \param bgData - new background data +*/ +void SVTK_ViewWindow::setBackground( const Qtx::BackgroundData& bgData ) +{ + bool ok = false; + + if ( bgData.isValid() ) { + switch ( bgData.mode() ) { + case Qtx::ColorBackground: + { + QColor c = bgData.color(); + if ( c.isValid() ) { + // show solid-colored background + getRenderer()->SetTexturedBackground( false ); // cancel texture mode + getRenderer()->SetGradientBackground( false ); // cancel gradient mode + getRenderer()->SetBackground( c.red()/255.0, + c.green()/255.0, + c.blue()/255.0 ); // set background color + ok = true; + } + break; + } + case Qtx::SimpleGradientBackground: + { + QColor c1, c2; + int type = bgData.gradient( c1, c2 ); + if ( c1.isValid() ) + { + if ( !c2.isValid() ) + c2 = c1; + + // show two-color gradient background + getRenderer()->SetTexturedBackground( false ); // cancel texture mode + getRenderer()->SetGradientBackground( true ); // switch to gradient mode + + VTKViewer_OpenGLRenderer* aRenderer = + VTKViewer_OpenGLRenderer::SafeDownCast( getRenderer() ); + if( aRenderer ) + { + aRenderer->SetGradientType( type ); + aRenderer->SetBackground( c1.redF(), c1.greenF(), c1.blueF() ); + aRenderer->SetBackground2( c2.redF(), c2.greenF(), c2.blueF() ); + ok = true; + } + } + break; + } + case Qtx::CustomGradientBackground: + { + // NOT IMPLEMENTED YET + getRenderer()->SetTexturedBackground( false ); // cancel texture mode + getRenderer()->SetGradientBackground( false ); // cancel gradient mode + // ......... + break; + } + default: + break; + } + if ( bgData.isTextureShown() ) { + QString fileName; + int textureMode = bgData.texture( fileName ); + QFileInfo fi( fileName ); + if ( !fileName.isEmpty() && fi.exists() ) { + // read texture from file + QString extension = fi.suffix().toLower(); + vtkImageReader2* aReader = 0; + if ( extension == "jpg" || extension == "jpeg" ) + aReader = vtkJPEGReader::New(); + else if ( extension == "bmp" ) + aReader = vtkBMPReader::New(); + else if ( extension == "tif" || extension == "tiff" ) + aReader = vtkTIFFReader::New(); + else if ( extension == "png" ) + aReader = vtkPNGReader::New(); + else if ( extension == "mhd" || extension == "mha" ) + aReader = vtkMetaImageReader::New(); + if ( aReader ) { + // create texture + aReader->SetFileName( fi.absoluteFilePath().toLatin1().constData() ); + aReader->Update(); + VTKViewer_Texture* aTexture = VTKViewer_Texture::New(); + vtkImageMapToColors* aMap = 0; + vtkAlgorithmOutput* anOutput; + /* + // special processing for BMP reader + vtkBMPReader* aBMPReader = (vtkBMPReader*)aReader; + if ( aBMPReader ) { + // Special processing for BMP file + aBMPReader->SetAllow8BitBMP(1); + + aMap = vtkImageMapToColors::New(); + aMap->SetInputConnection( aBMPReader->GetOutputPort() ); + aMap->SetLookupTable( (vtkScalarsToColors*)aBMPReader->GetLookupTable() ); + aMap->SetOutputFormatToRGB(); + + anOutput = aMap->GetOutputPort(); + } + else { + } + */ + anOutput = aReader->GetOutputPort( 0 ); + aTexture->SetInputConnection( anOutput ); + // set texture mode + // VSR: Currently, VTK only supports Stretch mode, so below code will give + // the same results for all modes + switch ( textureMode ) { + case Qtx::TileTexture: + aTexture->SetPosition((int)VTKViewer_Texture::Tiled); + break; + case Qtx::StretchTexture: + aTexture->SetPosition((int)VTKViewer_Texture::Stretched); + break; + case Qtx::CenterTexture: + aTexture->SetPosition((int)VTKViewer_Texture::Centered); + default: + break; + } + // show textured background + getRenderer()->SetTexturedBackground( true ); + getRenderer()->SetBackgroundTexture( aTexture ); + + // clean-up resources + if ( aMap ) + aMap->Delete(); + aReader->Delete(); + aTexture->Delete(); + ok = true; + } + } + } + } + if ( ok ) + myBackground = bgData; +} + +/*! + \return background data of viewer +*/ +Qtx::BackgroundData SVTK_ViewWindow::background() const +{ + return myBackground; } @@ -541,6 +798,7 @@ void SVTK_ViewWindow::SetScale( double theScale[3] ) { GetRenderer()->SetScale( theScale ); Repaint(); + emit transformed( this ); } /*! @@ -562,9 +820,9 @@ bool SVTK_ViewWindow::isCubeAxesDisplayed() /*! Redirect the request to #SVTK_Renderer::OnViewTrihedron */ -void SVTK_ViewWindow::onViewTrihedron() +void SVTK_ViewWindow::onViewTrihedron(bool show) { - GetRenderer()->OnViewTrihedron(); + GetRenderer()->SetTrihedronVisibility(show); Repaint(); } @@ -596,20 +854,160 @@ SVTK_CubeAxesActor2D* SVTK_ViewWindow::GetCubeAxes() /*! \return trihedron size */ -vtkFloatingPointType SVTK_ViewWindow::GetTrihedronSize() const +double SVTK_ViewWindow::GetTrihedronSize() const { return GetRenderer()->GetTrihedronSize(); } /*! Sets projection mode - \param theMode - projection mode ( 0 - orthogonal, 1 - perspective ) + \param theMode - projection mode ( 0 - orthogonal, 1 - perspective, 2 - stereo ) */ void SVTK_ViewWindow::SetProjectionMode(const int theMode) { - activateProjectionMode( theMode ); + QtxAction* aParallelAction = dynamic_cast( toolMgr()->action( ParallelModeId ) ); + QtxAction* aProjectionAction = dynamic_cast( toolMgr()->action( ProjectionModeId ) ); + QtxAction* aStereoAction = dynamic_cast( toolMgr()->action( StereoModeId ) ); + + switch ( theMode ) { + case Parallel: + onProjectionMode( aParallelAction ); + break; + case Projection: + onProjectionMode( aProjectionAction ); + break; + case Stereo: + onStereoMode( true ); + break; + } + + // update action state if method is called outside + SVTK_Viewer* aViewer = dynamic_cast(myModel); + QtxAction* aSwitchZoomingStyle = dynamic_cast( toolMgr()->action( SwitchZoomingStyleId ) ); + if ( theMode == Parallel && !aParallelAction->isChecked() ) { + aParallelAction->setChecked( true ); + aSwitchZoomingStyle->setEnabled(true); + aStereoAction->setChecked( false ); + } + if ( theMode == Projection && !aProjectionAction->isChecked() ) { + aProjectionAction->setChecked( true ); + aSwitchZoomingStyle->setEnabled(false); + } + if ( theMode == Stereo ) { + aStereoAction->setChecked( true ); + if ( aParallelAction->isEnabled() ) { + aParallelAction->setEnabled( false ); + aParallelAction->setChecked( false ); + aStereoAction->setChecked( false ); + } + else { + aParallelAction->setEnabled( true ); + aStereoAction->setChecked( false ); + aParallelAction->setChecked( aViewer->projectionMode() == Parallel ); + } + if ( aProjectionAction->isEnabled() ) { + aProjectionAction->setEnabled( false ); + aProjectionAction->setChecked( true ); + if ( getRenderWindow()->GetStereoCapableWindow() == 1 && !isOpenGlStereoSupport() && + strcmp( "CrystalEyes", getRenderWindow()->GetStereoTypeAsString() ) == 0 && + toolMgr()->action( StereoModeId )->isChecked() ) { + SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) ); + } + } + else { + aProjectionAction->setEnabled( true ); + aStereoAction->setChecked( false ); + aProjectionAction->setChecked( aViewer->projectionMode() == Projection ); + onProjectionMode(); + } + } + else { + if ( !aParallelAction->isEnabled() ) + aParallelAction->setEnabled( true ); + if ( !aProjectionAction->isEnabled() ) + aProjectionAction->setEnabled( true ); + } +} + +/*! + Sets stereo type + \param theType - stereo type +*/ +void SVTK_ViewWindow::SetStereoType(const int theType) +{ + vtkRenderWindow* aWindow = getRenderWindow(); + switch (theType ) { + case CrystalEyes: + aWindow->SetStereoTypeToCrystalEyes(); + break; + case RedBlue: + aWindow->SetStereoTypeToRedBlue(); + break; + case Interlaced: + aWindow->SetStereoTypeToInterlaced(); + break; + case Left: + aWindow->SetStereoTypeToLeft(); + break; + case Right: + aWindow->SetStereoTypeToRight(); + break; + case Dresden: + aWindow->SetStereoTypeToDresden(); + break; + case Anaglyph: + aWindow->SetStereoTypeToAnaglyph(); + break; + case Checkerboard: + aWindow->SetStereoTypeToCheckerboard(); + break; + case SplitViewPortHorizontal: + aWindow->SetStereoTypeToSplitViewportHorizontal(); + break; + } } +/*! + Sets anaglyph filter + \param theFilter - anaglyph filter +*/ +void SVTK_ViewWindow::SetAnaglyphFilter(const int theFilter) +{ + vtkRenderWindow* aWindow = getRenderWindow(); + switch (theFilter ) { + case RedCyan: + aWindow->SetAnaglyphColorMask(4,3); + break; + case YellowBlue: + aWindow->SetAnaglyphColorMask(6,1); + break; + case GreenMagenta: + aWindow->SetAnaglyphColorMask(2,5); + break; + } +} + +/*! + Set support quad-buffered stereo + \param theEnable - enable/disable support quad-buffered stereo +*/ +void SVTK_ViewWindow::SetQuadBufferSupport(const bool theEnable) +{ + vtkRenderWindow* aWindow = getRenderWindow(); + aWindow->SetStereoCapableWindow((int)theEnable); +} + +/*! + \return OpenGl stereo support +*/ +bool SVTK_ViewWindow::isOpenGlStereoSupport() const +{ + GLboolean support[1]; + glGetBooleanv (GL_STEREO, support); + if ( support[0] ) + return true; + return false; +} /*! Set the gravity center as a focal point @@ -637,10 +1035,17 @@ void SVTK_ViewWindow::activateStartFocalPointSelection() void SVTK_ViewWindow::activateProjectionMode(int theMode) { + QtxAction* aParallelAction = dynamic_cast( toolMgr()->action( ParallelModeId ) ); + QtxAction* aProjectionAction = dynamic_cast( toolMgr()->action( ProjectionModeId ) ); if (theMode) - toolMgr()->action( ProjectionModeId )->setChecked( true ); + aParallelAction->setChecked( true ); else - toolMgr()->action( ParallelModeId )->setChecked( true ); + aProjectionAction->setChecked( true ); + + if ( !aParallelAction->isEnabled() ) + aParallelAction->setEnabled( true ); + if ( !aProjectionAction->isEnabled() ) + aProjectionAction->setEnabled( true ); } /*! @@ -652,6 +1057,49 @@ void SVTK_ViewWindow::SetInteractionStyle(const int theStyle) onSwitchInteractionStyle( theStyle==1 ); } +/*! + Sets actual zooming style + \param theStyle - type of zooming style ( 0 - standard, 1 - advanced (at cursor) ) +*/ +void SVTK_ViewWindow::SetZoomingStyle(const int theStyle) +{ + onSwitchZoomingStyle( theStyle==1 ); +} + +/*! + Set preselection mode. + \param theMode the mode to set (standard, dynamic or disabled) +*/ +void SVTK_ViewWindow::SetPreSelectionMode( Preselection_Mode theMode ) +{ + onSwitchPreSelectionMode( theMode ); +} + +/*! + Enables/disables selection. + \param theEnable if true - selection will be enabled +*/ +void SVTK_ViewWindow::SetSelectionEnabled( bool theEnable ) +{ + GetSelector()->SetSelectionEnabled( theEnable ); + QtxAction* a = getAction( EnableSelectionId ); + if ( a->isChecked() != theEnable) + a->setChecked( theEnable ); + QtxActionGroup* aPreselectionGroup = + dynamic_cast( getAction( PreselectionId ) ); + if ( aPreselectionGroup ) + aPreselectionGroup->setEnabled( theEnable ); + + // notify actors + vtkActorCollection *actors = getRenderer()->GetActors(); + for (int i = 0; i < actors->GetNumberOfItems(); ++i ) + if (VTKViewer_Actor *actor = dynamic_cast(actors->GetItemAsObject(i))) + { + cout << "actor " << actor << endl; + actor->EnableSelection( theEnable ); + } +} + /*! Switches "keyboard free" interaction style on/off */ @@ -664,8 +1112,8 @@ void SVTK_ViewWindow::onSwitchInteractionStyle(bool theOn) // keep the same style extensions SVTK_InteractorStyle* aStyle = (SVTK_InteractorStyle*)GetInteractorStyle(); if ( aStyle ) { - myKeyFreeInteractorStyle->SetControllerIncrement(aStyle->ControllerIncrement()); - myKeyFreeInteractorStyle->SetControllerOnKeyDown(aStyle->ControllerOnKeyDown()); + myKeyFreeInteractorStyle->SetControllerIncrement(aStyle->ControllerIncrement()); + myKeyFreeInteractorStyle->SetControllerOnKeyDown(aStyle->ControllerOnKeyDown()); } PushInteractorStyle(myKeyFreeInteractorStyle.GetPointer()); @@ -682,6 +1130,48 @@ void SVTK_ViewWindow::onSwitchInteractionStyle(bool theOn) if ( a->isChecked() != theOn ) a->setChecked( theOn ); } +/*! + Toogles advanced zooming style (relatively to the cursor position) on/off +*/ +void SVTK_ViewWindow::onSwitchZoomingStyle( bool theOn ) +{ + if( myDefaultInteractorStyle.GetPointer() ) + myDefaultInteractorStyle->SetAdvancedZoomingEnabled( theOn ); + if( myKeyFreeInteractorStyle.GetPointer() ) + myKeyFreeInteractorStyle->SetAdvancedZoomingEnabled( theOn ); + + // update action state if method is called outside + QtxAction* a = getAction( SwitchZoomingStyleId ); + if ( a->isChecked() != theOn ) + a->setChecked( theOn ); +} + +/*! + Switch preselection mode. + \param theMode the preselection mode +*/ +void SVTK_ViewWindow::onSwitchPreSelectionMode( int theMode ) +{ + GetSelector()->SetDynamicPreSelection( theMode == Dynamic_Preselection ); + GetSelector()->SetPreSelectionEnabled( theMode != Preselection_Disabled ); + + // update action state if method is called outside + QtxAction* a = getAction( StandardPreselectionId + theMode ); + if ( a && !a->isChecked() ) + a->setChecked( true ); +} + +/*! + Enables/disables selection. + \param theOn if true - selection will be enabled +*/ +void SVTK_ViewWindow::onEnableSelection( bool on ) +{ + SVTK_Viewer* aViewer = dynamic_cast(myModel); + if(aViewer) + aViewer->enableSelection(on); +} + /*! Sets incremental speed \param theValue - new incremental speed @@ -700,8 +1190,8 @@ void SVTK_ViewWindow::SetIncrementalSpeed(const int theValue, const int theMode) \param theBtn3 - spacemouse button for the "dominant combined switch" */ void SVTK_ViewWindow::SetSpacemouseButtons(const int theBtn1, - const int theBtn2, - const int theBtn3) + const int theBtn2, + const int theBtn3) { int val = theBtn1; myEventDispatcher->InvokeEvent(SVTK::SetSMDecreaseSpeedEvent, &val); @@ -716,7 +1206,7 @@ void SVTK_ViewWindow::SetSpacemouseButtons(const int theBtn1, \param theSize - new trihedron size \param theRelative - trihedron relativeness */ -void SVTK_ViewWindow::SetTrihedronSize(const vtkFloatingPointType theSize, const bool theRelative) +void SVTK_ViewWindow::SetTrihedronSize(const double theSize, const bool theRelative) { GetRenderer()->SetTrihedronSize(theSize, theRelative); Repaint(); @@ -747,6 +1237,15 @@ void SVTK_ViewWindow::onAdjustCubeAxes() GetRenderer()->OnAdjustCubeAxes(); } +void SVTK_ViewWindow::synchronize(SVTK_ViewWindow* otherViewWindow ) +{ + if ( otherViewWindow ) { + bool blocked = blockSignals( true ); + doSetVisualParameters( otherViewWindow->getVisualParameters(), true ); + blockSignals( blocked ); + } +} + /*! Emits key pressed */ @@ -799,9 +1298,10 @@ void SVTK_ViewWindow::onMouseDoubleClicked( QMouseEvent* event ) Redirect the request to #SVTK_Renderer::AddActor */ void SVTK_ViewWindow::AddActor( VTKViewer_Actor* theActor, - bool theUpdate ) + bool theUpdate, + bool theIsAdjustActors ) { - GetRenderer()->AddActor(theActor); + GetRenderer()->AddActor(theActor, theIsAdjustActors); if(theUpdate) Repaint(); emit actorAdded(theActor); @@ -811,9 +1311,14 @@ void SVTK_ViewWindow::AddActor( VTKViewer_Actor* theActor, Redirect the request to #SVTK_Renderer::RemoveActor */ void SVTK_ViewWindow::RemoveActor( VTKViewer_Actor* theActor, - bool theUpdate ) -{ - GetRenderer()->RemoveActor(theActor); + bool theUpdate, + bool theIsAdjustActors ) +{ + GetRenderer()->RemoveActor(theActor, theIsAdjustActors); + if ( myDefaultInteractorStyle ) + myDefaultInteractorStyle->FreeActors(); + if ( myKeyFreeInteractorStyle ) + myKeyFreeInteractorStyle->FreeActors(); if(theUpdate) Repaint(); emit actorRemoved(theActor); @@ -826,6 +1331,33 @@ QImage SVTK_ViewWindow::dumpViewContent() int aWidth = aSize[0]; int aHeight = aSize[1]; +#ifndef DISABLE_GLVIEWER + OpenGLUtils_FrameBuffer aFrameBuffer; + if( aFrameBuffer.init( aWidth, aHeight ) ) + { + glPushAttrib( GL_VIEWPORT_BIT ); + glViewport( 0, 0, aWidth, aHeight ); + aFrameBuffer.bind(); + + // draw scene + aWindow->Render(); + + aFrameBuffer.unbind(); + glPopAttrib(); + + QImage anImage( aWidth, aHeight, QImage::Format_RGB32 ); + + aFrameBuffer.bind(); + glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() ); + aFrameBuffer.unbind(); + + anImage = anImage.rgbSwapped(); + anImage = anImage.mirrored(); + return anImage; + } +#endif + + // if frame buffers are unsupported, use old functionality unsigned char *aData = aWindow->GetRGBACharPixelData( 0, 0, aWidth-1, aHeight-1, 0 ); @@ -844,6 +1376,7 @@ QImage SVTK_ViewWindow::dumpView() if( myDumpImage.isNull() ) return dumpViewContent(); + RefreshDumpImage(); return myDumpImage; } @@ -857,33 +1390,43 @@ bool SVTK_ViewWindow::dumpViewToFormat( const QImage& img, const QString& fileNa if ( format != "PS" && format != "EPS" && format != "PDF" ) return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format ); - SUIT_OverrideCursor wc; - - vtkGL2PSExporter *anExporter = vtkGL2PSExporter::New(); - anExporter->SetRenderWindow(getRenderWindow()); - - if ( format == "PS" ) { - anExporter->SetFileFormatToPS(); - anExporter->CompressOff(); - } - - if ( format == "EPS" ) { - anExporter->SetFileFormatToEPS(); - anExporter->CompressOff(); - } + SVTK_PsOptionsDlg* optionsDlg = new SVTK_PsOptionsDlg(this); + if ( optionsDlg->exec() == QDialog::Accepted ) { + SUIT_OverrideCursor wc; + + vtkGL2PSExporter *anExporter = vtkGL2PSExporter::New(); + anExporter->SetRenderWindow(getRenderWindow()); + + // Set options + anExporter->SetLineWidthFactor(optionsDlg->getLineFactor()); + anExporter->SetPointSizeFactor(optionsDlg->getPointFactor()); + anExporter->SetSort((vtkGL2PSExporter::SortScheme)optionsDlg->getSortType()); + anExporter->SetWrite3DPropsAsRasterImage((int)optionsDlg->isRasterize3D()); + anExporter->SetPS3Shading((int)optionsDlg->isPs3Shading()); + + if ( format == "PS" ) { + anExporter->SetFileFormatToPS(); + anExporter->CompressOff(); + } + + if ( format == "EPS" ) { + anExporter->SetFileFormatToEPS(); + anExporter->CompressOff(); + } - if ( format == "PDF" ) { - anExporter->SetFileFormatToPDF(); + if ( format == "PDF" ) { + anExporter->SetFileFormatToPDF(); + } + + QString aFilePrefix(fileName); + QString anExtension(SUIT_Tools::extension(fileName)); + aFilePrefix.truncate(aFilePrefix.length() - 1 - anExtension.length()); + anExporter->SetFilePrefix(aFilePrefix.toLatin1().data()); + anExporter->Write(); + anExporter->Delete(); } - - QString aFilePrefix(fileName); - QString anExtension(SUIT_Tools::extension(fileName)); - aFilePrefix.truncate(aFilePrefix.length() - 1 - anExtension.length()); - anExporter->SetFilePrefix(aFilePrefix.toLatin1().data()); - anExporter->Write(); - anExporter->Delete(); - - return true; + delete optionsDlg; + return true; } /*! @@ -898,9 +1441,9 @@ void SVTK_ViewWindow::RefreshDumpImage() Redirect the request to #SVTK_Renderer::SetSelectionProp */ void SVTK_ViewWindow::SetSelectionProp(const double& theRed, - const double& theGreen, - const double& theBlue, - const int& theWidth) + const double& theGreen, + const double& theBlue, + const int& theWidth) { myView->SetSelectionProp(theRed,theGreen,theBlue,theWidth); } @@ -909,9 +1452,9 @@ void SVTK_ViewWindow::SetSelectionProp(const double& theRed, Redirect the request to #SVTK_Renderer::SetSelectionProp */ void SVTK_ViewWindow::SetPreselectionProp(const double& theRed, - const double& theGreen, - const double& theBlue, - const int& theWidth) + const double& theGreen, + const double& theBlue, + const int& theWidth) { myView->SetPreselectionProp(theRed,theGreen,theBlue,theWidth); } @@ -920,12 +1463,28 @@ void SVTK_ViewWindow::SetPreselectionProp(const double& theRed, Redirect the request to #SVTK_Renderer::SetSelectionTolerance */ void SVTK_ViewWindow::SetSelectionTolerance(const double& theTolNodes, - const double& theTolItems, - const double& theTolObjects) + const double& theTolItems, + const double& theTolObjects) { myView->SetSelectionTolerance(theTolNodes, theTolItems, theTolObjects); } +/*! + Get visibility status of the static trihedron +*/ +bool SVTK_ViewWindow::IsStaticTrihedronVisible() const +{ + return (bool)myAxesWidget->GetEnabled(); +} + +/*! + Set visibility status of the static trihedron +*/ +void SVTK_ViewWindow::SetStaticTrihedronVisible( const bool theIsVisible ) +{ + myAxesWidget->SetEnabled( (int)theIsVisible ); +} + /*! Performs action \param accelAction - action @@ -968,7 +1527,7 @@ void getGradAxisVisualParams( QXmlStreamWriter& writer, vtkAxisActor2D* actor, Q // Name bool isVisible = actor->GetTitleVisibility(); QString title ( actor->GetTitle() ); - vtkFloatingPointType color[ 3 ]; + double color[ 3 ]; int font = VTK_ARIAL; int bold = 0; int italic = 0; @@ -1002,7 +1561,7 @@ void getGradAxisVisualParams( QXmlStreamWriter& writer, vtkAxisActor2D* actor, Q writer.writeEndElement(); //params.sprintf( "* Graduated Axis: * Name *%u*%s*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible, - // title.toLatin1().data(), color[0], color[1], color[2], font, bold, italic, shadow ); + // title.toLatin1().data(), color[0], color[1], color[2], font, bold, italic, shadow ); // Labels isVisible = actor->GetLabelVisibility(); @@ -1039,7 +1598,7 @@ void getGradAxisVisualParams( QXmlStreamWriter& writer, vtkAxisActor2D* actor, Q writer.writeEndElement(); writer.writeEndElement(); // params += QString().sprintf( "* Labels *%u*%u*%u*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible, labels, offset, - // color[0], color[1], color[2], font, bold, italic, shadow ); + // color[0], color[1], color[2], font, bold, italic, shadow ); // Tick marks isVisible = actor->GetTickVisibility(); @@ -1082,7 +1641,7 @@ void setGradAxisVisualParams(QXmlStreamReader& reader, vtkAxisActor2D* actor) // Read title color aAttr = reader.attributes(); - vtkFloatingPointType color[3]; + double color[3]; color[0] = aAttr.value("R").toString().toDouble(); color[1] = aAttr.value("G").toString().toDouble(); color[2] = aAttr.value("B").toString().toDouble(); @@ -1164,7 +1723,7 @@ void setGradAxisVisualParams( vtkAxisActor2D* actor, const QString& params ) // retrieve and set name parameters bool isVisible = paramsLst[2].toUShort(); QString title = paramsLst[3]; - vtkFloatingPointType color[3]; + double color[3]; color[0] = paramsLst[4].toDouble(); color[1] = paramsLst[5].toDouble(); color[2] = paramsLst[6].toDouble(); @@ -1281,6 +1840,10 @@ QString SVTK_ViewWindow::getVisualParameters() aWriter.writeAttribute("Size", QString::number(GetTrihedronSize())); aWriter.writeEndElement(); + aWriter.writeStartElement("Background"); + aWriter.writeAttribute("Value", QString( "%1" ).arg( Qtx::backgroundToString(background()) )); + aWriter.writeEndElement(); + aWriter.writeEndElement(); aWriter.writeEndDocument(); @@ -1306,8 +1869,9 @@ void SVTK_ViewWindow::setVisualParameters( const QString& parameters ) /*! The method restores visual parameters of this view from a formated string */ -void SVTK_ViewWindow::doSetVisualParameters( const QString& parameters ) +void SVTK_ViewWindow::doSetVisualParameters( const QString& parameters, bool baseParamsOnly ) { + double pos[3], focalPnt[3], viewUp[3], parScale, scale[3]; QXmlStreamReader aReader(parameters); @@ -1318,47 +1882,64 @@ void SVTK_ViewWindow::doSetVisualParameters( const QString& parameters ) if (aReader.isStartElement()) { QXmlStreamAttributes aAttr = aReader.attributes(); //printf("### Name = %s\n", qPrintable(aReader.name().toString())); - if (aReader.name() == "Position") { - pos[0] = aAttr.value("X").toString().toDouble(); - pos[1] = aAttr.value("Y").toString().toDouble(); - pos[2] = aAttr.value("Z").toString().toDouble(); - //printf("#### Position %f; %f; %f\n", pos[0], pos[1], pos[2]); - } else if (aReader.name() == "FocalPoint") { - focalPnt[0] = aAttr.value("X").toString().toDouble(); - focalPnt[1] = aAttr.value("Y").toString().toDouble(); - focalPnt[2] = aAttr.value("Z").toString().toDouble(); - //printf("#### FocalPoint %f; %f; %f\n", focalPnt[0], focalPnt[1], focalPnt[2]); - } else if (aReader.name() == "ViewUp") { - viewUp[0] = aAttr.value("X").toString().toDouble(); - viewUp[1] = aAttr.value("Y").toString().toDouble(); - viewUp[2] = aAttr.value("Z").toString().toDouble(); - //printf("#### ViewUp %f; %f; %f\n", viewUp[0], viewUp[1], viewUp[2]); - } else if (aReader.name() == "ViewScale") { - parScale = aAttr.value("Parallel").toString().toDouble(); - scale[0] = aAttr.value("X").toString().toDouble(); - scale[1] = aAttr.value("Y").toString().toDouble(); - scale[2] = aAttr.value("Z").toString().toDouble(); - //printf("#### ViewScale %f; %f; %f\n", scale[0], scale[1], scale[2]); - } else if (aReader.name() == "DisplayCubeAxis") { - if (aAttr.value("Show") == "0") - gradAxesActor->VisibilityOff(); - else - gradAxesActor->VisibilityOn(); - } else if (aReader.name() == "GraduatedAxis") { - if(aAttr.value("Axis") == "X") - setGradAxisVisualParams(aReader, gradAxesActor->GetXAxisActor2D()); - else if(aAttr.value("Axis") == "Y") - setGradAxisVisualParams(aReader, gradAxesActor->GetYAxisActor2D()); - else if(aAttr.value("Axis") == "Z") - setGradAxisVisualParams(aReader, gradAxesActor->GetZAxisActor2D()); - } else if (aReader.name() == "Trihedron") { - if (aAttr.value("isShown") == "0") - GetTrihedron()->VisibilityOff(); - else - GetTrihedron()->VisibilityOn(); - SetTrihedronSize(aAttr.value("Size").toString().toDouble()); + if (aReader.name() == "Position") { + pos[0] = aAttr.value("X").toString().toDouble(); + pos[1] = aAttr.value("Y").toString().toDouble(); + pos[2] = aAttr.value("Z").toString().toDouble(); + //printf("#### Position %f; %f; %f\n", pos[0], pos[1], pos[2]); + } + else if (aReader.name() == "FocalPoint") { + focalPnt[0] = aAttr.value("X").toString().toDouble(); + focalPnt[1] = aAttr.value("Y").toString().toDouble(); + focalPnt[2] = aAttr.value("Z").toString().toDouble(); + //printf("#### FocalPoint %f; %f; %f\n", focalPnt[0], focalPnt[1], focalPnt[2]); + } + else if (aReader.name() == "ViewUp") { + viewUp[0] = aAttr.value("X").toString().toDouble(); + viewUp[1] = aAttr.value("Y").toString().toDouble(); + viewUp[2] = aAttr.value("Z").toString().toDouble(); + //printf("#### ViewUp %f; %f; %f\n", viewUp[0], viewUp[1], viewUp[2]); + } + else if (aReader.name() == "ViewScale") { + parScale = aAttr.value("Parallel").toString().toDouble(); + scale[0] = aAttr.value("X").toString().toDouble(); + scale[1] = aAttr.value("Y").toString().toDouble(); + scale[2] = aAttr.value("Z").toString().toDouble(); + //printf("#### ViewScale %f; %f; %f\n", scale[0], scale[1], scale[2]); + } + else if (aReader.name() == "DisplayCubeAxis") { + if ( !baseParamsOnly ) { + if (aAttr.value("Show") == "0") + gradAxesActor->VisibilityOff(); + else + gradAxesActor->VisibilityOn(); + } + } + else if (aReader.name() == "GraduatedAxis") { + if ( !baseParamsOnly ) { + if(aAttr.value("Axis") == "X") + setGradAxisVisualParams(aReader, gradAxesActor->GetXAxisActor2D()); + else if(aAttr.value("Axis") == "Y") + setGradAxisVisualParams(aReader, gradAxesActor->GetYAxisActor2D()); + else if(aAttr.value("Axis") == "Z") + setGradAxisVisualParams(aReader, gradAxesActor->GetZAxisActor2D()); + } + } + else if (aReader.name() == "Trihedron") { + if ( !baseParamsOnly ) { + if (aAttr.value("isShown") == "0") + GetTrihedron()->VisibilityOff(); + else + GetTrihedron()->VisibilityOn(); + SetTrihedronSize(aAttr.value("Size").toString().toDouble()); + } + } + else if (aReader.name() == "Background") { + if ( !baseParamsOnly ) { + setBackground( Qtx::stringToBackground( aAttr.value("Value").toString() ) ); + } } - } + } } if (!aReader.hasError()) { vtkCamera* camera = getRenderer()->GetActiveCamera(); @@ -1366,8 +1947,10 @@ void SVTK_ViewWindow::doSetVisualParameters( const QString& parameters ) camera->SetFocalPoint( focalPnt ); camera->SetViewUp( viewUp ); camera->SetParallelScale( parScale ); - SetScale( scale ); - } else { + GetRenderer()->SetScale( scale ); + //SetScale( scale ); + } + else { QStringList paramsLst = parameters.split( '*' ); if ( paramsLst.size() >= nNormalParams ) { // 'reading' list of parameters @@ -1391,32 +1974,37 @@ void SVTK_ViewWindow::doSetVisualParameters( const QString& parameters ) camera->SetFocalPoint( focalPnt ); camera->SetViewUp( viewUp ); camera->SetParallelScale( parScale ); - SetScale( scale ); + GetRenderer()->SetScale( scale ); + //SetScale( scale ); // apply graduated axes parameters - SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes(); - if ( gradAxesActor && paramsLst.size() == nAllParams ) { - int i = nNormalParams+1, j = i + nGradAxisParams - 1; - ::setGradAxisVisualParams( gradAxesActor->GetXAxisActor2D(), parameters.section( '*', i, j ) ); - i = j + 1; j += nGradAxisParams; - ::setGradAxisVisualParams( gradAxesActor->GetYAxisActor2D(), parameters.section( '*', i, j ) ); - i = j + 1; j += nGradAxisParams; - ::setGradAxisVisualParams( gradAxesActor->GetZAxisActor2D(), parameters.section( '*', i, j ) ); - - if ( paramsLst[13].toUShort() ) - gradAxesActor->VisibilityOn(); - else - gradAxesActor->VisibilityOff(); - } else if ( paramsLst.size() == nAllParams ) { - if ( paramsLst[90].toUShort() ) - GetTrihedron()->VisibilityOn(); - else - GetTrihedron()->VisibilityOff(); - - SetTrihedronSize(paramsLst[91].toDouble()); + if ( !baseParamsOnly ) { + SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes(); + if ( gradAxesActor && paramsLst.size() == nAllParams ) { + int i = nNormalParams+1, j = i + nGradAxisParams - 1; + ::setGradAxisVisualParams( gradAxesActor->GetXAxisActor2D(), parameters.section( '*', i, j ) ); + i = j + 1; j += nGradAxisParams; + ::setGradAxisVisualParams( gradAxesActor->GetYAxisActor2D(), parameters.section( '*', i, j ) ); + i = j + 1; j += nGradAxisParams; + ::setGradAxisVisualParams( gradAxesActor->GetZAxisActor2D(), parameters.section( '*', i, j ) ); + + if ( paramsLst[13].toUShort() ) + gradAxesActor->VisibilityOn(); + else + gradAxesActor->VisibilityOff(); + } + else if ( paramsLst.size() == nAllParams ) { + if ( paramsLst[90].toUShort() ) + GetTrihedron()->VisibilityOn(); + else + GetTrihedron()->VisibilityOff(); + + SetTrihedronSize(paramsLst[91].toDouble()); + } } } } + Repaint(); } @@ -1467,21 +2055,81 @@ void SVTK_ViewWindow::activateSetRotationSelected(void* theData) } /*! - Set the point selected by user as a rotation point + Set the gravity center of element selected by user as a rotation point */ -void SVTK_ViewWindow::activateStartPointSelection() +void SVTK_ViewWindow::activateStartPointSelection( Selection_Mode theSelectionMode ) { + SetSelectionMode( theSelectionMode ); myEventDispatcher->InvokeEvent(SVTK::StartPointSelection,0); } /*! - Set the view projection mode: orthogonal or perspective + \brief Set the given projection mode. + + Set the given projection mode: Orthographic or Perspective. */ -void SVTK_ViewWindow::onPerspectiveMode() +void SVTK_ViewWindow::onProjectionMode( QAction* theAction ) { + int aMode = Parallel; + if (theAction == toolMgr()->action( ProjectionModeId )) + aMode = Projection; + SVTK_Viewer* aViewer = dynamic_cast(myModel); + aViewer->setProjectionMode(aMode); + bool anIsParallelMode = (aMode == Parallel); vtkCamera* aCamera = getRenderer()->GetActiveCamera(); - aCamera->SetParallelProjection(toolMgr()->action( ParallelModeId )->isChecked()); + aCamera->SetParallelProjection(anIsParallelMode); GetInteractor()->GetDevice()->CreateTimer(VTKI_TIMER_FIRST); + getRenderWindow()->SetStereoRender(0); + Repaint(); +} + +/*! + \brief Sets Stereo projection mode. + + Sets Stereo projection mode. +*/ +void SVTK_ViewWindow::onStereoMode( bool activate ) +{ + if (activate) { + toolMgr()->action( ProjectionModeId )->setChecked(true); + vtkCamera* aCamera = getRenderer()->GetActiveCamera(); + aCamera->SetParallelProjection(false); + toolMgr()->action( ProjectionModeId )->actionGroup()->setEnabled(false); + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + SetStereoType( aResMgr->integerValue( "VTKViewer", "stereo_type", 0 ) ); + getRenderWindow()->SetStereoRender(1); + Repaint(); + } + else { + toolMgr()->action( ProjectionModeId )->actionGroup()->setEnabled(true); + SVTK_Viewer* aViewer = dynamic_cast(myModel); + if (aViewer->projectionMode() == Parallel) { + toolMgr()->action( ParallelModeId )->setChecked(true); + onProjectionMode(toolMgr()->action( ParallelModeId )); + } + else if (aViewer->projectionMode() == Projection) { + toolMgr()->action( ProjectionModeId )->setChecked(true); + onProjectionMode(toolMgr()->action( ProjectionModeId )); + } + } + if ( getRenderWindow()->GetStereoCapableWindow() == 1 && !isOpenGlStereoSupport() && + strcmp( "CrystalEyes", getRenderWindow()->GetStereoTypeAsString() ) == 0 && + toolMgr()->action( StereoModeId )->isChecked() ) + SUIT_MessageBox::warning( 0, tr( "WRN_WARNING" ), tr( "WRN_SUPPORT_QUAD_BUFFER" ) ); +} + +/*! + Set the view projection mode: orthogonal or perspective +*/ +void SVTK_ViewWindow::onProjectionMode() +{ + if (toolMgr()->action( ParallelModeId )->isChecked()) + SetProjectionMode( Parallel); + if (toolMgr()->action( ProjectionModeId )->isChecked()) + SetProjectionMode( Projection); + if (toolMgr()->action( StereoModeId )->isChecked()) + SetProjectionMode( Stereo); + emit transformed( this ); } void SVTK_ViewWindow::SetEventDispatcher(vtkObject* theDispatcher) @@ -1499,56 +2147,64 @@ void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr) // Dump view anAction = new QtxAction(tr("MNU_DUMP_VIEW"), - theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ), - tr( "MNU_DUMP_VIEW" ), 0, this); + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ), + tr( "MNU_DUMP_VIEW" ), 0, this); anAction->setStatusTip(tr("DSC_DUMP_VIEW")); - connect(anAction, SIGNAL(activated()), this, SLOT(onDumpView())); + connect(anAction, SIGNAL(triggered()), this, SLOT(onDumpView())); mgr->registerAction( anAction, DumpId ); // FitAll anAction = new QtxAction(tr("MNU_FITALL"), - theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ), - tr( "MNU_FITALL" ), 0, this); + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ), + tr( "MNU_FITALL" ), 0, this); anAction->setStatusTip(tr("DSC_FITALL")); - connect(anAction, SIGNAL(activated()), this, SLOT(onFitAll())); + connect(anAction, SIGNAL(triggered()), this, SLOT(onFitAll())); mgr->registerAction( anAction, FitAllId ); // FitRect anAction = new QtxAction(tr("MNU_FITRECT"), - theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ), - tr( "MNU_FITRECT" ), 0, this); + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ), + tr( "MNU_FITRECT" ), 0, this); anAction->setStatusTip(tr("DSC_FITRECT")); - connect(anAction, SIGNAL(activated()), this, SLOT(activateWindowFit())); + connect(anAction, SIGNAL(triggered()), this, SLOT(activateWindowFit())); mgr->registerAction( anAction, FitRectId ); + // FitSelection + anAction = new QtxAction(tr("MNU_FITSELECTION"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITSELECTION" ) ), + tr( "MNU_FITSELECTION" ), 0, this); + anAction->setStatusTip(tr("DSC_FITSELECTION")); + connect(anAction, SIGNAL(triggered()), this, SLOT(onFitSelection())); + mgr->registerAction( anAction, FitSelectionId ); + // Zoom anAction = new QtxAction(tr("MNU_ZOOM_VIEW"), - theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ), - tr( "MNU_ZOOM_VIEW" ), 0, this); + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ), + tr( "MNU_ZOOM_VIEW" ), 0, this); anAction->setStatusTip(tr("DSC_ZOOM_VIEW")); - connect(anAction, SIGNAL(activated()), this, SLOT(activateZoom())); + connect(anAction, SIGNAL(triggered()), this, SLOT(activateZoom())); mgr->registerAction( anAction, ZoomId ); // Panning anAction = new QtxAction(tr("MNU_PAN_VIEW"), - theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ), - tr( "MNU_PAN_VIEW" ), 0, this); + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ), + tr( "MNU_PAN_VIEW" ), 0, this); anAction->setStatusTip(tr("DSC_PAN_VIEW")); - connect(anAction, SIGNAL(activated()), this, SLOT(activatePanning())); + connect(anAction, SIGNAL(triggered()), this, SLOT(activatePanning())); mgr->registerAction( anAction, PanId ); // Global Panning anAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), - theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ), - tr( "MNU_GLOBALPAN_VIEW" ), 0, this); + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ), + tr( "MNU_GLOBALPAN_VIEW" ), 0, this); anAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW")); - connect(anAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning())); + connect(anAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning())); mgr->registerAction( anAction, GlobalPanId ); // Change rotation point anAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), - theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_ROTATION_POINT" ) ), - tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this); + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_ROTATION_POINT" ) ), + tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this); anAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW")); anAction->setCheckable(true); connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onChangeRotationPoint(bool))); @@ -1556,75 +2212,103 @@ void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr) // Rotation anAction = new QtxAction(tr("MNU_ROTATE_VIEW"), - theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ), - tr( "MNU_ROTATE_VIEW" ), 0, this); + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ), + tr( "MNU_ROTATE_VIEW" ), 0, this); anAction->setStatusTip(tr("DSC_ROTATE_VIEW")); - connect(anAction, SIGNAL(activated()), this, SLOT(activateRotation())); + connect(anAction, SIGNAL(triggered()), this, SLOT(activateRotation())); mgr->registerAction( anAction, RotationId ); // Projections anAction = new QtxAction(tr("MNU_FRONT_VIEW"), - theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ), - tr( "MNU_FRONT_VIEW" ), 0, this); + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ), + tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view"); anAction->setStatusTip(tr("DSC_FRONT_VIEW")); - connect(anAction, SIGNAL(activated()), this, SLOT(onFrontView())); + connect(anAction, SIGNAL(triggered()), this, SLOT(onFrontView())); + this->addAction(anAction); mgr->registerAction( anAction, FrontId ); anAction = new QtxAction(tr("MNU_BACK_VIEW"), - theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ), - tr( "MNU_BACK_VIEW" ), 0, this); + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ), + tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view"); anAction->setStatusTip(tr("DSC_BACK_VIEW")); - connect(anAction, SIGNAL(activated()), this, SLOT(onBackView())); + connect(anAction, SIGNAL(triggered()), this, SLOT(onBackView())); + this->addAction(anAction); mgr->registerAction( anAction, BackId ); anAction = new QtxAction(tr("MNU_TOP_VIEW"), - theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ), - tr( "MNU_TOP_VIEW" ), 0, this); + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ), + tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view"); anAction->setStatusTip(tr("DSC_TOP_VIEW")); - connect(anAction, SIGNAL(activated()), this, SLOT(onTopView())); + connect(anAction, SIGNAL(triggered()), this, SLOT(onTopView())); + this->addAction(anAction); mgr->registerAction( anAction, TopId ); anAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), - theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ), - tr( "MNU_BOTTOM_VIEW" ), 0, this); + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ), + tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view"); anAction->setStatusTip(tr("DSC_BOTTOM_VIEW")); - connect(anAction, SIGNAL(activated()), this, SLOT(onBottomView())); + connect(anAction, SIGNAL(triggered()), this, SLOT(onBottomView())); + this->addAction(anAction); mgr->registerAction( anAction, BottomId ); anAction = new QtxAction(tr("MNU_LEFT_VIEW"), - theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ), - tr( "MNU_LEFT_VIEW" ), 0, this); + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ), + tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view"); anAction->setStatusTip(tr("DSC_LEFT_VIEW")); - connect(anAction, SIGNAL(activated()), this, SLOT(onLeftView())); + connect(anAction, SIGNAL(triggered()), this, SLOT(onLeftView())); + this->addAction(anAction); mgr->registerAction( anAction, LeftId ); anAction = new QtxAction(tr("MNU_RIGHT_VIEW"), - theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ), - tr( "MNU_RIGHT_VIEW" ), 0, this); + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ), + tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view"); anAction->setStatusTip(tr("DSC_RIGHT_VIEW")); - connect(anAction, SIGNAL(activated()), this, SLOT(onRightView())); + connect(anAction, SIGNAL(triggered()), this, SLOT(onRightView())); + this->addAction(anAction); mgr->registerAction( anAction, RightId ); + // rotate anticlockwise + anAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ANTICLOCKWISE" ) ), + tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise"); + anAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW")); + connect(anAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView())); + this->addAction(anAction); + mgr->registerAction( anAction, AntiClockWiseId ); + + // rotate clockwise + anAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_CLOCKWISE" ) ), + tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise"); + anAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW")); + connect(anAction, SIGNAL(triggered()), this, SLOT(onClockWiseView())); + this->addAction(anAction); + mgr->registerAction( anAction, ClockWiseId ); + // Reset anAction = new QtxAction(tr("MNU_RESET_VIEW"), - theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ), - tr( "MNU_RESET_VIEW" ), 0, this); + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ), + tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view"); anAction->setStatusTip(tr("DSC_RESET_VIEW")); - connect(anAction, SIGNAL(activated()), this, SLOT(onResetView())); + connect(anAction, SIGNAL(triggered()), this, SLOT(onResetView())); + this->addAction(anAction); mgr->registerAction( anAction, ResetId ); // onViewTrihedron: Shows - Hides Trihedron anAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"), - theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ), - tr( "MNU_SHOW_TRIHEDRON" ), 0, this); + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ), + tr( "MNU_SHOW_TRIHEDRON" ), 0, this); + anAction->setCheckable( true ); + anAction->setChecked( true ); + anAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON")); - connect(anAction, SIGNAL(activated()), this, SLOT(onViewTrihedron())); + connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onViewTrihedron(bool))); mgr->registerAction( anAction, ViewTrihedronId ); // onNonIsometric: Manage non-isometric params anAction = new QtxAction(tr("MNU_SVTK_SCALING"), - theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SCALING" ) ), - tr( "MNU_SVTK_SCALING" ), 0, this); + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SCALING" ) ), + tr( "MNU_SVTK_SCALING" ), 0, this); anAction->setStatusTip(tr("DSC_SVTK_SCALING")); anAction->setCheckable(true); connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onNonIsometric(bool))); @@ -1632,8 +2316,8 @@ void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr) // onGraduatedAxes: Manage graduated axes params anAction = new QtxAction(tr("MNU_SVTK_GRADUATED_AXES"), - theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_GRADUATED_AXES" ) ), - tr( "MNU_SVTK_GRADUATED_AXES" ), 0, this); + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_GRADUATED_AXES" ) ), + tr( "MNU_SVTK_GRADUATED_AXES" ), 0, this); anAction->setStatusTip(tr("DSC_SVTK_GRADUATED_AXES")); anAction->setCheckable(true); connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onGraduatedAxes(bool))); @@ -1641,8 +2325,8 @@ void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr) // onGraduatedAxes: Manage graduated axes params anAction = new QtxAction(tr("MNU_SVTK_UPDATE_RATE"), - theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_UPDATE_RATE" ) ), - tr( "MNU_SVTK_UPDATE_RATE" ), 0, this); + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_UPDATE_RATE" ) ), + tr( "MNU_SVTK_UPDATE_RATE" ), 0, this); anAction->setStatusTip(tr("DSC_SVTK_UPDATE_RATE")); anAction->setCheckable(true); connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onUpdateRate(bool))); @@ -1650,55 +2334,120 @@ void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr) // Set perspective mode group anAction = new QtxAction(tr("MNU_SVTK_PARALLEL_MODE"), - theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARALLEL" ) ), - tr( "MNU_SVTK_PARALLEL_MODE" ), 0, this); + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARALLEL" ) ), + tr( "MNU_SVTK_PARALLEL_MODE" ), 0, this); anAction->setStatusTip(tr("DSC_SVTK_PARALLEL_MODE")); anAction->setCheckable(true); - connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onPerspectiveMode())); mgr->registerAction( anAction, ParallelModeId ); anAction = new QtxAction(tr("MNU_SVTK_PERSPECTIVE_MODE"), - theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PERSPECTIVE" ) ), - tr( "MNU_SVTK_PERSPECTIVE_MODE" ), 0, this); + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PERSPECTIVE" ) ), + tr( "MNU_SVTK_PERSPECTIVE_MODE" ), 0, this); anAction->setStatusTip(tr("DSC_SVTK_PERSPECTIVE_MODE")); anAction->setCheckable(true); - connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onPerspectiveMode())); mgr->registerAction( anAction, ProjectionModeId ); + anAction = new QtxAction(tr("MNU_SVTK_STEREO_MODE"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_STEREO" ) ), + tr( "MNU_SVTK_STEREO_MODE" ), 0, this); + anAction->setStatusTip(tr("DSC_SVTK_STEREO_MODE")); + anAction->setCheckable(true); + connect(anAction, SIGNAL(triggered(bool)), this, SLOT(onStereoMode(bool))); + mgr->registerAction( anAction, StereoModeId ); + QActionGroup* aPerspectiveGroup = new QActionGroup( this ); aPerspectiveGroup->addAction( mgr->action( ParallelModeId ) ); aPerspectiveGroup->addAction( mgr->action( ProjectionModeId ) ); + connect(aPerspectiveGroup, SIGNAL(triggered(QAction*)), this, SLOT(onProjectionMode(QAction*))); // View Parameters anAction = new QtxAction(tr("MNU_VIEWPARAMETERS_VIEW"), - theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARAMETERS" ) ), - tr( "MNU_VIEWPARAMETERS_VIEW" ), 0, this); + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARAMETERS" ) ), + tr( "MNU_VIEWPARAMETERS_VIEW" ), 0, this); anAction->setStatusTip(tr("DSC_VIEWPARAMETERS_VIEW")); anAction->setCheckable(true); connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onViewParameters(bool))); mgr->registerAction( anAction, ViewParametersId ); + // Synchronize View + mgr->registerAction( synchronizeAction(), SynchronizeId ); + // Switch between interaction styles anAction = new QtxAction(tr("MNU_SVTK_STYLE_SWITCH"), - theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_STYLE_SWITCH" ) ), - tr( "MNU_SVTK_STYLE_SWITCH" ), 0, this); + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_STYLE_SWITCH" ) ), + tr( "MNU_SVTK_STYLE_SWITCH" ), 0, this); anAction->setStatusTip(tr("DSC_SVTK_STYLE_SWITCH")); anAction->setCheckable(true); connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool))); mgr->registerAction( anAction, SwitchInteractionStyleId ); + // Switch between zooming styles + anAction = new QtxAction(tr("MNU_SVTK_ZOOMING_STYLE_SWITCH"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_ZOOMING_STYLE_SWITCH" ) ), + tr( "MNU_SVTK_ZOOMING_STYLE_SWITCH" ), 0, this); + anAction->setStatusTip(tr("DSC_SVTK_ZOOMING_STYLE_SWITCH")); + anAction->setCheckable(true); + connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool))); + mgr->registerAction( anAction, SwitchZoomingStyleId ); + + // Pre-selection + QSignalMapper* aSignalMapper = new QSignalMapper( this ); + connect(aSignalMapper, SIGNAL(mapped(int)), this, SLOT(onSwitchPreSelectionMode(int))); + + anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_STANDARD"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_STANDARD" ) ), + tr( "MNU_SVTK_PRESELECTION_STANDARD" ), 0, this); + anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_STANDARD")); + anAction->setCheckable(true); + connect(anAction, SIGNAL(triggered()), aSignalMapper, SLOT(map())); + aSignalMapper->setMapping( anAction, Standard_Preselection ); + mgr->registerAction( anAction, StandardPreselectionId ); + + anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_DYNAMIC"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_DYNAMIC" ) ), + tr( "MNU_SVTK_PRESELECTION_DYNAMIC" ), 0, this); + anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_DYNAMIC")); + anAction->setCheckable(true); + connect(anAction, SIGNAL(triggered()), aSignalMapper, SLOT(map())); + aSignalMapper->setMapping( anAction, Dynamic_Preselection ); + mgr->registerAction( anAction, DynamicPreselectionId ); + + anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_DISABLED"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_DISABLED" ) ), + tr( "MNU_SVTK_PRESELECTION_DISABLED" ), 0, this); + anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_DISABLED")); + anAction->setCheckable(true); + connect(anAction, SIGNAL(triggered()), aSignalMapper, SLOT(map())); + aSignalMapper->setMapping( anAction, Preselection_Disabled ); + mgr->registerAction( anAction, DisablePreselectionId ); + + QtxActionGroup* aPreselectionAction = new QtxActionGroup( this, true ); + aPreselectionAction->add( getAction( StandardPreselectionId ) ); + aPreselectionAction->add( getAction( DynamicPreselectionId ) ); + aPreselectionAction->add( getAction( DisablePreselectionId ) ); + mgr->registerAction( aPreselectionAction, PreselectionId ); + + // Selection + anAction = new QtxAction(tr("MNU_SVTK_ENABLE_SELECTION"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SELECTION" ) ), + tr( "MNU_SVTK_ENABLE_SELECTION" ), 0, this); + anAction->setStatusTip(tr("DSC_SVTK_ENABLE_SELECTION")); + anAction->setCheckable(true); + connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onEnableSelection(bool))); + mgr->registerAction( anAction, EnableSelectionId ); + // Start recording myStartAction = new QtxAction(tr("MNU_SVTK_RECORDING_START"), - theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_START" ) ), - tr( "MNU_SVTK_RECORDING_START" ), 0, this); + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_START" ) ), + tr( "MNU_SVTK_RECORDING_START" ), 0, this); myStartAction->setStatusTip(tr("DSC_SVTK_RECORDING_START")); connect( myStartAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStartRecording() ) ); mgr->registerAction( myStartAction, StartRecordingId ); // Play recording myPlayAction = new QtxAction(tr("MNU_SVTK_RECORDING_PLAY"), - theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PLAY" ) ), - tr( "MNU_SVTK_RECORDING_PLAY" ), 0, this); + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PLAY" ) ), + tr( "MNU_SVTK_RECORDING_PLAY" ), 0, this); myPlayAction->setStatusTip(tr("DSC_SVTK_RECORDING_PLAY")); myPlayAction->setEnabled( false ); connect( myPlayAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPlayRecording() ) ); @@ -1706,8 +2455,8 @@ void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr) // Pause recording myPauseAction = new QtxAction(tr("MNU_SVTK_RECORDING_PAUSE"), - theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PAUSE" ) ), - tr( "MNU_SVTK_RECORDING_PAUSE" ), 0, this); + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PAUSE" ) ), + tr( "MNU_SVTK_RECORDING_PAUSE" ), 0, this); myPauseAction->setStatusTip(tr("DSC_SVTK_RECORDING_PAUSE")); myPauseAction->setEnabled( false ); connect( myPauseAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPauseRecording() ) ); @@ -1715,8 +2464,8 @@ void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr) // Stop recording myStopAction = new QtxAction(tr("MNU_SVTK_RECORDING_STOP"), - theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_STOP" ) ), - tr( "MNU_SVTK_RECORDING_STOP" ), 0, this); + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_STOP" ) ), + tr( "MNU_SVTK_RECORDING_STOP" ), 0, this); myStopAction->setStatusTip(tr("DSC_SVTK_RECORDING_STOP")); myStopAction->setEnabled( false ); connect( myStopAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStopRecording() ) ); @@ -1732,11 +2481,21 @@ void SVTK_ViewWindow::createToolBar() mgr->append( DumpId, myToolBar ); mgr->append( SwitchInteractionStyleId, myToolBar ); + mgr->append( SwitchZoomingStyleId, myToolBar ); + + mgr->append( mgr->separator(), myToolBar ); + + mgr->append( PreselectionId, myToolBar ); + mgr->append( EnableSelectionId, myToolBar ); + + mgr->append( mgr->separator(), myToolBar ); + mgr->append( ViewTrihedronId, myToolBar ); QtxMultiAction* aScaleAction = new QtxMultiAction( this ); aScaleAction->insertAction( getAction( FitAllId ) ); aScaleAction->insertAction( getAction( FitRectId ) ); + aScaleAction->insertAction( getAction( FitSelectionId ) ); aScaleAction->insertAction( getAction( ZoomId ) ); mgr->append( aScaleAction, myToolBar ); @@ -1758,6 +2517,9 @@ void SVTK_ViewWindow::createToolBar() aViewsAction->insertAction( getAction( RightId ) ); mgr->append( aViewsAction, myToolBar ); + mgr->append( AntiClockWiseId, myToolBar ); + mgr->append( ClockWiseId, myToolBar ); + mgr->append( ResetId, myToolBar ); mgr->append( UpdateRate, myToolBar ); @@ -1765,9 +2527,13 @@ void SVTK_ViewWindow::createToolBar() mgr->append( GraduatedAxes, myToolBar ); mgr->append( ViewParametersId, myToolBar ); + mgr->append( SynchronizeId, myToolBar ); + mgr->append( toolMgr()->separator(), myToolBar ); + mgr->append( ParallelModeId, myToolBar ); mgr->append( ProjectionModeId, myToolBar ); + mgr->append( StereoModeId, myToolBar ); mgr->append( StartRecordingId, myRecordingToolBar ); mgr->append( PlayRecordingId, myRecordingToolBar ); @@ -1938,3 +2704,118 @@ void SVTK_ViewWindow::hideEvent( QHideEvent * theEvent ) emit Hide( theEvent ); } +/*! + Emit transformed signal. +*/ +void SVTK_ViewWindow::emitTransformed() { + transformed(this); +} + +/*! + Processes events +*/ +void SVTK_ViewWindow::ProcessEvents(vtkObject* vtkNotUsed(theObject), + unsigned long theEvent, + void* theClientData, + void* theCallData) +{ + SVTK_ViewWindow* self = reinterpret_cast(theClientData); + if(self) + self->emitTransformed(); +} + +/*! + Get camera properties for the SVTK view window. + \return shared pointer on camera properties. +*/ +SUIT_CameraProperties SVTK_ViewWindow::cameraProperties() +{ + SUIT_CameraProperties aProps; + + // get vtk camera + vtkCamera* aCamera = getRenderer()->GetActiveCamera(); + if ( !aCamera ) + return aProps; + + aProps.setDimension( SUIT_CameraProperties::Dim3D ); + if ( toolMgr()->action( ParallelModeId ) ) { + if ( toolMgr()->action( ParallelModeId )->isChecked() ) + aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal ); + else + aProps.setProjection( SUIT_CameraProperties::PrjPerspective ); + } + + double aFocalPoint[3]; + double aPosition[3]; + double aViewUp[3]; + double anAxialScale[3]; + + aCamera->OrthogonalizeViewUp(); + aCamera->GetFocalPoint( aFocalPoint ); + aCamera->GetPosition( aPosition ); + aCamera->GetViewUp( aViewUp ); + + aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] ); + aProps.setPosition( aPosition[0], aPosition[1], aPosition[2] ); + aProps.setViewUp( aViewUp[0], aViewUp[1], aViewUp[2] ); + aProps.setMappingScale( aCamera->GetParallelScale() * 2.0 ); + + if ( aProps.getProjection() == SUIT_CameraProperties::PrjPerspective ) + { + aProps.setViewAngle( aCamera->GetViewAngle() ); + } + + GetRenderer()->GetScale( anAxialScale ); + aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] ); + + return aProps; +} + +/*! + Synchronize views. + This implementation synchronizes camera propreties. +*/ +void SVTK_ViewWindow::synchronize( SUIT_ViewWindow* theView ) +{ + bool blocked = blockSignals( true ); + + SUIT_CameraProperties aProps = theView->cameraProperties(); + if ( !cameraProperties().isCompatible( aProps ) ) { + // other view, this one is being currently synchronized to, seems has become incompatible + // we have to break synchronization + updateSyncViews(); + return; + } + + // get camera + vtkCamera* aCamera = getRenderer()->GetActiveCamera(); + + double aFocalPoint[3]; + double aPosition[3]; + double aViewUp[3]; + double anAxialScale[3]; + + // get common properties + aProps.getViewUp( aViewUp[0], aViewUp[1], aViewUp[2] ); + aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] ); + aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] ); + aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] ); + + // restore properties to the camera + aCamera->SetViewUp( aViewUp ); + aCamera->SetPosition( aPosition ); + aCamera->SetFocalPoint( aFocalPoint ); + aCamera->SetParallelScale( aProps.getMappingScale() / 2.0 ); + + if ( aProps.getProjection() == SUIT_CameraProperties::PrjPerspective ) + { + aCamera->SetViewAngle( aProps.getViewAngle() ); + } + + GetRenderer()->SetScale( anAxialScale ); + + getRenderer()->ResetCameraClippingRange(); + Repaint( false ); + + blockSignals( blocked ); +}