2013-07-20 19:36:19 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2013-08-13 17:51:22 +00:00
|
|
|
* Copyright (C) 2013 CERN
|
2018-03-25 15:02:53 +00:00
|
|
|
* Copyright (C) 2016-2018 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-08-13 17:51:22 +00:00
|
|
|
* @author Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2013-07-20 19:36:19 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2016-06-11 13:51:05 +00:00
|
|
|
/**
|
|
|
|
* @file pagelayout_editor/hotkeys.cpp
|
|
|
|
*/
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <kicad_device_context.h>
|
|
|
|
#include <id.h>
|
|
|
|
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <pl_editor_frame.h>
|
2013-07-24 15:11:35 +00:00
|
|
|
#include <design_tree_frame.h>
|
2018-01-29 08:39:13 +00:00
|
|
|
#include <worksheet_dataitem.h>
|
2013-07-19 18:27:22 +00:00
|
|
|
#include <hotkeys.h>
|
2013-07-24 15:11:35 +00:00
|
|
|
#include <pl_editor_id.h>
|
2013-07-19 18:27:22 +00:00
|
|
|
|
|
|
|
|
2015-03-22 14:04:09 +00:00
|
|
|
// Remark: the hotkey message info is used as keyword in hotkey config files and
|
|
|
|
// as comments in help windows, therefore translated only when displayed
|
|
|
|
// they are marked _HKI to be extracted by translation tools
|
|
|
|
// See hotkeys_basic.h for more info
|
|
|
|
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
/* How to add a new hotkey:
|
2013-07-20 19:36:19 +00:00
|
|
|
* add a new id in the enum hotkey_id_commnand like MY_NEW_ID_FUNCTION.
|
|
|
|
* add a new EDA_HOTKEY entry like:
|
2015-03-22 14:04:09 +00:00
|
|
|
* static EDA_HOTKEY HkMyNewEntry(_HKI("Command Label"), MY_NEW_ID_FUNCTION, default key value);
|
2013-07-20 19:36:19 +00:00
|
|
|
* 'Command Label' is the name used in hotkey list display, and the identifier in the
|
|
|
|
* hotkey list file
|
|
|
|
* 'MY_NEW_ID_FUNCTION' is the id event function used in the switch in OnHotKey() function.
|
|
|
|
* 'Default key value' is the default hotkey for this command.
|
|
|
|
* Can be overrided by the user hotkey list
|
|
|
|
* Add the 'HkMyNewEntry' pointer in the s_PlEditor_Hotkey_List list
|
|
|
|
* Add the new code in the switch in OnHotKey() function.
|
2013-07-19 18:27:22 +00:00
|
|
|
*
|
|
|
|
* Note: If an hotkey is a special key, be sure the corresponding wxWidget keycode (WXK_XXXX)
|
|
|
|
* is handled in the hotkey_name_descr s_Hotkey_Name_List list (see hotkeys_basic.cpp)
|
|
|
|
* and see this list for some ascii keys (space ...)
|
|
|
|
*/
|
|
|
|
|
2014-04-03 07:40:55 +00:00
|
|
|
// Hotkey list:
|
|
|
|
|
|
|
|
// mouse click command:
|
2015-03-22 14:04:09 +00:00
|
|
|
static EDA_HOTKEY HkMouseLeftClick( _HKI( "Mouse Left Click" ), HK_LEFT_CLICK, WXK_RETURN, 0 );
|
2018-03-25 15:02:53 +00:00
|
|
|
static EDA_HOTKEY HkMouseLeftDClick( _HKI( "Mouse Left Double Click" ), HK_LEFT_DCLICK,
|
|
|
|
WXK_END, 0 );
|
2014-04-03 07:40:55 +00:00
|
|
|
|
2015-03-22 14:04:09 +00:00
|
|
|
static EDA_HOTKEY HkResetLocalCoord( _HKI( "Reset Local Coordinates" ),
|
2013-07-19 18:27:22 +00:00
|
|
|
HK_RESET_LOCAL_COORD, ' ' );
|
2015-03-22 14:04:09 +00:00
|
|
|
static EDA_HOTKEY HkZoomAuto( _HKI( "Zoom Auto" ), HK_ZOOM_AUTO, WXK_HOME, ID_ZOOM_PAGE );
|
|
|
|
static EDA_HOTKEY HkZoomCenter( _HKI( "Zoom Center" ), HK_ZOOM_CENTER, WXK_F4,
|
2013-07-24 15:11:35 +00:00
|
|
|
ID_POPUP_ZOOM_CENTER );
|
2015-03-22 14:04:09 +00:00
|
|
|
static EDA_HOTKEY HkZoomRedraw( _HKI( "Zoom Redraw" ), HK_ZOOM_REDRAW, WXK_F3, ID_ZOOM_REDRAW );
|
2018-01-12 10:40:55 +00:00
|
|
|
static EDA_HOTKEY HkZoomOut( _HKI( "Zoom Out" ), HK_ZOOM_OUT, WXK_F2, ID_KEY_ZOOM_OUT );
|
|
|
|
static EDA_HOTKEY HkZoomIn( _HKI( "Zoom In" ), HK_ZOOM_IN, WXK_F1, ID_KEY_ZOOM_IN );
|
2018-03-25 15:02:53 +00:00
|
|
|
static EDA_HOTKEY HkZoomSelection( _HKI( "Zoom to Selection" ), HK_ZOOM_SELECTION,
|
|
|
|
GR_KB_CTRL + WXK_F5, ID_ZOOM_SELECTION );
|
2019-01-02 05:12:52 +00:00
|
|
|
static EDA_HOTKEY HkHelp( _HKI( "List Hotkeys" ), HK_HELP, GR_KB_CTRL + WXK_F1 );
|
2015-03-22 14:04:09 +00:00
|
|
|
static EDA_HOTKEY HkMoveItem( _HKI( "Move Item" ), HK_MOVE_ITEM, 'M', ID_POPUP_ITEM_MOVE );
|
|
|
|
static EDA_HOTKEY HkPlaceItem( _HKI( "Place Item" ), HK_PLACE_ITEM, 'P', ID_POPUP_ITEM_PLACE );
|
|
|
|
static EDA_HOTKEY HkMoveStartPoint( _HKI( "Move Start Point" ), HK_MOVE_START_POINT, 'S',
|
2013-07-24 15:11:35 +00:00
|
|
|
ID_POPUP_ITEM_MOVE_START_POINT );
|
2015-03-22 14:04:09 +00:00
|
|
|
static EDA_HOTKEY HkMoveEndPoint( _HKI( "Move End Point" ), HK_MOVE_END_POINT, 'E',
|
2013-07-24 15:11:35 +00:00
|
|
|
ID_POPUP_ITEM_MOVE_END_POINT );
|
2015-03-22 14:04:09 +00:00
|
|
|
static EDA_HOTKEY HkDeleteItem( _HKI( "Delete Item" ), HK_DELETE_ITEM, WXK_DELETE,
|
2013-07-24 15:11:35 +00:00
|
|
|
ID_POPUP_ITEM_DELETE );
|
|
|
|
|
2017-08-29 15:07:48 +00:00
|
|
|
// Common: hotkeys_basic.h
|
2015-03-22 14:04:09 +00:00
|
|
|
static EDA_HOTKEY HkUndo( _HKI( "Undo" ), HK_UNDO, GR_KB_CTRL + 'Z', (int) wxID_UNDO );
|
|
|
|
static EDA_HOTKEY HkRedo( _HKI( "Redo" ), HK_REDO, GR_KB_CTRL + 'Y', (int) wxID_REDO );
|
2017-08-29 15:07:48 +00:00
|
|
|
static EDA_HOTKEY HkNew( _HKI( "New" ), HK_NEW, GR_KB_CTRL + 'N', (int) wxID_NEW );
|
|
|
|
static EDA_HOTKEY HkOpen( _HKI( "Open" ), HK_OPEN, GR_KB_CTRL + 'O', (int) wxID_OPEN );
|
|
|
|
static EDA_HOTKEY HkSave( _HKI( "Save" ), HK_SAVE, GR_KB_CTRL + 'S', (int) wxID_SAVE );
|
2018-03-25 15:02:53 +00:00
|
|
|
static EDA_HOTKEY HkSaveAs( _HKI( "Save As" ), HK_SAVEAS, GR_KB_CTRL + GR_KB_SHIFT + 'S',
|
|
|
|
(int) wxID_SAVEAS );
|
2017-08-29 15:07:48 +00:00
|
|
|
static EDA_HOTKEY HkPrint( _HKI( "Print" ), HK_PRINT, GR_KB_CTRL + 'P', (int) wxID_PRINT );
|
2013-07-19 18:27:22 +00:00
|
|
|
|
|
|
|
// List of common hotkey descriptors
|
2013-07-24 15:11:35 +00:00
|
|
|
EDA_HOTKEY* s_Common_Hotkey_List[] =
|
|
|
|
{
|
2017-08-29 15:07:48 +00:00
|
|
|
&HkNew, &HkOpen, &HkSave, &HkSaveAs, &HkPrint,
|
|
|
|
&HkUndo, &HkRedo,
|
2013-07-19 18:27:22 +00:00
|
|
|
&HkZoomIn, &HkZoomOut, &HkZoomRedraw, &HkZoomCenter,
|
2016-06-11 13:51:05 +00:00
|
|
|
&HkZoomAuto, &HkZoomSelection, &HkResetLocalCoord,
|
2017-08-29 15:07:48 +00:00
|
|
|
&HkHelp,
|
2014-04-03 07:40:55 +00:00
|
|
|
&HkMouseLeftClick,
|
|
|
|
&HkMouseLeftDClick,
|
2013-07-19 18:27:22 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2013-07-24 15:11:35 +00:00
|
|
|
EDA_HOTKEY* s_PlEditor_Hotkey_List[] =
|
|
|
|
{
|
|
|
|
&HkMoveItem, &HkMoveStartPoint,
|
2014-04-03 07:40:55 +00:00
|
|
|
&HkMoveEndPoint,
|
|
|
|
&HkPlaceItem,
|
|
|
|
&HkDeleteItem,
|
2013-07-26 12:50:29 +00:00
|
|
|
NULL
|
2013-07-24 15:11:35 +00:00
|
|
|
};
|
|
|
|
|
2015-04-16 15:26:51 +00:00
|
|
|
// Titles for hotkey editor and hotkey display
|
|
|
|
static wxString commonSectionTitle( _HKI( "Common" ) );
|
|
|
|
|
2013-07-24 15:11:35 +00:00
|
|
|
// list of sections and corresponding hotkey list for Pl_Editor
|
|
|
|
// (used to create an hotkey config file)
|
2015-04-16 15:26:51 +00:00
|
|
|
static wxString s_PlEditorSectionTag( wxT( "[pl_editor]" ) );
|
2015-04-19 11:07:31 +00:00
|
|
|
static wxString s_PlEditorSectionTitle( _HKI( "Page Layout Editor" ) );
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2015-04-19 18:41:57 +00:00
|
|
|
struct EDA_HOTKEY_CONFIG PlEditorHokeysDescr[] =
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2015-04-16 15:26:51 +00:00
|
|
|
{ &g_CommonSectionTag, s_Common_Hotkey_List, &commonSectionTitle },
|
2014-10-16 01:17:46 +00:00
|
|
|
{ &s_PlEditorSectionTag, s_PlEditor_Hotkey_List, &s_PlEditorSectionTitle },
|
|
|
|
{ NULL, NULL, NULL }
|
2013-07-19 18:27:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-05-05 18:39:42 +00:00
|
|
|
EDA_HOTKEY* PL_EDITOR_FRAME::GetHotKeyDescription( int aCommand ) const
|
|
|
|
{
|
|
|
|
EDA_HOTKEY* HK_Descr = GetDescriptorFromCommand( aCommand, s_Common_Hotkey_List );
|
|
|
|
|
|
|
|
if( HK_Descr == NULL )
|
|
|
|
HK_Descr = GetDescriptorFromCommand( aCommand, s_PlEditor_Hotkey_List );
|
|
|
|
|
|
|
|
return HK_Descr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-29 20:23:40 +00:00
|
|
|
bool PL_EDITOR_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode,
|
2013-07-20 19:36:19 +00:00
|
|
|
const wxPoint& aPosition, EDA_ITEM* aItem )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2013-07-24 15:11:35 +00:00
|
|
|
bool busy = GetScreen()->GetCurItem() != NULL;
|
2013-07-19 18:27:22 +00:00
|
|
|
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
|
|
|
|
cmd.SetEventObject( this );
|
|
|
|
|
|
|
|
/* Convert lower to upper case (the usual toupper function has problem with non ascii
|
|
|
|
* codes like function keys */
|
|
|
|
if( (aHotkeyCode >= 'a') && (aHotkeyCode <= 'z') )
|
|
|
|
aHotkeyCode += 'A' - 'a';
|
|
|
|
|
|
|
|
EDA_HOTKEY * HK_Descr = GetDescriptorFromHotkey( aHotkeyCode, s_PlEditor_Hotkey_List );
|
|
|
|
|
2013-07-24 15:11:35 +00:00
|
|
|
if( HK_Descr == NULL )
|
|
|
|
HK_Descr = GetDescriptorFromHotkey( aHotkeyCode, s_Common_Hotkey_List );
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
if( HK_Descr == NULL )
|
2014-08-29 20:23:40 +00:00
|
|
|
return false;
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2013-07-24 15:11:35 +00:00
|
|
|
WORKSHEET_DATAITEM* item;
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
switch( HK_Descr->m_Idcommand )
|
|
|
|
{
|
|
|
|
case HK_NOT_FOUND:
|
2014-08-29 20:23:40 +00:00
|
|
|
return false;
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2014-04-03 07:40:55 +00:00
|
|
|
case HK_LEFT_CLICK:
|
|
|
|
OnLeftClick( aDC, aPosition );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HK_LEFT_DCLICK: // Simulate a double left click: generate 2 events
|
|
|
|
OnLeftClick( aDC, aPosition );
|
|
|
|
OnLeftDClick( aDC, aPosition );
|
|
|
|
break;
|
|
|
|
|
2017-08-29 15:07:48 +00:00
|
|
|
case HK_NEW:
|
|
|
|
cmd.SetId( wxID_NEW );
|
|
|
|
GetEventHandler()->ProcessEvent( cmd );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HK_OPEN:
|
|
|
|
cmd.SetId( wxID_OPEN );
|
|
|
|
GetEventHandler()->ProcessEvent( cmd );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HK_SAVE:
|
|
|
|
cmd.SetId( wxID_SAVE );
|
|
|
|
GetEventHandler()->ProcessEvent( cmd );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HK_SAVEAS:
|
|
|
|
cmd.SetId( wxID_SAVEAS );
|
|
|
|
GetEventHandler()->ProcessEvent( cmd );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HK_PRINT:
|
|
|
|
cmd.SetId( wxID_PRINT );
|
|
|
|
GetEventHandler()->ProcessEvent( cmd );
|
2013-07-19 18:27:22 +00:00
|
|
|
break;
|
|
|
|
|
2013-07-26 12:50:29 +00:00
|
|
|
case HK_UNDO:
|
|
|
|
case HK_REDO:
|
|
|
|
if( busy )
|
|
|
|
break;
|
|
|
|
cmd.SetId( HK_Descr->m_IdMenuEvent );
|
|
|
|
GetEventHandler()->ProcessEvent( cmd );
|
|
|
|
break;
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
case HK_ZOOM_IN:
|
|
|
|
cmd.SetId( ID_POPUP_ZOOM_IN );
|
|
|
|
GetEventHandler()->ProcessEvent( cmd );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HK_ZOOM_OUT:
|
|
|
|
cmd.SetId( ID_POPUP_ZOOM_OUT );
|
|
|
|
GetEventHandler()->ProcessEvent( cmd );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HK_ZOOM_REDRAW:
|
|
|
|
cmd.SetId( ID_ZOOM_REDRAW );
|
|
|
|
GetEventHandler()->ProcessEvent( cmd );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HK_ZOOM_CENTER:
|
|
|
|
cmd.SetId( ID_POPUP_ZOOM_CENTER );
|
|
|
|
GetEventHandler()->ProcessEvent( cmd );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HK_ZOOM_AUTO:
|
|
|
|
cmd.SetId( ID_ZOOM_PAGE );
|
|
|
|
GetEventHandler()->ProcessEvent( cmd );
|
|
|
|
break;
|
|
|
|
|
2016-06-11 15:49:55 +00:00
|
|
|
case HK_ZOOM_SELECTION:
|
|
|
|
cmd.SetId( ID_ZOOM_SELECTION );
|
|
|
|
GetEventHandler()->ProcessEvent( cmd );
|
|
|
|
break;
|
|
|
|
|
2013-07-24 15:11:35 +00:00
|
|
|
case HK_RESET_LOCAL_COORD: // Reset the relative coord
|
2013-08-03 05:15:23 +00:00
|
|
|
GetScreen()->m_O_Curseur = GetCrossHairPosition();
|
|
|
|
break;
|
|
|
|
|
2017-08-29 15:07:48 +00:00
|
|
|
case HK_HELP: // Display Current hotkey list
|
|
|
|
DisplayHotkeyList( this, PlEditorHokeysDescr );
|
|
|
|
break;
|
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
case HK_SET_GRID_ORIGIN:
|
|
|
|
SetGridOrigin( GetCrossHairPosition() );
|
2013-07-19 18:27:22 +00:00
|
|
|
break;
|
|
|
|
|
2013-07-24 15:11:35 +00:00
|
|
|
case HK_MOVE_ITEM:
|
|
|
|
case HK_MOVE_START_POINT:
|
|
|
|
case HK_MOVE_END_POINT:
|
|
|
|
case HK_DELETE_ITEM:
|
|
|
|
if( busy )
|
|
|
|
break;
|
|
|
|
|
2018-08-19 19:49:35 +00:00
|
|
|
if( (item = Locate( aDC, aPosition ) ) == NULL )
|
2013-07-24 15:11:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
// Only rect and lines have a end point.
|
|
|
|
if( HK_Descr->m_Idcommand == HK_MOVE_END_POINT && !item->HasEndPoint() )
|
|
|
|
break;
|
|
|
|
|
|
|
|
if( m_treePagelayout->GetPageLayoutSelectedItem() != item )
|
|
|
|
m_treePagelayout->SelectCell( item );
|
|
|
|
|
|
|
|
cmd.SetId( HK_Descr->m_IdMenuEvent );
|
|
|
|
GetEventHandler()->ProcessEvent( cmd );
|
2013-07-19 18:27:22 +00:00
|
|
|
break;
|
|
|
|
|
2014-04-03 07:40:55 +00:00
|
|
|
case HK_PLACE_ITEM:
|
|
|
|
if( busy )
|
|
|
|
{
|
|
|
|
cmd.SetId( HK_Descr->m_IdMenuEvent );
|
|
|
|
GetEventHandler()->ProcessEvent( cmd );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-07-24 15:11:35 +00:00
|
|
|
default:
|
2014-08-29 20:23:40 +00:00
|
|
|
wxMessageBox( wxT( "Unknown hotkey" ) );
|
|
|
|
return false;
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|
2014-08-29 20:23:40 +00:00
|
|
|
|
|
|
|
return true;
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|