diff --git a/eeschema/onrightclick.cpp b/eeschema/onrightclick.cpp index b986465771..7119a9f71c 100644 --- a/eeschema/onrightclick.cpp +++ b/eeschema/onrightclick.cpp @@ -172,10 +172,6 @@ void AddMenusForHierchicalSheet( wxMenu* PopMenu, SCH_SHEET* Sheet ) { AddMenuItem( PopMenu, ID_POPUP_IMPORT_HLABEL_TO_SHEETPIN, _( "Import Sheet Pins" ), KiBitmap( import_hierarchical_label_xpm ) ); - - if( Sheet->HasUndefinedPins() ) // Sheet has pin labels, and can be cleaned - AddMenuItem( PopMenu, ID_POPUP_SCH_CLEANUP_SHEET, _( "Cleanup Sheet Pins" ), - KiBitmap( options_pinsheet_xpm ) ); } diff --git a/eeschema/schedit.cpp b/eeschema/schedit.cpp index 0a4dbc99ae..654e4a8e56 100644 --- a/eeschema/schedit.cpp +++ b/eeschema/schedit.cpp @@ -27,70 +27,26 @@ #include #include #include -#include #include #include #include #include -#include -#include #include -#include -#include -#include -#include -#include -#include #include #include #include #include - void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) +void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) { - int id = event.GetId(); - wxPoint pos; - SCH_SCREEN* screen = GetScreen(); - SCH_ITEM* item = screen->GetCurItem(); - - pos = wxGetMousePosition(); - - pos.y += 20; - - switch( id ) + if( event.GetId() == ID_HIERARCHY ) { - case ID_HIERARCHY: + wxPoint pos = wxGetMousePosition(); + pos.y += 20; + SetNoToolSelected(); InstallHierarchyFrame( pos ); SetRepeatItem( NULL ); - break; - - case ID_POPUP_SCH_CLEANUP_SHEET: - if( item != NULL && item->Type() == SCH_SHEET_T ) - { - SCH_SHEET* sheet = (SCH_SHEET*) item; - - if( !sheet->HasUndefinedPins() ) - { - DisplayInfoMessage( this, _( "There are no undefined labels in this sheet to clean up." ) ); - return; - } - - if( !IsOK( this, _( "Do you wish to cleanup this sheet?" ) ) ) - return; - - /* Save sheet in undo list before cleaning up unreferenced hierarchical labels. */ - SaveCopyInUndoList( sheet, UR_CHANGED ); - sheet->CleanupSheet(); - SyncView(); - GetCanvas()->Refresh(); - OnModify(); - } - break; - - default: // Log error: - wxFAIL_MSG( wxString::Format( "Cannot process command event ID %d", event.GetId() ) ); - break; } } diff --git a/eeschema/tools/sch_actions.cpp b/eeschema/tools/sch_actions.cpp index c51cfb4e42..8272b0745e 100644 --- a/eeschema/tools/sch_actions.cpp +++ b/eeschema/tools/sch_actions.cpp @@ -269,6 +269,9 @@ OPT SCH_ACTIONS::TranslateLegacyId( int aId ) case ID_POPUP_SCH_LEAVE_SHEET: return SCH_ACTIONS::leaveSheet.MakeEvent(); + case ID_POPUP_SCH_CLEANUP_SHEET: + return SCH_ACTIONS::cleanupSheetPins.MakeEvent(); + case ID_POPUP_SCH_SELECT_ON_PCB: return SCH_ACTIONS::explicitCrossProbe.MakeEvent(); } diff --git a/eeschema/tools/sch_actions.h b/eeschema/tools/sch_actions.h index 059f07b512..b1375812fb 100644 --- a/eeschema/tools/sch_actions.h +++ b/eeschema/tools/sch_actions.h @@ -145,6 +145,7 @@ public: // Miscellaneous static TOOL_ACTION enterSheet; static TOOL_ACTION leaveSheet; + static TOOL_ACTION cleanupSheetPins; static TOOL_ACTION switchCursor; static TOOL_ACTION switchUnits; static TOOL_ACTION updateUnits; diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index e400d0e093..dd8b192ba9 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -147,6 +147,11 @@ TOOL_ACTION SCH_ACTIONS::toText( "eeschema.InteractiveEdit.toText", _( "Change to Text" ), _( "Change existing item to a text comment" ), text_xpm ); +TOOL_ACTION SCH_ACTIONS::cleanupSheetPins( "eeschema.InteractiveEdit.cleanupSheetPins", + AS_GLOBAL, 0, + _( "Cleanup Sheet Pins" ), _( "Delete unreferenced sheet pins" ), + nullptr ); + TOOL_ACTION SCH_ACTIONS::doDelete( "eeschema.InteractiveEdit.doDelete", AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_DELETE ), _( "Delete" ), _( "Deletes selected item(s)" ), @@ -275,6 +280,9 @@ bool SCH_EDIT_TOOL::Init() auto singleComponentCondition = SELECTION_CONDITIONS::Count( 1 ) && SELECTION_CONDITIONS::OnlyType( SCH_COMPONENT_T ); + auto singleSheetCondition = SELECTION_CONDITIONS::Count( 1 ) + && SELECTION_CONDITIONS::OnlyType( SCH_SHEET_T ); + auto singleSymbolCondition = [] ( const SELECTION& aSel ) { if( aSel.GetSize() == 1 ) { @@ -406,6 +414,7 @@ bool SCH_EDIT_TOOL::Init() selToolMenu.AddItem( SCH_ACTIONS::toText, toTextlCondition, 200 ); selToolMenu.AddItem( SCH_ACTIONS::breakWire, wireSelectionCondition, 200 ); selToolMenu.AddItem( SCH_ACTIONS::breakBus, busSelectionCondition, 200 ); + selToolMenu.AddItem( SCH_ACTIONS::cleanupSheetPins, singleSheetCondition, 200 ); selToolMenu.AddSeparator( SELECTION_CONDITIONS::NotEmpty, 200 ); selToolMenu.AddItem( SCH_ACTIONS::cut, SELECTION_CONDITIONS::NotEmpty, 200 ); @@ -1609,6 +1618,34 @@ int SCH_EDIT_TOOL::BreakWire( const TOOL_EVENT& aEvent ) } +int SCH_EDIT_TOOL::CleanupSheetPins( const TOOL_EVENT& aEvent ) +{ + SELECTION& selection = m_selectionTool->RequestSelection( SCH_COLLECTOR::SheetsOnly ); + SCH_SHEET* sheet = (SCH_SHEET*) selection.Front(); + + if( !sheet ) + return 0; + + if( !sheet->HasUndefinedPins() ) + { + DisplayInfoMessage( m_frame, _( "There are no unreferenced pins in this sheet to remove." ) ); + return 0; + } + + if( !IsOK( m_frame, _( "Do you wish to delete the unreferenced pins from this sheet?" ) ) ) + return 0; + + m_frame->SaveCopyInUndoList( sheet, UR_CHANGED ); + + sheet->CleanupSheet(); + + updateView( sheet ); + m_frame->OnModify(); + + return 0; +} + + void SCH_EDIT_TOOL::updateView( EDA_ITEM* aItem ) { KICAD_T itemType = aItem->Type(); @@ -1660,4 +1697,6 @@ void SCH_EDIT_TOOL::setTransitions() Go( &SCH_EDIT_TOOL::BreakWire, SCH_ACTIONS::breakWire.MakeEvent() ); Go( &SCH_EDIT_TOOL::BreakWire, SCH_ACTIONS::breakBus.MakeEvent() ); + + Go( &SCH_EDIT_TOOL::CleanupSheetPins, SCH_ACTIONS::cleanupSheetPins.MakeEvent() ); } diff --git a/eeschema/tools/sch_edit_tool.h b/eeschema/tools/sch_edit_tool.h index 0f597fc0e3..fe3f6be8ee 100644 --- a/eeschema/tools/sch_edit_tool.h +++ b/eeschema/tools/sch_edit_tool.h @@ -71,6 +71,8 @@ public: int BreakWire( const TOOL_EVENT& aEvent ); + int CleanupSheetPins( const TOOL_EVENT& aEvent ); + /** * Function DoDelete() *