From 5734a5551508873b6e3ad9bb59f4d2f498a9aa7f Mon Sep 17 00:00:00 2001 From: Mike Williams Date: Wed, 15 Nov 2023 09:53:18 -0500 Subject: [PATCH] kicad-cli: correctly label non-existent fields Fixes: https://gitlab.com/kicad/code/kicad/-/issues/16085 --- eeschema/eeschema_jobs_handler.cpp | 10 ++++++---- kicad/cli/command_sch_export_bom.cpp | 7 +++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/eeschema/eeschema_jobs_handler.cpp b/eeschema/eeschema_jobs_handler.cpp index afa34bd3e6..c89d9a1b91 100644 --- a/eeschema/eeschema_jobs_handler.cpp +++ b/eeschema/eeschema_jobs_handler.cpp @@ -456,10 +456,12 @@ int EESCHEMA_JOBS_HANDLER::JobExportBom( JOB* aJob ) field.groupBy = std::find( aBomJob->m_fieldsGroupBy.begin(), aBomJob->m_fieldsGroupBy.end(), field.name ) != aBomJob->m_fieldsGroupBy.end(); - field.label = ( ( aBomJob->m_fieldsLabels.size() > i ) - && !aBomJob->m_fieldsLabels[i].IsEmpty() ) - ? aBomJob->m_fieldsLabels[i] - : field.name; + if( ( aBomJob->m_fieldsLabels.size() > i ) && !aBomJob->m_fieldsLabels[i].IsEmpty() ) + field.label = aBomJob->m_fieldsLabels[i]; + else if( IsTextVar( field.name ) ) + field.label = GetTextVars( field.name ); + else + field.label = field.name; preset.fieldsOrdered.emplace_back( field ); i++; diff --git a/kicad/cli/command_sch_export_bom.cpp b/kicad/cli/command_sch_export_bom.cpp index 0623c450de..2cb5df5c38 100644 --- a/kicad/cli/command_sch_export_bom.cpp +++ b/kicad/cli/command_sch_export_bom.cpp @@ -158,6 +158,13 @@ int CLI::SCH_EXPORT_BOM_COMMAND::doPerform( KIWAY& aKiway ) convertStringList( From_UTF8( m_argParser.get( ARG_FIELDS ).c_str() ) ); bomJob->m_fieldsLabels = convertStringList( From_UTF8( m_argParser.get( ARG_LABELS ).c_str() ) ); + + // We only apply the default labels if the default fields are used + if( m_argParser.is_used( ARG_FIELDS ) && !m_argParser.is_used( ARG_LABELS ) ) + { + bomJob->m_fieldsLabels.clear(); + } + bomJob->m_fieldsGroupBy = convertStringList( From_UTF8( m_argParser.get( ARG_GROUP_BY ).c_str() ) ); bomJob->m_sortField = From_UTF8( m_argParser.get( ARG_SORT_FIELD ).c_str() );