Unify Eeschema drag item commands into a single event handler.

* Create command event handler for draggining all schematic items.
* Remove redundant delete item command handler code.
* Remove unused close current tool command ID from process special
  functions event handler.
This commit is contained in:
Wayne Stambaugh 2011-10-27 13:51:22 -04:00
parent 7195644360
commit 60805606a0
7 changed files with 86 additions and 83 deletions

View File

@ -94,7 +94,6 @@ enum id_eeschema_frm
ID_POPUP_SCH_DELETE_CONNECTION,
ID_POPUP_SCH_DELETE_NODE,
ID_POPUP_SCH_DELETE_CMP,
ID_POPUP_SCH_DRAG_ITEM_REQUEST,
ID_POPUP_SCH_UNUSED_2,
ID_POPUP_SCH_ENTRY_SELECT_SLASH,
ID_POPUP_SCH_ENTRY_SELECT_ANTISLASH,
@ -177,6 +176,7 @@ enum id_eeschema_frm
ID_SCH_EDIT_COMPONENT_REFERENCE,
ID_SCH_EDIT_COMPONENT_FOOTPRINT,
ID_POPUP_SCH_MOVE_ITEM,
ID_SCH_DRAG_ITEM,
// Schematic editor commmands. These are command IDs that are generated by multiple
// events (menus, toolbar, context menu, etc.) that result in the same event handler.

View File

@ -174,8 +174,7 @@ static EDA_HOTKEY HkCopyComponentOrText( wxT( "Copy Component or Label" ),
HK_COPY_COMPONENT_OR_LABEL, 'C',
ID_POPUP_SCH_COPY_ITEM );
static EDA_HOTKEY HkDrag( wxT( "Drag Schematic Item" ), HK_DRAG, 'G',
ID_POPUP_SCH_DRAG_ITEM_REQUEST );
static EDA_HOTKEY HkDrag( wxT( "Drag Schematic Item" ), HK_DRAG, 'G', ID_SCH_DRAG_ITEM );
static EDA_HOTKEY HkMove2Drag( wxT( "Move Block -> Drag Block" ),
HK_MOVEBLOCK_TO_DRAGBLOCK, '\t' );
static EDA_HOTKEY HkInsert( wxT( "Repeat Last Item" ), HK_REPEAT_LAST, WXK_INSERT );
@ -507,50 +506,6 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
break;
case HK_DRAG: // Start drag
if( itemInEdit )
break;
if( aItem == NULL )
{
aItem = LocateAndShowItem( aPosition, SCH_COLLECTOR::DraggableItems,
hotKey->m_Idcommand );
if( aItem == NULL )
break;
}
if( aItem->GetFlags() == 0 )
{
switch( aItem->Type() )
{
// select the correct event for moving an schematic object
// and add it to the event queue
case SCH_COMPONENT_T:
case SCH_GLOBAL_LABEL_T:
case SCH_HIERARCHICAL_LABEL_T:
case SCH_SHEET_T:
cmd.SetId( hotKey->m_IdMenuEvent );
wxPostEvent( this, cmd );
break;
case SCH_BUS_ENTRY_T:
case SCH_LINE_T:
case SCH_JUNCTION_T:
if( ((SCH_ITEM*) aItem )->GetLayer() != LAYER_BUS )
{
cmd.SetId( hotKey->m_IdMenuEvent );
wxPostEvent( this, cmd );
}
break;
default:
;
}
}
break;
case HK_ROTATE: // Rotate schematic item or block.
case HK_MOVE_COMPONENT_OR_ITEM: // Start move schematic item.
case HK_EDIT: // Edit schematic item.
@ -558,7 +513,7 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
case HK_EDIT_COMPONENT_FOOTPRINT: // Edit component footprint field.
{
EDA_HOTKEY_CLIENT_DATA data( aPosition );
cmd.SetInt( aHotKey );
cmd.SetInt( hotKey->m_Idcommand );
cmd.SetClientObject( &data );
cmd.SetId( hotKey->m_IdMenuEvent );
GetEventHandler()->ProcessEvent( cmd );

View File

@ -179,10 +179,6 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
case ID_SCHEMATIC_DELETE_ITEM_BUTT:
DeleteItemAtCrossHair( aDC );
OnModify();
GetScreen()->SetCurItem( NULL );
GetScreen()->TestDanglingEnds();
DrawPanel->Refresh( true );
break;
case ID_WIRE_BUTT:

View File

@ -280,7 +280,7 @@ void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component )
msg = AddHotkeyName( msg, s_Schematic_Hokeys_Descr, HK_MOVE_COMPONENT_OR_ITEM );
AddMenuItem( PopMenu, ID_POPUP_SCH_MOVE_ITEM, msg, KiBitmap( move_xpm ) );
msg = AddHotkeyName( _( "Drag Component" ), s_Schematic_Hokeys_Descr, HK_DRAG );
AddMenuItem( PopMenu, ID_POPUP_SCH_DRAG_ITEM_REQUEST, msg, KiBitmap( move_xpm ) );
AddMenuItem( PopMenu, ID_SCH_DRAG_ITEM, msg, KiBitmap( move_xpm ) );
}
wxMenu* orientmenu = new wxMenu;
@ -377,7 +377,7 @@ void AddMenusForGLabel( wxMenu* PopMenu, SCH_GLOBALLABEL* GLabel )
AddMenuItem( PopMenu, ID_POPUP_SCH_MOVE_ITEM, msg, KiBitmap( move_text_xpm ) );
msg = AddHotkeyName( _( "Drag Global Label" ), s_Schematic_Hokeys_Descr,
HK_DRAG );
AddMenuItem( PopMenu, ID_POPUP_SCH_DRAG_ITEM_REQUEST, msg, KiBitmap( move_text_xpm ) );
AddMenuItem( PopMenu, ID_SCH_DRAG_ITEM, msg, KiBitmap( move_text_xpm ) );
msg = AddHotkeyName( _( "Copy Global Label" ), s_Schematic_Hokeys_Descr,
HK_COPY_COMPONENT_OR_LABEL );
AddMenuItem( PopMenu, ID_POPUP_SCH_COPY_ITEM, msg, KiBitmap( copy_button_xpm ) );
@ -413,7 +413,7 @@ void AddMenusForHLabel( wxMenu* PopMenu, SCH_HIERLABEL* HLabel )
HK_MOVE_COMPONENT_OR_ITEM );
AddMenuItem( PopMenu, ID_POPUP_SCH_MOVE_ITEM, msg, KiBitmap( move_text_xpm ) );
msg = AddHotkeyName( _( "Drag Hierarchical Label" ), s_Schematic_Hokeys_Descr, HK_DRAG );
AddMenuItem( PopMenu, ID_POPUP_SCH_DRAG_ITEM_REQUEST, msg, KiBitmap( move_text_xpm ) );
AddMenuItem( PopMenu, ID_SCH_DRAG_ITEM, msg, KiBitmap( move_text_xpm ) );
msg = AddHotkeyName( _( "Copy Hierarchical Label" ), s_Schematic_Hokeys_Descr,
HK_COPY_COMPONENT_OR_LABEL );
AddMenuItem( PopMenu, ID_POPUP_SCH_COPY_ITEM, msg, KiBitmap( copy_button_xpm ) );
@ -449,7 +449,7 @@ void AddMenusForLabel( wxMenu* PopMenu, SCH_LABEL* Label )
HK_MOVE_COMPONENT_OR_ITEM );
AddMenuItem( PopMenu, ID_POPUP_SCH_MOVE_ITEM, msg, KiBitmap( move_text_xpm ) );
msg = AddHotkeyName( _( "Drag Label" ), s_Schematic_Hokeys_Descr, HK_DRAG );
AddMenuItem( PopMenu, ID_POPUP_SCH_DRAG_ITEM_REQUEST, msg, KiBitmap( move_text_xpm ) );
AddMenuItem( PopMenu, ID_SCH_DRAG_ITEM, msg, KiBitmap( move_text_xpm ) );
msg = AddHotkeyName( _( "Copy Label" ), s_Schematic_Hokeys_Descr,
HK_COPY_COMPONENT_OR_LABEL );
AddMenuItem( PopMenu, ID_POPUP_SCH_COPY_ITEM, msg, KiBitmap( copy_button_xpm ) );
@ -524,8 +524,7 @@ void SCH_EDIT_FRAME::addJunctionMenuEntries( wxMenu* aMenu, SCH_JUNCTION* aJunct
if( !aJunction->IsNew() )
{
if( m_collectedItems.IsDraggableJunction() )
AddMenuItem( aMenu, ID_POPUP_SCH_DRAG_ITEM_REQUEST, _( "Drag Junction" ),
KiBitmap( move_xpm ) );
AddMenuItem( aMenu, ID_SCH_DRAG_ITEM, _( "Drag Junction" ), KiBitmap( move_xpm ) );
if( screen->GetWire( aJunction->GetPosition(), EXCLUDE_END_POINTS_T ) )
AddMenuItem( aMenu, ID_POPUP_SCH_BREAK_WIRE, _( "Break Wire" ),
@ -556,7 +555,7 @@ void AddMenusForWire( wxMenu* PopMenu, SCH_LINE* Wire, SCH_EDIT_FRAME* frame )
}
msg = AddHotkeyName( _( "Drag Wire" ), s_Schematic_Hokeys_Descr, HK_DRAG );
AddMenuItem( PopMenu, ID_POPUP_SCH_DRAG_ITEM_REQUEST, msg, KiBitmap( move_track_xpm ) );
AddMenuItem( PopMenu, ID_SCH_DRAG_ITEM, msg, KiBitmap( move_track_xpm ) );
PopMenu->AppendSeparator();
msg = AddHotkeyName( _( "Delete Wire" ), s_Schematic_Hokeys_Descr, HK_DELETE );
AddMenuItem( PopMenu, ID_POPUP_SCH_DELETE, msg, KiBitmap( delete_xpm ) );
@ -629,7 +628,7 @@ void AddMenusForHierchicalSheet( wxMenu* PopMenu, SCH_SHEET* Sheet )
AddMenuItem( PopMenu, ID_POPUP_SCH_MOVE_ITEM, msg, KiBitmap( move_sheet_xpm ) );
msg = AddHotkeyName( _( "Drag Sheet" ), s_Schematic_Hokeys_Descr, HK_DRAG );
AddMenuItem( PopMenu, ID_POPUP_SCH_DRAG_ITEM_REQUEST, msg, KiBitmap( move_sheet_xpm ) );
AddMenuItem( PopMenu, ID_SCH_DRAG_ITEM, msg, KiBitmap( move_sheet_xpm ) );
}
if( Sheet->GetFlags() )

View File

@ -74,7 +74,6 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
case ID_POPUP_SCH_END_SHEET:
case ID_POPUP_SCH_RESIZE_SHEET:
case ID_POPUP_IMPORT_GLABEL:
case ID_POPUP_SCH_DRAG_ITEM_REQUEST:
case ID_POPUP_SCH_INIT_CMP:
case ID_POPUP_SCH_DISPLAYDOC_CMP:
case ID_POPUP_SCH_EDIT_CONVERT_CMP:
@ -155,7 +154,10 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
SetToolID( GetToolId(), DrawPanel->GetCurrentCursor(), wxEmptyString );
}
else
{
SetToolID( ID_NO_TOOL_SELECTED, DrawPanel->GetDefaultCursor(), wxEmptyString );
}
break;
case ID_POPUP_END_LINE:
@ -242,23 +244,6 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
}
break;
case ID_POPUP_SCH_DRAG_ITEM_REQUEST:
DrawPanel->MoveCursorToCrossHair();
// The easiest way to handle a drag component or sheet command
// is to simulate a block drag command
if( screen->m_BlockLocate.m_State == STATE_NO_BLOCK )
{
if( !HandleBlockBegin( &dc, BLOCK_DRAG, screen->GetCrossHairPosition() ) )
break;
// Give a non null size to the search block:
screen->m_BlockLocate.Inflate( 1 );
HandleBlockEnd( &dc );
}
break;
case ID_POPUP_SCH_INIT_CMP:
DrawPanel->MoveCursorToCrossHair();
break;
@ -305,10 +290,6 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
DisplayCurrentSheet();
break;
case ID_POPUP_CLOSE_CURRENT_TOOL:
SetToolID( ID_NO_TOOL_SELECTED, DrawPanel->GetDefaultCursor(), wxEmptyString );
break;
case wxID_COPY: // really this is a Save block for paste
HandleBlockEndByPopUp( BLOCK_SAVE, &dc );
break;
@ -388,7 +369,8 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
break;
default: // Log error:
DisplayError( this, wxT( "SCH_EDIT_FRAME::Process_Special_Functions error" ) );
wxFAIL_MSG( wxString::Format( wxT( "Cannot process command event ID %d" ),
event.GetId() ) );
break;
}
@ -886,3 +868,67 @@ void SCH_EDIT_FRAME::OnEditItem( wxCommandEvent& aEvent )
if( item->GetFlags() == 0 )
screen->SetCurItem( NULL );
}
void SCH_EDIT_FRAME::OnDragItem( wxCommandEvent& aEvent )
{
SCH_SCREEN* screen = GetScreen();
SCH_ITEM* item = screen->GetCurItem();
INSTALL_UNBUFFERED_DC( dc, DrawPanel );
if( item == NULL )
{
// If we didn't get here by a hot key, then something has gone wrong.
if( aEvent.GetInt() == 0 )
return;
EDA_HOTKEY_CLIENT_DATA* data = (EDA_HOTKEY_CLIENT_DATA*) aEvent.GetClientObject();
wxCHECK_RET( data != NULL, wxT( "Invalid hot key client object." ) );
item = LocateAndShowItem( data->GetPosition(), SCH_COLLECTOR::DraggableItems,
aEvent.GetInt() );
// Exit if no item found at the current location or the item is already being edited.
if( (item == NULL) || (item->GetFlags() != 0) )
return;
}
switch( item->Type() )
{
case SCH_BUS_ENTRY_T:
case SCH_LINE_T:
case SCH_JUNCTION_T:
if( item->GetLayer() == LAYER_BUS )
break;
// Fall thru if item is not on bus layer.
case SCH_COMPONENT_T:
case SCH_GLOBAL_LABEL_T:
case SCH_HIERARCHICAL_LABEL_T:
case SCH_SHEET_T:
DrawPanel->MoveCursorToCrossHair();
// The easiest way to handle a drag component or sheet command
// is to simulate a block drag command
if( screen->m_BlockLocate.m_State == STATE_NO_BLOCK )
{
if( !HandleBlockBegin( &dc, BLOCK_DRAG, screen->GetCrossHairPosition() ) )
break;
// Give a non null size to the search block:
screen->m_BlockLocate.Inflate( 1 );
HandleBlockEnd( &dc );
}
break;
default:
wxFAIL_MSG( wxString::Format( wxT( "Cannot drag schematic item type %s." ),
GetChars( item->GetClass() ) ) );
}
// Since the drag is actually a block command, clear the current item.
screen->SetCurItem( NULL );
}

View File

@ -135,6 +135,7 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME )
EVT_MENU( ID_CANCEL_CURRENT_COMMAND, SCH_EDIT_FRAME::OnCancelCurrentCommand )
EVT_MENU( ID_SCH_ROTATE_ITEM, SCH_EDIT_FRAME::OnRotate )
EVT_MENU( ID_SCH_DRAG_ITEM, SCH_EDIT_FRAME::OnDragItem )
EVT_MENU_RANGE( ID_POPUP_START_RANGE, ID_POPUP_END_RANGE,
SCH_EDIT_FRAME::Process_Special_Functions )
EVT_MENU_RANGE( ID_SCH_EDIT_ITEM, ID_SCH_EDIT_COMPONENT_FOOTPRINT,

View File

@ -635,6 +635,12 @@ private:
*/
void OnEditItem( wxCommandEvent& aEvent );
/**
* Function OnDragItem
* handles the #ID_SCH_DRAG_ITEM event used to drag schematic itams.
*/
void OnDragItem( wxCommandEvent& aEvent );
void OnExit( wxCommandEvent& event );
void OnAnnotate( wxCommandEvent& event );
void OnErc( wxCommandEvent& event );