diff --git a/common/tool/common_tools.cpp b/common/tool/common_tools.cpp index 08b4c06cf3..0658ea5174 100644 --- a/common/tool/common_tools.cpp +++ b/common/tool/common_tools.cpp @@ -114,21 +114,15 @@ int COMMON_TOOLS::ZoomFitScreen( const TOOL_EVENT& aEvent ) if( bBox.GetWidth() == 0 || bBox.GetHeight() == 0 ) { - // Empty view - view->SetScale( 17.0 ); // works fine for the standard worksheet frame - - view->SetCenter( screenSize / 2.0 ); - } - else - { - VECTOR2D vsize = bBox.GetSize(); - double scale = view->GetScale() / std::max( fabs( vsize.x / screenSize.x ), - fabs( vsize.y / screenSize.y ) ); - - view->SetScale( scale ); - view->SetCenter( bBox.Centre() ); + bBox = galCanvas->GetDefaultViewBBox(); } + VECTOR2D vsize = bBox.GetSize(); + double scale = view->GetScale() / std::max( fabs( vsize.x / screenSize.x ), + fabs( vsize.y / screenSize.y ) ); + + view->SetScale( scale ); + view->SetCenter( bBox.Centre() ); // Take scrollbars into account VECTOR2D worldScrollbarSize = view->ToWorld( scrollbarSize, false ); diff --git a/include/class_draw_panel_gal.h b/include/class_draw_panel_gal.h index ea04963062..5fc128a28d 100644 --- a/include/class_draw_panel_gal.h +++ b/include/class_draw_panel_gal.h @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -224,6 +225,17 @@ public: */ int GetCurrentCursor() const { return m_currentCursor; } + /** + * Returns the bounding box of the view that should be used if model is not valid + * For example, the worksheet bounding box for an empty PCB + * + * @return the default bounding box for the panel + */ + virtual BOX2I GetDefaultViewBBox() const + { + return BOX2I(); + } + protected: void onPaint( wxPaintEvent& WXUNUSED( aEvent ) ); diff --git a/pcbnew/pcb_draw_panel_gal.cpp b/pcbnew/pcb_draw_panel_gal.cpp index b3af368023..61abe32743 100644 --- a/pcbnew/pcb_draw_panel_gal.cpp +++ b/pcbnew/pcb_draw_panel_gal.cpp @@ -395,6 +395,15 @@ void PCB_DRAW_PANEL_GAL::RedrawRatsnest() } +BOX2I PCB_DRAW_PANEL_GAL::GetDefaultViewBBox() const +{ + if( m_worksheet ) + return m_worksheet->ViewBBox(); + + return BOX2I(); +} + + void PCB_DRAW_PANEL_GAL::setDefaultLayerDeps() { // caching makes no sense for Cairo and other software renderers diff --git a/pcbnew/pcb_draw_panel_gal.h b/pcbnew/pcb_draw_panel_gal.h index 6f1f3cf18e..0d02580d62 100644 --- a/pcbnew/pcb_draw_panel_gal.h +++ b/pcbnew/pcb_draw_panel_gal.h @@ -103,6 +103,9 @@ public: ///> Forces refresh of the ratsnest visual representation void RedrawRatsnest(); + ///> @copydoc EDA_DRAW_PANEL_GAL::GetDefaultViewBBox() + BOX2I GetDefaultViewBBox() const override; + protected: KIGFX::PCB_VIEW* view() const;