Browse Source
Move TOOL_ACTIONs to their corresponding tools; create COMMON_TOOLS
Move TOOL_ACTIONs to their corresponding tools; create COMMON_TOOLS
Some grid/zoom tools are left in PCBNEW_CONTROL because they currently depend on Pcbnew-specific class members. Once refactoring is done to make it possible to use all zoom and grid controls outside of pcbnew, these last tools can be moved to common to match their ACTIONs.pull/3/merge
committed by
Maciej Suminski
26 changed files with 908 additions and 765 deletions
-
2common/CMakeLists.txt
-
63common/tool/actions.cpp
-
150common/tool/common_tools.cpp
-
18include/tool/actions.h
-
68include/tool/common_tools.h
-
2pcbnew/dialogs/dialog_set_grid.cpp
-
2pcbnew/moduleframe.cpp
-
2pcbnew/modview_frame.cpp
-
37pcbnew/router/router_tool.cpp
-
62pcbnew/tools/drawing_tool.cpp
-
88pcbnew/tools/edit_tool.cpp
-
2pcbnew/tools/grid_menu.cpp
-
28pcbnew/tools/module_editor_tools.cpp
-
20pcbnew/tools/pad_tool.cpp
-
644pcbnew/tools/pcb_actions.cpp
-
18pcbnew/tools/pcb_actions.h
-
91pcbnew/tools/pcb_editor_control.cpp
-
264pcbnew/tools/pcbnew_control.cpp
-
6pcbnew/tools/pcbnew_control.h
-
3pcbnew/tools/picker_tool.cpp
-
33pcbnew/tools/placement_tool.cpp
-
11pcbnew/tools/point_editor.cpp
-
47pcbnew/tools/selection_tool.cpp
-
8pcbnew/tools/tool_menu.cpp
-
2pcbnew/tools/tools_common.cpp
-
2pcbnew/tools/zoom_menu.cpp
@ -0,0 +1,63 @@ |
|||
#include <tool/actions.h>
|
|||
#include <hotkeys.h>
|
|||
#include <bitmaps.h>
|
|||
|
|||
// These members are static in class ACTIONS: Build them here:
|
|||
|
|||
// View Controls
|
|||
TOOL_ACTION ACTIONS::zoomIn( "common.Control.zoomIn", |
|||
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_ZOOM_IN ), |
|||
_( "Zoom In" ), "", zoom_in_xpm ); |
|||
|
|||
TOOL_ACTION ACTIONS::zoomOut( "common.Control.zoomOut", |
|||
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_ZOOM_OUT ), |
|||
_( "Zoom Out" ), "", zoom_out_xpm ); |
|||
|
|||
TOOL_ACTION ACTIONS::zoomInCenter( "common.Control.zoomInCenter", |
|||
AS_GLOBAL, 0, |
|||
"", "" ); |
|||
|
|||
TOOL_ACTION ACTIONS::zoomOutCenter( "common.Control.zoomOutCenter", |
|||
AS_GLOBAL, 0, |
|||
"", "" ); |
|||
|
|||
TOOL_ACTION ACTIONS::zoomCenter( "common.Control.zoomCenter", |
|||
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_ZOOM_CENTER ), |
|||
_( "Center" ), "", zoom_center_on_screen_xpm ); |
|||
|
|||
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::zoomPreset( "common.Control.zoomPreset", |
|||
AS_GLOBAL, 0, |
|||
"", "" ); |
|||
|
|||
// Grid control
|
|||
TOOL_ACTION ACTIONS::gridFast1( "common.Control.gridFast1", |
|||
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_SWITCH_GRID_TO_FASTGRID1 ), |
|||
"", "" ); |
|||
|
|||
TOOL_ACTION ACTIONS::gridFast2( "common.Control.gridFast2", |
|||
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_SWITCH_GRID_TO_FASTGRID2 ), |
|||
"", "" ); |
|||
|
|||
TOOL_ACTION ACTIONS::gridNext( "common.Control.gridNext", |
|||
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_SWITCH_GRID_TO_NEXT ), |
|||
"", "" ); |
|||
|
|||
TOOL_ACTION ACTIONS::gridPrev( "common.Control.gridPrev", |
|||
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_SWITCH_GRID_TO_PREVIOUS ), |
|||
"", "" ); |
|||
|
|||
TOOL_ACTION ACTIONS::gridSetOrigin( "common.Control.gridSetOrigin", |
|||
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_SET_GRID_ORIGIN ), |
|||
"", "" ); |
|||
|
|||
TOOL_ACTION ACTIONS::gridResetOrigin( "common.Control.gridResetOrigin", |
|||
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_RESET_GRID_ORIGIN ), |
|||
"", "" ); |
|||
|
|||
TOOL_ACTION ACTIONS::gridPreset( "common.Control.gridPreset", |
|||
AS_GLOBAL, 0, |
|||
"", "" ); |
@ -0,0 +1,150 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2014-2016 CERN |
|||
* @author Maciej Suminski <maciej.suminski@cern.ch> |
|||
* |
|||
* 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 Free Software Foundation; either version 2 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, you may find one here: |
|||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|||
* or you may search the http://www.gnu.org website for the version 2 license,
|
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
#include <tool/actions.h>
|
|||
#include <draw_frame.h>
|
|||
#include <class_draw_panel_gal.h>
|
|||
#include <view/view.h>
|
|||
#include <view/view_controls.h>
|
|||
#include <gal/graphics_abstraction_layer.h>
|
|||
#include <class_base_screen.h>
|
|||
|
|||
#include <tool/common_tools.h>
|
|||
|
|||
COMMON_TOOLS::COMMON_TOOLS() : |
|||
TOOL_INTERACTIVE( "common.Control" ), m_frame( NULL ) |
|||
{ |
|||
} |
|||
|
|||
|
|||
COMMON_TOOLS::~COMMON_TOOLS() |
|||
{ |
|||
} |
|||
|
|||
|
|||
void COMMON_TOOLS::Reset( RESET_REASON aReason ) |
|||
{ |
|||
m_frame = getEditFrame<EDA_DRAW_FRAME>(); |
|||
} |
|||
|
|||
|
|||
int COMMON_TOOLS::ZoomInOut( const TOOL_EVENT& aEvent ) |
|||
{ |
|||
KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView(); |
|||
KIGFX::VIEW_CONTROLS* ctls = getViewControls(); |
|||
double zoomScale = 1.0; |
|||
|
|||
if( aEvent.IsAction( &ACTIONS::zoomIn ) ) |
|||
zoomScale = 1.3; |
|||
else if( aEvent.IsAction( &ACTIONS::zoomOut ) ) |
|||
zoomScale = 0.7; |
|||
|
|||
view->SetScale( view->GetScale() * zoomScale, getViewControls()->GetCursorPosition() ); |
|||
|
|||
if( ctls->IsCursorWarpingEnabled() ) |
|||
ctls->CenterOnCursor(); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
int COMMON_TOOLS::ZoomInOutCenter( const TOOL_EVENT& aEvent ) |
|||
{ |
|||
KIGFX::VIEW* view = getView(); |
|||
double zoomScale = 1.0; |
|||
|
|||
if( aEvent.IsAction( &ACTIONS::zoomInCenter ) ) |
|||
zoomScale = 1.3; |
|||
else if( aEvent.IsAction( &ACTIONS::zoomOutCenter ) ) |
|||
zoomScale = 0.7; |
|||
|
|||
view->SetScale( view->GetScale() * zoomScale ); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
int COMMON_TOOLS::ZoomCenter( const TOOL_EVENT& aEvent ) |
|||
{ |
|||
KIGFX::VIEW_CONTROLS* ctls = getViewControls(); |
|||
|
|||
if( ctls->IsCursorWarpingEnabled() ) |
|||
ctls->CenterOnCursor(); |
|||
else |
|||
getView()->SetCenter( getViewControls()->GetCursorPosition() ); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
// Grid control
|
|||
int COMMON_TOOLS::GridNext( const TOOL_EVENT& aEvent ) |
|||
{ |
|||
m_frame->SetNextGrid(); |
|||
updateGrid(); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
int COMMON_TOOLS::GridPrev( const TOOL_EVENT& aEvent ) |
|||
{ |
|||
m_frame->SetPrevGrid(); |
|||
updateGrid(); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
int COMMON_TOOLS::GridPreset( const TOOL_EVENT& aEvent ) |
|||
{ |
|||
long idx = aEvent.Parameter<intptr_t>(); |
|||
|
|||
m_frame->SetPresetGrid( idx ); |
|||
updateGrid(); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
void COMMON_TOOLS::SetTransitions() |
|||
{ |
|||
Go( &COMMON_TOOLS::ZoomInOut, ACTIONS::zoomIn.MakeEvent() ); |
|||
Go( &COMMON_TOOLS::ZoomInOut, ACTIONS::zoomOut.MakeEvent() ); |
|||
Go( &COMMON_TOOLS::ZoomInOutCenter, ACTIONS::zoomInCenter.MakeEvent() ); |
|||
Go( &COMMON_TOOLS::ZoomInOutCenter, ACTIONS::zoomOutCenter.MakeEvent() ); |
|||
Go( &COMMON_TOOLS::ZoomCenter, ACTIONS::zoomCenter.MakeEvent() ); |
|||
|
|||
Go( &COMMON_TOOLS::GridNext, ACTIONS::gridNext.MakeEvent() ); |
|||
Go( &COMMON_TOOLS::GridPrev, ACTIONS::gridPrev.MakeEvent() ); |
|||
Go( &COMMON_TOOLS::GridPreset, ACTIONS::gridPreset.MakeEvent() ); |
|||
} |
|||
|
|||
|
|||
void COMMON_TOOLS::updateGrid() |
|||
{ |
|||
BASE_SCREEN* screen = m_frame->GetScreen(); |
|||
getView()->GetGAL()->SetGridSize( VECTOR2D( screen->GetGridSize() ) ); |
|||
getView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); |
|||
} |
@ -0,0 +1,68 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2014-2016 CERN |
|||
* @author Maciej Suminski <maciej.suminski@cern.ch> |
|||
* |
|||
* 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 Free Software Foundation; either version 2 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, you may find one here: |
|||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
|||
* or you may search the http://www.gnu.org website for the version 2 license, |
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
#ifndef _COMMON_TOOLS_H |
|||
#define _COMMON_TOOLS_H |
|||
|
|||
#include <tool/tool_interactive.h> |
|||
|
|||
class EDA_DRAW_FRAME; |
|||
|
|||
/** |
|||
* Class COMMON_TOOLS |
|||
* |
|||
* Handles actions that are shared between different applications |
|||
*/ |
|||
|
|||
class COMMON_TOOLS : public TOOL_INTERACTIVE |
|||
{ |
|||
public: |
|||
COMMON_TOOLS(); |
|||
~COMMON_TOOLS(); |
|||
|
|||
/// @copydoc TOOL_BASE::Reset() |
|||
void Reset( RESET_REASON aReason ) override; |
|||
|
|||
// View controls |
|||
int ZoomInOut( const TOOL_EVENT& aEvent ); |
|||
int ZoomInOutCenter( const TOOL_EVENT& aEvent ); |
|||
int ZoomCenter( const TOOL_EVENT& aEvent ); |
|||
|
|||
// Grid control |
|||
int GridNext( const TOOL_EVENT& aEvent ); |
|||
int GridPrev( const TOOL_EVENT& aEvent ); |
|||
int GridPreset( const TOOL_EVENT& aEvent ); |
|||
|
|||
///> Sets up handlers for various events. |
|||
void SetTransitions() override; |
|||
|
|||
private: |
|||
///> Pointer to the currently used edit frame. |
|||
EDA_DRAW_FRAME* m_frame; |
|||
|
|||
///> Applies the legacy canvas grid settings for GAL. |
|||
void updateGrid(); |
|||
}; |
|||
|
|||
#endif |
Write
Preview
Loading…
Cancel
Save
Reference in new issue