diff --git a/eeschema/netlist_exporters/netlist_exporter_spice.cpp b/eeschema/netlist_exporters/netlist_exporter_spice.cpp index e2817f3fce..4d7dad52a3 100644 --- a/eeschema/netlist_exporters/netlist_exporter_spice.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_spice.cpp @@ -51,6 +51,7 @@ #include #include #include +#include "markup_parser.h" namespace NETLIST_EXPORTER_SPICE_PARSER { @@ -280,11 +281,45 @@ bool NETLIST_EXPORTER_SPICE::ReadSchematicAndLibraries( unsigned aNetlistOptions } -void NETLIST_EXPORTER_SPICE::ReplaceForbiddenChars( std::string& aNetName ) +void NETLIST_EXPORTER_SPICE::ConvertToSpiceMarkup( std::string& aNetName ) { - boost::replace_all( aNetName, "(", "_" ); - boost::replace_all( aNetName, ")", "_" ); - boost::replace_all( aNetName, " ", "_" ); + MARKUP::MARKUP_PARSER markupParser( aNetName ); + std::unique_ptr root = markupParser.Parse(); + std::string converted; + + std::function&)> convertMarkup = + [&]( const std::unique_ptr& aNode ) + { + if( aNode ) + { + if( !aNode->is_root() ) + { + if( aNode->isOverbar() ) + { + // ~{CLK} is a different signal than CLK + converted += '~'; + } + else if( aNode->isSubscript() || aNode->isSuperscript() ) + { + // V_{OUT} is just a pretty-printed version of VOUT + } + + if( aNode->has_content() ) + converted += aNode->string(); + } + + for( const std::unique_ptr& child : aNode->children ) + convertMarkup( child ); + } + }; + + convertMarkup( root ); + + boost::replace_all( converted, "(", "_" ); + boost::replace_all( converted, ")", "_" ); + boost::replace_all( converted, " ", "_" ); + + aNetName = converted; } @@ -560,7 +595,7 @@ std::string NETLIST_EXPORTER_SPICE::GenerateItemPinNetName( const std::string& a { std::string netName = aNetName; - ReplaceForbiddenChars( netName ); + ConvertToSpiceMarkup( netName ); netName = std::string( UnescapeString( netName ).ToUTF8() ); if( netName == "" ) diff --git a/eeschema/netlist_exporters/netlist_exporter_spice.h b/eeschema/netlist_exporters/netlist_exporter_spice.h index 576208124d..b629a53a83 100644 --- a/eeschema/netlist_exporters/netlist_exporter_spice.h +++ b/eeschema/netlist_exporters/netlist_exporter_spice.h @@ -93,9 +93,9 @@ public: virtual bool ReadSchematicAndLibraries( unsigned aNetlistOptions, REPORTER& aReporter ); /** - * Replace illegal spice net name characters with underscores. + * Remove formatting wrappers and replace illegal spice net name characters with underscores. */ - static void ReplaceForbiddenChars( std::string& aNetName ); + static void ConvertToSpiceMarkup( std::string& aNetName ); /** * Return the list of nets. diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index a495b05ad6..c1b48622c0 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -911,7 +911,7 @@ int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent ) if( SCH_CONNECTION* conn = static_cast( item )->Connection() ) { std::string spiceNet = std::string( UnescapeString( conn->Name() ).ToUTF8() ); - NETLIST_EXPORTER_SPICE::ReplaceForbiddenChars( spiceNet ); + NETLIST_EXPORTER_SPICE::ConvertToSpiceMarkup( spiceNet ); simFrame->AddVoltagePlot( wxString::Format( "V(%s)", spiceNet ) ); }