Don't clear old footprint till after user has hit OK.
Fixes: lp:1759190 * https://bugs.launchpad.net/kicad/+bug/1759190
This commit is contained in:
parent
f4c972db5e
commit
d391489596
|
@ -443,19 +443,19 @@ public:
|
|||
|
||||
/**
|
||||
* Function LoadModuleFromLibrary
|
||||
* opens a dialog to select a footprint, and loads it into current board.
|
||||
* opens a dialog to select a footprint.
|
||||
*
|
||||
* @param aLibrary = the library name to use, or empty string to search
|
||||
* in all loaded libraries
|
||||
* @param aTable is the #FP_LIB_TABLE containing the avaiable footprint libraries.
|
||||
* @param aUseFootprintViewer = true to show the option
|
||||
* allowing the footprint selection by the footprint viewer
|
||||
* @param aLibrary = the library name to use, or empty string to search all libraries
|
||||
* @param aUseFootprintViewer = true to allow selection by the footprint viewer
|
||||
*/
|
||||
MODULE* LoadModuleFromLibrary( const wxString& aLibrary, bool aUseFootprintViewer = true );
|
||||
|
||||
/**
|
||||
* Adds the given module to the board.
|
||||
* @param module
|
||||
* @param aDC (can be NULL ) = the current Device Context, to draw the new footprint
|
||||
*/
|
||||
MODULE* LoadModuleFromLibrary( const wxString& aLibrary,
|
||||
FP_LIB_TABLE* aTable,
|
||||
bool aUseFootprintViewer = true,
|
||||
wxDC* aDC = NULL );
|
||||
void AddModuleToBoard( MODULE* module, wxDC* aDC = nullptr );
|
||||
|
||||
/**
|
||||
* Function SelectFootprintFromLibBrowser
|
||||
|
|
|
@ -300,15 +300,21 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
|
|||
|
||||
case ID_MODEDIT_NEW_MODULE:
|
||||
{
|
||||
if( !Clear_Pcb( true ) )
|
||||
break;
|
||||
|
||||
SetCrossHairPosition( wxPoint( 0, 0 ) );
|
||||
if( GetScreen()->IsModify() && !GetBoard()->IsEmpty() )
|
||||
{
|
||||
if( !IsOK( this, _( "Current Footprint will be lost and this operation cannot be undone. Continue ?" ) ) )
|
||||
break;
|
||||
}
|
||||
|
||||
MODULE* module = CreateNewModule( wxEmptyString );
|
||||
|
||||
if( module ) // i.e. if create module command not aborted
|
||||
{
|
||||
Clear_Pcb( false );
|
||||
|
||||
SetCrossHairPosition( wxPoint( 0, 0 ) );
|
||||
AddModuleToBoard( module );
|
||||
|
||||
// Initialize data relative to nets and netclasses (for a new
|
||||
// module the defaults are used)
|
||||
// This is mandatory to handle and draw pads
|
||||
|
@ -517,16 +523,26 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
|
|||
break;
|
||||
|
||||
case ID_MODEDIT_LOAD_MODULE:
|
||||
{
|
||||
wxLogDebug( wxT( "Loading module from library " ) + getLibPath() );
|
||||
|
||||
if( ! Clear_Pcb( true ) )
|
||||
if( GetScreen()->IsModify() && !GetBoard()->IsEmpty() )
|
||||
{
|
||||
if( !IsOK( this, _( "Current Footprint will be lost and this operation cannot be undone. Continue ?" ) ) )
|
||||
break;
|
||||
}
|
||||
|
||||
MODULE* module = LoadModuleFromLibrary( GetCurrentLib() );
|
||||
|
||||
if( !module )
|
||||
break;
|
||||
|
||||
Clear_Pcb( false );
|
||||
|
||||
SetCrossHairPosition( wxPoint( 0, 0 ) );
|
||||
AddModuleToBoard( module );
|
||||
|
||||
LoadModuleFromLibrary( GetCurrentLib(), Prj().PcbFootprintLibs(), true );
|
||||
|
||||
if( GetBoard() && GetBoard()->m_Modules )
|
||||
if( GetBoard()->m_Modules )
|
||||
{
|
||||
GetBoard()->m_Modules->ClearFlags();
|
||||
|
||||
|
@ -562,7 +578,7 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
|
|||
|
||||
updateView();
|
||||
m_canvas->Refresh();
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case ID_MODEDIT_PAD_SETTINGS:
|
||||
|
|
|
@ -807,12 +807,10 @@ void FOOTPRINT_VIEWER_FRAME::SelectCurrentFootprint( wxCommandEvent& event )
|
|||
{
|
||||
wxString curr_nickname = getCurNickname();
|
||||
MODULE* oldmodule = GetBoard()->m_Modules;
|
||||
MODULE* module = LoadModuleFromLibrary( curr_nickname, Prj().PcbFootprintLibs(), false );
|
||||
MODULE* module = LoadModuleFromLibrary( curr_nickname, false );
|
||||
|
||||
if( module )
|
||||
{
|
||||
module->SetPosition( wxPoint( 0, 0 ) );
|
||||
|
||||
// Only one footprint allowed: remove the previous footprint (if exists)
|
||||
if( oldmodule )
|
||||
{
|
||||
|
@ -820,6 +818,9 @@ void FOOTPRINT_VIEWER_FRAME::SelectCurrentFootprint( wxCommandEvent& event )
|
|||
delete oldmodule;
|
||||
}
|
||||
|
||||
SetCrossHairPosition( wxPoint( 0, 0 ) );
|
||||
AddModuleToBoard( module );
|
||||
|
||||
setCurFootprintName( module->GetFPID().GetLibItemName() );
|
||||
|
||||
wxString nickname = module->GetFPID().GetLibNickname();
|
||||
|
|
|
@ -160,13 +160,10 @@ wxString PCB_BASE_FRAME::SelectFootprintFromLibBrowser()
|
|||
}
|
||||
|
||||
|
||||
MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary,
|
||||
FP_LIB_TABLE* aTable,
|
||||
bool aUseFootprintViewer,
|
||||
wxDC* aDC )
|
||||
MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary, bool aUseFootprintViewer )
|
||||
{
|
||||
FP_LIB_TABLE* fpTable = Prj().PcbFootprintLibs();
|
||||
MODULE* module = NULL;
|
||||
wxPoint curspos = GetCrossHairPosition();
|
||||
wxString moduleName, keys;
|
||||
const wxString& libName = aLibrary;
|
||||
bool allowWildSeach = true;
|
||||
|
@ -207,7 +204,7 @@ MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary,
|
|||
// If the footprints are already in the cache, ReadFootprintFiles() will return
|
||||
// immediately.
|
||||
WX_PROGRESS_REPORTER progressReporter( this, _( "Loading Footprint Libraries" ), 2 );
|
||||
MList.ReadFootprintFiles( aTable, libName.length() ? &libName : NULL, &progressReporter );
|
||||
MList.ReadFootprintFiles( fpTable, libName.length() ? &libName : NULL, &progressReporter );
|
||||
progressReporter.Show( false );
|
||||
|
||||
if( MList.GetErrorCount() )
|
||||
|
@ -217,7 +214,7 @@ MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary,
|
|||
{
|
||||
allowWildSeach = false;
|
||||
keys = moduleName;
|
||||
moduleName = SelectFootprint( this, libName, wxEmptyString, keys, aTable );
|
||||
moduleName = SelectFootprint( this, libName, wxEmptyString, keys, fpTable );
|
||||
|
||||
if( moduleName.IsEmpty() ) // Cancel command
|
||||
{
|
||||
|
@ -228,7 +225,7 @@ MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary,
|
|||
else // Selection wild card
|
||||
{
|
||||
allowWildSeach = false;
|
||||
moduleName = SelectFootprint( this, libName, moduleName, wxEmptyString, aTable );
|
||||
moduleName = SelectFootprint( this, libName, moduleName, wxEmptyString, fpTable );
|
||||
|
||||
if( moduleName.IsEmpty() )
|
||||
{
|
||||
|
@ -261,7 +258,7 @@ MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary,
|
|||
wxString wildname = wxChar( '*' ) + moduleName + wxChar( '*' );
|
||||
moduleName = wildname;
|
||||
|
||||
moduleName = SelectFootprint( this, libName, moduleName, wxEmptyString, aTable );
|
||||
moduleName = SelectFootprint( this, libName, moduleName, wxEmptyString, fpTable );
|
||||
|
||||
if( moduleName.IsEmpty() )
|
||||
{
|
||||
|
@ -286,23 +283,29 @@ MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary,
|
|||
}
|
||||
}
|
||||
|
||||
SetCrossHairPosition( curspos );
|
||||
m_canvas->MoveCursorToCrossHair();
|
||||
if( module )
|
||||
{
|
||||
lastComponentName = moduleName;
|
||||
AddHistoryComponentName( HistoryList, moduleName );
|
||||
}
|
||||
|
||||
return module;
|
||||
}
|
||||
|
||||
|
||||
void PCB_BASE_FRAME::AddModuleToBoard( MODULE* module, wxDC* aDC )
|
||||
{
|
||||
if( module )
|
||||
{
|
||||
GetBoard()->Add( module, ADD_APPEND );
|
||||
|
||||
lastComponentName = moduleName;
|
||||
AddHistoryComponentName( HistoryList, moduleName );
|
||||
|
||||
module->SetFlags( IS_NEW );
|
||||
module->SetLink( 0 );
|
||||
|
||||
if( IsGalCanvasActive() )
|
||||
module->SetPosition( wxPoint( 0, 0 ) ); // cursor in GAL may not be initialized at the moment
|
||||
else
|
||||
module->SetPosition( curspos );
|
||||
module->SetPosition( GetCrossHairPosition() );
|
||||
|
||||
module->SetTimeStamp( GetNewTimeStamp() );
|
||||
GetBoard()->m_Status_Pcb = 0;
|
||||
|
@ -322,8 +325,6 @@ MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary,
|
|||
if( aDC )
|
||||
module->Draw( m_canvas, aDC, GR_OR );
|
||||
}
|
||||
|
||||
return module;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -368,13 +368,16 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
|
|||
if( (curr_item == NULL) || (curr_item->GetFlags() == 0) )
|
||||
{
|
||||
m_canvas->MoveCursorToCrossHair();
|
||||
curr_item = (BOARD_ITEM*) LoadModuleFromLibrary(
|
||||
wxEmptyString, Prj().PcbFootprintLibs(), true, aDC );
|
||||
MODULE* module = LoadModuleFromLibrary( wxEmptyString, Prj().PcbFootprintLibs() );
|
||||
|
||||
SetCurItem( curr_item );
|
||||
SetCurItem( (BOARD_ITEM*) module );
|
||||
|
||||
if( curr_item )
|
||||
StartMoveModule( (MODULE*) curr_item, aDC, false );
|
||||
if( module )
|
||||
{
|
||||
m_canvas->MoveCursorToCrossHair();
|
||||
AddModuleToBoard( module, aDC );
|
||||
StartMoveModule( module, aDC, false );
|
||||
}
|
||||
}
|
||||
else if( curr_item->Type() == PCB_MODULE_T )
|
||||
{
|
||||
|
|
|
@ -467,14 +467,12 @@ int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent )
|
|||
if( !module )
|
||||
{
|
||||
// Pick the module to be placed
|
||||
module = m_frame->LoadModuleFromLibrary( wxEmptyString,
|
||||
m_frame->Prj().PcbFootprintLibs(),
|
||||
true, NULL );
|
||||
module = m_frame->LoadModuleFromLibrary( wxEmptyString );
|
||||
|
||||
if( module == NULL )
|
||||
continue;
|
||||
|
||||
// NOTE: Module has been already added in LoadModuleFromLibrary(),
|
||||
m_frame->AddModuleToBoard( module );
|
||||
commit.Added( module );
|
||||
module->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
|
||||
m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, module );
|
||||
|
|
Loading…
Reference in New Issue