Move eeschema delete tool to modern toolset.

This commit is contained in:
Jeff Young 2019-04-23 14:06:37 +01:00
parent a967adbf26
commit d281f051ed
12 changed files with 193 additions and 98 deletions

View File

@ -41,6 +41,7 @@
#include <dialogs/dialog_schematic_find.h>
#include <tool/tool_manager.h>
#include <tools/sch_selection_tool.h>
#include <tools/sch_actions.h>
// Remark: the hotkey message info is used as keyword in hotkey config files and
// as comments in help windows, therefore translated only when displayed
@ -514,8 +515,8 @@ bool SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
cmd.SetId( ID_POPUP_DELETE_BLOCK );
GetEventHandler()->ProcessEvent( cmd );
}
else if( notBusy )
DeleteItemAtCrossHair();
else
GetToolManager()->RunAction( SCH_ACTIONS::remove, true );
break;
case HK_REPEAT_LAST:
@ -558,54 +559,6 @@ bool SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
}
break;
case HK_ADD_NEW_COMPONENT: // Add component
case HK_ADD_NEW_POWER: // Add power component
case HK_ADD_LABEL:
case HK_ADD_HLABEL:
case HK_ADD_GLABEL:
case HK_ADD_JUNCTION:
case HK_ADD_WIRE_ENTRY:
case HK_ADD_BUS_ENTRY:
case HK_ADD_HIER_SHEET:
case HK_ADD_GRAPHIC_TEXT:
case HK_ADD_GRAPHIC_POLYLINE:
case HK_ADD_NOCONN_FLAG: // Add a no connected flag
case HK_BEGIN_BUS:
case HK_BEGIN_WIRE:
if( notBusy )
{
EDA_HOTKEY_CLIENT_DATA data( aPosition );
cmd.SetInt( aHotKey );
cmd.SetClientObject( &data );
cmd.SetId( hotKey->m_IdMenuEvent );
GetEventHandler()->ProcessEvent( cmd );
}
else if( aItem && aItem->IsNew() )
{
// If the item is a bus or a wire, a begin command is not possible.
if( (GetToolId() == ID_BUS_BUTT) && (aItem->Type() == SCH_LINE_T) )
{
SCH_LINE* segment = (SCH_LINE*) aItem;
if( segment->GetLayer() != LAYER_BUS )
break;
// Bus in progress:
OnLeftClick( aDC, aPosition );
}
else if( (GetToolId() == ID_WIRE_BUTT ) && (aItem->Type() == SCH_LINE_T) )
{
SCH_LINE* segment = (SCH_LINE*) aItem;
if( segment->GetLayer() != LAYER_WIRE )
break;
// Wire in progress:
OnLeftClick( aDC, aPosition );
}
}
break;
case HK_DUPLICATE_ITEM: // Duplicate component or text/label
if( itemInEdit )
break;

View File

@ -88,10 +88,6 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
switch( GetToolId() )
{
case ID_SCHEMATIC_DELETE_ITEM_BUTT:
DeleteItemAtCrossHair();
break;
#ifdef KICAD_SPICE
case ID_SIM_PROBE:
{

View File

@ -282,8 +282,6 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME )
// Tools and buttons for vertical toolbar.
EVT_TOOL( ID_NO_TOOL_SELECTED, SCH_EDIT_FRAME::OnSelectTool )
EVT_TOOL( ID_SCHEMATIC_DELETE_ITEM_BUTT, SCH_EDIT_FRAME::OnSelectTool )
EVT_TOOL( ID_MENU_DELETE_ITEM_BUTT, SCH_EDIT_FRAME::OnSelectTool )
#ifdef KICAD_SPICE
EVT_TOOL( ID_SIM_SHOW, SCH_EDIT_FRAME::OnSimulate )

View File

@ -383,16 +383,6 @@ public:
*/
void AddItemToScreen( SCH_ITEM* aItem );
/**
* Delete the item found under the cross hair. If multiple items are found at the
* cross hair position, a context menu is displayed to clarify which item to delete.
* See LocateItem() for more information on locating multiple items.
*
* @return True if an item was deleted.
*/
bool DeleteItemAtCrossHair();
/**
* Finds a component in the schematic and an item in this component.
*

View File

@ -472,11 +472,6 @@ void SCH_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent )
SetNoToolSelected();
break;
case ID_MENU_DELETE_ITEM_BUTT:
case ID_SCHEMATIC_DELETE_ITEM_BUTT:
SetToolID( ID_SCHEMATIC_DELETE_ITEM_BUTT, wxCURSOR_BULLSEYE, _( "Delete item" ) );
break;
#ifdef KICAD_SPICE
case ID_SIM_PROBE:
SetToolID( id, -1, _( "Add a simulator probe" ) );
@ -525,32 +520,6 @@ void SCH_EDIT_FRAME::DeleteConnection( bool aFullConnection )
}
bool SCH_EDIT_FRAME::DeleteItemAtCrossHair()
{
SCH_SELECTION_TOOL* selTool = GetToolManager()->GetTool<SCH_SELECTION_TOOL>();
SCH_SCREEN* screen = GetScreen();
SCH_ITEM* item = selTool->SelectPoint( GetCrossHairPosition(), SCH_COLLECTOR::ParentItems );
if( item )
{
bool itemHasConnections = item->IsConnectable();
screen->SetCurItem( NULL );
SetRepeatItem( NULL );
DeleteItem( item );
if( itemHasConnections )
TestDanglingEnds();
GetCanvas()->Refresh();
OnModify();
return true;
}
return false;
}
// This function is a callback function, called by the mouse cursor moving event
static void moveItemWithMouseCursor( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
const wxPoint& aPosition, bool aErase )

View File

@ -30,6 +30,7 @@
#include <tools/sch_drawing_tool.h>
#include <tools/sch_selection_tool.h>
#include <tools/sch_actions.h>
#include <tools/sch_edit_tool.h>
#include <tool/zoom_tool.h>
OPT<TOOL_EVENT> SCH_ACTIONS::TranslateLegacyId( int aId )
@ -170,6 +171,13 @@ OPT<TOOL_EVENT> SCH_ACTIONS::TranslateLegacyId( int aId )
case ID_POPUP_END_LINE:
return SCH_ACTIONS::finishDrawing.MakeEvent();
case ID_MENU_DELETE_ITEM_BUTT:
case ID_SCHEMATIC_DELETE_ITEM_BUTT:
return SCH_ACTIONS::deleteItemCursor.MakeEvent();
case ID_POPUP_SCH_DELETE:
return SCH_ACTIONS::remove.MakeEvent();
}
return OPT<TOOL_EVENT>();
@ -184,4 +192,5 @@ void SCH_ACTIONS::RegisterAllTools( TOOL_MANAGER* aToolManager )
aToolManager->RegisterTool( new SCH_EDITOR_CONTROL );
aToolManager->RegisterTool( new SCH_PICKER_TOOL );
aToolManager->RegisterTool( new SCH_DRAWING_TOOL );
aToolManager->RegisterTool( new SCH_EDIT_TOOL );
}

View File

@ -117,6 +117,7 @@ public:
static TOOL_ACTION duplicate;
static TOOL_ACTION rotate;
static TOOL_ACTION properties;
static TOOL_ACTION remove;
static TOOL_ACTION addJunction;
static TOOL_ACTION addLabel;
static TOOL_ACTION addGlobalLabel;

View File

@ -122,6 +122,7 @@ private:
///> Sets up handlers for various events.
void setTransitions() override;
private:
KIGFX::SCH_VIEW* m_view;
KIGFX::VIEW_CONTROLS* m_controls;
SCH_EDIT_FRAME* m_frame;

View File

@ -21,10 +21,16 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "sch_edit_tool.h"
#include <tool/tool_manager.h>
#include <tools/sch_edit_tool.h>
#include <tools/sch_selection_tool.h>
#include <sch_actions.h>
#include <hotkeys.h>
#include <bitmaps.h>
#include <sch_item_struct.h>
#include <sch_view.h>
#include <sch_item_struct.h>
#include <sch_edit_frame.h>
TOOL_ACTION SCH_ACTIONS::editActivate( "eeschema.InteractiveEdit",
@ -48,3 +54,86 @@ TOOL_ACTION SCH_ACTIONS::properties( "eeschema.InteractiveEdit.properties",
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_EDIT ),
_( "Properties..." ), _( "Displays item properties dialog" ), config_xpm );
TOOL_ACTION SCH_ACTIONS::remove( "eeschema.InteractiveEdit.remove",
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_DELETE ),
_( "Delete" ), _( "Deletes selected item(s)" ), delete_xpm, AF_NONE );
SCH_EDIT_TOOL::SCH_EDIT_TOOL() :
TOOL_INTERACTIVE( "eeschema.InteractiveEdit" ),
m_view( nullptr ),
m_controls( nullptr ),
m_frame( nullptr ),
m_menu( *this )
{
};
SCH_EDIT_TOOL::~SCH_EDIT_TOOL()
{
}
bool SCH_EDIT_TOOL::Init()
{
auto activeToolFunctor = [ this ] ( const SELECTION& aSel ) {
return ( m_frame->GetToolId() != ID_NO_TOOL_SELECTED );
};
auto& ctxMenu = m_menu.GetMenu();
// cancel current tool goes in main context menu at the top if present
ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolFunctor, 1 );
ctxMenu.AddSeparator( activeToolFunctor, 1 );
return true;
}
void SCH_EDIT_TOOL::Reset( RESET_REASON aReason )
{
// Init variables used by every drawing tool
m_view = static_cast<KIGFX::SCH_VIEW*>( getView() );
m_controls = getViewControls();
m_frame = getEditFrame<SCH_EDIT_FRAME>();
}
int SCH_EDIT_TOOL::Remove( const TOOL_EVENT& aEvent )
{
SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
std::vector<SCH_ITEM*> lockedItems;
// get a copy instead of reference (as we're going to clear the selection before removing items)
SELECTION selectionCopy = selTool->RequestSelection();
if( selectionCopy.Empty() )
return 0;
// As we are about to remove items, they have to be removed from the selection first
m_toolMgr->RunAction( SCH_ACTIONS::selectionClear, true );
for( EDA_ITEM* it : selectionCopy )
{
SCH_ITEM* item = static_cast<SCH_ITEM*>( it );
bool itemHasConnections = item->IsConnectable();
m_frame->GetScreen()->SetCurItem( nullptr );
m_frame->SetRepeatItem( nullptr );
m_frame->DeleteItem( item );
if( itemHasConnections )
m_frame->TestDanglingEnds();
}
m_frame->GetCanvas()->Refresh();
m_frame->OnModify();
return 0;
}
void SCH_EDIT_TOOL::setTransitions()
{
Go( &SCH_EDIT_TOOL::Remove, SCH_ACTIONS::remove.MakeEvent() );
}

View File

@ -25,10 +25,44 @@
#define KICAD_SCH_EDIT_TOOL_H
#include <tool/tool_interactive.h>
#include <tool/tool_menu.h>
#include <sch_base_frame.h>
class SCH_EDIT_FRAME;
class SCH_EDIT_TOOL : public TOOL_INTERACTIVE
{
public:
SCH_EDIT_TOOL();
~SCH_EDIT_TOOL();
/// @copydoc TOOL_INTERACTIVE::Init()
bool Init() override;
/// @copydoc TOOL_INTERACTIVE::Reset()
void Reset( RESET_REASON aReason ) override;
///> Get the SCH_DRAWING_TOOL top-level context menu
inline TOOL_MENU& GetToolMenu()
{
return m_menu;
}
int Remove( const TOOL_EVENT& aEvent );
private:
///> Sets up handlers for various events.
void setTransitions() override;
private:
KIGFX::SCH_VIEW* m_view;
KIGFX::VIEW_CONTROLS* m_controls;
SCH_EDIT_FRAME* m_frame;
/// Menu model displayed by the tool.
TOOL_MENU m_menu;
};
#endif //KICAD_SCH_EDIT_TOOL_H

View File

@ -39,6 +39,7 @@
#include <project.h>
#include <hotkeys.h>
#include <advanced_config.h>
#include <status_popup.h>
TOOL_ACTION SCH_ACTIONS::refreshPreview( "eeschema.EditorControl.refreshPreview",
AS_GLOBAL, 0, "", "" );
@ -56,6 +57,10 @@ TOOL_ACTION SCH_ACTIONS::highlightNetCursor( "eeschema.EditorControl.highlightNe
AS_GLOBAL, 0,
_( "Highlight Net" ), _( "Highlight wires and pins of a net" ), NULL, AF_ACTIVATE );
TOOL_ACTION SCH_ACTIONS::deleteItemCursor( "eeschema.EditorControl.deleteItemCursor",
AS_GLOBAL, 0,
_( "Delete Items" ), _( "Delete clicked items" ), NULL, AF_ACTIVATE );
SCH_EDITOR_CONTROL::SCH_EDITOR_CONTROL() :
TOOL_INTERACTIVE( "eeschema.EditorControl" ),
@ -326,6 +331,51 @@ int SCH_EDITOR_CONTROL::HighlightNetCursor( const TOOL_EVENT& aEvent )
}
static bool deleteItem( SCH_EDIT_FRAME* aFrame, const VECTOR2D& aPosition )
{
SCH_SELECTION_TOOL* selectionTool = aFrame->GetToolManager()->GetTool<SCH_SELECTION_TOOL>();
wxCHECK( selectionTool, false );
aFrame->GetToolManager()->RunAction( SCH_ACTIONS::selectionClear, true );
SCH_ITEM* item = selectionTool->SelectPoint( aPosition );
if( item )
{
if( item->IsLocked() )
{
STATUS_TEXT_POPUP statusPopup( aFrame );
statusPopup.SetText( _( "Item locked." ) );
statusPopup.Expire( 2000 );
statusPopup.Popup();
statusPopup.Move( wxGetMousePosition() + wxPoint( 20, 20 ) );
}
else
{
aFrame->GetToolManager()->RunAction( SCH_ACTIONS::remove, true );
}
}
return true;
}
int SCH_EDITOR_CONTROL::DeleteItemCursor( const TOOL_EVENT& aEvent )
{
Activate();
SCH_PICKER_TOOL* picker = m_toolMgr->GetTool<SCH_PICKER_TOOL>();
wxCHECK( picker, 0 );
m_frame->SetToolID( ID_SCHEMATIC_DELETE_ITEM_BUTT, wxCURSOR_BULLSEYE, _( "Delete item" ) );
picker->SetClickHandler( std::bind( deleteItem, m_frame, std::placeholders::_1 ) );
picker->Activate();
Wait();
return 0;
}
void SCH_EDITOR_CONTROL::setTransitions()
{
/*
@ -345,4 +395,6 @@ void SCH_EDITOR_CONTROL::setTransitions()
Go( &SCH_EDITOR_CONTROL::ClearHighlight, SCH_ACTIONS::clearHighlight.MakeEvent() );
Go( &SCH_EDITOR_CONTROL::HighlightNetCursor, SCH_ACTIONS::highlightNetCursor.MakeEvent() );
Go( &SCH_EDITOR_CONTROL::HighlightNetSelection, SCH_ACTIONS::highlightNetSelection.MakeEvent() );
Go( &SCH_EDITOR_CONTROL::DeleteItemCursor, SCH_ACTIONS::deleteItemCursor.MakeEvent() );
}

View File

@ -71,6 +71,9 @@ public:
///> Launches a tool to highlight nets.
int HighlightNetCursor( const TOOL_EVENT& aEvent );
///> Runs the deletion tool.
int DeleteItemCursor( const TOOL_EVENT& aEvent );
private:
///> Sets up handlers for various events.