diff --git a/bitmaps_png/CMakeLists.txt b/bitmaps_png/CMakeLists.txt index 306dd5aaf9..070fe6092b 100644 --- a/bitmaps_png/CMakeLists.txt +++ b/bitmaps_png/CMakeLists.txt @@ -58,7 +58,7 @@ option( MAINTAIN_PNGS # SMALL - for menus - 16 x 16 # MID - for toolbars - 26 x 26 # BIG - for program icons - 48 x 48 -# which are given on three basename lists: BMAPS_SMALL, BMAPS_MID,a nd BMAPS_BIG +# which are given on three basename lists: BMAPS_SMALL, BMAPS_MID,and BMAPS_BIG # respectively. The basename is without file extension and without path. # A corresponding ${basename}.svg file must exist in 'sources' dir below here. @@ -508,6 +508,7 @@ set( BMAPS_MID zoom_area zoom_auto_fit_in_page zoom_fit_in_page + zoom_fit_to_objects zoom_center_on_screen zoom_in zoom_out diff --git a/bitmaps_png/cpp_26/zoom_fit_to_objects.cpp b/bitmaps_png/cpp_26/zoom_fit_to_objects.cpp new file mode 100644 index 0000000000..2e2a5ec5dd --- /dev/null +++ b/bitmaps_png/cpp_26/zoom_fit_to_objects.cpp @@ -0,0 +1,52 @@ + +/* Do not modify this file, it was automatically generated by the + * PNG2cpp CMake script, using a *.png file as input. + */ + +#include + +static const unsigned char png[] = { + 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, + 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x1a, 0x08, 0x04, 0x00, 0x00, 0x00, 0x03, 0x43, 0x84, + 0x45, 0x00, 0x00, 0x02, 0x29, 0x49, 0x44, 0x41, 0x54, 0x38, 0xcb, 0xd5, 0x94, 0xc1, 0x6f, 0x12, + 0x41, 0x14, 0xc6, 0x37, 0x31, 0x5e, 0xb4, 0xa5, 0x5e, 0xf8, 0x17, 0x5a, 0xef, 0x93, 0x62, 0x04, + 0x8c, 0x97, 0x26, 0xa4, 0x91, 0x84, 0x80, 0xb1, 0x37, 0x7a, 0x72, 0x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88, 0x32, 0x93, 0x86, 0x48, 0xa3, 0x38, 0x29, 0x51, 0x0f, 0x52, 0xa9, 0x3e, 0x48, + 0xd9, 0x25, 0x88, 0x57, 0x05, 0x21, 0xd2, 0xd8, 0xc2, 0x37, 0x66, 0x00, 0xc1, 0x15, 0x34, 0x99, + 0xb6, 0x18, 0x24, 0x08, 0x89, 0x1a, 0xc1, 0x53, 0xe3, 0x64, 0x72, 0xc3, 0xb2, 0xe9, 0x45, 0x66, + 0xbe, 0x0d, 0xed, 0xe0, 0x2a, 0xbc, 0xb8, 0x86, 0x6d, 0xac, 0xe1, 0xbd, 0x05, 0x65, 0x62, 0x1e, + 0xd6, 0x80, 0x13, 0x7d, 0xc3, 0x98, 0x48, 0x43, 0xd0, 0x03, 0x6d, 0xa8, 0xd9, 0xd1, 0x1a, 0x8b, + 0x17, 0xb7, 0xa0, 0x4a, 0x28, 0x88, 0x5b, 0x14, 0xa3, 0xc7, 0xa1, 0x51, 0x91, 0x06, 0x51, 0x09, + 0x72, 0x68, 0x13, 0x85, 0x8e, 0xf4, 0x6e, 0xa4, 0xcd, 0x1b, 0x41, 0x88, 0x7d, 0xd0, 0x10, 0x4f, + 0x4f, 0xb3, 0xd2, 0x2b, 0x59, 0x15, 0x71, 0x95, 0xbb, 0x35, 0x65, 0x62, 0x6e, 0xc8, 0x66, 0x9f, + 0x7f, 0xdc, 0x88, 0x85, 0x1a, 0x87, 0xca, 0x18, 0xef, 0xe8, 0xeb, 0x6f, 0x23, 0xb6, 0x09, 0x14, + 0xa3, 0xdf, 0xf2, 0xb4, 0x07, 0x12, 0xdd, 0xf0, 0x71, 0xcb, 0xcb, 0x3d, 0xe2, 0x96, 0x17, 0xfc, + 0xd2, 0xa1, 0x17, 0xe9, 0x64, 0x7f, 0x73, 0x1d, 0xb3, 0x2d, 0x82, 0x79, 0x9b, 0xe6, 0x46, 0x73, + 0x73, 0x4d, 0x82, 0x27, 0x2d, 0x5c, 0xb0, 0x99, 0x89, 0x75, 0x99, 0x8f, 0x91, 0x5a, 0xff, 0x3c, + 0xd9, 0xbb, 0x5a, 0xf0, 0xcf, 0x35, 0x5d, 0xb8, 0x84, 0x6c, 0xe9, 0x94, 0xe9, 0x5b, 0x5e, 0x9a, + 0x66, 0xe3, 0x29, 0xd1, 0x44, 0x35, 0xfb, 0x5c, 0x0f, 0x54, 0x82, 0x5a, 0x7c, 0xa1, 0x26, 0x1d, + 0x12, 0x86, 0x10, 0x4c, 0x51, 0xed, 0xd3, 0x87, 0xfb, 0x38, 0x6b, 0x83, 0xbd, 0x79, 0xf0, 0xb8, + 0xe5, 0x61, 0x5b, 0xdc, 0x08, 0x31, 0xf1, 0xa3, 0xe1, 0x65, 0x89, 0xbd, 0xfb, 0x32, 0xc5, 0x7e, + 0x36, 0x0e, 0x1f, 0x5e, 0x7d, 0x37, 0x9c, 0x76, 0x83, 0xeb, 0x48, 0xa5, 0x14, 0xe3, 0xa1, 0x29, + 0xd2, 0x9b, 0x54, 0x66, 0x87, 0x30, 0x9d, 0xe4, 0xb5, 0x64, 0xf2, 0x97, 0xad, 0x26, 0xb8, 0xb0, + 0xb8, 0x67, 0x8b, 0x59, 0xe8, 0x39, 0x8c, 0xb1, 0xe3, 0x3e, 0x7c, 0xf4, 0x9d, 0xbf, 0xeb, 0xef, + 0xf4, 0x8e, 0x63, 0x83, 0x5e, 0x02, 0x67, 0x5e, 0xee, 0xb8, 0xba, 0xd8, 0xc0, 0x57, 0x8d, 0xe1, + 0x5c, 0xdc, 0x3b, 0xc2, 0xfe, 0xe1, 0x86, 0x32, 0x9c, 0x2f, 0x7e, 0xb4, 0xb1, 0x5f, 0xc5, 0xd8, + 0xb1, 0x0b, 0xd5, 0xd8, 0x0b, 0x57, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, + 0x60, 0x82, +}; + +const BITMAP_OPAQUE zoom_fit_to_objects_xpm[1] = {{ png, sizeof( png ), "zoom_fit_to_objects_xpm" }}; + +//EOF diff --git a/bitmaps_png/include/bitmaps_png/bitmaps_list.h b/bitmaps_png/include/bitmaps_png/bitmaps_list.h index a2905a2fa6..782135d9f9 100644 --- a/bitmaps_png/include/bitmaps_png/bitmaps_list.h +++ b/bitmaps_png/include/bitmaps_png/bitmaps_list.h @@ -500,6 +500,7 @@ EXTERN_BITMAP( zoom_auto_fit_in_page_xpm ) EXTERN_BITMAP( zoom_center_on_screen_xpm ) EXTERN_BITMAP( zoom_redraw_xpm ) EXTERN_BITMAP( zoom_fit_in_page_xpm ) +EXTERN_BITMAP( zoom_fit_to_objects_xpm ) EXTERN_BITMAP( zoom_in_xpm ) EXTERN_BITMAP( zoom_out_xpm ) EXTERN_BITMAP( zoom_page_xpm ) diff --git a/bitmaps_png/sources/zoom_fit_to_objects.svg b/bitmaps_png/sources/zoom_fit_to_objects.svg new file mode 100644 index 0000000000..1b7baedd38 --- /dev/null +++ b/bitmaps_png/sources/zoom_fit_to_objects.svg @@ -0,0 +1,208 @@ + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/common/tool/actions.cpp b/common/tool/actions.cpp index 1ef0a10db6..157364b9b4 100644 --- a/common/tool/actions.cpp +++ b/common/tool/actions.cpp @@ -259,6 +259,11 @@ TOOL_ACTION ACTIONS::zoomFitScreen( "common.Control.zoomFitScreen", _( "Zoom to Fit" ), _( "Zoom to Fit" ), zoom_fit_in_page_xpm ); +TOOL_ACTION ACTIONS::zoomFitObjects( "common.Control.zoomFitObjects", + AS_GLOBAL, MD_CTRL + WXK_HOME, "", + _( "Zoom to Objects" ), _( "Zoom to Objects" ), + zoom_fit_to_objects_xpm ); + TOOL_ACTION ACTIONS::zoomIn( "common.Control.zoomIn", AS_GLOBAL, #if defined( __WXMAC__ ) diff --git a/common/tool/common_tools.cpp b/common/tool/common_tools.cpp index 92ae667b25..bed878c317 100644 --- a/common/tool/common_tools.cpp +++ b/common/tool/common_tools.cpp @@ -250,7 +250,19 @@ int COMMON_TOOLS::ZoomCenter( const TOOL_EVENT& aEvent ) int COMMON_TOOLS::ZoomFitScreen( const TOOL_EVENT& aEvent ) { - KIGFX::VIEW* view = getView(); + return doZoomFit( ZOOM_FIT_ALL ); +} + + +int COMMON_TOOLS::ZoomFitObjects( const TOOL_EVENT& aEvent ) +{ + return doZoomFit( ZOOM_FIT_OBJECTS ); +} + + +int COMMON_TOOLS::doZoomFit( ZOOM_FIT_TYPE_T aFitType ) +{ + KIGFX::VIEW* view = getView(); EDA_DRAW_PANEL_GAL* canvas = m_frame->GetCanvas(); EDA_DRAW_FRAME* frame = getEditFrame(); @@ -258,11 +270,24 @@ int COMMON_TOOLS::ZoomFitScreen( const TOOL_EVENT& aEvent ) BOX2I defaultBox = canvas->GetDefaultViewBBox(); VECTOR2D scrollbarSize = VECTOR2D( canvas->GetSize() - canvas->GetClientSize() ); - view->SetScale( 1.0 ); // the best scale will be fixed later, from this initial value - // but this call ensure all view parameters are up to date - // especially at init time + view->SetScale( 1.0 ); // The best scale will be determined later, but this initial + // value ensures all view parameters are up to date (especially + // at init time) VECTOR2D screenSize = view->ToWorld( canvas->GetClientSize(), false ); + // Currently "Zoom to Objects" is only supported on Eeschema. Support for other + // programs in the suite can be added as needed. + + if( aFitType == ZOOM_FIT_OBJECTS ) + { + if( frame->IsType( FRAME_SCH ) ) + bBox = view->GetItemsExtents(); // Get a BBox of all items except page and border + else + aFitType = ZOOM_FIT_ALL; // Just do a "Zoom to Fit" for unsupported editors + } + + // If the screen is empty then use the default view bbox + if( bBox.GetWidth() == 0 || bBox.GetHeight() == 0 ) bBox = defaultBox; @@ -270,27 +295,37 @@ int COMMON_TOOLS::ZoomFitScreen( const TOOL_EVENT& aEvent ) double scale = view->GetScale() / std::max( fabs( vsize.x / screenSize.x ), fabs( vsize.y / screenSize.y ) ); - // Reserve a 10% margin around component bounding box. - double margin_scale_factor = 1.1; + // Reserve a 2% margin around bounding boxes. + double margin_scale_factor = 1.02; - // Leave a bigger margin for library editors & viewers - if( frame->IsType( FRAME_FOOTPRINT_VIEWER ) || frame->IsType( FRAME_FOOTPRINT_VIEWER_MODAL ) - || frame->IsType( FRAME_SCH_VIEWER ) || frame->IsType( FRAME_SCH_VIEWER_MODAL ) ) + switch( aFitType ) { - margin_scale_factor = 1.4; - } - else if( frame->IsType( FRAME_SCH_LIB_EDITOR ) || frame->IsType( FRAME_FOOTPRINT_EDITOR ) ) - { - margin_scale_factor = 2; + case ZOOM_FIT_ALL: + // Leave a bigger margin for library editors & viewers + + if( frame->IsType( FRAME_FOOTPRINT_VIEWER ) || frame->IsType( FRAME_FOOTPRINT_VIEWER_MODAL ) + || frame->IsType( FRAME_SCH_VIEWER ) || frame->IsType( FRAME_SCH_VIEWER_MODAL ) ) + { + margin_scale_factor = 1.4; + } + else if( frame->IsType( FRAME_SCH_LIB_EDITOR ) || frame->IsType( FRAME_FOOTPRINT_EDITOR ) ) + { + margin_scale_factor = 2; + } + break; + + // Currently the same value as "ZOOM_FIT_ALL" but allows easy expansion/change in the future. + case ZOOM_FIT_OBJECTS: + margin_scale_factor = 1.02; // Reserve a 2% margin around bounding box. + break; + + default: + margin_scale_factor = 1.02; } view->SetScale( scale / margin_scale_factor ); view->SetCenter( bBox.Centre() ); - // Take scrollbars into account - VECTOR2D worldScrollbarSize = view->ToWorld( scrollbarSize, false ); - view->SetCenter( view->GetCenter() + worldScrollbarSize / 2.0 ); - return 0; } @@ -565,6 +600,7 @@ void COMMON_TOOLS::setTransitions() Go( &COMMON_TOOLS::ZoomInOutCenter, ACTIONS::zoomOutCenter.MakeEvent() ); Go( &COMMON_TOOLS::ZoomCenter, ACTIONS::zoomCenter.MakeEvent() ); Go( &COMMON_TOOLS::ZoomFitScreen, ACTIONS::zoomFitScreen.MakeEvent() ); + Go( &COMMON_TOOLS::ZoomFitObjects, ACTIONS::zoomFitObjects.MakeEvent() ); Go( &COMMON_TOOLS::ZoomPreset, ACTIONS::zoomPreset.MakeEvent() ); Go( &COMMON_TOOLS::CenterContents, ACTIONS::centerContents.MakeEvent() ); diff --git a/common/view/view.cpp b/common/view/view.cpp index b19fcdd8bc..8e8d234236 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -1591,4 +1591,10 @@ void VIEW::ShowPreview( bool aShow ) const int VIEW::TOP_LAYER_MODIFIER = -VIEW_MAX_LAYERS; +const BOX2I VIEW::GetItemsExtents() const +{ + // To be implemented by subclasses. + return BOX2I(); } + +} // namespace KIGFX diff --git a/eeschema/menubar.cpp b/eeschema/menubar.cpp index dd74186e1d..ac8742be9e 100644 --- a/eeschema/menubar.cpp +++ b/eeschema/menubar.cpp @@ -167,6 +167,7 @@ void SCH_EDIT_FRAME::ReCreateMenuBar() viewMenu->Add( ACTIONS::zoomInCenter ); viewMenu->Add( ACTIONS::zoomOutCenter ); viewMenu->Add( ACTIONS::zoomFitScreen ); + viewMenu->Add( ACTIONS::zoomFitObjects ); viewMenu->Add( ACTIONS::zoomTool ); viewMenu->Add( ACTIONS::zoomRedraw ); diff --git a/eeschema/sch_view.cpp b/eeschema/sch_view.cpp index 1a526efda9..1e322a7a1c 100644 --- a/eeschema/sch_view.cpp +++ b/eeschema/sch_view.cpp @@ -80,6 +80,20 @@ void SCH_VIEW::SetScale( double aScale, VECTOR2D aAnchor ) } +const BOX2I SCH_VIEW::GetItemsExtents() const +{ + // Calc the bounding box of all items on screen except the page border + EDA_RECT bBoxItems; + + for( EDA_ITEM* item : m_frame->GetScreen()->Items() ) + { + if( item != m_worksheet.get() ) + bBoxItems.Merge( item->GetBoundingBox() ); + } + + return bBoxItems; +} + void SCH_VIEW::ResizeSheetWorkingArea( SCH_SCREEN* aScreen ) { const PAGE_INFO& page_info = aScreen->GetPageSettings(); diff --git a/eeschema/sch_view.h b/eeschema/sch_view.h index 520f5c3672..1eb795d3a0 100644 --- a/eeschema/sch_view.h +++ b/eeschema/sch_view.h @@ -88,6 +88,12 @@ public: void SetScale( double aScale, VECTOR2D aAnchor = { 0, 0 } ) override; + /** + * Return BBox of all items on screen except page and border + */ + const BOX2I GetItemsExtents() const override; + + /** * Clear the hide flag of all items in the view */ diff --git a/eeschema/toolbars_sch_editor.cpp b/eeschema/toolbars_sch_editor.cpp index a61c5b38c9..d86bb7fb23 100644 --- a/eeschema/toolbars_sch_editor.cpp +++ b/eeschema/toolbars_sch_editor.cpp @@ -78,6 +78,7 @@ void SCH_EDIT_FRAME::ReCreateHToolbar() m_mainToolBar->Add( ACTIONS::zoomInCenter ); m_mainToolBar->Add( ACTIONS::zoomOutCenter ); m_mainToolBar->Add( ACTIONS::zoomFitScreen ); + m_mainToolBar->Add( ACTIONS::zoomFitObjects ); m_mainToolBar->Add( ACTIONS::zoomTool, ACTION_TOOLBAR::TOGGLE, ACTION_TOOLBAR::CANCEL ); m_mainToolBar->AddScaledSeparator( this ); diff --git a/include/tool/actions.h b/include/tool/actions.h index e83c8e0521..7c4ac1b653 100644 --- a/include/tool/actions.h +++ b/include/tool/actions.h @@ -92,6 +92,7 @@ public: static TOOL_ACTION zoomOutCenter; static TOOL_ACTION zoomCenter; static TOOL_ACTION zoomFitScreen; + static TOOL_ACTION zoomFitObjects; // Zooms to bbox of items on screen (except page border) static TOOL_ACTION zoomPreset; static TOOL_ACTION zoomTool; static TOOL_ACTION centerContents; diff --git a/include/tool/common_tools.h b/include/tool/common_tools.h index 688adbb3af..fa45771ce8 100644 --- a/include/tool/common_tools.h +++ b/include/tool/common_tools.h @@ -56,6 +56,7 @@ public: int ZoomInOutCenter( const TOOL_EVENT& aEvent ); int ZoomCenter( const TOOL_EVENT& aEvent ); int ZoomFitScreen( const TOOL_EVENT& aEvent ); + int ZoomFitObjects( const TOOL_EVENT& aEvent ); int ZoomPreset( const TOOL_EVENT& aEvent ); int CenterContents( const TOOL_EVENT& aEvent ); @@ -88,6 +89,16 @@ public: int SwitchCanvas( const TOOL_EVENT& aEvent ); private: + /** + * Enum ZOOM_FIT_TYPE_T + * is the set of "Zoom to Fit" types that can be performed + */ + enum ZOOM_FIT_TYPE_T + { + ZOOM_FIT_ALL, // Zoom to fall all items in view INCLUDING page and border + ZOOM_FIT_OBJECTS, // Zoom to fit all items in view EXCLUDING page and border + }; + ///> Sets up handlers for various events. void setTransitions() override; @@ -99,6 +110,8 @@ private: ///> Note: idx == 0 is Auto; idx == 1 is first entry in zoomList int doZoomToPreset( int idx, bool aCenterOnCursor ); + int doZoomFit( ZOOM_FIT_TYPE_T aFitType ); + std::vector m_grids; // grids from APP_SETTINGS converted to internal units // and with the user grid appended }; diff --git a/include/view/view.h b/include/view/view.h index 1e11dd1745..6e0c8caefd 100644 --- a/include/view/view.h +++ b/include/view/view.h @@ -289,6 +289,11 @@ public: return m_boundary; } + /** + * Return BBox of all items on screen except page and border + */ + virtual const BOX2I GetItemsExtents() const; + /** * Function SetScaleLimits() * Sets minimum and maximum values for scale.