Some cleanup of the cli functions

This commit is contained in:
Marek Roszko 2022-10-25 23:03:21 -04:00
parent a01de6bf53
commit a7e1f668a7
15 changed files with 403 additions and 94 deletions

View File

@ -287,11 +287,12 @@ set( COMMON_SRCS
${PLUGINS_CADSTAR_SRCS}
${PLUGINS_EAGLE_SRCS}
${FONT_SRCS}
cli/command_export_pcb_base.cpp
cli/command_export_pcb_dxf.cpp
cli/command_export_pcb_step.cpp
cli/command_export_pcb_svg.cpp
cli/command_pcb.cpp
cli/command_pcb_export.cpp
cli/command_export_step.cpp
jobs/job_export_step.cpp
jobs/job_dispatcher.cpp
advanced_config.cpp
array_axis.cpp

View File

@ -27,8 +27,9 @@
namespace CLI
{
struct COMMAND
class COMMAND
{
public:
COMMAND( std::string aName ) : m_name( aName ), m_argParser( aName ){};
virtual int Perform( KIWAY& aKiway ) const = 0;

View File

@ -0,0 +1,76 @@
/*
* 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) 2016 Cirilo Bernardo <cirilo.bernardo@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_pcb_base.h"
#include "exit_codes.h"
#include <kiface_base.h>
#include <macros.h>
#include <wx/tokenzr.h>
CLI::EXPORT_PCB_BASE_COMMAND::EXPORT_PCB_BASE_COMMAND( std::string aName ) : COMMAND( aName )
{
m_argParser.add_argument( "-o", ARG_OUTPUT )
.default_value( std::string() )
.help( "output file name" );
m_argParser.add_argument( ARG_INPUT ).help( "input file" );
for( int layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
{
std::string untranslated = TO_UTF8( wxString( LSET::Name( PCB_LAYER_ID( layer ) ) ) );
//m_layerIndices[untranslated] = PCB_LAYER_ID( layer );
m_layerMasks[untranslated] = LSET( PCB_LAYER_ID( layer ) );
}
m_layerMasks["*.Cu"] = LSET::AllCuMask();
m_layerMasks["*In.Cu"] = LSET::InternalCuMask();
m_layerMasks["F&B.Cu"] = LSET( 2, F_Cu, B_Cu );
m_layerMasks["*.Adhes"] = LSET( 2, B_Adhes, F_Adhes );
m_layerMasks["*.Paste"] = LSET( 2, B_Paste, F_Paste );
m_layerMasks["*.Mask"] = LSET( 2, B_Mask, F_Mask );
m_layerMasks["*.SilkS"] = LSET( 2, B_SilkS, F_SilkS );
m_layerMasks["*.Fab"] = LSET( 2, B_Fab, F_Fab );
m_layerMasks["*.CrtYd"] = LSET( 2, B_CrtYd, F_CrtYd );
}
LSET CLI::EXPORT_PCB_BASE_COMMAND::convertLayerStringList( wxString& aLayerString ) const
{
LSET layerMask = LSET::AllCuMask();
if( !aLayerString.IsEmpty() )
{
layerMask.reset();
wxStringTokenizer layerTokens( aLayerString, "," );
while( layerTokens.HasMoreTokens() )
{
std::string token = TO_UTF8( layerTokens.GetNextToken() );
if( m_layerMasks.count( token ) )
{
layerMask |= m_layerMasks.at(token);
}
}
}
return layerMask;
}

View File

@ -0,0 +1,43 @@
/*
* 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_PCB_BASE_H
#define COMMAND_EXPORT_PCB_BASE_H
#include "command.h"
#include <layer_ids.h>
namespace CLI
{
#define ARG_OUTPUT "--output"
#define ARG_INPUT "input"
struct EXPORT_PCB_BASE_COMMAND : public COMMAND
{
EXPORT_PCB_BASE_COMMAND( std::string aName );
protected:
LSET convertLayerStringList( wxString& aLayerString ) const;
std::map<std::string, LSET> m_layerMasks;
};
} // namespace CLI
#endif

View File

@ -0,0 +1,101 @@
/*
* 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) 2016 Cirilo Bernardo <cirilo.bernardo@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_pcb_dxf.h"
#include "exit_codes.h"
#include "jobs/job_export_pcb_dxf.h"
#include <kiface_base.h>
#include <layer_ids.h>
#include <wx/crt.h>
#include <macros.h>
#include <wx/tokenzr.h>
#define ARG_LAYERS "--layers"
#define ARG_INCLUDE_REFDES "--include-refdes"
#define ARG_INCLUDE_VALUE "--include-value"
#define ARG_USE_CONTOURS "--use-contours"
#define ARG_OUTPUT_UNITS "--output-units"
CLI::EXPORT_PCB_DXF_COMMAND::EXPORT_PCB_DXF_COMMAND() : EXPORT_PCB_BASE_COMMAND( "dxf" )
{
m_argParser.add_argument( "-l", ARG_LAYERS )
.default_value( std::string() )
.help( "comma separated list of untranslated layer names to include such as F.Cu,B.Cu" );
m_argParser.add_argument( "-ird", ARG_INCLUDE_REFDES )
.help( "Mirror the board (useful for trying to show bottom layers)" )
.implicit_value( true )
.default_value( true );
m_argParser.add_argument( "-iv", ARG_INCLUDE_VALUE )
.help( "Mirror the board (useful for trying to show bottom layers)" )
.implicit_value( true )
.default_value( true );
m_argParser.add_argument( "-uc", ARG_USE_CONTOURS )
.help( "Plot graphic items using their contours" )
.implicit_value( true )
.default_value( true );
m_argParser.add_argument( "-ou", ARG_OUTPUT_UNITS )
.default_value( std::string( "in" ) )
.help( "output file name" );
}
int CLI::EXPORT_PCB_DXF_COMMAND::Perform( KIWAY& aKiway ) const
{
JOB_EXPORT_PCB_DXF* dxfJob = new JOB_EXPORT_PCB_DXF( true );
dxfJob->m_filename = FROM_UTF8( m_argParser.get<std::string>( ARG_INPUT ).c_str() );
dxfJob->m_outputFile = FROM_UTF8( m_argParser.get<std::string>( ARG_OUTPUT ).c_str() );
dxfJob->m_plotFootprintValues = m_argParser.get<bool>( ARG_INCLUDE_VALUE );
dxfJob->m_plotRefDes = m_argParser.get<bool>( ARG_INCLUDE_VALUE );
dxfJob->m_plotGraphicItemsUsingContours = m_argParser.get<bool>( ARG_USE_CONTOURS );
wxString units = FROM_UTF8( m_argParser.get<std::string>( ARG_OUTPUT_UNITS ).c_str() );
if( units == wxS( "mm" ) )
{
dxfJob->m_dxfUnits = JOB_EXPORT_PCB_DXF::DXF_UNITS::MILLIMETERS;
}
else if( units == wxS( "in" ) )
{
dxfJob->m_dxfUnits = JOB_EXPORT_PCB_DXF::DXF_UNITS::INCHES;
}
else
{
wxFprintf( stderr, _( "Invalid units specified\n" ) );
return EXIT_CODES::ERR_ARGS;
}
wxString layers = FROM_UTF8( m_argParser.get<std::string>( ARG_LAYERS ).c_str() );
LSET layerMask = convertLayerStringList( layers );
dxfJob->m_printMaskLayer = layerMask;
int exitCode = aKiway.ProcessJob( KIWAY::FACE_PCB, dxfJob );
return exitCode;
}

View File

@ -18,17 +18,20 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "jobs/job_export_step.h"
#ifndef COMMAND_EXPORT_PCB_DXF_H
#define COMMAND_EXPORT_PCB_DXF_H
JOB_EXPORT_STEP::JOB_EXPORT_STEP( bool aIsCli ) : JOB( "step", aIsCli )
#include "command_export_pcb_base.h"
namespace CLI
{
m_overwrite = false;
m_useGridOrigin = false;
m_useDrillOrigin = false;
m_includeVirtual = true;
m_substModels = false;
m_xOrigin = 0.0;
m_yOrigin = 0.0;
m_minDistance = 0.01; // 0.01 mm is a good value to connect 2 items of the board outlines
m_gui = false;
}
class EXPORT_PCB_DXF_COMMAND : public EXPORT_PCB_BASE_COMMAND
{
public:
EXPORT_PCB_DXF_COMMAND();
int Perform( KIWAY& aKiway ) const override;
};
} // namespace CLI
#endif

View File

@ -19,9 +19,9 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "command_export_step.h"
#include "command_export_pcb_step.h"
#include "exit_codes.h"
#include "jobs/job_export_step.h"
#include "jobs/job_export_pcb_step.h"
#include <kiface_base.h>
#include <regex>
@ -36,13 +36,12 @@
#define ARG_INPUT "input"
#define ARG_MIN_DISTANCE "--min-distance"
#define ARG_USER_ORIGIN "--user-origin"
#define ARG_GUI "--gui"
#define REGEX_QUANTITY "([\\s]*[+-]?[\\d]*[.]?[\\d]*)"
#define REGEX_DELIMITER "(?:[\\s]*x)"
#define REGEX_UNIT "([m]{2}|(?:in))"
CLI::EXPORT_STEP_COMMAND::EXPORT_STEP_COMMAND() : COMMAND( "step" )
CLI::EXPORT_PCB_STEP_COMMAND::EXPORT_PCB_STEP_COMMAND() : COMMAND( "step" )
{
m_argParser.add_argument( ARG_DRILL_ORIGIN )
.help( "Use Drill Origin for output origin" )
@ -69,11 +68,6 @@ CLI::EXPORT_STEP_COMMAND::EXPORT_STEP_COMMAND() : COMMAND( "step" )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( ARG_GUI )
.help( "Show GUI (log window)" )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( ARG_MIN_DISTANCE )
.default_value( std::string() )
.help( "Minimum distance between points to treat them as separate ones (default 0.01mm)" );
@ -89,9 +83,9 @@ CLI::EXPORT_STEP_COMMAND::EXPORT_STEP_COMMAND() : COMMAND( "step" )
m_argParser.add_argument( ARG_INPUT ).help( "input file" );
}
int CLI::EXPORT_STEP_COMMAND::Perform( KIWAY& aKiway ) const
int CLI::EXPORT_PCB_STEP_COMMAND::Perform( KIWAY& aKiway ) const
{
std::unique_ptr<JOB_EXPORT_STEP> step( new JOB_EXPORT_STEP( true ) );
std::unique_ptr<JOB_EXPORT_PCB_STEP> step( new JOB_EXPORT_PCB_STEP( true ) );
step->m_useDrillOrigin = m_argParser.get<bool>( ARG_DRILL_ORIGIN );
step->m_useGridOrigin = m_argParser.get<bool>( ARG_GRID_ORIGIN );
@ -100,7 +94,6 @@ int CLI::EXPORT_STEP_COMMAND::Perform( KIWAY& aKiway ) const
step->m_overwrite = m_argParser.get<bool>( ARG_FORCE );
step->m_filename = FROM_UTF8( m_argParser.get<std::string>( ARG_INPUT ).c_str() );
step->m_outputFile = FROM_UTF8( m_argParser.get<std::string>( ARG_OUTPUT ).c_str() );
step->m_gui = m_argParser.get<bool>( ARG_GUI );
wxString userOrigin = FROM_UTF8( m_argParser.get<std::string>( ARG_USER_ORIGIN ).c_str() );
if( !userOrigin.IsEmpty() )

View File

@ -18,16 +18,16 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef COMMAND_EXPORT_STEP_H
#define COMMAND_EXPORT_STEP_H
#ifndef COMMAND_EXPORT_PCB_STEP_H
#define COMMAND_EXPORT_PCB_STEP_H
#include "command.h"
namespace CLI
{
struct EXPORT_STEP_COMMAND : public COMMAND
struct EXPORT_PCB_STEP_COMMAND : public COMMAND
{
EXPORT_STEP_COMMAND();
EXPORT_PCB_STEP_COMMAND();
int Perform( KIWAY& aKiway ) const override;
};

View File

@ -33,18 +33,12 @@
#define ARG_PAGE_SIZE "--page-size-mode"
#define ARG_MIRROR "--mirror"
#define ARG_BLACKANDWHITE "--black-and-white"
#define ARG_OUTPUT "--output"
#define ARG_THEME "--theme"
#define ARG_LAYERS "--layers"
#define ARG_INPUT "input"
CLI::EXPORT_PCB_SVG_COMMAND::EXPORT_PCB_SVG_COMMAND() : COMMAND( "svg" )
CLI::EXPORT_PCB_SVG_COMMAND::EXPORT_PCB_SVG_COMMAND() : EXPORT_PCB_BASE_COMMAND( "svg" )
{
m_argParser.add_argument( "-o", ARG_OUTPUT )
.default_value( std::string() )
.help( "output file name" );
m_argParser.add_argument( "-l", ARG_LAYERS )
.default_value( std::string() )
.help( "comma separated list of untranslated layer names to include such as F.Cu,B.Cu" );
@ -66,33 +60,11 @@ CLI::EXPORT_PCB_SVG_COMMAND::EXPORT_PCB_SVG_COMMAND() : COMMAND( "svg" )
m_argParser.add_argument( ARG_PAGE_SIZE )
.help( "Set page sizing mode (0 = page with frame and title block, 1 = current page size, 2 = board area only)" )
.default_value( 0 );
m_argParser.add_argument( ARG_INPUT ).help( "input file" );
}
int CLI::EXPORT_PCB_SVG_COMMAND::Perform( KIWAY& aKiway ) const
{
std::map<std::string, LSET> layerMasks;
for( int layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
{
std::string untranslated = TO_UTF8( wxString( LSET::Name( PCB_LAYER_ID( layer ) ) ) );
//m_layerIndices[untranslated] = PCB_LAYER_ID( layer );
layerMasks[untranslated] = LSET( PCB_LAYER_ID( layer ) );
}
layerMasks["*"] = LSET::AllLayersMask();
layerMasks["*.Cu"] = LSET::AllCuMask();
layerMasks["*In.Cu"] = LSET::InternalCuMask();
layerMasks["F&B.Cu"] = LSET( 2, F_Cu, B_Cu );
layerMasks["*.Adhes"] = LSET( 2, B_Adhes, F_Adhes );
layerMasks["*.Paste"] = LSET( 2, B_Paste, F_Paste );
layerMasks["*.Mask"] = LSET( 2, B_Mask, F_Mask );
layerMasks["*.SilkS"] = LSET( 2, B_SilkS, F_SilkS );
layerMasks["*.Fab"] = LSET( 2, B_Fab, F_Fab );
layerMasks["*.CrtYd"] = LSET( 2, B_CrtYd, F_CrtYd );
JOB_EXPORT_PCB_SVG* svgJob = new JOB_EXPORT_PCB_SVG( true );
svgJob->m_mirror = m_argParser.get<bool>( ARG_MIRROR );
@ -111,25 +83,7 @@ int CLI::EXPORT_PCB_SVG_COMMAND::Perform( KIWAY& aKiway ) const
wxString layers = FROM_UTF8( m_argParser.get<std::string>( ARG_LAYERS ).c_str() );
LSET layerMask = LSET::AllCuMask();
if( !layers.IsEmpty() )
{
layerMask.reset();
wxStringTokenizer layerTokens( layers, "," );
while( layerTokens.HasMoreTokens() )
{
std::string token = TO_UTF8(layerTokens.GetNextToken());
if( layerMasks.count( token ) )
{
layerMask |= layerMasks[token];
}
else
{
wxFprintf( stderr, _( "Invalid layer option: %s\n" ), token );
}
}
}
LSET layerMask = convertLayerStringList( layers );
svgJob->m_printMaskLayer = layerMask;

View File

@ -21,11 +21,11 @@
#ifndef COMMAND_EXPORT_PCB_SVG_H
#define COMMAND_EXPORT_PCB_SVG_H
#include "command.h"
#include "command_export_pcb_base.h"
namespace CLI
{
struct EXPORT_PCB_SVG_COMMAND : public COMMAND
struct EXPORT_PCB_SVG_COMMAND : public EXPORT_PCB_BASE_COMMAND
{
EXPORT_PCB_SVG_COMMAND();

View File

@ -0,0 +1,61 @@
/*
* 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_PCB_DXF_H
#define JOB_EXPORT_PCB_DXF_H
#include <layer_ids.h>
#include <wx/string.h>
#include "job.h"
class JOB_EXPORT_PCB_DXF : public JOB
{
public:
JOB_EXPORT_PCB_DXF( bool aIsCli ) :
JOB( "dxf", aIsCli ),
m_filename(),
m_outputFile(),
m_plotFootprintValues( true ),
m_plotRefDes( true ),
m_plotGraphicItemsUsingContours( true ),
m_printMaskLayer()
{
}
enum class DXF_UNITS
{
INCHES,
MILLIMETERS
};
wxString m_filename;
wxString m_outputFile;
bool m_plotFootprintValues;
bool m_plotRefDes;
bool m_plotGraphicItemsUsingContours;
DXF_UNITS m_dxfUnits;
int m_pageSizeMode;
LSET m_printMaskLayer;
};
#endif

View File

@ -24,10 +24,23 @@
#include <wx/string.h>
#include "job.h"
class JOB_EXPORT_STEP : public JOB
class JOB_EXPORT_PCB_STEP : public JOB
{
public:
JOB_EXPORT_STEP( bool aIsCli );
JOB_EXPORT_PCB_STEP::JOB_EXPORT_PCB_STEP( bool aIsCli ) :
JOB( "step", aIsCli ),
m_overwrite( false ),
m_useGridOrigin( false ),
m_useDrillOrigin( false ),
m_includeVirtual( false ),
m_substModels( false ),
m_filename(),
m_outputFile(),
m_xOrigin( 0.0 ),
m_yOrigin( 0.0 ),
m_minDistance( 0.01 ) // 0.01 mm is a good value to connect 2 items of the board outlines
{
}
bool m_overwrite;
bool m_useGridOrigin;
@ -39,7 +52,6 @@ public:
double m_xOrigin;
double m_yOrigin;
double m_minDistance;
bool m_gui;
};
#endif

View File

@ -48,8 +48,9 @@
#include "cli/command_pcb.h"
#include "cli/command_pcb_export.h"
#include "cli/command_export_pcb_dxf.h"
#include "cli/command_export_pcb_svg.h"
#include "cli/command_export_step.h"
#include "cli/command_export_pcb_step.h"
#include "cli/exit_codes.h"
// a dummy to quiet linking with EDA_BASE_FRAME::config();
@ -97,10 +98,11 @@ struct COMMAND_ENTRY
handler( aHandler ), subCommands( aSub ){};
};
static CLI::EXPORT_STEP_COMMAND stepCmd{};
static CLI::EXPORT_PCB_SVG_COMMAND svgCmd{};
static CLI::EXPORT_PCB_COMMAND exportPcbCmd{};
static CLI::PCB_COMMAND pcbCmd{};
static CLI::EXPORT_PCB_STEP_COMMAND stepCmd{};
static CLI::EXPORT_PCB_DXF_COMMAND dxfCmd{};
static CLI::EXPORT_PCB_SVG_COMMAND svgCmd{};
static CLI::EXPORT_PCB_COMMAND exportPcbCmd{};
static CLI::PCB_COMMAND pcbCmd{};
static std::vector<COMMAND_ENTRY> commandStack = {
{
@ -109,7 +111,8 @@ static std::vector<COMMAND_ENTRY> commandStack = {
{ &exportPcbCmd,
{
&stepCmd,
&svgCmd
&svgCmd,
&dxfCmd
}
}
}

View File

@ -20,10 +20,12 @@
#include "pcbnew_jobs_handler.h"
#include <kicad2step.h>
#include <jobs/job_export_pcb_dxf.h>
#include <jobs/job_export_pcb_svg.h>
#include <jobs/job_export_step.h>
#include <jobs/job_export_pcb_step.h>
#include <cli/exit_codes.h>
#include <plotters/plotters_pslike.h>
#include <plotters/plotter_dxf.h>
#include <pgm_base.h>
#include <pcbplot.h>
#include <board_design_settings.h>
@ -37,14 +39,14 @@ PCBNEW_JOBS_HANDLER::PCBNEW_JOBS_HANDLER()
{
Register( "step",
std::bind( &PCBNEW_JOBS_HANDLER::JobExportStep, this, std::placeholders::_1 ) );
Register( "svg",
std::bind( &PCBNEW_JOBS_HANDLER::JobExportSvg, this, std::placeholders::_1 ) );
Register( "svg", std::bind( &PCBNEW_JOBS_HANDLER::JobExportSvg, this, std::placeholders::_1 ) );
Register( "dxf", std::bind( &PCBNEW_JOBS_HANDLER::JobExportDxf, this, std::placeholders::_1 ) );
}
int PCBNEW_JOBS_HANDLER::JobExportStep( JOB* aJob )
{
JOB_EXPORT_STEP* aStepJob = dynamic_cast<JOB_EXPORT_STEP*>( aJob );
JOB_EXPORT_PCB_STEP* aStepJob = dynamic_cast<JOB_EXPORT_PCB_STEP*>( aJob );
if( aStepJob == nullptr )
return CLI::EXIT_CODES::ERR_UNKNOWN;
@ -97,5 +99,63 @@ int PCBNEW_JOBS_HANDLER::JobExportSvg( JOB* aJob )
wxPrintf( _( "Error creating svg file" ) );
}
return CLI::EXIT_CODES::OK;
}
int PCBNEW_JOBS_HANDLER::JobExportDxf( JOB* aJob )
{
JOB_EXPORT_PCB_DXF* aDxfJob = dynamic_cast<JOB_EXPORT_PCB_DXF*>( aJob );
if( aDxfJob == nullptr )
return CLI::EXIT_CODES::ERR_UNKNOWN;
if( aJob->IsCli() )
wxPrintf( _( "Loading board\n" ) );
BOARD* brd = LoadBoard( aDxfJob->m_filename );
if( aDxfJob->m_outputFile.IsEmpty() )
{
wxFileName fn = brd->GetFileName();
fn.SetName( fn.GetName() );
fn.SetExt( wxS( "dxf" ) );
aDxfJob->m_outputFile = fn.GetFullName();
}
PCB_PLOT_PARAMS plotOpts;
plotOpts.SetFormat( PLOT_FORMAT::DXF );
plotOpts.SetDXFPlotPolygonMode( aDxfJob->m_plotGraphicItemsUsingContours );
if( aDxfJob->m_dxfUnits == JOB_EXPORT_PCB_DXF::DXF_UNITS::MILLIMETERS )
{
plotOpts.SetDXFPlotUnits( DXF_UNITS::MILLIMETERS );
}
else
{
plotOpts.SetDXFPlotUnits( DXF_UNITS::INCHES );
}
plotOpts.SetPlotValue( aDxfJob->m_plotFootprintValues );
plotOpts.SetPlotReference( aDxfJob->m_plotRefDes );
plotOpts.SetLayerSelection( aDxfJob->m_printMaskLayer );
//@todo allow controlling the sheet name and path that will be displayed in the title block
// Leave blank for now
DXF_PLOTTER* plotter = (DXF_PLOTTER*) StartPlotBoard(
brd, &plotOpts, UNDEFINED_LAYER, aDxfJob->m_outputFile, wxEmptyString, wxEmptyString );
if( plotter )
{
PlotBoardLayers( brd, plotter, aDxfJob->m_printMaskLayer.SeqStackupBottom2Top(), plotOpts );
plotter->EndPlot();
}
delete plotter;
return CLI::EXIT_CODES::OK;
}

View File

@ -29,6 +29,7 @@ public:
PCBNEW_JOBS_HANDLER();
int JobExportStep( JOB* aJob );
int JobExportSvg( JOB* aJob );
int JobExportDxf( JOB* aJob );
};
#endif