Add schematic xml bom output

This commit is contained in:
Marek Roszko 2022-11-12 21:35:33 -05:00
parent 3dd2ae762d
commit 39d5cc31d4
8 changed files with 230 additions and 1 deletions

View File

@ -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

View File

@ -20,6 +20,7 @@
#include "eeschema_jobs_handler.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_pdf.h>
#include <jobs/job_export_sch_svg.h>
@ -48,6 +49,8 @@
EESCHEMA_JOBS_HANDLER::EESCHEMA_JOBS_HANDLER()
{
Register( "bom",
std::bind( &EESCHEMA_JOBS_HANDLER::JobExportBom, this, std::placeholders::_1 ) );
Register( "netlist",
std::bind( &EESCHEMA_JOBS_HANDLER::JobExportNetlist, this, std::placeholders::_1 ) );
Register( "pdf",
@ -209,4 +212,64 @@ int EESCHEMA_JOBS_HANDLER::JobExportNetlist( JOB* aJob )
}
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;
}

View File

@ -38,6 +38,7 @@ class EESCHEMA_JOBS_HANDLER : public JOB_DISPATCHER
{
public:
EESCHEMA_JOBS_HANDLER();
int JobExportBom( JOB* aJob );
int JobExportNetlist( JOB* aJob );
int JobExportPdf( JOB* aJob );
int JobExportSvg( JOB* aJob );

View File

@ -53,7 +53,14 @@ bool NETLIST_EXPORTER_XML::WriteNetlist( const wxString& aOutFileName, unsigned
return false;
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 */ );
}

View File

@ -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_bom.cpp
cli/command_export_sch_netlist.cpp
cli/command_export_sch_pdf.cpp
cli/command_export_sch_svg.cpp

View File

@ -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;
}

View File

@ -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

View File

@ -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_bom.h"
#include "cli/command_export_sch_netlist.h"
#include "cli/command_export_sch_pdf.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::EXPORT_SCH_COMMAND exportSchCmd{};
static CLI::SCH_COMMAND schCmd{};
static CLI::EXPORT_SCH_BOM_COMMAND exportSchBomCmd{};
static CLI::EXPORT_SCH_NETLIST_COMMAND exportSchNetlistCmd{};
static CLI::EXPORT_SCH_PDF_COMMAND exportSchPdfCmd{};
static CLI::EXPORT_SCH_SVG_COMMAND exportSchSvgCmd{};
@ -144,6 +146,7 @@ static std::vector<COMMAND_ENTRY> commandStack = {
{
{ &exportSchCmd,
{
&exportSchBomCmd,
&exportSchNetlistCmd,
&exportSchPdfCmd,
&exportSchSvgCmd