From 18b5046faeae43df3ee4421340e590d44ecafa34 Mon Sep 17 00:00:00 2001
From: dsa-t <dudesuchamazing@gmail.com>
Date: Thu, 13 Mar 2025 17:48:56 +0300
Subject: [PATCH] Fix Eagle PCB layers handling after v9 layer changes.

(cherry picked from commit 2bf369793c65962d06ce407a80cdfe6925ee3400)

Co-authored-by: Alex Shvartzkop <dudesuchamazing@gmail.com>
---
 pcbnew/pcb_io/eagle/pcb_io_eagle.cpp | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/pcbnew/pcb_io/eagle/pcb_io_eagle.cpp b/pcbnew/pcb_io/eagle/pcb_io_eagle.cpp
index eeaf566669..c2fe82c637 100644
--- a/pcbnew/pcb_io/eagle/pcb_io_eagle.cpp
+++ b/pcbnew/pcb_io/eagle/pcb_io_eagle.cpp
@@ -623,7 +623,7 @@ void PCB_IO_EAGLE::loadLayerDefs( wxXmlNode* aLayers )
         else
         {
             // some eagle boards do not have contiguous layer number sequences.
-            m_cu_map[it->number] = ki_layer_count;
+            m_cu_map[it->number] = BoardLayerFromLegacyId( ki_layer_count );
         }
     }
 
@@ -3330,9 +3330,13 @@ int PCB_IO_EAGLE::getMinimumCopperLayerCount() const
     {
         PCB_LAYER_ID layerId = it->second;
 
-        if( IsCopperLayer( layerId ) && layerId != F_Cu && layerId != B_Cu
-            && ( layerId + 2 ) > minLayerCount )
-            minLayerCount = layerId + 2;
+        if( !IsCopperLayer( layerId ) || layerId == F_Cu || layerId == B_Cu )
+            continue;
+
+        int ordinal = CopperLayerToOrdinal( layerId );
+
+        if( ( ordinal + 2 ) > minLayerCount )
+            minLayerCount = ordinal + 2;
     }
 
     // Ensure the copper layers count is a multiple of 2