From 956ec5b17c14d1709d5bb2dc3ff7ae14e4ee6f7e Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 27 Sep 2021 12:40:07 +0100 Subject: [PATCH] Work around the train-wreck that is wxString::Format. Fixes https://gitlab.com/kicad/code/kicad/issues/9247 --- cvpcb/cvpcb_mainframe.cpp | 33 ++++++++++++++++++++++++++------- cvpcb/cvpcb_mainframe.h | 8 +++----- cvpcb/readwrite_dlgs.cpp | 8 ++++---- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/cvpcb/cvpcb_mainframe.cpp b/cvpcb/cvpcb_mainframe.cpp index 96ff982474..c73b8e5c00 100644 --- a/cvpcb/cvpcb_mainframe.cpp +++ b/cvpcb/cvpcb_mainframe.cpp @@ -507,6 +507,27 @@ void CVPCB_MAINFRAME::RedoAssociation() } +wxString CVPCB_MAINFRAME::formatSymbolDesc( int idx, const wxString& aReference, + const wxString& aValue, const wxString& aFootprint ) +{ + // Work around a bug in wxString::Format with double-byte chars (and double-quote, for some + // reason). + wxString desc = wxString::Format( wxT( "%3d " ), idx ); + + for( int ii = aReference.Length(); ii < 8; ++ii ) + desc += wxS( " " ); + + desc += aReference + wxT( " - " ); + + for( int ii = aValue.Length(); ii < 16; ++ii ) + desc += wxS( " " ); + + desc += aValue + wxT( " : " ) + aFootprint; + + return desc; +} + + void CVPCB_MAINFRAME::AssociateFootprint( const CVPCB_ASSOCIATION& aAssociation, bool aNewEntry, bool aAddUndoItem ) { @@ -544,8 +565,7 @@ void CVPCB_MAINFRAME::AssociateFootprint( const CVPCB_ASSOCIATION& aAssociation, candidate->SetFPID( fpid ); // create the new symbol description and set it - wxString description = wxString::Format( CMP_FORMAT, - idx + 1, + wxString description = formatSymbolDesc( idx + 1, candidate->GetReference(), candidate->GetValue(), candidate->GetFPID().Format().wx_str() ); @@ -911,11 +931,10 @@ void CVPCB_MAINFRAME::BuildSymbolsListBox() { symbol = m_netlist.GetComponent( i ); - msg.Printf( CMP_FORMAT, - m_symbolsListBox->GetCount() + 1, - symbol->GetReference(), - symbol->GetValue(), - symbol->GetFPID().Format().wx_str() ); + msg = formatSymbolDesc( m_symbolsListBox->GetCount() + 1, + symbol->GetReference(), + symbol->GetValue(), + symbol->GetFPID().Format().wx_str() ); m_symbolsListBox->m_ComponentList.Add( msg ); } diff --git a/cvpcb/cvpcb_mainframe.h b/cvpcb/cvpcb_mainframe.h index b2871b26b0..ade2efd73c 100644 --- a/cvpcb/cvpcb_mainframe.h +++ b/cvpcb/cvpcb_mainframe.h @@ -49,11 +49,6 @@ typedef std::vector< CVPCB_ASSOCIATION > CVPCB_UNDO_REDO_ENTRIES; // The undo list is a vector of undo entries typedef std::vector< CVPCB_UNDO_REDO_ENTRIES > CVPCB_UNDO_REDO_LIST; -/** - * The print format to display a schematic component line. - * format: idx reference - value : footprint_id - */ -#define CMP_FORMAT wxT( "%3d %8s - %16s : %s" ) /** * The CvPcb application main window. @@ -343,6 +338,9 @@ protected: void setupUIConditions() override; private: + wxString formatSymbolDesc( int idx, const wxString& aReference, const wxString& aValue, + const wxString& aFootprint ); + /** * Setup the tool system for the CVPCB main frame. */ diff --git a/cvpcb/readwrite_dlgs.cpp b/cvpcb/readwrite_dlgs.cpp index 62c323c4de..d53e5a30f2 100644 --- a/cvpcb/readwrite_dlgs.cpp +++ b/cvpcb/readwrite_dlgs.cpp @@ -263,10 +263,10 @@ bool CVPCB_MAINFRAME::ReadNetListAndFpFiles( const std::string& aNetlist ) { COMPONENT* component = m_netlist.GetComponent( i ); - msg.Printf( CMP_FORMAT, m_symbolsListBox->GetCount() + 1, - component->GetReference(), - component->GetValue(), - FROM_UTF8( component->GetFPID().Format().c_str() ) ); + msg = formatSymbolDesc( m_symbolsListBox->GetCount() + 1, + component->GetReference(), + component->GetValue(), + FROM_UTF8( component->GetFPID().Format().c_str() ) ); m_symbolsListBox->AppendLine( msg ); }