From 2aac00f0ed055b677e5e169a215c26f4c5d005c2 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 24 Nov 2025 19:43:12 +0000 Subject: [PATCH] Trim values before setting into fields grid. Fixes https://gitlab.com/kicad/code/kicad/-/issues/18474 --- eeschema/fields_grid_table.cpp | 18 +++++------------- pcbnew/pcb_fields_grid_table.cpp | 19 ++++++++----------- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/eeschema/fields_grid_table.cpp b/eeschema/fields_grid_table.cpp index d93386643c..a370469a01 100644 --- a/eeschema/fields_grid_table.cpp +++ b/eeschema/fields_grid_table.cpp @@ -885,11 +885,11 @@ void FIELDS_GRID_TABLE::SetValue( int aRow, int aCol, const wxString &aValue ) VECTOR2I pos; wxString value = aValue; - switch( aCol ) + if( aCol != FDC_VALUE ) + value.Trim( true ).Trim( false ); + + if( aCol == FDC_TEXT_SIZE || aCol == FDC_POSX || aCol == FDC_POSY ) { - case FDC_TEXT_SIZE: - case FDC_POSX: - case FDC_POSY: m_eval->SetDefaultUnits( m_frame->GetUserUnits() ); if( m_eval->Process( value ) ) @@ -897,11 +897,6 @@ void FIELDS_GRID_TABLE::SetValue( int aRow, int aCol, const wxString &aValue ) m_evalOriginal[ { aRow, aCol } ] = value; value = m_eval->Result(); } - - break; - - default: - break; } switch( aCol ) @@ -911,7 +906,6 @@ void FIELDS_GRID_TABLE::SetValue( int aRow, int aCol, const wxString &aValue ) break; case FDC_VALUE: - { if( m_parentType == SCH_SHEET_T && field.GetId() == FIELD_T::SHEET_FILENAME ) { value = EnsureFileExtension( value, FILEEXT::KiCadSchematicFileExtension ); @@ -923,7 +917,6 @@ void FIELDS_GRID_TABLE::SetValue( int aRow, int aCol, const wxString &aValue ) field.SetText( UnescapeString( value ) ); break; - } case FDC_SHOWN: field.SetVisible( BoolFromString( value ) ); @@ -986,8 +979,7 @@ void FIELDS_GRID_TABLE::SetValue( int aRow, int aCol, const wxString &aValue ) break; case FDC_TEXT_SIZE: - field.SetTextSize( VECTOR2I( m_frame->ValueFromString( value ), - m_frame->ValueFromString( value ) ) ); + field.SetTextSize( VECTOR2I( m_frame->ValueFromString( value ), m_frame->ValueFromString( value ) ) ); break; case FDC_ORIENTATION: diff --git a/pcbnew/pcb_fields_grid_table.cpp b/pcbnew/pcb_fields_grid_table.cpp index 53ddcf5413..6d345739fe 100644 --- a/pcbnew/pcb_fields_grid_table.cpp +++ b/pcbnew/pcb_fields_grid_table.cpp @@ -345,13 +345,15 @@ void PCB_FIELDS_GRID_TABLE::SetValue( int aRow, int aCol, const wxString &aValue VECTOR2I pos; wxString value = aValue; - switch( aCol ) + if( aCol != PFC_VALUE ) + value.Trim( true ).Trim( false ); + + if( aCol == PFC_WIDTH + || aCol == PFC_HEIGHT + || aCol == PFC_THICKNESS + || aCol == PFC_XOFFSET + || aCol == PFC_YOFFSET ) { - case PFC_WIDTH: - case PFC_HEIGHT: - case PFC_THICKNESS: - case PFC_XOFFSET: - case PFC_YOFFSET: m_eval->SetDefaultUnits( m_frame->GetUserUnits() ); if( m_eval->Process( value ) ) @@ -359,11 +361,6 @@ void PCB_FIELDS_GRID_TABLE::SetValue( int aRow, int aCol, const wxString &aValue m_evalOriginal[ { aRow, aCol } ] = value; value = m_eval->Result(); } - - break; - - default: - break; } switch( aCol )