From c52a9d850b652fcb652335f53cc6a9ec7fde7456 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 5 Sep 2016 15:38:01 +0200 Subject: [PATCH] Converted netlist updater to use BOARD_COMMIT Fixes: lp:1579910 * https://bugs.launchpad.net/kicad/+bug/1579910 --- pcbnew/board_netlist_updater.cpp | 89 +++++++++++----------------- pcbnew/board_netlist_updater.h | 9 +-- pcbnew/class_board_connected_item.h | 10 ++++ pcbnew/dialogs/dialog_update_pcb.cpp | 28 ++------- 4 files changed, 51 insertions(+), 85 deletions(-) diff --git a/pcbnew/board_netlist_updater.cpp b/pcbnew/board_netlist_updater.cpp index d0dc086986..7088798302 100644 --- a/pcbnew/board_netlist_updater.cpp +++ b/pcbnew/board_netlist_updater.cpp @@ -50,11 +50,11 @@ BOARD_NETLIST_UPDATER::BOARD_NETLIST_UPDATER( PCB_EDIT_FRAME* aFrame, BOARD* aBoard ) : + m_commit( aFrame ), m_frame( aFrame ), m_board( aBoard ) { m_reporter = &NULL_REPORTER::GetInstance(); - m_undoList = new PICKED_ITEMS_LIST; m_deleteSinglePadNets = true; m_deleteUnusedComponents = false; @@ -69,23 +69,6 @@ BOARD_NETLIST_UPDATER::BOARD_NETLIST_UPDATER( PCB_EDIT_FRAME* aFrame, BOARD* aBo BOARD_NETLIST_UPDATER::~BOARD_NETLIST_UPDATER() { - delete m_undoList; -} - - -void BOARD_NETLIST_UPDATER::pushUndo( BOARD_ITEM* aItem, UNDO_REDO_T aCommandType, BOARD_ITEM* aCopy ) -{ - ITEM_PICKER picker( aItem, aCommandType ); - - if( aCommandType == UR_CHANGED ) - { - if( m_undoList->FindItem( aItem ) >= 0 ) // add only once - return; - - picker.SetLink( aCopy ? aCopy : aItem->Clone() ); - } - - m_undoList->PushItem( picker ); } @@ -143,10 +126,8 @@ MODULE* BOARD_NETLIST_UPDATER::addNewComponent( COMPONENT* aComponent ) footprint->SetPosition( estimateComponentInsertionPosition( ) ); footprint->SetTimeStamp( GetNewTimeStamp() ); - m_board->Add( footprint, ADD_APPEND ); m_addedComponents.push_back( footprint ); - - pushUndo( footprint, UR_NEW ); + m_commit.Add( footprint ); return footprint; } @@ -205,7 +186,9 @@ MODULE* BOARD_NETLIST_UPDATER::replaceComponent( NETLIST& aNetlist, MODULE* aPcb if( !m_isDryRun ) { wxASSERT( aPcbComponent != NULL ); + MODULE* newFootprint = new MODULE( *aNewComponent->GetModule() ); + newFootprint->SetParent( m_board ); if( aNetlist.IsFindByTimeStamp() ) newFootprint->SetReference( aPcbComponent->GetReference() ); @@ -213,11 +196,8 @@ MODULE* BOARD_NETLIST_UPDATER::replaceComponent( NETLIST& aNetlist, MODULE* aPcb newFootprint->SetPath( aPcbComponent->GetPath() ); aPcbComponent->CopyNetlistSettings( newFootprint, false ); - m_board->Remove( aPcbComponent ); - m_board->Add( newFootprint, ADD_APPEND ); - - pushUndo( aPcbComponent, UR_DELETED ); - pushUndo( newFootprint, UR_NEW ); + m_commit.Remove( aPcbComponent ); + m_commit.Add( newFootprint ); return newFootprint; } @@ -314,7 +294,7 @@ bool BOARD_NETLIST_UPDATER::updateComponentParameters( MODULE* aPcbComponent, CO m_reporter->Report( msg, REPORTER::RPT_INFO ); - if ( !m_isDryRun ) + if( !m_isDryRun ) { changed = true; aPcbComponent->SetPath( aNewComponent->GetTimeStamp() ); @@ -322,7 +302,7 @@ bool BOARD_NETLIST_UPDATER::updateComponentParameters( MODULE* aPcbComponent, CO } if( changed ) - pushUndo( aPcbComponent, UR_CHANGED, copy ); + m_commit.Modified( aPcbComponent, copy ); else delete copy; @@ -368,21 +348,30 @@ bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE* aPcbComponent { if( net.GetNetName() != pad->GetNetname() ) { - NETINFO_ITEM* netinfo = m_board->FindNet( net.GetNetName() ); + const wxString& netName = net.GetNetName(); + NETINFO_ITEM* netinfo = m_board->FindNet( netName ); - if( netinfo == NULL ) + if( netinfo == nullptr ) + { + // It might be a new net that has not been added to the board yet + auto netIt = m_addedNets.find( netName ); + + if( netIt != m_addedNets.end() ) + netinfo = netIt->second; + } + + if( netinfo == nullptr ) { // It is a new net, we have to add it if( !m_isDryRun ) { changed = true; - netinfo = new NETINFO_ITEM( m_board, net.GetNetName() ); - m_board->AppendNet( netinfo ); - pushUndo( netinfo, UR_NEW ); + netinfo = new NETINFO_ITEM( m_board, netName ); + m_commit.Add( netinfo ); + m_addedNets[netName] = netinfo; } - msg.Printf( _( "Add net %s.\n" ), GetChars( net.GetNetName() ) ); - + msg.Printf( _( "Add net %s.\n" ), GetChars( netName ) ); m_reporter->Report( msg, REPORTER::RPT_ACTION ); } @@ -392,13 +381,13 @@ bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE* aPcbComponent GetChars( aPcbComponent->GetReference() ), GetChars( pad->GetPadName() ), GetChars( pad->GetNetname() ), - GetChars( net.GetNetName() ) ); + GetChars( netName ) ); } else { msg.Printf( _( "Connect component %s pin %s to net %s.\n"), GetChars( aPcbComponent->GetReference() ), GetChars( pad->GetPadName() ), - GetChars( net.GetNetName() ) ); + GetChars( netName ) ); } m_reporter->Report( msg, REPORTER::RPT_ACTION ); @@ -409,21 +398,20 @@ bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE* aPcbComponent GetChars( aPcbComponent->GetPath() ), GetChars( pad->GetPadName() ), GetChars( pad->GetNetname() ), - GetChars( net.GetNetName() ) ); - + GetChars( netName ) ); m_reporter->Report( msg, REPORTER::RPT_INFO ); if( !m_isDryRun ) { changed = true; - pad->SetNetCode( netinfo->GetNet() ); + pad->SetNet( netinfo ); } } } } if( changed ) - pushUndo( aPcbComponent, UR_CHANGED, copy ); + m_commit.Modified( aPcbComponent, copy ); else delete copy; @@ -461,10 +449,7 @@ bool BOARD_NETLIST_UPDATER::deleteUnusedComponents( NETLIST& aNetlist ) m_reporter->Report( msg, REPORTER::RPT_INFO ); if( !m_isDryRun ) - { - pushUndo( module, UR_DELETED ); - m_board->Remove( module ); - } + m_commit.Remove( module ); } } @@ -533,7 +518,6 @@ bool BOARD_NETLIST_UPDATER::deleteSinglePadNets() GetChars( previouspad->GetPadName() ) ); m_reporter->Report( msg, REPORTER::RPT_ACTION ); - //pushUndo( previouspad, UR_CHANGED ); previouspad->SetNetCode( NETINFO_LIST::UNCONNECTED ); } } @@ -551,10 +535,8 @@ bool BOARD_NETLIST_UPDATER::deleteSinglePadNets() // Examine last pad if( pad && count == 1 ) - { - //pushUndo( pad, UR_CHANGED ); pad->SetNetCode( NETINFO_LIST::UNCONNECTED ); - } + return true; } @@ -679,14 +661,11 @@ bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist ) if( m_deleteSinglePadNets ) deleteSinglePadNets(); - if ( !m_isDryRun ) + if( !m_isDryRun ) { - m_frame->SaveCopyInUndoList( *m_undoList, UR_UNSPECIFIED, wxPoint( 0, 0 ) ); - m_frame->OnModify(); - - m_frame->Compile_Ratsnest( NULL, true ); + m_commit.Push( _( "Update netlist" ) ); + m_frame->Compile_Ratsnest( NULL, false ); m_board->GetRatsnest()->ProcessBoard(); - testConnectivity( aNetlist ); } diff --git a/pcbnew/board_netlist_updater.h b/pcbnew/board_netlist_updater.h index cf3cba506f..256722ddc6 100644 --- a/pcbnew/board_netlist_updater.h +++ b/pcbnew/board_netlist_updater.h @@ -39,10 +39,9 @@ class REPORTER; class NETLIST; class COMPONENT; class MODULE; -class PICKED_ITEMS_LIST; class PCB_EDIT_FRAME; -#include +#include /** * Class BOARD_NETLIST_UPDATER @@ -130,9 +129,6 @@ public: } private: - - void pushUndo( BOARD_ITEM* aItem, UNDO_REDO_T aCommandType, BOARD_ITEM* aCopy = NULL ); - wxPoint estimateComponentInsertionPosition(); MODULE* addNewComponent( COMPONENT* aComponent ); MODULE* replaceComponent( NETLIST& aNetlist, MODULE* aPcbComponent, COMPONENT* aNewComponent ); @@ -142,12 +138,13 @@ private: bool deleteSinglePadNets(); bool testConnectivity( NETLIST& aNetlist ); - PICKED_ITEMS_LIST* m_undoList; + BOARD_COMMIT m_commit; PCB_EDIT_FRAME* m_frame; BOARD* m_board; REPORTER* m_reporter; std::vector m_addedComponents; + std::map m_addedNets; bool m_deleteSinglePadNets; bool m_deleteUnusedComponents; diff --git a/pcbnew/class_board_connected_item.h b/pcbnew/class_board_connected_item.h index cd694577ef..6687f0ab3a 100644 --- a/pcbnew/class_board_connected_item.h +++ b/pcbnew/class_board_connected_item.h @@ -92,6 +92,16 @@ public: return m_netinfo; } + /** + * Function SetNet + * Sets a NET_INFO object for the item. + */ + void SetNet( NETINFO_ITEM* aNetInfo ) + { + assert( aNetInfo->GetBoard() == GetBoard() ); + m_netinfo = aNetInfo; + } + /** * Function GetNetCode * @return int - the net code. diff --git a/pcbnew/dialogs/dialog_update_pcb.cpp b/pcbnew/dialogs/dialog_update_pcb.cpp index 18f08a16f7..39f7cbe458 100644 --- a/pcbnew/dialogs/dialog_update_pcb.cpp +++ b/pcbnew/dialogs/dialog_update_pcb.cpp @@ -43,12 +43,6 @@ void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun ) if( !aDryRun ) { - // Remove old modules - for( MODULE* module = board->m_Modules; module; module = module->Next() ) - { - module->RunOnChildren( std::bind( &KIGFX::VIEW::Remove, view, _1 ) ); - view->Remove( module ); - } // Clear selection, just in case a selected item has to be removed toolManager->RunAction( COMMON_ACTIONS::selectionClear, true ); @@ -85,28 +79,14 @@ void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun ) if( aDryRun ) return; - std::vector newFootprints = updater.GetAddedComponents(); - - m_frame->OnModify(); m_frame->SetCurItem( NULL ); - - // Reload modules - for( MODULE* module = board->m_Modules; module; module = module->Next() ) - { - module->RunOnChildren( std::bind( &KIGFX::VIEW::Add, view, _1 ) ); - view->Add( module ); - module->ViewUpdate(); - } - - // Rebuild the board connectivity: - if( m_frame->IsGalCanvasActive() ) - board->GetRatsnest()->ProcessBoard(); - - m_frame->Compile_Ratsnest( NULL, true ); m_frame->SetMsgPanel( board ); if( m_frame->IsGalCanvasActive() ) { + std::vector newFootprints = updater.GetAddedComponents(); + + // Place the new modules m_frame->SpreadFootprints( &newFootprints, false, false, m_frame->GetCrossHairPosition() ); if( !newFootprints.empty() ) @@ -122,7 +102,7 @@ void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun ) m_btnPerformUpdate->Enable( false ); m_btnPerformUpdate->SetLabel( _( "Update complete" ) ); - m_btnCancel->SetLabel( _("Close") ); + m_btnCancel->SetLabel( _( "Close" ) ); m_btnCancel->SetFocus(); }