From 641ccdff8b7a2a0bf3e597014ab50d380f0d1abc Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 12 Sep 2019 11:18:43 +0300 Subject: [PATCH] Implement custom fit all command which is used in sketcher of SHAPER module --- src/OCCViewer/OCCViewer_ViewModel.cxx | 3 ++- src/OCCViewer/OCCViewer_ViewModel.h | 27 ++++++++++++++++++++++++++ src/OCCViewer/OCCViewer_ViewWindow.cxx | 5 ++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/OCCViewer/OCCViewer_ViewModel.cxx b/src/OCCViewer/OCCViewer_ViewModel.cxx index 87370f17d..0acca6fc5 100644 --- a/src/OCCViewer/OCCViewer_ViewModel.cxx +++ b/src/OCCViewer/OCCViewer_ViewModel.cxx @@ -115,7 +115,8 @@ OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron) #if OCC_VERSION_LARGE <= 0x07030000 myIsUseLocalSelection(false), #endif - myClippingDlg (NULL) + myClippingDlg (NULL), + myFitter(0) { // init CasCade viewers myV3dViewer = OCCViewer_VService::CreateViewer( TCollection_ExtendedString("Viewer3d").ToExtString() ); diff --git a/src/OCCViewer/OCCViewer_ViewModel.h b/src/OCCViewer/OCCViewer_ViewModel.h index 8d91518e9..dddf9d11a 100644 --- a/src/OCCViewer/OCCViewer_ViewModel.h +++ b/src/OCCViewer/OCCViewer_ViewModel.h @@ -58,6 +58,19 @@ class QtxAction; #pragma warning( disable:4251 ) #endif +/** +An object wich provides alternative way to fit scene in a view +*/ +class OCCViewer_Fitter +{ +public: + /// A method which has top be reimplemented to provide alterantive implementation FitAll command + /// \param theView - a view which has to be fit + virtual void fitAll(Handle(V3d_View) theView) = 0; +}; + + + class OCCVIEWER_EXPORT OCCViewer_Viewer: public SUIT_ViewModel { Q_OBJECT @@ -143,6 +156,18 @@ public: bool useLocalSelection() const; #endif + // Methods to access fitter + + /// Returns currently installed fitter + OCCViewer_Fitter* fitter() const { return myFitter; } + + /// Installs new fitter + /// \param theFitter a new fitter + void setFitter(OCCViewer_Fitter* theFitter) { + myFitter = theFitter; + } + + public: Handle(V3d_Viewer) getViewer3d() const { return myV3dViewer;} Handle(AIS_InteractiveContext) getAISContext() const { return myAISContext; } @@ -298,6 +323,8 @@ protected: #if OCC_VERSION_LARGE <= 0x07030000 bool myIsUseLocalSelection; #endif + + OCCViewer_Fitter* myFitter; }; #ifdef WIN32 diff --git a/src/OCCViewer/OCCViewer_ViewWindow.cxx b/src/OCCViewer/OCCViewer_ViewWindow.cxx index 7210d572e..a5826fd38 100644 --- a/src/OCCViewer/OCCViewer_ViewWindow.cxx +++ b/src/OCCViewer/OCCViewer_ViewWindow.cxx @@ -1941,7 +1941,10 @@ void OCCViewer_ViewWindow::setProjectionType( int mode ) void OCCViewer_ViewWindow::onFitAll() { emit vpTransformationStarted( FITALLVIEW ); - myViewPort->fitAll(); + if (myModel->fitter()) + myModel->fitter()->fitAll(myViewPort->getView()); + else + myViewPort->fitAll(); emit vpTransformationFinished( FITALLVIEW ); } -- 2.39.2