Fix up some more cases of missing escaping for symbol names.

Fixes https://gitlab.com/kicad/code/kicad/issues/8694
This commit is contained in:
Jeff Young 2021-07-28 16:39:40 +01:00
parent dda70622ba
commit 726f4d8016
7 changed files with 85 additions and 72 deletions

View File

@ -75,10 +75,10 @@ DIALOG_CHANGE_SYMBOLS::DIALOG_CHANGE_SYMBOLS( SCH_EDIT_FRAME* aParent, SCH_SYMBO
if( m_mode == MODE::CHANGE )
m_matchBySelection->SetLabel( _( "Change selected symbol(s)" ) );
m_newId->AppendText( FROM_UTF8( m_symbol->GetLibId().Format().c_str() ) );
m_newId->ChangeValue( UnescapeString( m_symbol->GetLibId().Format() ) );
m_specifiedReference->ChangeValue( m_symbol->GetRef( currentSheet ) );
m_specifiedValue->ChangeValue( m_symbol->GetValue( currentSheet, false ) );
m_specifiedId->ChangeValue( FROM_UTF8( m_symbol->GetLibId().Format().c_str() ) );
m_specifiedId->ChangeValue( UnescapeString( m_symbol->GetLibId().Format() ) );
}
else
{
@ -233,15 +233,25 @@ DIALOG_CHANGE_SYMBOLS::~DIALOG_CHANGE_SYMBOLS()
}
wxString getLibIdValue( const wxTextCtrl* aCtrl )
{
wxString rawValue = aCtrl->GetValue();
wxString itemName;
wxString libName = rawValue.BeforeFirst( ':', &itemName );
return EscapeString( libName, CTX_LIBID ) + ':' + EscapeString( itemName, CTX_LIBID );
}
void DIALOG_CHANGE_SYMBOLS::launchMatchIdSymbolBrowser( wxCommandEvent& aEvent )
{
wxString newName = m_specifiedId->GetValue();
wxString newName = getLibIdValue( m_specifiedId );
KIWAY_PLAYER* frame = Kiway().Player( FRAME_SCH_VIEWER_MODAL, true );
if( frame->ShowModal( &newName, this ) )
{
m_specifiedId->SetValue( newName );
m_specifiedId->SetValue( UnescapeString( newName ) );
updateFieldsList();
}
@ -251,13 +261,13 @@ void DIALOG_CHANGE_SYMBOLS::launchMatchIdSymbolBrowser( wxCommandEvent& aEvent )
void DIALOG_CHANGE_SYMBOLS::launchNewIdSymbolBrowser( wxCommandEvent& aEvent )
{
wxString newName = m_newId->GetValue();
wxString newName = getLibIdValue( m_newId );
KIWAY_PLAYER* frame = Kiway().Player( FRAME_SCH_VIEWER_MODAL, true );
if( frame->ShowModal( &newName, this ) )
{
m_newId->SetValue( newName );
m_newId->SetValue( UnescapeString( newName ) );
updateFieldsList();
}
@ -323,7 +333,7 @@ void DIALOG_CHANGE_SYMBOLS::updateFieldsList()
{
LIB_ID newId;
newId.Parse( m_newId->GetValue() );
newId.Parse( getLibIdValue( m_newId ) );
if( newId.IsValid() )
{
@ -421,7 +431,7 @@ bool DIALOG_CHANGE_SYMBOLS::isMatch( SCH_SYMBOL* aSymbol, SCH_SHEET_PATH* aInsta
}
else if( m_matchById )
{
id.Parse( m_specifiedId->GetValue() );
id.Parse( getLibIdValue( m_specifiedId ) );
return aSymbol->GetLibId() == id;
}
@ -442,7 +452,7 @@ bool DIALOG_CHANGE_SYMBOLS::processMatchingSymbols()
if( m_mode == MODE::CHANGE )
{
newId.Parse( m_newId->GetValue() );
newId.Parse( getLibIdValue( m_newId ) );
if( !newId.IsValid() )
return false;
@ -515,15 +525,15 @@ bool DIALOG_CHANGE_SYMBOLS::processSymbol( SCH_SYMBOL* aSymbol, const SCH_SHEET_
{
msg.Printf( _( "Update symbol %s from '%s' to '%s'" ),
references,
oldId.Format().c_str(),
aNewId.Format().c_str() );
UnescapeString( oldId.Format() ),
UnescapeString( aNewId.Format() ) );
}
else
{
msg.Printf( _( "Update symbols %s from '%s' to '%s'" ),
references,
oldId.Format().c_str(),
aNewId.Format().c_str() );
UnescapeString( oldId.Format() ),
UnescapeString( aNewId.Format() ) );
}
}
else
@ -532,15 +542,15 @@ bool DIALOG_CHANGE_SYMBOLS::processSymbol( SCH_SYMBOL* aSymbol, const SCH_SHEET_
{
msg.Printf( _( "Change symbol %s from '%s' to '%s'" ),
references,
oldId.Format().c_str(),
aNewId.Format().c_str() );
UnescapeString( oldId.Format() ),
UnescapeString( aNewId.Format() ) );
}
else
{
msg.Printf( _( "Change symbols %s from '%s' to '%s'" ),
references,
oldId.Format().c_str(),
aNewId.Format().c_str() );
UnescapeString( oldId.Format() ),
UnescapeString( aNewId.Format() ) );
}
}

View File

@ -243,10 +243,10 @@ int GRIDCELL_AUTOWRAP_STRINGRENDERER::GetHeight( wxDC& aDC, wxGrid* aGrid, int a
/**
* A helper to handle symbols to edit.
*/
class SYM_CANDIDATE
class SYMBOL_CANDIDATE
{
public:
SYM_CANDIDATE( SCH_SYMBOL* aSymbol )
SYMBOL_CANDIDATE( SCH_SYMBOL* aSymbol )
{
m_Symbol = aSymbol;
m_InitialLibId = m_Symbol->GetLibId().Format();
@ -261,12 +261,6 @@ public:
return m_Symbol->GetLibId().GetUniStringLibId();
}
// Return a string containing the reference of the symbol.
wxString GetSchematicReference()
{
return m_Reference;
}
SCH_SYMBOL* m_Symbol; // the schematic symbol
int m_Row; // the row index in m_grid
SCH_SCREEN* m_Screen; // the screen where m_Symbol lives
@ -345,7 +339,7 @@ private:
bool m_isModified; // set to true if the schematic is modified
std::vector<int> m_OrphansRowIndexes; // list of rows containing orphan lib_id
std::vector<SYM_CANDIDATE> m_symbols;
std::vector<SYMBOL_CANDIDATE> m_symbols;
GRIDCELL_AUTOWRAP_STRINGRENDERER* m_autoWrapRenderer;
};
@ -374,7 +368,7 @@ DIALOG_EDIT_SYMBOLS_LIBID::~DIALOG_EDIT_SYMBOLS_LIBID()
// A sort compare function to sort symbols list by LIB_ID and then reference.
static bool sort_by_libid( const SYM_CANDIDATE& candidate1, const SYM_CANDIDATE& candidate2 )
static bool sort_by_libid( const SYMBOL_CANDIDATE& candidate1, const SYMBOL_CANDIDATE& candidate2 )
{
if( candidate1.m_Symbol->GetLibId() == candidate2.m_Symbol->GetLibId() )
return candidate1.m_Reference.Cmp( candidate2.m_Reference ) < 0;
@ -405,7 +399,7 @@ void DIALOG_EDIT_SYMBOLS_LIBID::initDlg()
for( unsigned ii = 0; ii < references.GetCount(); ii++ )
{
SCH_REFERENCE& item = references[ii];
SYM_CANDIDATE candidate( item.GetSymbol() );
SYMBOL_CANDIDATE candidate( item.GetSymbol() );
candidate.m_Screen = item.GetSheetPath().LastScreen();
SCH_SHEET_PATH sheetpath = item.GetSheetPath();
candidate.m_Reference = candidate.m_Symbol->GetRef( &sheetpath );
@ -427,7 +421,7 @@ void DIALOG_EDIT_SYMBOLS_LIBID::initDlg()
wxString last_ref;
bool mark_cell = m_symbols.front().m_IsOrphan;
for( auto& symbol : m_symbols )
for( SYMBOL_CANDIDATE& symbol : m_symbols )
{
wxString str_libid = symbol.GetStringLibId();
@ -442,18 +436,18 @@ void DIALOG_EDIT_SYMBOLS_LIBID::initDlg()
refs.Empty();
row++;
}
else if( symbol.GetSchematicReference() == last_ref )
else if( symbol.m_Reference == last_ref )
{
symbol.m_Row = row;
continue;
}
last_ref = symbol.GetSchematicReference();
last_ref = symbol.m_Reference;
if( !refs.IsEmpty() )
refs += wxT( ", " );
refs += symbol.GetSchematicReference();
refs += symbol.m_Reference;
symbol.m_Row = row;
}
@ -484,10 +478,10 @@ void DIALOG_EDIT_SYMBOLS_LIBID::AddRowToGrid( bool aMarkRow, const wxString& aRe
m_grid->AppendRows( 1 );
m_grid->SetCellValue( row, COL_REFS, aReferences );
m_grid->SetCellValue( row, COL_REFS, UnescapeString( aReferences ) );
m_grid->SetReadOnly( row, COL_REFS );
m_grid->SetCellValue( row, COL_CURR_LIBID, aStrLibId );
m_grid->SetCellValue( row, COL_CURR_LIBID, UnescapeString( aStrLibId ) );
m_grid->SetReadOnly( row, COL_CURR_LIBID );
if( aMarkRow ) // A symbol is not existing in libraries: mark the cell
@ -507,11 +501,21 @@ void DIALOG_EDIT_SYMBOLS_LIBID::AddRowToGrid( bool aMarkRow, const wxString& aRe
// set new libid column browse button
wxGridCellAttr* attr = new wxGridCellAttr;
attr->SetEditor( new GRID_CELL_SYMBOL_ID_EDITOR( this, aStrLibId ) );
attr->SetEditor( new GRID_CELL_SYMBOL_ID_EDITOR( this, UnescapeString( aStrLibId ) ) );
m_grid->SetAttr( row, COL_NEW_LIBID, attr );
}
wxString getLibIdValue( const WX_GRID* aGrid, int aRow, int aCol )
{
wxString rawValue = aGrid->GetCellValue( aRow, aCol );
wxString itemName;
wxString libName = rawValue.BeforeFirst( ':', &itemName );
return EscapeString( libName, CTX_LIBID ) + ':' + EscapeString( itemName, CTX_LIBID );
}
bool DIALOG_EDIT_SYMBOLS_LIBID::validateLibIds()
{
if( !m_grid->CommitPendingChanges() )
@ -521,7 +525,7 @@ bool DIALOG_EDIT_SYMBOLS_LIBID::validateLibIds()
for( int row = 0; row <= row_max; row++ )
{
wxString new_libid = m_grid->GetCellValue( row, COL_NEW_LIBID );
wxString new_libid = getLibIdValue( m_grid, row, COL_NEW_LIBID );
if( new_libid.IsEmpty() )
continue;
@ -563,7 +567,7 @@ void DIALOG_EDIT_SYMBOLS_LIBID::onCellBrowseLib( wxGridEvent& event )
void DIALOG_EDIT_SYMBOLS_LIBID::onClickOrphansButton( wxCommandEvent& event )
{
std::vector< wxString > libs = Prj().SchSymbolLibTable()->GetLogicalLibs();
std::vector<wxString> libs = Prj().SchSymbolLibTable()->GetLogicalLibs();
wxArrayString aliasNames;
wxArrayString candidateSymbNames;
@ -572,12 +576,12 @@ void DIALOG_EDIT_SYMBOLS_LIBID::onClickOrphansButton( wxCommandEvent& event )
// Try to find a candidate for non existing symbols in any loaded library
for( int orphanRow : m_OrphansRowIndexes )
{
wxString orphanLibid = m_grid->GetCellValue( orphanRow, COL_CURR_LIBID );
wxString orphanLibid = getLibIdValue( m_grid, orphanRow, COL_CURR_LIBID );
int grid_row_idx = orphanRow; //row index in m_grid for the current item
LIB_ID curr_libid;
curr_libid.Parse( orphanLibid, true );
wxString symbName = curr_libid.GetLibItemName();
wxString symbolName = curr_libid.GetLibItemName();
// number of full LIB_ID candidates (because we search for a symbol name
// inside all available libraries, perhaps the same symbol name can be found
@ -586,7 +590,7 @@ void DIALOG_EDIT_SYMBOLS_LIBID::onClickOrphansButton( wxCommandEvent& event )
candidateSymbNames.Clear();
// now try to find a candidate
for( auto &lib : libs )
for( const wxString &lib : libs )
{
aliasNames.Clear();
@ -600,25 +604,25 @@ void DIALOG_EDIT_SYMBOLS_LIBID::onClickOrphansButton( wxCommandEvent& event )
continue;
// Find a symbol name in symbols inside this library:
int index = aliasNames.Index( symbName );
int index = aliasNames.Index( symbolName );
if( index != wxNOT_FOUND )
{
// a candidate is found!
libIdCandidateCount++;
wxString newLibid = lib + ':' + symbName;
wxString newLibid = lib + ':' + symbolName;
// Uses the first found. Most of time, it is alone.
// Others will be stored in a candidate list
if( libIdCandidateCount <= 1 )
{
m_grid->SetCellValue( grid_row_idx, COL_NEW_LIBID, newLibid );
m_grid->SetCellValue( grid_row_idx, COL_NEW_LIBID, UnescapeString( newLibid ) );
candidateSymbNames.Add( m_grid->GetCellValue( grid_row_idx, COL_NEW_LIBID ) );
fixesCount++;
}
else // Store other candidates for later selection
{
candidateSymbNames.Add( newLibid );
candidateSymbNames.Add( UnescapeString( newLibid ) );
}
}
}
@ -666,10 +670,10 @@ bool DIALOG_EDIT_SYMBOLS_LIBID::setLibIdByBrowser( int aRow )
#else
// Use library viewer to choose a symbol
LIB_ID preselected;
wxString current = m_grid->GetCellValue( aRow, COL_NEW_LIBID );
wxString current = getLibIdValue( m_grid, aRow, COL_NEW_LIBID );
if( current.IsEmpty() )
current = m_grid->GetCellValue( aRow, COL_CURR_LIBID );
current = getLibIdValue( m_grid, aRow, COL_CURR_LIBID );
if( !current.IsEmpty() )
preselected.Parse( current, true );
@ -689,7 +693,7 @@ bool DIALOG_EDIT_SYMBOLS_LIBID::setLibIdByBrowser( int aRow )
wxString new_libid;
new_libid = sel.LibId.Format();
m_grid->SetCellValue( aRow, COL_NEW_LIBID, new_libid );
m_grid->SetCellValue( aRow, COL_NEW_LIBID, UnescapeString( new_libid ) );
return true;
}
@ -709,16 +713,16 @@ bool DIALOG_EDIT_SYMBOLS_LIBID::TransferDataFromWindow()
for( int row = 0; row <= row_max; row++ )
{
wxString new_libid = m_grid->GetCellValue( row, COL_NEW_LIBID );
wxString new_libid = getLibIdValue( m_grid, row, COL_NEW_LIBID );
if( new_libid.IsEmpty() || new_libid == m_grid->GetCellValue( row, COL_CURR_LIBID ) )
if( new_libid.IsEmpty() || new_libid == getLibIdValue( m_grid, row, COL_CURR_LIBID ) )
continue;
// A new lib id is found and was already validated.
LIB_ID id;
id.Parse( new_libid, true );
for( SYM_CANDIDATE& candidate : m_symbols )
for( SYMBOL_CANDIDATE& candidate : m_symbols )
{
if( candidate.m_Row != row )
continue;

View File

@ -315,7 +315,7 @@ void DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::visitItem( const SCH_SHEET_PATH& aShe
{
if( aItem->Type() == SCH_SYMBOL_T )
{
wxString id = static_cast<SCH_SYMBOL*>( aItem )->GetLibId().Format();
wxString id = UnescapeString( static_cast<SCH_SYMBOL*>( aItem )->GetLibId().Format() );
if( !WildCompareString( m_symbolFilter->GetValue(), id, false ) )
return;

View File

@ -287,7 +287,7 @@ DIALOG_SYMBOL_PROPERTIES::DIALOG_SYMBOL_PROPERTIES( SCH_EDIT_FRAME* aParent,
// GetLibSymbolRef() now points to the cached part in the schematic, which should always be
// there for usual cases, but can be null when opening old schematics not storing the part
// so we need to handle m_part == nullptr
wxASSERT( m_part );
// wxASSERT( m_part );
m_fields = new FIELDS_GRID_TABLE<SCH_FIELD>( this, aParent, m_fieldsGrid, m_part );
@ -317,7 +317,7 @@ DIALOG_SYMBOL_PROPERTIES::DIALOG_SYMBOL_PROPERTIES( SCH_EDIT_FRAME* aParent,
m_fieldsGrid->PushEventHandler( new FIELDS_GRID_TRICKS( m_fieldsGrid, this ) );
// Show/hide columns according to user's preference
auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
if( cfg )
{
@ -331,8 +331,8 @@ DIALOG_SYMBOL_PROPERTIES::DIALOG_SYMBOL_PROPERTIES( SCH_EDIT_FRAME* aParent,
// free-form alternate assignments as well. (We won't know how to map the alternates
// back and forth when the conversion is changed.)
m_pinTablePage->Disable();
m_pinTablePage->SetToolTip(
_( "Alternate pin assignments are not available for DeMorgan symbols." ) );
m_pinTablePage->SetToolTip( _( "Alternate pin assignments are not available for DeMorgan "
"symbols." ) );
}
else
{
@ -374,7 +374,7 @@ DIALOG_SYMBOL_PROPERTIES::DIALOG_SYMBOL_PROPERTIES( SCH_EDIT_FRAME* aParent,
DIALOG_SYMBOL_PROPERTIES::~DIALOG_SYMBOL_PROPERTIES()
{
auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
if( cfg )
cfg->m_Appearance.edit_component_visible_columns = m_fieldsGrid->GetShownColumns();
@ -497,7 +497,7 @@ bool DIALOG_SYMBOL_PROPERTIES::TransferDataToWindow()
}
// Set the symbol's library name.
m_tcLibraryID->SetLabelText( m_symbol->GetLibId().Format() );
m_tcLibraryID->SetLabelText( UnescapeString( m_symbol->GetLibId().Format() ) );
Layout();
@ -1048,7 +1048,7 @@ void DIALOG_SYMBOL_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& event )
void DIALOG_SYMBOL_PROPERTIES::OnSizeGrid( wxSizeEvent& event )
{
auto new_size = event.GetSize().GetX();
int new_size = event.GetSize().GetX();
if( m_width != new_size )
{

View File

@ -557,7 +557,7 @@ void SCH_SCREEN::UpdateSymbolLinks( REPORTER* aReporter )
// Clear all existing symbol links.
clearLibSymbols();
for( auto symbol : symbols )
for( SCH_SYMBOL* symbol : symbols )
{
LIB_SYMBOL* tmp = nullptr;
libSymbol.reset();
@ -569,11 +569,10 @@ void SCH_SCREEN::UpdateSymbolLinks( REPORTER* aReporter )
{
if( aReporter )
{
msg.Printf( _( "Setting schematic symbol '%s %s' library identifier "
"to '%s'. " ),
msg.Printf( _( "Setting schematic symbol '%s %s' library identifier to '%s'." ),
symbol->GetField( REFERENCE_FIELD )->GetText(),
symbol->GetField( VALUE_FIELD )->GetText(),
symbol->GetLibId().Format().wx_str() );
UnescapeString( symbol->GetLibId().Format() ) );
aReporter->ReportTail( msg, RPT_SEVERITY_INFO );
}
@ -586,9 +585,9 @@ void SCH_SCREEN::UpdateSymbolLinks( REPORTER* aReporter )
{
if( aReporter )
{
msg.Printf( _( "Schematic symbol reference '%s' library identifier is not "
"valid. Unable to link library symbol." ),
symbol->GetLibId().Format().wx_str() );
msg.Printf( _( "Schematic symbol reference '%s' library identifier is not valid. "
"Unable to link library symbol." ),
UnescapeString( symbol->GetLibId().Format() ) );
aReporter->ReportTail( msg, RPT_SEVERITY_WARNING );
}
@ -602,8 +601,8 @@ void SCH_SCREEN::UpdateSymbolLinks( REPORTER* aReporter )
{
if( aReporter )
{
msg.Printf( _( "Symbol library '%s' not found and no fallback cache "
"library available. Unable to link library symbol." ),
msg.Printf( _( "Symbol library '%s' not found and no fallback cache library "
"available. Unable to link library symbol." ),
symbol->GetLibId().GetLibNickname().wx_str() );
aReporter->ReportTail( msg, RPT_SEVERITY_WARNING );
}
@ -622,7 +621,7 @@ void SCH_SCREEN::UpdateSymbolLinks( REPORTER* aReporter )
if( aReporter )
{
msg.Printf( _( "I/O error %s resolving library symbol %s" ), ioe.What(),
symbol->GetLibId().Format().wx_str() );
UnescapeString( symbol->GetLibId().Format() ) );
aReporter->ReportTail( msg, RPT_SEVERITY_ERROR );
}
}
@ -644,7 +643,7 @@ void SCH_SCREEN::UpdateSymbolLinks( REPORTER* aReporter )
msg.Printf( _( "Falling back to cache to set symbol '%s:%s' link '%s'." ),
symbol->GetField( REFERENCE_FIELD )->GetText(),
symbol->GetField( VALUE_FIELD )->GetText(),
id );
UnescapeString( id ) );
aReporter->ReportTail( msg, RPT_SEVERITY_WARNING );
}
@ -665,7 +664,7 @@ void SCH_SCREEN::UpdateSymbolLinks( REPORTER* aReporter )
msg.Printf( _( "Setting schematic symbol '%s %s' library identifier to '%s'." ),
symbol->GetField( REFERENCE_FIELD )->GetText(),
symbol->GetField( VALUE_FIELD )->GetText(),
symbol->GetLibId().Format().wx_str() );
UnescapeString( symbol->GetLibId().Format() ) );
aReporter->ReportTail( msg, RPT_SEVERITY_INFO );
}
}

View File

@ -241,7 +241,7 @@ wxString SCH_SYMBOL::GetSchSymbolLibraryName() const
if( !m_schLibSymbolName.IsEmpty() )
return m_schLibSymbolName;
else
return m_lib_id.Format().wx_str();
return m_lib_id.Format();
}

View File

@ -150,7 +150,7 @@ void SYMBOL_EDIT_FRAME::updateTitle()
if( GetScreen() && GetScreen()->IsContentModified() )
title = wxT( "*" );
title += FROM_UTF8( GetCurSymbol()->GetLibId().Format().c_str() );
title += UnescapeString( GetCurSymbol()->GetLibId().Format() );
if( m_libMgr && m_libMgr->IsLibraryReadOnly( GetCurLib() ) )
title += wxS( " " ) + _( "[Read Only Library]" );