Honour LAYER, SHEETNAME and SHEETPATH variable overrides on CLI.

Also allows the LAYER variable to work automatically
if you're plotting/exporting a single layer.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/17680
This commit is contained in:
Jeff Young 2024-05-13 20:03:45 +01:00
parent c659b46d5e
commit 3e0c598500
6 changed files with 119 additions and 31 deletions

View File

@ -1204,6 +1204,11 @@ void DIALOG_PLOT::Plot( wxCommandEvent& event )
}
PCB_LAYER_ID layer = *seq;
wxString layerName = board->GetLayerName( layer );
//@todo allow controlling the sheet name and path that will be displayed in the title block
// Leave blank for now
wxString sheetName;
wxString sheetPath;
// All copper layers that are disabled are actually selected
// This is due to wonkyness in automatically selecting copper layers
@ -1222,16 +1227,14 @@ void DIALOG_PLOT::Plot( wxCommandEvent& event )
if( m_plotOpts.GetFormat() == PLOT_FORMAT::GERBER && m_useGerberExtensions->GetValue() )
file_ext = GetGerberProtelExtension( layer );
BuildPlotFileName( &fn, outputDir.GetPath(), board->GetLayerName( layer ), file_ext );
BuildPlotFileName( &fn, outputDir.GetPath(), layerName, file_ext );
wxString fullname = fn.GetFullName();
jobfile_writer.AddGbrFile( layer, fullname );
LOCALE_IO toggle;
//@todo allow controlling the sheet name and path that will be displayed in the title block
// Leave blank for now
PLOTTER* plotter = StartPlotBoard( board, &m_plotOpts, layer, fn.GetFullPath(),
wxEmptyString, wxEmptyString );
PLOTTER* plotter = StartPlotBoard( board, &m_plotOpts, layer, layerName, fn.GetFullPath(),
sheetName, sheetPath );
// Print diags in messages box:
wxString msg;

View File

@ -88,11 +88,21 @@ bool EXPORT_SVG::Plot( BOARD* aBoard, const PCB_PLOT_SVG_OPTIONS& aSvgPlotOption
plot_opts.SetColorSettings( mgr.GetColorSettings( aSvgPlotOptions.m_colorTheme ) );
LOCALE_IO toggle;
PCB_LAYER_ID layer = UNDEFINED_LAYER;
wxString layerName;
//@todo allow controlling the sheet name and path that will be displayed in the title block
// Leave blank for now
SVG_PLOTTER* plotter = (SVG_PLOTTER*) StartPlotBoard( aBoard, &plot_opts, UNDEFINED_LAYER, outputFile,
wxEmptyString, wxEmptyString );
wxString sheetName;
wxString sheetPath;
if( aSvgPlotOptions.m_printMaskLayer.size() == 1 )
{
layer = aSvgPlotOptions.m_printMaskLayer.front();
layerName = aBoard->GetLayerName( layer );
}
SVG_PLOTTER* plotter = (SVG_PLOTTER*) StartPlotBoard( aBoard, &plot_opts, layer, layerName,
outputFile, sheetName, sheetPath );
if( plotter )
{

View File

@ -494,8 +494,29 @@ int PCBNEW_JOBS_HANDLER::JobExportDxf( JOB* aJob )
plotOpts.SetPlotReference( aDxfJob->m_plotRefDes );
plotOpts.SetLayerSelection( aDxfJob->m_printMaskLayer );
DXF_PLOTTER* plotter = (DXF_PLOTTER*) StartPlotBoard(
brd, &plotOpts, UNDEFINED_LAYER, aDxfJob->m_outputFile, wxEmptyString, wxEmptyString );
PCB_LAYER_ID layer = UNDEFINED_LAYER;
wxString layerName;
wxString sheetName;
wxString sheetPath;
if( aDxfJob->m_printMaskLayer.size() == 1 )
{
layer = aDxfJob->m_printMaskLayer.front();
layerName = brd->GetLayerName( layer );
}
if( aJob->GetVarOverrides().contains( wxT( "LAYER" ) ) )
layerName = aJob->GetVarOverrides().at( wxT( "LAYER" ) );
if( aJob->GetVarOverrides().contains( wxT( "SHEETNAME" ) ) )
sheetName = aJob->GetVarOverrides().at( wxT( "SHEETNAME" ) );
if( aJob->GetVarOverrides().contains( wxT( "SHEETPATH" ) ) )
sheetPath = aJob->GetVarOverrides().at( wxT( "SHEETPATH" ) );
DXF_PLOTTER* plotter = (DXF_PLOTTER*) StartPlotBoard( brd, &plotOpts, layer, layerName,
aDxfJob->m_outputFile, sheetName,
sheetPath );
if( plotter )
{
@ -555,8 +576,29 @@ int PCBNEW_JOBS_HANDLER::JobExportPdf( JOB* aJob )
case 2: plotOpts.SetDrillMarksType( DRILL_MARKS::FULL_DRILL_SHAPE ); break;
}
PDF_PLOTTER* plotter = (PDF_PLOTTER*) StartPlotBoard(
brd, &plotOpts, UNDEFINED_LAYER, aPdfJob->m_outputFile, wxEmptyString, wxEmptyString );
PCB_LAYER_ID layer = UNDEFINED_LAYER;
wxString layerName;
wxString sheetName;
wxString sheetPath;
if( aPdfJob->m_printMaskLayer.size() == 1 )
{
layer = aPdfJob->m_printMaskLayer.front();
layerName = brd->GetLayerName( layer );
}
if( aPdfJob->GetVarOverrides().contains( wxT( "LAYER" ) ) )
layerName = aPdfJob->GetVarOverrides().at( wxT( "LAYER" ) );
if( aPdfJob->GetVarOverrides().contains( wxT( "SHEETNAME" ) ) )
sheetName = aPdfJob->GetVarOverrides().at( wxT( "SHEETNAME" ) );
if( aPdfJob->GetVarOverrides().contains( wxT( "SHEETPATH" ) ) )
sheetPath = aPdfJob->GetVarOverrides().at( wxT( "SHEETPATH" ) );
PDF_PLOTTER* plotter = (PDF_PLOTTER*) StartPlotBoard( brd, &plotOpts, layer, layerName,
aPdfJob->m_outputFile, sheetName,
sheetPath );
if( plotter )
{
@ -633,6 +675,9 @@ int PCBNEW_JOBS_HANDLER::JobExportGerbers( JOB* aJob )
// Pick the basename from the board file
wxFileName fn( brd->GetFileName() );
PCB_LAYER_ID layer = *seq;
wxString layerName = brd->GetLayerName( layer );
wxString sheetName;
wxString sheetPath;
PCB_PLOT_PARAMS plotOpts;
if( aGerberJob->m_useBoardPlotParams )
@ -645,14 +690,24 @@ int PCBNEW_JOBS_HANDLER::JobExportGerbers( JOB* aJob )
else
fileExt = FILEEXT::GerberFileExtension;
BuildPlotFileName( &fn, aGerberJob->m_outputFile, brd->GetLayerName( layer ), fileExt );
BuildPlotFileName( &fn, aGerberJob->m_outputFile, layerName, fileExt );
wxString fullname = fn.GetFullName();
jobfile_writer.AddGbrFile( layer, fullname );
if( aJob->GetVarOverrides().contains( wxT( "LAYER" ) ) )
layerName = aJob->GetVarOverrides().at( wxT( "LAYER" ) );
if( aJob->GetVarOverrides().contains( wxT( "SHEETNAME" ) ) )
sheetName = aJob->GetVarOverrides().at( wxT( "SHEETNAME" ) );
if( aJob->GetVarOverrides().contains( wxT( "SHEETPATH" ) ) )
sheetPath = aJob->GetVarOverrides().at( wxT( "SHEETPATH" ) );
// We are feeding it one layer at the start here to silence a logic check
GERBER_PLOTTER* plotter = (GERBER_PLOTTER*) StartPlotBoard(
brd, &plotOpts, layer, fn.GetFullPath(), wxEmptyString, wxEmptyString );
GERBER_PLOTTER* plotter = (GERBER_PLOTTER*) StartPlotBoard( brd, &plotOpts, layer,
layerName, fn.GetFullPath(),
sheetName, sheetPath );
if( plotter )
{
@ -733,10 +788,30 @@ int PCBNEW_JOBS_HANDLER::JobExportGerber( JOB* aJob )
populateGerberPlotOptionsFromJob( plotOpts, aGerberJob );
plotOpts.SetLayerSelection( aGerberJob->m_printMaskLayer );
PCB_LAYER_ID layer = UNDEFINED_LAYER;
wxString layerName;
wxString sheetName;
wxString sheetPath;
if( aGerberJob->m_printMaskLayer.size() == 1 )
{
layer = aGerberJob->m_printMaskLayer.front();
layerName = brd->GetLayerName( layer );
}
if( aJob->GetVarOverrides().contains( wxT( "LAYER" ) ) )
layerName = aJob->GetVarOverrides().at( wxT( "LAYER" ) );
if( aJob->GetVarOverrides().contains( wxT( "SHEETNAME" ) ) )
sheetName = aJob->GetVarOverrides().at( wxT( "SHEETNAME" ) );
if( aJob->GetVarOverrides().contains( wxT( "SHEETPATH" ) ) )
sheetPath = aJob->GetVarOverrides().at( wxT( "SHEETPATH" ) );
// We are feeding it one layer at the start here to silence a logic check
GERBER_PLOTTER* plotter = (GERBER_PLOTTER*) StartPlotBoard(
brd, &plotOpts, aGerberJob->m_printMaskLayer.front(), aGerberJob->m_outputFile,
wxEmptyString, wxEmptyString );
GERBER_PLOTTER* plotter = (GERBER_PLOTTER*) StartPlotBoard( brd, &plotOpts, layer, layerName,
aGerberJob->m_outputFile,
sheetName, sheetPath );
if( plotter )
{

View File

@ -452,6 +452,8 @@ bool PLOT_CONTROLLER::OpenPlotfile( const wxString& aSuffix, PLOT_FORMAT aFormat
wxFileName outputDir = wxFileName::DirName( outputDirName );
wxString boardFilename = m_board->GetFileName();
PCB_LAYER_ID layer = ToLAYER_ID( GetLayer() );
wxString layerName = m_board->GetLayerName( layer );
if( EnsureFileDirectoryExists( &outputDir, boardFilename ) )
{
@ -471,7 +473,7 @@ bool PLOT_CONTROLLER::OpenPlotfile( const wxString& aSuffix, PLOT_FORMAT aFormat
// Build plot filenames from the board name and layer names:
BuildPlotFileName( &m_plotFile, outputDir.GetPath(), aSuffix, fileExt );
m_plotter = StartPlotBoard( m_board, &GetPlotOptions(), ToLAYER_ID( GetLayer() ),
m_plotter = StartPlotBoard( m_board, &GetPlotOptions(), layer, layerName,
m_plotFile.GetFullPath(), aSheetName, aSheetPath );
}

View File

@ -142,8 +142,8 @@ private:
PLOTTER* StartPlotBoard( BOARD* aBoard, const PCB_PLOT_PARAMS* aPlotOpts, int aLayer,
const wxString& aFullFileName, const wxString& aSheetName,
const wxString& aSheetPath );
const wxString& aLayerName, const wxString& aFullFileName,
const wxString& aSheetName, const wxString& aSheetPath );
/**
* Plot a sequence of board layer IDs.

View File

@ -1151,8 +1151,8 @@ static void ConfigureHPGLPenSizes( HPGL_PLOTTER *aPlotter, const PCB_PLOT_PARAMS
* @return the plotter object if OK, NULL if the file is not created (or has a problem).
*/
PLOTTER* StartPlotBoard( BOARD *aBoard, const PCB_PLOT_PARAMS *aPlotOpts, int aLayer,
const wxString& aFullFileName, const wxString& aSheetName,
const wxString& aSheetPath )
const wxString& aLayerName, const wxString& aFullFileName,
const wxString& aSheetName, const wxString& aSheetPath )
{
// Create the plotter driver and set the few plotter specific options
PLOTTER* plotter = nullptr;
@ -1213,9 +1213,7 @@ PLOTTER* StartPlotBoard( BOARD *aBoard, const PCB_PLOT_PARAMS *aPlotOpts, int aL
KIGFX::PCB_RENDER_SETTINGS* renderSettings = new KIGFX::PCB_RENDER_SETTINGS();
renderSettings->LoadColors( aPlotOpts->ColorSettings() );
renderSettings->SetDefaultPenWidth( pcbIUScale.mmToIU( 0.0212 ) ); // Hairline at 1200dpi
if( aLayer >= 0 && aLayer < GAL_LAYER_ID_END )
renderSettings->SetLayerName( aBoard->GetLayerName( ToLAYER_ID( aLayer ) ) );
renderSettings->SetLayerName( aLayerName );
plotter->SetRenderSettings( renderSettings );