From a99377c1ec2e55cf960f7eca6c058000d7e733f7 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 8 May 2024 18:19:24 +0100 Subject: [PATCH] The user can cancel the opening of many editors. Don't play dice with the devil. Fixes https://gitlab.com/kicad/code/kicad/-/issues/17989 --- common/widgets/grid_text_button_helpers.cpp | 32 ++++---- cvpcb/tools/cvpcb_control.cpp | 6 +- eeschema/dialogs/dialog_change_symbols.cpp | 30 ++++---- .../dialogs/dialog_symbol_fields_table.cpp | 13 ++-- eeschema/fields_grid_table.cpp | 12 +-- eeschema/tools/sch_edit_tool.cpp | 44 ++++++----- eeschema/tools/sch_editor_control.cpp | 4 +- pcbnew/dialogs/dialog_exchange_footprints.cpp | 59 ++++++++------- pcbnew/pcb_edit_frame.cpp | 24 +++--- pcbnew/tools/board_editor_control.cpp | 17 +++-- pcbnew/tools/footprint_editor_control.cpp | 75 ++++++++++--------- 11 files changed, 167 insertions(+), 149 deletions(-) diff --git a/common/widgets/grid_text_button_helpers.cpp b/common/widgets/grid_text_button_helpers.cpp index acf7374fa5..0c99384004 100644 --- a/common/widgets/grid_text_button_helpers.cpp +++ b/common/widgets/grid_text_button_helpers.cpp @@ -202,13 +202,15 @@ protected: if( rawValue.IsEmpty() ) rawValue = m_preselect; - wxString symbolId = escapeLibId( rawValue ); - KIWAY_PLAYER* frame = m_dlg->Kiway().Player( FRAME_SYMBOL_CHOOSER, true, m_dlg ); + wxString symbolId = escapeLibId( rawValue ); - if( frame->ShowModal( &symbolId, m_dlg ) ) - SetValue( UnescapeString( symbolId ) ); + if( KIWAY_PLAYER* frame = m_dlg->Kiway().Player( FRAME_SYMBOL_CHOOSER, true, m_dlg ) ) + { + if( frame->ShowModal( &symbolId, m_dlg ) ) + SetValue( UnescapeString( symbolId ) ); - frame->Destroy(); + frame->Destroy(); + } } DIALOG_SHIM* m_dlg; @@ -262,18 +264,20 @@ protected: // multiple clicks will cause multiple instances of the footprint loader process to start Disable(); - KIWAY_PLAYER* frame = m_dlg->Kiway().Player( FRAME_FOOTPRINT_CHOOSER, true, m_dlg ); - - if( !m_symbolNetlist.empty() ) + if( KIWAY_PLAYER* frame = m_dlg->Kiway().Player( FRAME_FOOTPRINT_CHOOSER, true, m_dlg ) ) { - KIWAY_EXPRESS event( FRAME_FOOTPRINT_CHOOSER, MAIL_SYMBOL_NETLIST, m_symbolNetlist ); - frame->KiwayMailIn( event ); + if( !m_symbolNetlist.empty() ) + { + KIWAY_EXPRESS event( FRAME_FOOTPRINT_CHOOSER, MAIL_SYMBOL_NETLIST, m_symbolNetlist ); + frame->KiwayMailIn( event ); + } + + if( frame->ShowModal( &fpid, m_dlg ) ) + SetValue( fpid ); + + frame->Destroy(); } - if( frame->ShowModal( &fpid, m_dlg ) ) - SetValue( fpid ); - - frame->Destroy(); Enable(); } diff --git a/cvpcb/tools/cvpcb_control.cpp b/cvpcb/tools/cvpcb_control.cpp index eb6d00476a..11a12e76ca 100644 --- a/cvpcb/tools/cvpcb_control.cpp +++ b/cvpcb/tools/cvpcb_control.cpp @@ -177,11 +177,11 @@ int CVPCB_CONTROL::ShowFootprintViewer( const TOOL_EVENT& aEvent ) fpframe = (DISPLAY_FOOTPRINTS_FRAME*) m_frame->Kiway().Player( FRAME_CVPCB_DISPLAY, true, m_frame ); + + // If Kiway() cannot create the eeschema frame, it shows a error message, and + // frame is null if( !fpframe ) - { - wxMessageBox( _( "Unable to create the footprint viewer frame" ) ); return 0; - } fpframe->Show( true ); } diff --git a/eeschema/dialogs/dialog_change_symbols.cpp b/eeschema/dialogs/dialog_change_symbols.cpp index 928454f7e6..620bd33be7 100644 --- a/eeschema/dialogs/dialog_change_symbols.cpp +++ b/eeschema/dialogs/dialog_change_symbols.cpp @@ -248,15 +248,16 @@ void DIALOG_CHANGE_SYMBOLS::launchMatchIdSymbolBrowser( wxCommandEvent& aEvent ) { wxString newName = getLibIdValue( m_specifiedId ); - KIWAY_PLAYER* frame = Kiway().Player( FRAME_SYMBOL_CHOOSER, true, this ); - - if( frame->ShowModal( &newName, this ) ) + if( KIWAY_PLAYER* frame = Kiway().Player( FRAME_SYMBOL_CHOOSER, true, this ) ) { - m_specifiedId->SetValue( UnescapeString( newName ) ); - updateFieldsList(); - } + if( frame->ShowModal( &newName, this ) ) + { + m_specifiedId->SetValue( UnescapeString( newName ) ); + updateFieldsList(); + } - frame->Destroy(); + frame->Destroy(); + } } @@ -264,15 +265,16 @@ void DIALOG_CHANGE_SYMBOLS::launchNewIdSymbolBrowser( wxCommandEvent& aEvent ) { wxString newName = getLibIdValue( m_newId ); - KIWAY_PLAYER* frame = Kiway().Player( FRAME_SYMBOL_CHOOSER, true, this ); - - if( frame->ShowModal( &newName, this ) ) + if( KIWAY_PLAYER* frame = Kiway().Player( FRAME_SYMBOL_CHOOSER, true, this ) ) { - m_newId->SetValue( UnescapeString( newName ) ); - updateFieldsList(); - } + if( frame->ShowModal( &newName, this ) ) + { + m_newId->SetValue( UnescapeString( newName ) ); + updateFieldsList(); + } - frame->Destroy(); + frame->Destroy(); + } } diff --git a/eeschema/dialogs/dialog_symbol_fields_table.cpp b/eeschema/dialogs/dialog_symbol_fields_table.cpp index aaa044d1ea..9e54d6e10c 100644 --- a/eeschema/dialogs/dialog_symbol_fields_table.cpp +++ b/eeschema/dialogs/dialog_symbol_fields_table.cpp @@ -110,14 +110,15 @@ protected: if( event.GetId() == MYID_SELECT_FOOTPRINT ) { // pick a footprint using the footprint picker. - wxString fpid = m_grid->GetCellValue( m_grid->GetGridCursorRow(), - FOOTPRINT_FIELD ); - KIWAY_PLAYER* frame = m_dlg->Kiway().Player( FRAME_FOOTPRINT_CHOOSER, true, m_dlg ); + wxString fpid = m_grid->GetCellValue( m_grid->GetGridCursorRow(), FOOTPRINT_FIELD ); - if( frame->ShowModal( &fpid, m_dlg ) ) - m_grid->SetCellValue( m_grid->GetGridCursorRow(), FOOTPRINT_FIELD, fpid ); + if( KIWAY_PLAYER* frame = m_dlg->Kiway().Player( FRAME_FOOTPRINT_CHOOSER, true, m_dlg ) ) + { + if( frame->ShowModal( &fpid, m_dlg ) ) + m_grid->SetCellValue( m_grid->GetGridCursorRow(), FOOTPRINT_FIELD, fpid ); - frame->Destroy(); + frame->Destroy(); + } } else if (event.GetId() == MYID_SHOW_DATASHEET ) { diff --git a/eeschema/fields_grid_table.cpp b/eeschema/fields_grid_table.cpp index 77d8273d20..0f16e3faea 100644 --- a/eeschema/fields_grid_table.cpp +++ b/eeschema/fields_grid_table.cpp @@ -918,13 +918,15 @@ void FIELDS_GRID_TRICKS::doPopupSelection( wxCommandEvent& event ) if( event.GetId() == MYID_SELECT_FOOTPRINT ) { // pick a footprint using the footprint picker. - wxString fpid = m_grid->GetCellValue( FOOTPRINT_FIELD, FDC_VALUE ); - KIWAY_PLAYER* frame = m_dlg->Kiway().Player( FRAME_FOOTPRINT_CHOOSER, true, m_dlg ); + wxString fpid = m_grid->GetCellValue( FOOTPRINT_FIELD, FDC_VALUE ); - if( frame->ShowModal( &fpid, m_dlg ) ) - m_grid->SetCellValue( FOOTPRINT_FIELD, FDC_VALUE, fpid ); + if( KIWAY_PLAYER* frame = m_dlg->Kiway().Player( FRAME_FOOTPRINT_CHOOSER, true, m_dlg ) ) + { + if( frame->ShowModal( &fpid, m_dlg ) ) + m_grid->SetCellValue( FOOTPRINT_FIELD, FDC_VALUE, fpid ); - frame->Destroy(); + frame->Destroy(); + } } else if (event.GetId() == MYID_SHOW_DATASHEET ) { diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index b4bc9784ac..87c85dffd8 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -1826,37 +1826,35 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) } else if( retval == SYMBOL_PROPS_EDIT_SCHEMATIC_SYMBOL ) { - auto editor = (SYMBOL_EDIT_FRAME*) m_frame->Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, - true ); + if( KIWAY_PLAYER* frame = m_frame->Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, true ) ) + { + SYMBOL_EDIT_FRAME* editor = static_cast( frame ); - wxCHECK( editor, 0 ); + if( wxWindow* blocking_win = editor->Kiway().GetBlockingDialog() ) + blocking_win->Close( true ); - if( wxWindow* blocking_win = editor->Kiway().GetBlockingDialog() ) - blocking_win->Close( true ); + // The broken library symbol link indicator cannot be edited. + if( symbol->IsMissingLibSymbol() ) + return 0; - // The broken library symbol link indicator cannot be edited. - if( symbol->IsMissingLibSymbol() ) - return 0; - - editor->LoadSymbolFromSchematic( symbol ); - - editor->Show( true ); - editor->Raise(); + editor->LoadSymbolFromSchematic( symbol ); + editor->Show( true ); + editor->Raise(); + } } else if( retval == SYMBOL_PROPS_EDIT_LIBRARY_SYMBOL ) { - auto editor = (SYMBOL_EDIT_FRAME*) m_frame->Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, - true ); + if( KIWAY_PLAYER* frame = m_frame->Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, true ) ) + { + SYMBOL_EDIT_FRAME* editor = static_cast( frame ); - wxCHECK( editor, 0 ); + if( wxWindow* blocking_win = editor->Kiway().GetBlockingDialog() ) + blocking_win->Close( true ); - if( wxWindow* blocking_win = editor->Kiway().GetBlockingDialog() ) - blocking_win->Close( true ); - - editor->LoadSymbol( symbol->GetLibId(), symbol->GetUnit(), symbol->GetBodyStyle() ); - - editor->Show( true ); - editor->Raise(); + editor->LoadSymbol( symbol->GetLibId(), symbol->GetUnit(), symbol->GetBodyStyle() ); + editor->Show( true ); + editor->Raise(); + } } else if( retval == SYMBOL_PROPS_WANT_UPDATE_SYMBOL ) { diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index 99983d7ee8..2fab669bf3 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -544,8 +544,8 @@ int SCH_EDITOR_CONTROL::ExportSymbolsToLibrary( const TOOL_EVENT& aEvent ) int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent ) { PICKER_TOOL* picker = m_toolMgr->GetTool(); - SIMULATOR_FRAME* simFrame = (SIMULATOR_FRAME*) m_frame->Kiway().Player( FRAME_SIMULATOR, - false ); + KIWAY_PLAYER* player = m_frame->Kiway().Player( FRAME_SIMULATOR, false ); + SIMULATOR_FRAME* simFrame = static_cast( player ); if( !simFrame ) // Defensive coding; shouldn't happen. return 0; diff --git a/pcbnew/dialogs/dialog_exchange_footprints.cpp b/pcbnew/dialogs/dialog_exchange_footprints.cpp index 835e2824d5..8ff5d54eed 100644 --- a/pcbnew/dialogs/dialog_exchange_footprints.cpp +++ b/pcbnew/dialogs/dialog_exchange_footprints.cpp @@ -406,43 +406,44 @@ void DIALOG_EXCHANGE_FOOTPRINTS::ViewAndSelectFootprint( wxCommandEvent& event ) { wxString newname = m_newID->GetValue(); - KIWAY_PLAYER* frame = Kiway().Player( FRAME_FOOTPRINT_CHOOSER, true, this ); - - if( m_currentFootprint ) + if( KIWAY_PLAYER* frame = Kiway().Player( FRAME_FOOTPRINT_CHOOSER, true, this ) ) { - /* - * Symbol netlist format: - * pinNumber pinName pinNumber pinName... - * fpFilter fpFilter... - */ - wxString netlist; + if( m_currentFootprint ) + { + /* + * Symbol netlist format: + * pinNumber pinName pinNumber pinName... + * fpFilter fpFilter... + */ + wxString netlist; - wxArrayString pins; + wxArrayString pins; - for( const wxString& pad : m_currentFootprint->GetUniquePadNumbers() ) - pins.push_back( pad + ' ' + wxEmptyString /* leave pinName empty */ ); + for( const wxString& pad : m_currentFootprint->GetUniquePadNumbers() ) + pins.push_back( pad + ' ' + wxEmptyString /* leave pinName empty */ ); - if( !pins.IsEmpty() ) - netlist << EscapeString( wxJoin( pins, '\t' ), CTX_LINE ); + if( !pins.IsEmpty() ) + netlist << EscapeString( wxJoin( pins, '\t' ), CTX_LINE ); - netlist << wxS( "\r" ); + netlist << wxS( "\r" ); - netlist << EscapeString( m_currentFootprint->GetFilters(), CTX_LINE ) << wxS( "\r" ); + netlist << EscapeString( m_currentFootprint->GetFilters(), CTX_LINE ) << wxS( "\r" ); - std::string payload( netlist.ToStdString() ); - KIWAY_EXPRESS mail( FRAME_FOOTPRINT_CHOOSER, MAIL_SYMBOL_NETLIST, payload ); - frame->KiwayMailIn( mail ); + std::string payload( netlist.ToStdString() ); + KIWAY_EXPRESS mail( FRAME_FOOTPRINT_CHOOSER, MAIL_SYMBOL_NETLIST, payload ); + frame->KiwayMailIn( mail ); + } + + if( frame->ShowModal( &newname, this ) ) + { + if( event.GetEventObject() == m_newIDBrowseButton ) + m_newID->SetValue( newname ); + else + m_specifiedID->SetValue( newname ); + } + + frame->Destroy(); } - - if( frame->ShowModal( &newname, this ) ) - { - if( event.GetEventObject() == m_newIDBrowseButton ) - m_newID->SetValue( newname ); - else - m_specifiedID->SetValue( newname ); - } - - frame->Destroy(); } diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index c7748af21a..b459bd7266 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -2100,21 +2100,25 @@ void PCB_EDIT_FRAME::ShowFootprintPropertiesDialog( FOOTPRINT* aFootprint ) } else if( retvalue == DIALOG_FOOTPRINT_PROPERTIES::FP_PROPS_EDIT_BOARD_FP ) { - auto editor = (FOOTPRINT_EDIT_FRAME*) Kiway().Player( FRAME_FOOTPRINT_EDITOR, true ); + if( KIWAY_PLAYER* frame = Kiway().Player( FRAME_FOOTPRINT_EDITOR, true ) ) + { + FOOTPRINT_EDIT_FRAME* fp_editor = static_cast( frame ); - editor->LoadFootprintFromBoard( aFootprint ); - - editor->Show( true ); - editor->Raise(); // Iconize( false ); + fp_editor->LoadFootprintFromBoard( aFootprint ); + fp_editor->Show( true ); + fp_editor->Raise(); // Iconize( false ); + } } else if( retvalue == DIALOG_FOOTPRINT_PROPERTIES::FP_PROPS_EDIT_LIBRARY_FP ) { - auto editor = (FOOTPRINT_EDIT_FRAME*) Kiway().Player( FRAME_FOOTPRINT_EDITOR, true ); + if( KIWAY_PLAYER* frame = Kiway().Player( FRAME_FOOTPRINT_EDITOR, true ) ) + { + FOOTPRINT_EDIT_FRAME* fp_editor = static_cast( frame ); - editor->LoadFootprintFromLibrary( aFootprint->GetFPID() ); - - editor->Show( true ); - editor->Raise(); // Iconize( false ); + fp_editor->LoadFootprintFromLibrary( aFootprint->GetFPID() ); + fp_editor->Show( true ); + fp_editor->Raise(); // Iconize( false ); + } } else if( retvalue == DIALOG_FOOTPRINT_PROPERTIES::FP_PROPS_UPDATE_FP ) { diff --git a/pcbnew/tools/board_editor_control.cpp b/pcbnew/tools/board_editor_control.cpp index 45bd335d4e..c0c07a9040 100644 --- a/pcbnew/tools/board_editor_control.cpp +++ b/pcbnew/tools/board_editor_control.cpp @@ -1591,15 +1591,18 @@ int BOARD_EDITOR_CONTROL::EditFpInFpEditor( const TOOL_EVENT& aEvent ) PCB_BASE_EDIT_FRAME* editFrame = getEditFrame(); - auto editor = (FOOTPRINT_EDIT_FRAME*) editFrame->Kiway().Player( FRAME_FOOTPRINT_EDITOR, true ); + if( KIWAY_PLAYER* frame = editFrame->Kiway().Player( FRAME_FOOTPRINT_EDITOR, true ) ) + { + FOOTPRINT_EDIT_FRAME* fp_editor = static_cast( frame ); - if( aEvent.IsAction( &PCB_ACTIONS::editFpInFpEditor ) ) - editor->LoadFootprintFromBoard( fp ); - else if( aEvent.IsAction( &PCB_ACTIONS::editLibFpInFpEditor ) ) - editor->LoadFootprintFromLibrary( fp->GetFPID() ); + if( aEvent.IsAction( &PCB_ACTIONS::editFpInFpEditor ) ) + fp_editor->LoadFootprintFromBoard( fp ); + else if( aEvent.IsAction( &PCB_ACTIONS::editLibFpInFpEditor ) ) + fp_editor->LoadFootprintFromLibrary( fp->GetFPID() ); - editor->Show( true ); - editor->Raise(); // Iconize( false ); + fp_editor->Show( true ); + fp_editor->Raise(); // Iconize( false ); + } if( selection.IsHover() ) m_toolMgr->RunAction( PCB_ACTIONS::selectionClear ); diff --git a/pcbnew/tools/footprint_editor_control.cpp b/pcbnew/tools/footprint_editor_control.cpp index d6c028b5c5..9de416cbcd 100644 --- a/pcbnew/tools/footprint_editor_control.cpp +++ b/pcbnew/tools/footprint_editor_control.cpp @@ -228,51 +228,54 @@ int FOOTPRINT_EDITOR_CONTROL::CreateFootprint( const TOOL_EVENT& aEvent ) } } - auto* wizard = (FOOTPRINT_WIZARD_FRAME*) m_frame->Kiway().Player( FRAME_FOOTPRINT_WIZARD, - true, m_frame ); - - if( wizard->ShowModal( nullptr, m_frame ) ) + if( KIWAY_PLAYER* frame = m_frame->Kiway().Player( FRAME_FOOTPRINT_WIZARD, true, m_frame ) ) { - // Creates the new footprint from python script wizard - FOOTPRINT* newFootprint = wizard->GetBuiltFootprint(); + FOOTPRINT_WIZARD_FRAME* wizard = static_cast( frame ); - if( newFootprint ) // i.e. if create footprint command is OK + if( wizard->ShowModal( nullptr, m_frame ) ) { - m_frame->Clear_Pcb( false ); + // Creates the new footprint from python script wizard + FOOTPRINT* newFootprint = wizard->GetBuiltFootprint(); - canvas()->GetViewControls()->SetCrossHairCursorPosition( VECTOR2D( 0, 0 ), false ); - // Add the new object to board - m_frame->AddFootprintToBoard( newFootprint ); - - // Initialize data relative to nets and netclasses (for a new footprint the defaults - // are used). This is mandatory to handle and draw pads. - board()->BuildListOfNets(); - newFootprint->SetPosition( VECTOR2I( 0, 0 ) ); - newFootprint->ClearFlags(); - - m_frame->Zoom_Automatique( false ); - m_frame->GetScreen()->SetContentModified(); - m_frame->OnModify(); - - // If selected from the library tree then go ahead and save it there - if( !selected.GetLibNickname().empty() ) + if( newFootprint ) // i.e. if create footprint command is OK { - LIB_ID fpid = newFootprint->GetFPID(); - fpid.SetLibNickname( selected.GetLibNickname() ); - newFootprint->SetFPID( fpid ); - m_frame->SaveFootprint( newFootprint ); - m_frame->ClearModify(); + m_frame->Clear_Pcb( false ); + + canvas()->GetViewControls()->SetCrossHairCursorPosition( VECTOR2D( 0, 0 ), false ); + // Add the new object to board + m_frame->AddFootprintToBoard( newFootprint ); + + // Initialize data relative to nets and netclasses (for a new footprint the + // defaults are used). This is mandatory to handle and draw pads. + board()->BuildListOfNets(); + newFootprint->SetPosition( VECTOR2I( 0, 0 ) ); + newFootprint->ClearFlags(); + + m_frame->Zoom_Automatique( false ); + m_frame->GetScreen()->SetContentModified(); + m_frame->OnModify(); + + // If selected from the library tree then go ahead and save it there + if( !selected.GetLibNickname().empty() ) + { + LIB_ID fpid = newFootprint->GetFPID(); + fpid.SetLibNickname( selected.GetLibNickname() ); + newFootprint->SetFPID( fpid ); + m_frame->SaveFootprint( newFootprint ); + m_frame->ClearModify(); + } + + m_frame->UpdateView(); + canvas()->Refresh(); + m_frame->Update3DView( true, true ); + + m_frame->SyncLibraryTree( false ); } - - m_frame->UpdateView(); - canvas()->Refresh(); - m_frame->Update3DView( true, true ); - - m_frame->SyncLibraryTree( false ); } + + wizard->Destroy(); } - wizard->Destroy(); return 0; }