Add --drawing-sheet arg for various cli commands for overriding the project sheet

Fixes https://gitlab.com/kicad/code/kicad/-/issues/15438
This commit is contained in:
Marek Roszko 2023-08-31 19:37:12 -04:00
parent f869e3fb87
commit b542539546
17 changed files with 129 additions and 9 deletions

View File

@ -32,6 +32,7 @@ public:
JOB( "dxf", aIsCli ),
m_filename(),
m_outputFile(),
m_drawingSheet(),
m_plotFootprintValues( true ),
m_plotRefDes( true ),
m_plotGraphicItemsUsingContours( true ),
@ -49,6 +50,7 @@ public:
wxString m_filename;
wxString m_outputFile;
wxString m_drawingSheet;
bool m_plotFootprintValues;
bool m_plotRefDes;

View File

@ -32,6 +32,7 @@ public:
JOB( aType, aIsCli ),
m_filename(),
m_outputFile(),
m_drawingSheet(),
m_plotFootprintValues( true ),
m_plotRefDes( true ),
m_plotBorderTitleBlocks( false ),
@ -53,6 +54,7 @@ public:
wxString m_filename;
wxString m_outputFile;
wxString m_drawingSheet;
bool m_plotFootprintValues;
bool m_plotRefDes;

View File

@ -33,6 +33,7 @@ public:
m_filename(),
m_outputFile(),
m_colorTheme(),
m_drawingSheet(),
m_mirror( false ),
m_blackAndWhite( false ),
m_negative( false ),
@ -47,6 +48,7 @@ public:
wxString m_filename;
wxString m_outputFile;
wxString m_colorTheme;
wxString m_drawingSheet;
bool m_mirror;
bool m_blackAndWhite;

View File

@ -33,6 +33,7 @@ public:
m_filename(),
m_outputFile(),
m_colorTheme(),
m_drawingSheet(),
m_mirror( false ),
m_blackAndWhite( false ),
m_negative( false ),
@ -46,6 +47,7 @@ public:
wxString m_filename;
wxString m_outputFile;
wxString m_colorTheme;
wxString m_drawingSheet;
bool m_mirror;
bool m_blackAndWhite;

View File

@ -29,13 +29,18 @@ class JOB_EXPORT_SCH_PLOT : public JOB
{
public:
JOB_EXPORT_SCH_PLOT( bool aIsCli, PLOT_FORMAT aPlotFormat, wxString aFilename ) :
JOB( "plot", aIsCli ), m_plotFormat( aPlotFormat ), m_filename( aFilename )
JOB( "plot", aIsCli ),
m_plotFormat( aPlotFormat ),
m_filename( aFilename ),
settings(),
m_drawingSheet()
{
}
PLOT_FORMAT m_plotFormat;
wxString m_filename;
SCH_PLOT_SETTINGS settings;
wxString m_drawingSheet;
};
#endif

View File

@ -83,7 +83,8 @@ EESCHEMA_JOBS_HANDLER::EESCHEMA_JOBS_HANDLER()
void EESCHEMA_JOBS_HANDLER::InitRenderSettings( KIGFX::SCH_RENDER_SETTINGS* aRenderSettings,
const wxString& aTheme, SCHEMATIC* aSch )
const wxString& aTheme, SCHEMATIC* aSch,
const wxString& aDrawingSheetOverride )
{
COLOR_SETTINGS* cs = Pgm().GetSettingsManager().GetColorSettings( aTheme );
aRenderSettings->LoadColors( cs );
@ -98,11 +99,30 @@ void EESCHEMA_JOBS_HANDLER::InitRenderSettings( KIGFX::SCH_RENDER_SETTINGS* aRen
// Load the drawing sheet from the filename stored in BASE_SCREEN::m_DrawingSheetFileName.
// If empty, or not existing, the default drawing sheet is loaded.
wxString filename = DS_DATA_MODEL::ResolvePath( aSch->Settings().m_SchDrawingSheetFileName,
aSch->Prj().GetProjectPath() );
if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename ) )
m_reporter->Report( _( "Error loading drawing sheet." ), RPT_SEVERITY_ERROR );
auto loadSheet = [&]( const wxString& path ) -> bool
{
wxString resolvedSheetPath =
DS_DATA_MODEL::ResolvePath( path, aSch->Prj().GetProjectPath() );
if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( resolvedSheetPath ) )
{
m_reporter->Report( wxString::Format( _( "Error loading drawing sheet '%s'." ), path ),
RPT_SEVERITY_ERROR );
return false;
}
return true;
};
// try to load the override first
if( !aDrawingSheetOverride.IsEmpty() && loadSheet( aDrawingSheetOverride ) )
{
return;
}
// no override or failed override continues here
loadSheet( aSch->Settings().m_SchDrawingSheetFileName );
}
@ -123,7 +143,7 @@ int EESCHEMA_JOBS_HANDLER::JobExportPlot( JOB* aJob )
std::unique_ptr<KIGFX::SCH_RENDER_SETTINGS> renderSettings =
std::make_unique<KIGFX::SCH_RENDER_SETTINGS>();
InitRenderSettings( renderSettings.get(), aPlotJob->settings.m_theme, sch );
InitRenderSettings( renderSettings.get(), aPlotJob->settings.m_theme, sch, aPlotJob->m_drawingSheet );
std::unique_ptr<SCH_PLOTTER> schPlotter = std::make_unique<SCH_PLOTTER>( sch );
schPlotter->Plot( aPlotJob->m_plotFormat, aPlotJob->settings, renderSettings.get(), m_reporter );

View File

@ -59,7 +59,7 @@ public:
* @param aSch The schematic to further copy settings from to be put into aRenderSettings
*/
void InitRenderSettings( KIGFX::SCH_RENDER_SETTINGS* aRenderSettings, const wxString& aTheme,
SCHEMATIC* aSch );
SCHEMATIC* aSch, const wxString& aDrawingSheetOverride = wxEmptyString );
private:
int doSymExportSvg( JOB_SYM_EXPORT_SVG* aSvgJob, KIGFX::SCH_RENDER_SETTINGS* aRenderSettings,

View File

@ -65,6 +65,11 @@ int CLI::COMMAND::Perform( KIWAY& aKiway )
m_argOutput = FROM_UTF8( m_argParser.get<std::string>( ARG_OUTPUT ).c_str() );
}
if( m_hasDrawingSheetArg )
{
m_argDrawingSheet = FROM_UTF8( m_argParser.get<std::string>( ARG_DRAWING_SHEET ).c_str() );
}
return doPerform( aKiway );
}
@ -105,3 +110,13 @@ void CLI::COMMAND::addCommonArgs( bool aInput, bool aOutput, bool aOutputIsDir )
}
}
}
void CLI::COMMAND::addDrawingSheetArg()
{
m_hasDrawingSheetArg = true;
m_argParser.add_argument( ARG_DRAWING_SHEET )
.default_value( std::string() )
.help( UTF8STDSTR( _( "Path to drawing sheet, this overrides any existing project defined sheet when used" ) ) );
}

View File

@ -32,6 +32,7 @@
#define ARG_HELP_DESC _( "shows help message and exits" )
#define ARG_OUTPUT "--output"
#define ARG_INPUT "input"
#define ARG_DRAWING_SHEET "--drawing-sheet"
namespace CLI
{
@ -68,6 +69,11 @@ protected:
*/
void addCommonArgs( bool aInput, bool aOutput, bool aOutputIsDir );
/**
* Sets up the drawing sheet arg used by many of the export commands
*/
void addDrawingSheetArg();
/**
* The internal handler that should be overloaded to implement command specific
* processing and work.
@ -93,6 +99,11 @@ protected:
*/
bool m_hasOutputArg;
/**
* Whether or not the input arg was added for parsing
*/
bool m_hasDrawingSheetArg;
/**
* Whether or not the output arg is expecting a directory
*/
@ -107,6 +118,11 @@ protected:
* Value of the output arg if configured
*/
wxString m_argOutput;
/**
* Value of the drawing sheet arg if configured
*/
wxString m_argDrawingSheet;
};
}

View File

@ -36,6 +36,7 @@
CLI::PCB_EXPORT_DXF_COMMAND::PCB_EXPORT_DXF_COMMAND() : PCB_EXPORT_BASE_COMMAND( "dxf" )
{
addLayerArg( true );
addDrawingSheetArg();
m_argParser.add_argument( "--erd", ARG_EXCLUDE_REFDES )
.help( UTF8STDSTR( _( "Exclude the reference designator text" ) ) )
@ -52,6 +53,11 @@ CLI::PCB_EXPORT_DXF_COMMAND::PCB_EXPORT_DXF_COMMAND() : PCB_EXPORT_BASE_COMMAND(
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( "--ibt", ARG_INCLUDE_BORDER_TITLE )
.help( UTF8STDSTR( _( "Include the border and title block" ) ) )
.implicit_value( true )
.default_value( false );
m_argParser.add_argument( "--ou", ARG_OUTPUT_UNITS )
.default_value( std::string( "in" ) )
.help( UTF8STDSTR( _( "Output units, valid options: mm, in" ) ) );
@ -68,6 +74,7 @@ int CLI::PCB_EXPORT_DXF_COMMAND::doPerform( KIWAY& aKiway )
dxfJob->m_filename = m_argInput;
dxfJob->m_outputFile = m_argOutput;
dxfJob->m_drawingSheet = m_argDrawingSheet;
if( !wxFile::Exists( dxfJob->m_filename ) )
{
@ -78,6 +85,7 @@ int CLI::PCB_EXPORT_DXF_COMMAND::doPerform( KIWAY& aKiway )
dxfJob->m_plotFootprintValues = m_argParser.get<bool>( ARG_EXCLUDE_VALUE );
dxfJob->m_plotRefDes = !m_argParser.get<bool>( ARG_EXCLUDE_REFDES );
dxfJob->m_plotGraphicItemsUsingContours = m_argParser.get<bool>( ARG_USE_CONTOURS );
dxfJob->m_plotBorderTitleBlocks = m_argParser.get<bool>( ARG_INCLUDE_BORDER_TITLE );
wxString units = FROM_UTF8( m_argParser.get<std::string>( ARG_OUTPUT_UNITS ).c_str() );

View File

@ -35,6 +35,7 @@ CLI::PCB_EXPORT_GERBER_COMMAND::PCB_EXPORT_GERBER_COMMAND( const std::string& aN
PCB_EXPORT_BASE_COMMAND( aName )
{
addLayerArg( true );
addDrawingSheetArg();
m_argParser.add_description( UTF8STDSTR( _( "Plot given layers to a single gerber file" ) ) );
@ -99,6 +100,7 @@ int CLI::PCB_EXPORT_GERBER_COMMAND::populateJob( JOB_EXPORT_PCB_GERBER* aJob )
{
aJob->m_filename = m_argInput;
aJob->m_outputFile = m_argOutput;
aJob->m_drawingSheet = m_argDrawingSheet;
aJob->m_plotFootprintValues = !m_argParser.get<bool>( ARG_EXCLUDE_VALUE );
aJob->m_plotRefDes = !m_argParser.get<bool>( ARG_EXCLUDE_REFDES );

View File

@ -38,6 +38,7 @@ CLI::PCB_EXPORT_GERBERS_COMMAND::PCB_EXPORT_GERBERS_COMMAND() :
PCB_EXPORT_GERBER_COMMAND( "gerbers" )
{
m_requireLayers = false;
addDrawingSheetArg();
m_argParser.add_description( UTF8STDSTR( _( "Plot multiple gerbers for a PCB, including the "
"ability to use stored board plot settings" ) ) );

View File

@ -36,6 +36,7 @@
CLI::PCB_EXPORT_PDF_COMMAND::PCB_EXPORT_PDF_COMMAND() : PCB_EXPORT_BASE_COMMAND( "pdf" )
{
addLayerArg( true );
addDrawingSheetArg();
m_argParser.add_argument( "-m", ARG_MIRROR )
.help( UTF8STDSTR( _( "Mirror the board (useful for trying to show bottom layers)" ) ) )
@ -90,6 +91,7 @@ int CLI::PCB_EXPORT_PDF_COMMAND::doPerform( KIWAY& aKiway )
pdfJob->m_filename = m_argInput;
pdfJob->m_outputFile = m_argOutput;
pdfJob->m_drawingSheet = m_argDrawingSheet;
if( !wxFile::Exists( pdfJob->m_filename ) )
{

View File

@ -39,6 +39,7 @@
CLI::PCB_EXPORT_SVG_COMMAND::PCB_EXPORT_SVG_COMMAND() : PCB_EXPORT_BASE_COMMAND( "svg" )
{
addLayerArg( true );
addDrawingSheetArg();
m_argParser.add_argument( "-m", ARG_MIRROR )
.help( UTF8STDSTR( _( "Mirror the board (useful for trying to show bottom layers)" ) ) )
@ -91,6 +92,7 @@ int CLI::PCB_EXPORT_SVG_COMMAND::doPerform( KIWAY& aKiway )
svgJob->m_pageSizeMode = m_argParser.get<int>( ARG_PAGE_SIZE );
svgJob->m_negative = m_argParser.get<bool>( ARG_NEGATIVE );
svgJob->m_drillShapeOption = m_argParser.get<int>( ARG_DRILL_SHAPE_OPTION );
svgJob->m_drawingSheet = m_argDrawingSheet;
svgJob->m_filename = m_argInput;
svgJob->m_outputFile = m_argOutput;

View File

@ -47,6 +47,7 @@ CLI::SCH_EXPORT_PLOT_COMMAND::SCH_EXPORT_PLOT_COMMAND( const std::string& aName,
m_plotFormat( aPlotFormat )
{
addCommonArgs( true, true, aOutputIsDir );
addDrawingSheetArg();
m_argParser.add_argument( "-t", ARG_THEME )
.default_value( std::string() )
@ -111,6 +112,9 @@ int CLI::SCH_EXPORT_PLOT_COMMAND::doPerform( KIWAY& aKiway )
settings.m_outputDirectory = m_argOutput;
else
settings.m_outputFile = m_argOutput;
plotJob->m_drawingSheet = m_argDrawingSheet;
// HPGL local options
if( m_plotFormat == PLOT_FORMAT::HPGL )
{

View File

@ -24,6 +24,7 @@
#include <board_design_settings.h>
#include <drc/drc_item.h>
#include <drc/drc_report.h>
#include <drawing_sheet/ds_data_model.h>
#include <drawing_sheet/ds_proxy_view_item.h>
#include <jobs/job_fp_export_svg.h>
#include <jobs/job_fp_upgrade.h>
@ -52,6 +53,7 @@
#include <macros.h>
#include <pad.h>
#include <pcb_marker.h>
#include <project/project_file.h>
#include <exporters/export_svg.h>
#include <pcbnew_settings.h>
#include <pcbplot.h>
@ -198,6 +200,7 @@ int PCBNEW_JOBS_HANDLER::JobExportSvg( JOB* aJob )
m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
BOARD* brd = LoadBoard( aSvgJob->m_filename );
loadOverrideDrawingSheet( brd, aSvgJob->m_drawingSheet );
if( aJob->IsCli() )
{
@ -222,6 +225,7 @@ int PCBNEW_JOBS_HANDLER::JobExportDxf( JOB* aJob )
m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
BOARD* brd = LoadBoard( aDxfJob->m_filename );
loadOverrideDrawingSheet( brd, aDxfJob->m_drawingSheet );
if( aDxfJob->m_outputFile.IsEmpty() )
{
@ -277,6 +281,7 @@ int PCBNEW_JOBS_HANDLER::JobExportPdf( JOB* aJob )
m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
BOARD* brd = LoadBoard( aPdfJob->m_filename );
loadOverrideDrawingSheet( brd, aPdfJob->m_drawingSheet );
if( aPdfJob->m_outputFile.IsEmpty() )
{
@ -346,6 +351,8 @@ int PCBNEW_JOBS_HANDLER::JobExportGerbers( JOB* aJob )
m_reporter->Report( _( "Loading board\n" ), RPT_SEVERITY_INFO );
BOARD* brd = LoadBoard( aGerberJob->m_filename );
loadOverrideDrawingSheet( brd, aGerberJob->m_drawingSheet );
PCB_PLOT_PARAMS boardPlotOptions = brd->GetPlotOptions();
LSET plotOnAllLayersSelection = boardPlotOptions.GetPlotOnAllLayersSelection();
GERBER_JOBFILE_WRITER jobfile_writer( brd );
@ -1029,3 +1036,32 @@ DS_PROXY_VIEW_ITEM* PCBNEW_JOBS_HANDLER::getDrawingSheetProxyView( BOARD* aBrd )
return drawingSheet;
}
void PCBNEW_JOBS_HANDLER::loadOverrideDrawingSheet( BOARD* aBrd, const wxString& aSheetPath )
{
// dont bother attempting to load a empty path, if there was one
if( aSheetPath.IsEmpty() )
return;
auto loadSheet = [&]( const wxString& path ) -> bool
{
BASE_SCREEN::m_DrawingSheetFileName = path;
wxString filename = DS_DATA_MODEL::ResolvePath( BASE_SCREEN::m_DrawingSheetFileName,
aBrd->GetProject()->GetProjectPath() );
if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( path ) )
{
m_reporter->Report( wxString::Format( _( "Error loading drawing sheet '%s'." ), path ),
RPT_SEVERITY_ERROR );
return false;
}
return true;
};
if( loadSheet( aSheetPath ) )
return;
// failed loading custom path, revert back to default
loadSheet( aBrd->GetProject()->GetProjectFile().m_BoardDrawingSheetFile );
}

View File

@ -50,6 +50,7 @@ private:
void populateGerberPlotOptionsFromJob( PCB_PLOT_PARAMS& aPlotOpts,
JOB_EXPORT_PCB_GERBER* aJob );
int doFpExportSvg( JOB_FP_EXPORT_SVG* aSvgJob, const FOOTPRINT* aFootprint );
void loadOverrideDrawingSheet( BOARD* brd, const wxString& aSheetPath );
DS_PROXY_VIEW_ITEM* getDrawingSheetProxyView( BOARD* aBrd );
};