Add schematic xml bom output
This commit is contained in:
parent
3dd2ae762d
commit
39d5cc31d4
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
* 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_BOM_H
|
||||||
|
#define JOB_EXPORT_SCH_BOM_H
|
||||||
|
|
||||||
|
#include <wx/string.h>
|
||||||
|
#include "job.h"
|
||||||
|
|
||||||
|
class JOB_EXPORT_SCH_BOM : public JOB
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
JOB_EXPORT_SCH_BOM( bool aIsCli ) :
|
||||||
|
JOB( "bom", aIsCli ),
|
||||||
|
m_filename(),
|
||||||
|
m_outputFile()
|
||||||
|
{
|
||||||
|
format = FORMAT::XML;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString m_filename;
|
||||||
|
wxString m_outputFile;
|
||||||
|
|
||||||
|
enum class FORMAT
|
||||||
|
{
|
||||||
|
XML
|
||||||
|
};
|
||||||
|
|
||||||
|
FORMAT format;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
#include "eeschema_jobs_handler.h"
|
#include "eeschema_jobs_handler.h"
|
||||||
#include <cli/exit_codes.h>
|
#include <cli/exit_codes.h>
|
||||||
|
#include <jobs/job_export_sch_bom.h>
|
||||||
#include <jobs/job_export_sch_netlist.h>
|
#include <jobs/job_export_sch_netlist.h>
|
||||||
#include <jobs/job_export_sch_pdf.h>
|
#include <jobs/job_export_sch_pdf.h>
|
||||||
#include <jobs/job_export_sch_svg.h>
|
#include <jobs/job_export_sch_svg.h>
|
||||||
|
@ -48,6 +49,8 @@
|
||||||
|
|
||||||
EESCHEMA_JOBS_HANDLER::EESCHEMA_JOBS_HANDLER()
|
EESCHEMA_JOBS_HANDLER::EESCHEMA_JOBS_HANDLER()
|
||||||
{
|
{
|
||||||
|
Register( "bom",
|
||||||
|
std::bind( &EESCHEMA_JOBS_HANDLER::JobExportBom, this, std::placeholders::_1 ) );
|
||||||
Register( "netlist",
|
Register( "netlist",
|
||||||
std::bind( &EESCHEMA_JOBS_HANDLER::JobExportNetlist, this, std::placeholders::_1 ) );
|
std::bind( &EESCHEMA_JOBS_HANDLER::JobExportNetlist, this, std::placeholders::_1 ) );
|
||||||
Register( "pdf",
|
Register( "pdf",
|
||||||
|
@ -210,3 +213,63 @@ int EESCHEMA_JOBS_HANDLER::JobExportNetlist( JOB* aJob )
|
||||||
|
|
||||||
return CLI::EXIT_CODES::OK;
|
return CLI::EXIT_CODES::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int EESCHEMA_JOBS_HANDLER::JobExportBom( JOB* aJob )
|
||||||
|
{
|
||||||
|
JOB_EXPORT_SCH_BOM* aNetJob = dynamic_cast<JOB_EXPORT_SCH_BOM*>( 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" ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( aNetJob->format == JOB_EXPORT_SCH_BOM::FORMAT::XML )
|
||||||
|
{
|
||||||
|
std::unique_ptr<NETLIST_EXPORTER_XML> xmlNetlist =
|
||||||
|
std::make_unique<NETLIST_EXPORTER_XML>( sch );
|
||||||
|
|
||||||
|
wxString fileExt = wxS( "xml" );
|
||||||
|
|
||||||
|
if( aNetJob->m_outputFile.IsEmpty() )
|
||||||
|
{
|
||||||
|
wxFileName fn = sch->GetFileName();
|
||||||
|
fn.SetName( fn.GetName() + "-bom" );
|
||||||
|
fn.SetExt( fileExt );
|
||||||
|
|
||||||
|
aNetJob->m_outputFile = fn.GetFullName();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool res = xmlNetlist->WriteNetlist( aNetJob->m_outputFile, GNL_OPT_BOM );
|
||||||
|
|
||||||
|
if( !res )
|
||||||
|
{
|
||||||
|
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
return CLI::EXIT_CODES::OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return CLI::EXIT_CODES::ERR_UNKNOWN;
|
||||||
|
}
|
|
@ -38,6 +38,7 @@ class EESCHEMA_JOBS_HANDLER : public JOB_DISPATCHER
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
EESCHEMA_JOBS_HANDLER();
|
EESCHEMA_JOBS_HANDLER();
|
||||||
|
int JobExportBom( JOB* aJob );
|
||||||
int JobExportNetlist( JOB* aJob );
|
int JobExportNetlist( JOB* aJob );
|
||||||
int JobExportPdf( JOB* aJob );
|
int JobExportPdf( JOB* aJob );
|
||||||
int JobExportSvg( JOB* aJob );
|
int JobExportSvg( JOB* aJob );
|
||||||
|
|
|
@ -53,7 +53,14 @@ bool NETLIST_EXPORTER_XML::WriteNetlist( const wxString& aOutFileName, unsigned
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
wxXmlDocument xdoc;
|
wxXmlDocument xdoc;
|
||||||
xdoc.SetRoot( makeRoot( GNL_ALL | aNetlistOptions ) );
|
|
||||||
|
unsigned aCtl = aNetlistOptions;
|
||||||
|
if( aNetlistOptions & GNL_OPT_BOM )
|
||||||
|
aCtl |= ( GNL_SYMBOLS | GNL_HEADER );
|
||||||
|
else
|
||||||
|
aCtl |= GNL_ALL;
|
||||||
|
|
||||||
|
xdoc.SetRoot( makeRoot( aCtl ) );
|
||||||
|
|
||||||
return xdoc.Save( stream, 2 /* indent bug, today was ignored by wxXml lib */ );
|
return xdoc.Save( stream, 2 /* indent bug, today was ignored by wxXml lib */ );
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ set( KICAD_SRCS
|
||||||
cli/command_export_pcb_svg.cpp
|
cli/command_export_pcb_svg.cpp
|
||||||
cli/command_pcb.cpp
|
cli/command_pcb.cpp
|
||||||
cli/command_pcb_export.cpp
|
cli/command_pcb_export.cpp
|
||||||
|
cli/command_export_sch_bom.cpp
|
||||||
cli/command_export_sch_netlist.cpp
|
cli/command_export_sch_netlist.cpp
|
||||||
cli/command_export_sch_pdf.cpp
|
cli/command_export_sch_pdf.cpp
|
||||||
cli/command_export_sch_svg.cpp
|
cli/command_export_sch_svg.cpp
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
* 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_bom.h"
|
||||||
|
#include <cli/exit_codes.h>
|
||||||
|
#include "jobs/job_export_sch_bom.h"
|
||||||
|
#include <kiface_base.h>
|
||||||
|
#include <layer_ids.h>
|
||||||
|
#include <wx/crt.h>
|
||||||
|
|
||||||
|
#include <macros.h>
|
||||||
|
|
||||||
|
#define ARG_FORMAT "--format"
|
||||||
|
|
||||||
|
CLI::EXPORT_SCH_BOM_COMMAND::EXPORT_SCH_BOM_COMMAND() : EXPORT_PCB_BASE_COMMAND( "bom" )
|
||||||
|
{
|
||||||
|
m_argParser.add_argument( ARG_FORMAT )
|
||||||
|
.default_value( std::string( "xml" ) )
|
||||||
|
.help( "Bom output format, valid options: xml" );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int CLI::EXPORT_SCH_BOM_COMMAND::Perform( KIWAY& aKiway )
|
||||||
|
{
|
||||||
|
std::unique_ptr<JOB_EXPORT_SCH_BOM> bomJob =
|
||||||
|
std::make_unique<JOB_EXPORT_SCH_BOM>( true );
|
||||||
|
|
||||||
|
bomJob->m_filename = FROM_UTF8( m_argParser.get<std::string>( ARG_INPUT ).c_str() );
|
||||||
|
bomJob->m_outputFile = FROM_UTF8( m_argParser.get<std::string>( ARG_OUTPUT ).c_str() );
|
||||||
|
|
||||||
|
if( !wxFile::Exists( bomJob->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 == "xml" )
|
||||||
|
{
|
||||||
|
bomJob->format = JOB_EXPORT_SCH_BOM::FORMAT::XML;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxFprintf( stderr, _( "Invalid format\n" ) );
|
||||||
|
return EXIT_CODES::ERR_ARGS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int exitCode = aKiway.ProcessJob( KIWAY::FACE_SCH, bomJob.get() );
|
||||||
|
|
||||||
|
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_BOM_H
|
||||||
|
#define COMMAND_EXPORT_SCH_BOM_H
|
||||||
|
|
||||||
|
#include "command_export_pcb_base.h"
|
||||||
|
|
||||||
|
namespace CLI
|
||||||
|
{
|
||||||
|
class EXPORT_SCH_BOM_COMMAND : public EXPORT_PCB_BASE_COMMAND
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
EXPORT_SCH_BOM_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_pos.h"
|
||||||
#include "cli/command_export_pcb_svg.h"
|
#include "cli/command_export_pcb_svg.h"
|
||||||
#include "cli/command_export_pcb_step.h"
|
#include "cli/command_export_pcb_step.h"
|
||||||
|
#include "cli/command_export_sch_bom.h"
|
||||||
#include "cli/command_export_sch_netlist.h"
|
#include "cli/command_export_sch_netlist.h"
|
||||||
#include "cli/command_export_sch_pdf.h"
|
#include "cli/command_export_sch_pdf.h"
|
||||||
#include "cli/command_export_sch_svg.h"
|
#include "cli/command_export_sch_svg.h"
|
||||||
|
@ -118,6 +119,7 @@ static CLI::EXPORT_PCB_COMMAND exportPcbCmd{};
|
||||||
static CLI::PCB_COMMAND pcbCmd{};
|
static CLI::PCB_COMMAND pcbCmd{};
|
||||||
static CLI::EXPORT_SCH_COMMAND exportSchCmd{};
|
static CLI::EXPORT_SCH_COMMAND exportSchCmd{};
|
||||||
static CLI::SCH_COMMAND schCmd{};
|
static CLI::SCH_COMMAND schCmd{};
|
||||||
|
static CLI::EXPORT_SCH_BOM_COMMAND exportSchBomCmd{};
|
||||||
static CLI::EXPORT_SCH_NETLIST_COMMAND exportSchNetlistCmd{};
|
static CLI::EXPORT_SCH_NETLIST_COMMAND exportSchNetlistCmd{};
|
||||||
static CLI::EXPORT_SCH_PDF_COMMAND exportSchPdfCmd{};
|
static CLI::EXPORT_SCH_PDF_COMMAND exportSchPdfCmd{};
|
||||||
static CLI::EXPORT_SCH_SVG_COMMAND exportSchSvgCmd{};
|
static CLI::EXPORT_SCH_SVG_COMMAND exportSchSvgCmd{};
|
||||||
|
@ -144,6 +146,7 @@ static std::vector<COMMAND_ENTRY> commandStack = {
|
||||||
{
|
{
|
||||||
{ &exportSchCmd,
|
{ &exportSchCmd,
|
||||||
{
|
{
|
||||||
|
&exportSchBomCmd,
|
||||||
&exportSchNetlistCmd,
|
&exportSchNetlistCmd,
|
||||||
&exportSchPdfCmd,
|
&exportSchPdfCmd,
|
||||||
&exportSchSvgCmd
|
&exportSchSvgCmd
|
||||||
|
|
Loading…
Reference in New Issue