Code formatting (BOARD_NETLIST_UPDATER)

This commit is contained in:
Maciej Suminski 2016-09-02 15:53:51 +02:00
parent 029e275aa0
commit 267f01fa69
3 changed files with 141 additions and 145 deletions

View File

@ -49,35 +49,37 @@
#include <wxPcbStruct.h>
BOARD_NETLIST_UPDATER::BOARD_NETLIST_UPDATER ( PCB_EDIT_FRAME *aFrame, BOARD *aBoard ) :
m_frame ( aFrame ),
BOARD_NETLIST_UPDATER::BOARD_NETLIST_UPDATER( PCB_EDIT_FRAME* aFrame, BOARD* aBoard ) :
m_frame( aFrame ),
m_board( aBoard )
{
m_reporter = &NULL_REPORTER::GetInstance();
m_undoList = new PICKED_ITEMS_LIST;
m_deleteSinglePadNets = true;
m_deleteUnusedComponents = false;
m_isDryRun = false;
m_replaceFootprints = true;
m_lookupByTimestamp = false;
m_deleteSinglePadNets = true;
m_deleteUnusedComponents = false;
m_isDryRun = false;
m_replaceFootprints = true;
m_lookupByTimestamp = false;
m_warningCount = 0;
m_errorCount = 0;
m_warningCount = 0;
m_errorCount = 0;
}
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
if( m_undoList->FindItem( aItem ) >= 0 ) // add only once
return;
picker.SetLink( aCopy ? aCopy : aItem->Clone() );
@ -86,6 +88,7 @@ void BOARD_NETLIST_UPDATER::pushUndo( BOARD_ITEM* aItem, UNDO_REDO_T aCommandTyp
m_undoList->PushItem( picker );
}
wxPoint BOARD_NETLIST_UPDATER::estimateComponentInsertionPosition()
{
wxPoint bestPosition;
@ -124,20 +127,18 @@ MODULE* BOARD_NETLIST_UPDATER::addNewComponent( COMPONENT* aComponent )
GetChars( aComponent->GetReference() ),
GetChars( aComponent->GetTimeStamp() ),
GetChars( aComponent->GetFPID().Format() ) );
m_reporter->Report( msg, REPORTER::RPT_INFO );
msg.Printf( _( "Add component %s, footprint: %s.\n" ),
GetChars( aComponent->GetReference() ),
GetChars( aComponent->GetFPID().Format() ) );
m_reporter->Report( msg, REPORTER::RPT_ACTION );
if( !m_isDryRun )
{
// Owned by NETLIST, can only copy it.
MODULE *footprint = new MODULE( *aComponent->GetModule() );
MODULE* footprint = new MODULE( *aComponent->GetModule() );
footprint->SetParent( m_board );
footprint->SetPosition( estimateComponentInsertionPosition( ) );
footprint->SetTimeStamp( GetNewTimeStamp() );
@ -165,23 +166,22 @@ MODULE* BOARD_NETLIST_UPDATER::addNewComponent( COMPONENT* aComponent )
GetChars( aComponent->GetFPID().Format() ) );
m_reporter->Report( msg, REPORTER::RPT_INFO );
m_errorCount ++;
++m_errorCount;
}
return NULL;
}
MODULE* BOARD_NETLIST_UPDATER::replaceComponent( NETLIST& aNetlist, MODULE *aPcbComponent, COMPONENT* aNewComponent )
MODULE* BOARD_NETLIST_UPDATER::replaceComponent( NETLIST& aNetlist, MODULE* aPcbComponent, COMPONENT* aNewComponent )
{
wxString msg;
if( !m_replaceFootprints )
return NULL;
// Test if the footprint has not changed
if( aNewComponent->GetFPID().empty() ||
aPcbComponent->GetFPID() == aNewComponent->GetFPID() )
// Test if the footprint has not changed
if( aNewComponent->GetFPID().empty() || aPcbComponent->GetFPID() == aNewComponent->GetFPID() )
return NULL;
if( aNewComponent->GetModule() != NULL )
@ -221,8 +221,9 @@ MODULE* BOARD_NETLIST_UPDATER::replaceComponent( NETLIST& aNetlist, MODULE *aPcb
return newFootprint;
}
} else {
}
else
{
msg.Printf( _( "Cannot change component %s footprint due to missing "
"footprint %s.\n" ),
GetChars( aPcbComponent->GetReference() ),
@ -238,13 +239,14 @@ MODULE* BOARD_NETLIST_UPDATER::replaceComponent( NETLIST& aNetlist, MODULE *aPcb
m_reporter->Report( msg, REPORTER::RPT_INFO );
m_errorCount ++;
++m_errorCount;
}
return NULL;
}
bool BOARD_NETLIST_UPDATER::updateComponentParameters( MODULE *aPcbComponent, COMPONENT* aNewComponent )
bool BOARD_NETLIST_UPDATER::updateComponentParameters( MODULE* aPcbComponent, COMPONENT* aNewComponent )
{
wxString msg;
@ -292,9 +294,10 @@ bool BOARD_NETLIST_UPDATER::updateComponentParameters( MODULE *aPcbComponent, CO
GetChars( aPcbComponent->GetPath() ),
GetChars( aPcbComponent->GetValue() ),
GetChars( aNewComponent->GetValue() ) );
m_reporter->Report( msg, REPORTER::RPT_ACTION );
if ( !m_isDryRun )
if( !m_isDryRun )
{
changed = true;
aPcbComponent->SetValue( aNewComponent->GetValue() );
@ -308,6 +311,7 @@ bool BOARD_NETLIST_UPDATER::updateComponentParameters( MODULE *aPcbComponent, CO
GetChars( aPcbComponent->GetReference() ),
GetChars( aPcbComponent->GetPath() ),
GetChars( aNewComponent->GetTimeStamp() ) );
m_reporter->Report( msg, REPORTER::RPT_INFO );
if ( !m_isDryRun )
@ -325,7 +329,8 @@ bool BOARD_NETLIST_UPDATER::updateComponentParameters( MODULE *aPcbComponent, CO
return true;
}
bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE *aPcbComponent, COMPONENT* aNewComponent )
bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE* aPcbComponent, COMPONENT* aNewComponent )
{
wxString msg;
@ -333,7 +338,7 @@ bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE *aPcbComponent
MODULE* copy = (MODULE*) aPcbComponent->Clone();
// At this point, the component footprint is updated. Now update the nets.
for( D_PAD *pad = aPcbComponent->Pads(); pad; pad = pad->Next() )
for( D_PAD* pad = aPcbComponent->Pads(); pad; pad = pad->Next() )
{
COMPONENT_NET net = aNewComponent->GetNet( pad->GetPadName() );
@ -351,7 +356,6 @@ bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE *aPcbComponent
GetChars( aPcbComponent->GetPath() ),
GetChars( pad->GetPadName() ) );
m_reporter->Report( msg, REPORTER::RPT_INFO );
}
if( !m_isDryRun )
@ -377,13 +381,12 @@ bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE *aPcbComponent
pushUndo( netinfo, UR_NEW );
}
msg.Printf( _( "Add net %s.\n" ),
GetChars( net.GetNetName() ) );
msg.Printf( _( "Add net %s.\n" ), GetChars( net.GetNetName() ) );
m_reporter->Report( msg, REPORTER::RPT_ACTION );
}
if( pad->GetNetname() != wxString("") )
if( !pad->GetNetname().IsEmpty() )
{
msg.Printf( _( "Reconnect component %s pin %s from net %s to net %s.\n"),
GetChars( aPcbComponent->GetReference() ),
@ -410,7 +413,7 @@ bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE *aPcbComponent
m_reporter->Report( msg, REPORTER::RPT_INFO );
if ( !m_isDryRun )
if( !m_isDryRun )
{
changed = true;
pad->SetNetCode( netinfo->GetNet() );
@ -427,6 +430,7 @@ bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE *aPcbComponent
return true;
}
bool BOARD_NETLIST_UPDATER::deleteUnusedComponents( NETLIST& aNetlist )
{
wxString msg;
@ -467,6 +471,7 @@ bool BOARD_NETLIST_UPDATER::deleteUnusedComponents( NETLIST& aNetlist )
return true;
}
bool BOARD_NETLIST_UPDATER::deleteSinglePadNets()
{
int count = 0;
@ -520,7 +525,6 @@ bool BOARD_NETLIST_UPDATER::deleteSinglePadNets()
{
msg.Printf( _( "Remove single pad net %s." ),
GetChars( previouspad->GetNetname() ) );
m_reporter->Report( msg, REPORTER::RPT_ACTION );
msg.Printf( _( "Remove single pad net \"%s\" on \"%s\" pad '%s'\n" ),
@ -554,6 +558,7 @@ bool BOARD_NETLIST_UPDATER::deleteSinglePadNets()
return true;
}
bool BOARD_NETLIST_UPDATER::testConnectivity( NETLIST& aNetlist )
{
// Last step: Some tests:
@ -592,7 +597,7 @@ bool BOARD_NETLIST_UPDATER::testConnectivity( NETLIST& aNetlist )
GetChars( padname ),
GetChars( footprint->GetFPID().Format() ) );
m_reporter->Report( msg, REPORTER::RPT_ERROR );
m_errorCount ++;
++m_errorCount;
}
}
@ -611,13 +616,14 @@ bool BOARD_NETLIST_UPDATER::testConnectivity( NETLIST& aNetlist )
msg.Printf( _( "Copper zone (net name %s): net has no pads connected." ),
GetChars( zone->GetNet()->GetNetname() ) );
m_reporter->Report( msg, REPORTER::RPT_WARNING );
m_warningCount ++;
++m_warningCount;
}
}
return true;
}
bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist )
{
wxString msg;
@ -630,17 +636,15 @@ bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist )
m_board->SetStatus( 0 );
}
for( int i = 0; i < (int) aNetlist.GetCount(); i++ )
{
COMPONENT* component = aNetlist.GetComponent( i );
MODULE *footprint = NULL;
MODULE* footprint = NULL;
msg.Printf( _( "Processing component \"%s:%s:%s\".\n" ),
GetChars( component->GetReference() ),
GetChars( component->GetTimeStamp() ),
GetChars( component->GetFPID().Format() ) );
m_reporter->Report( msg, REPORTER::RPT_INFO );
if( aNetlist.IsFindByTimeStamp() )
@ -650,8 +654,9 @@ bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist )
if( footprint ) // An existing footprint.
{
MODULE *newFootprint = replaceComponent ( aNetlist, footprint, component );
if ( newFootprint )
MODULE* newFootprint = replaceComponent( aNetlist, footprint, component );
if( newFootprint )
footprint = newFootprint;
}
else
@ -666,9 +671,6 @@ bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist )
}
}
//aNetlist.GetDeleteExtraFootprints()
if( m_deleteUnusedComponents )
@ -679,7 +681,7 @@ bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist )
if ( !m_isDryRun )
{
m_frame->SaveCopyInUndoList( *m_undoList, UR_UNSPECIFIED, wxPoint(0, 0) );
m_frame->SaveCopyInUndoList( *m_undoList, UR_UNSPECIFIED, wxPoint( 0, 0 ) );
m_frame->OnModify();
m_frame->Compile_Ratsnest( NULL, true );
@ -689,35 +691,31 @@ bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist )
}
// Update the ratsnest
m_reporter->Report( wxT( "" ), REPORTER::RPT_ACTION );
m_reporter->Report( wxT( "" ), REPORTER::RPT_ACTION );
m_reporter->Report( wxT(""), REPORTER::RPT_ACTION );
m_reporter->Report( wxT(""), REPORTER::RPT_ACTION );
msg.Printf( _( "Total warnings: %d, errors: %d." ),
m_warningCount, m_errorCount );
msg.Printf( _( "Total warnings: %d, errors: %d." ), m_warningCount, m_errorCount );
m_reporter->Report( msg, REPORTER::RPT_ACTION );
if ( m_errorCount )
if( m_errorCount )
{
m_reporter->Report( _("Errors occured during the netlist update. Unless you "
"fix them, your board will not be consistent with the schematics." ),
m_reporter->Report( _( "Errors occured during the netlist update. Unless you "
"fix them, your board will not be consistent with the schematics." ),
REPORTER::RPT_ERROR );
return false;
} else {
m_reporter->Report( _("Netlist update successful!" ),
REPORTER::RPT_ACTION );
}
else
{
m_reporter->Report( _( "Netlist update successful!" ), REPORTER::RPT_ACTION );
}
return true;
}
bool BOARD_NETLIST_UPDATER::UpdateNetlist( const wxString& aNetlistFileName,
const wxString& aCmpFileName )
const wxString& aCmpFileName )
{
return false;
}

View File

@ -72,94 +72,91 @@ class PCB_EDIT_FRAME;
class BOARD_NETLIST_UPDATER
{
public:
BOARD_NETLIST_UPDATER( PCB_EDIT_FRAME* aFrame, BOARD* aBoard );
~BOARD_NETLIST_UPDATER();
BOARD_NETLIST_UPDATER( PCB_EDIT_FRAME *aFrame, BOARD *aBoard );
~BOARD_NETLIST_UPDATER();
/**
* Function UpdateNetlist()
*
* Updates the board's components according to the new netlist.
* See BOARD_NETLIST_UPDATER class description for the details of the process.
* @param aNetlist the new netlist
* @return true if process was completed successfully
*/
bool UpdateNetlist( NETLIST& aNetlist );
/**
* Function UpdateNetlist()
*
* Updates the board's components according to the new netlist.
* See BOARD_NETLIST_UPDATER class description for the details of the process.
* @param aNetlist the new netlist
* @return true if process was completed successfully
*/
bool UpdateNetlist( NETLIST& aNetlist );
// @todo: implement and move NETLIST::ReadPcbNetlist here
bool UpdateNetlist( const wxString& aNetlistFileName, const wxString& aCmpFileName );
// @todo: implement and move NETLIST::ReadPcbNetlist here
bool UpdateNetlist( const wxString& aNetlistFileName,
const wxString& aCmpFileName );
///> Sets the reporter object
void SetReporter( REPORTER* aReporter )
{
m_reporter = aReporter;
}
///> Enables "delete single pad nets" option
void SetDeleteSinglePadNets( bool aEnabled )
{
m_deleteSinglePadNets = aEnabled;
}
///> Sets the reporter object
void SetReporter ( REPORTER *aReporter )
{
m_reporter = aReporter;
}
///> Enables dry run mode (just report, no changes to PCB)
void SetIsDryRun( bool aEnabled )
{
m_isDryRun = aEnabled;
}
///> Enables "delete single pad nets" option
void SetDeleteSinglePadNets( bool aEnabled )
{
m_deleteSinglePadNets = aEnabled;
}
///> Enables replacing footprints with new ones
void SetReplaceFootprints( bool aEnabled )
{
m_replaceFootprints = aEnabled;
}
///> Enables dry run mode (just report, no changes to PCB)
void SetIsDryRun ( bool aEnabled )
{
m_isDryRun = aEnabled;
}
///> Enables removing unused components
void SetDeleteUnusedComponents( bool aEnabled )
{
m_deleteUnusedComponents = aEnabled;
}
///> Enables replacing footprints with new ones
void SetReplaceFootprints ( bool aEnabled )
{
m_replaceFootprints = aEnabled;
}
///> Enables component lookup by timestamp instead of reference
void SetLookupByTimestamp( bool aEnabled )
{
m_lookupByTimestamp = aEnabled;
}
///> Enables removing unused components
void SetDeleteUnusedComponents ( bool aEnabled )
{
m_deleteUnusedComponents = aEnabled;
}
///> Enables component lookup by timestamp instead of reference
void SetLookupByTimestamp ( bool aEnabled )
{
m_lookupByTimestamp = aEnabled;
}
std::vector<MODULE*> GetAddedComponents() const
{
return m_addedComponents;
}
std::vector<MODULE*> GetAddedComponents() const
{
return m_addedComponents;
}
private:
void pushUndo( BOARD_ITEM* aItem, UNDO_REDO_T aCommandType, BOARD_ITEM* aCopy = NULL );
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 );
bool updateComponentParameters( MODULE *aPcbComponent, COMPONENT* aNewComponent );
bool updateComponentPadConnections( MODULE *aPcbComponent, COMPONENT* aNewComponent );
bool deleteUnusedComponents( NETLIST& aNetlist );
bool deleteSinglePadNets();
bool testConnectivity( NETLIST& aNetlist );
wxPoint estimateComponentInsertionPosition();
MODULE* addNewComponent( COMPONENT* aComponent );
MODULE* replaceComponent( NETLIST& aNetlist, MODULE* aPcbComponent, COMPONENT* aNewComponent );
bool updateComponentParameters( MODULE* aPcbComponent, COMPONENT* aNewComponent );
bool updateComponentPadConnections( MODULE* aPcbComponent, COMPONENT* aNewComponent );
bool deleteUnusedComponents( NETLIST& aNetlist );
bool deleteSinglePadNets();
bool testConnectivity( NETLIST& aNetlist );
PICKED_ITEMS_LIST *m_undoList;
PCB_EDIT_FRAME *m_frame;
BOARD *m_board;
REPORTER *m_reporter;
PICKED_ITEMS_LIST* m_undoList;
PCB_EDIT_FRAME* m_frame;
BOARD* m_board;
REPORTER* m_reporter;
std::vector<MODULE*> m_addedComponents;
std::vector<MODULE*> m_addedComponents;
bool m_deleteSinglePadNets;
bool m_deleteUnusedComponents;
bool m_isDryRun;
bool m_replaceFootprints;
bool m_lookupByTimestamp;
bool m_deleteSinglePadNets;
bool m_deleteUnusedComponents;
bool m_isDryRun;
bool m_replaceFootprints;
bool m_lookupByTimestamp;
int m_warningCount;
int m_errorCount;
int m_warningCount;
int m_errorCount;
};
#endif

View File

@ -19,26 +19,27 @@ DIALOG_UPDATE_PCB::DIALOG_UPDATE_PCB( PCB_EDIT_FRAME* aParent, NETLIST *aNetlist
m_netlist (aNetlist)
{
m_messagePanel->SetLabel( _("Changes to be applied:") );
m_messagePanel->SetLazyUpdate ( true );
m_messagePanel->SetLazyUpdate( true );
m_netlist->SortByReference();
m_btnPerformUpdate->SetFocus();
m_messagePanel->SetVisibleSeverities( REPORTER::RPT_WARNING | REPORTER::RPT_ERROR | REPORTER::RPT_ACTION );
}
DIALOG_UPDATE_PCB::~DIALOG_UPDATE_PCB()
{
}
void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun )
{
m_messagePanel->Clear();
REPORTER &reporter = m_messagePanel->Reporter();
KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView();
TOOL_MANAGER *toolManager = m_frame->GetToolManager();
BOARD *board = m_frame->GetBoard();
TOOL_MANAGER* toolManager = m_frame->GetToolManager();
BOARD* board = m_frame->GetBoard();
if( !aDryRun )
{
@ -57,7 +58,8 @@ void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun )
m_netlist->SetFindByTimeStamp( m_matchByTimestamp->GetValue() );
m_netlist->SetReplaceFootprints( true );
try {
try
{
m_frame->LoadFootprints( *m_netlist, &reporter );
}
catch( IO_ERROR &error )
@ -70,14 +72,12 @@ void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun )
}
BOARD_NETLIST_UPDATER updater( m_frame, m_frame->GetBoard() );
updater.SetReporter ( &reporter );
updater.SetIsDryRun( aDryRun);
updater.SetLookupByTimestamp( m_matchByTimestamp->GetValue() );
updater.SetDeleteUnusedComponents ( true );
updater.SetReplaceFootprints( true );
updater.SetDeleteSinglePadNets ( false );
updater.SetDeleteSinglePadNets( false );
updater.UpdateNetlist( *m_netlist );
m_messagePanel->Flush();
@ -103,10 +103,8 @@ void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun )
board->GetRatsnest()->ProcessBoard();
m_frame->Compile_Ratsnest( NULL, true );
m_frame->SetMsgPanel( board );
if( m_frame->IsGalCanvasActive() )
{
m_frame->SpreadFootprints( &newFootprints, false, false, m_frame->GetCrossHairPosition() );
@ -117,30 +115,33 @@ void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun )
{
toolManager->RunAction( COMMON_ACTIONS::selectItem, true, footprint );
}
toolManager->InvokeTool( "pcbnew.InteractiveEdit" );
}
}
m_btnPerformUpdate->Enable( false );
m_btnPerformUpdate->SetLabel( _( "Update complete" ) );
m_btnCancel->SetLabel ( _("Close") );
m_btnCancel->SetLabel( _("Close") );
m_btnCancel->SetFocus();
}
void DIALOG_UPDATE_PCB::OnMatchChange( wxCommandEvent& event )
{
PerformUpdate( true );
}
void DIALOG_UPDATE_PCB::OnCancelClick( wxCommandEvent& event )
{
EndModal( wxID_CANCEL );
}
void DIALOG_UPDATE_PCB::OnUpdateClick( wxCommandEvent& event )
{
m_messagePanel->SetLabel( _("Changes applied to the PCB:") );
m_messagePanel->SetLabel( _( "Changes applied to the PCB:" ) );
PerformUpdate( false );
m_btnCancel->SetFocus( );
m_btnCancel->SetFocus();
}