diff --git a/eeschema/sim/simulator_frame_ui.cpp b/eeschema/sim/simulator_frame_ui.cpp index 3cdedd25fa..7c49cf50c2 100644 --- a/eeschema/sim/simulator_frame_ui.cpp +++ b/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 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 ) { diff --git a/eeschema/sim/simulator_frame_ui.h b/eeschema/sim/simulator_frame_ui.h index 231e57d402..d70c07d51d 100644 --- a/eeschema/sim/simulator_frame_ui.h +++ b/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 m_quotedNetnames; + std::vector m_netnames; SPICE_VALUE_FORMAT m_cursorFormats[3][2];