Browse Source

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
lucas 9 months ago
committed by Ian McInerney
parent
commit
2559ac50a3
  1. 50
      eeschema/sim/simulator_frame_ui.cpp
  2. 2
      eeschema/sim/simulator_frame_ui.h

50
eeschema/sim/simulator_frame_ui.cpp

@ -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
auto quoteNetNames = [&]( wxString aExpression ) -> wxString
{
std::vector<bool> mask( aExpression.length(), false );
for( const auto& netname : m_netnames )
{
size_t pos = aExpression.find( netname );
while( pos != wxString::npos )
{
for( const auto& [netname, quotedNetname] : m_quotedNetnames )
aExpression.Replace( netname, quotedNetname );
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
}
}
return aExpression;
};
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 )
{

2
eeschema/sim/simulator_frame_ui.h

@ -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];

Loading…
Cancel
Save