Pcbnew: add write board netlist to file support.

This is hidden behind an advanced configuration setting and is primarily
useful for developers trying to troubleshoot the netlist payload sent
from the board editor to the schematic editor.

Fixes https://gitlab.com/kicad/code/kicad/issues/8051
This commit is contained in:
Wayne Stambaugh 2021-03-28 08:37:54 -04:00
parent 8a8167ff0a
commit 6d2f80b4cf
7 changed files with 141 additions and 6 deletions

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -153,6 +153,7 @@ static const wxChar DrawBoundingBoxes[] = wxT( "DrawBoundingBoxes" );
static const wxChar AllowDarkMode[] = wxT( "AllowDarkMode" );
static const wxChar ShowPcbnewExportNetlist[] = wxT( "ShowPcbnewExportNetlist" );
} // namespace KEYS
@ -255,6 +256,7 @@ ADVANCED_CFG::ADVANCED_CFG()
m_HotkeysDumper = false;
m_DrawBoundingBoxes = false;
m_AllowDarkMode = false;
m_ShowPcbnewExportNetlist = false;
loadFromConfigFile();
}
@ -354,12 +356,15 @@ void ADVANCED_CFG::loadSettings( wxConfigBase& aCfg )
configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::AllowDarkMode,
&m_AllowDarkMode, defaultDarkMode ) );
configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::ShowPcbnewExportNetlist,
&m_ShowPcbnewExportNetlist, false ) );
wxConfigLoadSetups( &aCfg, configParams );
dumpCfg( configParams );
for( PARAM_CFG* param : configParams )
delete param;
dumpCfg( configParams );
}

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -145,7 +145,7 @@ public:
bool m_DebugPDFWriter;
/**
* The diameter of the drill marks on print and plot outputs (in mm),
* The diameter of the drill marks on print and plot outputs (in mm),
* when the "Drill marks" option is set to "Small mark"
*/
double m_SmallDrillMarkSize;
@ -165,6 +165,11 @@ public:
*/
bool m_AllowDarkMode;
/**
* Enable exporting board editor netlist to a file for troubleshooting purposes.
*/
bool m_ShowPcbnewExportNetlist;
private:
ADVANCED_CFG();

View File

@ -24,6 +24,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <advanced_config.h>
#include <bitmaps.h>
#include <filehistory.h>
#include <kiface_i.h>
@ -141,6 +142,9 @@ void PCB_EDIT_FRAME::ReCreateMenuBar()
submenuExport->Add( _( "Hyperlynx..." ), "",
ID_GEN_EXPORT_FILE_HYPERLYNX, BITMAPS::export_step );
if( ADVANCED_CFG::GetCfg().m_ShowPcbnewExportNetlist )
submenuExport->Add( PCB_ACTIONS::exportNetlist );
submenuExport->AppendSeparator();
submenuExport->Add( _( "Footprints to Library..." ),
_( "Add footprints used on board to an existing footprint library\n"

View File

@ -120,6 +120,56 @@ public:
};
/**
* Helper widget to add controls to a wxFileDialog to set netlist configuration options.
*/
class NETLIST_OPTIONS_HELPER : public wxPanel
{
public:
NETLIST_OPTIONS_HELPER( wxWindow* aParent )
: wxPanel( aParent )
{
m_cbOmitExtras = new wxCheckBox( this, wxID_ANY, _( "Omit extra information" ) );
m_cbOmitNets = new wxCheckBox( this, wxID_ANY, _( "Omit nets" ) );
m_cbOmitFpUuids = new wxCheckBox( this, wxID_ANY,
_( "Do not prefix path with footprint UUID." ) );
wxBoxSizer* sizer = new wxBoxSizer( wxHORIZONTAL );
sizer->Add( m_cbOmitExtras, 0, wxALL, 5 );
sizer->Add( m_cbOmitNets, 0, wxALL, 5 );
sizer->Add( m_cbOmitFpUuids, 0, wxALL, 5 );
SetSizerAndFit( sizer );
}
int GetNetlistOptions() const
{
int options = 0;
if( m_cbOmitExtras->GetValue() )
options |= CTL_OMIT_EXTRA;
if( m_cbOmitNets->GetValue() )
options |= CTL_OMIT_NETS;
if( m_cbOmitFpUuids->GetValue() )
options |= CTL_OMIT_FP_UUID;
return options;
}
static wxWindow* Create( wxWindow* aParent )
{
return new NETLIST_OPTIONS_HELPER( aParent );
}
protected:
wxCheckBox* m_cbOmitExtras;
wxCheckBox* m_cbOmitNets;
wxCheckBox* m_cbOmitFpUuids;
};
BOARD_EDITOR_CONTROL::BOARD_EDITOR_CONTROL() :
PCB_TOOL_BASE( "pcbnew.EditorControl" ),
m_frame( nullptr )
@ -356,6 +406,70 @@ int BOARD_EDITOR_CONTROL::ExportSpecctraDSN( const TOOL_EVENT& aEvent )
}
int BOARD_EDITOR_CONTROL::ExportNetlist( const TOOL_EVENT& aEvent )
{
wxCHECK( m_frame, 0 );
wxFileName fn = m_frame->Prj().GetProjectFullName();
// Use a different file extension for the board netlist so the schematic netlist file
// is accidently overwritten.
fn.SetExt( "pcb_net" );
wxFileDialog dlg( m_frame, _( "Export Board Netlist" ), fn.GetPath(), fn.GetFullName(),
_( "KiCad board netlist files" ) + wxT( " (*.pcb_net)|*.pcb_net" ),
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
dlg.SetExtraControlCreator( &NETLIST_OPTIONS_HELPER::Create );
if( dlg.ShowModal() == wxID_CANCEL )
return 0;
fn = dlg.GetPath();
if( !fn.IsDirWritable() )
{
wxString msg;
msg.Printf( _( "Path `%s` is read only." ), fn.GetPath() );
wxMessageDialog( m_frame, msg, _( "I/O Error" ), wxOK | wxCENTER | wxICON_EXCLAMATION );
return 0;
}
const NETLIST_OPTIONS_HELPER* noh =
dynamic_cast<const NETLIST_OPTIONS_HELPER*>( dlg.GetExtraControl() );
wxCHECK( noh, 0 );
NETLIST netlist;
for( const FOOTPRINT* footprint : board()->Footprints() )
{
COMPONENT* component = new COMPONENT( footprint->GetFPID(), footprint->GetReference(),
footprint->GetValue(), footprint->GetPath(),
{ footprint->m_Uuid } );
for( const PAD* pad : footprint->Pads() )
{
const wxString& netname = pad->GetShortNetname();
if( !netname.IsEmpty() )
{
component->AddNet( pad->GetName(), netname, pad->GetPinFunction(),
pad->GetPinType() );
}
}
netlist.AddComponent( component );
}
FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
netlist.Format( "pcb_netlist", &formatter, 0, noh->GetNetlistOptions() );
return 0;
}
int BOARD_EDITOR_CONTROL::GenerateFabFiles( const TOOL_EVENT& aEvent )
{
wxCommandEvent dummy;
@ -1371,6 +1485,7 @@ void BOARD_EDITOR_CONTROL::setTransitions()
Go( &BOARD_EDITOR_CONTROL::ImportNetlist, PCB_ACTIONS::importNetlist.MakeEvent() );
Go( &BOARD_EDITOR_CONTROL::ImportSpecctraSession, PCB_ACTIONS::importSpecctraSession.MakeEvent() );
Go( &BOARD_EDITOR_CONTROL::ExportSpecctraDSN, PCB_ACTIONS::exportSpecctraDSN.MakeEvent() );
Go( &BOARD_EDITOR_CONTROL::ExportNetlist, PCB_ACTIONS::exportNetlist.MakeEvent() );
Go( &BOARD_EDITOR_CONTROL::GenerateDrillFiles, PCB_ACTIONS::generateDrillFiles.MakeEvent() );
Go( &BOARD_EDITOR_CONTROL::GenerateFabFiles, PCB_ACTIONS::generateGerbers.MakeEvent() );
Go( &BOARD_EDITOR_CONTROL::GeneratePosFile, PCB_ACTIONS::generatePosFile.MakeEvent() );

View File

@ -63,6 +63,7 @@ public:
int ImportNetlist( const TOOL_EVENT& aEvent );
int ImportSpecctraSession( const TOOL_EVENT& aEvent );
int ExportSpecctraDSN( const TOOL_EVENT& aEvent );
int ExportNetlist( const TOOL_EVENT& aEvent );
int GenerateDrillFiles( const TOOL_EVENT& aEvent );
int GeneratePosFile( const TOOL_EVENT& aEvent );
int GenerateFabFiles( const TOOL_EVENT& aEvent );

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013-2016 CERN
* Copyright (C) 2016-2019 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
@ -562,6 +562,10 @@ TOOL_ACTION PCB_ACTIONS::exportSpecctraDSN( "pcbnew.EditorControl.exportSpecctra
_( "Export Specctra DSN..." ), _( "Export Specctra DSN routing info" ),
BITMAPS::export_dsn );
TOOL_ACTION PCB_ACTIONS::exportNetlist( "pcbnew.EditorControl.exportNetlist", AS_GLOBAL, 0, "",
_( "Netlist..." ),
_( "Export netlist used to update schematics" ) );
TOOL_ACTION PCB_ACTIONS::generateGerbers( "pcbnew.EditorControl.generateGerbers",
AS_GLOBAL, 0, "",
_( "Gerbers (.gbr)..." ), _( "Generate Gerbers for fabrication" ),

View File

@ -332,6 +332,7 @@ public:
static TOOL_ACTION importSpecctraSession;
static TOOL_ACTION exportSpecctraDSN;
static TOOL_ACTION exportNetlist;
static TOOL_ACTION generateGerbers;
static TOOL_ACTION generateDrillFiles;