From 96e229de0a87391ac796b9d9836468e7026edd9f Mon Sep 17 00:00:00 2001 From: Mike Williams Date: Tue, 12 Dec 2023 10:59:58 -0500 Subject: [PATCH] kicad-cli: only plot user selected copper layers Fixes: https://gitlab.com/kicad/code/kicad/-/issues/15634 --- pcbnew/pcbnew_jobs_handler.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pcbnew/pcbnew_jobs_handler.cpp b/pcbnew/pcbnew_jobs_handler.cpp index 89bf1efd19..a56049da38 100644 --- a/pcbnew/pcbnew_jobs_handler.cpp +++ b/pcbnew/pcbnew_jobs_handler.cpp @@ -358,7 +358,7 @@ int PCBNEW_JOBS_HANDLER::JobExportGerbers( JOB* aJob ) BOARD* brd = LoadBoard( aGerberJob->m_filename ); loadOverrideDrawingSheet( brd, aGerberJob->m_drawingSheet ); - PCB_PLOT_PARAMS boardPlotOptions = brd->GetPlotOptions(); + PCB_PLOT_PARAMS boardPlotOptions = brd->GetPlotOptions(); LSET plotOnAllLayersSelection = boardPlotOptions.GetPlotOnAllLayersSelection(); GERBER_JOBFILE_WRITER jobfile_writer( brd ); @@ -366,7 +366,13 @@ int PCBNEW_JOBS_HANDLER::JobExportGerbers( JOB* aJob ) if( aGerberJob->m_useBoardPlotParams ) { - aGerberJob->m_printMaskLayer = boardPlotOptions.GetLayerSelection().SeqStackupForPlotting(); + // The board plot options are saved with all copper layers enabled, even those that don't + // exist in the current stackup. This is done so the layers are automatically enabled in the plot + // dialog when the user enables them. We need to filter out these not-enabled layers here so + // we don't plot 32 layers when we only have 4, etc. + LSET plotLayers = ( boardPlotOptions.GetLayerSelection() & LSET::AllNonCuMask() ) + | ( brd->GetEnabledLayers() & LSET::AllCuMask() ); + aGerberJob->m_printMaskLayer = plotLayers.SeqStackupForPlotting(); aGerberJob->m_layersIncludeOnAll = boardPlotOptions.GetPlotOnAllLayersSelection(); } else