Work around the train-wreck that is wxString::Format.

Fixes https://gitlab.com/kicad/code/kicad/issues/9247
This commit is contained in:
Jeff Young 2021-09-27 12:40:07 +01:00
parent 544fa939f8
commit 956ec5b17c
3 changed files with 33 additions and 16 deletions

View File

@ -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 );
}

View File

@ -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.
*/

View File

@ -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 );
}