File Fix-writing-pad-layer-information-to-the-board-file.patch of Package kicad

From 2718149f9575e4503a414eea08c7e0236797fe92 Mon Sep 17 00:00:00 2001
From: Ian McInerney <ian.s.mcinerney@ieee.org>
Date: Mon, 10 Feb 2025 00:00:50 +0000
Subject: [PATCH] Fix writing pad layer information to the board file

Patch-mainline: 9.0.0
Git-commit: 62f9355180897824286e08b292f52ccf9b3f44cd

Pads should write that they exist on all layers using the wildcard and
then not also enumerate the copper layers (in this case, enumerating the
copper layers that were not enabled on the board).
---
 .../pcb_io/kicad_sexpr/pcb_io_kicad_sexpr.cpp | 20 +++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr.cpp b/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr.cpp
index 1fccd4ef32..77acb08d15 100644
--- a/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr.cpp
+++ b/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr.cpp
@@ -1366,9 +1366,7 @@ void PCB_IO_KICAD_SEXPR::formatLayers( LSET aLayerMask, int aNestLevel, bool aEn
 
     output += "(layers";
 
-    static const LSET cu_all( LSET::AllCuMask( m_board  // Can be null in some cases in fp editor
-                                                ? m_board->GetCopperLayerCount()
-                                                : MAX_CU_LAYERS ) );
+    static const LSET cu_all( LSET::AllCuMask() );
     static const LSET fr_bk(  2, B_Cu,       F_Cu );
     static const LSET adhes(  2, B_Adhes,    F_Adhes );
     static const LSET paste(  2, B_Paste,    F_Paste );
@@ -1377,17 +1375,23 @@ void PCB_IO_KICAD_SEXPR::formatLayers( LSET aLayerMask, int aNestLevel, bool aEn
     static const LSET crt_yd( 2, B_CrtYd,    F_CrtYd );
     static const LSET fab(    2, B_Fab,      F_Fab );
 
-    LSET cu_mask = cu_all;
+    LSET cu_board_mask = LSET::AllCuMask( m_board
+                                           ? m_board->GetCopperLayerCount()
+                                           : MAX_CU_LAYERS );
 
     if( !aEnumerateLayers )
     {
-        // output copper layers first, then non copper
-        if( ( aLayerMask & cu_mask ) == cu_mask )
+        // If all copper layers present on the board are enabled, then output the wildcard
+        if( ( aLayerMask & cu_board_mask ) == cu_board_mask )
         {
             output += ' ' + m_out->Quotew( "*.Cu" );
-            aLayerMask &= ~cu_all;          // clear bits, so they are not output again below
+
+            // Clear all copper bits because pads might have internal layers that aren't part of the
+            // board enabled, and we don't want to output those in the layers listing if we already
+            // output the wildcard.
+            aLayerMask &= ~cu_all;
         }
-        else if( ( aLayerMask & cu_mask ) == fr_bk )
+        else if( ( aLayerMask & cu_board_mask ) == fr_bk )
         {
             output += ' ' + m_out->Quotew( "F&B.Cu" );
             aLayerMask &= ~fr_bk;
-- 
2.47.1

openSUSE Build Service is sponsored by