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
This commit is contained in:
Jeff Young 2024-05-08 18:19:24 +01:00
parent dc8822b421
commit a99377c1ec
11 changed files with 167 additions and 149 deletions

View File

@ -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();
}

View File

@ -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 );
}

View File

@ -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();
}
}

View File

@ -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 )
{

View File

@ -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 )
{

View File

@ -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<SYMBOL_EDIT_FRAME*>( 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<SYMBOL_EDIT_FRAME*>( 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 )
{

View File

@ -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<PICKER_TOOL>();
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<SIMULATOR_FRAME*>( player );
if( !simFrame ) // Defensive coding; shouldn't happen.
return 0;

View File

@ -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 <tab> pinNumber pinName...
* fpFilter fpFilter...
*/
wxString netlist;
if( m_currentFootprint )
{
/*
* Symbol netlist format:
* pinNumber pinName <tab> 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();
}

View File

@ -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<FOOTPRINT_EDIT_FRAME*>( 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<FOOTPRINT_EDIT_FRAME*>( 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 )
{

View File

@ -1591,15 +1591,18 @@ int BOARD_EDITOR_CONTROL::EditFpInFpEditor( const TOOL_EVENT& aEvent )
PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
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<FOOTPRINT_EDIT_FRAME*>( 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 );

View File

@ -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<FOOTPRINT_WIZARD_FRAME*>( 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;
}