2016-01-29 10:24:39 +00:00
|
|
|
/*
|
|
|
|
* 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>
|
2021-07-19 23:56:05 +00:00
|
|
|
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
|
2016-01-29 10:24:39 +00:00
|
|
|
*
|
2022-08-26 08:38:36 +00:00
|
|
|
* Copyright (C) 1992-2022 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
|
|
|
|
|
2022-08-27 17:23:43 +00:00
|
|
|
#include <base_units.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2018-01-30 14:34:09 +00:00
|
|
|
#include <netinfo.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <footprint.h>
|
|
|
|
#include <pad.h>
|
2021-06-11 21:07:02 +00:00
|
|
|
#include <pcb_track.h>
|
2020-11-11 23:05:59 +00:00
|
|
|
#include <zone.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2021-01-25 01:19:35 +00:00
|
|
|
#include <pcbnew_settings.h>
|
|
|
|
#include <pcb_edit_frame.h>
|
|
|
|
#include <netlist_reader/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
|
|
|
|
|
|
|
|
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
|
|
|
|
2021-05-23 21:21:34 +00:00
|
|
|
m_deleteUnusedFootprints = false;
|
2016-09-02 13:53:51 +00:00
|
|
|
m_isDryRun = false;
|
|
|
|
m_replaceFootprints = true;
|
|
|
|
m_lookupByTimestamp = 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.
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
void BOARD_NETLIST_UPDATER::cacheNetname( PAD* aPad, const wxString& aNetname )
|
2018-05-01 12:52:11 +00:00
|
|
|
{
|
|
|
|
m_padNets[ aPad ] = aNetname;
|
|
|
|
}
|
|
|
|
|
2019-11-17 09:11:29 +00:00
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
wxString BOARD_NETLIST_UPDATER::getNetname( PAD* aPad )
|
2018-05-01 12:52:11 +00:00
|
|
|
{
|
|
|
|
if( m_isDryRun && m_padNets.count( aPad ) )
|
|
|
|
return m_padNets[ aPad ];
|
|
|
|
else
|
|
|
|
return aPad->GetNetname();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
void BOARD_NETLIST_UPDATER::cachePinFunction( PAD* aPad, const wxString& aPinFunction )
|
2019-11-17 09:11:29 +00:00
|
|
|
{
|
|
|
|
m_padPinFunctions[ aPad ] = aPinFunction;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
wxString BOARD_NETLIST_UPDATER::getPinFunction( PAD* aPad )
|
2019-11-17 09:11:29 +00:00
|
|
|
{
|
|
|
|
if( m_isDryRun && m_padPinFunctions.count( aPad ) )
|
|
|
|
return m_padPinFunctions[ aPad ];
|
|
|
|
else
|
|
|
|
return aPad->GetPinFunction();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-30 23:28:18 +00:00
|
|
|
VECTOR2I BOARD_NETLIST_UPDATER::estimateFootprintInsertionPosition()
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
2022-08-30 23:28:18 +00:00
|
|
|
VECTOR2I bestPosition;
|
2016-01-29 10:24:39 +00:00
|
|
|
|
|
|
|
if( !m_board->IsEmpty() )
|
|
|
|
{
|
|
|
|
// Position new components below any existing board features.
|
2022-08-30 23:28:18 +00:00
|
|
|
BOX2I bbox = m_board->GetBoardEdgesBoundingBox();
|
2016-01-29 10:24:39 +00:00
|
|
|
|
|
|
|
if( bbox.GetWidth() || bbox.GetHeight() )
|
|
|
|
{
|
|
|
|
bestPosition.x = bbox.Centre().x;
|
2022-09-16 11:33:56 +00:00
|
|
|
bestPosition.y = bbox.GetBottom() + pcbIUScale.mmToIU( 10 );
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Position new components in the center of the page when the board is empty.
|
2022-09-16 23:25:07 +00:00
|
|
|
wxSize pageSize = m_board->GetPageSettings().GetSizeIU( pcbIUScale.IU_PER_MILS );
|
2016-01-29 10:24:39 +00:00
|
|
|
|
|
|
|
bestPosition.x = pageSize.GetWidth() / 2;
|
|
|
|
bestPosition.y = pageSize.GetHeight() / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bestPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-23 21:21:34 +00:00
|
|
|
FOOTPRINT* BOARD_NETLIST_UPDATER::addNewFootprint( COMPONENT* aComponent )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* 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 )
|
|
|
|
{
|
2021-06-07 22:14:29 +00:00
|
|
|
msg.Printf( _( "Cannot add %s (footprint '%s' not found)." ),
|
2018-08-20 00:54:22 +00:00
|
|
|
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
|
|
|
|
2021-03-11 12:33:06 +00:00
|
|
|
if( m_isDryRun )
|
2021-01-25 01:19:35 +00:00
|
|
|
{
|
2021-06-07 22:14:29 +00:00
|
|
|
msg.Printf( _( "Add %s (footprint '%s')." ),
|
2021-03-11 12:33:06 +00:00
|
|
|
aComponent->GetReference(),
|
|
|
|
aComponent->GetFPID().Format().wx_str() );
|
2021-01-25 01:19:35 +00:00
|
|
|
|
2021-03-11 12:33:06 +00:00
|
|
|
delete footprint;
|
|
|
|
footprint = nullptr;
|
2021-01-25 01:19:35 +00:00
|
|
|
}
|
2021-03-11 12:33:06 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
for( PAD* pad : footprint->Pads() )
|
|
|
|
{
|
|
|
|
// Set the pads ratsnest settings to the global settings
|
2022-07-24 15:49:46 +00:00
|
|
|
pad->SetLocalRatsnestVisible( m_frame->GetPcbNewSettings()->m_Display.m_ShowGlobalRatsnest );
|
2019-11-07 01:04:00 +00:00
|
|
|
|
2021-03-11 12:33:06 +00:00
|
|
|
// Pads in the library all have orphaned nets. Replace with Default.
|
|
|
|
pad->SetNetCode( 0 );
|
|
|
|
}
|
2019-04-17 08:54:00 +00:00
|
|
|
|
2018-08-20 00:54:22 +00:00
|
|
|
footprint->SetParent( m_board );
|
2021-05-23 21:21:34 +00:00
|
|
|
footprint->SetPosition( estimateFootprintInsertionPosition() );
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2021-12-09 01:38:59 +00:00
|
|
|
// This flag is used to prevent connectivity from considering the footprint during its
|
|
|
|
// initial build after the footprint is committed, because we're going to immediately start
|
|
|
|
// a move operation on the footprint and don't want its pads to drive nets onto vias/tracks
|
|
|
|
// it happens to land on at the initial position.
|
|
|
|
footprint->SetAttributes( footprint->GetAttributes() | FP_JUST_ADDED );
|
|
|
|
|
2021-05-23 21:21:34 +00:00
|
|
|
m_addedFootprints.push_back( footprint );
|
2018-08-20 00:54:22 +00:00
|
|
|
m_commit.Add( footprint );
|
|
|
|
|
2021-06-07 22:14:29 +00:00
|
|
|
msg.Printf( _( "Added %s (footprint '%s')." ),
|
2021-03-11 12:33:06 +00:00
|
|
|
aComponent->GetReference(),
|
|
|
|
aComponent->GetFPID().Format().wx_str() );
|
2021-01-25 01:19:35 +00:00
|
|
|
}
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2021-03-11 12:33:06 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ACTION );
|
|
|
|
m_newFootprintsCount++;
|
|
|
|
return footprint;
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
|
|
|
|
2016-09-02 13:53:51 +00:00
|
|
|
|
2021-05-23 21:21:34 +00:00
|
|
|
FOOTPRINT* BOARD_NETLIST_UPDATER::replaceFootprint( NETLIST& aNetlist, FOOTPRINT* aFootprint,
|
2020-11-13 15:15:52 +00:00
|
|
|
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
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* 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
|
|
|
{
|
2021-06-07 22:14:29 +00:00
|
|
|
msg.Printf( _( "Cannot update %s (footprint '%s' not found)." ),
|
2018-08-20 00:54:22 +00:00
|
|
|
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
|
|
|
|
2021-03-11 12:33:06 +00:00
|
|
|
if( m_isDryRun )
|
2018-08-20 00:54:22 +00:00
|
|
|
{
|
2021-03-11 12:33:06 +00:00
|
|
|
msg.Printf( _( "Change %s footprint from '%s' to '%s'."),
|
2021-05-23 21:21:34 +00:00
|
|
|
aFootprint->GetReference(),
|
|
|
|
aFootprint->GetFPID().Format().wx_str(),
|
2021-03-11 12:33:06 +00:00
|
|
|
aNewComponent->GetFPID().Format().wx_str() );
|
|
|
|
|
|
|
|
delete newFootprint;
|
|
|
|
newFootprint = nullptr;
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
2019-04-17 08:54:00 +00:00
|
|
|
else
|
2020-11-13 17:04:34 +00:00
|
|
|
{
|
2021-05-23 21:21:34 +00:00
|
|
|
m_frame->ExchangeFootprint( aFootprint, newFootprint, m_commit );
|
2021-03-11 12:33:06 +00:00
|
|
|
|
|
|
|
msg.Printf( _( "Changed %s footprint from '%s' to '%s'."),
|
2021-05-23 21:21:34 +00:00
|
|
|
aFootprint->GetReference(),
|
|
|
|
aFootprint->GetFPID().Format().wx_str(),
|
2021-03-11 12:33:06 +00:00
|
|
|
aNewComponent->GetFPID().Format().wx_str() );
|
2020-11-13 17:04:34 +00:00
|
|
|
}
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2021-03-11 12:33:06 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ACTION );
|
|
|
|
m_newFootprintsCount++;
|
|
|
|
return newFootprint;
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
|
|
|
|
2016-09-02 13:53:51 +00:00
|
|
|
|
2020-12-07 15:50:04 +00:00
|
|
|
bool BOARD_NETLIST_UPDATER::updateFootprintParameters( FOOTPRINT* aPcbFootprint,
|
|
|
|
COMPONENT* aNetlistComponent )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
2020-11-10 21:20:03 +00:00
|
|
|
// Create a copy only if the footprint has not been added during this update
|
2020-12-07 15:50:04 +00:00
|
|
|
FOOTPRINT* copy = m_commit.GetStatus( aPcbFootprint ) ? nullptr
|
|
|
|
: (FOOTPRINT*) aPcbFootprint->Clone();
|
2020-11-13 15:15:52 +00:00
|
|
|
bool changed = false;
|
2016-01-29 10:24:39 +00:00
|
|
|
|
|
|
|
// Test for reference designator field change.
|
2020-12-07 15:50:04 +00:00
|
|
|
if( aPcbFootprint->GetReference() != aNetlistComponent->GetReference() )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
2021-03-11 12:33:06 +00:00
|
|
|
if( m_isDryRun )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Change %s reference designator to %s." ),
|
|
|
|
aPcbFootprint->GetReference(),
|
|
|
|
aNetlistComponent->GetReference() );
|
|
|
|
}
|
|
|
|
else
|
2016-01-29 14:43:40 +00:00
|
|
|
{
|
2021-03-11 12:33:06 +00:00
|
|
|
msg.Printf( _( "Changed %s reference designator to %s." ),
|
|
|
|
aPcbFootprint->GetReference(),
|
|
|
|
aNetlistComponent->GetReference() );
|
2021-04-13 12:43:02 +00:00
|
|
|
|
|
|
|
changed = true;
|
|
|
|
aPcbFootprint->SetReference( aNetlistComponent->GetReference() );
|
2016-01-29 14:43:40 +00:00
|
|
|
}
|
2021-03-11 12:33:06 +00:00
|
|
|
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ACTION );
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test for value field change.
|
2020-12-07 15:50:04 +00:00
|
|
|
if( aPcbFootprint->GetValue() != aNetlistComponent->GetValue() )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
2021-03-11 12:33:06 +00:00
|
|
|
if( m_isDryRun )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Change %s value from %s to %s." ),
|
|
|
|
aPcbFootprint->GetReference(),
|
|
|
|
aPcbFootprint->GetValue(),
|
|
|
|
aNetlistComponent->GetValue() );
|
|
|
|
}
|
|
|
|
else
|
2016-01-29 14:43:40 +00:00
|
|
|
{
|
2021-03-11 12:33:06 +00:00
|
|
|
msg.Printf( _( "Changed %s value from %s to %s." ),
|
|
|
|
aPcbFootprint->GetReference(),
|
|
|
|
aPcbFootprint->GetValue(),
|
|
|
|
aNetlistComponent->GetValue() );
|
2021-04-13 12:43:02 +00:00
|
|
|
|
|
|
|
changed = true;
|
|
|
|
aPcbFootprint->SetValue( aNetlistComponent->GetValue() );
|
2016-01-29 14:43:40 +00:00
|
|
|
}
|
2021-03-11 12:33:06 +00:00
|
|
|
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ACTION );
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test for time stamp change.
|
2021-02-21 04:03:56 +00:00
|
|
|
KIID_PATH new_path = aNetlistComponent->GetPath();
|
2021-04-25 13:13:42 +00:00
|
|
|
|
|
|
|
if( !aNetlistComponent->GetKIIDs().empty() )
|
|
|
|
new_path.push_back( aNetlistComponent->GetKIIDs().front() );
|
2021-02-21 04:03:56 +00:00
|
|
|
|
|
|
|
if( aPcbFootprint->GetPath() != new_path )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
2021-03-11 12:33:06 +00:00
|
|
|
if( m_isDryRun )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Update %s symbol association from %s to %s." ),
|
|
|
|
aPcbFootprint->GetReference(),
|
|
|
|
aPcbFootprint->GetPath().AsString(),
|
|
|
|
new_path.AsString() );
|
|
|
|
}
|
|
|
|
else
|
2016-01-29 14:43:40 +00:00
|
|
|
{
|
2021-03-11 12:33:06 +00:00
|
|
|
msg.Printf( _( "Updated %s symbol association from %s to %s." ),
|
|
|
|
aPcbFootprint->GetReference(),
|
|
|
|
aPcbFootprint->GetPath().AsString(),
|
|
|
|
new_path.AsString() );
|
2021-04-13 12:43:02 +00:00
|
|
|
|
|
|
|
changed = true;
|
|
|
|
aPcbFootprint->SetPath( new_path );
|
2016-01-29 14:43:40 +00:00
|
|
|
}
|
2021-03-11 12:33:06 +00:00
|
|
|
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ACTION );
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 15:50:04 +00:00
|
|
|
if( aPcbFootprint->GetProperties() != aNetlistComponent->GetProperties() )
|
2020-08-08 21:47:57 +00:00
|
|
|
{
|
2021-03-11 12:33:06 +00:00
|
|
|
if( m_isDryRun )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Update %s properties." ),
|
|
|
|
aPcbFootprint->GetReference() );
|
|
|
|
}
|
|
|
|
else
|
2020-08-08 21:47:57 +00:00
|
|
|
{
|
2021-03-11 12:33:06 +00:00
|
|
|
msg.Printf( _( "Updated %s properties." ),
|
|
|
|
aPcbFootprint->GetReference() );
|
2021-04-13 12:43:02 +00:00
|
|
|
|
|
|
|
changed = true;
|
|
|
|
aPcbFootprint->SetProperties( aNetlistComponent->GetProperties() );
|
2020-08-08 21:47:57 +00:00
|
|
|
}
|
2021-03-11 12:33:06 +00:00
|
|
|
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ACTION );
|
2020-08-08 21:47:57 +00:00
|
|
|
}
|
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
if( ( aNetlistComponent->GetProperties().count( wxT( "exclude_from_bom" ) ) > 0 )
|
2020-12-07 15:50:04 +00:00
|
|
|
!= ( ( aPcbFootprint->GetAttributes() & FP_EXCLUDE_FROM_BOM ) > 0 ) )
|
2020-08-26 21:43:38 +00:00
|
|
|
{
|
2021-03-11 12:33:06 +00:00
|
|
|
if( m_isDryRun )
|
2020-08-26 21:43:38 +00:00
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
if( aNetlistComponent->GetProperties().count( wxT( "exclude_from_bom" ) ) )
|
2021-03-11 12:33:06 +00:00
|
|
|
{
|
2021-03-12 14:58:35 +00:00
|
|
|
msg.Printf( _( "Add %s 'exclude from BOM' fabrication attribute." ),
|
2021-03-11 12:33:06 +00:00
|
|
|
aPcbFootprint->GetReference() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Remove %s 'exclude from BOM' fabrication attribute." ),
|
|
|
|
aPcbFootprint->GetReference() );
|
|
|
|
}
|
2020-08-26 21:43:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-11 12:33:06 +00:00
|
|
|
int attributes = aPcbFootprint->GetAttributes();
|
2020-08-26 21:43:38 +00:00
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
if( aNetlistComponent->GetProperties().count( wxT( "exclude_from_bom" ) ) )
|
2021-03-11 12:33:06 +00:00
|
|
|
{
|
|
|
|
attributes |= FP_EXCLUDE_FROM_BOM;
|
2021-03-12 14:58:35 +00:00
|
|
|
msg.Printf( _( "Added %s 'exclude from BOM' fabrication attribute." ),
|
2021-03-11 12:33:06 +00:00
|
|
|
aPcbFootprint->GetReference() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
attributes &= ~FP_EXCLUDE_FROM_BOM;
|
|
|
|
msg.Printf( _( "Removed %s 'exclude from BOM' fabrication attribute." ),
|
|
|
|
aPcbFootprint->GetReference() );
|
|
|
|
}
|
2020-08-26 21:43:38 +00:00
|
|
|
|
|
|
|
changed = true;
|
2020-12-07 15:50:04 +00:00
|
|
|
aPcbFootprint->SetAttributes( attributes );
|
2020-08-26 21:43:38 +00:00
|
|
|
}
|
2021-03-11 12:33:06 +00:00
|
|
|
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ACTION );
|
2020-08-26 21:43:38 +00:00
|
|
|
}
|
|
|
|
|
2022-09-16 16:20:36 +00:00
|
|
|
if( ( aNetlistComponent->GetProperties().count( wxT( "dnp" ) ) > 0 )
|
|
|
|
!= ( ( aPcbFootprint->GetAttributes() & FP_EXCLUDE_FROM_POS_FILES ) > 0 ) )
|
|
|
|
{
|
|
|
|
if( m_isDryRun )
|
|
|
|
{
|
|
|
|
if( aNetlistComponent->GetProperties().count( wxT( "dnp" ) ) )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Add %s 'exclude from position files' fabrication attribute." ),
|
|
|
|
aPcbFootprint->GetReference() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Remove %s 'exclude from position files' fabrication attribute." ),
|
|
|
|
aPcbFootprint->GetReference() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int attributes = aPcbFootprint->GetAttributes();
|
|
|
|
|
|
|
|
if( aNetlistComponent->GetProperties().count( wxT( "dnp" ) ) )
|
|
|
|
{
|
|
|
|
attributes |= FP_EXCLUDE_FROM_POS_FILES;
|
|
|
|
msg.Printf( _( "Added %s 'exclude from position files' fabrication attribute." ),
|
|
|
|
aPcbFootprint->GetReference() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
attributes &= ~FP_EXCLUDE_FROM_POS_FILES;
|
|
|
|
msg.Printf( _( "Removed %s 'exclude from position files' fabrication attribute." ),
|
|
|
|
aPcbFootprint->GetReference() );
|
|
|
|
}
|
|
|
|
|
|
|
|
changed = true;
|
|
|
|
aPcbFootprint->SetAttributes( attributes );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ACTION );
|
|
|
|
}
|
|
|
|
|
2017-07-19 08:55:57 +00:00
|
|
|
if( changed && copy )
|
2020-12-07 15:50:04 +00:00
|
|
|
m_commit.Modified( aPcbFootprint, 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
|
|
|
|
2021-01-15 12:30:22 +00:00
|
|
|
bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( FOOTPRINT* aFootprint,
|
2018-08-20 00:54:22 +00:00
|
|
|
COMPONENT* aNewComponent )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
2020-11-10 21:20:03 +00:00
|
|
|
// Create a copy only if the footprint has not been added during this update
|
2021-01-15 12:30:22 +00:00
|
|
|
FOOTPRINT* copy = m_commit.GetStatus( aFootprint ) ? nullptr : (FOOTPRINT*) aFootprint->Clone();
|
2020-11-13 15:15:52 +00:00
|
|
|
bool changed = false;
|
2016-01-29 14:43:40 +00:00
|
|
|
|
2016-01-29 10:24:39 +00:00
|
|
|
// At this point, the component footprint is updated. Now update the nets.
|
2021-01-15 12:30:22 +00:00
|
|
|
for( PAD* pad : aFootprint->Pads() )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
2021-08-23 23:10:21 +00:00
|
|
|
const COMPONENT_NET& net = aNewComponent->GetNet( pad->GetNumber() );
|
2019-11-17 09:11:29 +00:00
|
|
|
|
|
|
|
wxString pinFunction;
|
2021-01-21 21:46:03 +00:00
|
|
|
wxString pinType;
|
2019-11-17 09:11:29 +00:00
|
|
|
|
|
|
|
if( net.IsValid() ) // i.e. the pad has a name
|
2021-01-21 21:46:03 +00:00
|
|
|
{
|
2019-11-17 09:11:29 +00:00
|
|
|
pinFunction = net.GetPinFunction();
|
2021-01-21 21:46:03 +00:00
|
|
|
pinType = net.GetPinType();
|
|
|
|
}
|
2019-11-17 09:11:29 +00:00
|
|
|
|
|
|
|
if( !m_isDryRun )
|
|
|
|
{
|
|
|
|
if( pad->GetPinFunction() != pinFunction )
|
|
|
|
{
|
|
|
|
changed = true;
|
|
|
|
pad->SetPinFunction( pinFunction );
|
|
|
|
}
|
2021-01-21 21:46:03 +00:00
|
|
|
|
|
|
|
if( pad->GetPinType() != pinType )
|
|
|
|
{
|
|
|
|
changed = true;
|
|
|
|
pad->SetPinType( pinType );
|
|
|
|
}
|
2019-11-17 09:11:29 +00:00
|
|
|
}
|
|
|
|
else
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2019-11-17 09:11:29 +00:00
|
|
|
cachePinFunction( pad, pinFunction );
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
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() )
|
|
|
|
{
|
2021-03-11 12:33:06 +00:00
|
|
|
if( m_isDryRun )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Disconnect %s pin %s." ),
|
|
|
|
aFootprint->GetReference(),
|
2021-08-23 23:10:21 +00:00
|
|
|
pad->GetNumber() );
|
2021-03-11 12:33:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Disconnected %s pin %s." ),
|
|
|
|
aFootprint->GetReference(),
|
2021-08-23 23:10:21 +00:00
|
|
|
pad->GetNumber() );
|
2021-03-11 12:33:06 +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
|
|
|
}
|
2021-09-18 17:30:58 +00:00
|
|
|
else if( pad->IsOnCopperLayer() && !pad->GetNumber().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
|
2021-03-11 12:33:06 +00:00
|
|
|
msg.Printf( _( "No net found for symbol %s pin %s." ),
|
2021-01-15 12:30:22 +00:00
|
|
|
aFootprint->GetReference(),
|
2021-08-23 23:10:21 +00:00
|
|
|
pad->GetNumber() );
|
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
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2018-05-01 12:52:11 +00:00
|
|
|
cacheNetname( pad, wxEmptyString );
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
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;
|
|
|
|
|
2021-03-11 12:33:06 +00:00
|
|
|
if( m_isDryRun )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Reconnect %s pin %s from %s to %s."),
|
|
|
|
aFootprint->GetReference(),
|
2021-08-23 23:10:21 +00:00
|
|
|
pad->GetNumber(),
|
2021-03-11 12:33:06 +00:00
|
|
|
UnescapeString( pad->GetNetname() ),
|
|
|
|
UnescapeString( netName ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Reconnected %s pin %s from %s to %s."),
|
|
|
|
aFootprint->GetReference(),
|
2021-08-23 23:10:21 +00:00
|
|
|
pad->GetNumber(),
|
2021-03-11 12:33:06 +00:00
|
|
|
UnescapeString( pad->GetNetname() ),
|
|
|
|
UnescapeString( netName ) );
|
|
|
|
}
|
2018-07-08 20:01:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-11 12:33:06 +00:00
|
|
|
if( m_isDryRun )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Connect %s pin %s to %s."),
|
|
|
|
aFootprint->GetReference(),
|
2021-08-23 23:10:21 +00:00
|
|
|
pad->GetNumber(),
|
2021-03-11 12:33:06 +00:00
|
|
|
UnescapeString( netName ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Connected %s pin %s to %s."),
|
|
|
|
aFootprint->GetReference(),
|
2021-08-23 23:10:21 +00:00
|
|
|
pad->GetNumber(),
|
2021-03-11 12:33:06 +00:00
|
|
|
UnescapeString( netName ) );
|
|
|
|
}
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
2021-03-11 12:33:06 +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
|
2021-03-11 12:33:06 +00:00
|
|
|
{
|
2018-05-01 12:52:11 +00:00
|
|
|
cacheNetname( pad, netName );
|
2021-03-11 12:33:06 +00:00
|
|
|
}
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-19 08:55:57 +00:00
|
|
|
if( changed && copy )
|
2021-01-15 12:30:22 +00:00
|
|
|
m_commit.Modified( aFootprint, 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-11-11 23:05:59 +00:00
|
|
|
for( ZONE* zone : m_board->Zones() )
|
2018-05-01 12:52:11 +00:00
|
|
|
{
|
2020-09-21 23:32:07 +00:00
|
|
|
if( !zone->IsOnCopperLayer() || zone->GetIsRuleArea() )
|
2018-05-01 12:52:11 +00:00
|
|
|
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 );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2018-05-01 12:52:11 +00:00
|
|
|
for( unsigned jj = 0; jj < component->GetNetCount(); jj++ )
|
|
|
|
{
|
|
|
|
const COMPONENT_NET& net = component->GetNet( jj );
|
|
|
|
netlistNetnames.insert( net.GetNetName() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_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() )
|
|
|
|
{
|
2021-03-11 12:33:06 +00:00
|
|
|
if( m_isDryRun )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Reconnect via from %s to %s." ),
|
|
|
|
UnescapeString( via->GetNetname() ),
|
|
|
|
UnescapeString( updatedNetname ) );
|
2019-05-28 14:13:14 +00:00
|
|
|
|
2021-03-11 12:33:06 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ACTION );
|
|
|
|
}
|
|
|
|
else
|
2019-05-28 14:13:14 +00:00
|
|
|
{
|
|
|
|
NETINFO_ITEM* netinfo = m_board->FindNet( updatedNetname );
|
|
|
|
|
|
|
|
if( !netinfo )
|
|
|
|
netinfo = m_addedNets[updatedNetname];
|
|
|
|
|
|
|
|
if( netinfo )
|
|
|
|
{
|
|
|
|
m_commit.Modify( via );
|
|
|
|
via->SetNet( netinfo );
|
2021-03-11 12:33:06 +00:00
|
|
|
|
|
|
|
msg.Printf( _( "Reconnected via from %s to %s." ),
|
|
|
|
UnescapeString( via->GetNetname() ),
|
|
|
|
UnescapeString( updatedNetname ) );
|
|
|
|
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ACTION );
|
2019-05-28 14:13:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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-11-11 23:05:59 +00:00
|
|
|
for( ZONE* zone : m_board->Zones() )
|
2018-05-01 12:52:11 +00:00
|
|
|
{
|
2020-09-21 23:32:07 +00:00
|
|
|
if( !zone->IsOnCopperLayer() || zone->GetIsRuleArea() )
|
2018-05-01 12:52:11 +00:00
|
|
|
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;
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : m_zoneConnectionsCache[ zone ] )
|
2018-05-01 12:52:11 +00:00
|
|
|
{
|
|
|
|
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() )
|
|
|
|
{
|
2021-03-11 12:33:06 +00:00
|
|
|
if( m_isDryRun )
|
|
|
|
{
|
|
|
|
if( !zone->GetZoneName().IsEmpty() )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Reconnect copper zone '%s' from %s to %s." ),
|
|
|
|
zone->GetZoneName(),
|
|
|
|
UnescapeString( zone->GetNetname() ),
|
|
|
|
UnescapeString( updatedNetname ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Reconnect copper zone from %s to %s." ),
|
|
|
|
UnescapeString( zone->GetNetname() ),
|
|
|
|
UnescapeString( updatedNetname ) );
|
|
|
|
}
|
2018-05-01 12:52:11 +00:00
|
|
|
|
2021-03-11 12:33:06 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ACTION );
|
|
|
|
}
|
|
|
|
else
|
2018-05-01 12:52:11 +00:00
|
|
|
{
|
|
|
|
NETINFO_ITEM* netinfo = m_board->FindNet( updatedNetname );
|
|
|
|
|
|
|
|
if( !netinfo )
|
|
|
|
netinfo = m_addedNets[ updatedNetname ];
|
|
|
|
|
|
|
|
if( netinfo )
|
|
|
|
{
|
|
|
|
m_commit.Modify( zone );
|
|
|
|
zone->SetNet( netinfo );
|
2021-03-11 12:33:06 +00:00
|
|
|
|
|
|
|
if( !zone->GetZoneName().IsEmpty() )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Reconnected copper zone '%s' from %s to %s." ),
|
|
|
|
zone->GetZoneName(),
|
|
|
|
UnescapeString( zone->GetNetname() ),
|
|
|
|
UnescapeString( updatedNetname ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Reconnected copper zone from %s to %s." ),
|
|
|
|
UnescapeString( zone->GetNetname() ),
|
|
|
|
UnescapeString( updatedNetname ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ACTION );
|
2018-05-01 12:52:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-11 12:33:06 +00:00
|
|
|
if( !zone->GetZoneName().IsEmpty() )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Copper zone '%s' has no pads connected." ),
|
|
|
|
zone->GetZoneName() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PCB_LAYER_ID layer = zone->GetLayer();
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I pos = zone->GetPosition();
|
2021-03-11 12:33:06 +00:00
|
|
|
|
|
|
|
msg.Printf( _( "Copper zone on layer %s at (%s, %s) has no pads connected." ),
|
|
|
|
m_board->GetLayerName( layer ),
|
2022-09-19 09:25:20 +00:00
|
|
|
m_frame->MessageTextFromValue( pos.x ),
|
|
|
|
m_frame->MessageTextFromValue( pos.y ) );
|
2021-03-11 12:33:06 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 17:04:34 +00:00
|
|
|
bool BOARD_NETLIST_UPDATER::testConnectivity( NETLIST& aNetlist,
|
|
|
|
std::map<COMPONENT*, FOOTPRINT*>& aFootprintMap )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
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.
|
2016-01-29 10:24:39 +00:00
|
|
|
|
|
|
|
wxString msg;
|
2021-08-23 23:10:21 +00:00
|
|
|
wxString padNumber;
|
2016-01-29 10:24:39 +00:00
|
|
|
|
|
|
|
for( int i = 0; i < (int) aNetlist.GetCount(); i++ )
|
|
|
|
{
|
2020-11-13 17:04:34 +00:00
|
|
|
COMPONENT* component = aNetlist.GetComponent( i );
|
|
|
|
FOOTPRINT* footprint = aFootprintMap[component];
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2020-11-13 17:04:34 +00:00
|
|
|
if( !footprint ) // It can be missing in partial designs
|
2016-01-29 10:24:39 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Explore all pins/pads in component
|
|
|
|
for( unsigned jj = 0; jj < component->GetNetCount(); jj++ )
|
|
|
|
{
|
2021-08-23 23:10:21 +00:00
|
|
|
padNumber = component->GetNet( jj ).GetPinName();
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2022-11-02 12:32:46 +00:00
|
|
|
if( padNumber.IsEmpty() )
|
|
|
|
{
|
|
|
|
// bad symbol, report error
|
|
|
|
msg.Printf( _( "Symbol %s has pins with no number. These pins can not be matched "
|
|
|
|
"to pads in %s." ),
|
|
|
|
component->GetReference(),
|
|
|
|
footprint->GetFPID().Format().wx_str() );
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
|
|
|
|
++m_errorCount;
|
|
|
|
}
|
|
|
|
else if( !footprint->FindPadByNumber( padNumber ) )
|
|
|
|
{
|
|
|
|
// not found: bad footprint, report error
|
|
|
|
msg.Printf( _( "%s pad %s not found in %s." ),
|
|
|
|
component->GetReference(),
|
|
|
|
padNumber,
|
|
|
|
footprint->GetFPID().Format().wx_str() );
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
|
|
|
|
++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 )
|
|
|
|
{
|
2021-01-15 12:30:22 +00:00
|
|
|
FOOTPRINT* lastPreexistingFootprint = nullptr;
|
|
|
|
COMPONENT* component = nullptr;
|
|
|
|
wxString msg;
|
|
|
|
|
2016-01-29 10:24:39 +00:00
|
|
|
m_errorCount = 0;
|
|
|
|
m_warningCount = 0;
|
2019-04-17 08:54:00 +00:00
|
|
|
m_newFootprintsCount = 0;
|
2020-11-13 17:04:34 +00:00
|
|
|
|
|
|
|
std::map<COMPONENT*, FOOTPRINT*> footprintMap;
|
|
|
|
|
|
|
|
if( !m_board->Footprints().empty() )
|
|
|
|
lastPreexistingFootprint = m_board->Footprints().back();
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2018-05-01 12:52:11 +00:00
|
|
|
cacheCopperZoneConnections();
|
|
|
|
|
2021-01-15 12:30:22 +00:00
|
|
|
// First mark all nets (except <no net>) as stale; we'll update those which are current
|
|
|
|
// in the following two loops.
|
|
|
|
//
|
2016-01-29 10:24:39 +00:00
|
|
|
if( !m_isDryRun )
|
|
|
|
{
|
|
|
|
m_board->SetStatus( 0 );
|
2018-10-18 09:35:59 +00:00
|
|
|
|
|
|
|
for( NETINFO_ITEM* net : m_board->GetNetInfo() )
|
2020-12-08 13:02:08 +00:00
|
|
|
net->SetIsCurrent( net->GetNetCode() == 0 );
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
|
|
|
|
2021-01-15 12:30:22 +00:00
|
|
|
// Next go through the netlist updating all board footprints which have matching component
|
|
|
|
// entries and adding new footprints for those that don't.
|
|
|
|
//
|
2018-09-15 18:37:57 +00:00
|
|
|
for( unsigned i = 0; i < aNetlist.GetCount(); i++ )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
2021-01-15 12:30:22 +00:00
|
|
|
component = aNetlist.GetComponent( i );
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
if( component->GetProperties().count( wxT( "exclude_from_board" ) ) )
|
2020-08-26 21:43:38 +00:00
|
|
|
continue;
|
|
|
|
|
2020-12-18 01:44:16 +00:00
|
|
|
msg.Printf( _( "Processing symbol '%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
|
|
|
|
2021-01-15 12:30:22 +00:00
|
|
|
int matchCount = 0;
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
2021-01-15 12:30:22 +00:00
|
|
|
bool match = false;
|
2018-09-15 18:37:57 +00:00
|
|
|
|
2021-01-15 12:30:22 +00:00
|
|
|
if( m_lookupByTimestamp )
|
2021-02-21 04:03:56 +00:00
|
|
|
{
|
2021-05-23 21:49:39 +00:00
|
|
|
for( const KIID& uuid : component->GetKIIDs() )
|
2021-02-21 04:03:56 +00:00
|
|
|
{
|
|
|
|
KIID_PATH base = component->GetPath();
|
|
|
|
base.push_back( uuid );
|
|
|
|
|
|
|
|
if( footprint->GetPath() == base )
|
|
|
|
{
|
|
|
|
match = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-15 12:30:22 +00:00
|
|
|
else
|
2021-05-23 21:49:39 +00:00
|
|
|
{
|
2021-01-15 12:30:22 +00:00
|
|
|
match = footprint->GetReference().CmpNoCase( component->GetReference() ) == 0;
|
2021-05-23 21:49:39 +00:00
|
|
|
}
|
2018-09-15 18:37:57 +00:00
|
|
|
|
|
|
|
if( match )
|
|
|
|
{
|
2021-01-15 12:30:22 +00:00
|
|
|
FOOTPRINT* tmp = footprint;
|
2018-09-15 18:37:57 +00:00
|
|
|
|
|
|
|
if( m_replaceFootprints && component->GetFPID() != footprint->GetFPID() )
|
2021-05-23 21:21:34 +00:00
|
|
|
tmp = replaceFootprint( aNetlist, footprint, component );
|
2018-09-15 18:37:57 +00:00
|
|
|
|
|
|
|
if( tmp )
|
|
|
|
{
|
2020-11-13 17:04:34 +00:00
|
|
|
footprintMap[ component ] = tmp;
|
|
|
|
|
2020-12-07 15:50:04 +00:00
|
|
|
updateFootprintParameters( tmp, component );
|
2018-09-15 18:37:57 +00:00
|
|
|
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 )
|
|
|
|
{
|
2021-05-23 21:21:34 +00:00
|
|
|
FOOTPRINT* footprint = addNewFootprint( component );
|
2018-10-02 17:17:16 +00:00
|
|
|
|
2021-01-15 12:30:22 +00:00
|
|
|
if( footprint )
|
2018-10-02 17:17:16 +00:00
|
|
|
{
|
2021-01-15 12:30:22 +00:00
|
|
|
footprintMap[ component ] = footprint;
|
2020-11-13 17:04:34 +00:00
|
|
|
|
2021-01-15 12:30:22 +00:00
|
|
|
updateFootprintParameters( footprint, component );
|
|
|
|
updateComponentPadConnections( footprint, component );
|
2018-10-02 17:17:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( matchCount > 1 )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
2021-09-20 21:03:33 +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 );
|
2022-11-03 16:54:59 +00:00
|
|
|
m_errorCount++;
|
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
|
|
|
|
2021-01-15 12:30:22 +00:00
|
|
|
// Finally go through the board footprints and update all those that *don't* have matching
|
|
|
|
// component entries.
|
|
|
|
//
|
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
|
|
|
{
|
2021-05-23 21:49:39 +00:00
|
|
|
bool matched = false;
|
2021-05-23 21:21:34 +00:00
|
|
|
bool doDelete = m_deleteUnusedFootprints;
|
2021-01-15 12:30:22 +00:00
|
|
|
|
|
|
|
if( ( footprint->GetAttributes() & FP_BOARD_ONLY ) > 0 )
|
|
|
|
doDelete = false;
|
|
|
|
|
2021-05-23 21:49:39 +00:00
|
|
|
if( m_lookupByTimestamp )
|
|
|
|
component = aNetlist.GetComponentByPath( footprint->GetPath() );
|
|
|
|
else
|
|
|
|
component = aNetlist.GetComponentByReference( footprint->GetReference() );
|
2021-01-15 12:30:22 +00:00
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
if( component && component->GetProperties().count( wxT( "exclude_from_board" ) ) == 0 )
|
2021-05-23 21:49:39 +00:00
|
|
|
matched = true;
|
2021-01-15 12:30:22 +00:00
|
|
|
|
2021-05-23 21:49:39 +00:00
|
|
|
if( doDelete && !matched && footprint->IsLocked() )
|
2021-01-15 12:30:22 +00:00
|
|
|
{
|
2021-03-11 12:33:06 +00:00
|
|
|
if( m_isDryRun )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Cannot remove unused footprint %s (locked)." ),
|
|
|
|
footprint->GetReference() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Could not remove unused footprint %s (locked)." ),
|
|
|
|
footprint->GetReference() );
|
|
|
|
}
|
|
|
|
|
2021-09-18 17:30:58 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
|
2022-11-03 16:54:59 +00:00
|
|
|
m_errorCount++;
|
2021-01-15 12:30:22 +00:00
|
|
|
doDelete = false;
|
|
|
|
}
|
|
|
|
|
2021-05-23 21:49:39 +00:00
|
|
|
if( doDelete && !matched )
|
2021-01-15 12:30:22 +00:00
|
|
|
{
|
2021-03-11 12:33:06 +00:00
|
|
|
if( m_isDryRun )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Remove unused footprint %s." ), footprint->GetReference() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-15 12:30:22 +00:00
|
|
|
m_commit.Remove( footprint );
|
2021-03-11 12:33:06 +00:00
|
|
|
msg.Printf( _( "Removed unused footprint %s." ), footprint->GetReference() );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ACTION );
|
2021-01-15 12:30:22 +00:00
|
|
|
}
|
|
|
|
else if( !m_isDryRun )
|
|
|
|
{
|
2021-05-23 21:49:39 +00:00
|
|
|
if( !matched )
|
|
|
|
footprint->SetPath( KIID_PATH() );
|
|
|
|
|
2021-01-15 12:30:22 +00:00
|
|
|
for( PAD* pad : footprint->Pads() )
|
|
|
|
{
|
|
|
|
if( pad->GetNet() )
|
|
|
|
pad->GetNet()->SetIsCurrent( true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2016-09-05 13:38:01 +00:00
|
|
|
if( !m_isDryRun )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
2022-09-29 16:07:42 +00:00
|
|
|
m_board->BuildConnectivity();
|
2020-11-13 17:04:34 +00:00
|
|
|
testConnectivity( aNetlist, footprintMap );
|
2019-04-17 08:54:00 +00:00
|
|
|
|
2020-07-13 21:35:05 +00:00
|
|
|
for( NETINFO_ITEM* net : m_board->GetNetInfo() )
|
|
|
|
{
|
|
|
|
if( !net->IsCurrent() )
|
|
|
|
{
|
2021-03-11 12:33:06 +00:00
|
|
|
msg.Printf( _( "Removed unused net %s." ), net->GetNetname() );
|
2020-07-13 21:35:05 +00:00
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ACTION );
|
|
|
|
m_commit.Removed( net );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_board->GetNetInfo().RemoveUnusedNets();
|
2021-03-23 21:42:56 +00:00
|
|
|
m_commit.SetResolveNetConflicts();
|
2022-08-26 08:38:36 +00:00
|
|
|
|
|
|
|
// When new footprints are added, the automatic zone refill is disabled because:
|
|
|
|
// * it creates crashes when calculating dynamic ratsnests if auto refill is enabled.
|
|
|
|
// (the auto refills rebuild the connectivity with incomplete data)
|
|
|
|
// * it is useless because zones will be refilled after placing new footprints
|
|
|
|
m_commit.Push( _( "Update netlist" ), m_newFootprintsCount ? ZONE_FILL_OP : 0 );
|
2021-03-04 15:04:25 +00:00
|
|
|
|
|
|
|
m_board->SynchronizeNetsAndNetClasses();
|
2021-03-05 19:14:53 +00:00
|
|
|
m_frame->SaveProjectSettings();
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
2019-04-17 08:54:00 +00:00
|
|
|
|
2019-04-18 02:21:23 +00:00
|
|
|
if( m_isDryRun )
|
|
|
|
{
|
2020-12-01 01:10:58 +00:00
|
|
|
for( const std::pair<const wxString, NETINFO_ITEM*>& addedNet : m_addedNets )
|
2020-11-26 15:22:19 +00:00
|
|
|
delete addedNet.second;
|
2019-04-18 02:21:23 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|