From 2dfacd648f0162d61ba02068b6c8cdc945805202 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 25 Jul 2025 14:27:06 +0100 Subject: [PATCH] Share more code. --- .../dialog_design_block_properties.cpp | 46 +---- common/dialogs/panel_setup_netclasses.cpp | 195 ++++++------------ common/widgets/wx_grid.cpp | 92 +++++++-- eeschema/dialogs/dialog_label_properties.cpp | 90 +++----- .../dialogs/dialog_lib_symbol_properties.cpp | 65 ++---- eeschema/dialogs/dialog_sheet_properties.cpp | 58 ++---- eeschema/dialogs/dialog_symbol_properties.cpp | 64 ++---- eeschema/dialogs/panel_setup_buses.cpp | 30 +-- .../dialogs/panel_template_fieldnames.cpp | 53 +---- include/widgets/wx_grid.h | 16 +- .../dialogs/dialog_manage_repositories.cpp | 88 ++------ .../pcm/dialogs/dialog_manage_repositories.h | 1 - pcbnew/CMakeLists.txt | 2 +- .../dialogs/panel_pcbnew_action_plugins.cpp | 77 ++----- .../dialogs/panel_setup_tracks_and_vias.cpp | 51 +++-- pcbnew/dialogs/panel_setup_tracks_and_vias.h | 2 + pcbnew/zone_manager/dialog_zone_manager.cpp | 94 ++++----- pcbnew/zone_manager/dialog_zone_manager.h | 26 +-- pcbnew/zone_manager/managed_zone.h | 2 +- ...iew_table.cpp => model_zones_overview.cpp} | 58 ++---- ...verview_table.h => model_zones_overview.h} | 20 +- 21 files changed, 421 insertions(+), 709 deletions(-) rename pcbnew/zone_manager/{model_zones_overview_table.cpp => model_zones_overview.cpp} (72%) rename pcbnew/zone_manager/{model_zones_overview_table.h => model_zones_overview.h} (91%) diff --git a/common/dialogs/dialog_design_block_properties.cpp b/common/dialogs/dialog_design_block_properties.cpp index 49c907c579..b467b6c07a 100644 --- a/common/dialogs/dialog_design_block_properties.cpp +++ b/common/dialogs/dialog_design_block_properties.cpp @@ -148,47 +148,21 @@ void DIALOG_DESIGN_BLOCK_PROPERTIES::OnDeleteField( wxCommandEvent& event ) void DIALOG_DESIGN_BLOCK_PROPERTIES::OnMoveFieldUp( wxCommandEvent& event ) { - if( !m_fieldsGrid->CommitPendingChanges() ) - return; - - int row = m_fieldsGrid->GetGridCursorRow(); - - if( m_fieldsGrid->GetNumberRows() < 2 || row == 0 ) - return; - - // Swap the grid at row with the grid at row - 1 - wxString temp0 = m_fieldsGrid->GetCellValue( row, 0 ); - m_fieldsGrid->SetCellValue( row, 0, m_fieldsGrid->GetCellValue( row - 1, 0 ) ); - m_fieldsGrid->SetCellValue( row - 1, 0, temp0 ); - - wxString temp1 = m_fieldsGrid->GetCellValue( row, 1 ); - m_fieldsGrid->SetCellValue( row, 1, m_fieldsGrid->GetCellValue( row - 1, 1 ) ); - m_fieldsGrid->SetCellValue( row - 1, 1, temp1 ); - - m_fieldsGrid->SetGridCursor( row - 1, 0 ); + m_fieldsGrid->OnMoveRowUp( + [&]( int row ) + { + m_fieldsGrid->SwapRows( row, row - 1 ); + } ); } void DIALOG_DESIGN_BLOCK_PROPERTIES::OnMoveFieldDown( wxCommandEvent& event ) { - if( !m_fieldsGrid->CommitPendingChanges() ) - return; - - int row = m_fieldsGrid->GetGridCursorRow(); - - if( m_fieldsGrid->GetNumberRows() < 2 || row == ( (int) m_fieldsGrid->GetNumberRows() - 1 ) ) - return; - - // Swap the grid at row with the grid at row + 1 - wxString temp0 = m_fieldsGrid->GetCellValue( row, 0 ); - m_fieldsGrid->SetCellValue( row, 0, m_fieldsGrid->GetCellValue( row + 1, 0 ) ); - m_fieldsGrid->SetCellValue( row + 1, 0, temp0 ); - - wxString temp1 = m_fieldsGrid->GetCellValue( row, 1 ); - m_fieldsGrid->SetCellValue( row, 1, m_fieldsGrid->GetCellValue( row + 1, 1 ) ); - m_fieldsGrid->SetCellValue( row + 1, 1, temp1 ); - - m_fieldsGrid->SetGridCursor( row + 1, 0 ); + m_fieldsGrid->OnMoveRowUp( + [&]( int row ) + { + m_fieldsGrid->SwapRows( row, row + 1 ); + } ); } diff --git a/common/dialogs/panel_setup_netclasses.cpp b/common/dialogs/panel_setup_netclasses.cpp index 4c71f7966a..edb7bcd226 100644 --- a/common/dialogs/panel_setup_netclasses.cpp +++ b/common/dialogs/panel_setup_netclasses.cpp @@ -79,8 +79,7 @@ wxArrayString g_lineStyleNames; PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES( wxWindow* aParentWindow, EDA_DRAW_FRAME* aFrame, std::shared_ptr aNetSettings, - const std::set& aNetNames, - bool aIsEEschema ) : + const std::set& aNetNames, bool aIsEEschema ) : PANEL_SETUP_NETCLASSES_BASE( aParentWindow ), m_frame( aFrame ), m_isEEschema( aIsEEschema ), @@ -198,7 +197,6 @@ PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES( wxWindow* aParentWindow, EDA_DRA GRID_DIFF_PAIR_WIDTH, GRID_DIFF_PAIR_GAP } ); - // Be sure the column labels are readable m_netclassGrid->EnsureColLabelsVisible(); @@ -378,19 +376,20 @@ void PANEL_SETUP_NETCLASSES::loadNetclasses() void PANEL_SETUP_NETCLASSES::setNetclassRowNullableEditors( int aRowId, bool aIsDefault ) { // Set nullable editors - auto setCellEditor = [this, aRowId, aIsDefault]( int aCol ) - { - GRID_CELL_MARK_AS_NULLABLE* cellEditor; + auto setCellEditor = + [this, aRowId, aIsDefault]( int aCol ) + { + GRID_CELL_MARK_AS_NULLABLE* cellEditor; - if( aIsDefault ) - cellEditor = new GRID_CELL_MARK_AS_NULLABLE( false ); - else - cellEditor = new GRID_CELL_MARK_AS_NULLABLE( true ); + if( aIsDefault ) + cellEditor = new GRID_CELL_MARK_AS_NULLABLE( false ); + else + cellEditor = new GRID_CELL_MARK_AS_NULLABLE( true ); - wxGridCellAttr* attr = m_netclassGrid->GetOrCreateCellAttr( aRowId, aCol ); - attr->SetEditor( cellEditor ); - attr->DecRef(); - }; + wxGridCellAttr* attr = m_netclassGrid->GetOrCreateCellAttr( aRowId, aCol ); + attr->SetEditor( cellEditor ); + attr->DecRef(); + }; setCellEditor( GRID_WIREWIDTH ); setCellEditor( GRID_BUSWIDTH ); @@ -557,8 +556,7 @@ bool PANEL_SETUP_NETCLASSES::TransferDataFromWindow() } -bool PANEL_SETUP_NETCLASSES::validateNetclassName( int aRow, const wxString& aName, - bool focusFirst ) +bool PANEL_SETUP_NETCLASSES::validateNetclassName( int aRow, const wxString& aName, bool focusFirst ) { wxString tmp = aName; @@ -577,8 +575,8 @@ bool PANEL_SETUP_NETCLASSES::validateNetclassName( int aRow, const wxString& aNa if( ii != aRow && m_netclassGrid->GetCellValue( ii, GRID_NAME ).CmpNoCase( tmp ) == 0 ) { wxString msg = _( "Netclass name already in use." ); - PAGED_DIALOG::GetDialog( this )->SetError( msg, this, m_netclassGrid, - focusFirst ? aRow : ii, GRID_NAME ); + PAGED_DIALOG::GetDialog( this )->SetError( msg, this, m_netclassGrid, focusFirst ? aRow : ii, + GRID_NAME ); return false; } } @@ -769,38 +767,31 @@ void PANEL_SETUP_NETCLASSES::OnAddNetclassClick( wxCommandEvent& event ) void PANEL_SETUP_NETCLASSES::OnRemoveNetclassClick( wxCommandEvent& event ) { - if( !m_netclassGrid->CommitPendingChanges() ) - return; + m_netclassGrid->OnDeleteRows( + [&]( int row ) + { + if( row == m_netclassGrid->GetNumberRows() - 1 ) + { + DisplayErrorMessage( wxGetTopLevelParent( this ), _( "The default net class is required." ) ); + return false; + } - int curRow = m_netclassGrid->GetGridCursorRow(); + return true; + }, + [&]( int row ) + { + // reset the net class to default for members of the removed class + wxString classname = m_netclassGrid->GetCellValue( row, GRID_NAME ); - if( curRow < 0 ) - { - return; - } - else if( curRow == m_netclassGrid->GetNumberRows() - 1 ) - { - wxWindow* topLevelParent = wxGetTopLevelParent( this ); + for( int assignment = 0; assignment < m_assignmentGrid->GetNumberRows(); ++assignment ) + { + if( m_assignmentGrid->GetCellValue( assignment, 1 ) == classname ) + m_assignmentGrid->SetCellValue( assignment, 1, NETCLASS::Default ); + } - DisplayErrorMessage( topLevelParent, _( "The default net class is required." ) ); - return; - } - - // reset the net class to default for members of the removed class - wxString classname = m_netclassGrid->GetCellValue( curRow, GRID_NAME ); - - for( int row = 0; row < m_assignmentGrid->GetNumberRows(); ++row ) - { - if( m_assignmentGrid->GetCellValue( row, 1 ) == classname ) - m_assignmentGrid->SetCellValue( row, 1, NETCLASS::Default ); - } - - m_netclassGrid->DeleteRows( curRow, 1 ); - - m_netclassGrid->MakeCellVisible( std::max( 0, curRow-1 ), m_netclassGrid->GetGridCursorCol() ); - m_netclassGrid->SetGridCursor( std::max( 0, curRow-1 ), m_netclassGrid->GetGridCursorCol() ); - - m_netclassesDirty = true; + m_netclassGrid->DeleteRows( row, 1 ); + m_netclassesDirty = true; + } ); } @@ -855,21 +846,11 @@ void PANEL_SETUP_NETCLASSES::OnAddAssignmentClick( wxCommandEvent& event ) void PANEL_SETUP_NETCLASSES::OnRemoveAssignmentClick( wxCommandEvent& event ) { - if( !m_assignmentGrid->CommitPendingChanges() ) - return; - - int curRow = m_assignmentGrid->GetGridCursorRow(); - - if( curRow < 0 ) - return; - - m_assignmentGrid->DeleteRows( curRow, 1 ); - - if( m_assignmentGrid->GetNumberRows() > 0 ) - { - m_assignmentGrid->MakeCellVisible( std::max( 0, curRow-1 ), 0 ); - m_assignmentGrid->SetGridCursor( std::max( 0, curRow-1 ), 0 ); - } + m_assignmentGrid->OnDeleteRows( + [&]( int row ) + { + m_assignmentGrid->DeleteRows( row, 1 ); + } ); } @@ -1008,79 +989,33 @@ void PANEL_SETUP_NETCLASSES::ImportSettingsFrom( const std::shared_ptrCommitPendingChanges() ) - return; - - // Work out which rows are selected - std::vector selectedRows; - - for( int i = 0; i < m_netclassGrid->GetNumberRows(); ++i ) - { - if( m_netclassGrid->IsInSelection( i, 0 ) ) - selectedRows.push_back( i ); - } - - // Only move one row at a time - if( selectedRows.size() != 1 ) - return; - - // Can't move the first netclass, nor move the Default netclass - if( selectedRows[0] == 0 || selectedRows[0] == ( m_netclassGrid->GetNumberRows() - 1 ) ) - return; - - int newRowId = selectedRows[0] - 1; - m_netclassGrid->InsertRows( newRowId ); - - for( int col = 0; col < m_netclassGrid->GetNumberCols(); col++ ) - m_netclassGrid->SetCellValue( newRowId, col, m_netclassGrid->GetCellValue( newRowId + 2, col ) ); - - // Set the row nullable editors - setNetclassRowNullableEditors( newRowId, false ); - - m_netclassGrid->DeleteRows( newRowId + 2, 1 ); - m_netclassGrid->MakeCellVisible( newRowId, 0 ); - m_netclassGrid->SetGridCursor( newRowId, 0 ); - - m_netclassesDirty = true; + m_netclassGrid->OnMoveRowUp( + [&]( int row ) + { + // Can't move the Default netclass + return row != m_netclassGrid->GetNumberRows() - 1; + }, + [&]( int row ) + { + m_netclassGrid->SwapRows( row, row - 1 ); + m_netclassesDirty = true; + } ); } void PANEL_SETUP_NETCLASSES::OnMoveNetclassDownClick( wxCommandEvent& event ) { - if( !m_netclassGrid->CommitPendingChanges() ) - return; - - // Work out which rows are selected - std::vector selectedRows; - - for( int i = 0; i < m_netclassGrid->GetNumberRows(); ++i ) - { - if( m_netclassGrid->IsInSelection( i, 0 ) ) - selectedRows.push_back( i ); - } - - // Only move one row at a time - if( selectedRows.size() != 1 ) - return; - - // Can't move the last row down, nor move the Default netclass - if( selectedRows[0] == ( m_netclassGrid->GetNumberRows() - 2 ) - || selectedRows[0] == ( m_netclassGrid->GetNumberRows() - 1 ) ) - { - return; - } - - int newRowId = selectedRows[0] + 2; - m_netclassGrid->InsertRows( newRowId ); - - for( int col = 0; col < m_netclassGrid->GetNumberCols(); col++ ) - m_netclassGrid->SetCellValue( newRowId, col, m_netclassGrid->GetCellValue( newRowId - 2, col ) ); - - m_netclassGrid->DeleteRows( newRowId - 2, 1 ); - m_netclassGrid->MakeCellVisible( newRowId - 1, 0 ); - m_netclassGrid->SetGridCursor( newRowId - 1, 0 ); - - m_netclassesDirty = true; + m_netclassGrid->OnMoveRowDown( + [&]( int row ) + { + // Can't move the Default netclass + return row + 1 != m_netclassGrid->GetNumberRows() - 1; + }, + [&]( int row ) + { + m_netclassGrid->SwapRows( row, row + 1 ); + m_netclassesDirty = true; + } ); } diff --git a/common/widgets/wx_grid.cpp b/common/widgets/wx_grid.cpp index 8b1df7395b..a7254524a1 100644 --- a/common/widgets/wx_grid.cpp +++ b/common/widgets/wx_grid.cpp @@ -309,8 +309,7 @@ void WX_GRID::EnableAlternateRowColors( bool aEnable ) { wxGridTableBase* table = wxGrid::GetTable(); - wxCHECK_MSG( table, /* void */, - "Tried to enable alternate row colors without a table assigned to the grid" ); + wxCHECK_MSG( table, /* void */, "Tried to enable alternate row colors without a table assigned to the grid" ); if( aEnable ) { @@ -510,18 +509,6 @@ void WX_GRID::ShowHideColumns( const wxString& shownColumns ) } -void WX_GRID::ShowHideColumns( const std::bitset<64>& aShownColumns ) -{ - for( int ii = 0; ii < GetNumberCols(); ++ ii ) - { - if( aShownColumns[ii] ) - ShowCol( ii ); - else - HideCol( ii ); - } -} - - void WX_GRID::DrawCornerLabel( wxDC& dc ) { if( m_nativeColumnLabels ) @@ -745,6 +732,83 @@ void WX_GRID::OnDeleteRows( const std::function& aFilter, } +void WX_GRID::SwapRows( int aRowA, int aRowB ) +{ + for( int col = 0; col < GetNumberCols(); ++col ) + { + wxString temp = GetCellValue( aRowA, col ); + SetCellValue( aRowA, col, GetCellValue( aRowB, col ) ); + SetCellValue( aRowB, col, temp ); + } +} + + +void WX_GRID::OnMoveRowUp( const std::function& aMover ) +{ + OnMoveRowUp( + []( int row ) + { + return true; + }, + aMover ); +} + + +void WX_GRID::OnMoveRowUp( const std::function& aFilter, + const std::function& aMover ) +{ + if( !CommitPendingChanges() ) + return; + + int i = GetGridCursorRow(); + + if( i > 0 && aFilter( i ) ) + { + aMover( i ); + + SetGridCursor( i - 1, GetGridCursorCol() ); + MakeCellVisible( GetGridCursorRow(), GetGridCursorCol() ); + } + else + { + wxBell(); + } +} + + +void WX_GRID::OnMoveRowDown( const std::function& aMover ) +{ + OnMoveRowDown( + []( int row ) + { + return true; + }, + aMover ); +} + + +void WX_GRID::OnMoveRowDown( const std::function& aFilter, + const std::function& aMover ) +{ + if( !CommitPendingChanges() ) + return; + + int i = GetGridCursorRow(); + + if( i + 1 < GetNumberRows() && aFilter( i ) ) + { + aMover( i ); + + SetGridCursor( i + 1, GetGridCursorCol() ); + MakeCellVisible( GetGridCursorRow(), GetGridCursorCol() ); + } + else + { + wxBell(); + } +} + + void WX_GRID::SetUnitsProvider( UNITS_PROVIDER* aProvider, int aCol ) { m_unitsProviders[ aCol ] = aProvider; diff --git a/eeschema/dialogs/dialog_label_properties.cpp b/eeschema/dialogs/dialog_label_properties.cpp index f0cd5c0d6e..feb34da2cd 100644 --- a/eeschema/dialogs/dialog_label_properties.cpp +++ b/eeschema/dialogs/dialog_label_properties.cpp @@ -42,8 +42,7 @@ #include -DIALOG_LABEL_PROPERTIES::DIALOG_LABEL_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_LABEL_BASE* aLabel, - bool aNew ) : +DIALOG_LABEL_PROPERTIES::DIALOG_LABEL_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_LABEL_BASE* aLabel, bool aNew ) : DIALOG_LABEL_PROPERTIES_BASE( aParent ), m_Parent( aParent ), m_currentLabel( aLabel ), @@ -616,30 +615,19 @@ bool DIALOG_LABEL_PROPERTIES::TransferDataFromWindow() if( m_shapeSizer->AreAnyItemsShown() ) { - if( m_bidirectional->GetValue() ) - m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_BIDI ); - else if( m_input->GetValue() ) - m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_INPUT ); - else if( m_output->GetValue() ) - m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_OUTPUT ); - else if( m_triState->GetValue() ) - m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_TRISTATE ); - else if( m_passive->GetValue() ) - m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_UNSPECIFIED ); - else if( m_dot->GetValue() ) - m_currentLabel->SetShape( LABEL_FLAG_SHAPE::F_DOT ); - else if( m_circle->GetValue() ) - m_currentLabel->SetShape( LABEL_FLAG_SHAPE::F_ROUND ); - else if( m_diamond->GetValue() ) - m_currentLabel->SetShape( LABEL_FLAG_SHAPE::F_DIAMOND ); - else if( m_rectangle->GetValue() ) - m_currentLabel->SetShape( LABEL_FLAG_SHAPE::F_RECTANGLE ); + if( m_bidirectional->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_BIDI ); + else if( m_input->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_INPUT ); + else if( m_output->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_OUTPUT ); + else if( m_triState->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_TRISTATE ); + else if( m_passive->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::L_UNSPECIFIED ); + else if( m_dot->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::F_DOT ); + else if( m_circle->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::F_ROUND ); + else if( m_diamond->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::F_DIAMOND ); + else if( m_rectangle->GetValue() ) m_currentLabel->SetShape( LABEL_FLAG_SHAPE::F_RECTANGLE ); } if( m_fontCtrl->HaveFontSelection() ) - { m_currentLabel->SetFont( m_fontCtrl->GetFontSelection( m_bold->IsChecked(), m_italic->IsChecked() ) ); - } if( m_currentLabel->Type() == SCH_DIRECTIVE_LABEL_T ) static_cast( m_currentLabel )->SetPinLength( m_textSize.GetIntValue() ); @@ -825,49 +813,31 @@ void DIALOG_LABEL_PROPERTIES::OnDeleteField( wxCommandEvent& event ) void DIALOG_LABEL_PROPERTIES::OnMoveUp( wxCommandEvent& event ) { - if( !m_grid->CommitPendingChanges() ) - return; - - int i = m_grid->GetGridCursorRow(); - - if( i > m_currentLabel->GetMandatoryFieldCount() ) - { - SCH_FIELD tmp = m_fields->at( (unsigned) i ); - m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 ); - m_fields->insert( m_fields->begin() + i - 1, tmp ); - m_grid->ForceRefresh(); - - m_grid->SetGridCursor( i - 1, m_grid->GetGridCursorCol() ); - m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() ); - } - else - { - wxBell(); - } + m_grid->OnMoveRowUp( + [&]( int row ) + { + return row > m_currentLabel->GetMandatoryFieldCount(); + }, + [&]( int row ) + { + std::swap( *( m_fields->begin() + row ), *( m_fields->begin() + row - 1 ) ); + m_grid->ForceRefresh(); + } ); } void DIALOG_LABEL_PROPERTIES::OnMoveDown( wxCommandEvent& event ) { - if( !m_grid->CommitPendingChanges() ) - return; - - int i = m_grid->GetGridCursorRow(); - - if( i >= m_currentLabel->GetMandatoryFieldCount() && i < m_grid->GetNumberRows() - 1 ) - { - SCH_FIELD tmp = m_fields->at( (unsigned) i ); - m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 ); - m_fields->insert( m_fields->begin() + i + 1, tmp ); - m_grid->ForceRefresh(); - - m_grid->SetGridCursor( i + 1, m_grid->GetGridCursorCol() ); - m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() ); - } - else - { - wxBell(); - } + m_grid->OnMoveRowUp( + [&]( int row ) + { + return row >= m_currentLabel->GetMandatoryFieldCount(); + }, + [&]( int row ) + { + std::swap( *( m_fields->begin() + row ), *( m_fields->begin() + row + 1 ) ); + m_grid->ForceRefresh(); + } ); } diff --git a/eeschema/dialogs/dialog_lib_symbol_properties.cpp b/eeschema/dialogs/dialog_lib_symbol_properties.cpp index 75dee17091..657eab41f7 100644 --- a/eeschema/dialogs/dialog_lib_symbol_properties.cpp +++ b/eeschema/dialogs/dialog_lib_symbol_properties.cpp @@ -385,7 +385,6 @@ bool DIALOG_LIB_SYMBOL_PROPERTIES::Validate() if( parentName.IsEmpty() ) { m_delayedErrorMessage = _( "Derived symbol must have a parent selected" ); - return false; } } @@ -701,53 +700,33 @@ void DIALOG_LIB_SYMBOL_PROPERTIES::OnDeleteField( wxCommandEvent& event ) void DIALOG_LIB_SYMBOL_PROPERTIES::OnMoveUp( wxCommandEvent& event ) { - if( !m_grid->CommitPendingChanges() ) - return; - - int i = m_grid->GetGridCursorRow(); - - if( i > m_fields->GetMandatoryRowCount() ) - { - SCH_FIELD tmp = m_fields->at( (unsigned) i ); - m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 ); - m_fields->insert( m_fields->begin() + i - 1, tmp ); - m_grid->ForceRefresh(); - - m_grid->SetGridCursor( i - 1, m_grid->GetGridCursorCol() ); - m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() ); - - OnModify(); - } - else - { - wxBell(); - } + m_grid->OnMoveRowUp( + [&]( int row ) + { + return row > m_fields->GetMandatoryRowCount(); + }, + [&]( int row ) + { + std::swap( *( m_fields->begin() + row ), *( m_fields->begin() + row - 1 ) ); + m_grid->ForceRefresh(); + OnModify(); + } ); } void DIALOG_LIB_SYMBOL_PROPERTIES::OnMoveDown( wxCommandEvent& event ) { - if( !m_grid->CommitPendingChanges() ) - return; - - int i = m_grid->GetGridCursorRow(); - - if( i >= m_fields->GetMandatoryRowCount() && i + 1 < m_fields->GetNumberRows() ) - { - SCH_FIELD tmp = m_fields->at( (unsigned) i ); - m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 ); - m_fields->insert( m_fields->begin() + i + 1, tmp ); - m_grid->ForceRefresh(); - - m_grid->SetGridCursor( i + 1, m_grid->GetGridCursorCol() ); - m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() ); - - OnModify(); - } - else - { - wxBell(); - } + m_grid->OnMoveRowDown( + [&]( int row ) + { + return row >= m_fields->GetMandatoryRowCount(); + }, + [&]( int row ) + { + std::swap( *( m_fields->begin() + row ), *( m_fields->begin() + row + 1 ) ); + m_grid->ForceRefresh(); + OnModify(); + } ); } diff --git a/eeschema/dialogs/dialog_sheet_properties.cpp b/eeschema/dialogs/dialog_sheet_properties.cpp index 5c46bc951f..b4cde19475 100644 --- a/eeschema/dialogs/dialog_sheet_properties.cpp +++ b/eeschema/dialogs/dialog_sheet_properties.cpp @@ -760,49 +760,31 @@ void DIALOG_SHEET_PROPERTIES::OnDeleteField( wxCommandEvent& event ) void DIALOG_SHEET_PROPERTIES::OnMoveUp( wxCommandEvent& event ) { - if( !m_grid->CommitPendingChanges() ) - return; - - int i = m_grid->GetGridCursorRow(); - - if( i > m_fields->GetMandatoryRowCount() ) - { - SCH_FIELD tmp = m_fields->at( (unsigned) i ); - m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 ); - m_fields->insert( m_fields->begin() + i - 1, tmp ); - m_grid->ForceRefresh(); - - m_grid->SetGridCursor( i - 1, m_grid->GetGridCursorCol() ); - m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() ); - } - else - { - wxBell(); - } + m_grid->OnMoveRowUp( + [&]( int row ) + { + return row > m_fields->GetMandatoryRowCount(); + }, + [&]( int row ) + { + std::swap( *( m_fields->begin() + row ), *( m_fields->begin() + row - 1 ) ); + m_grid->ForceRefresh(); + } ); } void DIALOG_SHEET_PROPERTIES::OnMoveDown( wxCommandEvent& event ) { - if( !m_grid->CommitPendingChanges() ) - return; - - int i = m_grid->GetGridCursorRow(); - - if( i >= m_fields->GetMandatoryRowCount() && i < m_grid->GetNumberRows() - 1 ) - { - SCH_FIELD tmp = m_fields->at( (unsigned) i ); - m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 ); - m_fields->insert( m_fields->begin() + i + 1, tmp ); - m_grid->ForceRefresh(); - - m_grid->SetGridCursor( i + 1, m_grid->GetGridCursorCol() ); - m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() ); - } - else - { - wxBell(); - } + m_grid->OnMoveRowUp( + [&]( int row ) + { + return row >= m_fields->GetMandatoryRowCount(); + }, + [&]( int row ) + { + std::swap( *( m_fields->begin() + row ), *( m_fields->begin() + row + 1 ) ); + m_grid->ForceRefresh(); + } ); } diff --git a/eeschema/dialogs/dialog_symbol_properties.cpp b/eeschema/dialogs/dialog_symbol_properties.cpp index e311efb0ca..6e12660ae1 100644 --- a/eeschema/dialogs/dialog_symbol_properties.cpp +++ b/eeschema/dialogs/dialog_symbol_properties.cpp @@ -898,53 +898,33 @@ void DIALOG_SYMBOL_PROPERTIES::OnDeleteField( wxCommandEvent& event ) void DIALOG_SYMBOL_PROPERTIES::OnMoveUp( wxCommandEvent& event ) { - if( !m_fieldsGrid->CommitPendingChanges() ) - return; - - int i = m_fieldsGrid->GetGridCursorRow(); - - if( i > m_fields->GetMandatoryRowCount() ) - { - SCH_FIELD tmp = m_fields->at( (unsigned) i ); - m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 ); - m_fields->insert( m_fields->begin() + i - 1, tmp ); - m_fieldsGrid->ForceRefresh(); - - m_fieldsGrid->SetGridCursor( i - 1, m_fieldsGrid->GetGridCursorCol() ); - m_fieldsGrid->MakeCellVisible( m_fieldsGrid->GetGridCursorRow(), m_fieldsGrid->GetGridCursorCol() ); - - OnModify(); - } - else - { - wxBell(); - } + m_fieldsGrid->OnMoveRowUp( + [&]( int row ) + { + return row > m_fields->GetMandatoryRowCount(); + }, + [&]( int row ) + { + std::swap( *( m_fields->begin() + row ), *( m_fields->begin() + row - 1 ) ); + m_fieldsGrid->ForceRefresh(); + OnModify(); + } ); } void DIALOG_SYMBOL_PROPERTIES::OnMoveDown( wxCommandEvent& event ) { - if( !m_fieldsGrid->CommitPendingChanges() ) - return; - - int i = m_fieldsGrid->GetGridCursorRow(); - - if( i >= m_fields->GetMandatoryRowCount() && i < m_fieldsGrid->GetNumberRows() - 1 ) - { - SCH_FIELD tmp = m_fields->at( (unsigned) i ); - m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 ); - m_fields->insert( m_fields->begin() + i + 1, tmp ); - m_fieldsGrid->ForceRefresh(); - - m_fieldsGrid->SetGridCursor( i + 1, m_fieldsGrid->GetGridCursorCol() ); - m_fieldsGrid->MakeCellVisible( m_fieldsGrid->GetGridCursorRow(), m_fieldsGrid->GetGridCursorCol() ); - - OnModify(); - } - else - { - wxBell(); - } + m_fieldsGrid->OnMoveRowDown( + [&]( int row ) + { + return row >= m_fields->GetMandatoryRowCount(); + }, + [&]( int row ) + { + std::swap( *( m_fields->begin() + row ), *( m_fields->begin() + row + 1 ) ); + m_fieldsGrid->ForceRefresh(); + OnModify(); + } ); } diff --git a/eeschema/dialogs/panel_setup_buses.cpp b/eeschema/dialogs/panel_setup_buses.cpp index 15e3cadd38..8439a285d5 100644 --- a/eeschema/dialogs/panel_setup_buses.cpp +++ b/eeschema/dialogs/panel_setup_buses.cpp @@ -265,28 +265,18 @@ void PANEL_SETUP_BUSES::OnAddMember( wxCommandEvent& aEvent ) void PANEL_SETUP_BUSES::OnRemoveMember( wxCommandEvent& aEvent ) { - if( !m_membersGrid->CommitPendingChanges() ) - return; + m_membersGrid->OnDeleteRows( + [&]( int row ) + { + m_membersGrid->DeleteRows( row, 1 ); - int curRow = m_membersGrid->GetGridCursorRow(); + // Update the member list of the current bus alias from the members grid + const std::shared_ptr& alias = m_aliases[ m_lastAlias ]; + alias->Members().clear(); - if( curRow < 0 ) - return; - - m_membersGrid->DeleteRows( curRow, 1 ); - - // Update the member list of the current bus alias from the members grid - const std::shared_ptr& alias = m_aliases[ m_lastAlias ]; - alias->Members().clear(); - - for( int ii = 0; ii < m_membersGrid->GetNumberRows(); ++ii ) - alias->Members().push_back( m_membersGrid->GetCellValue( ii, 0 ) ); - - if( m_membersGrid->GetNumberRows() > 0 ) - { - m_membersGrid->MakeCellVisible( std::max( 0, curRow-1 ), 0 ); - m_membersGrid->SelectRow( std::max( 0, curRow-1 ) ); - } + for( int ii = 0; ii < m_membersGrid->GetNumberRows(); ++ii ) + alias->Members().push_back( m_membersGrid->GetCellValue( ii, 0 ) ); + } ); } diff --git a/eeschema/dialogs/panel_template_fieldnames.cpp b/eeschema/dialogs/panel_template_fieldnames.cpp index d96c9123ae..65fd8f212d 100644 --- a/eeschema/dialogs/panel_template_fieldnames.cpp +++ b/eeschema/dialogs/panel_template_fieldnames.cpp @@ -124,56 +124,23 @@ void PANEL_TEMPLATE_FIELDNAMES::OnDeleteButtonClick( wxCommandEvent& event ) } -void swapRows( WX_GRID* aGrid, int aRowA, int aRowB ) -{ - for( int col = 0; col < aGrid->GetNumberCols(); ++col ) - { - wxString temp = aGrid->GetCellValue( aRowA, col ); - aGrid->SetCellValue( aRowA, col, aGrid->GetCellValue( aRowB, col ) ); - aGrid->SetCellValue( aRowB, col, temp ); - } -} - - void PANEL_TEMPLATE_FIELDNAMES::OnMoveUp( wxCommandEvent& event ) { - if( !m_grid->CommitPendingChanges() ) - return; - - int i = m_grid->GetGridCursorRow(); - - if( i > 0 ) - { - swapRows( m_grid, i, i - 1 ); - - m_grid->SetGridCursor( i - 1, m_grid->GetGridCursorCol() ); - m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() ); - } - else - { - wxBell(); - } + m_grid->OnMoveRowUp( + [&]( int row ) + { + m_grid->SwapRows( row, row - 1 ); + } ); } void PANEL_TEMPLATE_FIELDNAMES::OnMoveDown( wxCommandEvent& event ) { - if( !m_grid->CommitPendingChanges() ) - return; - - int i = m_grid->GetGridCursorRow(); - - if( i >= 0 && i + 1 < m_grid->GetNumberRows() ) - { - swapRows( m_grid, i, i + 1 ); - - m_grid->SetGridCursor( i + 1, m_grid->GetGridCursorCol() ); - m_grid->MakeCellVisible( m_grid->GetGridCursorRow(), m_grid->GetGridCursorCol() ); - } - else - { - wxBell(); - } + m_grid->OnMoveRowDown( + [&]( int row ) + { + m_grid->SwapRows( row, row + 1 ); + } ); } diff --git a/include/widgets/wx_grid.h b/include/widgets/wx_grid.h index d10e4c65cb..963cf02cf1 100644 --- a/include/widgets/wx_grid.h +++ b/include/widgets/wx_grid.h @@ -92,11 +92,6 @@ public: */ void ShowHideColumns( const wxString& shownColumns ); - /** - * A more performant version of ShowHideColumns (primarily for OnUpdateUI handlers). - */ - void ShowHideColumns( const std::bitset<64>& aShownColumns ); - /** * Hide wxGrid's SetTable() method with one which doesn't mess up the grid column * widths when setting the table. @@ -127,6 +122,17 @@ public: void OnDeleteRows( const std::function& aFilter, const std::function& aDeleter ); + /** + * These aren't that tricky, but might as well share code. + */ + void SwapRows( int aRowA, int aRowB ); + void OnMoveRowUp( const std::function& aMover ); + void OnMoveRowDown( const std::function& aMover ); + void OnMoveRowUp( const std::function& aFilter, + const std::function& aMover ); + void OnMoveRowDown( const std::function& aFilter, + const std::function& aMover ); + /** * Set a EUNITS_PROVIDER to enable use of unit- and eval-based Getters. * diff --git a/kicad/pcm/dialogs/dialog_manage_repositories.cpp b/kicad/pcm/dialogs/dialog_manage_repositories.cpp index 740200aaa1..59e3b01c63 100644 --- a/kicad/pcm/dialogs/dialog_manage_repositories.cpp +++ b/kicad/pcm/dialogs/dialog_manage_repositories.cpp @@ -93,8 +93,8 @@ void DIALOG_MANAGE_REPOSITORIES::setColumnWidths() void DIALOG_MANAGE_REPOSITORIES::OnAdd( wxCommandEvent& event ) { - wxTextEntryDialog entry_dialog( this, _( "Please enter fully qualified repository url" ), - _( "Add repository" ) ); + wxTextEntryDialog entry_dialog( this, _( "Fully qualified repository url:" ), + _( "Add Repository" ) ); if( entry_dialog.ShowModal() == wxID_OK ) { @@ -161,84 +161,32 @@ void DIALOG_MANAGE_REPOSITORIES::OnAddDefault( wxCommandEvent& event ) void DIALOG_MANAGE_REPOSITORIES::OnRemoveButtonClicked( wxCommandEvent& event ) { - auto selectedRows = m_grid->GetSelectedRows(); - - // If nothing is selected or multiple rows are selected don't do anything. - if( selectedRows.size() != 1 ) - { - wxBell(); - return; - } - - int selectedRow = selectedRows[0]; - m_grid->DeleteRows( selectedRow ); - setColumnWidths(); - - if( m_grid->GetNumberRows() > 0 ) - m_grid->SelectRow( selectedRow == m_grid->GetNumberRows() ? selectedRow - 1 : selectedRow ); + m_grid->OnDeleteRows( + [&]( int row ) + { + m_grid->DeleteRows( row ); + setColumnWidths(); + } ); } void DIALOG_MANAGE_REPOSITORIES::OnMoveUpButtonClicked( wxCommandEvent& event ) { - auto selectedRows = m_grid->GetSelectedRows(); - - // If nothing is selected or multiple rows are selected don't do anything. - if( selectedRows.size() != 1 ) - return; - - int selectedRow = selectedRows[0]; - - // If first row is selected, then it can't go any further up. - if( selectedRow == 0 ) - { - wxBell(); - return; - } - - swapRows( selectedRow, selectedRow - 1 ); - - selectRow( selectedRow - 1 ); + m_grid->OnMoveRowUp( + [&]( int row ) + { + m_grid->SwapRows( row, row - 1 ); + } ); } void DIALOG_MANAGE_REPOSITORIES::OnMoveDownButtonClicked( wxCommandEvent& event ) { - auto selectedRows = m_grid->GetSelectedRows(); - - // If nothing is selected or multiple rows are selected don't do anything. - if( selectedRows.size() != 1 ) - return; - - int selectedRow = selectedRows[0]; - - // If last row is selected, then it can't go any further down. - if( selectedRow + 1 == m_grid->GetNumberRows() ) - { - wxBell(); - return; - } - - swapRows( selectedRow, selectedRow + 1 ); - - selectRow( selectedRow + 1 ); -} - - -void DIALOG_MANAGE_REPOSITORIES::swapRows( int aRowA, int aRowB ) -{ - m_grid->Freeze(); - - wxString tempStr; - - for( int column = 0; column < m_grid->GetNumberCols(); column++ ) - { - tempStr = m_grid->GetCellValue( aRowA, column ); - m_grid->SetCellValue( aRowA, column, m_grid->GetCellValue( aRowB, column ) ); - m_grid->SetCellValue( aRowB, column, tempStr ); - } - - m_grid->Thaw(); + m_grid->OnMoveRowDown( + [&]( int row ) + { + m_grid->SwapRows( row, row + 1 ); + } ); } diff --git a/kicad/pcm/dialogs/dialog_manage_repositories.h b/kicad/pcm/dialogs/dialog_manage_repositories.h index d2f7774a08..8292b5a19c 100644 --- a/kicad/pcm/dialogs/dialog_manage_repositories.h +++ b/kicad/pcm/dialogs/dialog_manage_repositories.h @@ -53,7 +53,6 @@ public: std::vector> GetData(); private: - void swapRows( int aRowA, int aRowB ); void selectRow( int aRow ); void setColumnWidths(); void addRepository( const wxString& aUrl ); diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index 819ecf3201..791074a26f 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -302,7 +302,7 @@ set( ZONE_MANAGER_SRCS zone_manager/board_edges_bounding_item.cpp zone_manager/dialog_zone_manager.cpp zone_manager/dialog_zone_manager_base.cpp - zone_manager/model_zones_overview_table.cpp + zone_manager/model_zones_overview.cpp zone_manager/pane_zone_viewer.cpp zone_manager/panel_zone_gal.cpp zone_manager/panel_zone_properties.cpp diff --git a/pcbnew/dialogs/panel_pcbnew_action_plugins.cpp b/pcbnew/dialogs/panel_pcbnew_action_plugins.cpp index cb94d1119d..c4a84cf2e2 100644 --- a/pcbnew/dialogs/panel_pcbnew_action_plugins.cpp +++ b/pcbnew/dialogs/panel_pcbnew_action_plugins.cpp @@ -67,8 +67,7 @@ void PLUGINS_GRID_TRICKS::showPopupMenu( wxMenu& menu, wxGridEvent& aEvent ) if( std::optional action = mgr.GetAction( id ) ) { - menu.Append( MYID_RECREATE_ENV, _( "Recreate Plugin Environment" ), - _( "Recreate Plugin Environment" ) ); + menu.Append( MYID_RECREATE_ENV, _( "Recreate Plugin Environment" ), _( "Recreate Plugin Environment" ) ); menu.AppendSeparator(); } #endif @@ -87,9 +86,7 @@ void PLUGINS_GRID_TRICKS::doPopupSelection( wxCommandEvent& event ) PANEL_PCBNEW_ACTION_PLUGINS::COLUMN_SETTINGS_IDENTIFIER ); if( std::optional action = mgr.GetAction( id ) ) - { mgr.RecreatePluginEnvironment( ( *action )->plugin.Identifier() ); - } #endif } else @@ -135,45 +132,21 @@ void PANEL_PCBNEW_ACTION_PLUGINS::SelectRow( int aRow ) void PANEL_PCBNEW_ACTION_PLUGINS::OnMoveUpButtonClick( wxCommandEvent& event ) { - auto selectedRows = m_grid->GetSelectedRows(); - - // If nothing is selected or multiple rows are selected don't do anything. - if( selectedRows.size() != 1 ) return; - - int selectedRow = selectedRows[0]; - - // If first row is selected, then it can't go any further up. - if( selectedRow == 0 ) - { - wxBell(); - return; - } - - SwapRows( selectedRow, selectedRow - 1 ); - - SelectRow( selectedRow - 1 ); + m_grid->OnMoveRowUp( + [&]( int row ) + { + SwapRows( row, row - 1 ); + } ); } void PANEL_PCBNEW_ACTION_PLUGINS::OnMoveDownButtonClick( wxCommandEvent& event ) { - auto selectedRows = m_grid->GetSelectedRows(); - - // If nothing is selected or multiple rows are selected don't do anything. - if( selectedRows.size() != 1 ) return; - - int selectedRow = selectedRows[0]; - - // If last row is selected, then it can't go any further down. - if( selectedRow + 1 == m_grid->GetNumberRows() ) - { - wxBell(); - return; - } - - SwapRows( selectedRow, selectedRow + 1 ); - - SelectRow( selectedRow + 1 ); + m_grid->OnMoveRowDown( + [&]( int row ) + { + SwapRows( row, row + 1 ); + } ); } @@ -181,19 +154,11 @@ void PANEL_PCBNEW_ACTION_PLUGINS::SwapRows( int aRowA, int aRowB ) { m_grid->Freeze(); - wxString tempStr; - - for( int column = 0; column < m_grid->GetNumberCols(); column++ ) - { - tempStr = m_grid->GetCellValue( aRowA, column ); - m_grid->SetCellValue( aRowA, column, m_grid->GetCellValue( aRowB, column ) ); - m_grid->SetCellValue( aRowB, column, tempStr ); - } + m_grid->SwapRows( aRowA, aRowB ); // Swap icon column renderers auto cellRenderer = m_grid->GetCellRenderer( aRowA, COLUMN_ACTION_NAME ); - m_grid->SetCellRenderer( aRowA, COLUMN_ACTION_NAME, - m_grid->GetCellRenderer( aRowB, COLUMN_ACTION_NAME ) ); + m_grid->SetCellRenderer( aRowA, COLUMN_ACTION_NAME, m_grid->GetCellRenderer( aRowB, COLUMN_ACTION_NAME ) ); m_grid->SetCellRenderer( aRowB, COLUMN_ACTION_NAME, cellRenderer ); m_grid->Thaw(); @@ -261,8 +226,7 @@ bool PANEL_PCBNEW_ACTION_PLUGINS::TransferDataToWindow() m_grid->ClearRows(); - const std::vector& orderedPlugins = - PCB_EDIT_FRAME::GetOrderedActionPlugins(); + const std::vector& orderedPlugins = PCB_EDIT_FRAME::GetOrderedActionPlugins(); m_grid->AppendRows( orderedPlugins.size() ); int size = Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size; @@ -276,9 +240,8 @@ bool PANEL_PCBNEW_ACTION_PLUGINS::TransferDataToWindow() // Icon m_grid->SetCellRenderer( row, COLUMN_ACTION_NAME, - new GRID_CELL_ICON_TEXT_RENDERER( ap->iconBitmap.IsOk() - ? wxBitmapBundle( ap->iconBitmap ) - : m_genericIcon, + new GRID_CELL_ICON_TEXT_RENDERER( ap->iconBitmap.IsOk() ? wxBitmapBundle( ap->iconBitmap ) + : m_genericIcon, iconSize ) ); m_grid->SetCellValue( row, COLUMN_ACTION_NAME, ap->GetName() ); m_grid->SetCellValue( row, COLUMN_SETTINGS_IDENTIFIER, ap->GetPluginPath() ); @@ -300,9 +263,8 @@ bool PANEL_PCBNEW_ACTION_PLUGINS::TransferDataToWindow() #ifdef KICAD_IPC_API auto action = std::get( orderedPlugins[row] ); - const wxBitmapBundle& icon = KIPLATFORM::UI::IsDarkTheme() && action->icon_dark.IsOk() - ? action->icon_dark - : action->icon_light; + const wxBitmapBundle& icon = KIPLATFORM::UI::IsDarkTheme() && action->icon_dark.IsOk() ? action->icon_dark + : action->icon_light; // Icon m_grid->SetCellRenderer( row, COLUMN_ACTION_NAME, new GRID_CELL_ICON_TEXT_RENDERER( @@ -314,8 +276,7 @@ bool PANEL_PCBNEW_ACTION_PLUGINS::TransferDataToWindow() m_grid->SetCellRenderer( row, COLUMN_VISIBLE, new wxGridCellBoolRenderer() ); m_grid->SetCellAlignment( row, COLUMN_VISIBLE, wxALIGN_CENTER, wxALIGN_CENTER ); - bool show = PCB_EDIT_FRAME::GetActionPluginButtonVisible( action->identifier, - action->show_button ); + bool show = PCB_EDIT_FRAME::GetActionPluginButtonVisible( action->identifier, action->show_button ); m_grid->SetCellValue( row, COLUMN_VISIBLE, show ? wxT( "1" ) : wxEmptyString ); diff --git a/pcbnew/dialogs/panel_setup_tracks_and_vias.cpp b/pcbnew/dialogs/panel_setup_tracks_and_vias.cpp index 1f03be9dd4..5fa8c1375e 100644 --- a/pcbnew/dialogs/panel_setup_tracks_and_vias.cpp +++ b/pcbnew/dialogs/panel_setup_tracks_and_vias.cpp @@ -135,6 +135,9 @@ PANEL_SETUP_TRACKS_AND_VIAS::~PANEL_SETUP_TRACKS_AND_VIAS() void PANEL_SETUP_TRACKS_AND_VIAS::OnSortTrackWidthsClick( wxCommandEvent& aEvent ) { + if( m_trackWidthsGrid->GetNumberRows() < 2 ) + return; + std::vector trackWidths; wxString msg; @@ -161,6 +164,9 @@ void PANEL_SETUP_TRACKS_AND_VIAS::OnSortTrackWidthsClick( wxCommandEvent& aEvent void PANEL_SETUP_TRACKS_AND_VIAS::OnSortViaSizesClick( wxCommandEvent& aEvent ) { + if( m_viaSizesGrid->GetNumberRows() < 2 ) + return; + std::vector vias; wxString msg; @@ -197,6 +203,9 @@ void PANEL_SETUP_TRACKS_AND_VIAS::OnSortViaSizesClick( wxCommandEvent& aEvent ) void PANEL_SETUP_TRACKS_AND_VIAS::OnSortDiffPairsClick( wxCommandEvent& aEvent ) { + if( m_diffPairsGrid->GetNumberRows() < 2 ) + return; + wxString msg; std::vector diffPairs; @@ -283,12 +292,8 @@ bool PANEL_SETUP_TRACKS_AND_VIAS::TransferDataToWindow() bool PANEL_SETUP_TRACKS_AND_VIAS::TransferDataFromWindow() { - if( !m_trackWidthsGrid->CommitPendingChanges() - || !m_viaSizesGrid->CommitPendingChanges() - || !m_diffPairsGrid->CommitPendingChanges() ) - { + if( !commitPendingChanges() ) return false; - } std::vector trackWidths; std::vector vias; @@ -353,14 +358,18 @@ bool PANEL_SETUP_TRACKS_AND_VIAS::TransferDataFromWindow() } +bool PANEL_SETUP_TRACKS_AND_VIAS::commitPendingChanges( bool aQuietMode ) +{ + return m_trackWidthsGrid->CommitPendingChanges( aQuietMode ) + && m_viaSizesGrid->CommitPendingChanges( aQuietMode ) + && m_diffPairsGrid->CommitPendingChanges( aQuietMode ); +} + + bool PANEL_SETUP_TRACKS_AND_VIAS::Validate() { - if( !m_trackWidthsGrid->CommitPendingChanges() - || !m_viaSizesGrid->CommitPendingChanges() - || !m_diffPairsGrid->CommitPendingChanges() ) - { + if( !commitPendingChanges() ) return false; - } wxString msg; @@ -447,12 +456,8 @@ void removeSelectedRows( WX_GRID* aGrid ) void PANEL_SETUP_TRACKS_AND_VIAS::OnAddTrackWidthsClick( wxCommandEvent& aEvent ) { - if( !m_trackWidthsGrid->CommitPendingChanges() - || !m_viaSizesGrid->CommitPendingChanges() - || !m_diffPairsGrid->CommitPendingChanges() ) - { + if( !commitPendingChanges() ) return; - } AppendTrackWidth( 0 ); @@ -472,12 +477,8 @@ void PANEL_SETUP_TRACKS_AND_VIAS::OnRemoveTrackWidthsClick( wxCommandEvent& even void PANEL_SETUP_TRACKS_AND_VIAS::OnAddViaSizesClick( wxCommandEvent& event ) { - if( !m_trackWidthsGrid->CommitPendingChanges() - || !m_viaSizesGrid->CommitPendingChanges() - || !m_diffPairsGrid->CommitPendingChanges() ) - { + if( !commitPendingChanges() ) return; - } AppendViaSize( 0, 0 ); @@ -497,12 +498,8 @@ void PANEL_SETUP_TRACKS_AND_VIAS::OnRemoveViaSizesClick( wxCommandEvent& event ) void PANEL_SETUP_TRACKS_AND_VIAS::OnAddDiffPairsClick( wxCommandEvent& event ) { - if( !m_trackWidthsGrid->CommitPendingChanges() - || !m_viaSizesGrid->CommitPendingChanges() - || !m_diffPairsGrid->CommitPendingChanges() ) - { + if( !commitPendingChanges() ) return; - } AppendDiffPairs( 0, 0, 0 ); @@ -522,9 +519,7 @@ void PANEL_SETUP_TRACKS_AND_VIAS::OnRemoveDiffPairsClick( wxCommandEvent& event void PANEL_SETUP_TRACKS_AND_VIAS::ImportSettingsFrom( BOARD* aBoard ) { - m_trackWidthsGrid->CommitPendingChanges( true ); - m_viaSizesGrid->CommitPendingChanges( true ); - m_diffPairsGrid->CommitPendingChanges( true ); + commitPendingChanges( true ); // Note: do not change the board, as we need to get the current nets from it for // netclass memberships. All the netclass definitions and dimension lists are in diff --git a/pcbnew/dialogs/panel_setup_tracks_and_vias.h b/pcbnew/dialogs/panel_setup_tracks_and_vias.h index 3b50c6f00c..a13f24f2be 100644 --- a/pcbnew/dialogs/panel_setup_tracks_and_vias.h +++ b/pcbnew/dialogs/panel_setup_tracks_and_vias.h @@ -66,6 +66,8 @@ protected: void AppendViaSize( int aSize, int aDrill ); void AppendDiffPairs( int aWidth, int aGap, int aViaGap ); + bool commitPendingChanges( bool aQuietMode = false ); + private: PCB_EDIT_FRAME* m_Frame; BOARD* m_Pcb; diff --git a/pcbnew/zone_manager/dialog_zone_manager.cpp b/pcbnew/zone_manager/dialog_zone_manager.cpp index e97bf5cd26..4ea14dcace 100644 --- a/pcbnew/zone_manager/dialog_zone_manager.cpp +++ b/pcbnew/zone_manager/dialog_zone_manager.cpp @@ -43,12 +43,12 @@ #include #include "dialog_zone_manager_base.h" -#include "model_zones_overview_table.h" +#include "model_zones_overview.h" #include "panel_zone_properties.h" #include "dialog_zone_manager.h" #include "widgets/wx_progress_reporters.h" #include "zone_management_base.h" -#include "zone_manager/model_zones_overview_table.h" +#include "zone_manager/model_zones_overview.h" #include "zone_manager/panel_zone_gal.h" #include "zone_manager/zone_manager_preference.h" #include "zones_container.h" @@ -82,17 +82,17 @@ DIALOG_ZONE_MANAGER::DIALOG_ZONE_MANAGER( PCB_BASE_FRAME* aParent, ZONE_SETTINGS m_checkRepour->SetValue( ZONE_MANAGER_PREFERENCE::GetRepourOnClose() ); //m_zoneViewer->SetId( ZONE_VIEWER ); - for( const auto& [k, v] : MODEL_ZONES_OVERVIEW_TABLE::GetColumnNames() ) + for( const auto& [k, v] : MODEL_ZONES_OVERVIEW::GetColumnNames() ) { - if( k == MODEL_ZONES_OVERVIEW_TABLE::LAYERS ) + if( k == MODEL_ZONES_OVERVIEW::LAYERS ) m_viewZonesOverview->AppendIconTextColumn( v, k ); else m_viewZonesOverview->AppendTextColumn( v, k ); } - m_modelZoneOverviewTable = new MODEL_ZONES_OVERVIEW_TABLE( m_zonesContainer->GetManagedZones(), - aParent->GetBoard(), aParent, this ); - m_viewZonesOverview->AssociateModel( m_modelZoneOverviewTable.get() ); + m_modelZonesOverview = new MODEL_ZONES_OVERVIEW( m_zonesContainer->GetManagedZones(), aParent->GetBoard(), + aParent, this ); + m_viewZonesOverview->AssociateModel( m_modelZonesOverview.get() ); #if wxUSE_DRAG_AND_DROP m_viewZonesOverview->EnableDragSource( wxDF_UNICODETEXT ); @@ -115,8 +115,8 @@ DIALOG_ZONE_MANAGER::DIALOG_ZONE_MANAGER( PCB_BASE_FRAME* aParent, ZONE_SETTINGS }, m_zoneViewer->GetId() ); - if( m_modelZoneOverviewTable->GetCount() ) - SelectZoneTableItem( m_modelZoneOverviewTable->GetItem( 0 ) ); + if( m_modelZonesOverview->GetCount() ) + SelectZoneTableItem( m_modelZonesOverview->GetItem( 0 ) ); Layout(); m_MainBoxSizer->Fit( this ); @@ -137,7 +137,7 @@ void DIALOG_ZONE_MANAGER::FitCanvasToScreen() } -void DIALOG_ZONE_MANAGER::PostProcessZoneViewSelectionChange( wxDataViewItem const& aItem ) +void DIALOG_ZONE_MANAGER::PostProcessZoneViewSelChange( wxDataViewItem const& aItem ) { bool textCtrlHasFocus = m_filterCtrl->HasFocus(); long filterInsertPos = m_filterCtrl->GetInsertionPoint(); @@ -149,12 +149,12 @@ void DIALOG_ZONE_MANAGER::PostProcessZoneViewSelectionChange( wxDataViewItem con } else { - if( m_modelZoneOverviewTable->GetCount() ) + if( m_modelZonesOverview->GetCount() ) { - wxDataViewItem first_item = m_modelZoneOverviewTable->GetItem( 0 ); + wxDataViewItem first_item = m_modelZonesOverview->GetItem( 0 ); m_viewZonesOverview->Select( first_item ); m_viewZonesOverview->EnsureVisible( first_item ); - m_zoneViewer->ActivateSelectedZone( m_modelZoneOverviewTable->GetZone( first_item ) ); + m_zoneViewer->ActivateSelectedZone( m_modelZonesOverview->GetZone( first_item ) ); } else { @@ -216,11 +216,8 @@ void DIALOG_ZONE_MANAGER::OnZoneSelectionChanged( ZONE* zone ) { wxWindowUpdateLocker updateLock( this ); - for( ZONE_SELECTION_CHANGE_NOTIFIER* i : - std::list{ m_panelZoneProperties, m_zoneViewer } ) - { - i->OnZoneSelectionChanged( zone ); - } + m_panelZoneProperties->OnZoneSelectionChanged( zone ); + m_zoneViewer->OnZoneSelectionChanged( zone ); Layout(); } @@ -240,7 +237,7 @@ void DIALOG_ZONE_MANAGER::OnDataViewCtrlSelectionChanged( wxDataViewEvent& aEven void DIALOG_ZONE_MANAGER::SelectZoneTableItem( wxDataViewItem const& aItem ) { - ZONE* zone = m_modelZoneOverviewTable->GetZone( aItem ); + ZONE* zone = m_modelZonesOverview->GetZone( aItem ); if( !zone ) return; @@ -251,11 +248,8 @@ void DIALOG_ZONE_MANAGER::SelectZoneTableItem( wxDataViewItem const& aItem ) void DIALOG_ZONE_MANAGER::OnOk( wxCommandEvent& aEvt ) { - for( ZONE_MANAGEMENT_BASE* zone_management : - std::list{ m_panelZoneProperties, m_zonesContainer.get() } ) - { - zone_management->OnUserConfirmChange(); - } + m_panelZoneProperties->OnUserConfirmChange(); + m_zonesContainer->OnUserConfirmChange(); if( m_zoneInfo ) { @@ -284,7 +278,7 @@ void DIALOG_ZONE_MANAGER::OnBeginDrag( wxDataViewEvent& aEvent ) const wxDataViewItem it = aEvent.GetItem(); if( it.IsOk() ) - m_priorityDragIndex = m_modelZoneOverviewTable->GetRow( it ); + m_priorityDragIndex = m_modelZonesOverview->GetRow( it ); } @@ -313,13 +307,13 @@ void DIALOG_ZONE_MANAGER::OnDrop( wxDataViewEvent& aEvent ) return; } - unsigned int drop_index = m_modelZoneOverviewTable->GetRow( it ); - const std::optional rtn = - m_modelZoneOverviewTable->SwapZonePriority( *m_priorityDragIndex, drop_index ); + unsigned int drop_index = m_modelZonesOverview->GetRow( it ); + const std::optional rtn = m_modelZonesOverview->SwapZonePriority( *m_priorityDragIndex, drop_index ); if( rtn.has_value() ) { - const wxDataViewItem item = m_modelZoneOverviewTable->GetItem( *rtn ); + const wxDataViewItem item = m_modelZonesOverview->GetItem( *rtn ); + if( item.IsOk() ) m_viewZonesOverview->Select( item ); } @@ -342,32 +336,31 @@ void DIALOG_ZONE_MANAGER::OnMoveDownClick( wxCommandEvent& aEvent ) void DIALOG_ZONE_MANAGER::OnFilterCtrlCancel( wxCommandEvent& aEvent ) { - PostProcessZoneViewSelectionChange( - m_modelZoneOverviewTable->ClearFilter( m_viewZonesOverview->GetSelection() ) ); + PostProcessZoneViewSelChange( m_modelZonesOverview->ClearFilter( m_viewZonesOverview->GetSelection() ) ); aEvent.Skip(); } void DIALOG_ZONE_MANAGER::OnFilterCtrlSearch( wxCommandEvent& aEvent ) { - PostProcessZoneViewSelectionChange( m_modelZoneOverviewTable->ApplyFilter( - aEvent.GetString(), m_viewZonesOverview->GetSelection() ) ); + PostProcessZoneViewSelChange( m_modelZonesOverview->ApplyFilter( aEvent.GetString(), + m_viewZonesOverview->GetSelection() ) ); aEvent.Skip(); } void DIALOG_ZONE_MANAGER::OnFilterCtrlTextChange( wxCommandEvent& aEvent ) { - PostProcessZoneViewSelectionChange( m_modelZoneOverviewTable->ApplyFilter( - aEvent.GetString(), m_viewZonesOverview->GetSelection() ) ); + PostProcessZoneViewSelChange( m_modelZonesOverview->ApplyFilter( aEvent.GetString(), + m_viewZonesOverview->GetSelection() ) ); aEvent.Skip(); } void DIALOG_ZONE_MANAGER::OnFilterCtrlEnter( wxCommandEvent& aEvent ) { - PostProcessZoneViewSelectionChange( m_modelZoneOverviewTable->ApplyFilter( - aEvent.GetString(), m_viewZonesOverview->GetSelection() ) ); + PostProcessZoneViewSelChange( m_modelZonesOverview->ApplyFilter( aEvent.GetString(), + m_viewZonesOverview->GetSelection() ) ); aEvent.Skip(); } @@ -429,8 +422,7 @@ void DIALOG_ZONE_MANAGER::OnZoneNameUpdate( wxCommandEvent& aEvent ) if( ZONE* zone = m_panelZoneProperties->GetZone(); zone != nullptr ) { zone->SetZoneName( aEvent.GetString() ); - m_modelZoneOverviewTable->RowChanged( m_modelZoneOverviewTable->GetRow( - m_modelZoneOverviewTable->GetItemByZone( zone ) ) ); + m_modelZonesOverview->RowChanged( m_modelZonesOverview->GetRow( m_modelZonesOverview->GetItemByZone( zone ) ) ); } } @@ -440,7 +432,7 @@ void DIALOG_ZONE_MANAGER::OnZonesTableRowCountChange( wxCommandEvent& aEvent ) unsigned count = aEvent.GetInt(); for( STD_BITMAP_BUTTON* btn : { m_btnMoveDown, m_btnMoveUp } ) - btn->Enable( count == m_modelZoneOverviewTable->GetAllZonesCount() ); + btn->Enable( count == m_modelZonesOverview->GetAllZonesCount() ); } @@ -449,19 +441,12 @@ void DIALOG_ZONE_MANAGER::OnCheckBoxClicked( wxCommandEvent& aEvent ) const wxObject* sender = aEvent.GetEventObject(); if( aEvent.GetEventObject() == m_checkName ) - { - m_modelZoneOverviewTable->EnableFitterByName( aEvent.IsChecked() ); - } + m_modelZonesOverview->EnableFitterByName( aEvent.IsChecked() ); else if( aEvent.GetEventObject() == m_checkNet ) - { - m_modelZoneOverviewTable->EnableFitterByNet( aEvent.IsChecked() ); - } + m_modelZonesOverview->EnableFitterByNet( aEvent.IsChecked() ); if( ( sender == m_checkName || sender == m_checkNet ) && !m_filterCtrl->IsEmpty() ) - { - m_modelZoneOverviewTable->ApplyFilter( m_filterCtrl->GetValue(), - m_viewZonesOverview->GetSelection() ); - } + m_modelZonesOverview->ApplyFilter( m_filterCtrl->GetValue(), m_viewZonesOverview->GetSelection() ); } @@ -475,13 +460,12 @@ void DIALOG_ZONE_MANAGER::MoveSelectedZonePriority( ZONE_INDEX_MOVEMENT aMove ) if( !selectedItem.IsOk() ) return; - const unsigned int selectedRow = m_modelZoneOverviewTable->GetRow( selectedItem ); - const std::optional new_index = - m_modelZoneOverviewTable->MoveZoneIndex( selectedRow, aMove ); + const unsigned int selectedRow = m_modelZonesOverview->GetRow( selectedItem ); + const std::optional new_index = m_modelZonesOverview->MoveZoneIndex( selectedRow, aMove ); if( new_index.has_value() ) { - wxDataViewItem new_item = m_modelZoneOverviewTable->GetItem( *new_index ); - PostProcessZoneViewSelectionChange( new_item ); + wxDataViewItem new_item = m_modelZonesOverview->GetItem( *new_index ); + PostProcessZoneViewSelChange( new_item ); } } diff --git a/pcbnew/zone_manager/dialog_zone_manager.h b/pcbnew/zone_manager/dialog_zone_manager.h index c5b1acad59..02431865c6 100644 --- a/pcbnew/zone_manager/dialog_zone_manager.h +++ b/pcbnew/zone_manager/dialog_zone_manager.h @@ -47,7 +47,7 @@ class PANEL_ZONE_PROPERTIES; class MODEL_ZONES_PRIORITY_LIST; -class MODEL_ZONES_OVERVIEW_TABLE; +class MODEL_ZONES_OVERVIEW; class MODEL_ZONE_LAYERS_LIST; class ZONES_CONTAINER; class PANE_ZONE_VIEWER; @@ -100,7 +100,7 @@ protected: void OnRepourCheck( wxCommandEvent& aEvent ) override; void OnUpdateDisplayedZonesClick( wxCommandEvent& aEvent ) override; - void PostProcessZoneViewSelectionChange( wxDataViewItem const& item ); + void PostProcessZoneViewSelChange( wxDataViewItem const& aItem ); void OnTableChar( wxKeyEvent& event ) override; void OnTableCharHook( wxKeyEvent& event ) override; @@ -113,17 +113,17 @@ private: void FitCanvasToScreen(); private: - PCB_BASE_FRAME* m_pcbFrame; - ZONE_SETTINGS* m_zoneInfo; - std::unique_ptr m_zonesContainer; - PANEL_ZONE_PROPERTIES* m_panelZoneProperties; - wxObjectDataPtr m_modelZoneOverviewTable; - PANE_ZONE_VIEWER* m_zoneViewer; - std::optional m_priorityDragIndex; - std::unique_ptr m_filler; - bool m_needZoomGAL; - bool m_isFillingZones; - bool m_zoneFillComplete; + PCB_BASE_FRAME* m_pcbFrame; + ZONE_SETTINGS* m_zoneInfo; + std::unique_ptr m_zonesContainer; + PANEL_ZONE_PROPERTIES* m_panelZoneProperties; + wxObjectDataPtr m_modelZonesOverview; + PANE_ZONE_VIEWER* m_zoneViewer; + std::optional m_priorityDragIndex; + std::unique_ptr m_filler; + bool m_needZoomGAL; + bool m_isFillingZones; + bool m_zoneFillComplete; }; #endif \ No newline at end of file diff --git a/pcbnew/zone_manager/managed_zone.h b/pcbnew/zone_manager/managed_zone.h index 6615e95ff5..6b2b95e2f8 100644 --- a/pcbnew/zone_manager/managed_zone.h +++ b/pcbnew/zone_manager/managed_zone.h @@ -36,7 +36,7 @@ */ class MANAGED_ZONE : public ZONE_MANAGEMENT_BASE { - friend class MODEL_ZONES_OVERVIEW_TABLE; + friend class MODEL_ZONES_OVERVIEW; public: MANAGED_ZONE( std::shared_ptr aZone, unsigned aInitialIndex ) : diff --git a/pcbnew/zone_manager/model_zones_overview_table.cpp b/pcbnew/zone_manager/model_zones_overview.cpp similarity index 72% rename from pcbnew/zone_manager/model_zones_overview_table.cpp rename to pcbnew/zone_manager/model_zones_overview.cpp index b7f5201ecd..2f747f2634 100644 --- a/pcbnew/zone_manager/model_zones_overview_table.cpp +++ b/pcbnew/zone_manager/model_zones_overview.cpp @@ -32,11 +32,11 @@ #include #include "zone_manager_preference.h" #include "managed_zone.h" -#include "model_zones_overview_table.h" +#include "model_zones_overview.h" wxDEFINE_EVENT( EVT_ZONES_OVERVIEW_COUNT_CHANGE, wxCommandEvent ); -void MODEL_ZONES_OVERVIEW_TABLE::SortZoneContainers() +void MODEL_ZONES_OVERVIEW::SortZoneContainers() { std::sort( m_filteredZones.begin(), m_filteredZones.end(), []( std::shared_ptr const& l, std::shared_ptr const& r ) @@ -46,7 +46,7 @@ void MODEL_ZONES_OVERVIEW_TABLE::SortZoneContainers() } -void MODEL_ZONES_OVERVIEW_TABLE::OnRowCountChange() +void MODEL_ZONES_OVERVIEW::OnRowCountChange() { wxCommandEvent rowCountChange( EVT_ZONES_OVERVIEW_COUNT_CHANGE ); rowCountChange.SetInt( GetCount() ); @@ -69,13 +69,8 @@ static wxBitmap MakeBitmapForLayers( LSEQ const& layers, COLOR_SETTINGS const& s if( layer_cout > 4 ) { - for( const PCB_LAYER_ID& i : { layers[0], - layers[1], - layers[layer_cout - 1], - layers[layer_cout - 2] } ) - { + for( const PCB_LAYER_ID& i : { layers[0], layers[1], layers[layer_cout - 1], layers[layer_cout - 2] } ) layersToDraw.push_back( i ); - } } else { @@ -98,9 +93,8 @@ static wxBitmap MakeBitmapForLayers( LSEQ const& layers, COLOR_SETTINGS const& s } -MODEL_ZONES_OVERVIEW_TABLE::MODEL_ZONES_OVERVIEW_TABLE( std::vector> aZones, - BOARD* a_pcb, PCB_BASE_FRAME* aPCB_FRAME, - wxWindow* a_dialog ) : +MODEL_ZONES_OVERVIEW::MODEL_ZONES_OVERVIEW( std::vector> aZones, + BOARD* a_pcb, PCB_BASE_FRAME* aPCB_FRAME, wxWindow* a_dialog ) : m_allZones( aZones ), m_filteredZones( std::move( aZones ) ), m_pcb( a_pcb ), @@ -113,11 +107,7 @@ MODEL_ZONES_OVERVIEW_TABLE::MODEL_ZONES_OVERVIEW_TABLE( std::vector( aRow ) + 1 > m_filteredZones.size() ) return; @@ -142,10 +132,9 @@ void MODEL_ZONES_OVERVIEW_TABLE::GetValueByRow( wxVariant& aVariant, unsigned aR for( PCB_LAYER_ID layer : cur.GetLayerSet().Seq() ) layers.Add( m_pcb->GetLayerName( layer ) ); - aVariant << wxDataViewIconText( wxJoin( layers, ',' ), - MakeBitmapForLayers( cur.GetLayerSet().UIOrder(), - *m_PCB_FRAME->GetColorSettings(), - bmSize ) ); + aVariant << wxDataViewIconText( wxJoin( layers, ',' ), MakeBitmapForLayers( cur.GetLayerSet().UIOrder(), + *m_PCB_FRAME->GetColorSettings(), + bmSize ) ); break; } @@ -155,32 +144,31 @@ void MODEL_ZONES_OVERVIEW_TABLE::GetValueByRow( wxVariant& aVariant, unsigned aR } -void MODEL_ZONES_OVERVIEW_TABLE::EnableFitterByName( bool aEnable ) +void MODEL_ZONES_OVERVIEW::EnableFitterByName( bool aEnable ) { m_sortByName = aEnable; } -void MODEL_ZONES_OVERVIEW_TABLE::EnableFitterByNet( bool aEnable ) +void MODEL_ZONES_OVERVIEW::EnableFitterByNet( bool aEnable ) { m_sortByNet = aEnable; } -bool MODEL_ZONES_OVERVIEW_TABLE::SetValueByRow( const wxVariant& aVariant, unsigned aRow, - unsigned aCol ) +bool MODEL_ZONES_OVERVIEW::SetValueByRow( const wxVariant& aVariant, unsigned aRow, unsigned aCol ) { return {}; } -unsigned int MODEL_ZONES_OVERVIEW_TABLE::GetCount() const +unsigned int MODEL_ZONES_OVERVIEW::GetCount() const { return m_filteredZones.size(); } -ZONE* MODEL_ZONES_OVERVIEW_TABLE::GetZone( wxDataViewItem const& aItem ) const +ZONE* MODEL_ZONES_OVERVIEW::GetZone( wxDataViewItem const& aItem ) const { if( !aItem.IsOk() ) return nullptr; @@ -194,7 +182,7 @@ ZONE* MODEL_ZONES_OVERVIEW_TABLE::GetZone( wxDataViewItem const& aItem ) const } -wxDataViewItem MODEL_ZONES_OVERVIEW_TABLE::GetItemByZone( ZONE* aZone ) const +wxDataViewItem MODEL_ZONES_OVERVIEW::GetItemByZone( ZONE* aZone ) const { if( !aZone ) return {}; @@ -209,8 +197,7 @@ wxDataViewItem MODEL_ZONES_OVERVIEW_TABLE::GetItemByZone( ZONE* aZone ) const } -std::optional MODEL_ZONES_OVERVIEW_TABLE::MoveZoneIndex( unsigned aIndex, - ZONE_INDEX_MOVEMENT aMovement ) +std::optional MODEL_ZONES_OVERVIEW::MoveZoneIndex( unsigned aIndex, ZONE_INDEX_MOVEMENT aMovement ) { switch( aMovement ) { @@ -231,8 +218,7 @@ std::optional MODEL_ZONES_OVERVIEW_TABLE::MoveZoneIndex( unsigned } -std::optional MODEL_ZONES_OVERVIEW_TABLE::SwapZonePriority( unsigned aDragIndex, - unsigned aDropIndex ) +std::optional MODEL_ZONES_OVERVIEW::SwapZonePriority( unsigned aDragIndex, unsigned aDropIndex ) { for( const unsigned i : { aDragIndex, aDropIndex } ) { @@ -243,8 +229,7 @@ std::optional MODEL_ZONES_OVERVIEW_TABLE::SwapZonePriority( unsigned a if( aDragIndex == aDropIndex ) return aDragIndex; - std::swap( m_filteredZones[aDragIndex]->m_currentPriority, - m_filteredZones[aDropIndex]->m_currentPriority ); + std::swap( m_filteredZones[aDragIndex]->m_currentPriority, m_filteredZones[aDropIndex]->m_currentPriority ); std::swap( m_filteredZones[aDragIndex], m_filteredZones[aDropIndex] ); for( const unsigned int row : { aDragIndex, aDropIndex } ) @@ -254,8 +239,7 @@ std::optional MODEL_ZONES_OVERVIEW_TABLE::SwapZonePriority( unsigned a } -wxDataViewItem MODEL_ZONES_OVERVIEW_TABLE::ApplyFilter( wxString const& aFilterText, - wxDataViewItem aSelection ) +wxDataViewItem MODEL_ZONES_OVERVIEW::ApplyFilter( wxString const& aFilterText, wxDataViewItem aSelection ) { if( !GetAllZonesCount() ) return {}; @@ -286,7 +270,7 @@ wxDataViewItem MODEL_ZONES_OVERVIEW_TABLE::ApplyFilter( wxString const& aFilterT } -wxDataViewItem MODEL_ZONES_OVERVIEW_TABLE::ClearFilter( wxDataViewItem aSelection ) +wxDataViewItem MODEL_ZONES_OVERVIEW::ClearFilter( wxDataViewItem aSelection ) { if( !GetAllZonesCount() ) return {}; diff --git a/pcbnew/zone_manager/model_zones_overview_table.h b/pcbnew/zone_manager/model_zones_overview.h similarity index 91% rename from pcbnew/zone_manager/model_zones_overview_table.h rename to pcbnew/zone_manager/model_zones_overview.h index c9774b73cb..6d9ebefadd 100644 --- a/pcbnew/zone_manager/model_zones_overview_table.h +++ b/pcbnew/zone_manager/model_zones_overview.h @@ -23,8 +23,7 @@ */ -#ifndef MODEL_ZONES_OVERVIEW_TABLE_H -#define MODEL_ZONES_OVERVIEW_TABLE_H +#pragma once #include #include @@ -41,6 +40,8 @@ class MANAGED_ZONE; wxDECLARE_EVENT( EVT_ZONES_OVERVIEW_COUNT_CHANGE, wxCommandEvent ); +#define LAYER_BAR_WIDTH 16 + enum class ZONE_INDEX_MOVEMENT { @@ -49,7 +50,7 @@ enum class ZONE_INDEX_MOVEMENT }; -class MODEL_ZONES_OVERVIEW_TABLE : public wxDataViewVirtualListModel +class MODEL_ZONES_OVERVIEW : public wxDataViewVirtualListModel { public: enum @@ -61,13 +62,6 @@ public: COL_COUNT }; - enum WIDTH_SETTING - { - NAME_WIDTH = 128, - LAYER_BAR_WIDTH = 16 - }; - - static std::map GetColumnNames() { //NOTE - Build the column name dynamicly in case the display language changed @@ -79,10 +73,10 @@ public: return ColNames; } - MODEL_ZONES_OVERVIEW_TABLE( std::vector> aZones, BOARD* a_pcb, + MODEL_ZONES_OVERVIEW( std::vector> aZones, BOARD* a_pcb, PCB_BASE_FRAME* aPCB_FRAME, wxWindow* a_dialog ); - ~MODEL_ZONES_OVERVIEW_TABLE() override; + ~MODEL_ZONES_OVERVIEW() override = default; void EnableFitterByName( bool aEnable ); @@ -146,5 +140,3 @@ private: bool m_sortByName; bool m_sortByNet; }; - -#endif \ No newline at end of file