pcbnew: Add "Select All" Action to pcbnew and fpedit

Fixes https://gitlab.com/kicad/code/kicad/issues/2497
This commit is contained in:
Seth Hillbrand 2020-08-19 15:15:44 -07:00
parent 9cda3dbff5
commit 1e315bc3fe
11 changed files with 93 additions and 5 deletions

View File

@ -161,12 +161,18 @@ TOOL_ACTION ACTIONS::copy( "common.Interactive.copy",
TOOL_ACTION ACTIONS::paste( "common.Interactive.paste", TOOL_ACTION ACTIONS::paste( "common.Interactive.paste",
AS_GLOBAL, AS_GLOBAL,
MD_CTRL + 'V', LEGACY_HK_NAME( "Paste" ), MD_CTRL + 'V', LEGACY_HK_NAME( "Paste" ),
_( "Paste" ), _( "Paste clipboard into schematic" ), _( "Paste" ), _( "Paste items(s) from clipboard" ),
paste_xpm );
TOOL_ACTION ACTIONS::selectAll( "common.Interactive.selectAll",
AS_GLOBAL,
MD_CTRL + 'A', "",
_( "Select All" ), _( "Paste clipboard into schematic" ),
paste_xpm ); paste_xpm );
TOOL_ACTION ACTIONS::pasteSpecial( "common.Interactive.pasteSpecial", TOOL_ACTION ACTIONS::pasteSpecial( "common.Interactive.pasteSpecial",
AS_GLOBAL, 0, "", AS_GLOBAL, 0, "",
_( "Paste Special..." ), _( "Paste clipboard into schematic with options" ), _( "Paste Special..." ), _( "Paste item(s) from clipboard with options" ),
paste_xpm ); paste_xpm );
TOOL_ACTION ACTIONS::duplicate( "common.Interactive.duplicate", TOOL_ACTION ACTIONS::duplicate( "common.Interactive.duplicate",

View File

@ -70,6 +70,7 @@ public:
static TOOL_ACTION copy; static TOOL_ACTION copy;
static TOOL_ACTION paste; static TOOL_ACTION paste;
static TOOL_ACTION pasteSpecial; static TOOL_ACTION pasteSpecial;
static TOOL_ACTION selectAll;
static TOOL_ACTION duplicate; static TOOL_ACTION duplicate;
static TOOL_ACTION doDelete; // sadly 'delete' is a reserved word static TOOL_ACTION doDelete; // sadly 'delete' is a reserved word
static TOOL_ACTION deleteTool; static TOOL_ACTION deleteTool;

View File

@ -96,8 +96,7 @@ TOOL_ACTION KICAD_MANAGER_ACTIONS::convertImage( "kicad.Control.convertImage",
bitmap2component_xpm ); bitmap2component_xpm );
TOOL_ACTION KICAD_MANAGER_ACTIONS::showCalculator( "kicad.Control.showCalculator", TOOL_ACTION KICAD_MANAGER_ACTIONS::showCalculator( "kicad.Control.showCalculator",
AS_GLOBAL, AS_GLOBAL, 0, LEGACY_HK_NAME( "Run PcbCalculator" ),
MD_CTRL + 'A', LEGACY_HK_NAME( "Run PcbCalculator" ),
_( "Calculator Tools" ), _( "Run component calculations, track width calculations, etc." ), _( "Calculator Tools" ), _( "Run component calculations, track width calculations, etc." ),
calculator_xpm ); calculator_xpm );

View File

@ -114,6 +114,9 @@ void FOOTPRINT_EDIT_FRAME::ReCreateMenuBar()
editMenu->Add( ACTIONS::doDelete ); editMenu->Add( ACTIONS::doDelete );
editMenu->Add( ACTIONS::duplicate ); editMenu->Add( ACTIONS::duplicate );
editMenu->AppendSeparator();
editMenu->Add( ACTIONS::selectAll );
editMenu->AppendSeparator(); editMenu->AppendSeparator();
editMenu->Add( PCB_ACTIONS::footprintProperties ); editMenu->Add( PCB_ACTIONS::footprintProperties );
editMenu->Add( PCB_ACTIONS::defaultPadProperties ); editMenu->Add( PCB_ACTIONS::defaultPadProperties );

View File

@ -210,6 +210,9 @@ void PCB_EDIT_FRAME::ReCreateMenuBar()
editMenu->Add( ACTIONS::doDelete ); editMenu->Add( ACTIONS::doDelete );
editMenu->Add( ACTIONS::duplicate ); editMenu->Add( ACTIONS::duplicate );
editMenu->AppendSeparator();
editMenu->Add( ACTIONS::selectAll );
editMenu->AppendSeparator(); editMenu->AppendSeparator();
editMenu->Add( ACTIONS::find ); editMenu->Add( ACTIONS::find );

View File

@ -529,6 +529,7 @@ void PCB_EDIT_FRAME::setupUIConditions()
mgr->SetConditions( ACTIONS::copy, ENABLE( SELECTION_CONDITIONS::NotEmpty ) ); mgr->SetConditions( ACTIONS::copy, ENABLE( SELECTION_CONDITIONS::NotEmpty ) );
mgr->SetConditions( ACTIONS::paste, ENABLE( SELECTION_CONDITIONS::Idle && cond.NoActiveTool() ) ); mgr->SetConditions( ACTIONS::paste, ENABLE( SELECTION_CONDITIONS::Idle && cond.NoActiveTool() ) );
mgr->SetConditions( ACTIONS::pasteSpecial, ENABLE( SELECTION_CONDITIONS::Idle && cond.NoActiveTool() ) ); mgr->SetConditions( ACTIONS::pasteSpecial, ENABLE( SELECTION_CONDITIONS::Idle && cond.NoActiveTool() ) );
mgr->SetConditions( ACTIONS::selectAll, ENABLE( cond.HasItems() ) );
mgr->SetConditions( ACTIONS::doDelete, ENABLE( SELECTION_CONDITIONS::NotEmpty ) ); mgr->SetConditions( ACTIONS::doDelete, ENABLE( SELECTION_CONDITIONS::NotEmpty ) );
mgr->SetConditions( ACTIONS::duplicate, ENABLE( SELECTION_CONDITIONS::NotEmpty ) ); mgr->SetConditions( ACTIONS::duplicate, ENABLE( SELECTION_CONDITIONS::NotEmpty ) );

View File

@ -25,6 +25,7 @@
*/ */
#include <limits> #include <limits>
#include <class_board.h>
#include <class_module.h> #include <class_module.h>
#include <class_edge_mod.h> #include <class_edge_mod.h>
#include <collectors.h> #include <collectors.h>
@ -182,6 +183,12 @@ bool EDIT_TOOL::Init()
&& !frame()->IsCurrentTool( PCB_ACTIONS::moveWithReference ); && !frame()->IsCurrentTool( PCB_ACTIONS::moveWithReference );
}; };
auto noItemsCondition =
[ this ] ( const SELECTION& aSelections ) -> bool
{
return frame()->GetBoard() && !frame()->GetBoard()->IsEmpty();
};
// Add context menu entries that are displayed when selection tool is active // Add context menu entries that are displayed when selection tool is active
CONDITIONAL_MENU& menu = m_selectionTool->GetToolMenu().GetMenu(); CONDITIONAL_MENU& menu = m_selectionTool->GetToolMenu().GetMenu();
@ -215,6 +222,9 @@ bool EDIT_TOOL::Init()
// Don't add things like Paste when another tool is active. // Don't add things like Paste when another tool is active.
menu.AddItem( ACTIONS::paste, noActiveToolCondition ); menu.AddItem( ACTIONS::paste, noActiveToolCondition );
menu.AppendSeparator();
menu.AddItem( ACTIONS::selectAll, noItemsCondition );
// Footprint actions // Footprint actions
menu.AddSeparator(); menu.AddSeparator();
menu.AddItem( PCB_ACTIONS::editFpInFpEditor, singleModuleCondition ); menu.AddItem( PCB_ACTIONS::editFpInFpEditor, singleModuleCondition );

View File

@ -23,6 +23,7 @@
*/ */
#include <class_board.h>
#include <pcb_base_frame.h> #include <pcb_base_frame.h>
#include <tool/selection.h> #include <tool/selection.h>
#include <tools/pcb_editor_conditions.h> #include <tools/pcb_editor_conditions.h>
@ -33,6 +34,17 @@
using namespace std::placeholders; using namespace std::placeholders;
SELECTION_CONDITION PCB_EDITOR_CONDITIONS::HasItems()
{
// Requires a PCB_BASE_FRAME
PCB_BASE_FRAME* drwFrame = dynamic_cast<PCB_BASE_FRAME*>( m_frame );
wxASSERT( drwFrame );
return std::bind( &PCB_EDITOR_CONDITIONS::padNumberDisplayFunc, _1, drwFrame );
}
SELECTION_CONDITION PCB_EDITOR_CONDITIONS::PadNumbersDisplay() SELECTION_CONDITION PCB_EDITOR_CONDITIONS::PadNumbersDisplay()
{ {
// Requires a PCB_BASE_FRAME // Requires a PCB_BASE_FRAME
@ -110,6 +122,14 @@ SELECTION_CONDITION PCB_EDITOR_CONDITIONS::ZoneDisplayMode( ZONE_DISPLAY_MODE aM
} }
bool PCB_EDITOR_CONDITIONS::hasItemsFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame )
{
BOARD* board = aFrame->GetBoard();
return board && !board->IsEmpty();
}
bool PCB_EDITOR_CONDITIONS::padNumberDisplayFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame ) bool PCB_EDITOR_CONDITIONS::padNumberDisplayFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame )
{ {
return aFrame->GetDisplayOptions().m_DisplayPadNum; return aFrame->GetDisplayOptions().m_DisplayPadNum;

View File

@ -45,6 +45,13 @@ public:
EDITOR_CONDITIONS( aFrame ) EDITOR_CONDITIONS( aFrame )
{} {}
/**
* Creates a functor that tests if there are items in the board
*
* @return Functor returning true if the the current board has items
*/
SELECTION_CONDITION HasItems();
/** /**
* Creates a functor that tests if the pad numbers are displayed * Creates a functor that tests if the pad numbers are displayed
* *
@ -96,6 +103,9 @@ public:
SELECTION_CONDITION ZoneDisplayMode( ZONE_DISPLAY_MODE aMode ); SELECTION_CONDITION ZoneDisplayMode( ZONE_DISPLAY_MODE aMode );
protected: protected:
///> Helper function used by HasItems()
static bool hasItemsFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame );
///> Helper function used by PadNumbersDisplay() ///> Helper function used by PadNumbersDisplay()
static bool padNumberDisplayFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame ); static bool padNumberDisplayFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame );

View File

@ -357,6 +357,9 @@ PCBNEW_SELECTION& SELECTION_TOOL::GetSelection()
} }
PCBNEW_SELECTION& SELECTION_TOOL::RequestSelection( CLIENT_SELECTION_FILTER aClientFilter, PCBNEW_SELECTION& SELECTION_TOOL::RequestSelection( CLIENT_SELECTION_FILTER aClientFilter,
std::vector<BOARD_ITEM*>* aFiltered, std::vector<BOARD_ITEM*>* aFiltered,
bool aConfirmLockedItems ) bool aConfirmLockedItems )
@ -788,6 +791,33 @@ int SELECTION_TOOL::SelectItem( const TOOL_EVENT& aEvent )
} }
int SELECTION_TOOL::SelectAll( const TOOL_EVENT& aEvent )
{
KIGFX::VIEW* view = getView();
// hold all visible items
std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
// Filter the view items based on the selection box
BOX2I selectionBox;
selectionBox.SetMaximum();
view->Query( selectionBox, selectedItems ); // Get the list of selected items
for( auto& item_pair : selectedItems )
{
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( item_pair.first );
if( !item || !Selectable( item ) || !itemPassesFilter( item ) )
continue;
select( item );
}
return 0;
}
void SELECTION_TOOL::AddItemToSel( BOARD_ITEM* aItem, bool aQuietMode ) void SELECTION_TOOL::AddItemToSel( BOARD_ITEM* aItem, bool aQuietMode )
{ {
if( aItem ) if( aItem )
@ -2607,4 +2637,6 @@ void SELECTION_TOOL::setTransitions()
Go( &SELECTION_TOOL::selectSheetContents, PCB_ACTIONS::selectOnSheetFromEeschema.MakeEvent() ); Go( &SELECTION_TOOL::selectSheetContents, PCB_ACTIONS::selectOnSheetFromEeschema.MakeEvent() );
Go( &SELECTION_TOOL::updateSelection, EVENTS::SelectedItemsModified ); Go( &SELECTION_TOOL::updateSelection, EVENTS::SelectedItemsModified );
Go( &SELECTION_TOOL::updateSelection, EVENTS::SelectedItemsMoved ); Go( &SELECTION_TOOL::updateSelection, EVENTS::SelectedItemsMoved );
Go( &SELECTION_TOOL::SelectAll, ACTIONS::selectAll.MakeEvent() );
} }

View File

@ -112,6 +112,9 @@ public:
int SelectItem( const TOOL_EVENT& aEvent ); int SelectItem( const TOOL_EVENT& aEvent );
void AddItemToSel( BOARD_ITEM* aItem, bool aQuietMode = false ); void AddItemToSel( BOARD_ITEM* aItem, bool aQuietMode = false );
///> Select all items on the board
int SelectAll( const TOOL_EVENT& aEvent );
///> Multiple item selection event handler ///> Multiple item selection event handler
int SelectItems( const TOOL_EVENT& aEvent ); int SelectItems( const TOOL_EVENT& aEvent );
@ -186,7 +189,7 @@ public:
void FilterCollectorForGroups( GENERAL_COLLECTOR& aCollector ) const; void FilterCollectorForGroups( GENERAL_COLLECTOR& aCollector ) const;
PCB_GROUP* GetEnteredGroup() { return m_enteredGroup; } PCB_GROUP* GetEnteredGroup() { return m_enteredGroup; }
private: private:
/** /**
* Function selectPoint() * Function selectPoint()