Fixed crash on undo pad placement in the footprint editor (GAL).

This commit is contained in:
Maciej Suminski 2015-12-15 13:39:53 +01:00
parent 6f4be750b5
commit 0caa47e73c
1 changed files with 10 additions and 11 deletions

View File

@ -105,10 +105,9 @@ int MODULE_TOOLS::PlacePad( const TOOL_EVENT& aEvent )
{ {
m_frame->SetToolID( ID_MODEDIT_PAD_TOOL, wxCURSOR_PENCIL, _( "Add pads" ) ); m_frame->SetToolID( ID_MODEDIT_PAD_TOOL, wxCURSOR_PENCIL, _( "Add pads" ) );
MODULE* module = m_board->m_Modules; assert( m_board->m_Modules );
assert( module );
D_PAD* pad = new D_PAD( module ); D_PAD* pad = new D_PAD( m_board->m_Modules );
m_frame->Import_Pad_Settings( pad, false ); // use the global settings for pad m_frame->Import_Pad_Settings( pad, false ); // use the global settings for pad
VECTOR2I cursorPos = m_controls->GetCursorPosition(); VECTOR2I cursorPos = m_controls->GetCursorPosition();
@ -159,11 +158,12 @@ int MODULE_TOOLS::PlacePad( const TOOL_EVENT& aEvent )
else if( evt->IsClick( BUT_LEFT ) ) else if( evt->IsClick( BUT_LEFT ) )
{ {
m_frame->OnModify(); m_frame->OnModify();
m_frame->SaveCopyInUndoList( module, UR_MODEDIT ); m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_MODEDIT );
m_board->m_Status_Pcb = 0; // I have no clue why, but it is done in the legacy view m_board->m_Status_Pcb = 0; // I have no clue why, but it is done in the legacy view
module->SetLastEditTime(); pad->SetParent( m_board->m_Modules );
module->Pads().PushBack( pad ); m_board->m_Modules->SetLastEditTime();
m_board->m_Modules->Pads().PushBack( pad );
// Set the relative pad position // Set the relative pad position
// ( pad position for module orient, 0, and relative to the module position) // ( pad position for module orient, 0, and relative to the module position)
@ -177,7 +177,7 @@ int MODULE_TOOLS::PlacePad( const TOOL_EVENT& aEvent )
m_view->Add( pad ); m_view->Add( pad );
// Start placing next pad // Start placing next pad
pad = new D_PAD( module ); pad = new D_PAD( m_board->m_Modules );
m_frame->Import_Pad_Settings( pad, false ); m_frame->Import_Pad_Settings( pad, false );
pad->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) ); pad->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
preview.Add( pad ); preview.Add( pad );
@ -199,9 +199,8 @@ int MODULE_TOOLS::EnumeratePads( const TOOL_EVENT& aEvent )
{ {
std::list<D_PAD*> pads; std::list<D_PAD*> pads;
std::set<D_PAD*> allPads; std::set<D_PAD*> allPads;
MODULE* module = m_board->m_Modules;
if( !module || !module->Pads() ) if( !m_board->m_Modules || !m_board->m_Modules->Pads() )
return 0; return 0;
GENERAL_COLLECTOR collector; GENERAL_COLLECTOR collector;
@ -215,7 +214,7 @@ int MODULE_TOOLS::EnumeratePads( const TOOL_EVENT& aEvent )
guide.SetIgnoreModulesRefs( true ); guide.SetIgnoreModulesRefs( true );
// Create a set containing all pads (to avoid double adding to the list) // Create a set containing all pads (to avoid double adding to the list)
for( D_PAD* p = module->Pads(); p; p = p->Next() ) for( D_PAD* p = m_board->m_Modules->Pads(); p; p = p->Next() )
allPads.insert( p ); allPads.insert( p );
DIALOG_ENUM_PADS settingsDlg( m_frame ); DIALOG_ENUM_PADS settingsDlg( m_frame );
@ -309,7 +308,7 @@ int MODULE_TOOLS::EnumeratePads( const TOOL_EVENT& aEvent )
{ {
// Accept changes // Accept changes
m_frame->OnModify(); m_frame->OnModify();
m_frame->SaveCopyInUndoList( module, UR_MODEDIT ); m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_MODEDIT );
BOOST_FOREACH( D_PAD* pad, pads ) BOOST_FOREACH( D_PAD* pad, pads )
pad->SetPadName( wxString::Format( wxT( "%s%d" ), padPrefix.c_str(), padNumber++ ) ); pad->SetPadName( wxString::Format( wxT( "%s%d" ), padPrefix.c_str(), padNumber++ ) );