Move ZOOM_TOOL to common; add RMB-drag to zoom out
This commit is contained in:
parent
21c104fcc7
commit
eec1366ead
|
@ -337,6 +337,7 @@ set( COMMON_SRCS
|
|||
tool/tool_menu.cpp
|
||||
tool/conditional_menu.cpp
|
||||
tool/selection_conditions.cpp
|
||||
tool/zoom_tool.cpp
|
||||
|
||||
geometry/seg.cpp
|
||||
geometry/shape.cpp
|
||||
|
|
|
@ -35,6 +35,10 @@ TOOL_ACTION ACTIONS::zoomFitScreen( "common.Control.zoomFitScreen",
|
|||
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_ZOOM_AUTO ),
|
||||
_( "Zoom Auto" ), "", zoom_fit_in_page_xpm );
|
||||
|
||||
TOOL_ACTION ACTIONS::zoomTool( "common.Control.zoomTool",
|
||||
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_ZOOM_SELECTION ),
|
||||
_( "Zoom to Selection" ), "", NULL, AF_ACTIVATE );
|
||||
|
||||
TOOL_ACTION ACTIONS::zoomPreset( "common.Control.zoomPreset",
|
||||
AS_GLOBAL, 0,
|
||||
"", "" );
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
|
@ -23,14 +23,13 @@
|
|||
#include <view/view_controls.h>
|
||||
#include <view/view.h>
|
||||
#include <tool/tool_manager.h>
|
||||
#include <tool/actions.h>
|
||||
#include <tool/zoom_tool.h>
|
||||
#include <preview_items/selection_area.h>
|
||||
|
||||
#include "zoom_tool.h"
|
||||
#include "pcb_actions.h"
|
||||
|
||||
|
||||
ZOOM_TOOL::ZOOM_TOOL() :
|
||||
TOOL_INTERACTIVE( "pcbnew.Control.zoomTool" )
|
||||
TOOL_INTERACTIVE( "common.Control.zoomTool" )
|
||||
{
|
||||
m_frame = NULL;
|
||||
}
|
||||
|
@ -41,14 +40,14 @@ ZOOM_TOOL::~ZOOM_TOOL() {}
|
|||
|
||||
void ZOOM_TOOL::Reset( RESET_REASON aReason )
|
||||
{
|
||||
m_frame = getEditFrame<PCB_EDIT_FRAME>();
|
||||
m_frame = getEditFrame<EDA_DRAW_FRAME>();
|
||||
}
|
||||
|
||||
|
||||
int ZOOM_TOOL::Main( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
// This method is called both when the zoom tool is activated (on) or deactivated (off)
|
||||
bool zoom_tool_is_on = m_frame->GetMainToolBar()->GetToolToggled( ID_ZOOM_SELECTION );
|
||||
bool zoom_tool_is_on = m_frame->GetToolToggled( ID_ZOOM_SELECTION );
|
||||
|
||||
if( !zoom_tool_is_on ) // This is a tool deselection: do nothing
|
||||
return 0;
|
||||
|
@ -60,7 +59,7 @@ int ZOOM_TOOL::Main( const TOOL_EVENT& aEvent )
|
|||
if( evt->IsCancel() || evt->IsActivate() )
|
||||
break;
|
||||
|
||||
else if( evt->IsDrag( BUT_LEFT ) )
|
||||
else if( evt->IsDrag( BUT_LEFT ) || evt->IsDrag( BUT_RIGHT ) )
|
||||
{
|
||||
if( selectRegion() )
|
||||
break;
|
||||
|
@ -94,7 +93,7 @@ bool ZOOM_TOOL::selectRegion()
|
|||
break;
|
||||
}
|
||||
|
||||
if( evt->IsDrag( BUT_LEFT ) )
|
||||
if( evt->IsDrag( BUT_LEFT ) || evt->IsDrag( BUT_RIGHT ) )
|
||||
{
|
||||
area.SetOrigin( evt->DragOrigin() );
|
||||
area.SetEnd( evt->Position() );
|
||||
|
@ -102,7 +101,7 @@ bool ZOOM_TOOL::selectRegion()
|
|||
view->Update( &area, KIGFX::GEOMETRY );
|
||||
}
|
||||
|
||||
if( evt->IsMouseUp( BUT_LEFT ) )
|
||||
if( evt->IsMouseUp( BUT_LEFT ) || evt->IsMouseUp( BUT_RIGHT ) )
|
||||
{
|
||||
view->SetVisible( &area, false );
|
||||
auto selectionBox = area.ViewBBox();
|
||||
|
@ -116,8 +115,19 @@ bool ZOOM_TOOL::selectRegion()
|
|||
else
|
||||
{
|
||||
VECTOR2D vsize = selectionBox.GetSize();
|
||||
double scale = view->GetScale() / std::max( fabs( vsize.x / screenSize.x ),
|
||||
fabs( vsize.y / screenSize.y ) );
|
||||
double scale;
|
||||
double ratio = std::max( fabs( vsize.x / screenSize.x ),
|
||||
fabs( vsize.y / screenSize.y ) );
|
||||
|
||||
if( evt->IsMouseUp( BUT_LEFT ) )
|
||||
{
|
||||
scale = view->GetScale() / ratio;
|
||||
}
|
||||
else
|
||||
{
|
||||
scale = view->GetScale() * ratio;
|
||||
}
|
||||
|
||||
view->SetScale( scale );
|
||||
view->SetCenter( selectionBox.Centre() );
|
||||
|
||||
|
@ -136,5 +146,5 @@ bool ZOOM_TOOL::selectRegion()
|
|||
|
||||
void ZOOM_TOOL::setTransitions()
|
||||
{
|
||||
Go( &ZOOM_TOOL::Main, PCB_ACTIONS::zoomTool.MakeEvent() );
|
||||
Go( &ZOOM_TOOL::Main, ACTIONS::zoomTool.MakeEvent() );
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
|
@ -22,7 +22,7 @@
|
|||
|
||||
#include <tool/tool_interactive.h>
|
||||
|
||||
class PCB_EDIT_FRAME;
|
||||
class EDA_DRAW_FRAME;
|
||||
|
||||
|
||||
class ZOOM_TOOL : public TOOL_INTERACTIVE
|
||||
|
@ -42,7 +42,7 @@ public:
|
|||
|
||||
private:
|
||||
bool selectRegion();
|
||||
PCB_EDIT_FRAME* m_frame;
|
||||
EDA_DRAW_FRAME* m_frame;
|
||||
};
|
||||
|
||||
#endif // _ZOOM_TOOL_H
|
|
@ -392,6 +392,20 @@ public:
|
|||
// Toolbar accessors
|
||||
wxAuiToolBar* GetMainToolBar() const { return m_mainToolBar; }
|
||||
|
||||
/**
|
||||
* Checks all the toolbars and returns true if the given tool id is toggled.
|
||||
*
|
||||
* This is needed because GerbView and Pcbnew put some of the same tools in
|
||||
* different toolbars (for example, zoom selection is in the main bar in
|
||||
* Pcbnew and in the options bar in GerbView).
|
||||
*/
|
||||
bool GetToolToggled( int aToolId )
|
||||
{
|
||||
return ( m_mainToolBar->GetToolToggled( aToolId ) ||
|
||||
m_optionsToolBar->GetToolToggled( aToolId ) ||
|
||||
m_drawToolBar->GetToolToggled( aToolId ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Function SetToolID
|
||||
* sets the tool command ID to \a aId and sets the cursor to \a aCursor. The
|
||||
|
|
|
@ -55,6 +55,7 @@ public:
|
|||
static TOOL_ACTION zoomCenter;
|
||||
static TOOL_ACTION zoomFitScreen;
|
||||
static TOOL_ACTION zoomPreset;
|
||||
static TOOL_ACTION zoomTool;
|
||||
|
||||
// Grid control
|
||||
static TOOL_ACTION gridFast1;
|
||||
|
|
|
@ -310,7 +310,6 @@ set( PCBNEW_CLASS_SRCS
|
|||
tools/grid_helper.cpp
|
||||
tools/pad_tool.cpp
|
||||
tools/picker_tool.cpp
|
||||
tools/zoom_tool.cpp
|
||||
tools/zone_create_helper.cpp
|
||||
tools/tools_common.cpp
|
||||
tools/tool_event_utils.cpp
|
||||
|
|
|
@ -62,9 +62,9 @@
|
|||
#include <tool/tool_manager.h>
|
||||
#include <tool/common_tools.h>
|
||||
#include <tool/tool_dispatcher.h>
|
||||
#include <tool/zoom_tool.h>
|
||||
|
||||
#include "tools/selection_tool.h"
|
||||
#include "tools/zoom_tool.h"
|
||||
#include "tools/edit_tool.h"
|
||||
#include "tools/drawing_tool.h"
|
||||
#include "tools/point_editor.h"
|
||||
|
|
|
@ -145,7 +145,7 @@ boost::optional<TOOL_EVENT> PCB_ACTIONS::TranslateLegacyId( int aId )
|
|||
return PCB_ACTIONS::selectionTool.MakeEvent();
|
||||
|
||||
case ID_ZOOM_SELECTION:
|
||||
return PCB_ACTIONS::zoomTool.MakeEvent();
|
||||
return ACTIONS::zoomTool.MakeEvent();
|
||||
|
||||
case ID_PCB_DELETE_ITEM_BUTT:
|
||||
case ID_MODEDIT_DELETE_TOOL:
|
||||
|
|
|
@ -204,7 +204,7 @@ public:
|
|||
|
||||
/// Activation of the Push and Shove router (inline dragging mode)
|
||||
static TOOL_ACTION routerInlineDrag;
|
||||
|
||||
|
||||
// Point Editor
|
||||
/// Break outline (insert additional points to an edge)
|
||||
static TOOL_ACTION pointEditorAddCorner;
|
||||
|
@ -354,7 +354,6 @@ public:
|
|||
|
||||
// Miscellaneous
|
||||
static TOOL_ACTION selectionTool;
|
||||
static TOOL_ACTION zoomTool;
|
||||
static TOOL_ACTION pickerTool;
|
||||
static TOOL_ACTION resetCoords;
|
||||
static TOOL_ACTION measureTool;
|
||||
|
|
|
@ -197,10 +197,6 @@ TOOL_ACTION PCB_ACTIONS::selectionTool( "pcbnew.Control.selectionTool",
|
|||
AS_GLOBAL, 0,
|
||||
"", "", NULL, AF_ACTIVATE );
|
||||
|
||||
TOOL_ACTION PCB_ACTIONS::zoomTool( "pcbnew.Control.zoomTool",
|
||||
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_ZOOM_SELECTION ),
|
||||
_( "Zoom to Selection" ), "", NULL, AF_ACTIVATE );
|
||||
|
||||
TOOL_ACTION PCB_ACTIONS::resetCoords( "pcbnew.Control.resetCoords",
|
||||
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_RESET_LOCAL_COORD ),
|
||||
"", "" );
|
||||
|
|
|
@ -27,9 +27,9 @@
|
|||
|
||||
#include <tool/tool_manager.h>
|
||||
#include <tool/common_tools.h>
|
||||
#include <tool/zoom_tool.h>
|
||||
|
||||
#include <tools/selection_tool.h>
|
||||
#include <tools/zoom_tool.h>
|
||||
#include <tools/picker_tool.h>
|
||||
#include <tools/edit_tool.h>
|
||||
#include <tools/drawing_tool.h>
|
||||
|
|
Loading…
Reference in New Issue