2016-01-29 10:24:39 +00:00
|
|
|
/**
|
|
|
|
* @file board_netlist_updater.h
|
|
|
|
* @brief BOARD_NETLIST_UPDATER class definition
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 2015 CERN
|
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
|
|
|
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
*
|
2019-04-17 08:54:00 +00:00
|
|
|
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-01-29 10:24:39 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <common.h> // for PAGE_INFO
|
|
|
|
|
|
|
|
#include <class_board.h>
|
2018-01-30 14:34:09 +00:00
|
|
|
#include <netinfo.h>
|
2016-01-29 10:24:39 +00:00
|
|
|
#include <class_module.h>
|
|
|
|
#include <class_pad.h>
|
2019-12-06 14:47:03 +00:00
|
|
|
#include <class_track.h>
|
2016-01-29 10:24:39 +00:00
|
|
|
#include <class_zone.h>
|
|
|
|
|
2019-11-17 12:58:38 +00:00
|
|
|
#include "pcb_netlist.h"
|
2018-10-12 06:17:15 +00:00
|
|
|
#include <connectivity/connectivity_data.h>
|
2016-01-29 10:24:39 +00:00
|
|
|
#include <reporter.h>
|
|
|
|
|
2019-11-17 12:58:38 +00:00
|
|
|
#include "board_netlist_updater.h"
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2016-01-29 10:24:39 +00:00
|
|
|
|
|
|
|
|
2016-09-02 13:53:51 +00:00
|
|
|
BOARD_NETLIST_UPDATER::BOARD_NETLIST_UPDATER( PCB_EDIT_FRAME* aFrame, BOARD* aBoard ) :
|
2018-08-20 00:54:22 +00:00
|
|
|
m_frame( aFrame ),
|
2016-09-05 13:38:01 +00:00
|
|
|
m_commit( aFrame ),
|
2016-01-29 10:24:39 +00:00
|
|
|
m_board( aBoard )
|
|
|
|
{
|
|
|
|
m_reporter = &NULL_REPORTER::GetInstance();
|
2016-04-07 11:09:31 +00:00
|
|
|
|
2016-09-02 13:53:51 +00:00
|
|
|
m_deleteSinglePadNets = true;
|
|
|
|
m_deleteUnusedComponents = false;
|
|
|
|
m_isDryRun = false;
|
|
|
|
m_replaceFootprints = true;
|
|
|
|
m_lookupByTimestamp = false;
|
2019-11-17 15:37:32 +00:00
|
|
|
m_warnForNoNetPads = false;
|
2016-04-07 11:09:31 +00:00
|
|
|
|
2016-09-02 13:53:51 +00:00
|
|
|
m_warningCount = 0;
|
|
|
|
m_errorCount = 0;
|
2019-04-17 08:54:00 +00:00
|
|
|
m_newFootprintsCount = 0;
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
|
|
|
|
2016-09-02 13:53:51 +00:00
|
|
|
|
|
|
|
BOARD_NETLIST_UPDATER::~BOARD_NETLIST_UPDATER()
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-09-02 13:53:51 +00:00
|
|
|
|
2018-05-01 12:52:11 +00:00
|
|
|
// These functions allow inspection of pad nets during dry runs by keeping a cache of
|
|
|
|
// current pad netnames indexed by pad.
|
|
|
|
|
|
|
|
void BOARD_NETLIST_UPDATER::cacheNetname( D_PAD* aPad, const wxString& aNetname )
|
|
|
|
{
|
|
|
|
m_padNets[ aPad ] = aNetname;
|
|
|
|
}
|
|
|
|
|
2019-11-17 09:11:29 +00:00
|
|
|
|
2018-05-01 12:52:11 +00:00
|
|
|
wxString BOARD_NETLIST_UPDATER::getNetname( D_PAD* aPad )
|
|
|
|
{
|
|
|
|
if( m_isDryRun && m_padNets.count( aPad ) )
|
|
|
|
return m_padNets[ aPad ];
|
|
|
|
else
|
|
|
|
return aPad->GetNetname();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-17 09:11:29 +00:00
|
|
|
void BOARD_NETLIST_UPDATER::cachePinFunction( D_PAD* aPad, const wxString& aPinFunction )
|
|
|
|
{
|
|
|
|
m_padPinFunctions[ aPad ] = aPinFunction;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString BOARD_NETLIST_UPDATER::getPinFunction( D_PAD* aPad )
|
|
|
|
{
|
|
|
|
if( m_isDryRun && m_padPinFunctions.count( aPad ) )
|
|
|
|
return m_padPinFunctions[ aPad ];
|
|
|
|
else
|
|
|
|
return aPad->GetPinFunction();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-29 10:24:39 +00:00
|
|
|
wxPoint BOARD_NETLIST_UPDATER::estimateComponentInsertionPosition()
|
|
|
|
{
|
|
|
|
wxPoint bestPosition;
|
|
|
|
|
|
|
|
if( !m_board->IsEmpty() )
|
|
|
|
{
|
|
|
|
// Position new components below any existing board features.
|
2017-02-23 04:31:26 +00:00
|
|
|
EDA_RECT bbox = m_board->GetBoardEdgesBoundingBox();
|
2016-01-29 10:24:39 +00:00
|
|
|
|
|
|
|
if( bbox.GetWidth() || bbox.GetHeight() )
|
|
|
|
{
|
|
|
|
bestPosition.x = bbox.Centre().x;
|
|
|
|
bestPosition.y = bbox.GetBottom() + Millimeter2iu( 10 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Position new components in the center of the page when the board is empty.
|
|
|
|
wxSize pageSize = m_board->GetPageSettings().GetSizeIU();
|
|
|
|
|
|
|
|
bestPosition.x = pageSize.GetWidth() / 2;
|
|
|
|
bestPosition.y = pageSize.GetHeight() / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bestPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MODULE* BOARD_NETLIST_UPDATER::addNewComponent( COMPONENT* aComponent )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
2018-08-20 00:54:22 +00:00
|
|
|
if( aComponent->GetFPID().empty() )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
2018-08-20 00:54:22 +00:00
|
|
|
msg.Printf( _( "Cannot add %s (no footprint assigned)." ),
|
|
|
|
aComponent->GetReference(),
|
|
|
|
aComponent->GetFPID().Format().wx_str() );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
|
2018-08-20 00:54:22 +00:00
|
|
|
++m_errorCount;
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2018-08-20 00:54:22 +00:00
|
|
|
MODULE* footprint = m_frame->LoadFootprint( aComponent->GetFPID() );
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2018-08-20 00:54:22 +00:00
|
|
|
if( footprint == nullptr )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Cannot add %s (footprint \"%s\" not found)." ),
|
|
|
|
aComponent->GetReference(),
|
|
|
|
aComponent->GetFPID().Format().wx_str() );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
|
2018-08-20 00:54:22 +00:00
|
|
|
++m_errorCount;
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2018-08-20 00:54:22 +00:00
|
|
|
msg.Printf( _( "Add %s (footprint \"%s\")." ),
|
|
|
|
aComponent->GetReference(),
|
|
|
|
aComponent->GetFPID().Format().wx_str() );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ACTION );
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2019-11-07 01:04:00 +00:00
|
|
|
// Set the pads ratsnest settings to the global settings
|
2019-11-07 14:23:09 +00:00
|
|
|
bool set_ratsnest = m_frame->GetDisplayOptions().m_ShowGlobalRatsnest;
|
2020-09-04 09:32:20 +00:00
|
|
|
|
|
|
|
for ( D_PAD* pad : footprint->Pads() )
|
2019-11-07 01:04:00 +00:00
|
|
|
pad->SetLocalRatsnestVisible( set_ratsnest );
|
|
|
|
|
2019-04-17 08:54:00 +00:00
|
|
|
m_newFootprintsCount++;
|
|
|
|
|
2018-08-20 00:54:22 +00:00
|
|
|
if( !m_isDryRun )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
2018-08-20 00:54:22 +00:00
|
|
|
footprint->SetParent( m_board );
|
|
|
|
footprint->SetPosition( estimateComponentInsertionPosition( ) );
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2018-08-20 00:54:22 +00:00
|
|
|
m_addedComponents.push_back( footprint );
|
|
|
|
m_commit.Add( footprint );
|
|
|
|
|
|
|
|
return footprint;
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
2019-04-17 08:54:00 +00:00
|
|
|
else
|
|
|
|
delete footprint;
|
2016-01-29 10:24:39 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-09-02 13:53:51 +00:00
|
|
|
|
2018-08-20 00:54:22 +00:00
|
|
|
MODULE* BOARD_NETLIST_UPDATER::replaceComponent( NETLIST& aNetlist, MODULE* aPcbComponent,
|
|
|
|
COMPONENT* aNewComponent )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
2018-08-20 00:54:22 +00:00
|
|
|
if( aNewComponent->GetFPID().empty() )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
2018-08-20 00:54:22 +00:00
|
|
|
msg.Printf( _( "Cannot update %s (no footprint assigned)." ),
|
|
|
|
aNewComponent->GetReference(),
|
|
|
|
aNewComponent->GetFPID().Format().wx_str() );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
|
2018-08-20 00:54:22 +00:00
|
|
|
++m_errorCount;
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2018-08-20 00:54:22 +00:00
|
|
|
MODULE* newFootprint = m_frame->LoadFootprint( aNewComponent->GetFPID() );
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2018-08-20 00:54:22 +00:00
|
|
|
if( newFootprint == nullptr )
|
2016-09-02 13:53:51 +00:00
|
|
|
{
|
2018-08-20 00:54:22 +00:00
|
|
|
msg.Printf( _( "Cannot update %s (footprint \"%s\" not found)." ),
|
|
|
|
aNewComponent->GetReference(),
|
|
|
|
aNewComponent->GetFPID().Format().wx_str() );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
|
2018-08-20 00:54:22 +00:00
|
|
|
++m_errorCount;
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2018-08-20 00:54:22 +00:00
|
|
|
msg.Printf( _( "Change %s footprint from \"%s\" to \"%s\"."),
|
|
|
|
aPcbComponent->GetReference(),
|
|
|
|
aPcbComponent->GetFPID().Format().wx_str(),
|
|
|
|
aNewComponent->GetFPID().Format().wx_str() );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ACTION );
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2019-04-17 08:54:00 +00:00
|
|
|
m_newFootprintsCount++;
|
|
|
|
|
2018-08-20 00:54:22 +00:00
|
|
|
if( !m_isDryRun )
|
|
|
|
{
|
2019-08-25 21:10:15 +00:00
|
|
|
m_frame->Exchange_Module( aPcbComponent, newFootprint, m_commit );
|
2018-08-20 00:54:22 +00:00
|
|
|
return newFootprint;
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
2019-04-17 08:54:00 +00:00
|
|
|
else
|
|
|
|
delete newFootprint;
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2018-08-20 00:54:22 +00:00
|
|
|
return nullptr;
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
|
|
|
|
2016-09-02 13:53:51 +00:00
|
|
|
|
2018-08-20 00:54:22 +00:00
|
|
|
bool BOARD_NETLIST_UPDATER::updateComponentParameters( MODULE* aPcbComponent,
|
|
|
|
COMPONENT* aNewComponent )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
2017-07-19 08:55:57 +00:00
|
|
|
// Create a copy only if the module has not been added during this update
|
|
|
|
MODULE* copy = m_commit.GetStatus( aPcbComponent ) ? nullptr : (MODULE*) aPcbComponent->Clone();
|
2016-01-29 14:43:40 +00:00
|
|
|
bool changed = false;
|
2016-01-29 10:24:39 +00:00
|
|
|
|
|
|
|
// Test for reference designator field change.
|
|
|
|
if( aPcbComponent->GetReference() != aNewComponent->GetReference() )
|
|
|
|
{
|
2020-03-17 16:08:29 +00:00
|
|
|
msg.Printf( _( "Change %s reference designator to %s." ),
|
2018-08-20 00:54:22 +00:00
|
|
|
aPcbComponent->GetReference(),
|
|
|
|
aNewComponent->GetReference() );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ACTION );
|
2016-01-29 10:24:39 +00:00
|
|
|
|
|
|
|
if ( !m_isDryRun )
|
2016-01-29 14:43:40 +00:00
|
|
|
{
|
|
|
|
changed = true;
|
|
|
|
aPcbComponent->SetReference( aNewComponent->GetReference() );
|
|
|
|
}
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test for value field change.
|
|
|
|
if( aPcbComponent->GetValue() != aNewComponent->GetValue() )
|
|
|
|
{
|
2018-08-20 00:54:22 +00:00
|
|
|
msg.Printf( _( "Change %s value from %s to %s." ),
|
|
|
|
aPcbComponent->GetReference(),
|
|
|
|
aPcbComponent->GetValue(),
|
|
|
|
aNewComponent->GetValue() );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ACTION );
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2016-09-02 13:53:51 +00:00
|
|
|
if( !m_isDryRun )
|
2016-01-29 14:43:40 +00:00
|
|
|
{
|
|
|
|
changed = true;
|
2016-01-29 10:24:39 +00:00
|
|
|
aPcbComponent->SetValue( aNewComponent->GetValue() );
|
2016-01-29 14:43:40 +00:00
|
|
|
}
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test for time stamp change.
|
2020-02-20 12:11:04 +00:00
|
|
|
if( aPcbComponent->GetPath() != aNewComponent->GetPath() )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
2020-02-20 12:11:04 +00:00
|
|
|
msg.Printf( _( "Update %s symbol association from %s to %s." ),
|
2018-08-20 00:54:22 +00:00
|
|
|
aPcbComponent->GetReference(),
|
2020-02-20 12:11:04 +00:00
|
|
|
aPcbComponent->GetPath().AsString(),
|
|
|
|
aNewComponent->GetPath().AsString() );
|
2020-08-08 21:47:57 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ACTION );
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2016-09-05 13:38:01 +00:00
|
|
|
if( !m_isDryRun )
|
2016-01-29 14:43:40 +00:00
|
|
|
{
|
|
|
|
changed = true;
|
2020-02-20 12:11:04 +00:00
|
|
|
aPcbComponent->SetPath( aNewComponent->GetPath() );
|
2016-01-29 14:43:40 +00:00
|
|
|
}
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
|
|
|
|
2020-08-08 21:47:57 +00:00
|
|
|
if( aPcbComponent->GetProperties() != aNewComponent->GetProperties() )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Update %s properties." ),
|
|
|
|
aPcbComponent->GetReference() );
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ACTION );
|
|
|
|
|
|
|
|
if( !m_isDryRun )
|
|
|
|
{
|
|
|
|
changed = true;
|
|
|
|
aPcbComponent->SetProperties( aNewComponent->GetProperties() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-26 21:43:38 +00:00
|
|
|
if( ( aNewComponent->GetProperties().count( "exclude_from_bom" ) > 0 )
|
|
|
|
!= ( ( aPcbComponent->GetAttributes() & MOD_EXCLUDE_FROM_BOM ) > 0 ) )
|
|
|
|
{
|
|
|
|
int attributes = aPcbComponent->GetAttributes();
|
|
|
|
|
|
|
|
if( aNewComponent->GetProperties().count( "exclude_from_bom" ) )
|
|
|
|
{
|
|
|
|
attributes |= MOD_EXCLUDE_FROM_BOM;
|
|
|
|
msg.Printf( _( "Setting %s 'exclude from BOM' fabrication attribute." ),
|
|
|
|
aPcbComponent->GetReference() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
attributes &= ~MOD_EXCLUDE_FROM_BOM;
|
|
|
|
msg.Printf( _( "Removing %s 'exclude from BOM' fabrication attribute." ),
|
|
|
|
aPcbComponent->GetReference() );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ACTION );
|
|
|
|
|
|
|
|
if( !m_isDryRun )
|
|
|
|
{
|
|
|
|
changed = true;
|
|
|
|
aPcbComponent->SetAttributes( attributes );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-19 08:55:57 +00:00
|
|
|
if( changed && copy )
|
2016-09-05 13:38:01 +00:00
|
|
|
m_commit.Modified( aPcbComponent, copy );
|
2016-01-29 14:43:40 +00:00
|
|
|
else
|
|
|
|
delete copy;
|
|
|
|
|
2016-01-29 10:24:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-02 13:53:51 +00:00
|
|
|
|
2018-08-20 00:54:22 +00:00
|
|
|
bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE* aPcbComponent,
|
|
|
|
COMPONENT* aNewComponent )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
2017-07-19 08:55:57 +00:00
|
|
|
// Create a copy only if the module has not been added during this update
|
|
|
|
MODULE* copy = m_commit.GetStatus( aPcbComponent ) ? nullptr : (MODULE*) aPcbComponent->Clone();
|
2016-01-29 14:43:40 +00:00
|
|
|
bool changed = false;
|
|
|
|
|
2016-01-29 10:24:39 +00:00
|
|
|
// At this point, the component footprint is updated. Now update the nets.
|
2020-08-26 21:43:38 +00:00
|
|
|
for( D_PAD* pad : aPcbComponent->Pads() )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
2019-11-17 09:11:29 +00:00
|
|
|
const COMPONENT_NET& net = aNewComponent->GetNet( pad->GetName() );
|
|
|
|
|
|
|
|
wxString pinFunction;
|
|
|
|
|
|
|
|
if( net.IsValid() ) // i.e. the pad has a name
|
|
|
|
pinFunction = net.GetPinFunction();
|
|
|
|
|
|
|
|
if( !m_isDryRun )
|
|
|
|
{
|
|
|
|
if( pad->GetPinFunction() != pinFunction )
|
|
|
|
{
|
|
|
|
changed = true;
|
|
|
|
pad->SetPinFunction( pinFunction );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cachePinFunction( pad, pinFunction );
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2019-07-25 11:08:41 +00:00
|
|
|
// Test if new footprint pad has no net (pads not on copper layers have no net).
|
|
|
|
if( !net.IsValid() || !pad->IsOnCopperLayer() )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
|
|
|
if( !pad->GetNetname().IsEmpty() )
|
|
|
|
{
|
2018-08-20 00:54:22 +00:00
|
|
|
msg.Printf( _( "Disconnect %s pin %s." ),
|
|
|
|
aPcbComponent->GetReference(),
|
|
|
|
pad->GetName() );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ACTION );
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
2019-11-17 15:37:32 +00:00
|
|
|
else if( m_warnForNoNetPads && pad->IsOnCopperLayer() && !pad->GetName().IsEmpty() )
|
2019-10-24 11:54:41 +00:00
|
|
|
{
|
2019-11-17 15:37:32 +00:00
|
|
|
// pad is connectable but has no net found in netlist
|
2019-10-24 11:54:41 +00:00
|
|
|
msg.Printf( _( "No net for component %s pin %s." ),
|
|
|
|
aPcbComponent->GetReference(),
|
|
|
|
pad->GetName() );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_WARNING);
|
2019-10-24 11:54:41 +00:00
|
|
|
}
|
2019-11-17 09:11:29 +00:00
|
|
|
|
2016-01-29 10:24:39 +00:00
|
|
|
if( !m_isDryRun )
|
|
|
|
{
|
2016-01-29 14:43:40 +00:00
|
|
|
changed = true;
|
2016-01-29 10:24:39 +00:00
|
|
|
pad->SetNetCode( NETINFO_LIST::UNCONNECTED );
|
2019-11-17 09:11:29 +00:00
|
|
|
|
|
|
|
// If the pad has no net from netlist (i.e. not in netlist
|
|
|
|
// it cannot have a pin function
|
|
|
|
if( pad->GetNetname().IsEmpty() )
|
|
|
|
pad->SetPinFunction( wxEmptyString );
|
|
|
|
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
2018-05-01 12:52:11 +00:00
|
|
|
else
|
|
|
|
cacheNetname( pad, wxEmptyString );
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
|
|
|
else // New footprint pad has a net.
|
|
|
|
{
|
2018-10-18 09:35:59 +00:00
|
|
|
const wxString& netName = net.GetNetName();
|
|
|
|
NETINFO_ITEM* netinfo = m_board->FindNet( netName );
|
|
|
|
|
|
|
|
if( netinfo && !m_isDryRun )
|
|
|
|
netinfo->SetIsCurrent( true );
|
|
|
|
|
|
|
|
if( pad->GetNetname() != netName )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
|
|
|
|
2016-09-05 13:38:01 +00:00
|
|
|
if( netinfo == nullptr )
|
|
|
|
{
|
|
|
|
// It might be a new net that has not been added to the board yet
|
2018-05-01 12:52:11 +00:00
|
|
|
if( m_addedNets.count( netName ) )
|
|
|
|
netinfo = m_addedNets[ netName ];
|
2016-09-05 13:38:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( netinfo == nullptr )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
2019-04-18 02:21:23 +00:00
|
|
|
netinfo = new NETINFO_ITEM( m_board, netName );
|
|
|
|
|
2016-01-29 10:24:39 +00:00
|
|
|
// It is a new net, we have to add it
|
|
|
|
if( !m_isDryRun )
|
|
|
|
{
|
2016-01-29 14:43:40 +00:00
|
|
|
changed = true;
|
2016-09-05 13:38:01 +00:00
|
|
|
m_commit.Add( netinfo );
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
|
|
|
|
2018-10-18 09:35:59 +00:00
|
|
|
m_addedNets[netName] = netinfo;
|
2018-10-19 11:28:34 +00:00
|
|
|
msg.Printf( _( "Add net %s." ), UnescapeString( netName ) );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ACTION );
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
|
|
|
|
2016-09-02 13:53:51 +00:00
|
|
|
if( !pad->GetNetname().IsEmpty() )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
2019-03-18 23:02:24 +00:00
|
|
|
m_oldToNewNets[ pad->GetNetname() ] = netName;
|
|
|
|
|
2018-08-20 00:54:22 +00:00
|
|
|
msg.Printf( _( "Reconnect %s pin %s from %s to %s."),
|
2020-08-26 21:43:38 +00:00
|
|
|
aPcbComponent->GetReference(),
|
|
|
|
pad->GetName(),
|
|
|
|
UnescapeString( pad->GetNetname() ),
|
|
|
|
UnescapeString( netName ) );
|
2018-07-08 20:01:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-20 00:54:22 +00:00
|
|
|
msg.Printf( _( "Connect %s pin %s to %s."),
|
2020-08-26 21:43:38 +00:00
|
|
|
aPcbComponent->GetReference(),
|
|
|
|
pad->GetName(),
|
|
|
|
UnescapeString( netName ) );
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ACTION );
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2016-09-02 13:53:51 +00:00
|
|
|
if( !m_isDryRun )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
2016-01-29 14:43:40 +00:00
|
|
|
changed = true;
|
2016-09-05 13:38:01 +00:00
|
|
|
pad->SetNet( netinfo );
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
2018-05-01 12:52:11 +00:00
|
|
|
else
|
|
|
|
cacheNetname( pad, netName );
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-19 08:55:57 +00:00
|
|
|
if( changed && copy )
|
2016-09-05 13:38:01 +00:00
|
|
|
m_commit.Modified( aPcbComponent, copy );
|
2016-01-29 14:43:40 +00:00
|
|
|
else
|
|
|
|
delete copy;
|
|
|
|
|
2016-01-29 10:24:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-02 13:53:51 +00:00
|
|
|
|
2018-05-01 12:52:11 +00:00
|
|
|
void BOARD_NETLIST_UPDATER::cacheCopperZoneConnections()
|
|
|
|
{
|
2020-08-26 23:52:12 +00:00
|
|
|
for( ZONE_CONTAINER* zone : m_board->Zones() )
|
2018-05-01 12:52:11 +00:00
|
|
|
{
|
|
|
|
if( !zone->IsOnCopperLayer() || zone->GetIsKeepout() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
m_zoneConnectionsCache[ zone ] = m_board->GetConnectivity()->GetConnectedPads( zone );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool BOARD_NETLIST_UPDATER::updateCopperZoneNets( NETLIST& aNetlist )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
std::set<wxString> netlistNetnames;
|
|
|
|
|
|
|
|
for( int ii = 0; ii < (int) aNetlist.GetCount(); ii++ )
|
|
|
|
{
|
|
|
|
const COMPONENT* component = aNetlist.GetComponent( ii );
|
|
|
|
for( unsigned jj = 0; jj < component->GetNetCount(); jj++ )
|
|
|
|
{
|
|
|
|
const COMPONENT_NET& net = component->GetNet( jj );
|
|
|
|
netlistNetnames.insert( net.GetNetName() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-26 21:43:38 +00:00
|
|
|
for( TRACK* via : m_board->Tracks() )
|
2019-05-28 14:13:14 +00:00
|
|
|
{
|
|
|
|
if( via->Type() != PCB_VIA_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( netlistNetnames.count( via->GetNetname() ) == 0 )
|
|
|
|
{
|
|
|
|
wxString updatedNetname = wxEmptyString;
|
|
|
|
|
|
|
|
// Take via name from name change map if it didn't match to a new pad
|
|
|
|
// (this is useful for stitching vias that don't connect to tracks)
|
|
|
|
if( m_oldToNewNets.count( via->GetNetname() ) )
|
|
|
|
{
|
|
|
|
updatedNetname = m_oldToNewNets[via->GetNetname()];
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !updatedNetname.IsEmpty() )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Reconnect via from %s to %s." ),
|
2020-08-26 21:43:38 +00:00
|
|
|
UnescapeString( via->GetNetname() ),
|
|
|
|
UnescapeString( updatedNetname ) );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ACTION );
|
2019-05-28 14:13:14 +00:00
|
|
|
|
|
|
|
if( !m_isDryRun )
|
|
|
|
{
|
|
|
|
NETINFO_ITEM* netinfo = m_board->FindNet( updatedNetname );
|
|
|
|
|
|
|
|
if( !netinfo )
|
|
|
|
netinfo = m_addedNets[updatedNetname];
|
|
|
|
|
|
|
|
if( netinfo )
|
|
|
|
{
|
|
|
|
m_commit.Modify( via );
|
|
|
|
via->SetNet( netinfo );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Via connected to unknown net (%s)." ),
|
2020-08-26 21:43:38 +00:00
|
|
|
UnescapeString( via->GetNetname() ) );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_WARNING );
|
2019-05-28 14:13:14 +00:00
|
|
|
++m_warningCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-01 12:52:11 +00:00
|
|
|
// Test copper zones to detect "dead" nets (nets without any pad):
|
2020-08-26 23:52:12 +00:00
|
|
|
for( ZONE_CONTAINER* zone : m_board->Zones() )
|
2018-05-01 12:52:11 +00:00
|
|
|
{
|
|
|
|
if( !zone->IsOnCopperLayer() || zone->GetIsKeepout() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( netlistNetnames.count( zone->GetNetname() ) == 0 )
|
|
|
|
{
|
|
|
|
// Look for a pad in the zone's connected-pad-cache which has been updated to
|
|
|
|
// a new net and use that. While this won't always be the right net, the dead
|
|
|
|
// net is guaranteed to be wrong.
|
|
|
|
wxString updatedNetname = wxEmptyString;
|
|
|
|
|
|
|
|
for( D_PAD* pad : m_zoneConnectionsCache[ zone ] )
|
|
|
|
{
|
|
|
|
if( getNetname( pad ) != zone->GetNetname() )
|
|
|
|
{
|
|
|
|
updatedNetname = getNetname( pad );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-18 23:02:24 +00:00
|
|
|
// Take zone name from name change map if it didn't match to a new pad
|
|
|
|
// (this is useful for zones on internal layers)
|
|
|
|
if( updatedNetname.IsEmpty() && m_oldToNewNets.count( zone->GetNetname() ) )
|
|
|
|
{
|
|
|
|
updatedNetname = m_oldToNewNets[ zone->GetNetname() ];
|
|
|
|
}
|
|
|
|
|
2018-05-01 12:52:11 +00:00
|
|
|
if( !updatedNetname.IsEmpty() )
|
|
|
|
{
|
2018-08-20 00:54:22 +00:00
|
|
|
msg.Printf( _( "Reconnect copper zone from %s to %s." ),
|
2018-10-19 11:28:34 +00:00
|
|
|
UnescapeString( zone->GetNetname() ),
|
|
|
|
UnescapeString( updatedNetname ) );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ACTION );
|
2018-05-01 12:52:11 +00:00
|
|
|
|
|
|
|
if( !m_isDryRun )
|
|
|
|
{
|
|
|
|
NETINFO_ITEM* netinfo = m_board->FindNet( updatedNetname );
|
|
|
|
|
|
|
|
if( !netinfo )
|
|
|
|
netinfo = m_addedNets[ updatedNetname ];
|
|
|
|
|
|
|
|
if( netinfo )
|
|
|
|
{
|
|
|
|
m_commit.Modify( zone );
|
|
|
|
zone->SetNet( netinfo );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-19 11:28:34 +00:00
|
|
|
msg.Printf( _( "Copper zone (%s) has no pads connected." ),
|
|
|
|
UnescapeString( zone->GetNetname() ) );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_WARNING );
|
2018-05-01 12:52:11 +00:00
|
|
|
++m_warningCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-29 10:24:39 +00:00
|
|
|
bool BOARD_NETLIST_UPDATER::deleteUnusedComponents( NETLIST& aNetlist )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
const COMPONENT* component;
|
|
|
|
|
2020-08-26 21:43:38 +00:00
|
|
|
for( MODULE* module : m_board->Modules() )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
2020-08-26 21:43:38 +00:00
|
|
|
if( ( module->GetAttributes() & MOD_BOARD_ONLY ) > 0 )
|
|
|
|
continue;
|
2016-01-29 10:24:39 +00:00
|
|
|
|
|
|
|
if( m_lookupByTimestamp )
|
2020-02-20 12:11:04 +00:00
|
|
|
component = aNetlist.GetComponentByPath( module->GetPath() );
|
2016-01-29 10:24:39 +00:00
|
|
|
else
|
|
|
|
component = aNetlist.GetComponentByReference( module->GetReference() );
|
|
|
|
|
2020-08-26 21:43:38 +00:00
|
|
|
if( component == NULL || component->GetProperties().count( "exclude_from_board" ) )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
2016-09-05 13:46:29 +00:00
|
|
|
if( module->IsLocked() )
|
|
|
|
{
|
2018-11-16 09:42:03 +00:00
|
|
|
msg.Printf( _( "Cannot remove unused footprint %s (locked)." ), module->GetReference() );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_WARNING );
|
2016-09-05 13:46:29 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-11-16 09:42:03 +00:00
|
|
|
msg.Printf( _( "Remove unused footprint %s." ), module->GetReference() );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ACTION );
|
2016-01-29 10:24:39 +00:00
|
|
|
|
|
|
|
if( !m_isDryRun )
|
2016-09-05 13:38:01 +00:00
|
|
|
m_commit.Remove( module );
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-02 13:53:51 +00:00
|
|
|
|
2016-01-29 10:24:39 +00:00
|
|
|
bool BOARD_NETLIST_UPDATER::deleteSinglePadNets()
|
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
wxString netname;
|
2018-05-01 12:52:11 +00:00
|
|
|
wxString msg;
|
2016-01-29 10:24:39 +00:00
|
|
|
D_PAD* previouspad = NULL;
|
|
|
|
|
2018-05-01 12:52:11 +00:00
|
|
|
// We need the pad list for next tests.
|
2016-01-29 10:24:39 +00:00
|
|
|
|
|
|
|
m_board->BuildListOfNets();
|
|
|
|
|
|
|
|
std::vector<D_PAD*> padlist = m_board->GetPads();
|
|
|
|
|
2018-07-22 14:33:20 +00:00
|
|
|
// Sort pads by netlist name
|
2020-08-26 21:43:38 +00:00
|
|
|
std::sort( padlist.begin(), padlist.end(), [ this ]( D_PAD* a, D_PAD* b ) -> bool
|
|
|
|
{
|
|
|
|
return getNetname( a ) < getNetname( b );
|
|
|
|
} );
|
2018-05-01 12:52:11 +00:00
|
|
|
|
2018-08-20 00:54:22 +00:00
|
|
|
for( D_PAD* pad : padlist )
|
2016-05-23 15:47:16 +00:00
|
|
|
{
|
2018-05-01 12:52:11 +00:00
|
|
|
if( getNetname( pad ).IsEmpty() )
|
|
|
|
continue;
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2018-05-01 12:52:11 +00:00
|
|
|
if( netname != getNetname( pad ) ) // End of net
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
|
|
|
if( previouspad && count == 1 )
|
|
|
|
{
|
|
|
|
// First, see if we have a copper zone attached to this pad.
|
|
|
|
// If so, this is not really a single pad net
|
|
|
|
|
2018-08-20 00:54:22 +00:00
|
|
|
for( ZONE_CONTAINER* zone : m_board->Zones() )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
|
|
|
if( !zone->IsOnCopperLayer() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( zone->GetIsKeepout() )
|
|
|
|
continue;
|
|
|
|
|
2018-05-01 12:52:11 +00:00
|
|
|
if( zone->GetNetname() == getNetname( previouspad ) )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
|
|
|
count++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( count == 1 ) // Really one pad, and nothing else
|
|
|
|
{
|
2018-10-19 11:28:34 +00:00
|
|
|
msg.Printf( _( "Remove single pad net %s." ),
|
|
|
|
UnescapeString( getNetname( previouspad ) ) );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ACTION );
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2018-05-01 12:52:11 +00:00
|
|
|
if( !m_isDryRun )
|
|
|
|
previouspad->SetNetCode( NETINFO_LIST::UNCONNECTED );
|
|
|
|
else
|
|
|
|
cacheNetname( previouspad, wxEmptyString );
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-01 12:52:11 +00:00
|
|
|
netname = getNetname( pad );
|
2016-01-29 10:24:39 +00:00
|
|
|
count = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
previouspad = pad;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Examine last pad
|
2018-08-20 00:54:22 +00:00
|
|
|
if( count == 1 )
|
2018-05-01 12:52:11 +00:00
|
|
|
{
|
|
|
|
if( !m_isDryRun )
|
2018-08-20 00:54:22 +00:00
|
|
|
previouspad->SetNetCode( NETINFO_LIST::UNCONNECTED );
|
2018-05-01 12:52:11 +00:00
|
|
|
else
|
2018-08-20 00:54:22 +00:00
|
|
|
cacheNetname( previouspad, wxEmptyString );
|
2018-05-01 12:52:11 +00:00
|
|
|
}
|
2016-09-05 13:38:01 +00:00
|
|
|
|
2016-01-29 10:24:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-02 13:53:51 +00:00
|
|
|
|
2016-01-29 10:24:39 +00:00
|
|
|
bool BOARD_NETLIST_UPDATER::testConnectivity( NETLIST& aNetlist )
|
|
|
|
{
|
2018-05-01 12:52:11 +00:00
|
|
|
// Verify that board contains all pads in netlist: if it doesn't then footprints are
|
|
|
|
// wrong or missing.
|
|
|
|
// Note that we use references to find the footprints as they're already updated by this
|
|
|
|
// point (whether by-reference or by-timestamp).
|
2016-01-29 10:24:39 +00:00
|
|
|
|
|
|
|
wxString msg;
|
|
|
|
wxString padname;
|
|
|
|
|
|
|
|
for( int i = 0; i < (int) aNetlist.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
const COMPONENT* component = aNetlist.GetComponent( i );
|
|
|
|
MODULE* footprint = m_board->FindModuleByReference( component->GetReference() );
|
|
|
|
|
|
|
|
if( footprint == NULL ) // It can be missing in partial designs
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Explore all pins/pads in component
|
|
|
|
for( unsigned jj = 0; jj < component->GetNetCount(); jj++ )
|
|
|
|
{
|
2017-09-22 17:11:11 +00:00
|
|
|
const COMPONENT_NET& net = component->GetNet( jj );
|
2016-01-29 10:24:39 +00:00
|
|
|
padname = net.GetPinName();
|
|
|
|
|
|
|
|
if( footprint->FindPadByName( padname ) )
|
|
|
|
continue; // OK, pad found
|
|
|
|
|
|
|
|
// not found: bad footprint, report error
|
2018-08-20 00:54:22 +00:00
|
|
|
msg.Printf( _( "%s pad %s not found in %s." ),
|
|
|
|
component->GetReference(),
|
|
|
|
padname,
|
|
|
|
footprint->GetFPID().Format().wx_str() );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
|
2016-09-02 13:53:51 +00:00
|
|
|
++m_errorCount;
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-02 13:53:51 +00:00
|
|
|
|
2016-01-29 10:24:39 +00:00
|
|
|
bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
m_errorCount = 0;
|
|
|
|
m_warningCount = 0;
|
2019-04-17 08:54:00 +00:00
|
|
|
m_newFootprintsCount = 0;
|
2019-06-02 01:33:33 +00:00
|
|
|
MODULE* lastPreexistingFootprint = m_board->Modules().empty() ? NULL : m_board->Modules().back();
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2018-05-01 12:52:11 +00:00
|
|
|
cacheCopperZoneConnections();
|
|
|
|
|
2016-01-29 10:24:39 +00:00
|
|
|
if( !m_isDryRun )
|
|
|
|
{
|
|
|
|
m_board->SetStatus( 0 );
|
2018-10-18 09:35:59 +00:00
|
|
|
|
|
|
|
// Mark all nets (except <no net>) as stale; we'll update those to current that
|
|
|
|
// we find in the netlist
|
|
|
|
for( NETINFO_ITEM* net : m_board->GetNetInfo() )
|
|
|
|
net->SetIsCurrent( net->GetNet() == 0 );
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
|
|
|
|
2018-09-15 18:37:57 +00:00
|
|
|
for( unsigned i = 0; i < aNetlist.GetCount(); i++ )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
|
|
|
COMPONENT* component = aNetlist.GetComponent( i );
|
2018-09-15 18:37:57 +00:00
|
|
|
int matchCount = 0;
|
2018-10-02 17:17:16 +00:00
|
|
|
MODULE* tmp;
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2020-08-26 21:43:38 +00:00
|
|
|
if( component->GetProperties().count( "exclude_from_board" ) )
|
|
|
|
continue;
|
|
|
|
|
2020-02-20 12:11:04 +00:00
|
|
|
msg.Printf( _( "Processing component \"%s:%s\"." ),
|
2018-08-20 00:54:22 +00:00
|
|
|
component->GetReference(),
|
|
|
|
component->GetFPID().Format().wx_str() );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_INFO );
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2019-05-31 00:15:57 +00:00
|
|
|
for( auto footprint : m_board->Modules() )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
2018-09-21 07:58:50 +00:00
|
|
|
bool match = false;
|
2018-09-15 18:37:57 +00:00
|
|
|
|
2018-09-21 07:58:50 +00:00
|
|
|
if( footprint )
|
|
|
|
{
|
2019-05-27 21:18:01 +00:00
|
|
|
if( m_lookupByTimestamp )
|
2020-02-20 12:11:04 +00:00
|
|
|
match = footprint->GetPath() == component->GetPath();
|
2018-09-21 07:58:50 +00:00
|
|
|
else
|
2018-09-23 22:49:03 +00:00
|
|
|
match = footprint->GetReference().CmpNoCase( component->GetReference() ) == 0;
|
2018-09-21 07:58:50 +00:00
|
|
|
}
|
2018-09-15 18:37:57 +00:00
|
|
|
|
|
|
|
if( match )
|
|
|
|
{
|
|
|
|
tmp = footprint;
|
|
|
|
|
|
|
|
if( m_replaceFootprints && component->GetFPID() != footprint->GetFPID() )
|
|
|
|
tmp = replaceComponent( aNetlist, footprint, component );
|
|
|
|
|
|
|
|
if( tmp )
|
|
|
|
{
|
|
|
|
updateComponentParameters( tmp, component );
|
|
|
|
updateComponentPadConnections( tmp, component );
|
|
|
|
}
|
|
|
|
|
|
|
|
matchCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( footprint == lastPreexistingFootprint )
|
|
|
|
{
|
2018-09-21 07:58:50 +00:00
|
|
|
// No sense going through the newly-created footprints: end of loop
|
2018-09-15 18:37:57 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
|
|
|
|
2018-10-02 17:17:16 +00:00
|
|
|
if( matchCount == 0 )
|
|
|
|
{
|
|
|
|
tmp = addNewComponent( component );
|
|
|
|
|
|
|
|
if( tmp )
|
|
|
|
{
|
|
|
|
updateComponentParameters( tmp, component );
|
|
|
|
updateComponentPadConnections( tmp, component );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( matchCount > 1 )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
2018-09-15 18:37:57 +00:00
|
|
|
msg.Printf( _( "Multiple footprints found for \"%s\"." ),
|
|
|
|
component->GetReference() );
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-01 12:52:11 +00:00
|
|
|
updateCopperZoneNets( aNetlist );
|
2016-01-29 10:24:39 +00:00
|
|
|
|
|
|
|
if( m_deleteUnusedComponents )
|
|
|
|
deleteUnusedComponents( aNetlist );
|
|
|
|
|
2016-09-05 13:38:01 +00:00
|
|
|
if( !m_isDryRun )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
2017-03-22 13:43:10 +00:00
|
|
|
m_board->GetConnectivity()->Build( m_board );
|
2016-01-29 14:43:40 +00:00
|
|
|
testConnectivity( aNetlist );
|
2019-04-17 08:54:00 +00:00
|
|
|
|
|
|
|
// Now the connectivity data is rebuilt, we can delete single pads nets
|
|
|
|
if( m_deleteSinglePadNets )
|
|
|
|
deleteSinglePadNets();
|
2020-07-13 21:35:05 +00:00
|
|
|
|
|
|
|
for( NETINFO_ITEM* net : m_board->GetNetInfo() )
|
|
|
|
{
|
|
|
|
if( !net->IsCurrent() )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Remove unused net \"%s\"." ), net->GetNetname() );
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ACTION );
|
|
|
|
m_commit.Removed( net );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_board->GetNetInfo().RemoveUnusedNets();
|
|
|
|
m_commit.Push( _( "Update netlist" ) );
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
2019-04-17 08:54:00 +00:00
|
|
|
else if( m_deleteSinglePadNets && !m_newFootprintsCount )
|
|
|
|
// We can delete single net pads in dry run mode only if no new footprints
|
|
|
|
// are added, because these new footprints are not actually added to the board
|
|
|
|
// and the current pad list is wrong in this case.
|
|
|
|
deleteSinglePadNets();
|
|
|
|
|
2019-04-18 02:21:23 +00:00
|
|
|
if( m_isDryRun )
|
|
|
|
{
|
2019-12-05 15:20:59 +00:00
|
|
|
for( const auto& it : m_addedNets )
|
2019-04-18 02:21:23 +00:00
|
|
|
delete it.second;
|
|
|
|
|
|
|
|
m_addedNets.clear();
|
|
|
|
}
|
2016-01-29 10:24:39 +00:00
|
|
|
|
|
|
|
// Update the ratsnest
|
2020-03-04 09:48:18 +00:00
|
|
|
m_reporter->ReportTail( wxT( "" ), RPT_SEVERITY_ACTION );
|
|
|
|
m_reporter->ReportTail( wxT( "" ), RPT_SEVERITY_ACTION );
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2016-09-02 13:53:51 +00:00
|
|
|
msg.Printf( _( "Total warnings: %d, errors: %d." ), m_warningCount, m_errorCount );
|
2020-06-01 19:36:58 +00:00
|
|
|
m_reporter->ReportTail( msg, RPT_SEVERITY_INFO );
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2016-09-02 13:53:51 +00:00
|
|
|
if( m_errorCount )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
2018-08-20 00:54:22 +00:00
|
|
|
m_reporter->ReportTail( _( "Errors occurred during the netlist update. Unless you fix them "
|
|
|
|
"your board will not be consistent with the schematics." ),
|
2020-03-04 09:48:18 +00:00
|
|
|
RPT_SEVERITY_ERROR );
|
2016-01-29 10:24:39 +00:00
|
|
|
return false;
|
2016-09-02 13:53:51 +00:00
|
|
|
}
|
2016-01-29 10:24:39 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|