From 32afe5285e9fd2fd5dfd3ab081bfefee8b0380e2 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 27 Jul 2025 20:54:36 +0100 Subject: [PATCH] Finish off WX_GRID code sharing exercise. --- common/dialogs/dialog_configure_paths.cpp | 46 +++---- common/dialogs/dialog_plugin_options.cpp | 5 +- .../dialogs/panel_design_block_lib_table.cpp | 85 ++++--------- eeschema/dialogs/panel_sym_lib_table.cpp | 75 ++++-------- kicad/pcm/dialogs/panel_packages_view.cpp | 61 ++++------ pcbnew/dialogs/dialog_map_layers.cpp | 17 +-- ...ialog_multichannel_generate_rule_areas.cpp | 21 ++-- pcbnew/dialogs/panel_fp_lib_table.cpp | 85 ++++--------- .../dialogs/panel_fp_properties_3d_model.cpp | 37 +++--- .../panel_setup_time_domain_parameters.cpp | 114 ++++++++---------- pcbnew/sel_layer.cpp | 20 +-- 11 files changed, 202 insertions(+), 364 deletions(-) diff --git a/common/dialogs/dialog_configure_paths.cpp b/common/dialogs/dialog_configure_paths.cpp index 51a81f027b..2b3107315a 100644 --- a/common/dialogs/dialog_configure_paths.cpp +++ b/common/dialogs/dialog_configure_paths.cpp @@ -319,38 +319,32 @@ void DIALOG_CONFIGURE_PATHS::OnGridCellChanging( wxGridEvent& event ) void DIALOG_CONFIGURE_PATHS::OnAddEnvVar( wxCommandEvent& event ) { - if( !m_EnvVars->CommitPendingChanges() ) - return; - - AppendEnvVar( wxEmptyString, wxEmptyString, false ); - - m_EnvVars->MakeCellVisible( m_EnvVars->GetNumberRows() - 1, TV_NAME_COL ); - m_EnvVars->SetGridCursor( m_EnvVars->GetNumberRows() - 1, TV_NAME_COL ); - - m_EnvVars->EnableCellEditControl( true ); - m_EnvVars->ShowCellEditControl(); + m_EnvVars->OnAddRow( + [&]() -> std::pair + { + AppendEnvVar( wxEmptyString, wxEmptyString, false ); + return { m_EnvVars->GetNumberRows() - 1, TV_NAME_COL }; + } ); } void DIALOG_CONFIGURE_PATHS::OnRemoveEnvVar( wxCommandEvent& event ) { - int curRow = m_EnvVars->GetGridCursorRow(); + m_EnvVars->OnDeleteRows( + [&]( int row ) + { + if( ENV_VAR::IsEnvVarImmutable( m_EnvVars->GetCellValue( row, TV_NAME_COL ) ) ) + { + wxBell(); + return false; + } - if( curRow < 0 || m_EnvVars->GetNumberRows() <= curRow ) - { - return; - } - else if( ENV_VAR::IsEnvVarImmutable( m_EnvVars->GetCellValue( curRow, TV_NAME_COL ) ) ) - { - wxBell(); - return; - } - - m_EnvVars->CommitPendingChanges( true /* silent mode; we don't care if it's valid */ ); - m_EnvVars->DeleteRows( curRow, 1 ); - - m_EnvVars->MakeCellVisible( std::max( 0, curRow-1 ), m_EnvVars->GetGridCursorCol() ); - m_EnvVars->SetGridCursor( std::max( 0, curRow-1 ), m_EnvVars->GetGridCursorCol() ); + return true; + }, + [&]( int row ) + { + m_EnvVars->DeleteRows( row, 1 ); + } ); } diff --git a/common/dialogs/dialog_plugin_options.cpp b/common/dialogs/dialog_plugin_options.cpp index 691e96cf73..a80f17d5c7 100644 --- a/common/dialogs/dialog_plugin_options.cpp +++ b/common/dialogs/dialog_plugin_options.cpp @@ -147,11 +147,8 @@ bool DIALOG_PLUGIN_OPTIONS::TransferDataFromWindow() int DIALOG_PLUGIN_OPTIONS::appendRow() { - int row = m_grid->GetNumberRows(); - m_grid->AppendRows( 1 ); - - return row; + return m_grid->GetNumberRows() - 1; } diff --git a/common/dialogs/panel_design_block_lib_table.cpp b/common/dialogs/panel_design_block_lib_table.cpp index cd0b686d50..921f2d01fd 100644 --- a/common/dialogs/panel_design_block_lib_table.cpp +++ b/common/dialogs/panel_design_block_lib_table.cpp @@ -607,19 +607,12 @@ void PANEL_DESIGN_BLOCK_LIB_TABLE::OnUpdateUI( wxUpdateUIEvent& event ) void PANEL_DESIGN_BLOCK_LIB_TABLE::appendRowHandler( wxCommandEvent& event ) { - if( !m_cur_grid->CommitPendingChanges() ) - return; - - if( m_cur_grid->AppendRows( 1 ) ) - { - int last_row = m_cur_grid->GetNumberRows() - 1; - - // wx documentation is wrong, SetGridCursor does not make visible. - m_cur_grid->MakeCellVisible( last_row, COL_ENABLED ); - m_cur_grid->SetGridCursor( last_row, COL_NICKNAME ); - m_cur_grid->EnableCellEditControl( true ); - m_cur_grid->ShowCellEditControl(); - } + m_cur_grid->OnAddRow( + [&]() -> std::pair + { + m_cur_grid->AppendRows( 1 ); + return { m_cur_grid->GetNumberRows() - 1, COL_NICKNAME }; + } ); } @@ -691,61 +684,35 @@ void PANEL_DESIGN_BLOCK_LIB_TABLE::deleteRowHandler( wxCommandEvent& event ) void PANEL_DESIGN_BLOCK_LIB_TABLE::moveUpHandler( wxCommandEvent& event ) { - if( !m_cur_grid->CommitPendingChanges() ) - return; + m_cur_grid->OnMoveRowUp( + [&]( int row ) + { + DESIGN_BLOCK_LIB_TABLE_GRID* tbl = cur_model(); + boost::ptr_vector::auto_type move_me = tbl->m_rows.release( tbl->m_rows.begin() + row ); - DESIGN_BLOCK_LIB_TABLE_GRID* tbl = cur_model(); - int curRow = m_cur_grid->GetGridCursorRow(); + tbl->m_rows.insert( tbl->m_rows.begin() + row - 1, move_me.release() ); - // @todo: add multiple selection moves. - if( curRow >= 1 ) - { - boost::ptr_vector::auto_type move_me = - tbl->m_rows.release( tbl->m_rows.begin() + curRow ); - - --curRow; - tbl->m_rows.insert( tbl->m_rows.begin() + curRow, move_me.release() ); - - if( tbl->GetView() ) - { - // Update the wxGrid - wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow, 0 ); - tbl->GetView()->ProcessTableMessage( msg ); - } - - m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() ); - m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() ); - } + // Update the wxGrid + wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, row - 1, 0 ); + tbl->GetView()->ProcessTableMessage( msg ); + } ); } void PANEL_DESIGN_BLOCK_LIB_TABLE::moveDownHandler( wxCommandEvent& event ) { - if( !m_cur_grid->CommitPendingChanges() ) - return; + m_cur_grid->OnMoveRowDown( + [&]( int row ) + { + DESIGN_BLOCK_LIB_TABLE_GRID* tbl = cur_model(); + boost::ptr_vector::auto_type move_me = tbl->m_rows.release( tbl->m_rows.begin() + row ); - DESIGN_BLOCK_LIB_TABLE_GRID* tbl = cur_model(); - int curRow = m_cur_grid->GetGridCursorRow(); + tbl->m_rows.insert( tbl->m_rows.begin() + row + 1, move_me.release() ); - // @todo: add multiple selection moves. - if( unsigned( curRow + 1 ) < tbl->m_rows.size() ) - { - boost::ptr_vector::auto_type move_me = - tbl->m_rows.release( tbl->m_rows.begin() + curRow ); - - ++curRow; - tbl->m_rows.insert( tbl->m_rows.begin() + curRow, move_me.release() ); - - if( tbl->GetView() ) - { - // Update the wxGrid - wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow - 1, 0 ); - tbl->GetView()->ProcessTableMessage( msg ); - } - - m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() ); - m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() ); - } + // Update the wxGrid + wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, row, 0 ); + tbl->GetView()->ProcessTableMessage( msg ); + } ); } diff --git a/eeschema/dialogs/panel_sym_lib_table.cpp b/eeschema/dialogs/panel_sym_lib_table.cpp index 7ba05bbf9f..dd5df8586c 100644 --- a/eeschema/dialogs/panel_sym_lib_table.cpp +++ b/eeschema/dialogs/panel_sym_lib_table.cpp @@ -711,19 +711,12 @@ void PANEL_SYM_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event ) void PANEL_SYM_LIB_TABLE::appendRowHandler( wxCommandEvent& event ) { - if( !m_cur_grid->CommitPendingChanges() ) - return; - - if( m_cur_grid->AppendRows( 1 ) ) - { - int row = m_cur_grid->GetNumberRows() - 1; - - // wx documentation is wrong, SetGridCursor does not make visible. - m_cur_grid->MakeCellVisible( row, COL_ENABLED ); - m_cur_grid->SetGridCursor( row, COL_NICKNAME ); - m_cur_grid->EnableCellEditControl( true ); - m_cur_grid->ShowCellEditControl(); - } + m_cur_grid->OnAddRow( + [&]() -> std::pair + { + m_cur_grid->AppendRows( 1 ); + return { m_cur_grid->GetNumberRows() - 1, COL_NICKNAME }; + } ); } @@ -795,53 +788,29 @@ void PANEL_SYM_LIB_TABLE::deleteRowHandler( wxCommandEvent& event ) void PANEL_SYM_LIB_TABLE::moveUpHandler( wxCommandEvent& event ) { - if( !m_cur_grid->CommitPendingChanges() ) - return; + m_cur_grid->OnMoveRowUp( + [&]( int row ) + { + cur_model()->ChangeRowOrder( row, -1 ); - SYMBOL_LIB_TABLE_GRID* tbl = cur_model(); - int curRow = m_cur_grid->GetGridCursorRow(); - - // @todo: add multiple selection moves. - if( curRow >= 1 ) - { - tbl->ChangeRowOrder( curRow--, -1 ); - - if( tbl->GetView() ) - { - // Update the wxGrid - wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow, 0 ); - tbl->GetView()->ProcessTableMessage( msg ); - } - - m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() ); - m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() ); - } + // Update the wxGrid + wxGridTableMessage msg( cur_model(), wxGRIDTABLE_NOTIFY_ROWS_INSERTED, row - 1, 0 ); + cur_model()->GetView()->ProcessTableMessage( msg ); + } ); } void PANEL_SYM_LIB_TABLE::moveDownHandler( wxCommandEvent& event ) { - if( !m_cur_grid->CommitPendingChanges() ) - return; + m_cur_grid->OnMoveRowDown( + [&]( int row ) + { + cur_model()->ChangeRowOrder( row, 1 ); - SYMBOL_LIB_TABLE_GRID* tbl = cur_model(); - int curRow = m_cur_grid->GetGridCursorRow(); - - // @todo: add multiple selection moves. - if( unsigned( curRow + 1 ) < tbl->m_rows.size() ) - { - tbl->ChangeRowOrder( curRow++, 1 ); - - if( tbl->GetView() ) - { - // Update the wxGrid - wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow - 1, 0 ); - tbl->GetView()->ProcessTableMessage( msg ); - } - - m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() ); - m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() ); - } + // Update the wxGrid + wxGridTableMessage msg( cur_model(), wxGRIDTABLE_NOTIFY_ROWS_INSERTED, row, 0 ); + cur_model()->GetView()->ProcessTableMessage( msg ); + } ); } diff --git a/kicad/pcm/dialogs/panel_packages_view.cpp b/kicad/pcm/dialogs/panel_packages_view.cpp index 3dc87caa42..e465e20bd1 100644 --- a/kicad/pcm/dialogs/panel_packages_view.cpp +++ b/kicad/pcm/dialogs/panel_packages_view.cpp @@ -322,12 +322,9 @@ void PANEL_PACKAGES_VIEW::setPackageDetails( const PACKAGE_VIEW_DATA& aPackageDa m_gridVersions->InsertRows( row ); m_gridVersions->SetCellValue( row, COL_VERSION, version.version ); - m_gridVersions->SetCellValue( row, COL_DOWNLOAD_SIZE, - toHumanReadableSize( version.download_size ) ); - m_gridVersions->SetCellValue( row, COL_INSTALL_SIZE, - toHumanReadableSize( version.install_size ) ); - m_gridVersions->SetCellValue( row, COL_COMPATIBILITY, - version.compatible ? wxT( "\u2714" ) : wxEmptyString ); + m_gridVersions->SetCellValue( row, COL_DOWNLOAD_SIZE, toHumanReadableSize( version.download_size ) ); + m_gridVersions->SetCellValue( row, COL_INSTALL_SIZE, toHumanReadableSize( version.install_size ) ); + m_gridVersions->SetCellValue( row, COL_COMPATIBILITY, version.compatible ? wxT( "\u2714" ) : wxEmptyString ); m_gridVersions->SetCellValue( row, COL_STATUS, STATUS_ENUM_TO_STR.at( version.status ) ); m_gridVersions->SetCellAlignment( row, COL_COMPATIBILITY, wxALIGN_CENTER, wxALIGN_CENTER ); @@ -451,8 +448,8 @@ bool PANEL_PACKAGES_VIEW::canRunAction() const } -void PANEL_PACKAGES_VIEW::SetPackageState( const wxString& aPackageId, - const PCM_PACKAGE_STATE aState, const bool aPinned ) +void PANEL_PACKAGES_VIEW::SetPackageState( const wxString& aPackageId, const PCM_PACKAGE_STATE aState, + const bool aPinned ) { auto it = m_packagePanels.find( aPackageId ); @@ -467,13 +464,9 @@ void PANEL_PACKAGES_VIEW::SetPackageState( const wxString& aPackageId, } if( aState == PPS_UPDATE_AVAILABLE && !aPinned ) - { m_updateablePackages.insert( aPackageId ); - } else - { m_updateablePackages.erase( aPackageId ); - } updateCommonState(); } @@ -515,9 +508,8 @@ void PANEL_PACKAGES_VIEW::OnDownloadVersionClicked( wxCommandEvent& event ) if( !ver_it->download_url ) { - wxMessageBox( _( "Package download url is not specified" ), - _( "Error downloading package" ), wxICON_INFORMATION | wxOK, - wxGetTopLevelParent( this ) ); + wxMessageBox( _( "Package download url is not specified" ), _( "Error downloading package" ), + wxICON_INFORMATION | wxOK, wxGetTopLevelParent( this ) ); return; } @@ -553,13 +545,11 @@ void PANEL_PACKAGES_VIEW::OnDownloadVersionClicked( wxCommandEvent& event ) stream.close(); - if( !matches - && wxMessageBox( - _( "Integrity of the downloaded package could not be verified, hash " - "does not match. Are you sure you want to keep this file?" ), - _( "Keep downloaded file" ), wxICON_EXCLAMATION | wxYES_NO, - wxGetTopLevelParent( this ) ) - == wxNO ) + if( !matches && wxMessageBox( _( "Integrity of the downloaded package could not be verified, hash " + "does not match. Are you sure you want to keep this file?" ), + _( "Keep downloaded file" ), wxICON_EXCLAMATION | wxYES_NO, + wxGetTopLevelParent( this ) ) + == wxNO ) { wxRemoveFile( path ); } @@ -606,12 +596,11 @@ void PANEL_PACKAGES_VIEW::OnVersionActionClicked( wxCommandEvent& event ) wxCHECK_RET( ver_it != package.versions.end(), "Could not find package version" ); - if( !ver_it->compatible - && wxMessageBox( _( "This package version is incompatible with your KiCad version or " - "platform. Are you sure you want to install it anyway?" ), - _( "Install package" ), wxICON_EXCLAMATION | wxYES_NO, - wxGetTopLevelParent( this ) ) - == wxNO ) + if( !ver_it->compatible && wxMessageBox( _( "This package version is incompatible with your KiCad version or " + "platform. Are you sure you want to install it anyway?" ), + _( "Install package" ), wxICON_EXCLAMATION | wxYES_NO, + wxGetTopLevelParent( this ) ) + == wxNO ) { return; } @@ -655,8 +644,7 @@ void PANEL_PACKAGES_VIEW::updatePackageList() for( size_t index = 0; index < m_packageInitialOrder.size(); index++ ) { int rank = 1; - const PCM_PACKAGE& pkg = - m_packagePanels[m_packageInitialOrder[index]]->GetPackageData().package; + const PCM_PACKAGE& pkg = m_packagePanels[m_packageInitialOrder[index]]->GetPackageData().package; if( search_term.size() > 2 ) rank = m_pcm->GetPackageSearchRank( pkg, search_term ); @@ -717,9 +705,9 @@ void PANEL_PACKAGES_VIEW::updateDetailsButtons() switch( action ) { - case PPA_INSTALL: m_buttonAction->SetLabel( _( "Install" ) ); break; + case PPA_INSTALL: m_buttonAction->SetLabel( _( "Install" ) ); break; case PPA_UNINSTALL: m_buttonAction->SetLabel( _( "Uninstall" ) ); break; - case PPA_UPDATE: m_buttonAction->SetLabel( _( "Update" ) ); break; + case PPA_UPDATE: m_buttonAction->SetLabel( _( "Update" ) ); break; } } else @@ -732,8 +720,7 @@ void PANEL_PACKAGES_VIEW::updateDetailsButtons() PCM_PACKAGE_ACTION PANEL_PACKAGES_VIEW::getAction() const { - wxASSERT_MSG( m_gridVersions->GetNumberRows() == 1 - || m_gridVersions->GetSelectedRows().size() == 1, + wxASSERT_MSG( m_gridVersions->GetNumberRows() == 1 || m_gridVersions->GetSelectedRows().size() == 1, wxT( "getAction() called with ambiguous version selection" ) ); int selected_row = 0; @@ -801,8 +788,7 @@ void PANEL_PACKAGES_VIEW::SetSashOnIdle( wxIdleEvent& aEvent ) m_packageListWindow->FitInside(); - m_splitter1->Disconnect( wxEVT_IDLE, wxIdleEventHandler( PANEL_PACKAGES_VIEW::SetSashOnIdle ), - NULL, this ); + m_splitter1->Disconnect( wxEVT_IDLE, wxIdleEventHandler( PANEL_PACKAGES_VIEW::SetSashOnIdle ), nullptr, this ); } @@ -817,8 +803,7 @@ void PANEL_PACKAGES_VIEW::OnUpdateAllClicked( wxCommandEvent& event ) // The map will be modified by the callback so we copy the list here std::vector packages; - std::copy( m_updateablePackages.begin(), m_updateablePackages.end(), - std::back_inserter( packages ) ); + std::copy( m_updateablePackages.begin(), m_updateablePackages.end(), std::back_inserter( packages ) ); for( const wxString& pkg_id : packages ) { diff --git a/pcbnew/dialogs/dialog_map_layers.cpp b/pcbnew/dialogs/dialog_map_layers.cpp index 38b4482fde..2726673d66 100644 --- a/pcbnew/dialogs/dialog_map_layers.cpp +++ b/pcbnew/dialogs/dialog_map_layers.cpp @@ -154,8 +154,7 @@ void DIALOG_MAP_LAYERS::RemoveMappings( int aStatus ) wxArrayInt rowsToDelete; int itemIndex = -1; - while( ( itemIndex = m_matched_layers_list->GetNextItem( itemIndex, wxLIST_NEXT_ALL, aStatus ) ) - != wxNOT_FOUND ) + while( ( itemIndex = m_matched_layers_list->GetNextItem( itemIndex, wxLIST_NEXT_ALL, aStatus ) ) != wxNOT_FOUND ) { wxString selectedLayerName = m_matched_layers_list->GetItemText( itemIndex, 0 ); wxString pureSelectedLayerName = UnwrapRequired( selectedLayerName ); @@ -188,8 +187,7 @@ void DIALOG_MAP_LAYERS::OnAutoMatchLayersClicked( wxCommandEvent& event ) wxArrayInt rowsToDelete; while( ( itemIndex = m_unmatched_layers_list->GetNextItem( itemIndex, wxLIST_NEXT_ALL, - wxLIST_STATE_DONTCARE ) ) - != wxNOT_FOUND ) + wxLIST_STATE_DONTCARE ) ) != wxNOT_FOUND ) { wxString layerName = m_unmatched_layers_list->GetItemText( itemIndex ); PCB_LAYER_ID autoMatchLayer = GetAutoMatchLayerID( layerName ); @@ -206,8 +204,7 @@ void DIALOG_MAP_LAYERS::OnAutoMatchLayersClicked( wxCommandEvent& event ) m_matched_layers_map.insert( { UnwrapRequired( layerName ), autoMatchLayer } ); // remove selected layer from vector and also GUI list - for( auto iter = m_unmatched_layer_names.begin(); iter != m_unmatched_layer_names.end(); - ++iter ) + for( auto iter = m_unmatched_layer_names.begin(); iter != m_unmatched_layer_names.end(); ++iter ) { if( *iter == layerName ) { @@ -223,8 +220,7 @@ void DIALOG_MAP_LAYERS::OnAutoMatchLayersClicked( wxCommandEvent& event ) } -DIALOG_MAP_LAYERS::DIALOG_MAP_LAYERS( wxWindow* aParent, - const std::vector& aLayerDesc ) : +DIALOG_MAP_LAYERS::DIALOG_MAP_LAYERS( wxWindow* aParent, const std::vector& aLayerDesc ) : DIALOG_IMPORTED_LAYERS_BASE( aParent ) { LSET kiCadLayers; @@ -333,9 +329,8 @@ DIALOG_MAP_LAYERS::RunModal( wxWindow* aParent, const std::vector 0 ) { - wxMessageBox( _( "All required layers (marked with '*') must be matched. " - "Please click on 'Auto-Match Layers' to " - "automatically match the remaining layers" ), + wxMessageBox( _( "All required layers (marked with '*') must be matched. Please click " + "'Auto-Match Layers' to automatically match the remaining layers" ), _( "Unmatched Layers" ), wxICON_ERROR | wxOK ); } else diff --git a/pcbnew/dialogs/dialog_multichannel_generate_rule_areas.cpp b/pcbnew/dialogs/dialog_multichannel_generate_rule_areas.cpp index e57df7bee0..ac7c95a2a5 100644 --- a/pcbnew/dialogs/dialog_multichannel_generate_rule_areas.cpp +++ b/pcbnew/dialogs/dialog_multichannel_generate_rule_areas.cpp @@ -29,9 +29,8 @@ #include -DIALOG_MULTICHANNEL_GENERATE_RULE_AREAS::DIALOG_MULTICHANNEL_GENERATE_RULE_AREAS( - PCB_BASE_FRAME* aFrame, - MULTICHANNEL_TOOL* aParentTool ) : +DIALOG_MULTICHANNEL_GENERATE_RULE_AREAS::DIALOG_MULTICHANNEL_GENERATE_RULE_AREAS( PCB_BASE_FRAME* aFrame, + MULTICHANNEL_TOOL* aParentTool ) : DIALOG_MULTICHANNEL_GENERATE_RULE_AREAS_BASE( aFrame ), m_parentTool( aParentTool ) { @@ -159,20 +158,16 @@ DIALOG_MULTICHANNEL_GENERATE_RULE_AREAS::DIALOG_MULTICHANNEL_GENERATE_RULE_AREAS m_sheetGrid->SetCellValue( sheetRowIdx, 2, ruleArea.m_sheetName ); m_sheetGrid->SetCellRenderer( sheetRowIdx, 0, new wxGridCellBoolRenderer ); m_sheetGrid->SetCellEditor( sheetRowIdx, 0, new wxGridCellBoolEditor ); - m_sheetGrid->SetCellValue( sheetRowIdx, 0, - ruleArea.m_generateEnabled ? wxT( "1" ) : wxT( "" ) ); + m_sheetGrid->SetCellValue( sheetRowIdx, 0, ruleArea.m_generateEnabled ? wxT( "1" ) : wxT( "" ) ); sheetRowIdx++; } else if( ruleArea.m_sourceType == PLACEMENT_SOURCE_T::COMPONENT_CLASS ) { - m_componentClassGrid->SetCellValue( componentClassRowIdx, 1, - ruleArea.m_componentClass ); - m_componentClassGrid->SetCellRenderer( componentClassRowIdx, 0, - new wxGridCellBoolRenderer ); - m_componentClassGrid->SetCellEditor( componentClassRowIdx, 0, - new wxGridCellBoolEditor ); - m_componentClassGrid->SetCellValue( - componentClassRowIdx, 0, ruleArea.m_generateEnabled ? wxT( "1" ) : wxT( "" ) ); + m_componentClassGrid->SetCellValue( componentClassRowIdx, 1, ruleArea.m_componentClass ); + m_componentClassGrid->SetCellRenderer( componentClassRowIdx, 0, new wxGridCellBoolRenderer ); + m_componentClassGrid->SetCellEditor( componentClassRowIdx, 0, new wxGridCellBoolEditor ); + m_componentClassGrid->SetCellValue( componentClassRowIdx, 0, ruleArea.m_generateEnabled ? wxT( "1" ) + : wxT( "" ) ); componentClassRowIdx++; } else diff --git a/pcbnew/dialogs/panel_fp_lib_table.cpp b/pcbnew/dialogs/panel_fp_lib_table.cpp index 6580bccb85..bfe0482f67 100644 --- a/pcbnew/dialogs/panel_fp_lib_table.cpp +++ b/pcbnew/dialogs/panel_fp_lib_table.cpp @@ -587,19 +587,12 @@ void PANEL_FP_LIB_TABLE::OnUpdateUI( wxUpdateUIEvent& event ) void PANEL_FP_LIB_TABLE::appendRowHandler( wxCommandEvent& event ) { - if( !m_cur_grid->CommitPendingChanges() ) - return; - - if( m_cur_grid->AppendRows( 1 ) ) - { - int last_row = m_cur_grid->GetNumberRows() - 1; - - // wx documentation is wrong, SetGridCursor does not make visible. - m_cur_grid->MakeCellVisible( last_row, COL_ENABLED ); - m_cur_grid->SetGridCursor( last_row, COL_NICKNAME ); - m_cur_grid->EnableCellEditControl( true ); - m_cur_grid->ShowCellEditControl(); - } + m_cur_grid->OnAddRow( + [&]() -> std::pair + { + m_cur_grid->AppendRows( 1 ); + return { m_cur_grid->GetNumberRows() - 1, COL_NICKNAME }; + } ); } @@ -671,61 +664,35 @@ void PANEL_FP_LIB_TABLE::deleteRowHandler( wxCommandEvent& event ) void PANEL_FP_LIB_TABLE::moveUpHandler( wxCommandEvent& event ) { - if( !m_cur_grid->CommitPendingChanges() ) - return; + m_cur_grid->OnMoveRowUp( + [&]( int row ) + { + FP_LIB_TABLE_GRID* tbl = cur_model(); + boost::ptr_vector::auto_type move_me = tbl->m_rows.release( tbl->m_rows.begin() + row ); - FP_LIB_TABLE_GRID* tbl = cur_model(); - int curRow = m_cur_grid->GetGridCursorRow(); + tbl->m_rows.insert( tbl->m_rows.begin() + row - 1, move_me.release() ); - // @todo: add multiple selection moves. - if( curRow >= 1 ) - { - boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me = - tbl->m_rows.release( tbl->m_rows.begin() + curRow ); - - --curRow; - tbl->m_rows.insert( tbl->m_rows.begin() + curRow, move_me.release() ); - - if( tbl->GetView() ) - { - // Update the wxGrid - wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow, 0 ); - tbl->GetView()->ProcessTableMessage( msg ); - } - - m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() ); - m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() ); - } + // Update the wxGrid + wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, row - 1, 0 ); + tbl->GetView()->ProcessTableMessage( msg ); + } ); } void PANEL_FP_LIB_TABLE::moveDownHandler( wxCommandEvent& event ) { - if( !m_cur_grid->CommitPendingChanges() ) - return; + m_cur_grid->OnMoveRowDown( + [&]( int row ) + { + FP_LIB_TABLE_GRID* tbl = cur_model(); + boost::ptr_vector::auto_type move_me = tbl->m_rows.release( tbl->m_rows.begin() + row ); - FP_LIB_TABLE_GRID* tbl = cur_model(); - int curRow = m_cur_grid->GetGridCursorRow(); + tbl->m_rows.insert( tbl->m_rows.begin() + row + 1, move_me.release() ); - // @todo: add multiple selection moves. - if( unsigned( curRow + 1 ) < tbl->m_rows.size() ) - { - boost::ptr_vector< LIB_TABLE_ROW >::auto_type move_me = - tbl->m_rows.release( tbl->m_rows.begin() + curRow ); - - ++curRow; - tbl->m_rows.insert( tbl->m_rows.begin() + curRow, move_me.release() ); - - if( tbl->GetView() ) - { - // Update the wxGrid - wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, curRow - 1, 0 ); - tbl->GetView()->ProcessTableMessage( msg ); - } - - m_cur_grid->MakeCellVisible( curRow, m_cur_grid->GetGridCursorCol() ); - m_cur_grid->SetGridCursor( curRow, m_cur_grid->GetGridCursorCol() ); - } + // Update the wxGrid + wxGridTableMessage msg( tbl, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, row, 0 ); + tbl->GetView()->ProcessTableMessage( msg ); + } ); } diff --git a/pcbnew/dialogs/panel_fp_properties_3d_model.cpp b/pcbnew/dialogs/panel_fp_properties_3d_model.cpp index ff82d301f3..9a57c43a64 100644 --- a/pcbnew/dialogs/panel_fp_properties_3d_model.cpp +++ b/pcbnew/dialogs/panel_fp_properties_3d_model.cpp @@ -343,7 +343,6 @@ void PANEL_FP_PROPERTIES_3D_MODEL::OnAdd3DModel( wxCommandEvent& ) filter = (int) tmp; } - DIALOG_SELECT_3DMODEL dm( m_parentDialog, cache, &model, initialpath, filter ); // Use QuasiModal so that Configure3DPaths (and its help window) will work @@ -399,7 +398,6 @@ void PANEL_FP_PROPERTIES_3D_MODEL::OnAdd3DModel( wxCommandEvent& ) model.m_Filename = result->GetLink(); } - prj.SetRString( PROJECT::VIEWER_3D_PATH, initialpath ); sidx = wxString::Format( wxT( "%i" ), filter ); prj.SetRString( PROJECT::VIEWER_3D_FILTER_INDEX, sidx ); @@ -434,30 +432,25 @@ void PANEL_FP_PROPERTIES_3D_MODEL::OnAdd3DModel( wxCommandEvent& ) void PANEL_FP_PROPERTIES_3D_MODEL::OnAdd3DRow( wxCommandEvent& ) { - if( !m_modelsGrid->CommitPendingChanges() ) - return; + m_modelsGrid->OnAddRow( + [&]() -> std::pair + { + FP_3DMODEL model; - FP_3DMODEL model; + model.m_Show = true; + m_shapes3D_list.push_back( model ); - model.m_Show = true; - m_shapes3D_list.push_back( model ); + int row = m_modelsGrid->GetNumberRows(); + m_modelsGrid->AppendRows( 1 ); + m_modelsGrid->SetCellValue( row, COL_SHOWN, wxT( "1" ) ); + m_modelsGrid->SetCellValue( row, COL_PROBLEM, "" ); - int row = m_modelsGrid->GetNumberRows(); - m_modelsGrid->AppendRows( 1 ); - m_modelsGrid->SetCellValue( row, COL_SHOWN, wxT( "1" ) ); - m_modelsGrid->SetCellValue( row, COL_PROBLEM, "" ); + select3DModel( row ); + updateValidateStatus( row ); + onModify(); - select3DModel( row ); - - m_modelsGrid->SetFocus(); - m_modelsGrid->MakeCellVisible( row, COL_FILENAME ); - m_modelsGrid->SetGridCursor( row, COL_FILENAME ); - - m_modelsGrid->EnableCellEditControl( true ); - m_modelsGrid->ShowCellEditControl(); - - updateValidateStatus( row ); - onModify(); + return { row, COL_FILENAME }; + } ); } diff --git a/pcbnew/dialogs/panel_setup_time_domain_parameters.cpp b/pcbnew/dialogs/panel_setup_time_domain_parameters.cpp index 27c00a02a7..7f1a73c6ed 100644 --- a/pcbnew/dialogs/panel_setup_time_domain_parameters.cpp +++ b/pcbnew/dialogs/panel_setup_time_domain_parameters.cpp @@ -403,93 +403,77 @@ void PANEL_SETUP_TIME_DOMAIN_PARAMETERS::updateViaGridColumns() void PANEL_SETUP_TIME_DOMAIN_PARAMETERS::OnAddDelayProfileClick( wxCommandEvent& event ) { - if( !m_tracePropagationGrid->CommitPendingChanges() ) - return; + m_tracePropagationGrid->OnAddRow( + [&]() -> std::pair + { + const int row = m_tracePropagationGrid->GetNumberRows(); + m_tracePropagationGrid->AppendRows(); + m_tracePropagationGrid->SetCellValue( row, PROFILE_GRID_PROFILE_NAME, "" ); - const int rowId = m_tracePropagationGrid->GetNumberRows(); - m_tracePropagationGrid->AppendRows(); - m_tracePropagationGrid->SetCellValue( rowId, PROFILE_GRID_PROFILE_NAME, "" ); + for( int i = PROFILE_GRID_VIA_PROP_DELAY; i < m_tracePropagationGrid->GetNumberCols(); ++i ) + m_tracePropagationGrid->SetUnitValue( row, i, 0 ); - for( int i = PROFILE_GRID_VIA_PROP_DELAY; i < m_tracePropagationGrid->GetNumberCols(); ++i ) - m_tracePropagationGrid->SetUnitValue( rowId, i, 0 ); - - const int newRow = m_tracePropagationGrid->GetNumberRows() - 1; - m_tracePropagationGrid->MakeCellVisible( newRow, PROFILE_GRID_PROFILE_NAME ); - m_tracePropagationGrid->SetGridCursor( newRow, PROFILE_GRID_PROFILE_NAME ); - m_tracePropagationGrid->EnableCellEditControl( true ); - m_tracePropagationGrid->ShowCellEditControl(); + return { row, PROFILE_GRID_PROFILE_NAME }; + } ); } void PANEL_SETUP_TIME_DOMAIN_PARAMETERS::OnRemoveDelayProfileClick( wxCommandEvent& event ) { - if( !m_tracePropagationGrid->CommitPendingChanges() ) - return; + m_tracePropagationGrid->OnDeleteRows( + [&]( int row ) + { + wxString profileName = getProfileNameForProfileGridRow( row ); - const int curRow = m_tracePropagationGrid->GetGridCursorRow(); + // Delete associated via overrides + for( int viaRow = m_viaPropagationGrid->GetNumberRows() - 1; viaRow >= 0; --viaRow ) + { + if( m_viaPropagationGrid->GetCellValue( viaRow, VIA_GRID_PROFILE_NAME ) == profileName ) + m_viaPropagationGrid->DeleteRows( viaRow, 1 ); + } - if( curRow < 0 ) - return; + // Delete tuning profile + m_tracePropagationGrid->DeleteRows( row, 1 ); - wxString profileName = getProfileNameForProfileGridRow( curRow ); - - // Delete associated via overrides - for( int viaRow = m_viaPropagationGrid->GetNumberRows() - 1; viaRow >= 0; --viaRow ) - { - if( m_viaPropagationGrid->GetCellValue( viaRow, VIA_GRID_PROFILE_NAME ) == profileName ) - m_viaPropagationGrid->DeleteRows( viaRow, 1 ); - } - - // Delete tuning profile - m_tracePropagationGrid->DeleteRows( curRow, 1 ); - - m_tracePropagationGrid->MakeCellVisible( std::max( 0, curRow - 1 ), - m_tracePropagationGrid->GetGridCursorCol() ); - m_tracePropagationGrid->SetGridCursor( std::max( 0, curRow - 1 ), - m_tracePropagationGrid->GetGridCursorCol() ); - - updateViaProfileNamesEditor(); + updateViaProfileNamesEditor(); + } ); } void PANEL_SETUP_TIME_DOMAIN_PARAMETERS::OnAddViaOverrideClick( wxCommandEvent& event ) { - if( !m_viaPropagationGrid->CommitPendingChanges() ) - return; + m_viaPropagationGrid->OnAddRow( + [&]() -> std::pair + { + const int row = m_viaPropagationGrid->GetNumberRows(); - // Check we have delay profiles to override - if( m_tracePropagationGrid->GetNumberRows() == 0 ) - { - const wxString msg = _( "No delay profiles to override" ); - PAGED_DIALOG::GetDialog( this )->SetError( msg, this, nullptr ); - return; - } + // Check we have delay profiles to override + if( m_tracePropagationGrid->GetNumberRows() == 0 ) + { + PAGED_DIALOG::GetDialog( this )->SetError( _( "No delay profiles to override" ), this, nullptr ); + return { row, -1 }; + } - const int rowId = m_viaPropagationGrid->GetNumberRows(); - m_viaPropagationGrid->AppendRows(); - m_viaPropagationGrid->SetCellValue( rowId, VIA_GRID_PROFILE_NAME, getProfileNameForProfileGridRow( 0 ) ); - m_viaPropagationGrid->SetCellValue( rowId, VIA_GRID_SIGNAL_LAYER_FROM, m_layerNames.front() ); - m_viaPropagationGrid->SetCellValue( rowId, VIA_GRID_SIGNAL_LAYER_TO, m_layerNames.back() ); - m_viaPropagationGrid->SetCellValue( rowId, VIA_GRID_VIA_LAYER_FROM, m_layerNames.front() ); - m_viaPropagationGrid->SetCellValue( rowId, VIA_GRID_VIA_LAYER_TO, m_layerNames.back() ); - m_viaPropagationGrid->SetUnitValue( rowId, VIA_GRID_DELAY, 0 ); + m_viaPropagationGrid->AppendRows(); + m_viaPropagationGrid->SetCellValue( row, VIA_GRID_PROFILE_NAME, getProfileNameForProfileGridRow( 0 ) ); + m_viaPropagationGrid->SetCellValue( row, VIA_GRID_SIGNAL_LAYER_FROM, m_layerNames.front() ); + m_viaPropagationGrid->SetCellValue( row, VIA_GRID_SIGNAL_LAYER_TO, m_layerNames.back() ); + m_viaPropagationGrid->SetCellValue( row, VIA_GRID_VIA_LAYER_FROM, m_layerNames.front() ); + m_viaPropagationGrid->SetCellValue( row, VIA_GRID_VIA_LAYER_TO, m_layerNames.back() ); + m_viaPropagationGrid->SetUnitValue( row, VIA_GRID_DELAY, 0 ); + + return { row, VIA_GRID_DELAY }; + } ); } void PANEL_SETUP_TIME_DOMAIN_PARAMETERS::OnRemoveViaOverrideClick( wxCommandEvent& event ) { - if( !m_viaPropagationGrid->CommitPendingChanges() ) - return; - - int curRow = m_viaPropagationGrid->GetGridCursorRow(); - - if( curRow < 0 ) - return; - - m_viaPropagationGrid->DeleteRows( curRow, 1 ); - - m_viaPropagationGrid->MakeCellVisible( std::max( 0, curRow - 1 ), m_viaPropagationGrid->GetGridCursorCol() ); - m_viaPropagationGrid->SetGridCursor( std::max( 0, curRow - 1 ), m_viaPropagationGrid->GetGridCursorCol() ); + m_viaPropagationGrid->OnDeleteRows( + [&]( int row ) + { + m_viaPropagationGrid->DeleteRows( row, 1 ); + } ); } diff --git a/pcbnew/sel_layer.cpp b/pcbnew/sel_layer.cpp index bc3e0b38ca..13889b883a 100644 --- a/pcbnew/sel_layer.cpp +++ b/pcbnew/sel_layer.cpp @@ -520,9 +520,7 @@ public: for( const PCB_LAYER_ID& layerId : m_layerPresentation.getOrderedEnabledLayers() ) { if( IsCopperLayer( layerId ) ) - { m_layersId.push_back( layerId ); - } } fillLayerGrid( m_leftGrid ); @@ -543,8 +541,7 @@ public: m_layerPairSettings.Bind( PCB_CURRENT_LAYER_PAIR_CHANGED, [this]( wxCommandEvent& aEvent ) { - const LAYER_PAIR& newPair = - m_layerPairSettings.GetCurrentLayerPair(); + const LAYER_PAIR& newPair = m_layerPairSettings.GetCurrentLayerPair(); setCurrentSelection( rowForLayer( newPair.GetLayerA() ), rowForLayer( newPair.GetLayerB() ) ); } ); @@ -567,10 +564,9 @@ private: for( const PCB_LAYER_ID& layerId : m_layersId ) { const wxColour fg = m_layerPresentation.getLayerColor( layerId ).ToColour(); - const wxColour color( - wxColour::AlphaBlend( fg.Red(), bg.Red(), fg.Alpha() / 255.0 ), - wxColour::AlphaBlend( fg.Green(), bg.Green(), fg.Alpha() / 255.0 ), - wxColour::AlphaBlend( fg.Blue(), bg.Blue(), fg.Alpha() / 255.0 ) ); + const wxColour color( wxColour::AlphaBlend( fg.Red(), bg.Red(), fg.Alpha() / 255.0 ), + wxColour::AlphaBlend( fg.Green(), bg.Green(), fg.Alpha() / 255.0 ), + wxColour::AlphaBlend( fg.Blue(), bg.Blue(), fg.Alpha() / 255.0 ) ); const wxString layerName = wxT( " " ) + m_layerPresentation.getLayerName( layerId ); @@ -591,9 +587,7 @@ private: for( unsigned i = 0; i < m_layersId.size(); ++i ) { if( m_layersId[i] == aLayerId ) - { return i; - } } wxASSERT_MSG( false, wxString::Format( "Unknown layer in grid: %d", aLayerId ) ); @@ -632,9 +626,8 @@ private: { // At start, there is no old row if( aRow < 0 ) - { return; - } + const wxString val = aSelect ? wxT( "1" ) : wxEmptyString; aGrid.SetCellValue( aRow, (int) CU_LAYER_COLNUMS::SELECT, val ); aGrid.SetGridCursor( aRow, (int) CU_LAYER_COLNUMS::COLOR ); @@ -690,8 +683,7 @@ public: m_addToPresetsButton->Bind( wxEVT_BUTTON, [this]( wxCommandEvent& aEvent ) { - const LAYER_PAIR newPair = - m_dialogPairSettings.GetCurrentLayerPair(); + const LAYER_PAIR newPair = m_dialogPairSettings.GetCurrentLayerPair(); m_presetsGridController.OnLayerPairAdded( newPair ); } );