From fb80ee5a0e2bdeacf354b9c4ad00891922e2a075 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Fri, 24 May 2019 21:55:40 -0400 Subject: [PATCH] Store items changed by connectivity algorithm in undo list Fixes: lp:1828442 * https://bugs.launchpad.net/kicad/+bug/1828442 --- pcbnew/board_commit.cpp | 45 +++++++++++++++++++---- pcbnew/connectivity/connectivity_algo.cpp | 10 +++-- pcbnew/connectivity/connectivity_algo.h | 10 ++++- pcbnew/connectivity/connectivity_data.cpp | 4 +- pcbnew/connectivity/connectivity_data.h | 4 +- 5 files changed, 57 insertions(+), 16 deletions(-) diff --git a/pcbnew/board_commit.cpp b/pcbnew/board_commit.cpp index 4f3d03e75d..69bf406cc1 100644 --- a/pcbnew/board_commit.cpp +++ b/pcbnew/board_commit.cpp @@ -256,20 +256,49 @@ void BOARD_COMMIT::Push( const wxString& aMessage, bool aCreateUndoEntry, bool a if( itemsToDeselect.size() > 0 ) m_toolMgr->RunAction( PCB_ACTIONS::unselectItems, true, &itemsToDeselect ); + if ( !m_editModules ) + { + size_t num_changes = m_changes.size(); + + auto panel = static_cast( frame->GetGalCanvas() ); + connectivity->RecalculateRatsnest( this ); + connectivity->ClearDynamicRatsnest(); + panel->RedrawRatsnest(); + + if( m_changes.size() > num_changes ) + { + for( size_t i = num_changes; i < m_changes.size(); ++i ) + { + COMMIT_LINE& ent = m_changes[i]; + + // This should only be modifications from the connectivity algo + wxASSERT( ( ent.m_type & CHT_TYPE ) == CHT_MODIFY ); + + auto boardItem = static_cast( ent.m_item ); + + if( aCreateUndoEntry ) + { + ITEM_PICKER itemWrapper( boardItem, UR_CHANGED ); + wxASSERT( ent.m_copy ); + itemWrapper.SetLink( ent.m_copy ); + undoList.PushItem( itemWrapper ); + } + else + { + delete ent.m_copy; + } + + view->Update( boardItem ); + } + } + } + if( !m_editModules && aCreateUndoEntry ) frame->SaveCopyInUndoList( undoList, UR_UNSPECIFIED ); if( TOOL_MANAGER* toolMgr = frame->GetToolManager() ) toolMgr->PostEvent( { TC_MESSAGE, TA_MODEL_CHANGE, AS_GLOBAL } ); - if ( !m_editModules ) - { - auto panel = static_cast( frame->GetGalCanvas() ); - connectivity->RecalculateRatsnest(); - connectivity->ClearDynamicRatsnest(); - panel->RedrawRatsnest(); - } - if( aSetDirtyBit ) frame->OnModify(); diff --git a/pcbnew/connectivity/connectivity_algo.cpp b/pcbnew/connectivity/connectivity_algo.cpp index 003ae835f5..93f51ccd9d 100644 --- a/pcbnew/connectivity/connectivity_algo.cpp +++ b/pcbnew/connectivity/connectivity_algo.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -449,7 +450,7 @@ void CN_CONNECTIVITY_ALGO::Build( const std::vector& aItems ) } -void CN_CONNECTIVITY_ALGO::propagateConnections() +void CN_CONNECTIVITY_ALGO::propagateConnections( BOARD_COMMIT* aCommit ) { for( const auto& cluster : m_connClusters ) { @@ -476,6 +477,9 @@ void CN_CONNECTIVITY_ALGO::propagateConnections() MarkNetAsDirty( item->Parent()->GetNetCode() ); MarkNetAsDirty( cluster->OriginNet() ); + if( aCommit ) + aCommit->Modify( item->Parent() ); + item->Parent()->SetNetCode( cluster->OriginNet() ); n_changed++; } @@ -496,10 +500,10 @@ void CN_CONNECTIVITY_ALGO::propagateConnections() } -void CN_CONNECTIVITY_ALGO::PropagateNets() +void CN_CONNECTIVITY_ALGO::PropagateNets( BOARD_COMMIT* aCommit ) { m_connClusters = SearchClusters( CSM_PROPAGATE ); - propagateConnections(); + propagateConnections( aCommit ); } diff --git a/pcbnew/connectivity/connectivity_algo.h b/pcbnew/connectivity/connectivity_algo.h index 4c6433caec..80c59603cc 100644 --- a/pcbnew/connectivity/connectivity_algo.h +++ b/pcbnew/connectivity/connectivity_algo.h @@ -155,7 +155,8 @@ private: void searchConnections(); void update(); - void propagateConnections(); + + void propagateConnections( BOARD_COMMIT* aCommit = nullptr ); template void add( Container& c, BItem brditem ) @@ -223,7 +224,12 @@ public: const CLUSTERS SearchClusters( CLUSTER_SEARCH_MODE aMode, const KICAD_T aTypes[], int aSingleNet ); const CLUSTERS SearchClusters( CLUSTER_SEARCH_MODE aMode ); - void PropagateNets(); + /** + * Propagates nets from pads to other items in clusters + * @param aCommit is used to store undo information for items modified by the call + */ + void PropagateNets( BOARD_COMMIT* aCommit = nullptr ); + void FindIsolatedCopperIslands( ZONE_CONTAINER* aZone, std::vector& aIslands ); /** diff --git a/pcbnew/connectivity/connectivity_data.cpp b/pcbnew/connectivity/connectivity_data.cpp index 1a61f0a097..90222cb5e4 100644 --- a/pcbnew/connectivity/connectivity_data.cpp +++ b/pcbnew/connectivity/connectivity_data.cpp @@ -147,9 +147,9 @@ void CONNECTIVITY_DATA::addRatsnestCluster( const std::shared_ptr& a } -void CONNECTIVITY_DATA::RecalculateRatsnest() +void CONNECTIVITY_DATA::RecalculateRatsnest( BOARD_COMMIT* aCommit ) { - m_connAlgo->PropagateNets(); + m_connAlgo->PropagateNets( aCommit ); int lastNet = m_connAlgo->NetCount(); diff --git a/pcbnew/connectivity/connectivity_data.h b/pcbnew/connectivity/connectivity_data.h index dca307904e..2f69051537 100644 --- a/pcbnew/connectivity/connectivity_data.h +++ b/pcbnew/connectivity/connectivity_data.h @@ -41,6 +41,7 @@ class CN_CLUSTER; class CN_CONNECTIVITY_ALGO; class CN_EDGE; class BOARD; +class BOARD_COMMIT; class BOARD_CONNECTED_ITEM; class BOARD_ITEM; class ZONE_CONTAINER; @@ -157,8 +158,9 @@ public: /** * Function RecalculateRatsnest() * Updates the ratsnest for the board. + * @param aCommit is used to save the undo state of items modified by this call */ - void RecalculateRatsnest(); + void RecalculateRatsnest( BOARD_COMMIT* aCommit = nullptr ); /** * Function GetUnconnectedCount()