Converted netlist updater to use BOARD_COMMIT
Fixes: lp:1579910 * https://bugs.launchpad.net/kicad/+bug/1579910
This commit is contained in:
parent
3425624510
commit
c52a9d850b
|
@ -50,11 +50,11 @@
|
||||||
|
|
||||||
|
|
||||||
BOARD_NETLIST_UPDATER::BOARD_NETLIST_UPDATER( PCB_EDIT_FRAME* aFrame, BOARD* aBoard ) :
|
BOARD_NETLIST_UPDATER::BOARD_NETLIST_UPDATER( PCB_EDIT_FRAME* aFrame, BOARD* aBoard ) :
|
||||||
|
m_commit( aFrame ),
|
||||||
m_frame( aFrame ),
|
m_frame( aFrame ),
|
||||||
m_board( aBoard )
|
m_board( aBoard )
|
||||||
{
|
{
|
||||||
m_reporter = &NULL_REPORTER::GetInstance();
|
m_reporter = &NULL_REPORTER::GetInstance();
|
||||||
m_undoList = new PICKED_ITEMS_LIST;
|
|
||||||
|
|
||||||
m_deleteSinglePadNets = true;
|
m_deleteSinglePadNets = true;
|
||||||
m_deleteUnusedComponents = false;
|
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()
|
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->SetPosition( estimateComponentInsertionPosition( ) );
|
||||||
footprint->SetTimeStamp( GetNewTimeStamp() );
|
footprint->SetTimeStamp( GetNewTimeStamp() );
|
||||||
|
|
||||||
m_board->Add( footprint, ADD_APPEND );
|
|
||||||
m_addedComponents.push_back( footprint );
|
m_addedComponents.push_back( footprint );
|
||||||
|
m_commit.Add( footprint );
|
||||||
pushUndo( footprint, UR_NEW );
|
|
||||||
|
|
||||||
return footprint;
|
return footprint;
|
||||||
}
|
}
|
||||||
|
@ -205,7 +186,9 @@ MODULE* BOARD_NETLIST_UPDATER::replaceComponent( NETLIST& aNetlist, MODULE* aPcb
|
||||||
if( !m_isDryRun )
|
if( !m_isDryRun )
|
||||||
{
|
{
|
||||||
wxASSERT( aPcbComponent != NULL );
|
wxASSERT( aPcbComponent != NULL );
|
||||||
|
|
||||||
MODULE* newFootprint = new MODULE( *aNewComponent->GetModule() );
|
MODULE* newFootprint = new MODULE( *aNewComponent->GetModule() );
|
||||||
|
newFootprint->SetParent( m_board );
|
||||||
|
|
||||||
if( aNetlist.IsFindByTimeStamp() )
|
if( aNetlist.IsFindByTimeStamp() )
|
||||||
newFootprint->SetReference( aPcbComponent->GetReference() );
|
newFootprint->SetReference( aPcbComponent->GetReference() );
|
||||||
|
@ -213,11 +196,8 @@ MODULE* BOARD_NETLIST_UPDATER::replaceComponent( NETLIST& aNetlist, MODULE* aPcb
|
||||||
newFootprint->SetPath( aPcbComponent->GetPath() );
|
newFootprint->SetPath( aPcbComponent->GetPath() );
|
||||||
|
|
||||||
aPcbComponent->CopyNetlistSettings( newFootprint, false );
|
aPcbComponent->CopyNetlistSettings( newFootprint, false );
|
||||||
m_board->Remove( aPcbComponent );
|
m_commit.Remove( aPcbComponent );
|
||||||
m_board->Add( newFootprint, ADD_APPEND );
|
m_commit.Add( newFootprint );
|
||||||
|
|
||||||
pushUndo( aPcbComponent, UR_DELETED );
|
|
||||||
pushUndo( newFootprint, UR_NEW );
|
|
||||||
|
|
||||||
return newFootprint;
|
return newFootprint;
|
||||||
}
|
}
|
||||||
|
@ -314,7 +294,7 @@ bool BOARD_NETLIST_UPDATER::updateComponentParameters( MODULE* aPcbComponent, CO
|
||||||
|
|
||||||
m_reporter->Report( msg, REPORTER::RPT_INFO );
|
m_reporter->Report( msg, REPORTER::RPT_INFO );
|
||||||
|
|
||||||
if ( !m_isDryRun )
|
if( !m_isDryRun )
|
||||||
{
|
{
|
||||||
changed = true;
|
changed = true;
|
||||||
aPcbComponent->SetPath( aNewComponent->GetTimeStamp() );
|
aPcbComponent->SetPath( aNewComponent->GetTimeStamp() );
|
||||||
|
@ -322,7 +302,7 @@ bool BOARD_NETLIST_UPDATER::updateComponentParameters( MODULE* aPcbComponent, CO
|
||||||
}
|
}
|
||||||
|
|
||||||
if( changed )
|
if( changed )
|
||||||
pushUndo( aPcbComponent, UR_CHANGED, copy );
|
m_commit.Modified( aPcbComponent, copy );
|
||||||
else
|
else
|
||||||
delete copy;
|
delete copy;
|
||||||
|
|
||||||
|
@ -368,21 +348,30 @@ bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE* aPcbComponent
|
||||||
{
|
{
|
||||||
if( net.GetNetName() != pad->GetNetname() )
|
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
|
// It is a new net, we have to add it
|
||||||
if( !m_isDryRun )
|
if( !m_isDryRun )
|
||||||
{
|
{
|
||||||
changed = true;
|
changed = true;
|
||||||
netinfo = new NETINFO_ITEM( m_board, net.GetNetName() );
|
netinfo = new NETINFO_ITEM( m_board, netName );
|
||||||
m_board->AppendNet( netinfo );
|
m_commit.Add( netinfo );
|
||||||
pushUndo( netinfo, UR_NEW );
|
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 );
|
m_reporter->Report( msg, REPORTER::RPT_ACTION );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,13 +381,13 @@ bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE* aPcbComponent
|
||||||
GetChars( aPcbComponent->GetReference() ),
|
GetChars( aPcbComponent->GetReference() ),
|
||||||
GetChars( pad->GetPadName() ),
|
GetChars( pad->GetPadName() ),
|
||||||
GetChars( pad->GetNetname() ),
|
GetChars( pad->GetNetname() ),
|
||||||
GetChars( net.GetNetName() ) );
|
GetChars( netName ) );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
msg.Printf( _( "Connect component %s pin %s to net %s.\n"),
|
msg.Printf( _( "Connect component %s pin %s to net %s.\n"),
|
||||||
GetChars( aPcbComponent->GetReference() ),
|
GetChars( aPcbComponent->GetReference() ),
|
||||||
GetChars( pad->GetPadName() ),
|
GetChars( pad->GetPadName() ),
|
||||||
GetChars( net.GetNetName() ) );
|
GetChars( netName ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
m_reporter->Report( msg, REPORTER::RPT_ACTION );
|
m_reporter->Report( msg, REPORTER::RPT_ACTION );
|
||||||
|
@ -409,21 +398,20 @@ bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE* aPcbComponent
|
||||||
GetChars( aPcbComponent->GetPath() ),
|
GetChars( aPcbComponent->GetPath() ),
|
||||||
GetChars( pad->GetPadName() ),
|
GetChars( pad->GetPadName() ),
|
||||||
GetChars( pad->GetNetname() ),
|
GetChars( pad->GetNetname() ),
|
||||||
GetChars( net.GetNetName() ) );
|
GetChars( netName ) );
|
||||||
|
|
||||||
m_reporter->Report( msg, REPORTER::RPT_INFO );
|
m_reporter->Report( msg, REPORTER::RPT_INFO );
|
||||||
|
|
||||||
if( !m_isDryRun )
|
if( !m_isDryRun )
|
||||||
{
|
{
|
||||||
changed = true;
|
changed = true;
|
||||||
pad->SetNetCode( netinfo->GetNet() );
|
pad->SetNet( netinfo );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( changed )
|
if( changed )
|
||||||
pushUndo( aPcbComponent, UR_CHANGED, copy );
|
m_commit.Modified( aPcbComponent, copy );
|
||||||
else
|
else
|
||||||
delete copy;
|
delete copy;
|
||||||
|
|
||||||
|
@ -461,10 +449,7 @@ bool BOARD_NETLIST_UPDATER::deleteUnusedComponents( NETLIST& aNetlist )
|
||||||
m_reporter->Report( msg, REPORTER::RPT_INFO );
|
m_reporter->Report( msg, REPORTER::RPT_INFO );
|
||||||
|
|
||||||
if( !m_isDryRun )
|
if( !m_isDryRun )
|
||||||
{
|
m_commit.Remove( module );
|
||||||
pushUndo( module, UR_DELETED );
|
|
||||||
m_board->Remove( module );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -533,7 +518,6 @@ bool BOARD_NETLIST_UPDATER::deleteSinglePadNets()
|
||||||
GetChars( previouspad->GetPadName() ) );
|
GetChars( previouspad->GetPadName() ) );
|
||||||
m_reporter->Report( msg, REPORTER::RPT_ACTION );
|
m_reporter->Report( msg, REPORTER::RPT_ACTION );
|
||||||
|
|
||||||
//pushUndo( previouspad, UR_CHANGED );
|
|
||||||
previouspad->SetNetCode( NETINFO_LIST::UNCONNECTED );
|
previouspad->SetNetCode( NETINFO_LIST::UNCONNECTED );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -551,10 +535,8 @@ bool BOARD_NETLIST_UPDATER::deleteSinglePadNets()
|
||||||
|
|
||||||
// Examine last pad
|
// Examine last pad
|
||||||
if( pad && count == 1 )
|
if( pad && count == 1 )
|
||||||
{
|
|
||||||
//pushUndo( pad, UR_CHANGED );
|
|
||||||
pad->SetNetCode( NETINFO_LIST::UNCONNECTED );
|
pad->SetNetCode( NETINFO_LIST::UNCONNECTED );
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -679,14 +661,11 @@ bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist )
|
||||||
if( m_deleteSinglePadNets )
|
if( m_deleteSinglePadNets )
|
||||||
deleteSinglePadNets();
|
deleteSinglePadNets();
|
||||||
|
|
||||||
if ( !m_isDryRun )
|
if( !m_isDryRun )
|
||||||
{
|
{
|
||||||
m_frame->SaveCopyInUndoList( *m_undoList, UR_UNSPECIFIED, wxPoint( 0, 0 ) );
|
m_commit.Push( _( "Update netlist" ) );
|
||||||
m_frame->OnModify();
|
m_frame->Compile_Ratsnest( NULL, false );
|
||||||
|
|
||||||
m_frame->Compile_Ratsnest( NULL, true );
|
|
||||||
m_board->GetRatsnest()->ProcessBoard();
|
m_board->GetRatsnest()->ProcessBoard();
|
||||||
|
|
||||||
testConnectivity( aNetlist );
|
testConnectivity( aNetlist );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,10 +39,9 @@ class REPORTER;
|
||||||
class NETLIST;
|
class NETLIST;
|
||||||
class COMPONENT;
|
class COMPONENT;
|
||||||
class MODULE;
|
class MODULE;
|
||||||
class PICKED_ITEMS_LIST;
|
|
||||||
class PCB_EDIT_FRAME;
|
class PCB_EDIT_FRAME;
|
||||||
|
|
||||||
#include <class_undoredo_container.h>
|
#include <board_commit.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class BOARD_NETLIST_UPDATER
|
* Class BOARD_NETLIST_UPDATER
|
||||||
|
@ -130,9 +129,6 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void pushUndo( BOARD_ITEM* aItem, UNDO_REDO_T aCommandType, BOARD_ITEM* aCopy = NULL );
|
|
||||||
|
|
||||||
wxPoint estimateComponentInsertionPosition();
|
wxPoint estimateComponentInsertionPosition();
|
||||||
MODULE* addNewComponent( COMPONENT* aComponent );
|
MODULE* addNewComponent( COMPONENT* aComponent );
|
||||||
MODULE* replaceComponent( NETLIST& aNetlist, MODULE* aPcbComponent, COMPONENT* aNewComponent );
|
MODULE* replaceComponent( NETLIST& aNetlist, MODULE* aPcbComponent, COMPONENT* aNewComponent );
|
||||||
|
@ -142,12 +138,13 @@ private:
|
||||||
bool deleteSinglePadNets();
|
bool deleteSinglePadNets();
|
||||||
bool testConnectivity( NETLIST& aNetlist );
|
bool testConnectivity( NETLIST& aNetlist );
|
||||||
|
|
||||||
PICKED_ITEMS_LIST* m_undoList;
|
BOARD_COMMIT m_commit;
|
||||||
PCB_EDIT_FRAME* m_frame;
|
PCB_EDIT_FRAME* m_frame;
|
||||||
BOARD* m_board;
|
BOARD* m_board;
|
||||||
REPORTER* m_reporter;
|
REPORTER* m_reporter;
|
||||||
|
|
||||||
std::vector<MODULE*> m_addedComponents;
|
std::vector<MODULE*> m_addedComponents;
|
||||||
|
std::map<wxString, NETINFO_ITEM*> m_addedNets;
|
||||||
|
|
||||||
bool m_deleteSinglePadNets;
|
bool m_deleteSinglePadNets;
|
||||||
bool m_deleteUnusedComponents;
|
bool m_deleteUnusedComponents;
|
||||||
|
|
|
@ -92,6 +92,16 @@ public:
|
||||||
return m_netinfo;
|
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
|
* Function GetNetCode
|
||||||
* @return int - the net code.
|
* @return int - the net code.
|
||||||
|
|
|
@ -43,12 +43,6 @@ void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun )
|
||||||
|
|
||||||
if( !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
|
// Clear selection, just in case a selected item has to be removed
|
||||||
toolManager->RunAction( COMMON_ACTIONS::selectionClear, true );
|
toolManager->RunAction( COMMON_ACTIONS::selectionClear, true );
|
||||||
|
@ -85,28 +79,14 @@ void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun )
|
||||||
if( aDryRun )
|
if( aDryRun )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::vector<MODULE*> newFootprints = updater.GetAddedComponents();
|
|
||||||
|
|
||||||
m_frame->OnModify();
|
|
||||||
m_frame->SetCurItem( NULL );
|
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 );
|
m_frame->SetMsgPanel( board );
|
||||||
|
|
||||||
if( m_frame->IsGalCanvasActive() )
|
if( m_frame->IsGalCanvasActive() )
|
||||||
{
|
{
|
||||||
|
std::vector<MODULE*> newFootprints = updater.GetAddedComponents();
|
||||||
|
|
||||||
|
// Place the new modules
|
||||||
m_frame->SpreadFootprints( &newFootprints, false, false, m_frame->GetCrossHairPosition() );
|
m_frame->SpreadFootprints( &newFootprints, false, false, m_frame->GetCrossHairPosition() );
|
||||||
|
|
||||||
if( !newFootprints.empty() )
|
if( !newFootprints.empty() )
|
||||||
|
@ -122,7 +102,7 @@ void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun )
|
||||||
|
|
||||||
m_btnPerformUpdate->Enable( false );
|
m_btnPerformUpdate->Enable( false );
|
||||||
m_btnPerformUpdate->SetLabel( _( "Update complete" ) );
|
m_btnPerformUpdate->SetLabel( _( "Update complete" ) );
|
||||||
m_btnCancel->SetLabel( _("Close") );
|
m_btnCancel->SetLabel( _( "Close" ) );
|
||||||
m_btnCancel->SetFocus();
|
m_btnCancel->SetFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue