kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #33090
[PATCH] Use worksheet bounding box when the board is empty
Adds a mechanism for EDA_DRAW_PANEL_GAL children to define what the default
bounding box should be when the model doesn't provide a valid bounding box.
Fixes: https://bugs.launchpad.net/kicad/+bug/1742140
-Jon
From caac1e0bfa0c0e166d6cb55c8eefd7f8706238bb Mon Sep 17 00:00:00 2001
From: Jon Evans <jon@xxxxxxxxxxxxx>
Date: Wed, 10 Jan 2018 22:53:55 -0500
Subject: [PATCH] Use worksheet bounding box when the board is empty
Fixes: lp:1742140
* https://bugs.launchpad.net/kicad/+bug/1742140
---
common/tool/common_tools.cpp | 18 ++++++------------
include/class_draw_panel_gal.h | 12 ++++++++++++
pcbnew/pcb_draw_panel_gal.cpp | 9 +++++++++
pcbnew/pcb_draw_panel_gal.h | 3 +++
4 files changed, 30 insertions(+), 12 deletions(-)
diff --git a/common/tool/common_tools.cpp b/common/tool/common_tools.cpp
index 08b4c06cf..0658ea517 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 );
+ bBox = galCanvas->GetDefaultViewBBox();
}
- 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() );
- }
+ 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 ea0496306..5fc128a28 100644
--- a/include/class_draw_panel_gal.h
+++ b/include/class_draw_panel_gal.h
@@ -33,6 +33,7 @@
#include <wx/window.h>
#include <wx/timer.h>
+#include <math/box2.h>
#include <math/vector2d.h>
#include <msgpanel.h>
#include <memory>
@@ -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 b3af36802..61abe3274 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 6f1f3cf18..0d02580d6 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;
--
2.14.1
Follow ups