Simulator: Bug fix quoting netnames for user defined signals

- Fixes issue: #18598
- Netnames that contained other netnames weren't quoted correctly
- E.g. /out1 and /out were in conflict in previous method
- Fixed formatting afted review

(cherry picked from commit 2559ac50a358db695484426e0440c0f194d09ac1)
This commit is contained in:
lucas 2025-01-21 00:41:54 +01:00 committed by Ian McInerney
parent 3cae075945
commit 072a2b6305
2 changed files with 45 additions and 9 deletions

View File

@ -894,7 +894,7 @@ void SIMULATOR_FRAME_UI::rebuildSignalsList()
if( netname == "GND" || netname == "0" || netname.StartsWith( unconnected ) )
continue;
m_quotedNetnames[ netname ] = wxString::Format( wxS( "\"%s\"" ), netname );
m_netnames.emplace_back( netname );
addSignal( wxString::Format( wxS( "V(%s)" ), netname ) );
}
}
@ -1872,14 +1872,50 @@ void SIMULATOR_FRAME_UI::updateSignalsGrid()
void SIMULATOR_FRAME_UI::applyUserDefinedSignals()
{
auto quoteNetNames =
[&]( wxString aExpression ) -> wxString
{
for( const auto& [netname, quotedNetname] : m_quotedNetnames )
aExpression.Replace( netname, quotedNetname );
auto quoteNetNames = [&]( wxString aExpression ) -> wxString
{
std::vector<bool> mask( aExpression.length(), false );
return aExpression;
};
for( const auto& netname : m_netnames )
{
size_t pos = aExpression.find( netname );
while( pos != wxString::npos )
{
for( size_t i = 0; i < netname.length(); ++i )
{
mask[pos + i] = true; // Mark the positions of the netname
}
pos = aExpression.find( netname, pos + 1 ); // Find the next occurrence
}
}
wxString quotedNetnames = "";
bool startQuote = true;
// put quotes around all the positions that were found above
for( size_t i = 0; i < aExpression.length(); i++ )
{
if( mask[i] && startQuote )
{
quotedNetnames = quotedNetnames + "\"";
startQuote = false;
}
else if( !mask[i] && !startQuote )
{
quotedNetnames = quotedNetnames + "\"";
startQuote = true;
}
wxString ch = aExpression[i];
quotedNetnames = quotedNetnames + ch;
}
if( !startQuote )
{
quotedNetnames = quotedNetnames + "\"";
}
return quotedNetnames;
};
for( const auto& [ id, signal ] : m_userDefinedSignals )
{

View File

@ -335,7 +335,7 @@ private:
///< SPICE expressions need quoted versions of the netnames since KiCad allows '-' and '/'
///< in netnames.
std::map<wxString, wxString> m_quotedNetnames;
std::vector<wxString> m_netnames;
SPICE_VALUE_FORMAT m_cursorFormats[3][2];