Convert formatting constructs for SPICE consumption.
Fixes https://gitlab.com/kicad/code/kicad/issues/11383
This commit is contained in:
parent
9c129ed03f
commit
fbd2d66a75
|
@ -51,6 +51,7 @@
|
||||||
#include <pegtl/contrib/parse_tree.hpp>
|
#include <pegtl/contrib/parse_tree.hpp>
|
||||||
#include <wx/dir.h>
|
#include <wx/dir.h>
|
||||||
#include <locale_io.h>
|
#include <locale_io.h>
|
||||||
|
#include "markup_parser.h"
|
||||||
|
|
||||||
namespace NETLIST_EXPORTER_SPICE_PARSER
|
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, "(", "_" );
|
MARKUP::MARKUP_PARSER markupParser( aNetName );
|
||||||
boost::replace_all( aNetName, ")", "_" );
|
std::unique_ptr<MARKUP::NODE> root = markupParser.Parse();
|
||||||
boost::replace_all( aNetName, " ", "_" );
|
std::string converted;
|
||||||
|
|
||||||
|
std::function<void( const std::unique_ptr<MARKUP::NODE>&)> convertMarkup =
|
||||||
|
[&]( const std::unique_ptr<MARKUP::NODE>& 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<MARKUP::NODE>& 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;
|
std::string netName = aNetName;
|
||||||
|
|
||||||
ReplaceForbiddenChars( netName );
|
ConvertToSpiceMarkup( netName );
|
||||||
netName = std::string( UnescapeString( netName ).ToUTF8() );
|
netName = std::string( UnescapeString( netName ).ToUTF8() );
|
||||||
|
|
||||||
if( netName == "" )
|
if( netName == "" )
|
||||||
|
|
|
@ -93,9 +93,9 @@ public:
|
||||||
virtual bool ReadSchematicAndLibraries( unsigned aNetlistOptions, REPORTER& aReporter );
|
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.
|
* Return the list of nets.
|
||||||
|
|
|
@ -911,7 +911,7 @@ int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent )
|
||||||
if( SCH_CONNECTION* conn = static_cast<SCH_ITEM*>( item )->Connection() )
|
if( SCH_CONNECTION* conn = static_cast<SCH_ITEM*>( item )->Connection() )
|
||||||
{
|
{
|
||||||
std::string spiceNet = std::string( UnescapeString( conn->Name() ).ToUTF8() );
|
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 ) );
|
simFrame->AddVoltagePlot( wxString::Format( "V(%s)", spiceNet ) );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue