Commit ea6aba82 authored by CHARRAS's avatar CHARRAS

Better Hotkey.cpp code for eeschema

parent c3a1b404
......@@ -4,6 +4,11 @@ Started 2007-June-11
Please add newer entries at the top, list the date and your name with
email address.
2007-aug-10 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================
+ eeschema
better hotkeys.cpp code.
2007-Aug-08 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================
......
......@@ -5,15 +5,14 @@
/* Fichier TRIGO.CPP */
#include "fctsys.h"
#define global extern
#include "trigo.h"
/*****************************/
/************************************************************************/
bool DistanceTest( int seuil, int dx, int dy, int spot_cX, int spot_cY )
/*****************************/
/************************************************************************/
/*
* Calcul de la distance du curseur souris a un segment de droite :
......@@ -291,6 +290,27 @@ void RotatePoint( int* pX, int* pY, int cx, int cy, int angle )
}
/********************************************/
void RotatePoint( wxPoint* point, int angle )
/********************************************/
/*
* Fonction surchargee!
* calcule les nouvelles coord du point point,
* pour une rotation d'angle angle ( en 1/10 degre)
*/
{
int ox, oy;
ox = point->x;
oy = point->y;
RotatePoint( &ox, &oy, angle );
point->x = ox;
point->y = oy;
}
/*****************************************************************/
void RotatePoint( wxPoint* point, const wxPoint& centre, int angle )
/*****************************************************************/
......@@ -312,6 +332,7 @@ void RotatePoint( wxPoint* point, const wxPoint& centre, int angle )
}
/*************************************************************************/
void RotatePoint( double* pX, double* pY, double cx, double cy, int angle )
/*************************************************************************/
......
......@@ -297,10 +297,6 @@ int hotkey = 0;
m_CurrentScreen->m_O_Curseur = m_CurrentScreen->m_Curseur;
break;
case '\t': // Switch to drag mode, when block moving
((WinEDA_SchematicFrame*)this)->HandleBlockEndByPopUp(BLOCK_DRAG, DC);
break;
case WXK_NUMPAD8 : /* Deplacement curseur vers le haut */
case WXK_UP :
MousePositionInPixels.y -= delta.y;
......@@ -325,33 +321,6 @@ int hotkey = 0;
DrawPanel->MouseTo(MousePositionInPixels);
break;
case WXK_INSERT:
case WXK_NUMPAD0:
if ( m_Ident == SCHEMATIC_FRAME )
{
if ( g_ItemToRepeat && (g_ItemToRepeat->m_Flags == 0) )
{
((WinEDA_SchematicFrame*)this)->RepeatDrawItem(DC);
}
else wxBell();
break;
}
if ( m_Ident == LIBEDITOR_FRAME )
{
if ( LibItemToRepeat && (LibItemToRepeat->m_Flags == 0) &&
(LibItemToRepeat->m_StructType == COMPONENT_PIN_DRAW_TYPE) )
{
((WinEDA_LibeditFrame*)this)->RepeatPinItem(DC,
(LibDrawPin*) LibItemToRepeat);
}
else wxBell();
break;
}
case 0:
case WXK_DECIMAL:
break;
default: hotkey = g_KeyPressed;
break;
......@@ -367,8 +336,7 @@ int hotkey = 0;
RedrawActiveWindow(DC, TRUE);
}
if ( (oldpos.x != m_CurrentScreen->m_Curseur.x) ||
(oldpos.y != m_CurrentScreen->m_Curseur.y) )
if ( oldpos != m_CurrentScreen->m_Curseur )
{
curpos = m_CurrentScreen->m_Curseur;
m_CurrentScreen->m_Curseur = oldpos;
......
......@@ -15,9 +15,188 @@
#include "protos.h"
/* Routines locales */
enum hotkey_id_commnand {
HK_NOT_FOUND = 0,
HK_HELP,
HK_ZOOM_IN,
HK_ZOOM_OUT,
HK_ZOOM_REDRAW,
HK_ZOOM_CENTER,
HK_NEXT_SEARCH,
HK_DELETE,
HK_REPEAT_LAST,
HK_MOVEBLOCK_TO_DRAGBLOCK,
HK_ROTATE_COMPONENT,
HK_MIRROR_X_COMPONENT,
HK_MIRROR_Y_COMPONENT,
HK_ORIENT_NORMAL_COMPONENT,
HK_MOVE_COMPONENT,
HK_ADD_NEW_COMPONENT,
HK_BEGIN_WIRE
};
/* Class to handle hotkey commnands. hotkeys have a default value
This class allows (for the future..) the real key code changed by user(from a key code list file, TODO)
*/
class Ki_HotkeyInfo
{
public:
int m_KeyCode; // Key code (ascii value for ascii keys or wxWidgets code for function key
wxString m_InfoMsg; // info message.
hotkey_id_commnand m_Idcommand; // internal id for the corresponding command (see hotkey_id_commnand list)
public:
Ki_HotkeyInfo(const wxChar * infomsg, hotkey_id_commnand idcommand, int keycode);
};
Ki_HotkeyInfo::Ki_HotkeyInfo(const wxChar * infomsg, hotkey_id_commnand idcommand, int keycode)
{
m_KeyCode = keycode; // Key code (ascii value for ascii keys or wxWidgets code for function key
m_InfoMsg = infomsg; // info message.
m_Idcommand = idcommand; // internal id for the corresponding command (see hotkey_id_commnand list)
}
/* local variables */
/* Hotkey list: */
static Ki_HotkeyInfo HkBeginWire(wxT("begin Wire"), HK_BEGIN_WIRE, 'W');
static Ki_HotkeyInfo HkAddComponent(wxT("Add Component"), HK_ADD_NEW_COMPONENT, 'A');
static Ki_HotkeyInfo HkMirrorYComponent(wxT("Mirror Y Component"), HK_MIRROR_Y_COMPONENT, 'Y');
static Ki_HotkeyInfo HkMirrorXComponent(wxT("Mirror X Component"), HK_MIRROR_X_COMPONENT, 'X');
static Ki_HotkeyInfo HkOrientNormalComponent(wxT("Orient Normal Component"), HK_ORIENT_NORMAL_COMPONENT, 'N');
static Ki_HotkeyInfo HkRotateComponent(wxT("Rotate Component"), HK_ROTATE_COMPONENT, 'R');
static Ki_HotkeyInfo HkMoveComponent(wxT("Move Component"), HK_MOVE_COMPONENT, 'M');
static Ki_HotkeyInfo HkMove2Drag(wxT("Switch move block to drag block"), HK_MOVEBLOCK_TO_DRAGBLOCK, '\t');
static Ki_HotkeyInfo HkInsert(wxT("Repeat Last Item"), HK_REPEAT_LAST, WXK_INSERT);
static Ki_HotkeyInfo HkDelete(wxT("Delete Item"), HK_DELETE, WXK_DELETE);
static Ki_HotkeyInfo HkNextSearch(wxT("Next Search"), HK_NEXT_SEARCH, WXK_F5);
static Ki_HotkeyInfo HkZoomCenter(wxT("Zoom Center"), HK_ZOOM_CENTER, WXK_F4);
static Ki_HotkeyInfo HkZoomRedraw(wxT("Zoom Redraw"), HK_ZOOM_REDRAW, WXK_F3);
static Ki_HotkeyInfo HkZoomOut(wxT("Zoom Out"), HK_ZOOM_OUT, WXK_F2);
static Ki_HotkeyInfo HkZoomIn(wxT("Zoom In"), HK_ZOOM_IN, WXK_F1);
static Ki_HotkeyInfo HkHelp(wxT("Help: this message"), HK_HELP, '?');
// List of hotkey descriptors for schematic
static Ki_HotkeyInfo *s_Schematic_Hotkey_List[] = {
&HkHelp,
&HkZoomIn, &HkZoomOut, &HkZoomRedraw, &HkZoomCenter,
&HkNextSearch, &HkDelete, &HkInsert, &HkMove2Drag,
&HkMoveComponent, &HkAddComponent,
&HkRotateComponent, &HkMirrorXComponent, &HkMirrorYComponent, & HkOrientNormalComponent,
&HkBeginWire,
NULL
};
// Library editor:
static Ki_HotkeyInfo HkInsertPin(wxT("Repeat Pin"), HK_REPEAT_LAST, WXK_INSERT);
// List of hotkey descriptors for libray editor
static Ki_HotkeyInfo *s_LibEdit_Hotkey_List[] =
{
&HkHelp,
&HkZoomIn, &HkZoomOut, &HkZoomRedraw, &HkZoomCenter,
&HkInsertPin,
NULL
};
/****************************************************/
static wxString ReturnKeyNameFromKeyCode(int keycode)
/****************************************************/
/*
* return the key name from the key code
* Only some wxWidgets key values are handled for function key
* @param key = key code (ascii value, or wxWidgets value for function keys)
* @return the key name wxString
*/
{
wxString keyname, modifier, fullkeyname;
if ( keycode & GR_KB_CTRL) modifier << wxT("Ctrl ");
if ( keycode & GR_KB_ALT) modifier << wxT("Alt ");
if ( keycode & GR_KB_SHIFT) modifier << wxT("Shift ");
keycode &= ~(GR_KB_CTRL|GR_KB_ALT|GR_KB_SHIFT);
switch ( keycode )
{
default:
keyname.Printf(wxT("%c"), keycode);
break;
case WXK_F1:
case WXK_F2:
case WXK_F3:
case WXK_F4:
case WXK_F5:
case WXK_F6:
case WXK_F7:
case WXK_F8:
case WXK_F9:
case WXK_F10:
case WXK_F11:
case WXK_F12:
keyname.Printf(wxT("F%d"), keycode - WXK_F1 + 1);
break;
case '\t':
keyname = wxT("Tab");
break;
case WXK_DELETE:
keyname = wxT("Delete");
break;
case WXK_INSERT:
keyname = wxT("Insert");
break;
}
/* variables externes */
fullkeyname = modifier + keyname;
return keyname;
}
/****************************************************************************/
static void DisplayHotkeyList(WinEDA_DrawFrame * frame, Ki_HotkeyInfo ** List)
/*****************************************************************************/
/*
* Displays the current hotkey list
* @param frame = current open frame
* @param List = pointer to a Ki_HotkeyInfo list of commands
* @return none
*/
{
wxString keyname;
wxString msg = _("Current hotkey list:\n\n");
for ( ; * List != NULL; List++ )
{
Ki_HotkeyInfo * hk_decr = * List;
if ( hk_decr->m_InfoMsg.IsEmpty() ) break;
msg += _("key ");
keyname = ReturnKeyNameFromKeyCode(hk_decr->m_KeyCode);
msg += keyname + wxT(": ") + hk_decr->m_InfoMsg + wxT("\n");
}
DisplayInfo(frame, msg);
}
/******************************************************************/
static int GetCommandCodeFromHotkey(int key, Ki_HotkeyInfo ** List)
/******************************************************************/
/*
* Return an id identifier fron a key code for OnHotKey() function
* @param key = key code (ascii value, or wxWidgets value for function keys
* @param List = pointer to a Ki_HotkeyInfo list of commands
* @return the corresponding function identifier from the Ki_HotkeyInfo List
*/
{
for ( ; * List != NULL; List++ )
{
Ki_HotkeyInfo * hk_decr = * List;
if ( hk_decr->m_KeyCode == key ) return hk_decr->m_Idcommand;
}
return HK_NOT_FOUND;
}
/***********************************************************/
void WinEDA_SchematicFrame::OnHotKey(wxDC * DC, int hotkey,
......@@ -27,27 +206,7 @@ void WinEDA_SchematicFrame::OnHotKey(wxDC * DC, int hotkey,
Commands are case insensitive
Zoom commands are not managed here
*/
/* Hotkey list: */
{
static wxString s_Hotkey_List[] =
{
wxT("key F1: Zoom in"), // general zoom hotkey, not managed here
wxT("key F2: Zoom out"), // general zoom hotkey, not managed here
wxT("key F5: Zoom Redraw"), // general zoom hotkey, not managed here
wxT("key F4: Zoom Center"), // general zoom hotkey, not managed here
wxT("key F5: Next search"),
wxT("key DELETE: delete item"),
wxT("key R: Rotation (component or label)"),
wxT("key X: Mirror X (component)"),
wxT("key Y: Mirror Y (component)"),
wxT("key N: Orient 0 (component)"),
wxT("key M: Start Move component"),
wxT("key A: Add new component"),
wxT("key W: begin new Wire"),
wxT("") // End of list, do not change
};
bool PopupOn = m_CurrentScreen->m_CurrentItem &&
m_CurrentScreen->m_CurrentItem->m_Flags;
bool RefreshToolBar = FALSE; // We must refresh tool bar when the undo/redo tool state is modified
......@@ -56,22 +215,32 @@ bool RefreshToolBar = FALSE; // We must refresh tool bar when the undo/redo tool
wxPoint MousePos = m_CurrentScreen->m_MousePosition;
switch (hotkey)
{
case '?': // Display Current hotkey list
{
wxString msg = _("Current hotkey list:\n\n");
for ( unsigned int ii = 0; ; ii++ )
/* Convert lower to upper case (the usual toupper function has problem with non ascii codes like function keys */
if( (hotkey >= 'a') && (hotkey <= 'z') ) hotkey += 'A' - 'a';
// Search commnd from key :
switch ( GetCommandCodeFromHotkey(hotkey, s_Schematic_Hotkey_List) )
{
if ( s_Hotkey_List[ii].IsEmpty() ) break;
msg += s_Hotkey_List[ii]; msg += wxT("\n");
}
DisplayInfo(this, msg);
default:
case HK_NOT_FOUND:
return;
break;
}
case WXK_DELETE:
case WXK_NUMPAD_DELETE:
case HK_HELP: // Display Current hotkey list
DisplayHotkeyList(this, s_Schematic_Hotkey_List);
break;
case HK_ZOOM_IN:
case HK_ZOOM_OUT:
case HK_ZOOM_REDRAW:
case HK_ZOOM_CENTER:
break;
case HK_MOVEBLOCK_TO_DRAGBLOCK: // Switch to drag mode, when block moving
HandleBlockEndByPopUp(BLOCK_DRAG, DC);
break;
case HK_DELETE:
if ( PopupOn ) break;
RefreshToolBar = LocateAndDeleteItem(this, DC);
m_CurrentScreen->SetModify();
......@@ -79,21 +248,27 @@ wxPoint MousePos = m_CurrentScreen->m_MousePosition;
TestDanglingEnds(m_CurrentScreen->EEDrawList, DC);
break;
case WXK_F5 :
case HK_REPEAT_LAST:
if ( g_ItemToRepeat && (g_ItemToRepeat->m_Flags == 0) )
{
RepeatDrawItem(DC);
}
else wxBell();
break;
case HK_NEXT_SEARCH :
if ( g_LastSearchIsMarker ) WinEDA_SchematicFrame::FindMarker(1);
else FindSchematicItem(wxEmptyString, 2);
break;
case 'a':
case 'A': // Add component
case HK_ADD_NEW_COMPONENT: // Add component
if ( DrawStruct && DrawStruct->m_Flags ) break;
// switch to m_ID_current_state = ID_COMPONENT_BUTT;
if ( m_ID_current_state != ID_COMPONENT_BUTT ) SetToolID( ID_COMPONENT_BUTT, wxCURSOR_PENCIL, _("Add Component"));
OnLeftClick(DC, MousePos);
break;
case 'w':
case 'W': // Add wire
case HK_BEGIN_WIRE: // Add wire
if ( DrawStruct ) // An item is selected. If edited and not a wire, a new command is not possible
{
if ( DrawStruct->m_Flags ) // Item selected and edition in progress
......@@ -111,8 +286,7 @@ wxPoint MousePos = m_CurrentScreen->m_MousePosition;
OnLeftClick(DC, MousePos);
break;
case 'r': // Rotation
case 'R':
case HK_ROTATE_COMPONENT: // Component Rotation
if ( DrawStruct == NULL )
{
DrawStruct = PickStruct( GetScreen()->m_Curseur,
......@@ -148,8 +322,7 @@ wxPoint MousePos = m_CurrentScreen->m_MousePosition;
}
break;
case 'y': // Mirror Y (drawlibpart)
case 'Y':
case HK_MIRROR_Y_COMPONENT: // Mirror Y (Component)
if ( DrawStruct == NULL )
DrawStruct = LocateSmallestComponent( GetScreen() );
if ( DrawStruct )
......@@ -164,8 +337,7 @@ wxPoint MousePos = m_CurrentScreen->m_MousePosition;
}
break;
case 'x': // Mirror X (drawlibpart)
case 'X':
case HK_MIRROR_X_COMPONENT: // Mirror X (Component)
if ( DrawStruct == NULL )
DrawStruct = LocateSmallestComponent( GetScreen() );
if ( DrawStruct )
......@@ -180,8 +352,7 @@ wxPoint MousePos = m_CurrentScreen->m_MousePosition;
}
break;
case 'n':
case 'N': // Orient 0, no mirror (drawlibpart)
case HK_ORIENT_NORMAL_COMPONENT: // Orient 0, no mirror (Component)
if ( DrawStruct == NULL )
DrawStruct = LocateSmallestComponent( GetScreen() );
if ( DrawStruct )
......@@ -197,8 +368,7 @@ wxPoint MousePos = m_CurrentScreen->m_MousePosition;
}
break;
case 'm':
case 'M': // Start move drawlibpart
case HK_MOVE_COMPONENT: // Start move Component
if ( PopupOn ) break;
if ( DrawStruct == NULL )
DrawStruct = LocateSmallestComponent( GetScreen() );
......@@ -212,3 +382,55 @@ wxPoint MousePos = m_CurrentScreen->m_MousePosition;
if ( RefreshToolBar ) SetToolbars();
}
/***********************************************************/
void WinEDA_LibeditFrame::OnHotKey(wxDC * DC, int hotkey,
EDA_BaseStruct * DrawStruct)
/***********************************************************/
/* Hot keys for the component editot. Some commands are relatives to the item under the mouse cursor
Commands are case insensitive
Zoom commands are not managed here
*/
{
bool PopupOn = m_CurrentScreen->m_CurrentItem &&
m_CurrentScreen->m_CurrentItem->m_Flags;
bool RefreshToolBar = FALSE; // We must refresh tool bar when the undo/redo tool state is modified
if ( hotkey == 0 ) return;
wxPoint MousePos = m_CurrentScreen->m_MousePosition;
/* Convert lower to upper case (the usual toupper function has problem with non ascii codes like function keys */
if( (hotkey >= 'a') && (hotkey <= 'z') ) hotkey += 'A' - 'a';
switch ( GetCommandCodeFromHotkey(hotkey, s_LibEdit_Hotkey_List) )
{
default:
case HK_NOT_FOUND:
return;
break;
case HK_HELP: // Display Current hotkey list
DisplayHotkeyList(this, s_LibEdit_Hotkey_List);
break;
case HK_ZOOM_IN:
case HK_ZOOM_OUT:
case HK_ZOOM_REDRAW:
case HK_ZOOM_CENTER:
break;
case HK_REPEAT_LAST:
if ( LibItemToRepeat && (LibItemToRepeat->m_Flags == 0) &&
(LibItemToRepeat->m_StructType == COMPONENT_PIN_DRAW_TYPE) )
{
RepeatPinItem(DC, (LibDrawPin*) LibItemToRepeat);
}
else wxBell();
break;
}
if ( RefreshToolBar ) SetToolbars();
}
......@@ -10,6 +10,7 @@
/* Prototype des fonctions de trigo.cpp */
void RotatePoint(int *pX, int *pY, int angle);
void RotatePoint(int *pX, int *pY, int cx, int cy, int angle);
void RotatePoint(wxPoint* point, int angle );
void RotatePoint(wxPoint *point, const wxPoint & centre, int angle);
void RotatePoint(double *pX, double *pY, int angle);
void RotatePoint(double *pX, double *pY, double cx, double cy, int angle);
......@@ -22,37 +23,6 @@ int ArcTangente(int dy, int dx);
bool DistanceTest( int seuil, int dx, int dy, int spot_cX, int spot_cY );
/*************************************************/
/* Table lookup de 1/COS(X) en fonction de tg(X) */
/*************************************************/
eda_global float invcostab[17]
#if defined MAIN
= { 1.0, 1/0.998, 1/0.9923, 1/0.9829, 1/0.97014, 1/0.9545,
1/0.93633, 1/0.91615, 1/0.8944, 1/0.8715, 1/0.848, 1/0.82404,
1/0.8, 1/0.7761, 1/0.75257, 1/0.7295, 1/0.707 }
#endif
;
/***************************************************/
/* Table lookup de 256*COS(X) en fonction de tg(X) */
/***************************************************/
eda_global long costab[17]
#if defined MAIN
= { 256, 255, 253, 251, 248, 244, 240, 234, 229,
223, 217, 211, 205, 198, 192, 187, 181 }
#endif
;
/***************************************************/
/* Table lookup de 256*SIN(X) en fonction de tg(X) */
/***************************************************/
eda_global long sintab[17]
#if defined MAIN
= { 0, 16, 32, 47, 62, 76, 90, 103, 114,
125, 136, 145, 154, 161, 168, 175, 181 }
#endif
;
/*******************/
/* Macro NEW_COORD */
/*******************/
......
......@@ -1120,9 +1120,8 @@ public:
int BestZoom( void ); // Retourne le meilleur zoom
void SetToolbars( void );
void OnLeftDClick( wxDC* DC, const wxPoint& MousePos );
SCH_SCREEN* GetScreen( void ) { return (SCH_SCREEN*) m_CurrentScreen; }
void OnHotKey( wxDC* DC, int hotkey, EDA_BaseStruct* DrawStruct );
private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment