From 791116529464961efe61f5c312bbf0857b98a40a Mon Sep 17 00:00:00 2001
From: Seth Hillbrand <seth@kipro-pcb.com>
Date: Tue, 11 Feb 2025 11:01:20 -0800
Subject: [PATCH] Prevent overplotting copper layers

68fa45dea0115ae23a8650eb6f6ce05448a2d42e wanted to ensure that drill
marks were visible even when plotting non-copper layers.  However, this
had the effect of changing the plot order depending on whether drill
marks were shown or not.  The current solution is to overplot drill
marks if both copper and non-copper layers are shown.

This remains a sub-optimal solution as buried vias will be overplotted
along with through holes.  It may be a better long-term solution to gate
the plotting of covering pad layers' drill marks to the plot options
that include copper layers on the same page
---
 pcbnew/plot_board_layers.cpp | 27 ++++++++++-----------------
 1 file changed, 10 insertions(+), 17 deletions(-)

diff --git a/pcbnew/plot_board_layers.cpp b/pcbnew/plot_board_layers.cpp
index 9e4cd6349d..bfe5c391bf 100644
--- a/pcbnew/plot_board_layers.cpp
+++ b/pcbnew/plot_board_layers.cpp
@@ -60,29 +60,22 @@ void PlotBoardLayers( BOARD* aBoard, PLOTTER* aPlotter, const LSEQ& aLayers,
     if( !aBoard || !aPlotter || aLayers.empty() )
         return;
 
-    // if a drill mark must be plotted, the copper layer needs to be plotted
-    // after other layers because the drill mark must be plotted as a filled
-    // white shape *after* all other shapes are plotted
-    bool plot_mark = aPlotOptions.GetDrillMarksType() != DRILL_MARKS::NO_DRILL_SHAPE;
+    // if a drill mark must be plotted,it must be plotted as a filled
+    // white shape *after* all other shapes are plotted, provided that
+    // the other shapes are not copper layers
+    bool plot_mark = ( aPlotOptions.GetDrillMarksType() != DRILL_MARKS::NO_DRILL_SHAPE
+                       && !aPlotOptions.GetLayerSelection().ClearCopperLayers().empty()
+                       && !aPlotOptions.GetLayerSelection().ClearNonCopperLayers().empty() );
 
     for( PCB_LAYER_ID layer : aLayers )
-    {
-        // copper layers with drill marks will be plotted after all other layers
-        if( IsCopperLayer( layer ) && plot_mark )
-            continue;
-
         PlotOneBoardLayer( aBoard, aPlotter, layer, aPlotOptions );
-    }
 
-    if( !plot_mark )
-        return;
 
-    for( PCB_LAYER_ID layer : aLayers )
+    if( plot_mark )
     {
-        if( !IsCopperLayer( layer ) )
-            continue;
-
-        PlotOneBoardLayer( aBoard, aPlotter, layer, aPlotOptions );
+        aPlotter->SetColor( WHITE );
+        BRDITEMS_PLOTTER itemplotter( aPlotter, aBoard, aPlotOptions );
+        itemplotter.PlotDrillMarks();
     }
 }