2012-01-26 09:37:36 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2013-08-24 13:03:59 +00:00
|
|
|
* Copyright (C) 1992-2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2016-11-20 23:35:08 +00:00
|
|
|
* Copyright (C) 2013-2016 Wayne Stambaugh <stambaughw@verizon.net>
|
2022-09-03 18:29:02 +00:00
|
|
|
* Copyright (C) 1992-2022 KiCad Developers, see change_log.txt for contributors.
|
2012-01-26 09:37:36 +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
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2016-06-29 10:23:11 +00:00
|
|
|
#include <functional>
|
|
|
|
using namespace std::placeholders;
|
|
|
|
|
2023-01-19 00:53:16 +00:00
|
|
|
#include <confirm.h>
|
2020-07-06 10:51:04 +00:00
|
|
|
#include <kiway.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2020-08-26 21:43:38 +00:00
|
|
|
#include <netlist_reader/pcb_netlist.h>
|
|
|
|
#include <netlist_reader/netlist_reader.h>
|
2013-04-25 16:29:35 +00:00
|
|
|
#include <reporter.h>
|
2016-11-20 23:35:08 +00:00
|
|
|
#include <lib_id.h>
|
2013-05-28 16:54:59 +00:00
|
|
|
#include <fp_lib_table.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
|
|
|
#include <footprint.h>
|
2022-09-27 13:30:17 +00:00
|
|
|
#include <spread_footprints.h>
|
2020-06-16 18:15:14 +00:00
|
|
|
#include <ratsnest/ratsnest_data.h>
|
2013-04-25 16:29:35 +00:00
|
|
|
#include <io_mgr.h>
|
2019-11-17 12:58:38 +00:00
|
|
|
#include "board_netlist_updater.h"
|
2015-04-07 16:31:37 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2017-02-21 12:42:08 +00:00
|
|
|
#include <tools/pcb_actions.h>
|
2020-12-16 13:31:32 +00:00
|
|
|
#include <tools/pcb_selection_tool.h>
|
2020-05-31 21:42:04 +00:00
|
|
|
#include <project/project_file.h> // LAST_PATH_TYPE
|
2023-09-28 03:15:54 +00:00
|
|
|
#include <project_pcb.h>
|
2020-10-03 12:01:59 +00:00
|
|
|
|
2015-04-07 16:31:37 +00:00
|
|
|
|
2020-08-26 21:43:38 +00:00
|
|
|
bool PCB_EDIT_FRAME::ReadNetlistFromFile( const wxString &aFilename, NETLIST& aNetlist,
|
2019-04-18 02:10:56 +00:00
|
|
|
REPORTER& aReporter )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2019-04-18 02:10:56 +00:00
|
|
|
wxString msg;
|
2013-08-23 06:38:57 +00:00
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
try
|
2009-04-24 07:36:36 +00:00
|
|
|
{
|
2016-05-29 15:02:34 +00:00
|
|
|
std::unique_ptr<NETLIST_READER> netlistReader( NETLIST_READER::GetNetlistReader(
|
2019-04-18 02:10:56 +00:00
|
|
|
&aNetlist, aFilename, wxEmptyString ) );
|
2011-09-16 14:13:02 +00:00
|
|
|
|
2015-06-07 18:18:45 +00:00
|
|
|
if( !netlistReader.get() )
|
2011-05-03 12:57:44 +00:00
|
|
|
{
|
2021-06-16 22:35:00 +00:00
|
|
|
msg.Printf( _( "Cannot open netlist file '%s'." ), aFilename );
|
2023-01-19 00:53:16 +00:00
|
|
|
DisplayErrorMessage( this, msg );
|
2019-04-18 02:10:56 +00:00
|
|
|
return false;
|
2011-05-03 12:57:44 +00:00
|
|
|
}
|
2012-01-26 09:37:36 +00:00
|
|
|
|
2019-08-03 03:03:03 +00:00
|
|
|
SetLastPath( LAST_PATH_NETLIST, aFilename );
|
2013-04-25 16:29:35 +00:00
|
|
|
netlistReader->LoadNetlist();
|
2019-04-18 02:10:56 +00:00
|
|
|
LoadFootprints( aNetlist, aReporter );
|
2013-04-25 16:29:35 +00:00
|
|
|
}
|
2014-04-09 13:33:04 +00:00
|
|
|
catch( const IO_ERROR& ioe )
|
2013-04-25 16:29:35 +00:00
|
|
|
{
|
2016-09-14 22:36:45 +00:00
|
|
|
msg.Printf( _( "Error loading netlist.\n%s" ), ioe.What().GetData() );
|
2023-01-19 00:53:16 +00:00
|
|
|
DisplayErrorMessage( this, msg );
|
2019-04-18 02:10:56 +00:00
|
|
|
return false;
|
2013-03-19 01:25:19 +00:00
|
|
|
}
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2019-08-03 03:03:03 +00:00
|
|
|
SetLastPath( LAST_PATH_NETLIST, aFilename );
|
2011-05-03 12:57:44 +00:00
|
|
|
|
2019-04-18 02:10:56 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-13 17:28:55 +00:00
|
|
|
void PCB_EDIT_FRAME::OnNetlistChanged( BOARD_NETLIST_UPDATER& aUpdater, bool* aRunDragCommand )
|
2019-04-18 02:10:56 +00:00
|
|
|
{
|
|
|
|
BOARD* board = GetBoard();
|
2014-04-04 15:42:35 +00:00
|
|
|
|
2019-04-18 02:10:56 +00:00
|
|
|
SetMsgPanel( board );
|
2015-04-07 16:31:37 +00:00
|
|
|
|
2022-11-29 15:17:38 +00:00
|
|
|
// Update rendered track/via/pad net labels, and any text items that might reference a
|
|
|
|
// netName or netClass
|
|
|
|
int netNamesCfg = GetPcbNewSettings()->m_Display.m_NetNames;
|
|
|
|
|
2022-12-03 13:25:20 +00:00
|
|
|
GetCanvas()->GetView()->UpdateAllItemsConditionally(
|
|
|
|
[&]( KIGFX::VIEW_ITEM* aItem ) -> int
|
2022-11-29 15:17:38 +00:00
|
|
|
{
|
|
|
|
if( dynamic_cast<PCB_TRACK*>( aItem ) )
|
|
|
|
{
|
|
|
|
if( netNamesCfg == 2 || netNamesCfg == 3 )
|
2022-12-03 13:25:20 +00:00
|
|
|
return KIGFX::REPAINT;
|
2022-11-29 15:17:38 +00:00
|
|
|
}
|
|
|
|
else if( dynamic_cast<PAD*>( aItem ) )
|
|
|
|
{
|
|
|
|
if( netNamesCfg == 1 || netNamesCfg == 3 )
|
2022-12-03 13:25:20 +00:00
|
|
|
return KIGFX::REPAINT;
|
2022-11-29 15:17:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem );
|
|
|
|
|
|
|
|
if( text && text->HasTextVars() )
|
2022-12-03 13:25:20 +00:00
|
|
|
{
|
|
|
|
text->ClearRenderCache();
|
|
|
|
text->ClearBoundingBoxCache();
|
|
|
|
return KIGFX::GEOMETRY | KIGFX::REPAINT;
|
|
|
|
}
|
2022-11-29 15:17:38 +00:00
|
|
|
|
2022-12-03 13:25:20 +00:00
|
|
|
return 0;
|
2022-11-29 15:17:38 +00:00
|
|
|
} );
|
2019-04-18 02:10:56 +00:00
|
|
|
|
|
|
|
// Spread new footprints.
|
2022-09-03 18:29:02 +00:00
|
|
|
std::vector<FOOTPRINT*> newFootprints = aUpdater.GetAddedFootprints();
|
2016-07-11 07:48:51 +00:00
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
GetToolManager()->RunAction( PCB_ACTIONS::selectionClear );
|
2011-05-03 12:57:44 +00:00
|
|
|
|
2022-09-27 13:30:17 +00:00
|
|
|
SpreadFootprints( &newFootprints, { 0, 0 }, true );
|
2018-12-10 19:34:08 +00:00
|
|
|
|
2020-10-21 03:48:06 +00:00
|
|
|
// Start drag command for new footprints
|
2019-05-27 16:16:54 +00:00
|
|
|
if( !newFootprints.empty() )
|
2018-12-10 19:34:08 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : newFootprints )
|
2023-06-26 22:16:51 +00:00
|
|
|
GetToolManager()->RunAction<EDA_ITEM*>( PCB_ACTIONS::selectItem, footprint );
|
2014-04-04 15:42:35 +00:00
|
|
|
|
2019-05-27 16:16:54 +00:00
|
|
|
*aRunDragCommand = true;
|
2011-05-03 12:57:44 +00:00
|
|
|
}
|
|
|
|
|
2021-01-28 01:56:55 +00:00
|
|
|
Compile_Ratsnest( true );
|
|
|
|
|
2019-06-13 17:28:55 +00:00
|
|
|
GetCanvas()->Refresh();
|
2011-05-03 12:57:44 +00:00
|
|
|
}
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-09-17 09:54:49 +00:00
|
|
|
void PCB_EDIT_FRAME::LoadFootprints( NETLIST& aNetlist, REPORTER& aReporter )
|
2013-05-28 16:54:59 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
2016-11-20 23:35:08 +00:00
|
|
|
LIB_ID lastFPID;
|
2013-05-28 16:54:59 +00:00
|
|
|
COMPONENT* component;
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint = nullptr;
|
2021-02-22 18:07:40 +00:00
|
|
|
FOOTPRINT* fpOnBoard = nullptr;
|
2013-05-28 16:54:59 +00:00
|
|
|
|
2023-09-28 03:15:54 +00:00
|
|
|
if( aNetlist.IsEmpty() || PROJECT_PCB::PcbFootprintLibs( &Prj() )->IsEmpty() )
|
2013-05-28 16:54:59 +00:00
|
|
|
return;
|
|
|
|
|
2013-09-08 18:31:21 +00:00
|
|
|
aNetlist.SortByFPID();
|
2013-05-28 16:54:59 +00:00
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < aNetlist.GetCount(); ii++ )
|
|
|
|
{
|
|
|
|
component = aNetlist.GetComponent( ii );
|
|
|
|
|
2020-02-20 12:11:04 +00:00
|
|
|
// The FPID is ok as long as there is a footprint portion coming from eeschema.
|
2016-11-20 23:35:08 +00:00
|
|
|
if( !component->GetFPID().GetLibItemName().size() )
|
2013-06-15 16:55:51 +00:00
|
|
|
{
|
2021-07-05 12:40:38 +00:00
|
|
|
msg.Printf( _( "No footprint defined for symbol %s." ),
|
2018-09-17 09:54:49 +00:00
|
|
|
component->GetReference() );
|
2020-03-04 09:48:18 +00:00
|
|
|
aReporter.Report( msg, RPT_SEVERITY_ERROR );
|
2013-06-15 16:55:51 +00:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-05-28 16:54:59 +00:00
|
|
|
// Check if component footprint is already on BOARD and only load the footprint from
|
2013-11-02 00:24:38 +00:00
|
|
|
// the library if it's needed. Nickname can be blank.
|
2013-05-28 16:54:59 +00:00
|
|
|
if( aNetlist.IsFindByTimeStamp() )
|
2021-02-21 04:03:56 +00:00
|
|
|
{
|
|
|
|
for( const KIID& uuid : component->GetKIIDs() )
|
|
|
|
{
|
|
|
|
KIID_PATH path = component->GetPath();
|
|
|
|
path.push_back( uuid );
|
|
|
|
|
2023-04-11 08:53:35 +00:00
|
|
|
if( ( fpOnBoard = m_pcb->FindFootprintByPath( path ) ) != nullptr )
|
2021-02-21 04:03:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-05-28 16:54:59 +00:00
|
|
|
else
|
2021-02-21 04:03:56 +00:00
|
|
|
fpOnBoard = m_pcb->FindFootprintByReference( component->GetReference() );
|
2013-05-28 16:54:59 +00:00
|
|
|
|
2018-09-17 09:54:49 +00:00
|
|
|
bool footprintMisMatch = fpOnBoard && fpOnBoard->GetFPID() != component->GetFPID();
|
2013-08-23 06:38:57 +00:00
|
|
|
|
|
|
|
if( footprintMisMatch && !aNetlist.GetReplaceFootprints() )
|
|
|
|
{
|
2021-06-16 22:35:00 +00:00
|
|
|
msg.Printf( _( "Footprint of %s changed: board footprint '%s', netlist footprint '%s'." ),
|
2018-09-17 09:54:49 +00:00
|
|
|
component->GetReference(),
|
2020-10-16 00:39:55 +00:00
|
|
|
fpOnBoard->GetFPID().Format().wx_str(),
|
|
|
|
component->GetFPID().Format().wx_str() );
|
2020-03-04 09:48:18 +00:00
|
|
|
aReporter.Report( msg, RPT_SEVERITY_WARNING );
|
2013-08-23 06:38:57 +00:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !aNetlist.GetReplaceFootprints() )
|
|
|
|
footprintMisMatch = false;
|
|
|
|
|
2017-10-30 13:19:42 +00:00
|
|
|
if( fpOnBoard && !footprintMisMatch ) // nothing else to do here
|
|
|
|
continue;
|
2013-05-28 16:54:59 +00:00
|
|
|
|
2017-10-30 13:19:42 +00:00
|
|
|
if( component->GetFPID() != lastFPID )
|
2013-05-28 16:54:59 +00:00
|
|
|
{
|
2020-11-13 11:17:15 +00:00
|
|
|
footprint = nullptr;
|
2013-05-28 16:54:59 +00:00
|
|
|
|
2020-08-26 21:43:38 +00:00
|
|
|
// The LIB_ID is ok as long as there is a footprint portion coming the library if
|
|
|
|
// it's needed. Nickname can be blank.
|
2016-11-20 23:35:08 +00:00
|
|
|
if( !component->GetFPID().GetLibItemName().size() )
|
2013-05-28 16:54:59 +00:00
|
|
|
{
|
2021-06-16 22:35:00 +00:00
|
|
|
msg.Printf( _( "%s footprint ID '%s' is not valid." ),
|
2018-09-17 09:54:49 +00:00
|
|
|
component->GetReference(),
|
2020-10-16 00:39:55 +00:00
|
|
|
component->GetFPID().Format().wx_str() );
|
2020-03-04 09:48:18 +00:00
|
|
|
aReporter.Report( msg, RPT_SEVERITY_ERROR );
|
2013-05-28 16:54:59 +00:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-11-02 00:24:38 +00:00
|
|
|
// loadFootprint() can find a footprint with an empty nickname in fpid.
|
2020-11-13 11:17:15 +00:00
|
|
|
footprint = PCB_BASE_FRAME::loadFootprint( component->GetFPID() );
|
2013-05-28 16:54:59 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
if( footprint )
|
2013-05-28 16:54:59 +00:00
|
|
|
{
|
2013-09-08 18:31:21 +00:00
|
|
|
lastFPID = component->GetFPID();
|
2013-05-28 16:54:59 +00:00
|
|
|
}
|
2013-11-02 00:24:38 +00:00
|
|
|
else
|
2013-05-28 16:54:59 +00:00
|
|
|
{
|
2021-06-16 22:35:00 +00:00
|
|
|
msg.Printf( _( "%s footprint '%s' not found in any libraries in the footprint "
|
2021-07-05 12:40:38 +00:00
|
|
|
"library table." ),
|
2018-09-17 09:54:49 +00:00
|
|
|
component->GetReference(),
|
2020-10-16 00:39:55 +00:00
|
|
|
component->GetFPID().GetLibItemName().wx_str() );
|
2020-03-04 09:48:18 +00:00
|
|
|
aReporter.Report( msg, RPT_SEVERITY_ERROR );
|
2013-05-28 16:54:59 +00:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Footprint already loaded from a library, duplicate it (faster)
|
2020-11-13 11:17:15 +00:00
|
|
|
if( !footprint )
|
|
|
|
continue; // Footprint does not exist in any library.
|
2013-05-28 16:54:59 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint = new FOOTPRINT( *footprint );
|
2020-11-13 11:17:15 +00:00
|
|
|
const_cast<KIID&>( footprint->m_Uuid ) = KIID();
|
2013-05-28 16:54:59 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
if( footprint )
|
2020-11-13 15:15:52 +00:00
|
|
|
component->SetFootprint( footprint );
|
2013-05-28 16:54:59 +00:00
|
|
|
}
|
2016-02-02 00:43:28 +00:00
|
|
|
}
|