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