From c5330ac0bfca98693abae5a75a8b4ea61ae2bc15 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 3 Sep 2018 14:58:47 +0100 Subject: [PATCH] Implement zoom for GAL canvas. --- common/base_screen.cpp | 10 ++++++++-- eeschema/sch_base_frame.cpp | 38 ++++++++++++++++++++++++++++++++----- eeschema/sch_screen.cpp | 8 +------- eeschema/sch_screen.h | 1 - 4 files changed, 42 insertions(+), 15 deletions(-) diff --git a/common/base_screen.cpp b/common/base_screen.cpp index e706693135..5930ac580c 100644 --- a/common/base_screen.cpp +++ b/common/base_screen.cpp @@ -138,9 +138,12 @@ bool BASE_SCREEN::SetZoom( double iu_per_du ) bool BASE_SCREEN::SetNextZoom() { + // Step must be AT LEAST 1.2 + double target = m_Zoom * 1.2; + for( unsigned i=0; i < m_ZoomList.size(); ++i ) { - if( m_Zoom < m_ZoomList[i] ) + if( target < m_ZoomList[i] ) { SetZoom( m_ZoomList[i] ); return true; @@ -153,9 +156,12 @@ bool BASE_SCREEN::SetNextZoom() bool BASE_SCREEN::SetPreviousZoom() { + // Step must be AT LEAST 1.2 + double target = m_Zoom / 1.2; + for( unsigned i = m_ZoomList.size(); i != 0; --i ) { - if( m_Zoom > m_ZoomList[i - 1] ) + if( target > m_ZoomList[i - 1] ) { SetZoom( m_ZoomList[i - 1] ); return true; diff --git a/eeschema/sch_base_frame.cpp b/eeschema/sch_base_frame.cpp index 4b3eeef997..9118ffe732 100644 --- a/eeschema/sch_base_frame.cpp +++ b/eeschema/sch_base_frame.cpp @@ -337,8 +337,8 @@ bool SCH_BASE_FRAME::saveSymbolLibTables( bool aGlobal, bool aProject ) void SCH_BASE_FRAME::Zoom_Automatique( bool aWarpPointer ) { - auto galCanvas = GetGalCanvas(); - auto view = GetGalCanvas()->GetView(); + EDA_DRAW_PANEL_GAL* galCanvas = GetGalCanvas(); + KIGFX::VIEW* view = GetGalCanvas()->GetView(); BOX2I bBox = GetDocumentExtents(); @@ -365,7 +365,11 @@ void SCH_BASE_FRAME::Zoom_Automatique( bool aWarpPointer ) margin_scale_factor = 1.2; } - view->SetScale( scale / margin_scale_factor ); + scale /= margin_scale_factor; + + GetScreen()->SetScalingFactor( 1 / scale ); + + view->SetScale( scale ); view->SetCenter( bBox.Centre() ); // Take scrollbars into account @@ -377,7 +381,7 @@ void SCH_BASE_FRAME::Zoom_Automatique( bool aWarpPointer ) /* Set the zoom level to show the area Rect */ void SCH_BASE_FRAME::Window_Zoom( EDA_RECT& Rect ) { - auto view = GetGalCanvas()->GetView(); + KIGFX::VIEW* view = GetGalCanvas()->GetView(); BOX2I selectionBox ( Rect.GetPosition(), Rect.GetSize() ); VECTOR2D screenSize = view->ToWorld( GetGalCanvas()->GetClientSize(), false ); @@ -392,6 +396,8 @@ void SCH_BASE_FRAME::Window_Zoom( EDA_RECT& Rect ) scale = view->GetScale() / ratio; + GetScreen()->SetScalingFactor( 1 / scale ); + view->SetScale( scale ); view->SetCenter( selectionBox.Centre() ); GetGalCanvas()->Refresh(); @@ -400,12 +406,34 @@ void SCH_BASE_FRAME::Window_Zoom( EDA_RECT& Rect ) void SCH_BASE_FRAME::RedrawScreen( const wxPoint& aCenterPoint, bool aWarpPointer ) { - GetGalCanvas()->Refresh(); + KIGFX::GAL* gal = GetCanvas()->GetGAL(); + + double selectedZoom = GetScreen()->GetZoom(); + double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); + double scale = 1.0 / ( zoomFactor * selectedZoom ); + + if( aCenterPoint != wxPoint( 0, 0 ) ) + GetCanvas()->GetView()->SetScale( scale, aCenterPoint ); + else + GetCanvas()->GetView()->SetScale( scale ); + + if( aWarpPointer ) + GetCanvas()->GetViewControls()->CenterOnCursor(); + + GetCanvas()->Refresh(); } void SCH_BASE_FRAME::RedrawScreen2( const wxPoint& posBefore ) { + KIGFX::GAL* gal = GetCanvas()->GetGAL(); + + double selectedZoom = GetScreen()->GetZoom(); + double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); + double scale = 1.0 / ( zoomFactor * selectedZoom ); + + GetCanvas()->GetView()->SetScale( scale ); + GetGalCanvas()->Refresh(); } diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index 7a7d913834..6baf6a3205 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -54,6 +54,7 @@ #include #include #include +#include #define EESCHEMA_FILE_STAMP "EESchema" @@ -1606,13 +1607,6 @@ int SCH_SCREENS::ChangeSymbolLibNickname( const wxString& aFrom, const wxString& } -bool SCH_SCREEN::SetZoom( double iu_per_du ) -{ - printf("SetZoom!\n"); - return true; -} - - void SCH_SCREENS::BuildClientSheetPathList() { SCH_SHEET_LIST sheetList( g_RootSheet ); diff --git a/eeschema/sch_screen.h b/eeschema/sch_screen.h index 99d035f3f9..a973855f88 100644 --- a/eeschema/sch_screen.h +++ b/eeschema/sch_screen.h @@ -165,7 +165,6 @@ public: --m_modification_sync; } - virtual bool SetZoom( double iu_per_du ) override; /** * Copy the contents of \a aScreen into this #SCH_SCREEN object. *