ADDED grouping of selected pins in Pin Table.
Fixes https://gitlab.com/kicad/code/kicad/issues/4956
This commit is contained in:
parent
a54457386c
commit
48dd810cd1
|
@ -44,6 +44,38 @@
|
|||
#define DEMORGAN_STD _( "Standard" )
|
||||
#define DEMORGAN_ALT _( "Alternate" )
|
||||
|
||||
|
||||
void getSelectedArea( WX_GRID* aGrid, int* aRowStart, int* aRowCount )
|
||||
{
|
||||
wxGridCellCoordsArray topLeft = aGrid->GetSelectionBlockTopLeft();
|
||||
wxGridCellCoordsArray botRight = aGrid->GetSelectionBlockBottomRight();
|
||||
|
||||
wxArrayInt cols = aGrid->GetSelectedCols();
|
||||
wxArrayInt rows = aGrid->GetSelectedRows();
|
||||
|
||||
if( topLeft.Count() && botRight.Count() )
|
||||
{
|
||||
*aRowStart = topLeft[0].GetRow();
|
||||
*aRowCount = botRight[0].GetRow() - *aRowStart + 1;
|
||||
}
|
||||
else if( cols.Count() )
|
||||
{
|
||||
*aRowStart = 0;
|
||||
*aRowCount = aGrid->GetNumberRows();
|
||||
}
|
||||
else if( rows.Count() )
|
||||
{
|
||||
*aRowStart = rows[0];
|
||||
*aRowCount = rows.Count();
|
||||
}
|
||||
else
|
||||
{
|
||||
*aRowStart = aGrid->GetGridCursorRow();
|
||||
*aRowCount = *aRowStart >= 0 ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class PIN_TABLE_DATA_MODEL : public wxGridTableBase
|
||||
{
|
||||
public:
|
||||
|
@ -438,14 +470,32 @@ public:
|
|||
return res;
|
||||
}
|
||||
|
||||
void RebuildRows( const LIB_PINS& aPins, bool groupByName )
|
||||
void RebuildRows( const LIB_PINS& aPins, bool groupByName, bool groupBySelection )
|
||||
{
|
||||
if ( GetView() )
|
||||
WX_GRID* grid = dynamic_cast<WX_GRID*>( GetView() );
|
||||
|
||||
if( grid )
|
||||
{
|
||||
if( groupBySelection )
|
||||
{
|
||||
for( LIB_PIN* pin : aPins )
|
||||
pin->ClearTempFlags();
|
||||
|
||||
int firstSelectedRow;
|
||||
int selectedRowCount;
|
||||
|
||||
getSelectedArea( grid, &firstSelectedRow, &selectedRowCount );
|
||||
|
||||
for( int ii = 0; ii < selectedRowCount; ++ii )
|
||||
{
|
||||
for( LIB_PIN* pin : m_rows[ firstSelectedRow + ii ] )
|
||||
pin->SetFlags( TEMP_SELECTED );
|
||||
}
|
||||
}
|
||||
|
||||
// Commit any pending in-place edits before the row gets moved out from under
|
||||
// the editor.
|
||||
if( WX_GRID* grid = dynamic_cast<WX_GRID*>( GetView() ) )
|
||||
grid->CommitPendingChanges( true );
|
||||
grid->CommitPendingChanges( true );
|
||||
|
||||
wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0, m_rows.size() );
|
||||
GetView()->ProcessTableMessage( msg );
|
||||
|
@ -453,6 +503,9 @@ public:
|
|||
|
||||
m_rows.clear();
|
||||
|
||||
if( groupBySelection )
|
||||
m_rows.emplace_back( LIB_PINS() );
|
||||
|
||||
for( LIB_PIN* pin : aPins )
|
||||
{
|
||||
if( m_unitFilter == -1 || pin->GetUnit() == 0 || pin->GetUnit() == m_unitFilter )
|
||||
|
@ -461,6 +514,8 @@ public:
|
|||
|
||||
if( groupByName )
|
||||
rowIndex = findRow( m_rows, pin->GetName() );
|
||||
else if( groupBySelection && pin->GetFlags() & TEMP_SELECTED )
|
||||
rowIndex = 0;
|
||||
|
||||
if( rowIndex < 0 )
|
||||
{
|
||||
|
@ -484,12 +539,16 @@ public:
|
|||
for( LIB_PINS& row : m_rows )
|
||||
SortPins( row );
|
||||
|
||||
SortRows( sortCol, ascending );
|
||||
if( !groupBySelection )
|
||||
SortRows( sortCol, ascending );
|
||||
|
||||
if ( GetView() )
|
||||
{
|
||||
wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_rows.size() );
|
||||
GetView()->ProcessTableMessage( msg );
|
||||
|
||||
if( groupBySelection )
|
||||
GetView()->SelectRow( 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -747,7 +806,7 @@ bool DIALOG_LIB_EDIT_PIN_TABLE::TransferDataToWindow()
|
|||
for( LIB_PIN* pin = m_part->GetNextPin( nullptr ); pin; pin = m_part->GetNextPin( pin ) )
|
||||
m_pins.push_back( new LIB_PIN( *pin ) );
|
||||
|
||||
m_dataModel->RebuildRows( m_pins, m_cbGroup->GetValue() );
|
||||
m_dataModel->RebuildRows( m_pins, m_cbGroup->GetValue(), false );
|
||||
|
||||
if( m_part->IsMulti() )
|
||||
m_grid->ShowCol( COL_UNIT );
|
||||
|
@ -759,11 +818,6 @@ bool DIALOG_LIB_EDIT_PIN_TABLE::TransferDataToWindow()
|
|||
else
|
||||
m_grid->HideCol( COL_DEMORGAN );
|
||||
|
||||
if( m_cbGroup->GetValue() )
|
||||
m_grid->ShowCol( COL_PIN_COUNT );
|
||||
else
|
||||
m_grid->HideCol( COL_PIN_COUNT );
|
||||
|
||||
updateSummary();
|
||||
|
||||
return true;
|
||||
|
@ -909,22 +963,31 @@ bool DIALOG_LIB_EDIT_PIN_TABLE::IsDisplayGrouped()
|
|||
}
|
||||
|
||||
|
||||
void DIALOG_LIB_EDIT_PIN_TABLE::OnGroupSelected( wxCommandEvent& event )
|
||||
{
|
||||
m_cbGroup->SetValue( false );
|
||||
|
||||
m_dataModel->RebuildRows( m_pins, false, true );
|
||||
|
||||
m_grid->ShowCol( COL_PIN_COUNT );
|
||||
m_grid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
|
||||
|
||||
adjustGridColumns();
|
||||
}
|
||||
|
||||
|
||||
void DIALOG_LIB_EDIT_PIN_TABLE::OnRebuildRows( wxCommandEvent& )
|
||||
{
|
||||
if( !m_grid->CommitPendingChanges() )
|
||||
return;
|
||||
|
||||
m_dataModel->RebuildRows( m_pins, m_cbGroup->GetValue() );
|
||||
m_dataModel->RebuildRows( m_pins, m_cbGroup->GetValue(), false );
|
||||
|
||||
if( m_cbGroup->GetValue() )
|
||||
{
|
||||
m_grid->ShowCol( COL_PIN_COUNT );
|
||||
m_grid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_grid->HideCol( COL_PIN_COUNT );
|
||||
}
|
||||
|
||||
adjustGridColumns();
|
||||
}
|
||||
|
@ -1016,6 +1079,14 @@ void DIALOG_LIB_EDIT_PIN_TABLE::OnUpdateUI( wxUpdateUIEvent& event )
|
|||
if( !m_grid->IsCellEditControlShown() )
|
||||
adjustGridColumns();
|
||||
}
|
||||
|
||||
int firstSelectedRow;
|
||||
int selectedRowCount;
|
||||
|
||||
getSelectedArea( m_grid, &firstSelectedRow, &selectedRowCount );
|
||||
|
||||
if( selectedRowCount > 1 != m_groupSelected->IsEnabled() )
|
||||
m_groupSelected->Enable( selectedRowCount > 1 );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -66,6 +66,7 @@ public:
|
|||
void OnSize( wxSizeEvent& event ) override;
|
||||
void OnCellEdited( wxGridEvent& event ) override;
|
||||
void OnRebuildRows( wxCommandEvent& event ) override;
|
||||
void OnGroupSelected( wxCommandEvent& event ) override;
|
||||
void OnFilterCheckBox( wxCommandEvent& event ) override;
|
||||
void OnFilterChoice( wxCommandEvent& event ) override;
|
||||
void OnUpdateUI( wxUpdateUIEvent& event ) override;
|
||||
|
|
|
@ -119,38 +119,44 @@ DIALOG_LIB_EDIT_PIN_TABLE_BASE::DIALOG_LIB_EDIT_PIN_TABLE_BASE( wxWindow* parent
|
|||
wxBoxSizer* bBottomSizer;
|
||||
bBottomSizer = new wxBoxSizer( wxHORIZONTAL );
|
||||
|
||||
wxBoxSizer* bSizer5;
|
||||
bSizer5 = new wxBoxSizer( wxHORIZONTAL );
|
||||
|
||||
m_addButton = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 );
|
||||
bBottomSizer->Add( m_addButton, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 );
|
||||
|
||||
|
||||
bBottomSizer->Add( 20, 0, 0, wxEXPAND, 5 );
|
||||
bSizer5->Add( m_addButton, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 );
|
||||
|
||||
m_deleteButton = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 );
|
||||
bBottomSizer->Add( m_deleteButton, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 10 );
|
||||
bSizer5->Add( m_deleteButton, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 10 );
|
||||
|
||||
m_divider1 = new BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 );
|
||||
m_divider1->Enable( false );
|
||||
|
||||
bBottomSizer->Add( m_divider1, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 10 );
|
||||
bSizer5->Add( m_divider1, 0, wxEXPAND|wxALL, 4 );
|
||||
|
||||
m_cbGroup = new wxCheckBox( this, wxID_ANY, _("Group by name"), wxDefaultPosition, wxDefaultSize, 0 );
|
||||
bBottomSizer->Add( m_cbGroup, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 10 );
|
||||
bSizer5->Add( m_cbGroup, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 );
|
||||
|
||||
m_groupSelected = new wxButton( this, wxID_ANY, _("Group Selected"), wxDefaultPosition, wxDefaultSize, 0 );
|
||||
bSizer5->Add( m_groupSelected, 0, wxALL|wxALIGN_CENTER_VERTICAL, 7 );
|
||||
|
||||
m_refreshButton = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 );
|
||||
bBottomSizer->Add( m_refreshButton, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 10 );
|
||||
bSizer5->Add( m_refreshButton, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 10 );
|
||||
|
||||
m_divider2 = new BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 );
|
||||
m_divider2->Enable( false );
|
||||
|
||||
bBottomSizer->Add( m_divider2, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 10 );
|
||||
bSizer5->Add( m_divider2, 0, wxEXPAND|wxALL, 4 );
|
||||
|
||||
m_cbFilterByUnit = new wxCheckBox( this, wxID_ANY, _("Filter by unit:"), wxDefaultPosition, wxDefaultSize, 0 );
|
||||
bBottomSizer->Add( m_cbFilterByUnit, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 );
|
||||
bSizer5->Add( m_cbFilterByUnit, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM, 5 );
|
||||
|
||||
wxArrayString m_unitFilterChoices;
|
||||
m_unitFilter = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_unitFilterChoices, 0 );
|
||||
m_unitFilter->SetSelection( 0 );
|
||||
bBottomSizer->Add( m_unitFilter, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
||||
bSizer5->Add( m_unitFilter, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
||||
|
||||
|
||||
bBottomSizer->Add( bSizer5, 0, wxEXPAND|wxTOP|wxBOTTOM|wxRIGHT, 5 );
|
||||
|
||||
|
||||
bBottomSizer->Add( 30, 0, 1, wxEXPAND, 5 );
|
||||
|
@ -182,6 +188,7 @@ DIALOG_LIB_EDIT_PIN_TABLE_BASE::DIALOG_LIB_EDIT_PIN_TABLE_BASE( wxWindow* parent
|
|||
m_addButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnAddRow ), NULL, this );
|
||||
m_deleteButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnDeleteRow ), NULL, this );
|
||||
m_cbGroup->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnRebuildRows ), NULL, this );
|
||||
m_groupSelected->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnGroupSelected ), NULL, this );
|
||||
m_refreshButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnRebuildRows ), NULL, this );
|
||||
m_cbFilterByUnit->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnFilterCheckBox ), NULL, this );
|
||||
m_unitFilter->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnFilterChoice ), NULL, this );
|
||||
|
@ -198,6 +205,7 @@ DIALOG_LIB_EDIT_PIN_TABLE_BASE::~DIALOG_LIB_EDIT_PIN_TABLE_BASE()
|
|||
m_addButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnAddRow ), NULL, this );
|
||||
m_deleteButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnDeleteRow ), NULL, this );
|
||||
m_cbGroup->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnRebuildRows ), NULL, this );
|
||||
m_groupSelected->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnGroupSelected ), NULL, this );
|
||||
m_refreshButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnRebuildRows ), NULL, this );
|
||||
m_cbFilterByUnit->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnFilterCheckBox ), NULL, this );
|
||||
m_unitFilter->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_LIB_EDIT_PIN_TABLE_BASE::OnFilterChoice ), NULL, this );
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -53,6 +53,7 @@ class DIALOG_LIB_EDIT_PIN_TABLE_BASE : public DIALOG_SHIM
|
|||
wxBitmapButton* m_deleteButton;
|
||||
BITMAP_BUTTON* m_divider1;
|
||||
wxCheckBox* m_cbGroup;
|
||||
wxButton* m_groupSelected;
|
||||
wxBitmapButton* m_refreshButton;
|
||||
BITMAP_BUTTON* m_divider2;
|
||||
wxCheckBox* m_cbFilterByUnit;
|
||||
|
@ -69,6 +70,7 @@ class DIALOG_LIB_EDIT_PIN_TABLE_BASE : public DIALOG_SHIM
|
|||
virtual void OnAddRow( wxCommandEvent& event ) = 0;
|
||||
virtual void OnDeleteRow( wxCommandEvent& event ) = 0;
|
||||
virtual void OnRebuildRows( wxCommandEvent& event ) = 0;
|
||||
virtual void OnGroupSelected( wxCommandEvent& event ) = 0;
|
||||
virtual void OnFilterCheckBox( wxCommandEvent& event ) = 0;
|
||||
virtual void OnFilterChoice( wxCommandEvent& event ) = 0;
|
||||
virtual void OnCancel( wxCommandEvent& event ) = 0;
|
||||
|
|
Loading…
Reference in New Issue