Converted netlist updater to use BOARD_COMMIT

Fixes: lp:1579910
* https://bugs.launchpad.net/kicad/+bug/1579910
This commit is contained in:
Maciej Suminski 2016-09-05 15:38:01 +02:00
parent 3425624510
commit c52a9d850b
4 changed files with 51 additions and 85 deletions

View File

@ -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;
}
@ -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;
}
@ -681,12 +663,9 @@ bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist )
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 );
}

View File

@ -39,10 +39,9 @@ class REPORTER;
class NETLIST;
class COMPONENT;
class MODULE;
class PICKED_ITEMS_LIST;
class PCB_EDIT_FRAME;
#include <class_undoredo_container.h>
#include <board_commit.h>
/**
* 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<MODULE*> m_addedComponents;
std::map<wxString, NETINFO_ITEM*> m_addedNets;
bool m_deleteSinglePadNets;
bool m_deleteUnusedComponents;

View File

@ -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.

View File

@ -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<MODULE*> 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<MODULE*> newFootprints = updater.GetAddedComponents();
// Place the new modules
m_frame->SpreadFootprints( &newFootprints, false, false, m_frame->GetCrossHairPosition() );
if( !newFootprints.empty() )