Rename the bom cli to pythonbom since we'll have a real bom system later

This commit is contained in:
Marek Roszko 2022-11-30 19:56:59 -05:00
parent f5770fe7e0
commit bae8cb55c0
8 changed files with 63 additions and 97 deletions

View File

@ -18,32 +18,24 @@
* with this program. If not, see <http://www.gnu.org/licenses/>. * with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef JOB_EXPORT_SCH_BOM_H #ifndef JOB_EXPORT_SCH_PYTHONBOM_H
#define JOB_EXPORT_SCH_BOM_H #define JOB_EXPORT_SCH_PYTHONBOM_H
#include <wx/string.h> #include <wx/string.h>
#include "job.h" #include "job.h"
class JOB_EXPORT_SCH_BOM : public JOB class JOB_EXPORT_SCH_PYTHONBOM : public JOB
{ {
public: public:
JOB_EXPORT_SCH_BOM( bool aIsCli ) : JOB_EXPORT_SCH_PYTHONBOM( bool aIsCli ) :
JOB( "bom", aIsCli ), JOB( "pythonbom", aIsCli ),
m_filename(), m_filename(),
m_outputFile() m_outputFile()
{ {
format = FORMAT::XML;
} }
wxString m_filename; wxString m_filename;
wxString m_outputFile; wxString m_outputFile;
enum class FORMAT
{
XML
};
FORMAT format;
}; };
#endif #endif

View File

@ -20,7 +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_pythonbom.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>
@ -53,8 +53,8 @@
EESCHEMA_JOBS_HANDLER::EESCHEMA_JOBS_HANDLER() EESCHEMA_JOBS_HANDLER::EESCHEMA_JOBS_HANDLER()
{ {
Register( "bom", Register( "pythonbom",
std::bind( &EESCHEMA_JOBS_HANDLER::JobExportBom, this, std::placeholders::_1 ) ); std::bind( &EESCHEMA_JOBS_HANDLER::JobExportPythonBom, 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",
@ -261,9 +261,9 @@ int EESCHEMA_JOBS_HANDLER::JobExportNetlist( JOB* aJob )
} }
int EESCHEMA_JOBS_HANDLER::JobExportBom( JOB* aJob ) int EESCHEMA_JOBS_HANDLER::JobExportPythonBom( JOB* aJob )
{ {
JOB_EXPORT_SCH_BOM* aNetJob = dynamic_cast<JOB_EXPORT_SCH_BOM*>( aJob ); JOB_EXPORT_SCH_PYTHONBOM* aNetJob = dynamic_cast<JOB_EXPORT_SCH_PYTHONBOM*>( aJob );
SCHEMATIC* sch = EESCHEMA_HELPERS::LoadSchematic( aNetJob->m_filename, SCH_IO_MGR::SCH_KICAD ); SCHEMATIC* sch = EESCHEMA_HELPERS::LoadSchematic( aNetJob->m_filename, SCH_IO_MGR::SCH_KICAD );
@ -297,33 +297,28 @@ int EESCHEMA_JOBS_HANDLER::JobExportBom( JOB* aJob )
wxPrintf( _( "Warning: duplicate sheet names.\n" ) ); 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() )
{ {
std::unique_ptr<NETLIST_EXPORTER_XML> xmlNetlist = wxFileName fn = sch->GetFileName();
std::make_unique<NETLIST_EXPORTER_XML>( sch ); fn.SetName( fn.GetName() + "-bom" );
fn.SetExt( fileExt );
wxString fileExt = wxS( "xml" ); aNetJob->m_outputFile = fn.GetFullName();
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, *this );
if( !res )
{
return CLI::EXIT_CODES::ERR_UNKNOWN;
}
return CLI::EXIT_CODES::OK;
} }
return CLI::EXIT_CODES::ERR_UNKNOWN; bool res = xmlNetlist->WriteNetlist( aNetJob->m_outputFile, GNL_OPT_BOM, *this );
if( !res )
{
return CLI::EXIT_CODES::ERR_UNKNOWN;
}
return CLI::EXIT_CODES::OK;
} }

View File

@ -39,7 +39,7 @@ class EESCHEMA_JOBS_HANDLER : public JOB_DISPATCHER, REPORTER
{ {
public: public:
EESCHEMA_JOBS_HANDLER(); EESCHEMA_JOBS_HANDLER();
int JobExportBom( JOB* aJob ); int JobExportPythonBom( 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 );

View File

@ -54,15 +54,7 @@ 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 | GNL_PARTS );
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 */ );
} }

View File

@ -27,7 +27,7 @@ set( KICAD_SRCS
cli/command_export_pcb_svg.cpp cli/command_export_pcb_svg.cpp
cli/command_fp_upgrade.cpp cli/command_fp_upgrade.cpp
cli/command_pcb_export.cpp cli/command_pcb_export.cpp
cli/command_export_sch_bom.cpp cli/command_export_sch_pythonbom.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

View File

@ -18,29 +18,26 @@
* with this program. If not, see <http://www.gnu.org/licenses/>. * with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "command_export_sch_bom.h" #include "command_export_sch_pythonbom.h"
#include <cli/exit_codes.h> #include <cli/exit_codes.h>
#include "jobs/job_export_sch_bom.h" #include "jobs/job_export_sch_pythonbom.h"
#include <kiface_base.h> #include <kiface_base.h>
#include <layer_ids.h> #include <layer_ids.h>
#include <wx/crt.h> #include <wx/crt.h>
#include <macros.h> #include <macros.h>
#define ARG_FORMAT "--format"
CLI::EXPORT_SCH_BOM_COMMAND::EXPORT_SCH_BOM_COMMAND() : EXPORT_PCB_BASE_COMMAND( "bom" ) CLI::EXPORT_SCH_PYTHONBOM_COMMAND::EXPORT_SCH_PYTHONBOM_COMMAND() :
EXPORT_PCB_BASE_COMMAND( "python-bom" )
{ {
m_argParser.add_argument( ARG_FORMAT )
.default_value( std::string( "xml" ) )
.help( UTF8STDSTR( _( "Bom output format, valid options: xml" ) ) );
} }
int CLI::EXPORT_SCH_BOM_COMMAND::Perform( KIWAY& aKiway ) int CLI::EXPORT_SCH_PYTHONBOM_COMMAND::Perform( KIWAY& aKiway )
{ {
std::unique_ptr<JOB_EXPORT_SCH_BOM> bomJob = std::unique_ptr<JOB_EXPORT_SCH_PYTHONBOM> bomJob =
std::make_unique<JOB_EXPORT_SCH_BOM>( true ); std::make_unique<JOB_EXPORT_SCH_PYTHONBOM>( true );
bomJob->m_filename = FROM_UTF8( m_argParser.get<std::string>( ARG_INPUT ).c_str() ); 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() ); bomJob->m_outputFile = FROM_UTF8( m_argParser.get<std::string>( ARG_OUTPUT ).c_str() );
@ -51,16 +48,6 @@ int CLI::EXPORT_SCH_BOM_COMMAND::Perform( KIWAY& aKiway )
return EXIT_CODES::ERR_INVALID_INPUT_FILE; 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() ); int exitCode = aKiway.ProcessJob( KIWAY::FACE_SCH, bomJob.get() );

View File

@ -18,17 +18,17 @@
* with this program. If not, see <http://www.gnu.org/licenses/>. * with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef COMMAND_EXPORT_SCH_BOM_H #ifndef COMMAND_EXPORT_SCH_PYTHONBOM_H
#define COMMAND_EXPORT_SCH_BOM_H #define COMMAND_EXPORT_SCH_PYTHONBOM_H
#include "command_export_pcb_base.h" #include "command_export_pcb_base.h"
namespace CLI namespace CLI
{ {
class EXPORT_SCH_BOM_COMMAND : public EXPORT_PCB_BASE_COMMAND class EXPORT_SCH_PYTHONBOM_COMMAND : public EXPORT_PCB_BASE_COMMAND
{ {
public: public:
EXPORT_SCH_BOM_COMMAND(); EXPORT_SCH_PYTHONBOM_COMMAND();
int Perform( KIWAY& aKiway ) override; int Perform( KIWAY& aKiway ) override;
}; };

View File

@ -56,7 +56,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_pythonbom.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"
@ -113,25 +113,25 @@ struct COMMAND_ENTRY
handler( aHandler ), subCommands( aSub ){}; handler( aHandler ), subCommands( aSub ){};
}; };
static CLI::EXPORT_PCB_DRILL_COMMAND exportPcbDrillCmd{}; static CLI::EXPORT_PCB_DRILL_COMMAND exportPcbDrillCmd{};
static CLI::EXPORT_PCB_DXF_COMMAND exportPcbDxfCmd{}; static CLI::EXPORT_PCB_DXF_COMMAND exportPcbDxfCmd{};
static CLI::EXPORT_PCB_STEP_COMMAND exportPcbStepCmd{}; static CLI::EXPORT_PCB_STEP_COMMAND exportPcbStepCmd{};
static CLI::EXPORT_PCB_SVG_COMMAND exportPcbSvgCmd{}; static CLI::EXPORT_PCB_SVG_COMMAND exportPcbSvgCmd{};
static CLI::EXPORT_PCB_PDF_COMMAND exportPcbPdfCmd{}; static CLI::EXPORT_PCB_PDF_COMMAND exportPcbPdfCmd{};
static CLI::EXPORT_PCB_POS_COMMAND exportPcbPosCmd{}; static CLI::EXPORT_PCB_POS_COMMAND exportPcbPosCmd{};
static CLI::EXPORT_PCB_GERBER_COMMAND exportPcbGerberCmd{}; static CLI::EXPORT_PCB_GERBER_COMMAND exportPcbGerberCmd{};
static CLI::EXPORT_PCB_COMMAND exportPcbCmd{}; 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_PYTHONBOM_COMMAND exportSchPythonBomCmd{};
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{};
static CLI::FP_COMMAND fpCmd{}; static CLI::FP_COMMAND fpCmd{};
static CLI::FP_UPGRADE_COMMAND fpUpgradeCmd{}; static CLI::FP_UPGRADE_COMMAND fpUpgradeCmd{};
static CLI::SYM_COMMAND symCmd{}; static CLI::SYM_COMMAND symCmd{};
static CLI::SYM_UPGRADE_COMMAND symUpgradeCmd{}; static CLI::SYM_UPGRADE_COMMAND symUpgradeCmd{};
static std::vector<COMMAND_ENTRY> commandStack = { static std::vector<COMMAND_ENTRY> commandStack = {
{ {
@ -163,9 +163,9 @@ static std::vector<COMMAND_ENTRY> commandStack = {
{ {
{ &exportSchCmd, { &exportSchCmd,
{ {
&exportSchBomCmd,
&exportSchNetlistCmd, &exportSchNetlistCmd,
&exportSchPdfCmd, &exportSchPdfCmd,
&exportSchPythonBomCmd,
&exportSchSvgCmd &exportSchSvgCmd
} }
} }