From faace3090cd7b6397c50cadeca2f2d46859adbb0 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 19 Apr 2020 22:41:37 +0100 Subject: [PATCH] Add specific selection updating when adding 3D models. This keeps us from being at the receiving end of wxWidgets' vagaries. Fixes https://gitlab.com/kicad/code/kicad/issues/3760 --- .../dialogs/dialog_edit_footprint_for_BoardEditor.cpp | 6 ++++++ pcbnew/dialogs/dialog_edit_footprint_for_fp_editor.cpp | 10 ++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pcbnew/dialogs/dialog_edit_footprint_for_BoardEditor.cpp b/pcbnew/dialogs/dialog_edit_footprint_for_BoardEditor.cpp index fceb4a9b68..9e3b6b35cf 100644 --- a/pcbnew/dialogs/dialog_edit_footprint_for_BoardEditor.cpp +++ b/pcbnew/dialogs/dialog_edit_footprint_for_BoardEditor.cpp @@ -493,6 +493,8 @@ void DIALOG_FOOTPRINT_BOARD_EDITOR::OnAdd3DModel( wxCommandEvent& ) if( !m_modelsGrid->CommitPendingChanges() ) return; + int selected = m_modelsGrid->GetGridCursorRow(); + PROJECT& prj = Prj(); MODULE_3D_SETTINGS model; @@ -520,6 +522,7 @@ void DIALOG_FOOTPRINT_BOARD_EDITOR::OnAdd3DModel( wxCommandEvent& ) if( !S3D::Select3DModel( this, Prj().Get3DCacheManager(), initialpath, filter, &model ) || model.m_Filename.empty() ) { + select3DModel( selected ); return; } @@ -547,6 +550,7 @@ void DIALOG_FOOTPRINT_BOARD_EDITOR::OnAdd3DModel( wxCommandEvent& ) m_modelsGrid->SetCellValue( idx, 0, filename ); m_modelsGrid->SetCellValue( idx, 1, wxT( "1" ) ); + select3DModel( idx ); m_PreviewPane->UpdateDummyModule(); } @@ -565,6 +569,8 @@ void DIALOG_FOOTPRINT_BOARD_EDITOR::OnAdd3DRow( wxCommandEvent& ) m_modelsGrid->AppendRows( 1 ); m_modelsGrid->SetCellValue( row, 1, wxT( "1" ) ); + select3DModel( row ); + m_modelsGrid->SetFocus(); m_modelsGrid->MakeCellVisible( row, 0 ); m_modelsGrid->SetGridCursor( row, 0 ); diff --git a/pcbnew/dialogs/dialog_edit_footprint_for_fp_editor.cpp b/pcbnew/dialogs/dialog_edit_footprint_for_fp_editor.cpp index d5017ab4c7..2a651745b9 100644 --- a/pcbnew/dialogs/dialog_edit_footprint_for_fp_editor.cpp +++ b/pcbnew/dialogs/dialog_edit_footprint_for_fp_editor.cpp @@ -404,7 +404,7 @@ void DIALOG_FOOTPRINT_FP_EDITOR::OnRemove3DModel( wxCommandEvent& ) m_shapes3D_list.erase( m_shapes3D_list.begin() + idx ); m_modelsGrid->DeleteRows( idx ); - select3DModel( idx-1 ); // will clamp idx within bounds + select3DModel( idx ); // will clamp idx within bounds m_PreviewPane->UpdateDummyModule(); } } @@ -415,12 +415,14 @@ void DIALOG_FOOTPRINT_FP_EDITOR::OnAdd3DModel( wxCommandEvent& ) if( !m_modelsGrid->CommitPendingChanges() ) return; + int selected = m_modelsGrid->GetGridCursorRow(); + PROJECT& prj = Prj(); MODULE_3D_SETTINGS model; wxString initialpath = prj.GetRString( PROJECT::VIEWER_3D_PATH ); wxString sidx = prj.GetRString( PROJECT::VIEWER_3D_FILTER_INDEX ); - int filter = 0; + int filter = 0; // If the PROJECT::VIEWER_3D_PATH hasn't been set yet, use the KISYS3DMOD environment // varaible and fall back to the project path if necessary. @@ -442,6 +444,7 @@ void DIALOG_FOOTPRINT_FP_EDITOR::OnAdd3DModel( wxCommandEvent& ) if( !S3D::Select3DModel( this, Prj().Get3DCacheManager(), initialpath, filter, &model ) || model.m_Filename.empty() ) { + select3DModel( selected ); return; } @@ -469,6 +472,7 @@ void DIALOG_FOOTPRINT_FP_EDITOR::OnAdd3DModel( wxCommandEvent& ) m_modelsGrid->SetCellValue( idx, 0, filename ); m_modelsGrid->SetCellValue( idx, 1, wxT( "1" ) ); + select3DModel( idx ); m_PreviewPane->UpdateDummyModule(); } @@ -487,6 +491,8 @@ void DIALOG_FOOTPRINT_FP_EDITOR::OnAdd3DRow( wxCommandEvent& ) m_modelsGrid->AppendRows( 1 ); m_modelsGrid->SetCellValue( row, 1, wxT( "1" ) ); + select3DModel( row ); + m_modelsGrid->SetFocus(); m_modelsGrid->MakeCellVisible( row, 0 ); m_modelsGrid->SetGridCursor( row, 0 );