Store items changed by connectivity algorithm in undo list

Fixes: lp:1828442
* https://bugs.launchpad.net/kicad/+bug/1828442

(cherry picked from commit fb80ee5a0e)
This commit is contained in:
Jon Evans 2019-05-24 21:55:40 -04:00
parent b9898e2bb0
commit 52a9e68093
5 changed files with 57 additions and 16 deletions

View File

@ -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<PCB_DRAW_PANEL_GAL*>( 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<BOARD_ITEM*>( 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<PCB_DRAW_PANEL_GAL*>( frame->GetGalCanvas() );
connectivity->RecalculateRatsnest();
connectivity->ClearDynamicRatsnest();
panel->RedrawRatsnest();
}
if( aSetDirtyBit )
frame->OnModify();

View File

@ -25,6 +25,7 @@
#include <connectivity/connectivity_algo.h>
#include <widgets/progress_reporter.h>
#include <geometry/geometry_utils.h>
#include <board_commit.h>
#include <thread>
#include <mutex>
@ -444,7 +445,7 @@ void CN_CONNECTIVITY_ALGO::Build( const std::vector<BOARD_ITEM*>& aItems )
}
void CN_CONNECTIVITY_ALGO::propagateConnections()
void CN_CONNECTIVITY_ALGO::propagateConnections( BOARD_COMMIT* aCommit )
{
for( const auto& cluster : m_connClusters )
{
@ -471,6 +472,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++;
}
@ -491,10 +495,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 );
}

View File

@ -155,7 +155,8 @@ private:
void searchConnections();
void update();
void propagateConnections();
void propagateConnections( BOARD_COMMIT* aCommit = nullptr );
template <class Container, class BItem>
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<int>& aIslands );
/**

View File

@ -147,9 +147,9 @@ void CONNECTIVITY_DATA::addRatsnestCluster( const std::shared_ptr<CN_CLUSTER>& a
}
void CONNECTIVITY_DATA::RecalculateRatsnest()
void CONNECTIVITY_DATA::RecalculateRatsnest( BOARD_COMMIT* aCommit )
{
m_connAlgo->PropagateNets();
m_connAlgo->PropagateNets( aCommit );
int lastNet = m_connAlgo->NetCount();

View File

@ -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()