Table selections for PCBNew.

This commit is contained in:
Jeff Young 2024-03-09 19:19:47 +00:00
parent 36b9ef0dc9
commit 63b06095e6
4 changed files with 116 additions and 2 deletions

View File

@ -2400,7 +2400,7 @@ void PCB_PAINTER::draw( const PCB_TABLE* aTable, int aLayer )
// Highlight selected tablecells with a background wash.
for( PCB_TABLECELL* cell : aTable->GetCells() )
{
if( cell->IsSelected() )
if( aTable->IsSelected() || cell->IsSelected() )
{
std::vector<VECTOR2I> corners = cell->GetCorners();
std::deque<VECTOR2D> pts;

View File

@ -2756,7 +2756,7 @@ bool EDIT_TOOL::updateModificationPoint( PCB_SELECTION& aSelection )
return false;
// When there is only one item selected, the reference point is its position...
if( aSelection.Size() == 1 )
if( aSelection.Size() == 1 && aSelection.Front()->Type() != PCB_TABLE_T )
{
if( BOARD_ITEM* item = dynamic_cast<BOARD_ITEM*>( aSelection.Front() ) )
aSelection.SetReferencePoint( item->GetPosition() );

View File

@ -197,6 +197,9 @@ bool PCB_SELECTION_TOOL::Init()
return m_enteredGroup != nullptr;
};
auto tableCellSelection = SELECTION_CONDITIONS::MoreThan( 0 )
&& SELECTION_CONDITIONS::OnlyTypes( { PCB_TABLECELL_T } );
if( frame && frame->IsType( FRAME_PCB_EDITOR ) )
{
menu.AddMenu( selectMenu.get(), SELECTION_CONDITIONS::NotEmpty );
@ -208,6 +211,11 @@ bool PCB_SELECTION_TOOL::Init()
menu.AddItem( PCB_ACTIONS::groupEnter, groupEnterCondition, 1 );
menu.AddItem( PCB_ACTIONS::groupLeave, inGroupCondition, 1 );
menu.AddItem( PCB_ACTIONS::clearHighlight, haveHighlight, 1 );
menu.AddSeparator( haveHighlight, 1 );
menu.AddItem( ACTIONS::selectColumns, tableCellSelection, 2 );
menu.AddItem( ACTIONS::selectRows, tableCellSelection, 2 );
menu.AddItem( ACTIONS::selectTable, tableCellSelection, 2 );
menu.AddSeparator( 1 );
@ -3905,6 +3913,105 @@ int PCB_SELECTION_TOOL::updateSelection( const TOOL_EVENT& aEvent )
}
int PCB_SELECTION_TOOL::SelectColumns( const TOOL_EVENT& aEvent )
{
std::set<std::pair<PCB_TABLE*, int>> columns;
bool added = false;
for( EDA_ITEM* item : m_selection )
{
if( PCB_TABLECELL* cell = dynamic_cast<PCB_TABLECELL*>( item ) )
{
PCB_TABLE* table = static_cast<PCB_TABLE*>( cell->GetParent() );
columns.insert( std::make_pair( table, cell->GetColumn() ) );
}
}
for( auto& [ table, col ] : columns )
{
for( int row = 0; row < table->GetRowCount(); ++row )
{
PCB_TABLECELL* cell = table->GetCell( row, col );
if( !cell->IsSelected() )
{
select( table->GetCell( row, col ) );
added = true;
}
}
}
if( added )
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
return 0;
}
int PCB_SELECTION_TOOL::SelectRows( const TOOL_EVENT& aEvent )
{
std::set<std::pair<PCB_TABLE*, int>> rows;
bool added = false;
for( EDA_ITEM* item : m_selection )
{
if( PCB_TABLECELL* cell = dynamic_cast<PCB_TABLECELL*>( item ) )
{
PCB_TABLE* table = static_cast<PCB_TABLE*>( cell->GetParent() );
rows.insert( std::make_pair( table, cell->GetRow() ) );
}
}
for( auto& [ table, row ] : rows )
{
for( int col = 0; col < table->GetRowCount(); ++col )
{
PCB_TABLECELL* cell = table->GetCell( row, col );
if( !cell->IsSelected() )
{
select( table->GetCell( row, col ) );
added = true;
}
}
}
if( added )
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
return 0;
}
int PCB_SELECTION_TOOL::SelectTable( const TOOL_EVENT& aEvent )
{
std::set<PCB_TABLE*> tables;
bool added = false;
for( EDA_ITEM* item : m_selection )
{
if( PCB_TABLECELL* cell = dynamic_cast<PCB_TABLECELL*>( item ) )
tables.insert( static_cast<PCB_TABLE*>( cell->GetParent() ) );
}
ClearSelection();
for( PCB_TABLE* table : tables )
{
if( !table->IsSelected() )
{
select( table );
added = true;
}
}
if( added )
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
return 0;
}
void PCB_SELECTION_TOOL::setTransitions()
{
Go( &PCB_SELECTION_TOOL::UpdateMenu, ACTIONS::updateMenu.MakeEvent() );
@ -3935,6 +4042,9 @@ void PCB_SELECTION_TOOL::setTransitions()
PCB_ACTIONS::selectOnSheetFromEeschema.MakeEvent() );
Go( &PCB_SELECTION_TOOL::updateSelection, EVENTS::SelectedItemsModified );
Go( &PCB_SELECTION_TOOL::updateSelection, EVENTS::SelectedItemsMoved );
Go( &PCB_SELECTION_TOOL::SelectColumns, ACTIONS::selectColumns.MakeEvent() );
Go( &PCB_SELECTION_TOOL::SelectRows, ACTIONS::selectRows.MakeEvent() );
Go( &PCB_SELECTION_TOOL::SelectTable, ACTIONS::selectTable.MakeEvent() );
Go( &PCB_SELECTION_TOOL::SelectAll, ACTIONS::selectAll.MakeEvent() );
Go( &PCB_SELECTION_TOOL::UnselectAll, ACTIONS::unselectAll.MakeEvent() );

View File

@ -106,6 +106,10 @@ public:
///< Select a single item under cursor event handler.
int CursorSelection( const TOOL_EVENT& aEvent );
int SelectColumns( const TOOL_EVENT& aEvent );
int SelectRows( const TOOL_EVENT& aEvent );
int SelectTable( const TOOL_EVENT& aEvent );
///< Clear current selection event handler.
int ClearSelection( const TOOL_EVENT& aEvent );
void ClearSelection( bool aQuietMode = false );