7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-20 00:21:31 +00:00

Add a zoom/pan-to-selection actions

This is useful is some process ends up doing sometihng
offcreen and wants to show you.
This commit is contained in:
John Beard 2024-11-02 00:56:10 +08:00
parent 88df35654e
commit c6f7fa9b6e
4 changed files with 74 additions and 6 deletions

View File

@ -582,6 +582,11 @@ TOOL_ACTION ACTIONS::zoomFitObjects( TOOL_ACTION_ARGS()
.FriendlyName( _( "Zoom to Objects" ) )
.Icon( BITMAPS::zoom_fit_to_objects ) );
TOOL_ACTION ACTIONS::zoomFitSelection( TOOL_ACTION_ARGS()
.Name( "common.Control.zoomFitSelection" )
.Scope( AS_GLOBAL )
.FriendlyName( _( "Zoom to Selected Objects" ) ) );
TOOL_ACTION ACTIONS::zoomIn( TOOL_ACTION_ARGS()
.Name( "common.Control.zoomIn" )
.Scope( AS_GLOBAL )
@ -686,6 +691,11 @@ TOOL_ACTION ACTIONS::centerContents( TOOL_ACTION_ARGS()
.Name( "common.Control.centerContents" )
.Scope( AS_GLOBAL ) );
TOOL_ACTION ACTIONS::centerSelection( TOOL_ACTION_ARGS()
.Name( "common.Control.centerSelection" )
.Scope( AS_GLOBAL )
.FriendlyName( _( "Pan to Center Selected Objects" ) ) );
// Cursor control
TOOL_ACTION ACTIONS::cursorUp( TOOL_ACTION_ARGS()
.Name( "common.Control.cursorUp" )

View File

@ -304,6 +304,12 @@ int COMMON_TOOLS::ZoomFitObjects( const TOOL_EVENT& aEvent )
}
int COMMON_TOOLS::ZoomFitSelection( const TOOL_EVENT& aEvent )
{
return doZoomFit( ZOOM_FIT_SELECTION );
}
int COMMON_TOOLS::doZoomFit( ZOOM_FIT_TYPE_T aFitType )
{
KIGFX::VIEW* view = getView();
@ -335,6 +341,16 @@ int COMMON_TOOLS::doZoomFit( ZOOM_FIT_TYPE_T aFitType )
aFitType = ZOOM_FIT_ALL; // Just do a "Zoom to Fit" for unsupported editors
}
if( aFitType == ZOOM_FIT_SELECTION )
{
SELECTION& selection = m_frame->GetCurrentSelection();
if( selection.Empty() )
return 0;
bBox = selection.GetBoundingBox();
}
// If the screen is empty then use the default view bbox
if( bBox.GetWidth() == 0 || bBox.GetHeight() == 0 )
@ -384,13 +400,40 @@ int COMMON_TOOLS::doZoomFit( ZOOM_FIT_TYPE_T aFitType )
}
int COMMON_TOOLS::CenterSelection( const TOOL_EVENT& aEvent )
{
return doCenter( CENTER_TYPE::CENTER_SELECTION );
}
int COMMON_TOOLS::CenterContents( const TOOL_EVENT& aEvent )
{
EDA_DRAW_PANEL_GAL* canvas = m_frame->GetCanvas();
BOX2I bBox = getModel<EDA_ITEM>()->ViewBBox();
return doCenter( CENTER_TYPE::CENTER_CONTENTS );
}
if( bBox.GetWidth() == 0 || bBox.GetHeight() == 0 )
bBox = canvas->GetDefaultViewBBox();
int COMMON_TOOLS::doCenter( CENTER_TYPE aCenterType )
{
EDA_DRAW_PANEL_GAL* canvas = m_frame->GetCanvas();
BOX2I bBox;
if( aCenterType == CENTER_TYPE::CENTER_SELECTION )
{
SELECTION& selection = m_frame->GetCurrentSelection();
// No selection: do nothing
if( selection.Empty() )
return 0;
bBox = selection.GetBoundingBox().Centre();
}
else
{
bBox = getModel<EDA_ITEM>()->ViewBBox();
if( bBox.GetWidth() == 0 || bBox.GetHeight() == 0 )
bBox = canvas->GetDefaultViewBBox();
}
getView()->SetCenter( bBox.Centre() );
@ -725,8 +768,10 @@ void COMMON_TOOLS::setTransitions()
Go( &COMMON_TOOLS::ZoomCenter, ACTIONS::zoomCenter.MakeEvent() );
Go( &COMMON_TOOLS::ZoomFitScreen, ACTIONS::zoomFitScreen.MakeEvent() );
Go( &COMMON_TOOLS::ZoomFitObjects, ACTIONS::zoomFitObjects.MakeEvent() );
Go( &COMMON_TOOLS::ZoomFitSelection, ACTIONS::zoomFitSelection.MakeEvent() );
Go( &COMMON_TOOLS::ZoomPreset, ACTIONS::zoomPreset.MakeEvent() );
Go( &COMMON_TOOLS::CenterContents, ACTIONS::centerContents.MakeEvent() );
Go( &COMMON_TOOLS::CenterSelection, ACTIONS::centerSelection.MakeEvent() );
// Grid control
Go( &COMMON_TOOLS::GridNext, ACTIONS::gridNext.MakeEvent() );

View File

@ -133,11 +133,13 @@ public:
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 zoomFitSelection;
static TOOL_ACTION zoomPreset;
static TOOL_ACTION zoomTool;
static TOOL_ACTION zoomUndo;
static TOOL_ACTION zoomRedo;
static TOOL_ACTION centerContents;
static TOOL_ACTION centerSelection;
static TOOL_ACTION toggleCursor;
static TOOL_ACTION toggleCursorStyle;
static TOOL_ACTION highContrastMode;

View File

@ -53,9 +53,11 @@ public:
int ZoomCenter( const TOOL_EVENT& aEvent );
int ZoomFitScreen( const TOOL_EVENT& aEvent );
int ZoomFitObjects( const TOOL_EVENT& aEvent );
int ZoomFitSelection( const TOOL_EVENT& aEvent );
int ZoomPreset( const TOOL_EVENT& aEvent );
int CenterContents( const TOOL_EVENT& aEvent );
int CenterSelection( const TOOL_EVENT& aEvent );
int PanControl( const TOOL_EVENT& aEvent );
@ -98,8 +100,15 @@ private:
*/
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
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
ZOOM_FIT_SELECTION, ///< Zoom to fit selected items in view
};
enum class CENTER_TYPE
{
CENTER_CONTENTS,
CENTER_SELECTION,
};
///< Sets up handlers for various events.
@ -115,6 +124,8 @@ private:
int doZoomFit( ZOOM_FIT_TYPE_T aFitType );
int doCenter( CENTER_TYPE aCenterType );
std::vector<VECTOR2I> m_grids; ///< Grids from #APP_SETTINGS converted to internal units
///< and with the user grid appended.