From f1374338ead2e2c2c4fb959223131ab46b448316 Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 28 Nov 2013 14:26:20 +0000 Subject: [PATCH] Set 2d mode for OCC viewer. --- src/HYDROCurveCreator/CMakeLists.txt | 2 + src/HYDROCurveCreator/CurveCreator_Widget.cxx | 4 ++ src/HYDROCurveCreator/OCCViewer_Utilities.cxx | 59 +++++++++++++++++++ src/HYDROCurveCreator/OCCViewer_Utilities.h | 28 +++++++++ src/HYDROGUI/HYDROGUI_Module.cxx | 6 ++ src/HYDROGUI/HYDROGUI_Tool.cxx | 37 ++++++++++++ src/HYDROGUI/HYDROGUI_Tool.h | 21 +++++++ 7 files changed, 157 insertions(+) create mode 100644 src/HYDROCurveCreator/OCCViewer_Utilities.cxx create mode 100644 src/HYDROCurveCreator/OCCViewer_Utilities.h diff --git a/src/HYDROCurveCreator/CMakeLists.txt b/src/HYDROCurveCreator/CMakeLists.txt index ee2a4c9e..679e6ab0 100644 --- a/src/HYDROCurveCreator/CMakeLists.txt +++ b/src/HYDROCurveCreator/CMakeLists.txt @@ -62,6 +62,7 @@ IF(SALOME_BUILD_GUI) CurveCreator_TreeView.h # CurveCreator_UndoOptsDlg.h CurveCreator_Widget.h + OCCViewer_Utilities.h OCCViewer_ViewWidget.h ) ENDIF(SALOME_BUILD_GUI) @@ -107,6 +108,7 @@ IF(SALOME_BUILD_GUI) CurveCreator_TreeView.cxx # CurveCreator_UndoOptsDlg.cxx CurveCreator_Widget.cxx + OCCViewer_Utilities.cxx OCCViewer_ViewWidget.cxx ) ENDIF(SALOME_BUILD_GUI) diff --git a/src/HYDROCurveCreator/CurveCreator_Widget.cxx b/src/HYDROCurveCreator/CurveCreator_Widget.cxx index c2fb84ce..7c0b180e 100644 --- a/src/HYDROCurveCreator/CurveCreator_Widget.cxx +++ b/src/HYDROCurveCreator/CurveCreator_Widget.cxx @@ -35,6 +35,7 @@ #include #include #include +#include "OCCViewer_Utilities.h" #include #include @@ -236,6 +237,8 @@ void CurveCreator_Widget::setOCCViewer( OCCViewer_Viewer* theViewer ) this, SLOT( onMouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ) ); disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ), this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) ); + // restore normal mode in the viewer + OCCViewer_Utilities::setViewer2DMode( myOCCViewer, OCCViewer_ViewWindow::No2dMode ); // all local contexts should be closed if the viewer is not more used setLocalPointContext( false, true ); } @@ -250,6 +253,7 @@ void CurveCreator_Widget::setOCCViewer( OCCViewer_Viewer* theViewer ) this, SLOT( onMouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ) ); connect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ), this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) ); + OCCViewer_Utilities::setViewer2DMode( theViewer, OCCViewer_ViewWindow::XYPlane ); } } diff --git a/src/HYDROCurveCreator/OCCViewer_Utilities.cxx b/src/HYDROCurveCreator/OCCViewer_Utilities.cxx new file mode 100644 index 00000000..425179f9 --- /dev/null +++ b/src/HYDROCurveCreator/OCCViewer_Utilities.cxx @@ -0,0 +1,59 @@ + +#include "OCCViewer_Utilities.h" + +#include +#include +#include + +#include + +#include + +void OCCViewer_Utilities::setViewer2DMode( OCCViewer_Viewer* theViewer, + const OCCViewer_ViewWindow::Mode2dType& theMode ) +{ + OCCViewer_ViewFrame* aFrame = dynamic_cast + ( theViewer->getViewManager()->getActiveView() ); + OCCViewer_ViewWindow* aView = aFrame ? aFrame->getView( OCCViewer_ViewFrame::MAIN_VIEW ) : 0; + if ( !aView ) + return; + + // set a view mode + aView->set2dMode( theMode ); + bool is2dMode = theMode != OCCViewer_ViewWindow::No2dMode; + + // enable/disable view actions + QList aNo2dActions; + aNo2dActions << OCCViewer_ViewWindow::ChangeRotationPointId + << OCCViewer_ViewWindow::RotationId + << OCCViewer_ViewWindow::FrontId + << OCCViewer_ViewWindow::BackId + << OCCViewer_ViewWindow::TopId + << OCCViewer_ViewWindow::BottomId + << OCCViewer_ViewWindow::LeftId + << OCCViewer_ViewWindow::RightId + << OCCViewer_ViewWindow::AntiClockWiseId + << OCCViewer_ViewWindow::ClockWiseId + << OCCViewer_ViewWindow::ResetId; + + QtxActionToolMgr* aToolMgr = aView->toolMgr(); + QAction* anAction; + for ( int i = 0, aNb = aNo2dActions.size(); i < aNb; i++ ) { + anAction = aToolMgr->action( aNo2dActions[i] ); + if ( anAction ) + anAction->setEnabled( !is2dMode ); + } + + // change view position + switch ( theMode ) { + case OCCViewer_ViewWindow::XYPlane: + aView->onTopView(); + break; + case OCCViewer_ViewWindow::XZPlane: + aView->onLeftView(); + break; + case OCCViewer_ViewWindow::YZPlane: + aView->onFrontView(); + break; + } +} diff --git a/src/HYDROCurveCreator/OCCViewer_Utilities.h b/src/HYDROCurveCreator/OCCViewer_Utilities.h new file mode 100644 index 00000000..c89eb45f --- /dev/null +++ b/src/HYDROCurveCreator/OCCViewer_Utilities.h @@ -0,0 +1,28 @@ +#ifndef OCCVIEWER_UTILITIES_H +#define OCCVIEWER_UTILITIES_H + +#include "CurveCreator_Macro.hxx" + +#include + +class OCCViewer_Viewer; + +#ifdef WIN32 +#pragma warning ( disable:4251 ) +#endif + +class CURVECREATOR_EXPORT OCCViewer_Utilities +{ +public: + + /*! + * Set 2D mode for the viewer. Hide or show 3D actions. + * \param theViewer an OCC viewer + * \param theMode OCC view window mode + */ + static void setViewer2DMode( OCCViewer_Viewer* theViewer, + const OCCViewer_ViewWindow::Mode2dType& theMode ); + +}; + +#endif diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index c92f41b4..36b56ec1 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -153,6 +153,8 @@ bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy ) connect( anApp, SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ), this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) ); + HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false ); + return aRes; } @@ -179,6 +181,8 @@ bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy ) disconnect( getApp(), SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ), this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) ); + HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true ); + return LightApp_Module::deactivateModule( theStudy ); } @@ -987,6 +991,8 @@ void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow ) if( OCCViewer_ViewFrame* aViewFrame = dynamic_cast( theViewWindow ) ) { aViewFrame->onTopView(); + + HYDROGUI_Tool::setOCCActionShown( aViewFrame, OCCViewer_ViewWindow::MaximizedId, false ); } } } diff --git a/src/HYDROGUI/HYDROGUI_Tool.cxx b/src/HYDROGUI/HYDROGUI_Tool.cxx index 51126a3c..0f2b7c2c 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.cxx +++ b/src/HYDROGUI/HYDROGUI_Tool.cxx @@ -43,8 +43,10 @@ #include #include +#include #include +#include #include @@ -461,6 +463,41 @@ QList HYDROGUI_Tool::GetOCCViewIdList( HYDROGUI_Module* theModule ) return getViewIdList( theModule, OCCViewer_Viewer::Type() ); } +void HYDROGUI_Tool::setOCCActionShown( OCCViewer_ViewFrame* theViewFrame, + const int theActionId, + const bool isShown ) +{ + if ( !theViewFrame ) + return; + + OCCViewer_ViewWindow* aView = theViewFrame->getView( OCCViewer_ViewFrame::MAIN_VIEW ); + if ( aView ) { + aView->toolMgr()->setShown( theActionId, isShown ); + if ( theActionId == OCCViewer_ViewWindow::MaximizedId ) + theViewFrame->onMaximizedView( aView, true ); + } +} + +void HYDROGUI_Tool::setOCCActionShown( HYDROGUI_Module* theModule, + const int theActionId, + const bool isShown ) +{ + QList aList; + ViewManagerList aViewMgrs; + theModule->getApp()->viewManagers( OCCViewer_Viewer::Type(), aViewMgrs ); + QListIterator anIter( aViewMgrs ); + while( anIter.hasNext() ) + { + if( SUIT_ViewManager* aViewMgr = anIter.next() ) + { + OCCViewer_ViewFrame* aViewFrame = dynamic_cast + ( aViewMgr->getActiveView() ); + if ( aViewFrame ) + setOCCActionShown( aViewFrame, theActionId, isShown ); + } + } +} + void HYDROGUI_Tool::GetObjectReferences( const Handle(HYDROData_Image)& theImage, HYDROData_SequenceOfObjects& theRefObjects, QStringList& theRefNames ) diff --git a/src/HYDROGUI/HYDROGUI_Tool.h b/src/HYDROGUI/HYDROGUI_Tool.h index 7a77b3af..ec6f2075 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.h +++ b/src/HYDROGUI/HYDROGUI_Tool.h @@ -34,6 +34,7 @@ #include class SUIT_ViewManager; +class OCCViewer_ViewFrame; class HYDROGUI_DataModel; class HYDROGUI_Module; @@ -240,6 +241,26 @@ public: */ static QList GetOCCViewIdList( HYDROGUI_Module* theModule ); + + /** + * \brief Change OCC viewer action visibility. + * \param theViewFrame OCC viewer frame + * \param theActionId an action index, which state should be changed + * \param isShown the action visibility state + */ + static void setOCCActionShown( OCCViewer_ViewFrame* theViewFrame, + const int theActionId, + const bool isShown ); + + /** + * \brief Change OCC viewer action visibility for all opened views. + * \param theActionId an action index, which state should be changed + * \param isShown the action visibility state + */ + static void setOCCActionShown( HYDROGUI_Module* theModule, + const int theActionId, + const bool isShown ); + /** * \brief Get the list of references (recursively) for the specified image object * \param theImage image data object -- 2.39.2