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

@ -66,11 +66,13 @@ BOARD_NETLIST_UPDATER::BOARD_NETLIST_UPDATER ( PCB_EDIT_FRAME *aFrame, BOARD *aB
m_errorCount = 0; m_errorCount = 0;
} }
BOARD_NETLIST_UPDATER::~BOARD_NETLIST_UPDATER() BOARD_NETLIST_UPDATER::~BOARD_NETLIST_UPDATER()
{ {
delete m_undoList; delete m_undoList;
} }
void BOARD_NETLIST_UPDATER::pushUndo( BOARD_ITEM* aItem, UNDO_REDO_T aCommandType, BOARD_ITEM* aCopy ) void BOARD_NETLIST_UPDATER::pushUndo( BOARD_ITEM* aItem, UNDO_REDO_T aCommandType, BOARD_ITEM* aCopy )
{ {
ITEM_PICKER picker( aItem, aCommandType ); ITEM_PICKER picker( aItem, aCommandType );
@ -86,6 +88,7 @@ void BOARD_NETLIST_UPDATER::pushUndo( BOARD_ITEM* aItem, UNDO_REDO_T aCommandTyp
m_undoList->PushItem( picker ); m_undoList->PushItem( picker );
} }
wxPoint BOARD_NETLIST_UPDATER::estimateComponentInsertionPosition() wxPoint BOARD_NETLIST_UPDATER::estimateComponentInsertionPosition()
{ {
wxPoint bestPosition; wxPoint bestPosition;
@ -124,13 +127,11 @@ MODULE* BOARD_NETLIST_UPDATER::addNewComponent( COMPONENT* aComponent )
GetChars( aComponent->GetReference() ), GetChars( aComponent->GetReference() ),
GetChars( aComponent->GetTimeStamp() ), GetChars( aComponent->GetTimeStamp() ),
GetChars( aComponent->GetFPID().Format() ) ); GetChars( aComponent->GetFPID().Format() ) );
m_reporter->Report( msg, REPORTER::RPT_INFO ); m_reporter->Report( msg, REPORTER::RPT_INFO );
msg.Printf( _( "Add component %s, footprint: %s.\n" ), msg.Printf( _( "Add component %s, footprint: %s.\n" ),
GetChars( aComponent->GetReference() ), GetChars( aComponent->GetReference() ),
GetChars( aComponent->GetFPID().Format() ) ); GetChars( aComponent->GetFPID().Format() ) );
m_reporter->Report( msg, REPORTER::RPT_ACTION ); m_reporter->Report( msg, REPORTER::RPT_ACTION );
@ -165,13 +166,13 @@ MODULE* BOARD_NETLIST_UPDATER::addNewComponent( COMPONENT* aComponent )
GetChars( aComponent->GetFPID().Format() ) ); GetChars( aComponent->GetFPID().Format() ) );
m_reporter->Report( msg, REPORTER::RPT_INFO ); m_reporter->Report( msg, REPORTER::RPT_INFO );
++m_errorCount;
m_errorCount ++;
} }
return NULL; 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; wxString msg;
@ -180,8 +181,7 @@ MODULE* BOARD_NETLIST_UPDATER::replaceComponent( NETLIST& aNetlist, MODULE *aPcb
return NULL; return NULL;
// Test if the footprint has not changed // Test if the footprint has not changed
if( aNewComponent->GetFPID().empty() || if( aNewComponent->GetFPID().empty() || aPcbComponent->GetFPID() == aNewComponent->GetFPID() )
aPcbComponent->GetFPID() == aNewComponent->GetFPID() )
return NULL; return NULL;
if( aNewComponent->GetModule() != NULL ) if( aNewComponent->GetModule() != NULL )
@ -221,8 +221,9 @@ MODULE* BOARD_NETLIST_UPDATER::replaceComponent( NETLIST& aNetlist, MODULE *aPcb
return newFootprint; return newFootprint;
} }
} else { }
else
{
msg.Printf( _( "Cannot change component %s footprint due to missing " msg.Printf( _( "Cannot change component %s footprint due to missing "
"footprint %s.\n" ), "footprint %s.\n" ),
GetChars( aPcbComponent->GetReference() ), GetChars( aPcbComponent->GetReference() ),
@ -238,12 +239,13 @@ MODULE* BOARD_NETLIST_UPDATER::replaceComponent( NETLIST& aNetlist, MODULE *aPcb
m_reporter->Report( msg, REPORTER::RPT_INFO ); m_reporter->Report( msg, REPORTER::RPT_INFO );
m_errorCount ++; ++m_errorCount;
} }
return NULL; return NULL;
} }
bool BOARD_NETLIST_UPDATER::updateComponentParameters( MODULE* aPcbComponent, COMPONENT* aNewComponent ) bool BOARD_NETLIST_UPDATER::updateComponentParameters( MODULE* aPcbComponent, COMPONENT* aNewComponent )
{ {
wxString msg; wxString msg;
@ -292,6 +294,7 @@ bool BOARD_NETLIST_UPDATER::updateComponentParameters( MODULE *aPcbComponent, CO
GetChars( aPcbComponent->GetPath() ), GetChars( aPcbComponent->GetPath() ),
GetChars( aPcbComponent->GetValue() ), GetChars( aPcbComponent->GetValue() ),
GetChars( aNewComponent->GetValue() ) ); GetChars( aNewComponent->GetValue() ) );
m_reporter->Report( msg, REPORTER::RPT_ACTION ); m_reporter->Report( msg, REPORTER::RPT_ACTION );
if( !m_isDryRun ) if( !m_isDryRun )
@ -308,6 +311,7 @@ bool BOARD_NETLIST_UPDATER::updateComponentParameters( MODULE *aPcbComponent, CO
GetChars( aPcbComponent->GetReference() ), GetChars( aPcbComponent->GetReference() ),
GetChars( aPcbComponent->GetPath() ), GetChars( aPcbComponent->GetPath() ),
GetChars( aNewComponent->GetTimeStamp() ) ); GetChars( aNewComponent->GetTimeStamp() ) );
m_reporter->Report( msg, REPORTER::RPT_INFO ); m_reporter->Report( msg, REPORTER::RPT_INFO );
if ( !m_isDryRun ) if ( !m_isDryRun )
@ -325,6 +329,7 @@ bool BOARD_NETLIST_UPDATER::updateComponentParameters( MODULE *aPcbComponent, CO
return true; return true;
} }
bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE* aPcbComponent, COMPONENT* aNewComponent ) bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE* aPcbComponent, COMPONENT* aNewComponent )
{ {
wxString msg; wxString msg;
@ -351,7 +356,6 @@ bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE *aPcbComponent
GetChars( aPcbComponent->GetPath() ), GetChars( aPcbComponent->GetPath() ),
GetChars( pad->GetPadName() ) ); GetChars( pad->GetPadName() ) );
m_reporter->Report( msg, REPORTER::RPT_INFO ); m_reporter->Report( msg, REPORTER::RPT_INFO );
} }
if( !m_isDryRun ) if( !m_isDryRun )
@ -377,13 +381,12 @@ bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE *aPcbComponent
pushUndo( netinfo, UR_NEW ); pushUndo( netinfo, UR_NEW );
} }
msg.Printf( _( "Add net %s.\n" ), msg.Printf( _( "Add net %s.\n" ), GetChars( net.GetNetName() ) );
GetChars( net.GetNetName() ) );
m_reporter->Report( msg, REPORTER::RPT_ACTION ); 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"), msg.Printf( _( "Reconnect component %s pin %s from net %s to net %s.\n"),
GetChars( aPcbComponent->GetReference() ), GetChars( aPcbComponent->GetReference() ),
@ -427,6 +430,7 @@ bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE *aPcbComponent
return true; return true;
} }
bool BOARD_NETLIST_UPDATER::deleteUnusedComponents( NETLIST& aNetlist ) bool BOARD_NETLIST_UPDATER::deleteUnusedComponents( NETLIST& aNetlist )
{ {
wxString msg; wxString msg;
@ -467,6 +471,7 @@ bool BOARD_NETLIST_UPDATER::deleteUnusedComponents( NETLIST& aNetlist )
return true; return true;
} }
bool BOARD_NETLIST_UPDATER::deleteSinglePadNets() bool BOARD_NETLIST_UPDATER::deleteSinglePadNets()
{ {
int count = 0; int count = 0;
@ -520,7 +525,6 @@ bool BOARD_NETLIST_UPDATER::deleteSinglePadNets()
{ {
msg.Printf( _( "Remove single pad net %s." ), msg.Printf( _( "Remove single pad net %s." ),
GetChars( previouspad->GetNetname() ) ); GetChars( previouspad->GetNetname() ) );
m_reporter->Report( msg, REPORTER::RPT_ACTION ); m_reporter->Report( msg, REPORTER::RPT_ACTION );
msg.Printf( _( "Remove single pad net \"%s\" on \"%s\" pad '%s'\n" ), msg.Printf( _( "Remove single pad net \"%s\" on \"%s\" pad '%s'\n" ),
@ -554,6 +558,7 @@ bool BOARD_NETLIST_UPDATER::deleteSinglePadNets()
return true; return true;
} }
bool BOARD_NETLIST_UPDATER::testConnectivity( NETLIST& aNetlist ) bool BOARD_NETLIST_UPDATER::testConnectivity( NETLIST& aNetlist )
{ {
// Last step: Some tests: // Last step: Some tests:
@ -592,7 +597,7 @@ bool BOARD_NETLIST_UPDATER::testConnectivity( NETLIST& aNetlist )
GetChars( padname ), GetChars( padname ),
GetChars( footprint->GetFPID().Format() ) ); GetChars( footprint->GetFPID().Format() ) );
m_reporter->Report( msg, REPORTER::RPT_ERROR ); 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." ), msg.Printf( _( "Copper zone (net name %s): net has no pads connected." ),
GetChars( zone->GetNet()->GetNetname() ) ); GetChars( zone->GetNet()->GetNetname() ) );
m_reporter->Report( msg, REPORTER::RPT_WARNING ); m_reporter->Report( msg, REPORTER::RPT_WARNING );
m_warningCount ++; ++m_warningCount;
} }
} }
return true; return true;
} }
bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist ) bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist )
{ {
wxString msg; wxString msg;
@ -630,7 +636,6 @@ bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist )
m_board->SetStatus( 0 ); m_board->SetStatus( 0 );
} }
for( int i = 0; i < (int) aNetlist.GetCount(); i++ ) for( int i = 0; i < (int) aNetlist.GetCount(); i++ )
{ {
COMPONENT* component = aNetlist.GetComponent( i ); COMPONENT* component = aNetlist.GetComponent( i );
@ -640,7 +645,6 @@ bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist )
GetChars( component->GetReference() ), GetChars( component->GetReference() ),
GetChars( component->GetTimeStamp() ), GetChars( component->GetTimeStamp() ),
GetChars( component->GetFPID().Format() ) ); GetChars( component->GetFPID().Format() ) );
m_reporter->Report( msg, REPORTER::RPT_INFO ); m_reporter->Report( msg, REPORTER::RPT_INFO );
if( aNetlist.IsFindByTimeStamp() ) if( aNetlist.IsFindByTimeStamp() )
@ -651,6 +655,7 @@ bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist )
if( footprint ) // An existing footprint. if( footprint ) // An existing footprint.
{ {
MODULE* newFootprint = replaceComponent( aNetlist, footprint, component ); MODULE* newFootprint = replaceComponent( aNetlist, footprint, component );
if( newFootprint ) if( newFootprint )
footprint = newFootprint; footprint = newFootprint;
} }
@ -666,9 +671,6 @@ bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist )
} }
} }
//aNetlist.GetDeleteExtraFootprints() //aNetlist.GetDeleteExtraFootprints()
if( m_deleteUnusedComponents ) if( m_deleteUnusedComponents )
@ -689,33 +691,29 @@ bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist )
} }
// Update the ratsnest // 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." ), msg.Printf( _( "Total warnings: %d, errors: %d." ), m_warningCount, m_errorCount );
m_warningCount, m_errorCount );
m_reporter->Report( msg, REPORTER::RPT_ACTION ); m_reporter->Report( msg, REPORTER::RPT_ACTION );
if( m_errorCount ) if( m_errorCount )
{ {
m_reporter->Report( _( "Errors occured during the netlist update. Unless you " m_reporter->Report( _( "Errors occured during the netlist update. Unless you "
"fix them, your board will not be consistent with the schematics." ), "fix them, your board will not be consistent with the schematics." ),
REPORTER::RPT_ERROR ); REPORTER::RPT_ERROR );
return false; return false;
} else { }
m_reporter->Report( _("Netlist update successful!" ), else
REPORTER::RPT_ACTION ); {
m_reporter->Report( _( "Netlist update successful!" ), REPORTER::RPT_ACTION );
} }
return true; return true;
} }
bool BOARD_NETLIST_UPDATER::UpdateNetlist( const wxString& aNetlistFileName, bool BOARD_NETLIST_UPDATER::UpdateNetlist( const wxString& aNetlistFileName,
const wxString& aCmpFileName ) const wxString& aCmpFileName )
{ {

View File

@ -72,7 +72,6 @@ class PCB_EDIT_FRAME;
class BOARD_NETLIST_UPDATER class BOARD_NETLIST_UPDATER
{ {
public: public:
BOARD_NETLIST_UPDATER( PCB_EDIT_FRAME* aFrame, BOARD* aBoard ); BOARD_NETLIST_UPDATER( PCB_EDIT_FRAME* aFrame, BOARD* aBoard );
~BOARD_NETLIST_UPDATER(); ~BOARD_NETLIST_UPDATER();
@ -87,9 +86,7 @@ public:
bool UpdateNetlist( NETLIST& aNetlist ); bool UpdateNetlist( NETLIST& aNetlist );
// @todo: implement and move NETLIST::ReadPcbNetlist here // @todo: implement and move NETLIST::ReadPcbNetlist here
bool UpdateNetlist( const wxString& aNetlistFileName, bool UpdateNetlist( const wxString& aNetlistFileName, const wxString& aCmpFileName );
const wxString& aCmpFileName );
///> Sets the reporter object ///> Sets the reporter object
void SetReporter( REPORTER* aReporter ) void SetReporter( REPORTER* aReporter )

View File

@ -26,11 +26,12 @@ DIALOG_UPDATE_PCB::DIALOG_UPDATE_PCB( PCB_EDIT_FRAME* aParent, NETLIST *aNetlist
m_messagePanel->SetVisibleSeverities( REPORTER::RPT_WARNING | REPORTER::RPT_ERROR | REPORTER::RPT_ACTION ); m_messagePanel->SetVisibleSeverities( REPORTER::RPT_WARNING | REPORTER::RPT_ERROR | REPORTER::RPT_ACTION );
} }
DIALOG_UPDATE_PCB::~DIALOG_UPDATE_PCB() DIALOG_UPDATE_PCB::~DIALOG_UPDATE_PCB()
{ {
} }
void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun ) void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun )
{ {
m_messagePanel->Clear(); m_messagePanel->Clear();
@ -57,7 +58,8 @@ void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun )
m_netlist->SetFindByTimeStamp( m_matchByTimestamp->GetValue() ); m_netlist->SetFindByTimeStamp( m_matchByTimestamp->GetValue() );
m_netlist->SetReplaceFootprints( true ); m_netlist->SetReplaceFootprints( true );
try { try
{
m_frame->LoadFootprints( *m_netlist, &reporter ); m_frame->LoadFootprints( *m_netlist, &reporter );
} }
catch( IO_ERROR &error ) catch( IO_ERROR &error )
@ -70,14 +72,12 @@ void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun )
} }
BOARD_NETLIST_UPDATER updater( m_frame, m_frame->GetBoard() ); BOARD_NETLIST_UPDATER updater( m_frame, m_frame->GetBoard() );
updater.SetReporter ( &reporter ); updater.SetReporter ( &reporter );
updater.SetIsDryRun( aDryRun); updater.SetIsDryRun( aDryRun);
updater.SetLookupByTimestamp( m_matchByTimestamp->GetValue() ); updater.SetLookupByTimestamp( m_matchByTimestamp->GetValue() );
updater.SetDeleteUnusedComponents ( true ); updater.SetDeleteUnusedComponents ( true );
updater.SetReplaceFootprints( true ); updater.SetReplaceFootprints( true );
updater.SetDeleteSinglePadNets( false ); updater.SetDeleteSinglePadNets( false );
updater.UpdateNetlist( *m_netlist ); updater.UpdateNetlist( *m_netlist );
m_messagePanel->Flush(); m_messagePanel->Flush();
@ -103,10 +103,8 @@ void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun )
board->GetRatsnest()->ProcessBoard(); board->GetRatsnest()->ProcessBoard();
m_frame->Compile_Ratsnest( NULL, true ); m_frame->Compile_Ratsnest( NULL, true );
m_frame->SetMsgPanel( board ); m_frame->SetMsgPanel( board );
if( m_frame->IsGalCanvasActive() ) if( m_frame->IsGalCanvasActive() )
{ {
m_frame->SpreadFootprints( &newFootprints, false, false, m_frame->GetCrossHairPosition() ); m_frame->SpreadFootprints( &newFootprints, false, false, m_frame->GetCrossHairPosition() );
@ -117,27 +115,30 @@ void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun )
{ {
toolManager->RunAction( COMMON_ACTIONS::selectItem, true, footprint ); toolManager->RunAction( COMMON_ACTIONS::selectItem, true, footprint );
} }
toolManager->InvokeTool( "pcbnew.InteractiveEdit" ); toolManager->InvokeTool( "pcbnew.InteractiveEdit" );
} }
} }
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();
} }
void DIALOG_UPDATE_PCB::OnMatchChange( wxCommandEvent& event ) void DIALOG_UPDATE_PCB::OnMatchChange( wxCommandEvent& event )
{ {
PerformUpdate( true ); PerformUpdate( true );
} }
void DIALOG_UPDATE_PCB::OnCancelClick( wxCommandEvent& event ) void DIALOG_UPDATE_PCB::OnCancelClick( wxCommandEvent& event )
{ {
EndModal( wxID_CANCEL ); EndModal( wxID_CANCEL );
} }
void DIALOG_UPDATE_PCB::OnUpdateClick( wxCommandEvent& event ) void DIALOG_UPDATE_PCB::OnUpdateClick( wxCommandEvent& event )
{ {
m_messagePanel->SetLabel( _( "Changes applied to the PCB:" ) ); m_messagePanel->SetLabel( _( "Changes applied to the PCB:" ) );