From add6705e9802d46fe09c8ef01f114932b5a3fac4 Mon Sep 17 00:00:00 2001
From: Jeff Young <jeff@rokeby.ie>
Date: Tue, 11 Feb 2025 15:46:49 +0000
Subject: [PATCH] Don't copy built-in presets to user list.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/19885
---
 eeschema/eeschema_jobs_handler.cpp | 34 +++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/eeschema/eeschema_jobs_handler.cpp b/eeschema/eeschema_jobs_handler.cpp
index 2f87c0d673..8db1d5af06 100644
--- a/eeschema/eeschema_jobs_handler.cpp
+++ b/eeschema/eeschema_jobs_handler.cpp
@@ -571,14 +571,19 @@ int EESCHEMA_JOBS_HANDLER::JobExportBom( JOB* aJob )
     // Load a preset if one is specified
     if( !aBomJob->m_bomPresetName.IsEmpty() )
     {
-        // Make sure the built-in presets are loaded
-        for( const BOM_PRESET& p : BOM_PRESET::BuiltInPresets() )
-            sch->Settings().m_BomPresets.emplace_back( p );
-
         // Find the preset
-        BOM_PRESET* schPreset = nullptr;
+        const BOM_PRESET* schPreset = nullptr;
 
-        for( BOM_PRESET& p : sch->Settings().m_BomPresets )
+        for( const BOM_PRESET& p : BOM_PRESET::BuiltInPresets() )
+        {
+            if( p.name == aBomJob->m_bomPresetName )
+            {
+                schPreset = &p;
+                break;
+            }
+        }
+
+        for( const BOM_PRESET& p : sch->Settings().m_BomPresets )
         {
             if( p.name == aBomJob->m_bomPresetName )
             {
@@ -707,14 +712,19 @@ int EESCHEMA_JOBS_HANDLER::JobExportBom( JOB* aJob )
     // Load a format preset if one is specified
     if( !aBomJob->m_bomFmtPresetName.IsEmpty() )
     {
-        // Make sure the built-in presets are loaded
-        for( const BOM_FMT_PRESET& p : BOM_FMT_PRESET::BuiltInPresets() )
-            sch->Settings().m_BomFmtPresets.emplace_back( p );
-
         // Find the preset
-        BOM_FMT_PRESET* schFmtPreset = nullptr;
+        const BOM_FMT_PRESET* schFmtPreset = nullptr;
 
-        for( BOM_FMT_PRESET& p : sch->Settings().m_BomFmtPresets )
+        for( const BOM_FMT_PRESET& p : BOM_FMT_PRESET::BuiltInPresets() )
+        {
+            if( p.name == aBomJob->m_bomFmtPresetName )
+            {
+                schFmtPreset = &p;
+                break;
+            }
+        }
+
+        for( const BOM_FMT_PRESET& p : sch->Settings().m_BomFmtPresets )
         {
             if( p.name == aBomJob->m_bomFmtPresetName )
             {