From 1e5ceb6e277edfc2a2b491bedc1dc04c8af9c4ab Mon Sep 17 00:00:00 2001 From: skv Date: Mon, 8 Sep 2014 14:13:26 +0400 Subject: [PATCH] Copy utilities from GEOM module --- src/OCCViewer/CMakeLists.txt | 2 + src/OCCViewer/OCCViewer_Utilities.cxx | 64 +++++++++++++++++++++++++++ src/OCCViewer/OCCViewer_Utilities.h | 27 +++++++++++ 3 files changed, 93 insertions(+) create mode 100644 src/OCCViewer/OCCViewer_Utilities.cxx create mode 100644 src/OCCViewer/OCCViewer_Utilities.h diff --git a/src/OCCViewer/CMakeLists.txt b/src/OCCViewer/CMakeLists.txt index de1434512..a7cc4289c 100755 --- a/src/OCCViewer/CMakeLists.txt +++ b/src/OCCViewer/CMakeLists.txt @@ -76,6 +76,7 @@ SET(_other_HEADERS OCCViewer.h OCCViewer_ClipPlane.h OCCViewer_Trihedron.h + OCCViewer_Utilities.h OCCViewer_VService.h ) @@ -152,6 +153,7 @@ SET(_other_SOURCES OCCViewer_SetRotationPointDlg.cxx OCCViewer_ToolTip.cxx OCCViewer_Trihedron.cxx + OCCViewer_Utilities.cxx OCCViewer_VService.cxx OCCViewer_ViewFrame.cxx OCCViewer_ViewManager.cxx diff --git a/src/OCCViewer/OCCViewer_Utilities.cxx b/src/OCCViewer/OCCViewer_Utilities.cxx new file mode 100644 index 000000000..1fe25f4f6 --- /dev/null +++ b/src/OCCViewer/OCCViewer_Utilities.cxx @@ -0,0 +1,64 @@ + +#include "OCCViewer_Utilities.h" +#include "OCCViewer_ViewFrame.h" +#include "OCCViewer_ViewModel.h" +#include "OCCViewer_ViewPort3d.h" + +#include "SUIT_ViewManager.h" +#include "QtxActionToolMgr.h" + +#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 + Handle(V3d_View) aView3d = aView->getViewPort()->getView(); + if ( !aView3d.IsNull() ) { + switch ( theMode ) { + case OCCViewer_ViewWindow::XYPlane: + aView3d->SetProj (V3d_Zpos); + break; + case OCCViewer_ViewWindow::XZPlane: + aView3d->SetProj (V3d_Yneg); + break; + case OCCViewer_ViewWindow::YZPlane: + aView3d->SetProj (V3d_Xpos); + break; + } + } +} diff --git a/src/OCCViewer/OCCViewer_Utilities.h b/src/OCCViewer/OCCViewer_Utilities.h new file mode 100644 index 000000000..8460f3cc1 --- /dev/null +++ b/src/OCCViewer/OCCViewer_Utilities.h @@ -0,0 +1,27 @@ +#ifndef OCCVIEWER_UTILITIES_H +#define OCCVIEWER_UTILITIES_H + +#include "OCCViewer.h" +#include "OCCViewer_ViewWindow.h" + +class OCCViewer_Viewer; + +#ifdef WIN32 +#pragma warning ( disable:4251 ) +#endif + +class OCCVIEWER_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 -- 2.39.2