Improve zoom-to-extents for footprints with long text.

Fixes: lp:1820540
* https://bugs.launchpad.net/kicad/+bug/1820540
This commit is contained in:
Jeff Young 2019-09-05 16:24:51 +01:00
parent 66f0bd4f6a
commit 3bd38ec245
18 changed files with 23 additions and 199 deletions

View File

@ -705,17 +705,6 @@ void EDA_DRAW_FRAME::HardRedraw()
}
// Factor out the calculation portion of the various BestZoom() implementations.
//
// Note that like it's forerunners this routine has an intentional side-effect: it
// sets the scroll centre position. While I'm not happy about that, it's probably
// not worth fixing as its days are numbered (GAL canvases use a different method).
double EDA_DRAW_FRAME::bestZoom( double sizeX, double sizeY, double scaleFactor, wxPoint centre )
{
return 1.0;
}
void EDA_DRAW_FRAME::Zoom_Automatique( bool aWarpPointer )
{
m_toolManager->RunAction( ACTIONS::zoomFitScreen, true );

View File

@ -254,12 +254,15 @@ int COMMON_TOOLS::ZoomFitScreen( const TOOL_EVENT& aEvent )
// Reserve a 10% margin around component bounding box.
double margin_scale_factor = 1.1;
// Leave 20% for library editors & viewers
if( frame->IsType( FRAME_PCB_MODULE_VIEWER ) || frame->IsType( FRAME_PCB_MODULE_VIEWER_MODAL )
|| frame->IsType( FRAME_SCH_VIEWER ) || frame->IsType( FRAME_SCH_VIEWER_MODAL )
|| frame->IsType( FRAME_SCH_LIB_EDITOR ) || frame->IsType( FRAME_PCB_MODULE_EDITOR ) )
// Leave a bigger margin for library editors & viewers
if( frame->IsType( FRAME_SCH_LIB_EDITOR ) || frame->IsType( FRAME_PCB_MODULE_EDITOR ) )
{
margin_scale_factor = 1.2;
margin_scale_factor = 2;
}
else if( frame->IsType( FRAME_PCB_MODULE_VIEWER ) || frame->IsType( FRAME_PCB_MODULE_VIEWER_MODAL )
|| frame->IsType( FRAME_SCH_VIEWER ) || frame->IsType( FRAME_SCH_VIEWER_MODAL ) )
{
margin_scale_factor = 1.4;
}
view->SetScale( scale / margin_scale_factor );

View File

@ -54,17 +54,10 @@ static struct IFACE : public KIFACE_I
{
switch( aClassId )
{
case FRAME_CVPCB:
return new CVPCB_MAINFRAME( aKiway, aParent );
case FRAME_CVPCB_DISPLAY:
return new DISPLAY_FOOTPRINTS_FRAME( aKiway, aParent );
default:
;
case FRAME_CVPCB: return new CVPCB_MAINFRAME( aKiway, aParent );
case FRAME_CVPCB_DISPLAY: return new DISPLAY_FOOTPRINTS_FRAME( aKiway, aParent );
default: return NULL;
}
return NULL;
}
/**

View File

@ -244,30 +244,6 @@ void LIB_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event )
}
double LIB_EDIT_FRAME::BestZoom()
{
LIB_PART* part = GetCurPart();
double defaultLibraryZoom = 7.33;
if( !part )
{
GetCanvas()->GetView()->SetCenter( VECTOR2D( 0, 0 ) );
return defaultLibraryZoom;
}
EDA_RECT boundingBox = part->GetUnitBoundingBox( m_unit, m_convert );
double sizeX = (double) boundingBox.GetWidth();
double sizeY = (double) boundingBox.GetHeight();
wxPoint centre = boundingBox.Centre();
// Reserve a 20% margin around component bounding box.
double margin_scale_factor = 1.2;
return bestZoom( sizeX, sizeY, margin_scale_factor, centre);
}
void LIB_EDIT_FRAME::RebuildSymbolUnitsList()
{
if( !m_unitSelectBox )

View File

@ -243,7 +243,6 @@ public:
void ReCreateHToolbar() override;
void ReCreateVToolbar() override;
void ReCreateOptToolbar() override;
double BestZoom() override; // Returns the best zoom
void LoadSettings( wxConfigBase* aCfg ) override;
void SaveSettings( wxConfigBase* aCfg ) override;

View File

@ -575,20 +575,6 @@ void SCH_EDIT_FRAME::OnCloseWindow( wxCloseEvent& aEvent )
}
double SCH_EDIT_FRAME::BestZoom()
{
double sizeX = (double) GetScreen()->GetPageSettings().GetWidthIU();
double sizeY = (double) GetScreen()->GetPageSettings().GetHeightIU();
wxPoint centre( wxPoint( sizeX / 2, sizeY / 2 ) );
// The sheet boundary already affords us some margin, so add only an
// additional 5%.
double margin_scale_factor = 1.05;
return bestZoom( sizeX, sizeY, margin_scale_factor, centre );
}
wxString SCH_EDIT_FRAME::GetUniqueFilenameForCurrentSheet()
{
wxFileName fn = GetScreen()->GetFileName();

View File

@ -311,8 +311,6 @@ public:
void KiwayMailIn( KIWAY_EXPRESS& aEvent ) override;
double BestZoom() override;
/**
* Add an item to the schematic and adds the changes to the undo/redo container.
* @param aUndoAppend True if the action should be appended to the current undo record.

View File

@ -399,49 +399,6 @@ void LIB_VIEW_FRAME::onUpdateUnitChoice( wxUpdateUIEvent& aEvent )
}
double LIB_VIEW_FRAME::BestZoom()
{
LIB_PART* part = nullptr;
double defaultLibraryZoom = 7.33;
if( m_libraryName.IsEmpty() || m_entryName.IsEmpty() )
{
GetCanvas()->GetView()->SetCenter( VECTOR2D( 0, 0 ) );
return defaultLibraryZoom;
}
LIB_ALIAS* alias = nullptr;
try
{
alias = Prj().SchSymbolLibTable()->LoadSymbol( m_libraryName, m_entryName );
}
catch( ... )
{
}
if( alias )
part = alias->GetPart();
if( !part )
{
GetCanvas()->GetView()->SetCenter( VECTOR2D( 0, 0 ) );
return defaultLibraryZoom;
}
EDA_RECT boundingBox = part->GetUnitBoundingBox( m_unit, m_convert );
double sizeX = (double) boundingBox.GetWidth();
double sizeY = (double) boundingBox.GetHeight();
wxPoint centre = boundingBox.Centre();
// Reserve a 20% margin around component bounding box.
double margin_scale_factor = 1.2;
return bestZoom( sizeX, sizeY, margin_scale_factor, centre );
}
bool LIB_VIEW_FRAME::ReCreateListLib()
{
if( !m_libList )

View File

@ -96,7 +96,6 @@ public:
void ReCreateOptToolbar() override {}
void ReCreateMenuBar() override;
double BestZoom() override;
void ClickOnLibList( wxCommandEvent& event );
void ClickOnCmpList( wxCommandEvent& event );
void OnSelectSymbol( wxCommandEvent& aEvent );

View File

@ -22,7 +22,6 @@
#include <kiface_i.h>
#include <pgm_base.h>
#include <eda_base_frame.h>
#include <build_version.h>
#include <trigo.h>
#include <base_units.h>
#include <gbr_layer_box_selector.h>
@ -35,7 +34,6 @@
#include <gerbview_id.h>
#include <gerber_file_image.h>
#include <gerber_file_image_list.h>
#include <dialog_helpers.h>
#include <DCodeSelectionbox.h>
#include <gerbview_layer_widget.h>
#include <gerbview_draw_panel_gal.h>
@ -303,28 +301,6 @@ bool GERBVIEW_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
}
double GERBVIEW_FRAME::BestZoom()
{
EDA_RECT bbox = GetGerberLayout()->ComputeBoundingBox();
// Reserve a margin around the bounding box, for a better display.
double margin_scale_factor = 1.05;
// If there is not item loaded, use the current page size
if( bbox.GetWidth() == 0 || bbox.GetHeight() == 0 )
{
bbox.SetSize( GetPageSizeIU() );
bbox.SetOrigin( 0, 0 );
}
double sizeX = (double) bbox.GetWidth();
double sizeY = (double) bbox.GetHeight();
wxPoint centre = bbox.Centre();
return bestZoom( sizeX, sizeY, margin_scale_factor, centre );
}
void GERBVIEW_FRAME::LoadSettings( wxConfigBase* aCfg )
{
EDA_DRAW_FRAME::LoadSettings( aCfg );

View File

@ -224,7 +224,6 @@ public:
void ReCreateMenuBar() override;
void OnUpdateSelectZoom( wxUpdateUIEvent& aEvent );
double BestZoom() override;
void UpdateStatusBar() override;
/**

View File

@ -134,8 +134,6 @@ protected:
virtual void SetScreen( BASE_SCREEN* aScreen ) { m_currentScreen = aScreen; }
double bestZoom( double sizeX, double sizeY, double scaleFactor, wxPoint centre );
void unitsChangeRefresh() override;
void CommonSettingsChanged( bool aEnvVarsChanged ) override;
@ -351,9 +349,6 @@ public:
*/
virtual void Zoom_Automatique( bool aWarpPointer );
/** Return the zoom level which displays the full page on screen */
virtual double BestZoom() = 0;
/**
* Useful to focus on a particular location, in find functions
* Move the graphic cursor (crosshair cursor) at a given coordinate and reframes

View File

@ -206,12 +206,6 @@ public:
void UpdateGridSelectBox();
/**
* Function BestZoom
* @return the "best" zoom to show the entire board or footprint on the screen.
*/
virtual double BestZoom() override;
/**
* Function GetZoomLevelIndicator
* returns a human readable value which can be displayed as zoom

View File

@ -376,20 +376,6 @@ const BOX2I PL_EDITOR_FRAME::GetDocumentExtents() const
}
double PL_EDITOR_FRAME::BestZoom()
{
double sizeX = (double) GetPageLayout().GetPageSettings().GetWidthIU();
double sizeY = (double) GetPageLayout().GetPageSettings().GetHeightIU();
wxPoint centre( KiROUND( sizeX / 2 ), KiROUND( sizeY / 2 ) );
// The sheet boundary already affords us some margin, so add only an
// additional 5%.
double margin_scale_factor = 1.05;
return bestZoom( sizeX, sizeY, margin_scale_factor, centre );
}
void PL_EDITOR_FRAME::InstallPreferences( PAGED_DIALOG* aParent,
PANEL_HOTKEYS_EDITOR* aHotkeysPanel )
{

View File

@ -181,7 +181,6 @@ public:
void ReCreateOptToolbar() override;
void ReCreateMenuBar() override;
double BestZoom() override;
void SyncToolbars() override;

View File

@ -28,12 +28,9 @@
#include <pcb_draw_panel_gal.h>
#include <confirm.h>
#include <pcb_edit_frame.h>
#include <dialog_helpers.h>
#include <3d_viewer/eda_3d_viewer.h>
#include <msgpanel.h>
#include <fp_lib_table.h>
#include <bitmaps.h>
#include <gal/graphics_abstraction_layer.h>
#include <eda_dockart.h>
#include <class_board.h>
#include <class_module.h>
@ -43,7 +40,6 @@
#include <footprint_viewer_frame.h>
#include <wildcards_and_files_ext.h>
#include <pcb_layer_widget.h>
#include <invoke_pcb_dialog.h>
#include <tool/tool_manager.h>
#include <tool/common_control.h>
#include <tool/common_tools.h>
@ -52,7 +48,6 @@
#include <tool/zoom_tool.h>
#include <footprint_tree_pane.h>
#include <widgets/lib_tree.h>
#include <fp_lib_table.h>
#include <footprint_info_impl.h>
#include <widgets/paged_dialog.h>
#include <dialogs/panel_modedit_settings.h>
@ -432,18 +427,14 @@ void FOOTPRINT_EDIT_FRAME::SaveSettings( wxConfigBase* aCfg )
}
double FOOTPRINT_EDIT_FRAME::BestZoom()
const BOX2I FOOTPRINT_EDIT_FRAME::GetDocumentExtents() const
{
EDA_RECT ibbbox = GetBoardBoundingBox();
MODULE* module = GetBoard()->GetFirstModule();
double sizeX = (double) ibbbox.GetWidth();
double sizeY = (double) ibbbox.GetHeight();
wxPoint centre = ibbbox.Centre();
// Reserve a 20% margin around "board" bounding box.
double margin_scale_factor = 1.2;
return bestZoom( sizeX, sizeY, margin_scale_factor, centre );
if( module )
return module->GetFootprintRect();
else
return GetBoardBoundingBox( false );
}

View File

@ -72,7 +72,7 @@ public:
void LoadSettings( wxConfigBase* aCfg ) override;
void SaveSettings( wxConfigBase* aCfg ) override;
double BestZoom() override;
const BOX2I GetDocumentExtents() const override;
/**
* Return the footprint editor settings list.

View File

@ -184,18 +184,17 @@ void PCB_BASE_FRAME::AddModuleToBoard( MODULE* module )
module->SetFlags( IS_NEW );
module->SetPosition( wxPoint( 0, 0 ) ); // cursor in GAL may not be initialized at the moment
module->SetPosition( wxPoint( 0, 0 ) ); // cursor in GAL may not be initialized yet
module->SetTimeStamp( GetNewTimeStamp() );
// Put it on FRONT layer,
// (Can be stored flipped if the lib is an archive built from a board)
// Put it on FRONT layer (note that it might be stored flipped if the lib is an archive
// built from a board)
if( module->IsFlipped() )
module->Flip( module->GetPosition(), m_configSettings.m_FlipLeftRight );
// Place it in orientation 0,
// even if it is not saved with orientation 0 in lib
// (Can happen if the lib is an archive built from a board)
// Place it in orientation 0 even if it is not saved with orientation 0 in lib (note that
// it might be stored in another orientation if the lib is an archive built from a board)
module->SetOrientation( 0 );
}
}
@ -346,21 +345,6 @@ EDA_RECT PCB_BASE_FRAME::GetBoardBoundingBox( bool aBoardEdgesOnly ) const
}
double PCB_BASE_FRAME::BestZoom()
{
EDA_RECT ibbbox = GetBoardBoundingBox();
double sizeX = (double) ibbbox.GetWidth();
double sizeY = (double) ibbbox.GetHeight();
wxPoint centre = ibbbox.Centre();
// Reserve a 10% margin around board bounding box.
double margin_scale_factor = 1.1;
return bestZoom( sizeX, sizeY, margin_scale_factor, centre );
}
// Virtual function
void PCB_BASE_FRAME::ReCreateMenuBar()
{