Add netlist export cli
This commit is contained in:
parent
108d5b5433
commit
43f039ef5f
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2022 Mark Roszko <mark.roszko@gmail.com>
|
||||
* Copyright (C) 1992-2022 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 as published by the
|
||||
* Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef JOB_EXPORT_SCH_NETLIST_H
|
||||
#define JOB_EXPORT_SCH_NETLIST_H
|
||||
|
||||
#include <wx/string.h>
|
||||
#include "job.h"
|
||||
|
||||
class JOB_EXPORT_SCH_NETLIST : public JOB
|
||||
{
|
||||
public:
|
||||
JOB_EXPORT_SCH_NETLIST( bool aIsCli ) :
|
||||
JOB( "netlist", aIsCli ),
|
||||
m_filename(),
|
||||
m_outputFile()
|
||||
{
|
||||
}
|
||||
|
||||
wxString m_filename;
|
||||
wxString m_outputFile;
|
||||
|
||||
enum class FORMAT
|
||||
{
|
||||
KICADXML,
|
||||
KICADSEXPR,
|
||||
ORCADPCB2,
|
||||
CADSTAR,
|
||||
SPICE,
|
||||
SPICEMODEL
|
||||
};
|
||||
|
||||
FORMAT format;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -138,6 +138,8 @@ const std::string LegacySchematicFileExtension( "sch" );
|
|||
const std::string EagleSchematicFileExtension( "sch" );
|
||||
const std::string CadstarSchematicFileExtension( "csa" );
|
||||
const std::string KiCadSchematicFileExtension( "kicad_sch" );
|
||||
const std::string SpiceFileExtension( "cir" );
|
||||
const std::string CadstarNetlistFileExtension( "frp" );
|
||||
const std::string OrCadPcb2NetlistFileExtension( "net" );
|
||||
const std::string NetlistFileExtension( "net" );
|
||||
const std::string FootprintAssignmentFileExtension( "cmp" );
|
||||
|
|
|
@ -579,12 +579,12 @@ bool NETLIST_DIALOG::FilenamePrms( NETLIST_TYPE_ID aType, wxString * aExt, wxStr
|
|||
switch( aType )
|
||||
{
|
||||
case NET_TYPE_SPICE:
|
||||
fileExt = wxT( "cir" );
|
||||
fileExt = SpiceFileExtension;
|
||||
fileWildcard = SpiceNetlistFileWildcard();
|
||||
break;
|
||||
|
||||
case NET_TYPE_CADSTAR:
|
||||
fileExt = wxT( "frp" );
|
||||
fileExt = CadstarNetlistFileExtension;
|
||||
fileWildcard = CadstarNetlistFileWildcard();
|
||||
break;
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "eeschema_jobs_handler.h"
|
||||
#include <cli/exit_codes.h>
|
||||
#include <jobs/job_export_sch_netlist.h>
|
||||
#include <jobs/job_export_sch_pdf.h>
|
||||
#include <jobs/job_export_sch_svg.h>
|
||||
#include <pgm_base.h>
|
||||
|
@ -30,12 +31,25 @@
|
|||
#include <connection_graph.h>
|
||||
#include "eeschema_helpers.h"
|
||||
#include <sch_painter.h>
|
||||
#include <erc.h>
|
||||
#include <wildcards_and_files_ext.h>
|
||||
|
||||
#include <settings/settings_manager.h>
|
||||
|
||||
#include <netlist.h>
|
||||
#include <netlist_exporter_base.h>
|
||||
#include <netlist_exporter_orcadpcb2.h>
|
||||
#include <netlist_exporter_cadstar.h>
|
||||
#include <netlist_exporter_spice.h>
|
||||
#include <netlist_exporter_spice_model.h>
|
||||
#include <netlist_exporter_kicad.h>
|
||||
#include <netlist_exporter_xml.h>
|
||||
|
||||
|
||||
EESCHEMA_JOBS_HANDLER::EESCHEMA_JOBS_HANDLER()
|
||||
{
|
||||
Register( "netlist",
|
||||
std::bind( &EESCHEMA_JOBS_HANDLER::JobExportNetlist, this, std::placeholders::_1 ) );
|
||||
Register( "pdf",
|
||||
std::bind( &EESCHEMA_JOBS_HANDLER::JobExportPdf, this, std::placeholders::_1 ) );
|
||||
Register( "svg",
|
||||
|
@ -81,7 +95,7 @@ int EESCHEMA_JOBS_HANDLER::JobExportPdf( JOB* aJob )
|
|||
|
||||
schPlotter->Plot( PLOT_FORMAT::PDF, settings, renderSettings.get(), nullptr );
|
||||
|
||||
return 0;
|
||||
return CLI::EXIT_CODES::OK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -107,5 +121,92 @@ int EESCHEMA_JOBS_HANDLER::JobExportSvg( JOB* aJob )
|
|||
|
||||
schPlotter->Plot( PLOT_FORMAT::SVG, settings, renderSettings.get(), nullptr );
|
||||
|
||||
return 0;
|
||||
return CLI::EXIT_CODES::OK;
|
||||
}
|
||||
|
||||
|
||||
int EESCHEMA_JOBS_HANDLER::JobExportNetlist( JOB* aJob )
|
||||
{
|
||||
JOB_EXPORT_SCH_NETLIST* aNetJob = dynamic_cast<JOB_EXPORT_SCH_NETLIST*>( aJob );
|
||||
|
||||
SCHEMATIC* sch = EESCHEMA_HELPERS::LoadSchematic( aNetJob->m_filename, SCH_IO_MGR::SCH_KICAD );
|
||||
|
||||
// Annotation warning check
|
||||
SCH_REFERENCE_LIST referenceList;
|
||||
sch->GetSheets().GetSymbols( referenceList );
|
||||
if( referenceList.GetCount() > 0 )
|
||||
{
|
||||
if( referenceList.CheckAnnotation( []( ERCE_T, const wxString&, SCH_REFERENCE*, SCH_REFERENCE* ) {} ) > 0 )
|
||||
{
|
||||
wxPrintf( _( "Warning: schematic has annotation errors, please use the schematic editor to fix them\n" ) );
|
||||
}
|
||||
}
|
||||
|
||||
// Test duplicate sheet names:
|
||||
ERC_TESTER erc( sch );
|
||||
|
||||
if( erc.TestDuplicateSheetNames( false ) > 0 )
|
||||
{
|
||||
wxPrintf( _( "Warning: duplicate sheet names.\n" ) );
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<NETLIST_EXPORTER_BASE> helper;
|
||||
|
||||
wxString fileExt;
|
||||
|
||||
switch( aNetJob->format )
|
||||
{
|
||||
case JOB_EXPORT_SCH_NETLIST::FORMAT::KICADSEXPR:
|
||||
fileExt = NetlistFileExtension;
|
||||
helper = std::make_unique<NETLIST_EXPORTER_KICAD>( sch );
|
||||
break;
|
||||
|
||||
case JOB_EXPORT_SCH_NETLIST::FORMAT::ORCADPCB2:
|
||||
fileExt = OrCadPcb2NetlistFileExtension;
|
||||
helper = std::make_unique<NETLIST_EXPORTER_ORCADPCB2>( sch );
|
||||
break;
|
||||
|
||||
case JOB_EXPORT_SCH_NETLIST::FORMAT::CADSTAR:
|
||||
fileExt = CadstarNetlistFileExtension;
|
||||
helper = std::make_unique<NETLIST_EXPORTER_CADSTAR>( sch );
|
||||
break;
|
||||
|
||||
case JOB_EXPORT_SCH_NETLIST::FORMAT::SPICE:
|
||||
fileExt = SpiceFileExtension;
|
||||
helper = std::make_unique<NETLIST_EXPORTER_SPICE>( sch );
|
||||
break;
|
||||
|
||||
case JOB_EXPORT_SCH_NETLIST::FORMAT::SPICEMODEL:
|
||||
fileExt = SpiceFileExtension;
|
||||
helper = std::make_unique<NETLIST_EXPORTER_SPICE_MODEL>( sch );
|
||||
break;
|
||||
|
||||
case JOB_EXPORT_SCH_NETLIST::FORMAT::KICADXML:
|
||||
fileExt = wxS( "xml" );
|
||||
helper = std::make_unique<NETLIST_EXPORTER_XML>( sch );
|
||||
break;
|
||||
default:
|
||||
wxFprintf( stderr, _( "Unknown netlist format.\n" ) );
|
||||
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
||||
}
|
||||
|
||||
|
||||
if( aNetJob->m_outputFile.IsEmpty() )
|
||||
{
|
||||
wxFileName fn = sch->GetFileName();
|
||||
fn.SetName( fn.GetName() );
|
||||
fn.SetExt( fileExt );
|
||||
|
||||
aNetJob->m_outputFile = fn.GetFullName();
|
||||
}
|
||||
|
||||
bool res = helper->WriteNetlist( aNetJob->m_outputFile, 0 );
|
||||
|
||||
if(!res)
|
||||
{
|
||||
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
||||
}
|
||||
|
||||
return CLI::EXIT_CODES::OK;
|
||||
}
|
|
@ -38,6 +38,7 @@ class EESCHEMA_JOBS_HANDLER : public JOB_DISPATCHER
|
|||
{
|
||||
public:
|
||||
EESCHEMA_JOBS_HANDLER();
|
||||
int JobExportNetlist( JOB* aJob );
|
||||
int JobExportPdf( JOB* aJob );
|
||||
int JobExportSvg( JOB* aJob );
|
||||
|
||||
|
|
|
@ -123,6 +123,8 @@ extern const std::string LegacySchematicFileExtension;
|
|||
extern const std::string EagleSchematicFileExtension;
|
||||
extern const std::string CadstarSchematicFileExtension;
|
||||
extern const std::string KiCadSchematicFileExtension;
|
||||
extern const std::string SpiceFileExtension;
|
||||
extern const std::string CadstarNetlistFileExtension;
|
||||
extern const std::string OrCadPcb2NetlistFileExtension;
|
||||
extern const std::string NetlistFileExtension;
|
||||
extern const std::string GerberFileExtension;
|
||||
|
|
|
@ -26,6 +26,7 @@ set( KICAD_SRCS
|
|||
cli/command_export_pcb_svg.cpp
|
||||
cli/command_pcb.cpp
|
||||
cli/command_pcb_export.cpp
|
||||
cli/command_export_sch_netlist.cpp
|
||||
cli/command_export_sch_pdf.cpp
|
||||
cli/command_export_sch_svg.cpp
|
||||
cli/command_sch.cpp
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2022 Mark Roszko <mark.roszko@gmail.com>
|
||||
* Copyright (C) 1992-2022 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 as published by the
|
||||
* Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "command_export_sch_netlist.h"
|
||||
#include <cli/exit_codes.h>
|
||||
#include "jobs/job_export_sch_netlist.h"
|
||||
#include <kiface_base.h>
|
||||
#include <layer_ids.h>
|
||||
#include <wx/crt.h>
|
||||
|
||||
#include <macros.h>
|
||||
|
||||
#define ARG_FORMAT "--format"
|
||||
|
||||
CLI::EXPORT_SCH_NETLIST_COMMAND::EXPORT_SCH_NETLIST_COMMAND() : EXPORT_PCB_BASE_COMMAND( "netlist" )
|
||||
{
|
||||
m_argParser.add_argument( ARG_FORMAT )
|
||||
.default_value( std::string( "kicadsexpr" ) )
|
||||
.help( "Netlist output format, valid options: kicadsexpr, kicadxml, cadstar, orcadpcb2, spice, spicemodel" );
|
||||
}
|
||||
|
||||
|
||||
int CLI::EXPORT_SCH_NETLIST_COMMAND::Perform( KIWAY& aKiway )
|
||||
{
|
||||
JOB_EXPORT_SCH_NETLIST* netJob = new JOB_EXPORT_SCH_NETLIST( true );
|
||||
|
||||
netJob->m_filename = FROM_UTF8( m_argParser.get<std::string>( ARG_INPUT ).c_str() );
|
||||
netJob->m_outputFile = FROM_UTF8( m_argParser.get<std::string>( ARG_OUTPUT ).c_str() );
|
||||
|
||||
if( !wxFile::Exists( netJob->m_filename ) )
|
||||
{
|
||||
wxFprintf( stderr, _( "Schematic file does not exist or is not accessible\n" ) );
|
||||
return EXIT_CODES::ERR_INVALID_INPUT_FILE;
|
||||
}
|
||||
|
||||
wxString format = FROM_UTF8( m_argParser.get<std::string>( ARG_FORMAT ).c_str() );
|
||||
if( format == "kicadsexpr" )
|
||||
{
|
||||
netJob->format = JOB_EXPORT_SCH_NETLIST::FORMAT::KICADSEXPR;
|
||||
}
|
||||
else if( format == "kicadxml" )
|
||||
{
|
||||
netJob->format = JOB_EXPORT_SCH_NETLIST::FORMAT::KICADXML;
|
||||
}
|
||||
else if( format == "cadstar" )
|
||||
{
|
||||
netJob->format = JOB_EXPORT_SCH_NETLIST::FORMAT::CADSTAR;
|
||||
}
|
||||
else if( format == "orcadpcb2" )
|
||||
{
|
||||
netJob->format = JOB_EXPORT_SCH_NETLIST::FORMAT::ORCADPCB2;
|
||||
}
|
||||
else if( format == "spice" )
|
||||
{
|
||||
netJob->format = JOB_EXPORT_SCH_NETLIST::FORMAT::SPICE;
|
||||
}
|
||||
else if( format == "spicemodel" )
|
||||
{
|
||||
netJob->format = JOB_EXPORT_SCH_NETLIST::FORMAT::SPICEMODEL;
|
||||
}
|
||||
else
|
||||
{
|
||||
wxFprintf( stderr, _( "Invalid format\n" ) );
|
||||
return EXIT_CODES::ERR_ARGS;
|
||||
}
|
||||
|
||||
int exitCode = aKiway.ProcessJob( KIWAY::FACE_SCH, netJob );
|
||||
|
||||
return exitCode;
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2022 Mark Roszko <mark.roszko@gmail.com>
|
||||
* Copyright (C) 1992-2022 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 as published by the
|
||||
* Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef COMMAND_EXPORT_SCH_NETLIST_H
|
||||
#define COMMAND_EXPORT_SCH_NETLIST_H
|
||||
|
||||
#include "command_export_pcb_base.h"
|
||||
|
||||
namespace CLI
|
||||
{
|
||||
class EXPORT_SCH_NETLIST_COMMAND : public EXPORT_PCB_BASE_COMMAND
|
||||
{
|
||||
public:
|
||||
EXPORT_SCH_NETLIST_COMMAND();
|
||||
|
||||
int Perform( KIWAY& aKiway ) override;
|
||||
};
|
||||
} // namespace CLI
|
||||
|
||||
#endif
|
|
@ -55,6 +55,7 @@
|
|||
#include "cli/command_export_pcb_pos.h"
|
||||
#include "cli/command_export_pcb_svg.h"
|
||||
#include "cli/command_export_pcb_step.h"
|
||||
#include "cli/command_export_sch_netlist.h"
|
||||
#include "cli/command_export_sch_pdf.h"
|
||||
#include "cli/command_export_sch_svg.h"
|
||||
#include "cli/command_sch.h"
|
||||
|
@ -106,19 +107,20 @@ struct COMMAND_ENTRY
|
|||
handler( aHandler ), subCommands( aSub ){};
|
||||
};
|
||||
|
||||
static CLI::EXPORT_PCB_DRILL_COMMAND exportPcbDrillCmd{};
|
||||
static CLI::EXPORT_PCB_DXF_COMMAND exportPcbDxfCmd{};
|
||||
static CLI::EXPORT_PCB_STEP_COMMAND exportPcbStepCmd{};
|
||||
static CLI::EXPORT_PCB_SVG_COMMAND exportPcbSvgCmd{};
|
||||
static CLI::EXPORT_PCB_PDF_COMMAND exportPcbPdfCmd{};
|
||||
static CLI::EXPORT_PCB_POS_COMMAND exportPcbPosCmd{};
|
||||
static CLI::EXPORT_PCB_GERBER_COMMAND exportPcbGerberCmd{};
|
||||
static CLI::EXPORT_PCB_COMMAND exportPcbCmd{};
|
||||
static CLI::PCB_COMMAND pcbCmd{};
|
||||
static CLI::EXPORT_SCH_COMMAND exportSchCmd{};
|
||||
static CLI::SCH_COMMAND schCmd{};
|
||||
static CLI::EXPORT_SCH_PDF_COMMAND exportSchPdfCmd{};
|
||||
static CLI::EXPORT_SCH_SVG_COMMAND exportSchSvgCmd{};
|
||||
static CLI::EXPORT_PCB_DRILL_COMMAND exportPcbDrillCmd{};
|
||||
static CLI::EXPORT_PCB_DXF_COMMAND exportPcbDxfCmd{};
|
||||
static CLI::EXPORT_PCB_STEP_COMMAND exportPcbStepCmd{};
|
||||
static CLI::EXPORT_PCB_SVG_COMMAND exportPcbSvgCmd{};
|
||||
static CLI::EXPORT_PCB_PDF_COMMAND exportPcbPdfCmd{};
|
||||
static CLI::EXPORT_PCB_POS_COMMAND exportPcbPosCmd{};
|
||||
static CLI::EXPORT_PCB_GERBER_COMMAND exportPcbGerberCmd{};
|
||||
static CLI::EXPORT_PCB_COMMAND exportPcbCmd{};
|
||||
static CLI::PCB_COMMAND pcbCmd{};
|
||||
static CLI::EXPORT_SCH_COMMAND exportSchCmd{};
|
||||
static CLI::SCH_COMMAND schCmd{};
|
||||
static CLI::EXPORT_SCH_NETLIST_COMMAND exportSchNetlistCmd{};
|
||||
static CLI::EXPORT_SCH_PDF_COMMAND exportSchPdfCmd{};
|
||||
static CLI::EXPORT_SCH_SVG_COMMAND exportSchSvgCmd{};
|
||||
|
||||
static std::vector<COMMAND_ENTRY> commandStack = {
|
||||
{
|
||||
|
@ -142,6 +144,7 @@ static std::vector<COMMAND_ENTRY> commandStack = {
|
|||
{
|
||||
{ &exportSchCmd,
|
||||
{
|
||||
&exportSchNetlistCmd,
|
||||
&exportSchPdfCmd,
|
||||
&exportSchSvgCmd
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue