Excise wxString from simulation
This commit is contained in:
parent
fc10db25ba
commit
e4865ce543
|
@ -167,14 +167,14 @@ bool DIALOG_SIM_MODEL<T>::TransferDataFromWindow()
|
|||
if( !DIALOG_SIM_MODEL_BASE::TransferDataFromWindow() )
|
||||
return false;
|
||||
|
||||
wxString modelName = "";
|
||||
std::string modelName;
|
||||
|
||||
if( m_useLibraryModelRadioButton->GetValue() )
|
||||
modelName = m_modelNameCombobox->GetValue();
|
||||
|
||||
SIM_MODEL::SetFieldValue( m_fields, SIM_LIBRARY_SPICE::NAME_FIELD, modelName );
|
||||
|
||||
wxString path = "";
|
||||
std::string path;
|
||||
|
||||
if( m_useLibraryModelRadioButton->GetValue() )
|
||||
{
|
||||
|
@ -338,7 +338,7 @@ void DIALOG_SIM_MODEL<T>::updateModelCodeTab()
|
|||
wxTextFile file;
|
||||
wxString text;
|
||||
|
||||
text << curModel().SpiceGenerator().Preview( modelName );
|
||||
text << curModel().SpiceGenerator().Preview( std::string( modelName.ToUTF8() ) );
|
||||
text << "\n";
|
||||
text << "--- FILE SOURCE (" << path << ") ---\n";
|
||||
text << "\n";
|
||||
|
@ -356,7 +356,7 @@ void DIALOG_SIM_MODEL<T>::updateModelCodeTab()
|
|||
}
|
||||
}
|
||||
else
|
||||
m_codePreview->SetText( curModel().SpiceGenerator().Preview( modelName ) );
|
||||
m_codePreview->SetText( curModel().SpiceGenerator().Preview( std::string( modelName.ToUTF8() ) ) );
|
||||
|
||||
m_codePreview->SetEditable( false ); // ???
|
||||
m_wasCodePreviewUpdated = true;
|
||||
|
@ -453,7 +453,7 @@ void DIALOG_SIM_MODEL<T>::loadLibrary( const wxString& aFilePath )
|
|||
|
||||
try
|
||||
{
|
||||
m_library->ReadFile( absolutePath );
|
||||
m_library->ReadFile( std::string( absolutePath.ToUTF8() ) );
|
||||
}
|
||||
catch( const IO_ERROR& e )
|
||||
{
|
||||
|
@ -634,9 +634,9 @@ wxPGProperty* DIALOG_SIM_MODEL<T>::newParamProperty( int aParamIndex ) const
|
|||
|
||||
// Legacy due to the way we extracted the parameters from Ngspice.
|
||||
if( param.isOtherVariant )
|
||||
prop->SetCell( 3, param.info.defaultValueOfOtherVariant );
|
||||
prop->SetCell( 3, wxString( param.info.defaultValueOfOtherVariant ) );
|
||||
else
|
||||
prop->SetCell( 3, param.info.defaultValue );
|
||||
prop->SetCell( 3, wxString( param.info.defaultValue ) );
|
||||
|
||||
wxString typeStr;
|
||||
|
||||
|
@ -898,7 +898,7 @@ void DIALOG_SIM_MODEL<T>::onPinAssignmentsGridCellChange( wxGridEvent& aEvent )
|
|||
if( modelPinIndex != SIM_MODEL::PIN::NOT_CONNECTED )
|
||||
{
|
||||
curModel().SetPinSymbolPinNumber( modelPinIndex,
|
||||
m_sortedSymbolPins.at( symbolPinIndex )->GetShownNumber() );
|
||||
std::string( m_sortedSymbolPins.at( symbolPinIndex )->GetShownNumber().ToUTF8() ) );
|
||||
}
|
||||
|
||||
updatePinAssignments();
|
||||
|
|
|
@ -133,7 +133,7 @@ wxString DIALOG_SIM_SETTINGS::evaluateDCControls( wxChoice* aDcSource, wxTextCtr
|
|||
{
|
||||
// pick device name from exporter when something different than temperature is selected
|
||||
if( dcSource.Cmp( "TEMP" ) )
|
||||
dcSource = m_circuitModel->GetItemName( dcSource );
|
||||
dcSource = m_circuitModel->GetItemName( std::string( dcSource.ToUTF8() ) );
|
||||
|
||||
return wxString::Format( "%s %s %s %s", dcSource,
|
||||
SPICE_VALUE( aDcStart->GetValue() ).ToSpiceString(),
|
||||
|
|
|
@ -35,9 +35,12 @@
|
|||
#include <sch_text.h>
|
||||
#include <sch_textbox.h>
|
||||
#include <string_utils.h>
|
||||
|
||||
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include <fmt/core.h>
|
||||
#include <pegtl.hpp>
|
||||
#include <pegtl/contrib/parse_tree.hpp>
|
||||
#include <locale_io.h>
|
||||
|
||||
|
||||
namespace NETLIST_EXPORTER_SPICE_PARSER
|
||||
|
@ -74,8 +77,6 @@ bool NETLIST_EXPORTER_SPICE::WriteNetlist( const wxString& aOutFileName, unsigne
|
|||
|
||||
bool NETLIST_EXPORTER_SPICE::DoWriteNetlist( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions )
|
||||
{
|
||||
LOCALE_IO dummy;
|
||||
|
||||
// Cleanup list to avoid duplicate if the netlist exporter is run more than once.
|
||||
m_rawIncludes.clear();
|
||||
|
||||
|
@ -100,7 +101,7 @@ bool NETLIST_EXPORTER_SPICE::DoWriteNetlist( OUTPUTFORMATTER& aFormatter, unsign
|
|||
|
||||
void NETLIST_EXPORTER_SPICE::WriteHead( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions )
|
||||
{
|
||||
aFormatter.Print( 0, ".title %s\n", TO_UTF8( m_title ) );
|
||||
aFormatter.Print( 0, ".title %s\n", m_title.c_str() );
|
||||
}
|
||||
|
||||
|
||||
|
@ -112,7 +113,7 @@ void NETLIST_EXPORTER_SPICE::WriteTail( OUTPUTFORMATTER& aFormatter, unsigned aN
|
|||
|
||||
bool NETLIST_EXPORTER_SPICE::ReadSchematicAndLibraries( unsigned aNetlistOptions )
|
||||
{
|
||||
std::set<wxString> refNames; // Set of reference names to check for duplication.
|
||||
std::set<std::string> refNames; // Set of reference names to check for duplication.
|
||||
int ncCounter = 1;
|
||||
|
||||
ReadDirectives( aNetlistOptions );
|
||||
|
@ -156,15 +157,15 @@ bool NETLIST_EXPORTER_SPICE::ReadSchematicAndLibraries( unsigned aNetlistOptions
|
|||
}
|
||||
|
||||
|
||||
void NETLIST_EXPORTER_SPICE::ReplaceForbiddenChars( wxString& aNetName )
|
||||
void NETLIST_EXPORTER_SPICE::ReplaceForbiddenChars( std::string& aNetName )
|
||||
{
|
||||
aNetName.Replace( "(", "_" );
|
||||
aNetName.Replace( ")", "_" );
|
||||
aNetName.Replace( " ", "_" );
|
||||
boost::replace_all( aNetName, "(", "_" );
|
||||
boost::replace_all( aNetName, ")", "_" );
|
||||
boost::replace_all( aNetName, " ", "_" );
|
||||
}
|
||||
|
||||
|
||||
wxString NETLIST_EXPORTER_SPICE::GetItemName( const wxString& aRefName ) const
|
||||
std::string NETLIST_EXPORTER_SPICE::GetItemName( const std::string& aRefName ) const
|
||||
{
|
||||
const std::list<ITEM>& spiceItems = GetItems();
|
||||
|
||||
|
@ -223,7 +224,7 @@ void NETLIST_EXPORTER_SPICE::ReadDirectives( unsigned aNetlistOptions )
|
|||
}
|
||||
else if( node->is_type<NETLIST_EXPORTER_SPICE_PARSER::dotInclude>() )
|
||||
{
|
||||
wxString path = node->children.at( 0 )->string();
|
||||
std::string path = node->children.at( 0 )->string();
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -247,19 +248,19 @@ void NETLIST_EXPORTER_SPICE::ReadDirectives( unsigned aNetlistOptions )
|
|||
void NETLIST_EXPORTER_SPICE::readLibraryField( SCH_SYMBOL& aSymbol, ITEM& aItem )
|
||||
{
|
||||
SCH_FIELD* field = aSymbol.FindField( SIM_LIBRARY::LIBRARY_FIELD );
|
||||
wxString path;
|
||||
std::string path;
|
||||
|
||||
if( field )
|
||||
path = field->GetShownText();
|
||||
path = std::string( field->GetShownText().ToUTF8() );
|
||||
|
||||
if( path.IsEmpty() )
|
||||
if( path == "" )
|
||||
return;
|
||||
|
||||
wxString absolutePath = m_schematic->Prj().AbsolutePath( path );
|
||||
|
||||
try
|
||||
{
|
||||
m_libraries.try_emplace( path, SIM_LIBRARY::Create( absolutePath ) );
|
||||
m_libraries.try_emplace( path, SIM_LIBRARY::Create( std::string( absolutePath.ToUTF8() ) ) );
|
||||
}
|
||||
catch( const IO_ERROR& e )
|
||||
{
|
||||
|
@ -281,7 +282,7 @@ void NETLIST_EXPORTER_SPICE::readNameField( SCH_SYMBOL& aSymbol, ITEM& aItem )
|
|||
if( !field )
|
||||
return;
|
||||
|
||||
wxString modelName = field->GetShownText();
|
||||
std::string modelName = std::string( field->GetShownText().ToUTF8() );
|
||||
const SIM_LIBRARY& library = *m_libraries.at( aItem.libraryPath );
|
||||
const SIM_MODEL* baseModel = library.FindModel( modelName );
|
||||
|
||||
|
@ -312,7 +313,7 @@ void NETLIST_EXPORTER_SPICE::readNameField( SCH_SYMBOL& aSymbol, ITEM& aItem )
|
|||
|
||||
bool NETLIST_EXPORTER_SPICE::readRefName( SCH_SHEET_PATH& aSheet, SCH_SYMBOL& aSymbol,
|
||||
ITEM& aItem,
|
||||
std::set<wxString>& aRefNames )
|
||||
std::set<std::string>& aRefNames )
|
||||
{
|
||||
aItem.refName = aSymbol.GetRef( &aSheet );
|
||||
|
||||
|
@ -351,7 +352,7 @@ bool NETLIST_EXPORTER_SPICE::readModel( SCH_SYMBOL& aSymbol, ITEM& aItem )
|
|||
if( auto model = dynamic_cast<const SIM_MODEL_RAW_SPICE*>( aItem.model.get() ) )
|
||||
{
|
||||
unsigned libParamIndex = static_cast<unsigned>( SIM_MODEL_RAW_SPICE::SPICE_PARAM::LIB );
|
||||
wxString path = model->GetParam( libParamIndex ).value->ToString();
|
||||
std::string path = model->GetParam( libParamIndex ).value->ToString();
|
||||
|
||||
if( path != "" )
|
||||
m_rawIncludes.insert( path );
|
||||
|
@ -364,7 +365,7 @@ bool NETLIST_EXPORTER_SPICE::readModel( SCH_SYMBOL& aSymbol, ITEM& aItem )
|
|||
void NETLIST_EXPORTER_SPICE::readPinNumbers( SCH_SYMBOL& aSymbol, ITEM& aItem )
|
||||
{
|
||||
for( const PIN_INFO& pin : m_sortedSymbolPinList )
|
||||
aItem.pinNumbers.push_back( pin.num );
|
||||
aItem.pinNumbers.emplace_back( std::string( pin.num.ToUTF8() ) );
|
||||
}
|
||||
|
||||
|
||||
|
@ -373,7 +374,8 @@ void NETLIST_EXPORTER_SPICE::readPinNetNames( SCH_SYMBOL& aSymbol, ITEM& aItem,
|
|||
{
|
||||
for( const PIN_INFO& pinInfo : m_sortedSymbolPinList )
|
||||
{
|
||||
wxString netName = GenerateItemPinNetName( pinInfo.netName, aNcCounter );
|
||||
std::string netName = GenerateItemPinNetName( std::string( pinInfo.netName.ToUTF8() ),
|
||||
aNcCounter );
|
||||
|
||||
aItem.pinNetNames.push_back( netName );
|
||||
m_nets.insert( netName );
|
||||
|
@ -382,7 +384,7 @@ void NETLIST_EXPORTER_SPICE::readPinNetNames( SCH_SYMBOL& aSymbol, ITEM& aItem,
|
|||
|
||||
|
||||
void NETLIST_EXPORTER_SPICE::writeInclude( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions,
|
||||
const wxString& aPath )
|
||||
const std::string& aPath )
|
||||
{
|
||||
// First, expand env vars, if any.
|
||||
wxString expandedPath = ExpandEnvVarSubstitutions( aPath, &m_schematic->Prj() );
|
||||
|
@ -397,8 +399,8 @@ void NETLIST_EXPORTER_SPICE::writeInclude( OUTPUTFORMATTER& aFormatter, unsigned
|
|||
if( fullPath.IsEmpty() )
|
||||
{
|
||||
DisplayErrorMessage( nullptr,
|
||||
wxString::Format( _( "Could not find library file '%s'" ),
|
||||
expandedPath ) );
|
||||
wxString::Format( _( "Could not find library file '%s'" ),
|
||||
expandedPath ) );
|
||||
fullPath = expandedPath;
|
||||
}
|
||||
}
|
||||
|
@ -414,7 +416,7 @@ void NETLIST_EXPORTER_SPICE::writeIncludes( OUTPUTFORMATTER& aFormatter, unsigne
|
|||
for( auto&& [path, library] : m_libraries )
|
||||
writeInclude( aFormatter, aNetlistOptions, path );
|
||||
|
||||
for( const wxString& path : m_rawIncludes )
|
||||
for( const std::string& path : m_rawIncludes )
|
||||
writeInclude( aFormatter, aNetlistOptions, path );
|
||||
}
|
||||
|
||||
|
@ -426,7 +428,8 @@ void NETLIST_EXPORTER_SPICE::writeModels( OUTPUTFORMATTER& aFormatter )
|
|||
if( !item.model->IsEnabled() )
|
||||
continue;
|
||||
|
||||
aFormatter.Print( 0, "%s", TO_UTF8( item.model->SpiceGenerator().ModelLine( item.modelName ) ) );
|
||||
aFormatter.Print( 0, "%s",
|
||||
item.model->SpiceGenerator().ModelLine( item.modelName ).c_str() );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -439,10 +442,10 @@ void NETLIST_EXPORTER_SPICE::writeItems( OUTPUTFORMATTER& aFormatter )
|
|||
continue;
|
||||
|
||||
aFormatter.Print( 0, "%s",
|
||||
TO_UTF8( item.model->SpiceGenerator().ItemLine( item.refName,
|
||||
item.modelName,
|
||||
item.pinNumbers,
|
||||
item.pinNetNames ) ) );
|
||||
item.model->SpiceGenerator().ItemLine( item.refName,
|
||||
item.modelName,
|
||||
item.pinNumbers,
|
||||
item.pinNetNames ).c_str() );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -456,21 +459,21 @@ void NETLIST_EXPORTER_SPICE::WriteDirectives( OUTPUTFORMATTER& aFormatter,
|
|||
if( aNetlistOptions & OPTION_SAVE_ALL_CURRENTS )
|
||||
aFormatter.Print( 0, ".probe alli\n" );
|
||||
|
||||
for( const wxString& directive : m_directives )
|
||||
aFormatter.Print( 0, "%s\n", TO_UTF8( directive ) );
|
||||
for( const std::string& directive : m_directives )
|
||||
aFormatter.Print( 0, "%s\n", directive.c_str() );
|
||||
}
|
||||
|
||||
|
||||
wxString NETLIST_EXPORTER_SPICE::GenerateItemPinNetName( const wxString& aNetName,
|
||||
int& aNcCounter ) const
|
||||
std::string NETLIST_EXPORTER_SPICE::GenerateItemPinNetName( const std::string& aNetName,
|
||||
int& aNcCounter ) const
|
||||
{
|
||||
wxString netName = aNetName;
|
||||
std::string netName = aNetName;
|
||||
|
||||
ReplaceForbiddenChars( netName );
|
||||
netName = UnescapeString( netName );
|
||||
netName = std::string( UnescapeString( netName ).ToUTF8() );
|
||||
|
||||
if( netName == "" )
|
||||
netName = wxString::Format( wxT( "NC-%u" ), aNcCounter++ );
|
||||
netName = fmt::format( "NC-{}", aNcCounter++ );
|
||||
|
||||
return netName;
|
||||
}
|
||||
|
|
|
@ -49,12 +49,12 @@ public:
|
|||
|
||||
struct ITEM
|
||||
{
|
||||
wxString refName;
|
||||
wxString libraryPath;
|
||||
std::vector<wxString> pinNumbers;
|
||||
std::vector<wxString> pinNetNames;
|
||||
std::string refName;
|
||||
std::string libraryPath;
|
||||
std::vector<std::string> pinNumbers;
|
||||
std::vector<std::string> pinNetNames;
|
||||
std::unique_ptr<const SIM_MODEL> model;
|
||||
wxString modelName;
|
||||
std::string modelName;
|
||||
};
|
||||
|
||||
NETLIST_EXPORTER_SPICE( SCHEMATIC_IFACE* aSchematic ) : NETLIST_EXPORTER_BASE( aSchematic ) {}
|
||||
|
@ -90,12 +90,12 @@ public:
|
|||
/**
|
||||
* Replace illegal spice net name characters with underscores.
|
||||
*/
|
||||
static void ReplaceForbiddenChars( wxString& aNetName );
|
||||
static void ReplaceForbiddenChars( std::string& aNetName );
|
||||
|
||||
/**
|
||||
* Return the list of nets.
|
||||
*/
|
||||
std::set<wxString> GetNets() const { return m_nets; }
|
||||
std::set<std::string> GetNets() const { return m_nets; }
|
||||
|
||||
|
||||
/**
|
||||
|
@ -107,20 +107,20 @@ public:
|
|||
* to the assigned device model type or it is the reference prefixed with a character defining
|
||||
* the device model type.
|
||||
*/
|
||||
wxString GetItemName( const wxString& aRefName ) const;
|
||||
std::string GetItemName( const std::string& aRefName ) const;
|
||||
|
||||
/**
|
||||
* Return the list of items representing schematic components in the Spice world.
|
||||
*/
|
||||
const std::list<ITEM>& GetItems() const { return m_items; }
|
||||
|
||||
const std::vector<wxString>& GetDirectives() { return m_directives; }
|
||||
const std::vector<std::string>& GetDirectives() { return m_directives; }
|
||||
|
||||
protected:
|
||||
void ReadDirectives( unsigned aNetlistOptions = 0 );
|
||||
virtual void WriteDirectives( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions ) const;
|
||||
|
||||
virtual wxString GenerateItemPinNetName( const wxString& aNetName, int& aNcCounter ) const;
|
||||
virtual std::string GenerateItemPinNetName( const std::string& aNetName, int& aNcCounter ) const;
|
||||
|
||||
/**
|
||||
* Return the paths of exported sheets (either all or the current one).
|
||||
|
@ -132,23 +132,23 @@ private:
|
|||
void readNameField( SCH_SYMBOL& aSymbol, ITEM& aItem );
|
||||
void readEnabledField( SCH_SYMBOL& aSymbol, ITEM& aItem );
|
||||
bool readRefName( SCH_SHEET_PATH& aSheet, SCH_SYMBOL& aSymbol, ITEM& aItem,
|
||||
std::set<wxString>& aRefNames );
|
||||
std::set<std::string>& aRefNames );
|
||||
bool readModel( SCH_SYMBOL& aSymbol, ITEM& aItem );
|
||||
void readPinNumbers( SCH_SYMBOL& aSymbol, ITEM& aItem );
|
||||
void readPinNetNames( SCH_SYMBOL& aSymbol, ITEM& aItem, int& aNcCounter );
|
||||
|
||||
void writeInclude( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions,
|
||||
const wxString& aPath );
|
||||
const std::string& aPath );
|
||||
|
||||
void writeIncludes( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions );
|
||||
void writeModels( OUTPUTFORMATTER& aFormatter );
|
||||
void writeItems( OUTPUTFORMATTER& aFormatter );
|
||||
|
||||
wxString m_title; ///< Spice simulation title found in the schematic sheet
|
||||
std::vector<wxString> m_directives; ///< Spice directives found in the schematic sheet
|
||||
std::map<wxString, std::unique_ptr<SIM_LIBRARY>> m_libraries; ///< Spice libraries
|
||||
std::set<wxString> m_rawIncludes; ///< include directives found in symbols
|
||||
std::set<wxString> m_nets;
|
||||
std::string m_title; ///< Spice simulation title found in the schematic sheet
|
||||
std::vector<std::string> m_directives; ///< Spice directives found in the schematic sheet
|
||||
std::map<std::string, std::unique_ptr<SIM_LIBRARY>> m_libraries; ///< Spice libraries
|
||||
std::set<std::string> m_rawIncludes; ///< include directives found in symbols
|
||||
std::set<std::string> m_nets;
|
||||
std::list<ITEM> m_items; ///< Items representing schematic symbols in Spice world
|
||||
};
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ void NETLIST_EXPORTER_SPICE_MODEL::WriteHead( OUTPUTFORMATTER& aFormatter,
|
|||
|
||||
for( auto const& [key, port] : m_ports )
|
||||
{
|
||||
wxString portDir;
|
||||
std::string portDir;
|
||||
|
||||
switch( port.dir )
|
||||
{
|
||||
|
@ -49,7 +49,7 @@ void NETLIST_EXPORTER_SPICE_MODEL::WriteHead( OUTPUTFORMATTER& aFormatter,
|
|||
break;
|
||||
}
|
||||
|
||||
aFormatter.Print( 0, "+ %s ; %s\n", TO_UTF8( port.name ), TO_UTF8( portDir ) );
|
||||
aFormatter.Print( 0, "+ %s ; %s\n", port.name.c_str(), portDir.c_str() );
|
||||
}
|
||||
|
||||
aFormatter.Print( 0, "\n\n" );
|
||||
|
@ -71,10 +71,10 @@ bool NETLIST_EXPORTER_SPICE_MODEL::ReadSchematicAndLibraries( unsigned aNetlistO
|
|||
}
|
||||
|
||||
|
||||
wxString NETLIST_EXPORTER_SPICE_MODEL::GenerateItemPinNetName( const wxString& aNetName,
|
||||
int& aNcCounter ) const
|
||||
std::string NETLIST_EXPORTER_SPICE_MODEL::GenerateItemPinNetName( const std::string& aNetName,
|
||||
int& aNcCounter ) const
|
||||
{
|
||||
wxString netName = aNetName;
|
||||
std::string netName = aNetName;
|
||||
|
||||
if( m_ports.count( netName ) )
|
||||
netName = m_ports.at( netName ).name;
|
||||
|
@ -92,10 +92,9 @@ void NETLIST_EXPORTER_SPICE_MODEL::readPorts( unsigned aNetlistOptions )
|
|||
auto label = static_cast<SCH_LABEL_BASE*>( item );
|
||||
|
||||
if( SCH_CONNECTION* conn = label->Connection( &sheet ) )
|
||||
{
|
||||
m_ports.insert( { conn->Name(), PORT_INFO{ label->GetText(),
|
||||
label->GetShape() } } );
|
||||
}
|
||||
m_ports.insert( { std::string( conn->Name().ToUTF8() ),
|
||||
PORT_INFO{ std::string( label->GetText().ToUTF8() ),
|
||||
label->GetShape() } } );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,18 +40,18 @@ public:
|
|||
bool ReadSchematicAndLibraries( unsigned aNetlistOptions ) override;
|
||||
|
||||
protected:
|
||||
wxString GenerateItemPinNetName( const wxString& aNetName, int& aNcCounter ) const override;
|
||||
std::string GenerateItemPinNetName( const std::string& aNetName, int& aNcCounter ) const override;
|
||||
|
||||
private:
|
||||
struct PORT_INFO
|
||||
{
|
||||
wxString name;
|
||||
std::string name;
|
||||
LABEL_FLAG_SHAPE dir;
|
||||
};
|
||||
|
||||
void readPorts( unsigned aNetlistOptions );
|
||||
|
||||
std::map<wxString, PORT_INFO> m_ports;
|
||||
std::map<std::string, PORT_INFO> m_ports;
|
||||
};
|
||||
|
||||
#endif // NETLIST_EXPORTER_SPICE_MODEL_H
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#include <sim/sim_library_spice.h>
|
||||
|
||||
|
||||
std::unique_ptr<SIM_LIBRARY> SIM_LIBRARY::Create( wxString aFilePath )
|
||||
std::unique_ptr<SIM_LIBRARY> SIM_LIBRARY::Create( std::string aFilePath )
|
||||
{
|
||||
std::unique_ptr<SIM_LIBRARY> library = std::make_unique<SIM_LIBRARY_SPICE>();
|
||||
|
||||
|
@ -35,17 +35,17 @@ std::unique_ptr<SIM_LIBRARY> SIM_LIBRARY::Create( wxString aFilePath )
|
|||
}
|
||||
|
||||
|
||||
void SIM_LIBRARY::ReadFile( const wxString& aFilePath )
|
||||
void SIM_LIBRARY::ReadFile( const std::string& aFilePath )
|
||||
{
|
||||
m_filePath = aFilePath;
|
||||
}
|
||||
|
||||
|
||||
SIM_MODEL* SIM_LIBRARY::FindModel( const wxString& aModelName ) const
|
||||
SIM_MODEL* SIM_LIBRARY::FindModel( const std::string& aModelName ) const
|
||||
{
|
||||
for( unsigned i = 0; i < GetModelNames().size(); ++i )
|
||||
{
|
||||
wxString curModelName = GetModelNames().at( i );
|
||||
std::string curModelName = GetModelNames().at( i );
|
||||
|
||||
if( curModelName == aModelName )
|
||||
return m_models.at( i ).get();
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
* @param aFilePath Path to the file.
|
||||
* @return The library loaded in a newly constructed object.
|
||||
*/
|
||||
static std::unique_ptr<SIM_LIBRARY> Create( wxString aFilePath );
|
||||
static std::unique_ptr<SIM_LIBRARY> Create( std::string aFilePath );
|
||||
|
||||
/**
|
||||
* Read library from a source file. Must be in the format appropriate to the subclass, e.g.
|
||||
|
@ -53,7 +53,7 @@ public:
|
|||
* @param aFilePath Path to the file.
|
||||
* @throw IO_ERROR on read or parsing error.
|
||||
*/
|
||||
virtual void ReadFile( const wxString& aFilePath ) = 0;
|
||||
virtual void ReadFile( const std::string& aFilePath ) = 0;
|
||||
|
||||
/**
|
||||
* Write library to a source file (e.g. in Spice format).
|
||||
|
@ -61,22 +61,22 @@ public:
|
|||
* @param aFilePath Path to the file.
|
||||
* @throw IO_ERROR on write error.
|
||||
*/
|
||||
virtual void WriteFile( const wxString& aFilePath ) = 0;
|
||||
virtual void WriteFile( const std::string& aFilePath ) = 0;
|
||||
|
||||
SIM_MODEL* FindModel( const wxString& aModelName ) const;
|
||||
SIM_MODEL* FindModel( const std::string& aModelName ) const;
|
||||
|
||||
std::vector<std::reference_wrapper<SIM_MODEL>> GetModels() const;
|
||||
const std::vector<wxString>& GetModelNames() const { return m_modelNames; }
|
||||
const std::vector<std::string>& GetModelNames() const { return m_modelNames; }
|
||||
|
||||
wxString GetFilePath() const { return m_filePath; }
|
||||
wxString GetError() const { return m_error; }
|
||||
std::string GetFilePath() const { return m_filePath; }
|
||||
std::string GetError() const { return m_error; }
|
||||
|
||||
protected:
|
||||
std::vector<std::unique_ptr<SIM_MODEL>> m_models;
|
||||
std::vector<wxString> m_modelNames;
|
||||
std::vector<std::string> m_modelNames;
|
||||
|
||||
wxString m_filePath;
|
||||
wxString m_error;
|
||||
std::string m_filePath;
|
||||
std::string m_error;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -33,14 +33,14 @@ SIM_LIBRARY_SPICE::SIM_LIBRARY_SPICE() :
|
|||
}
|
||||
|
||||
|
||||
void SIM_LIBRARY_SPICE::ReadFile( const wxString& aFilePath )
|
||||
void SIM_LIBRARY_SPICE::ReadFile( const std::string& aFilePath )
|
||||
{
|
||||
SIM_LIBRARY::ReadFile( aFilePath );
|
||||
m_spiceLibraryParser->ReadFile( aFilePath );
|
||||
}
|
||||
|
||||
|
||||
void SIM_LIBRARY_SPICE::WriteFile( const wxString& aFilePath )
|
||||
void SIM_LIBRARY_SPICE::WriteFile( const std::string& aFilePath )
|
||||
{
|
||||
// Not implemented yet.
|
||||
}
|
||||
|
|
|
@ -37,10 +37,10 @@ public:
|
|||
SIM_LIBRARY_SPICE();
|
||||
|
||||
// @copydoc SIM_LIBRARY::ReadFile()
|
||||
void ReadFile( const wxString& aFilePath ) override;
|
||||
void ReadFile( const std::string& aFilePath ) override;
|
||||
|
||||
// @copydoc SIM_LIBRARY::WriteFile()
|
||||
void WriteFile( const wxString& aFilePath ) override;
|
||||
void WriteFile( const std::string& aFilePath ) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<SPICE_LIBRARY_PARSER> m_spiceLibraryParser;
|
||||
|
|
|
@ -34,9 +34,13 @@
|
|||
#include <sim/sim_model_tline.h>
|
||||
#include <sim/sim_model_xspice.h>
|
||||
|
||||
#include <locale_io.h>
|
||||
#include <lib_symbol.h>
|
||||
#include <confirm.h>
|
||||
|
||||
#include <boost/algorithm/string/case_conv.hpp>
|
||||
#include <boost/algorithm/string/trim.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <fmt/core.h>
|
||||
#include <pegtl.hpp>
|
||||
#include <pegtl/contrib/parse_tree.hpp>
|
||||
|
||||
|
@ -373,8 +377,8 @@ template TYPE SIM_MODEL::ReadTypeFromFields( const std::vector<LIB_FIELD>& aFiel
|
|||
template <typename T>
|
||||
TYPE SIM_MODEL::ReadTypeFromFields( const std::vector<T>& aFields )
|
||||
{
|
||||
wxString deviceTypeFieldValue = GetFieldValue( &aFields, DEVICE_TYPE_FIELD );
|
||||
wxString typeFieldValue = GetFieldValue( &aFields, TYPE_FIELD );
|
||||
std::string deviceTypeFieldValue = GetFieldValue( &aFields, DEVICE_TYPE_FIELD );
|
||||
std::string typeFieldValue = GetFieldValue( &aFields, TYPE_FIELD );
|
||||
|
||||
if( deviceTypeFieldValue != "" )
|
||||
{
|
||||
|
@ -404,9 +408,9 @@ TYPE SIM_MODEL::ReadTypeFromFields( const std::vector<T>& aFields )
|
|||
}
|
||||
|
||||
|
||||
TYPE SIM_MODEL::InferTypeFromRefAndValue( const wxString& aRef, const wxString& aValue )
|
||||
TYPE SIM_MODEL::InferTypeFromRefAndValue( const std::string& aRef, const std::string& aValue )
|
||||
{
|
||||
static std::map<wxString, TYPE> refPrefixToType = {
|
||||
static std::map<std::string, TYPE> refPrefixToType = {
|
||||
{ "R", TYPE::R },
|
||||
{ "C", TYPE::C },
|
||||
{ "L", TYPE::L },
|
||||
|
@ -443,7 +447,7 @@ TYPE SIM_MODEL::InferTypeFromRefAndValue( const wxString& aRef, const wxString&
|
|||
|
||||
for( auto&& [curPrefix, curType] : refPrefixToType )
|
||||
{
|
||||
if( aRef.StartsWith( curPrefix ) )
|
||||
if( boost::starts_with( aRef, curPrefix ) )
|
||||
{
|
||||
type = curType;
|
||||
break;
|
||||
|
@ -452,46 +456,46 @@ TYPE SIM_MODEL::InferTypeFromRefAndValue( const wxString& aRef, const wxString&
|
|||
|
||||
// We handle "V" and "I" later because it collides and std::map is unordered.
|
||||
|
||||
if( type == TYPE::NONE && aRef.StartsWith( "V" ) )
|
||||
if( type == TYPE::NONE && boost::starts_with( aRef, "V" ) )
|
||||
type = TYPE::V;
|
||||
|
||||
if( type == TYPE::NONE && aRef.StartsWith( "I" ) )
|
||||
if( type == TYPE::NONE && boost::starts_with( aRef, "I" ) )
|
||||
type = TYPE::I;
|
||||
|
||||
wxString value = aValue;
|
||||
std::string value = aValue;
|
||||
|
||||
// Some types have to be inferred from Value field.
|
||||
switch( type )
|
||||
{
|
||||
case TYPE::R:
|
||||
if( value.Trim( false ).StartsWith( "=" ) )
|
||||
if( boost::starts_with( boost::trim_left_copy( value ), "=" ) )
|
||||
type = TYPE::R_BEHAVIORAL;
|
||||
break;
|
||||
|
||||
case TYPE::C:
|
||||
if( value.Trim( false ).StartsWith( "=" ) )
|
||||
if( boost::starts_with( boost::trim_left_copy( value ), "=" ) )
|
||||
type = TYPE::C_BEHAVIORAL;
|
||||
break;
|
||||
|
||||
case TYPE::L:
|
||||
if( value.Trim( false ).StartsWith( "=" ) )
|
||||
if( boost::starts_with( boost::trim_left_copy( value ), "=" ) )
|
||||
type = TYPE::L_BEHAVIORAL;
|
||||
break;
|
||||
|
||||
case TYPE::V:
|
||||
if( value.Trim( false ).StartsWith( "=" ) )
|
||||
if( boost::starts_with( boost::trim_left_copy( value ), "=" ) )
|
||||
type = TYPE::V_BEHAVIORAL;
|
||||
break;
|
||||
|
||||
case TYPE::I:
|
||||
if( value.Trim( false ).StartsWith( "=" ) )
|
||||
if( boost::starts_with( boost::trim_left_copy( value ), "=" ) )
|
||||
type = TYPE::I_BEHAVIORAL;
|
||||
break;
|
||||
|
||||
case TYPE::TLINE_Z0:
|
||||
try
|
||||
{
|
||||
tao::pegtl::string_input<> in( aValue.ToUTF8(), "Value" );
|
||||
tao::pegtl::string_input<> in( aValue, "Value" );
|
||||
auto root = tao::pegtl::parse_tree::parse<
|
||||
SIM_MODEL_PARSER::fieldParamValuePairsGrammar,
|
||||
SIM_MODEL_PARSER::fieldParamValuePairsSelector>
|
||||
|
@ -655,12 +659,12 @@ template std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( unsigned aSymbolPinCount,
|
|||
|
||||
|
||||
template <typename T>
|
||||
wxString SIM_MODEL::GetFieldValue( const std::vector<T>* aFields, const wxString& aFieldName )
|
||||
std::string SIM_MODEL::GetFieldValue( const std::vector<T>* aFields, const std::string& aFieldName )
|
||||
{
|
||||
static_assert( std::is_same<T, SCH_FIELD>::value || std::is_same<T, LIB_FIELD>::value );
|
||||
|
||||
if( !aFields )
|
||||
return wxEmptyString; // Should not happen, T=void specialization will be called instead.
|
||||
return ""; // Should not happen, T=void specialization will be called instead.
|
||||
|
||||
auto fieldIt = std::find_if( aFields->begin(), aFields->end(),
|
||||
[aFieldName]( const T& field )
|
||||
|
@ -669,23 +673,23 @@ wxString SIM_MODEL::GetFieldValue( const std::vector<T>* aFields, const wxString
|
|||
} );
|
||||
|
||||
if( fieldIt != aFields->end() )
|
||||
return fieldIt->GetText();
|
||||
return std::string( fieldIt->GetText().ToUTF8() );
|
||||
|
||||
return wxEmptyString;
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
// This specialization is used when no fields are passed.
|
||||
template <>
|
||||
wxString SIM_MODEL::GetFieldValue( const std::vector<void>* aFields, const wxString& aFieldName )
|
||||
std::string SIM_MODEL::GetFieldValue( const std::vector<void>* aFields, const std::string& aFieldName )
|
||||
{
|
||||
return wxEmptyString;
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
void SIM_MODEL::SetFieldValue( std::vector<T>& aFields, const wxString& aFieldName,
|
||||
const wxString& aValue )
|
||||
void SIM_MODEL::SetFieldValue( std::vector<T>& aFields, const std::string& aFieldName,
|
||||
const std::string& aValue )
|
||||
{
|
||||
static_assert( std::is_same<T, SCH_FIELD>::value || std::is_same<T, LIB_FIELD>::value );
|
||||
|
||||
|
@ -697,7 +701,7 @@ void SIM_MODEL::SetFieldValue( std::vector<T>& aFields, const wxString& aFieldNa
|
|||
|
||||
if( fieldIt != aFields.end() )
|
||||
{
|
||||
if( aValue.IsEmpty() )
|
||||
if( aValue == "" )
|
||||
aFields.erase( fieldIt );
|
||||
else
|
||||
fieldIt->SetText( aValue );
|
||||
|
@ -705,7 +709,7 @@ void SIM_MODEL::SetFieldValue( std::vector<T>& aFields, const wxString& aFieldNa
|
|||
return;
|
||||
}
|
||||
|
||||
if( aValue.IsEmpty() )
|
||||
if( aValue == "" )
|
||||
return;
|
||||
|
||||
if constexpr( std::is_same<T, SCH_FIELD>::value )
|
||||
|
@ -731,7 +735,7 @@ void SIM_MODEL::AddPin( const PIN& aPin )
|
|||
}
|
||||
|
||||
|
||||
int SIM_MODEL::FindModelPinIndex( const wxString& aSymbolPinNumber )
|
||||
int SIM_MODEL::FindModelPinIndex( const std::string& aSymbolPinNumber )
|
||||
{
|
||||
for( int modelPinIndex = 0; modelPinIndex < GetPinCount(); ++modelPinIndex )
|
||||
{
|
||||
|
@ -769,14 +773,14 @@ const SIM_MODEL::PARAM& SIM_MODEL::GetParam( unsigned aParamIndex ) const
|
|||
}
|
||||
|
||||
|
||||
const SIM_MODEL::PARAM* SIM_MODEL::FindParam( const wxString& aParamName ) const
|
||||
const SIM_MODEL::PARAM* SIM_MODEL::FindParam( const std::string& aParamName ) const
|
||||
{
|
||||
std::vector<std::reference_wrapper<const PARAM>> params = GetParams();
|
||||
|
||||
auto it = std::find_if( params.begin(), params.end(),
|
||||
[aParamName]( const PARAM& param )
|
||||
{
|
||||
return param.info.name == aParamName.Lower();
|
||||
return param.info.name == boost::to_lower_copy( aParamName );
|
||||
} );
|
||||
|
||||
if( it == params.end() )
|
||||
|
@ -812,14 +816,14 @@ const SIM_MODEL::PARAM& SIM_MODEL::GetBaseParam( unsigned aParamIndex ) const
|
|||
}
|
||||
|
||||
|
||||
bool SIM_MODEL::SetParamValue( unsigned aParamIndex, const wxString& aValue,
|
||||
bool SIM_MODEL::SetParamValue( unsigned aParamIndex, const std::string& aValue,
|
||||
SIM_VALUE_GRAMMAR::NOTATION aNotation )
|
||||
{
|
||||
return m_params.at( aParamIndex ).value->FromString( aValue.ToStdString(), aNotation );
|
||||
return m_params.at( aParamIndex ).value->FromString( aValue, aNotation );
|
||||
}
|
||||
|
||||
|
||||
bool SIM_MODEL::SetParamValue( const wxString& aParamName, const wxString& aValue,
|
||||
bool SIM_MODEL::SetParamValue( const std::string& aParamName, const std::string& aValue,
|
||||
SIM_VALUE_GRAMMAR::NOTATION aNotation )
|
||||
{
|
||||
std::vector<std::reference_wrapper<const PARAM>> params = GetParams();
|
||||
|
@ -827,7 +831,7 @@ bool SIM_MODEL::SetParamValue( const wxString& aParamName, const wxString& aValu
|
|||
auto it = std::find_if( params.begin(), params.end(),
|
||||
[aParamName]( const PARAM& param )
|
||||
{
|
||||
return param.info.name == aParamName.Lower();
|
||||
return param.info.name == boost::to_lower_copy( aParamName );
|
||||
} );
|
||||
|
||||
if( it == params.end() )
|
||||
|
@ -967,13 +971,13 @@ void SIM_MODEL::CreatePins( unsigned aSymbolPinCount )
|
|||
// Excess model pins are set as Not Connected.
|
||||
// Note that intentionally nothing is added if `getPinNames()` returns an empty vector.
|
||||
|
||||
// SIM_MODEL pins must be ordered by symbol pin numbers -- this is assumed by code that
|
||||
// SIM_MODEL pins must be ordered by symbol pin numbers -- this is assumed by the code that
|
||||
// accesses them.
|
||||
|
||||
for( unsigned modelPinIndex = 0; modelPinIndex < getPinNames().size(); ++modelPinIndex )
|
||||
{
|
||||
if( modelPinIndex < aSymbolPinCount )
|
||||
AddPin( { getPinNames().at( modelPinIndex ), wxString::FromCDouble( modelPinIndex + 1 ) } );
|
||||
AddPin( { getPinNames().at( modelPinIndex ), fmt::format( "{}", modelPinIndex + 1 ) } );
|
||||
else
|
||||
AddPin( { getPinNames().at( modelPinIndex ), "" } );
|
||||
}
|
||||
|
@ -981,12 +985,12 @@ void SIM_MODEL::CreatePins( unsigned aSymbolPinCount )
|
|||
|
||||
|
||||
template void SIM_MODEL::WriteInferredDataFields( std::vector<SCH_FIELD>& aFields,
|
||||
const wxString& aValue ) const;
|
||||
const std::string& aValue ) const;
|
||||
template void SIM_MODEL::WriteInferredDataFields( std::vector<LIB_FIELD>& aFields,
|
||||
const wxString& aValue ) const;
|
||||
const std::string& aValue ) const;
|
||||
|
||||
template <typename T>
|
||||
void SIM_MODEL::WriteInferredDataFields( std::vector<T>& aFields, const wxString& aValue ) const
|
||||
void SIM_MODEL::WriteInferredDataFields( std::vector<T>& aFields, const std::string& aValue ) const
|
||||
{
|
||||
if( GetPinCount() == 2
|
||||
&& GetPin( 0 ).symbolPinNumber == "1"
|
||||
|
@ -1003,33 +1007,33 @@ void SIM_MODEL::WriteInferredDataFields( std::vector<T>& aFields, const wxString
|
|||
}
|
||||
|
||||
|
||||
wxString SIM_MODEL::GenerateParamValuePair( const PARAM& aParam, bool& aIsFirst ) const
|
||||
std::string SIM_MODEL::GenerateParamValuePair( const PARAM& aParam, bool& aIsFirst ) const
|
||||
{
|
||||
wxString result;
|
||||
std::string result;
|
||||
|
||||
if( aIsFirst )
|
||||
aIsFirst = false;
|
||||
else
|
||||
result << " ";
|
||||
result.append( " " );
|
||||
|
||||
wxString name = aParam.info.name;
|
||||
std::string name = aParam.info.name;
|
||||
|
||||
// Because of collisions with instance parameters, we append some model parameters with "_".
|
||||
if( aParam.info.name.EndsWith( "_" ) )
|
||||
name = aParam.info.name.BeforeLast( '_' );
|
||||
if( boost::ends_with( aParam.info.name, "_" ) )
|
||||
name = aParam.info.name.substr( 0, aParam.info.name.length() - 1);
|
||||
|
||||
wxString value = aParam.value->ToString();
|
||||
if( value.Contains( " " ) )
|
||||
std::string value = aParam.value->ToString();
|
||||
if( value.find( " " ) != std::string::npos )
|
||||
value = "\"" + value + "\"";
|
||||
|
||||
result << aParam.info.name + "=" + value;
|
||||
result.append( fmt::format( "{}={}", aParam.info.name, value ) );
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
wxString SIM_MODEL::GenerateParamsField( const wxString& aPairSeparator ) const
|
||||
std::string SIM_MODEL::GenerateParamsField( const std::string& aPairSeparator ) const
|
||||
{
|
||||
wxString result;
|
||||
std::string result;
|
||||
bool isFirst = true;
|
||||
|
||||
for( const PARAM& param : m_params )
|
||||
|
@ -1037,18 +1041,16 @@ wxString SIM_MODEL::GenerateParamsField( const wxString& aPairSeparator ) const
|
|||
if( param.value->ToString() == "" )
|
||||
continue;
|
||||
|
||||
result << GenerateParamValuePair( param, isFirst );
|
||||
result.append( GenerateParamValuePair( param, isFirst ) );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void SIM_MODEL::ParseParamsField( const wxString& aParamsField )
|
||||
void SIM_MODEL::ParseParamsField( const std::string& aParamsField )
|
||||
{
|
||||
LOCALE_IO toggle;
|
||||
|
||||
tao::pegtl::string_input<> in( aParamsField.ToUTF8(), "Sim_Params" );
|
||||
tao::pegtl::string_input<> in( aParamsField, "Sim_Params" );
|
||||
std::unique_ptr<tao::pegtl::parse_tree::node> root;
|
||||
|
||||
try
|
||||
|
@ -1065,7 +1067,7 @@ void SIM_MODEL::ParseParamsField( const wxString& aParamsField )
|
|||
THROW_IO_ERROR( e.what() );
|
||||
}
|
||||
|
||||
wxString paramName;
|
||||
std::string paramName;
|
||||
|
||||
for( const auto& node : root->children )
|
||||
{
|
||||
|
@ -1083,12 +1085,10 @@ void SIM_MODEL::ParseParamsField( const wxString& aParamsField )
|
|||
}
|
||||
else if( node->is_type<SIM_MODEL_PARSER::quotedString>() )
|
||||
{
|
||||
wxASSERT( !paramName.IsEmpty() );
|
||||
|
||||
wxString str = node->string();
|
||||
std::string str = node->string();
|
||||
|
||||
// Unescape quotes.
|
||||
str.Replace( "\\\"", "\"" );
|
||||
boost::replace_all( str, "\\\"", "\"" );
|
||||
|
||||
SetParamValue( paramName, str, SIM_VALUE_GRAMMAR::NOTATION::SI );
|
||||
}
|
||||
|
@ -1100,14 +1100,14 @@ void SIM_MODEL::ParseParamsField( const wxString& aParamsField )
|
|||
}
|
||||
|
||||
|
||||
void SIM_MODEL::ParsePinsField( unsigned aSymbolPinCount, const wxString& aPinsField )
|
||||
void SIM_MODEL::ParsePinsField( unsigned aSymbolPinCount, const std::string& aPinsField )
|
||||
{
|
||||
CreatePins( aSymbolPinCount );
|
||||
|
||||
if( aPinsField == "" )
|
||||
return;
|
||||
|
||||
tao::pegtl::string_input<> in( aPinsField.ToUTF8(), PINS_FIELD );
|
||||
tao::pegtl::string_input<> in( aPinsField, PINS_FIELD );
|
||||
std::unique_ptr<tao::pegtl::parse_tree::node> root;
|
||||
|
||||
try
|
||||
|
@ -1138,12 +1138,12 @@ void SIM_MODEL::ParsePinsField( unsigned aSymbolPinCount, const wxString& aPinsF
|
|||
}
|
||||
|
||||
|
||||
void SIM_MODEL::ParseDisabledField( const wxString& aDisabledField )
|
||||
void SIM_MODEL::ParseDisabledField( const std::string& aDisabledField )
|
||||
{
|
||||
if( aDisabledField == "" )
|
||||
return;
|
||||
|
||||
char c = aDisabledField.Lower()[0];
|
||||
char c = boost::to_lower_copy( aDisabledField )[0];
|
||||
|
||||
if( c == 'y' || c == 't' || c == '1' )
|
||||
m_isEnabled = false;
|
||||
|
@ -1179,7 +1179,7 @@ void SIM_MODEL::InferredReadDataFields( unsigned aSymbolPinCount, const std::vec
|
|||
return;
|
||||
}
|
||||
|
||||
wxString valueField = GetFieldValue( aFields, VALUE_FIELD );
|
||||
std::string valueField = GetFieldValue( aFields, VALUE_FIELD );
|
||||
|
||||
if( aAllowParamValuePairs ) // The usual param-value pairs have precedence.
|
||||
{
|
||||
|
@ -1228,21 +1228,21 @@ void SIM_MODEL::doWriteFields( std::vector<T>& aFields ) const
|
|||
}
|
||||
|
||||
|
||||
wxString SIM_MODEL::generateDeviceTypeField() const
|
||||
std::string SIM_MODEL::generateDeviceTypeField() const
|
||||
{
|
||||
return DeviceTypeInfo( TypeInfo( m_type ).deviceType ).fieldValue;
|
||||
}
|
||||
|
||||
|
||||
wxString SIM_MODEL::generateTypeField() const
|
||||
std::string SIM_MODEL::generateTypeField() const
|
||||
{
|
||||
return TypeInfo( m_type ).fieldValue;
|
||||
}
|
||||
|
||||
|
||||
wxString SIM_MODEL::generatePinsField() const
|
||||
std::string SIM_MODEL::generatePinsField() const
|
||||
{
|
||||
wxString result = "";
|
||||
std::string result = "";
|
||||
bool isFirst = true;
|
||||
|
||||
for( const PIN& pin : GetPins() )
|
||||
|
@ -1250,29 +1250,29 @@ wxString SIM_MODEL::generatePinsField() const
|
|||
if( isFirst )
|
||||
isFirst = false;
|
||||
else
|
||||
result << " ";
|
||||
result.append( " " );
|
||||
|
||||
if( pin.symbolPinNumber == "" )
|
||||
result << "~";
|
||||
result.append( "~" );
|
||||
else
|
||||
result << pin.symbolPinNumber; // Note that it's numbered from 1.
|
||||
result.append( pin.symbolPinNumber ); // Note that it's numbered from 1.
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
wxString SIM_MODEL::generateDisabledField() const
|
||||
std::string SIM_MODEL::generateDisabledField() const
|
||||
{
|
||||
return m_isEnabled ? "" : "1";
|
||||
}
|
||||
|
||||
|
||||
wxString SIM_MODEL::parseFieldFloatValue( wxString aFieldFloatValue )
|
||||
std::string SIM_MODEL::parseFieldFloatValue( std::string aFieldFloatValue )
|
||||
{
|
||||
try
|
||||
{
|
||||
tao::pegtl::string_input<> in( aFieldFloatValue.ToUTF8(), "Value" );
|
||||
tao::pegtl::string_input<> in( aFieldFloatValue, "Value" );
|
||||
auto root = tao::pegtl::parse_tree::parse<
|
||||
SIM_MODEL_PARSER::fieldFloatValueGrammar,
|
||||
SIM_MODEL_PARSER::fieldFloatValueSelector>
|
||||
|
|
|
@ -146,8 +146,8 @@ public:
|
|||
|
||||
struct DEVICE_INFO
|
||||
{
|
||||
wxString fieldValue;
|
||||
wxString description;
|
||||
std::string fieldValue;
|
||||
std::string description;
|
||||
};
|
||||
|
||||
|
||||
|
@ -302,27 +302,27 @@ public:
|
|||
struct INFO
|
||||
{
|
||||
DEVICE_TYPE_ deviceType;
|
||||
wxString fieldValue;
|
||||
wxString description;
|
||||
std::string fieldValue;
|
||||
std::string description;
|
||||
};
|
||||
|
||||
|
||||
struct SPICE_INFO
|
||||
{
|
||||
wxString itemType;
|
||||
wxString modelType = "";
|
||||
wxString inlineTypeString = "";
|
||||
wxString level = "";
|
||||
std::string itemType;
|
||||
std::string modelType = "";
|
||||
std::string inlineTypeString = "";
|
||||
std::string level = "";
|
||||
bool isDefaultLevel = false;
|
||||
bool hasExpression = false;
|
||||
wxString version = "";
|
||||
std::string version = "";
|
||||
};
|
||||
|
||||
|
||||
struct PIN
|
||||
{
|
||||
const wxString name;
|
||||
wxString symbolPinNumber;
|
||||
const std::string name;
|
||||
std::string symbolPinNumber;
|
||||
|
||||
static constexpr auto NOT_CONNECTED = -1;
|
||||
};
|
||||
|
@ -359,38 +359,38 @@ public:
|
|||
|
||||
struct INFO
|
||||
{
|
||||
wxString name = "";
|
||||
std::string name = "";
|
||||
unsigned id = 0; // Legacy (don't remove).
|
||||
DIR dir = DIR_INOUT;
|
||||
SIM_VALUE::TYPE type = SIM_VALUE::TYPE_FLOAT;
|
||||
FLAGS flags = {}; // Legacy (don't remove).
|
||||
wxString unit = "";
|
||||
std::string unit = "";
|
||||
CATEGORY category = CATEGORY::PRINCIPAL;
|
||||
wxString defaultValue = "";
|
||||
wxString defaultValueOfOtherVariant = ""; // Legacy (don't remove).
|
||||
wxString description = "";
|
||||
std::string defaultValue = "";
|
||||
std::string defaultValueOfOtherVariant = ""; // Legacy (don't remove).
|
||||
std::string description = "";
|
||||
bool isSpiceInstanceParam = false;
|
||||
bool isInstanceParam = false;
|
||||
wxString spiceModelName = "";
|
||||
wxString spiceInstanceName = "";
|
||||
std::vector<wxString> enumValues = {};
|
||||
std::string spiceModelName = "";
|
||||
std::string spiceInstanceName = "";
|
||||
std::vector<std::string> enumValues = {};
|
||||
|
||||
// TODO: Stop using brace-initializers, use this constructor for all info structs.
|
||||
INFO( wxString aName = "",
|
||||
INFO( std::string aName = "",
|
||||
unsigned aId = 0,
|
||||
DIR aDir = DIR_INOUT,
|
||||
SIM_VALUE::TYPE aType = SIM_VALUE::TYPE_FLOAT,
|
||||
FLAGS aFlags = {},
|
||||
const wxString& aUnit = "",
|
||||
const std::string& aUnit = "",
|
||||
CATEGORY aCategory = CATEGORY::PRINCIPAL,
|
||||
const wxString& aDefaultValue = "",
|
||||
const wxString& aDefaultValueOfOtherVariant = "",
|
||||
const wxString& aDescription = "",
|
||||
const std::string& aDefaultValue = "",
|
||||
const std::string& aDefaultValueOfOtherVariant = "",
|
||||
const std::string& aDescription = "",
|
||||
bool aIsSpiceInstanceParam = false,
|
||||
bool aIsInstanceParam = false,
|
||||
const wxString& aSpiceModelName = "",
|
||||
const wxString& aSpiceInstanceName = "",
|
||||
std::vector<wxString> aEnumValues = {} ) :
|
||||
const std::string& aSpiceModelName = "",
|
||||
const std::string& aSpiceInstanceName = "",
|
||||
std::vector<std::string> aEnumValues = {} ) :
|
||||
name( aName ),
|
||||
id( aId ),
|
||||
dir( aDir ),
|
||||
|
@ -430,7 +430,7 @@ public:
|
|||
template <typename T>
|
||||
static TYPE ReadTypeFromFields( const std::vector<T>& aFields );
|
||||
|
||||
static TYPE InferTypeFromRefAndValue( const wxString& aRef, const wxString& aValue );
|
||||
static TYPE InferTypeFromRefAndValue( const std::string& aRef, const std::string& aValue );
|
||||
|
||||
template <typename T>
|
||||
static TYPE InferTypeFromLegacyFields( const std::vector<T>& aFields );
|
||||
|
@ -449,11 +449,11 @@ public:
|
|||
const std::vector<T>& aFields );
|
||||
|
||||
template <typename T>
|
||||
static wxString GetFieldValue( const std::vector<T>* aFields, const wxString& aFieldName );
|
||||
static std::string GetFieldValue( const std::vector<T>* aFields, const std::string& aFieldName );
|
||||
|
||||
template <typename T>
|
||||
static void SetFieldValue( std::vector<T>& aFields, const wxString& aFieldName,
|
||||
const wxString& aValue );
|
||||
static void SetFieldValue( std::vector<T>& aFields, const std::string& aFieldName,
|
||||
const std::string& aValue );
|
||||
|
||||
const SPICE_GENERATOR& SpiceGenerator() const { return *m_spiceGenerator; }
|
||||
|
||||
|
@ -487,7 +487,7 @@ public:
|
|||
SPICE_INFO GetSpiceInfo() const { return SpiceInfo( GetType() ); }
|
||||
|
||||
void AddPin( const PIN& aPin );
|
||||
int FindModelPinIndex( const wxString& aSymbolPinNumber );
|
||||
int FindModelPinIndex( const std::string& aSymbolPinNumber );
|
||||
void AddParam( const PARAM::INFO& aInfo, bool aIsOtherVariant = false );
|
||||
|
||||
DEVICE_INFO GetDeviceTypeInfo() const { return DeviceTypeInfo( GetDeviceType() ); }
|
||||
|
@ -504,7 +504,7 @@ public:
|
|||
|
||||
std::vector<std::reference_wrapper<const PIN>> GetPins() const;
|
||||
|
||||
void SetPinSymbolPinNumber( int aPinIndex, const wxString& aSymbolPinNumber )
|
||||
void SetPinSymbolPinNumber( int aPinIndex, const std::string& aSymbolPinNumber )
|
||||
{
|
||||
m_pins.at( aPinIndex ).symbolPinNumber = aSymbolPinNumber;
|
||||
}
|
||||
|
@ -513,18 +513,18 @@ public:
|
|||
int GetParamCount() const { return static_cast<int>( m_params.size() ); }
|
||||
const PARAM& GetParam( unsigned aParamIndex ) const; // Return base parameter unless it's overridden.
|
||||
|
||||
const PARAM* FindParam( const wxString& aParamName ) const;
|
||||
const PARAM* FindParam( const std::string& aParamName ) const;
|
||||
|
||||
std::vector<std::reference_wrapper<const PARAM>> GetParams() const;
|
||||
|
||||
const PARAM& GetUnderlyingParam( unsigned aParamIndex ) const; // Return the actual parameter.
|
||||
const PARAM& GetBaseParam( unsigned aParamIndex ) const; // Always return base parameter if it exists.
|
||||
|
||||
virtual bool SetParamValue( unsigned aParamIndex, const wxString& aValue,
|
||||
virtual bool SetParamValue( unsigned aParamIndex, const std::string& aValue,
|
||||
SIM_VALUE_GRAMMAR::NOTATION aNotation
|
||||
= SIM_VALUE_GRAMMAR::NOTATION::SI );
|
||||
|
||||
bool SetParamValue( const wxString& aParamName, const wxString& aValue,
|
||||
bool SetParamValue( const std::string& aParamName, const std::string& aValue,
|
||||
SIM_VALUE_GRAMMAR::NOTATION aNotation = SIM_VALUE_GRAMMAR::NOTATION::SI );
|
||||
|
||||
bool HasOverrides() const;
|
||||
|
@ -546,15 +546,15 @@ protected:
|
|||
virtual void CreatePins( unsigned aSymbolPinCount );
|
||||
|
||||
template <typename T>
|
||||
void WriteInferredDataFields( std::vector<T>& aFields, const wxString& aValue ) const;
|
||||
void WriteInferredDataFields( std::vector<T>& aFields, const std::string& aValue ) const;
|
||||
|
||||
virtual wxString GenerateParamValuePair( const PARAM& aParam, bool& aIsFirst ) const;
|
||||
virtual std::string GenerateParamValuePair( const PARAM& aParam, bool& aIsFirst ) const;
|
||||
|
||||
wxString GenerateParamsField( const wxString& aPairSeparator ) const;
|
||||
void ParseParamsField( const wxString& aParamsField );
|
||||
std::string GenerateParamsField( const std::string& aPairSeparator ) const;
|
||||
void ParseParamsField( const std::string& aParamsField );
|
||||
|
||||
void ParsePinsField( unsigned aSymbolPinCount, const wxString& aPinsField );
|
||||
void ParseDisabledField( const wxString& aDisabledField );
|
||||
void ParsePinsField( unsigned aSymbolPinCount, const std::string& aPinsField );
|
||||
void ParseDisabledField( const std::string& aDisabledField );
|
||||
|
||||
template <typename T>
|
||||
void InferredReadDataFields( unsigned aSymbolPinCount, const std::vector<T>* aFields,
|
||||
|
@ -562,9 +562,9 @@ protected:
|
|||
bool aAllowParamValuePairs = true );
|
||||
|
||||
private:
|
||||
static TYPE readTypeFromSpiceStrings( const wxString& aTypeString,
|
||||
const wxString& aLevel = "",
|
||||
const wxString& aVersion = "",
|
||||
static TYPE readTypeFromSpiceStrings( const std::string& aTypeString,
|
||||
const std::string& aLevel = "",
|
||||
const std::string& aVersion = "",
|
||||
bool aSkipDefaultLevel = true );
|
||||
|
||||
|
||||
|
@ -574,17 +574,17 @@ private:
|
|||
template <typename T>
|
||||
void doWriteFields( std::vector<T>& aFields ) const;
|
||||
|
||||
wxString generateDeviceTypeField() const;
|
||||
wxString generateTypeField() const;
|
||||
std::string generateDeviceTypeField() const;
|
||||
std::string generateTypeField() const;
|
||||
|
||||
wxString generatePinsField() const;
|
||||
wxString generateDisabledField() const;
|
||||
std::string generatePinsField() const;
|
||||
std::string generateDisabledField() const;
|
||||
|
||||
wxString parseFieldFloatValue( wxString aFieldFloatValue );
|
||||
std::string parseFieldFloatValue( std::string aFieldFloatValue );
|
||||
|
||||
virtual bool requiresSpiceModelLine() const;
|
||||
|
||||
virtual std::vector<wxString> getPinNames() const { return {}; }
|
||||
virtual std::vector<std::string> getPinNames() const { return {}; }
|
||||
|
||||
|
||||
std::unique_ptr<SPICE_GENERATOR> m_spiceGenerator;
|
||||
|
|
|
@ -23,22 +23,23 @@
|
|||
*/
|
||||
|
||||
#include <sim/sim_model_behavioral.h>
|
||||
#include <locale_io.h>
|
||||
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include <boost/algorithm/string/trim.hpp>
|
||||
#include <fmt/core.h>
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR_BEHAVIORAL::ModelLine( const wxString& aModelName ) const
|
||||
std::string SPICE_GENERATOR_BEHAVIORAL::ModelLine( const std::string& aModelName ) const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR_BEHAVIORAL::ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const
|
||||
std::string SPICE_GENERATOR_BEHAVIORAL::ItemLine( const std::string& aRefName,
|
||||
const std::string& aModelName,
|
||||
const std::vector<std::string>& aSymbolPinNumbers,
|
||||
const std::vector<std::string>& aPinNetNames ) const
|
||||
{
|
||||
LOCALE_IO toggle;
|
||||
|
||||
switch( m_model.GetType() )
|
||||
{
|
||||
case SIM_MODEL::TYPE::R_BEHAVIORAL:
|
||||
|
@ -51,13 +52,15 @@ wxString SPICE_GENERATOR_BEHAVIORAL::ItemLine( const wxString& aRefName,
|
|||
|
||||
case SIM_MODEL::TYPE::V_BEHAVIORAL:
|
||||
return SPICE_GENERATOR::ItemLine( aRefName,
|
||||
wxString::Format( "V=%s", m_model.GetParam( 0 ).value->ToString() ),
|
||||
fmt::format( "V={0}",
|
||||
m_model.GetParam( 0 ).value->ToString() ),
|
||||
aSymbolPinNumbers,
|
||||
aPinNetNames );
|
||||
|
||||
case SIM_MODEL::TYPE::I_BEHAVIORAL:
|
||||
return SPICE_GENERATOR::ItemLine( aRefName,
|
||||
wxString::Format( "I=%s", m_model.GetParam( 0 ).value->ToString() ),
|
||||
fmt::format( "I={0}",
|
||||
m_model.GetParam( 0 ).value->ToString() ),
|
||||
aSymbolPinNumbers,
|
||||
aPinNetNames );
|
||||
|
||||
|
@ -129,14 +132,16 @@ void SIM_MODEL_BEHAVIORAL::WriteDataLibFields( std::vector<LIB_FIELD>& aFields )
|
|||
}
|
||||
|
||||
|
||||
bool SIM_MODEL_BEHAVIORAL::parseValueField( const wxString& aValueField )
|
||||
bool SIM_MODEL_BEHAVIORAL::parseValueField( const std::string& aValueField )
|
||||
{
|
||||
wxString expr = aValueField;
|
||||
|
||||
if( !expr.Replace( "=", "", false ) )
|
||||
return false;
|
||||
std::string expr = aValueField;
|
||||
|
||||
SetParamValue( 0, expr.Trim( false ).Trim( true ) );
|
||||
if( expr.find( "=" ) == std::string::npos )
|
||||
return false;
|
||||
|
||||
boost::replace_first( expr, "=", "" );
|
||||
|
||||
SetParamValue( 0, boost::trim_copy( expr ) );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -161,7 +166,7 @@ void SIM_MODEL_BEHAVIORAL::inferredReadDataFields( unsigned aSymbolPinCount,
|
|||
template <typename T>
|
||||
void SIM_MODEL_BEHAVIORAL::inferredWriteDataFields( std::vector<T>& aFields ) const
|
||||
{
|
||||
wxString value = GetParam( 0 ).value->ToString();
|
||||
std::string value = GetParam( 0 ).value->ToString();
|
||||
|
||||
if( value == "" )
|
||||
value = GetDeviceTypeInfo().fieldValue;
|
||||
|
@ -170,8 +175,8 @@ void SIM_MODEL_BEHAVIORAL::inferredWriteDataFields( std::vector<T>& aFields ) co
|
|||
}
|
||||
|
||||
|
||||
SIM_MODEL::PARAM::INFO SIM_MODEL_BEHAVIORAL::makeParams( wxString aName, wxString aDescription,
|
||||
wxString aUnit )
|
||||
SIM_MODEL::PARAM::INFO SIM_MODEL_BEHAVIORAL::makeParams( std::string aName, std::string aDescription,
|
||||
std::string aUnit )
|
||||
{
|
||||
PARAM::INFO paramInfo = {};
|
||||
|
||||
|
|
|
@ -34,11 +34,11 @@ class SPICE_GENERATOR_BEHAVIORAL : public SPICE_GENERATOR
|
|||
public:
|
||||
using SPICE_GENERATOR::SPICE_GENERATOR;
|
||||
|
||||
wxString ModelLine( const wxString& aModelName ) const override;
|
||||
wxString ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const override;
|
||||
std::string ModelLine( const std::string& aModelName ) const override;
|
||||
std::string ItemLine( const std::string& aRefName,
|
||||
const std::string& aModelName,
|
||||
const std::vector<std::string>& aSymbolPinNumbers,
|
||||
const std::vector<std::string>& aPinNetNames ) const override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -57,7 +57,7 @@ public:
|
|||
|
||||
|
||||
private:
|
||||
bool parseValueField( const wxString& aValueField );
|
||||
bool parseValueField( const std::string& aValueField );
|
||||
|
||||
template <typename T>
|
||||
void inferredReadDataFields( unsigned aSymbolPinCount, const std::vector<T>* aFields );
|
||||
|
@ -65,9 +65,9 @@ private:
|
|||
template <typename T>
|
||||
void inferredWriteDataFields( std::vector<T>& aFields ) const;
|
||||
|
||||
std::vector<wxString> getPinNames() const override { return { "+", "-" }; }
|
||||
std::vector<std::string> getPinNames() const override { return { "+", "-" }; }
|
||||
|
||||
static PARAM::INFO makeParams( wxString aName, wxString aDescription, wxString aUnit );
|
||||
static PARAM::INFO makeParams( std::string aName, std::string aDescription, std::string aUnit );
|
||||
|
||||
|
||||
bool m_isInferred;
|
||||
|
|
|
@ -27,18 +27,18 @@
|
|||
#include <pegtl/contrib/parse_tree.hpp>
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR_IDEAL::ModelLine( const wxString& aModelName ) const
|
||||
std::string SPICE_GENERATOR_IDEAL::ModelLine( const std::string& aModelName ) const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR_IDEAL::ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const
|
||||
std::string SPICE_GENERATOR_IDEAL::ItemLine( const std::string& aRefName,
|
||||
const std::string& aModelName,
|
||||
const std::vector<std::string>& aSymbolPinNumbers,
|
||||
const std::vector<std::string>& aPinNetNames ) const
|
||||
{
|
||||
wxString valueStr = m_model.GetParam( 0 ).value->ToString( SIM_VALUE::NOTATION::SPICE );
|
||||
std::string valueStr = m_model.GetParam( 0 ).value->ToString( SIM_VALUE::NOTATION::SPICE );
|
||||
|
||||
if( valueStr != "" )
|
||||
return SPICE_GENERATOR::ItemLine( aRefName, valueStr, aSymbolPinNumbers,
|
||||
|
@ -108,17 +108,17 @@ void SIM_MODEL_IDEAL::WriteDataLibFields( std::vector<LIB_FIELD>& aFields ) cons
|
|||
template <typename T>
|
||||
void SIM_MODEL_IDEAL::inferredWriteDataFields( std::vector<T>& aFields ) const
|
||||
{
|
||||
wxString value = GetParam( 0 ).value->ToString();
|
||||
std::string value = GetParam( 0 ).value->ToString();
|
||||
|
||||
if( value.IsEmpty() )
|
||||
if( value == "" )
|
||||
value = DeviceTypeInfo( GetDeviceType() ).fieldValue;
|
||||
|
||||
WriteInferredDataFields( aFields, value );
|
||||
}
|
||||
|
||||
|
||||
SIM_MODEL::PARAM::INFO SIM_MODEL_IDEAL::makeParamInfo( wxString aName, wxString aDescription,
|
||||
wxString aUnit )
|
||||
SIM_MODEL::PARAM::INFO SIM_MODEL_IDEAL::makeParamInfo( std::string aName, std::string aDescription,
|
||||
std::string aUnit )
|
||||
{
|
||||
SIM_MODEL::PARAM::INFO paramInfo = {};
|
||||
|
||||
|
|
|
@ -34,11 +34,11 @@ class SPICE_GENERATOR_IDEAL : public SPICE_GENERATOR
|
|||
public:
|
||||
using SPICE_GENERATOR::SPICE_GENERATOR;
|
||||
|
||||
wxString ModelLine( const wxString& aModelName ) const override;
|
||||
wxString ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const override;
|
||||
std::string ModelLine( const std::string& aModelName ) const override;
|
||||
std::string ItemLine( const std::string& aRefName,
|
||||
const std::string& aModelName,
|
||||
const std::vector<std::string>& aSymbolPinNumbers,
|
||||
const std::vector<std::string>& aPinNetNames ) const override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -57,9 +57,9 @@ private:
|
|||
template <typename T>
|
||||
void inferredWriteDataFields( std::vector<T>& aFields ) const;
|
||||
|
||||
std::vector<wxString> getPinNames() const override { return { "+", "-" }; }
|
||||
std::vector<std::string> getPinNames() const override { return { "+", "-" }; }
|
||||
|
||||
static PARAM::INFO makeParamInfo( wxString aName, wxString aDescription, wxString aUnit );
|
||||
static PARAM::INFO makeParamInfo( std::string aName, std::string aDescription, std::string aUnit );
|
||||
|
||||
bool m_isInferred;
|
||||
};
|
||||
|
|
|
@ -25,12 +25,12 @@
|
|||
#include <sim/sim_model_mutual_inductor.h>
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR_MUTUAL_INDUCTOR::ItemParams() const
|
||||
std::string SPICE_GENERATOR_MUTUAL_INDUCTOR::ItemParams() const
|
||||
{
|
||||
wxString result;
|
||||
std::string result;
|
||||
|
||||
for( const SIM_MODEL::PARAM& param : GetInstanceParams() )
|
||||
result << " " << param.value->ToSpiceString();
|
||||
result.append( " " + param.value->ToSpiceString() );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ class SPICE_GENERATOR_MUTUAL_INDUCTOR : public SPICE_GENERATOR
|
|||
public:
|
||||
using SPICE_GENERATOR::SPICE_GENERATOR;
|
||||
|
||||
wxString ItemParams() const override;
|
||||
std::string ItemParams() const override;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -23,20 +23,20 @@
|
|||
*/
|
||||
|
||||
#include <sim/sim_model_ngspice.h>
|
||||
#include <locale_io.h>
|
||||
|
||||
#include <boost/algorithm/string/case_conv.hpp>
|
||||
#include <fmt/core.h>
|
||||
|
||||
|
||||
std::vector<wxString> SPICE_GENERATOR_NGSPICE::CurrentNames( const wxString& aRefName ) const
|
||||
std::vector<std::string> SPICE_GENERATOR_NGSPICE::CurrentNames( const std::string& aRefName ) const
|
||||
{
|
||||
LOCALE_IO toggle;
|
||||
|
||||
switch( m_model.GetTypeInfo().deviceType )
|
||||
{
|
||||
case SIM_MODEL::DEVICE_TYPE_::NPN:
|
||||
case SIM_MODEL::DEVICE_TYPE_::PNP:
|
||||
return { wxString::Format( "I(%s:c)", aRefName ),
|
||||
wxString::Format( "I(%s:b)", aRefName ),
|
||||
wxString::Format( "I(%s:e)", aRefName ) };
|
||||
return { fmt::format( "I({}:c)", aRefName ),
|
||||
fmt::format( "I({}:b)", aRefName ),
|
||||
fmt::format( "I({}:e)", aRefName ) };
|
||||
|
||||
case SIM_MODEL::DEVICE_TYPE_::NJFET:
|
||||
case SIM_MODEL::DEVICE_TYPE_::PJFET:
|
||||
|
@ -44,9 +44,9 @@ std::vector<wxString> SPICE_GENERATOR_NGSPICE::CurrentNames( const wxString& aRe
|
|||
case SIM_MODEL::DEVICE_TYPE_::PMES:
|
||||
case SIM_MODEL::DEVICE_TYPE_::NMOS:
|
||||
case SIM_MODEL::DEVICE_TYPE_::PMOS:
|
||||
return { wxString::Format( "I(%s:d)", aRefName ),
|
||||
wxString::Format( "I(%s:g)", aRefName ),
|
||||
wxString::Format( "I(%s:s)", aRefName ) };
|
||||
return { fmt::format( "I({}:d)", aRefName ),
|
||||
fmt::format( "I({}:g)", aRefName ),
|
||||
fmt::format( "I({}:s)", aRefName ) };
|
||||
|
||||
case SIM_MODEL::DEVICE_TYPE_::R:
|
||||
case SIM_MODEL::DEVICE_TYPE_::C:
|
||||
|
@ -81,7 +81,7 @@ SIM_MODEL_NGSPICE::SIM_MODEL_NGSPICE( TYPE aType ) :
|
|||
}
|
||||
|
||||
|
||||
bool SIM_MODEL_NGSPICE::SetParamFromSpiceCode( const wxString& aParamName, const wxString& aParamValue,
|
||||
bool SIM_MODEL_NGSPICE::SetParamFromSpiceCode( const std::string& aParamName, const std::string& aParamValue,
|
||||
SIM_VALUE_GRAMMAR::NOTATION aNotation )
|
||||
{
|
||||
// "level" and "version" are not really parameters - they're part of the type - so silently
|
||||
|
@ -107,8 +107,8 @@ bool SIM_MODEL_NGSPICE::SetParamFromSpiceCode( const wxString& aParamName, const
|
|||
{
|
||||
return !param.info.isSpiceInstanceParam
|
||||
&& param.info.category != PARAM::CATEGORY::SUPERFLUOUS
|
||||
&& ( param.info.name == aParamName.Lower()
|
||||
|| param.info.name == aParamName.Lower() + "_" );
|
||||
&& ( param.info.name == boost::to_lower_copy( aParamName )
|
||||
|| param.info.name == boost::to_lower_copy( aParamName ) + "_" );
|
||||
} );
|
||||
|
||||
if( paramIt != params.end() )
|
||||
|
@ -122,7 +122,7 @@ bool SIM_MODEL_NGSPICE::SetParamFromSpiceCode( const wxString& aParamName, const
|
|||
auto ngspiceParamIt = std::find_if( ngspiceParams.begin(), ngspiceParams.end(),
|
||||
[aParamName]( const PARAM& param )
|
||||
{
|
||||
return param.info.name == aParamName.Lower();
|
||||
return param.info.name == boost::to_lower_copy( aParamName );
|
||||
} );
|
||||
|
||||
if( ngspiceParamIt == ngspiceParams.end() )
|
||||
|
@ -146,7 +146,7 @@ bool SIM_MODEL_NGSPICE::SetParamFromSpiceCode( const wxString& aParamName, const
|
|||
}
|
||||
|
||||
|
||||
std::vector<wxString> SIM_MODEL_NGSPICE::getPinNames() const
|
||||
std::vector<std::string> SIM_MODEL_NGSPICE::getPinNames() const
|
||||
{
|
||||
return ModelInfo( getModelType() ).pinNames;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ class SPICE_GENERATOR_NGSPICE : public SPICE_GENERATOR_SPICE
|
|||
public:
|
||||
using SPICE_GENERATOR_SPICE::SPICE_GENERATOR_SPICE;
|
||||
|
||||
std::vector<wxString> CurrentNames( const wxString& aRefName ) const override;
|
||||
std::vector<std::string> CurrentNames( const std::string& aRefName ) const override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -46,7 +46,7 @@ public:
|
|||
|
||||
SIM_MODEL_NGSPICE( TYPE aType );
|
||||
|
||||
bool SetParamFromSpiceCode( const wxString& aParamName, const wxString& aParamValue,
|
||||
bool SetParamFromSpiceCode( const std::string& aParamName, const std::string& aParamValue,
|
||||
SIM_VALUE_GRAMMAR::NOTATION aNotation ) override;
|
||||
|
||||
// Protected because it's accessed by QA tests.
|
||||
|
@ -92,11 +92,11 @@ protected:
|
|||
|
||||
struct MODEL_INFO
|
||||
{
|
||||
wxString name;
|
||||
wxString variant1;
|
||||
wxString variant2;
|
||||
std::vector<wxString> pinNames;
|
||||
wxString description;
|
||||
std::string name;
|
||||
std::string variant1;
|
||||
std::string variant2;
|
||||
std::vector<std::string> pinNames;
|
||||
std::string description;
|
||||
std::vector<SIM_MODEL::PARAM::INFO> modelParams;
|
||||
std::vector<SIM_MODEL::PARAM::INFO> instanceParams;
|
||||
};
|
||||
|
@ -106,7 +106,7 @@ protected:
|
|||
private:
|
||||
bool requiresSpiceModelLine() const override { return false; }
|
||||
|
||||
std::vector<wxString> getPinNames() const override;
|
||||
std::vector<std::string> getPinNames() const override;
|
||||
|
||||
MODEL_TYPE getModelType() const;
|
||||
bool getIsOtherVariant();
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
*/
|
||||
|
||||
#include <sim/sim_model_raw_spice.h>
|
||||
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <fmt/core.h>
|
||||
#include <pegtl.hpp>
|
||||
#include <pegtl/contrib/parse_tree.hpp>
|
||||
|
||||
|
@ -36,30 +39,30 @@ namespace SIM_MODEL_RAW_SPICE_PARSER
|
|||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR_RAW_SPICE::ModelLine( const wxString& aModelName ) const
|
||||
std::string SPICE_GENERATOR_RAW_SPICE::ModelLine( const std::string& aModelName ) const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR_RAW_SPICE::ItemName( const wxString& aRefName ) const
|
||||
std::string SPICE_GENERATOR_RAW_SPICE::ItemName( const std::string& aRefName ) const
|
||||
{
|
||||
wxString elementType = m_model.GetParam(
|
||||
std::string elementType = m_model.GetParam(
|
||||
static_cast<int>( SIM_MODEL_RAW_SPICE::SPICE_PARAM::TYPE ) ).value->ToString();
|
||||
|
||||
if( aRefName != "" && aRefName.StartsWith( elementType ) )
|
||||
if( aRefName != "" && boost::starts_with( aRefName, elementType ) )
|
||||
return aRefName;
|
||||
else
|
||||
return elementType + aRefName;
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR_RAW_SPICE::ItemPins( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const
|
||||
std::string SPICE_GENERATOR_RAW_SPICE::ItemPins( const std::string& aRefName,
|
||||
const std::string& aModelName,
|
||||
const std::vector<std::string>& aSymbolPinNumbers,
|
||||
const std::vector<std::string>& aPinNetNames ) const
|
||||
{
|
||||
wxString result;
|
||||
std::string result;
|
||||
|
||||
for( const SIM_MODEL::PIN& pin : GetPins() )
|
||||
{
|
||||
|
@ -69,7 +72,7 @@ wxString SPICE_GENERATOR_RAW_SPICE::ItemPins( const wxString& aRefName,
|
|||
if( it != aSymbolPinNumbers.end() )
|
||||
{
|
||||
long symbolPinIndex = std::distance( aSymbolPinNumbers.begin(), it );
|
||||
result << " " << aPinNetNames.at( symbolPinIndex );
|
||||
result.append( " " + aPinNetNames.at( symbolPinIndex ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,37 +80,35 @@ wxString SPICE_GENERATOR_RAW_SPICE::ItemPins( const wxString& aRefName,
|
|||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR_RAW_SPICE::ItemModelName( const wxString& aModelName ) const
|
||||
std::string SPICE_GENERATOR_RAW_SPICE::ItemModelName( const std::string& aModelName ) const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR_RAW_SPICE::ItemParams() const
|
||||
std::string SPICE_GENERATOR_RAW_SPICE::ItemParams() const
|
||||
{
|
||||
wxString result;
|
||||
std::string result;
|
||||
|
||||
for( const SIM_MODEL::PARAM& param : GetInstanceParams() )
|
||||
{
|
||||
if( param.info.name != "model" )
|
||||
result << "";
|
||||
else
|
||||
result << " " << param.value->ToString();
|
||||
if( param.info.name == "model" )
|
||||
result.append( " " + param.value->ToString() );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR_RAW_SPICE::Preview( const wxString& aModelName ) const
|
||||
std::string SPICE_GENERATOR_RAW_SPICE::Preview( const std::string& aModelName ) const
|
||||
{
|
||||
std::vector<wxString> pinNumbers;
|
||||
std::vector<wxString> pinNetNames;
|
||||
std::vector<std::string> pinNumbers;
|
||||
std::vector<std::string> pinNetNames;
|
||||
|
||||
for( int i = 0; i < m_model.GetPinCount(); ++i )
|
||||
{
|
||||
pinNumbers.push_back( wxString::FromCDouble( i + 1 ) );
|
||||
pinNetNames.push_back( wxString::FromCDouble( i + 1 ) );
|
||||
pinNumbers.push_back( fmt::format( "{0}", i + 1 ) );
|
||||
pinNetNames.push_back( fmt::format( "{0}", i + 1 ) );
|
||||
}
|
||||
|
||||
return ItemLine( "", aModelName, pinNumbers, pinNetNames );
|
||||
|
@ -162,7 +163,7 @@ void SIM_MODEL_RAW_SPICE::WriteDataLibFields( std::vector<LIB_FIELD>& aFields )
|
|||
void SIM_MODEL_RAW_SPICE::CreatePins( unsigned aSymbolPinCount )
|
||||
{
|
||||
for( unsigned symbolPinIndex = 0; symbolPinIndex < aSymbolPinCount; ++symbolPinIndex )
|
||||
AddPin( { "", wxString::FromCDouble( symbolPinIndex + 1 ) } );
|
||||
AddPin( { "", fmt::format( "{}", symbolPinIndex + 1 ) } );
|
||||
}
|
||||
|
||||
|
||||
|
@ -258,7 +259,7 @@ void SIM_MODEL_RAW_SPICE::readLegacyDataFields( unsigned aSymbolPinCount,
|
|||
|
||||
|
||||
void SIM_MODEL_RAW_SPICE::parseLegacyPinsField( unsigned aSymbolPinCount,
|
||||
const wxString& aLegacyPinsField )
|
||||
const std::string& aLegacyPinsField )
|
||||
{
|
||||
if( aLegacyPinsField == "" )
|
||||
return;
|
||||
|
@ -267,7 +268,7 @@ void SIM_MODEL_RAW_SPICE::parseLegacyPinsField( unsigned aSymbolPinCount,
|
|||
for( int modelPinIndex = 0; modelPinIndex < GetPinCount(); ++modelPinIndex )
|
||||
SetPinSymbolPinNumber( static_cast<int>( modelPinIndex ), "" );
|
||||
|
||||
tao::pegtl::string_input<> in( aLegacyPinsField.ToUTF8(), PINS_FIELD );
|
||||
tao::pegtl::string_input<> in( aLegacyPinsField, PINS_FIELD );
|
||||
std::unique_ptr<tao::pegtl::parse_tree::node> root;
|
||||
|
||||
try
|
||||
|
@ -287,12 +288,8 @@ void SIM_MODEL_RAW_SPICE::parseLegacyPinsField( unsigned aSymbolPinCount,
|
|||
int symbolPinIndex = std::stoi( symbolPinStr ) - 1;
|
||||
|
||||
if( symbolPinIndex < 0 || symbolPinIndex >= static_cast<int>( aSymbolPinCount ) )
|
||||
{
|
||||
THROW_IO_ERROR( wxString::Format( _( "Invalid symbol pin index: '%s'" ),
|
||||
symbolPinStr ) );
|
||||
}
|
||||
THROW_IO_ERROR( wxString::Format( _( "Invalid symbol pin index: '%s'" ), symbolPinStr ) );
|
||||
|
||||
|
||||
SetPinSymbolPinNumber( pinIndex, root->children.at( pinIndex )->string() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,17 +34,17 @@ class SPICE_GENERATOR_RAW_SPICE : public SPICE_GENERATOR
|
|||
public:
|
||||
using SPICE_GENERATOR::SPICE_GENERATOR;
|
||||
|
||||
wxString ModelLine( const wxString& aModelName ) const override;
|
||||
std::string ModelLine( const std::string& aModelName ) const override;
|
||||
|
||||
wxString ItemName( const wxString& aRefName ) const override;
|
||||
wxString ItemPins( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const override;
|
||||
wxString ItemModelName( const wxString& aModelName ) const override;
|
||||
wxString ItemParams() const override;
|
||||
std::string ItemName( const std::string& aRefName ) const override;
|
||||
std::string ItemPins( const std::string& aRefName,
|
||||
const std::string& aModelName,
|
||||
const std::vector<std::string>& aSymbolPinNumbers,
|
||||
const std::vector<std::string>& aPinNetNames ) const override;
|
||||
std::string ItemModelName( const std::string& aModelName ) const override;
|
||||
std::string ItemParams() const override;
|
||||
|
||||
wxString Preview( const wxString& aModelName ) const override;
|
||||
std::string Preview( const std::string& aModelName ) const override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -84,7 +84,7 @@ private:
|
|||
template <typename T>
|
||||
void readLegacyDataFields( unsigned aSymbolPinCount, const std::vector<T>* aFields );
|
||||
|
||||
void parseLegacyPinsField( unsigned aSymbolPinCount, const wxString& aLegacyPinsField );
|
||||
void parseLegacyPinsField( unsigned aSymbolPinCount, const std::string& aLegacyPinsField );
|
||||
|
||||
bool requiresSpiceModelLine() const override { return false; }
|
||||
|
||||
|
|
|
@ -23,9 +23,10 @@
|
|||
*/
|
||||
|
||||
#include <sim/sim_model_source.h>
|
||||
|
||||
#include <fmt/core.h>
|
||||
#include <pegtl.hpp>
|
||||
#include <pegtl/contrib/parse_tree.hpp>
|
||||
#include <locale_io.h>
|
||||
|
||||
|
||||
namespace SIM_MODEL_SOURCE_PARSER
|
||||
|
@ -38,29 +39,28 @@ namespace SIM_MODEL_SOURCE_PARSER
|
|||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR_SOURCE::ModelLine( const wxString& aModelName ) const
|
||||
std::string SPICE_GENERATOR_SOURCE::ModelLine( const std::string& aModelName ) const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR_SOURCE::ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const
|
||||
std::string SPICE_GENERATOR_SOURCE::ItemLine( const std::string& aRefName,
|
||||
const std::string& aModelName,
|
||||
const std::vector<std::string>& aSymbolPinNumbers,
|
||||
const std::vector<std::string>& aPinNetNames ) const
|
||||
{
|
||||
LOCALE_IO toggle;
|
||||
wxString model;
|
||||
std::string model;
|
||||
|
||||
wxString ac = m_model.FindParam( "ac" )->value->ToSpiceString();
|
||||
wxString ph = m_model.FindParam( "ph" )->value->ToSpiceString();
|
||||
std::string ac = m_model.FindParam( "ac" )->value->ToSpiceString();
|
||||
std::string ph = m_model.FindParam( "ph" )->value->ToSpiceString();
|
||||
|
||||
if( ac != "" )
|
||||
model << wxString::Format( "AC %s %s ", ac, ph );
|
||||
model.append( fmt::format( "AC {} {} ", ac, ph ) );
|
||||
|
||||
if( m_model.GetSpiceInfo().inlineTypeString != "" )
|
||||
{
|
||||
wxString args = "";
|
||||
std::string args = "";
|
||||
|
||||
switch( m_model.GetType() )
|
||||
{
|
||||
|
@ -91,7 +91,7 @@ wxString SPICE_GENERATOR_SOURCE::ItemLine( const wxString& aRefName,
|
|||
{
|
||||
std::unique_ptr<SIM_VALUE> value = SIM_VALUE::Create( SIM_VALUE::TYPE_FLOAT,
|
||||
node->string() );
|
||||
args << value->ToString( SIM_VALUE::NOTATION::SPICE ) << " ";
|
||||
args.append( value->ToString( SIM_VALUE::NOTATION::SPICE ) + " " );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -102,96 +102,96 @@ wxString SPICE_GENERATOR_SOURCE::ItemLine( const wxString& aRefName,
|
|||
|
||||
case SIM_MODEL::TYPE::V_WHITENOISE:
|
||||
case SIM_MODEL::TYPE::I_WHITENOISE:
|
||||
args << getParamValueString( "rms", "0" ) << " ";
|
||||
args << getParamValueString( "dt", "0" ) << " ";
|
||||
args << "0 0 0 0 0 ";
|
||||
args.append( getParamValueString( "rms", "0" ) + " " );
|
||||
args.append( getParamValueString( "dt", "0" ) + " " );
|
||||
args.append( "0 0 0 0 0 " );
|
||||
break;
|
||||
|
||||
case SIM_MODEL::TYPE::V_PINKNOISE:
|
||||
case SIM_MODEL::TYPE::I_PINKNOISE:
|
||||
args << "0 ";
|
||||
args << getParamValueString( "dt", "0" ) << " ";
|
||||
args << getParamValueString( "slope", "0" ) << " ";
|
||||
args << getParamValueString( "rms", "0" ) << " ";
|
||||
args << "0 0 0 ";
|
||||
args.append( "0 " );
|
||||
args.append( getParamValueString( "dt", "0" ) + " " );
|
||||
args.append( getParamValueString( "slope", "0" ) + " " );
|
||||
args.append( getParamValueString( "rms", "0" ) + " " );
|
||||
args.append( "0 0 0 " );
|
||||
break;
|
||||
|
||||
case SIM_MODEL::TYPE::V_BURSTNOISE:
|
||||
case SIM_MODEL::TYPE::I_BURSTNOISE:
|
||||
args << "0 0 0 0 ";
|
||||
args << getParamValueString( "ampl", "0" ) << " ";
|
||||
args << getParamValueString( "tcapt", "0" ) << " ";
|
||||
args << getParamValueString( "temit", "0" ) << " ";
|
||||
args.append( "0 0 0 0 " );
|
||||
args.append( getParamValueString( "ampl", "0" ) + " " );
|
||||
args.append( getParamValueString( "tcapt", "0" ) + " " );
|
||||
args.append( getParamValueString( "temit", "0" ) + " " );
|
||||
break;
|
||||
|
||||
case SIM_MODEL::TYPE::V_RANDUNIFORM:
|
||||
case SIM_MODEL::TYPE::I_RANDUNIFORM:
|
||||
{
|
||||
args << "1 ";
|
||||
args << getParamValueString( "dt", "0" ) << " ";
|
||||
args << getParamValueString( "td", "0" ) << " ";
|
||||
args.append( "1 " );
|
||||
args.append( getParamValueString( "dt", "0" ) + " " );
|
||||
args.append( getParamValueString( "td", "0" ) + " " );
|
||||
|
||||
auto min = dynamic_cast<SIM_VALUE_FLOAT&>( *m_model.FindParam( "max" )->value );
|
||||
auto max = dynamic_cast<SIM_VALUE_FLOAT&>( *m_model.FindParam( "min" )->value );
|
||||
SIM_VALUE_FLOAT range = max - min;
|
||||
SIM_VALUE_FLOAT offset = ( max + min ) / SIM_VALUE_FLOAT( 2 );
|
||||
|
||||
args << range.ToSpiceString() << " ";
|
||||
args << offset.ToSpiceString() << " ";
|
||||
args.append( range.ToSpiceString() + " " );
|
||||
args.append( offset.ToSpiceString() + " " );
|
||||
}
|
||||
break;
|
||||
|
||||
case SIM_MODEL::TYPE::V_RANDNORMAL:
|
||||
case SIM_MODEL::TYPE::I_RANDNORMAL:
|
||||
args << "2 ";
|
||||
args << getParamValueString( "dt", "0" ) << " ";
|
||||
args << getParamValueString( "td", "0" ) << " ";
|
||||
args << getParamValueString( "stddev", "0" ) << " ";
|
||||
args << getParamValueString( "mean", "0" ) << " ";
|
||||
args.append( "2 " );
|
||||
args.append( getParamValueString( "dt", "0" ) + " " );
|
||||
args.append( getParamValueString( "td", "0" ) + " " );
|
||||
args.append( getParamValueString( "stddev", "0" ) + " " );
|
||||
args.append( getParamValueString( "mean", "0" ) + " " );
|
||||
break;
|
||||
|
||||
case SIM_MODEL::TYPE::V_RANDEXP:
|
||||
case SIM_MODEL::TYPE::I_RANDEXP:
|
||||
args << "3 ";
|
||||
args << getParamValueString( "dt", "0" ) << " ";
|
||||
args << getParamValueString( "td", "0" ) << " ";
|
||||
args << getParamValueString( "mean", "0" ) << " ";
|
||||
args << getParamValueString( "offset", "0" ) << " ";
|
||||
args.append( "3 " );
|
||||
args.append( getParamValueString( "dt", "0" ) + " " );
|
||||
args.append( getParamValueString( "td", "0" ) + " " );
|
||||
args.append( getParamValueString( "mean", "0" ) + " " );
|
||||
args.append( getParamValueString( "offset", "0" ) + " " );
|
||||
break;
|
||||
|
||||
/*case SIM_MODEL::TYPE::V_RANDPOISSON:
|
||||
case SIM_MODEL::TYPE::I_RANDPOISSON:
|
||||
args << "4 ";
|
||||
args << FindParam( "dt" )->value->ToSpiceString() << " ";
|
||||
args << FindParam( "td" )->value->ToSpiceString() << " ";
|
||||
args << FindParam( "lambda" )->value->ToSpiceString() << " ";
|
||||
args << FindParam( "offset" )->value->ToSpiceString() << " ";
|
||||
args.append( "4 " );
|
||||
args.append( FindParam( "dt" )->value->ToSpiceString() + " " );
|
||||
args.append( FindParam( "td" )->value->ToSpiceString() + " " );
|
||||
args.append( FindParam( "lambda" )->value->ToSpiceString() + " " );
|
||||
args.append( FindParam( "offset" )->value->ToSpiceString() + " " );
|
||||
break;*/
|
||||
|
||||
default:
|
||||
for( const SIM_MODEL::PARAM& param : m_model.GetParams() )
|
||||
{
|
||||
wxString argStr = param.value->ToString( SIM_VALUE_GRAMMAR::NOTATION::SPICE );
|
||||
std::string argStr = param.value->ToString( SIM_VALUE_GRAMMAR::NOTATION::SPICE );
|
||||
|
||||
if( argStr != "" )
|
||||
args << argStr << " ";
|
||||
args.append( argStr + " " );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
model << wxString::Format( "%s( %s)", m_model.GetSpiceInfo().inlineTypeString, args );
|
||||
model.append( fmt::format( "{}( {})", m_model.GetSpiceInfo().inlineTypeString, args ) );
|
||||
}
|
||||
else
|
||||
model << m_model.GetParam( 0 ).value->ToSpiceString();
|
||||
model.append( m_model.GetParam( 0 ).value->ToSpiceString() );
|
||||
|
||||
return SPICE_GENERATOR::ItemLine( aRefName, model, aSymbolPinNumbers, aPinNetNames );
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR_SOURCE::getParamValueString( const wxString& aParamName,
|
||||
const wxString& aDefaultValue ) const
|
||||
std::string SPICE_GENERATOR_SOURCE::getParamValueString( const std::string& aParamName,
|
||||
const std::string& aDefaultValue ) const
|
||||
{
|
||||
wxString result = m_model.FindParam( aParamName )->value->ToSpiceString();
|
||||
std::string result = m_model.FindParam( aParamName )->value->ToSpiceString();
|
||||
|
||||
if( result == "" )
|
||||
result = aDefaultValue;
|
||||
|
@ -227,7 +227,7 @@ void SIM_MODEL_SOURCE::WriteDataLibFields( std::vector<LIB_FIELD>& aFields ) con
|
|||
}
|
||||
|
||||
|
||||
bool SIM_MODEL_SOURCE::SetParamValue( unsigned aParamIndex, const wxString& aValue,
|
||||
bool SIM_MODEL_SOURCE::SetParamValue( unsigned aParamIndex, const std::string& aValue,
|
||||
SIM_VALUE_GRAMMAR::NOTATION aNotation )
|
||||
{
|
||||
// Sources are special. All preceding parameter values must be filled. If they are not, fill
|
||||
|
@ -254,7 +254,7 @@ bool SIM_MODEL_SOURCE::SetParamValue( unsigned aParamIndex, const wxString& aVal
|
|||
}
|
||||
|
||||
|
||||
wxString SIM_MODEL_SOURCE::GenerateParamValuePair( const PARAM& aParam, bool& aIsFirst ) const
|
||||
std::string SIM_MODEL_SOURCE::GenerateParamValuePair( const PARAM& aParam, bool& aIsFirst ) const
|
||||
{
|
||||
if( aParam.value->ToString() == "0" )
|
||||
return "";
|
||||
|
@ -266,7 +266,7 @@ wxString SIM_MODEL_SOURCE::GenerateParamValuePair( const PARAM& aParam, bool& aI
|
|||
template <typename T>
|
||||
void SIM_MODEL_SOURCE::inferredWriteDataFields( std::vector<T>& aFields ) const
|
||||
{
|
||||
wxString value = GetFieldValue( &aFields, PARAMS_FIELD );
|
||||
std::string value = GetFieldValue( &aFields, PARAMS_FIELD );
|
||||
|
||||
if( value == "" )
|
||||
value = GetDeviceTypeInfo().fieldValue;
|
||||
|
@ -357,8 +357,8 @@ const std::vector<SIM_MODEL::PARAM::INFO>& SIM_MODEL_SOURCE::makeParamInfos( TYP
|
|||
}
|
||||
|
||||
|
||||
std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeDcParamInfos( wxString aPrefix,
|
||||
wxString aUnit )
|
||||
std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeDcParamInfos( std::string aPrefix,
|
||||
std::string aUnit )
|
||||
{
|
||||
std::vector<PARAM::INFO> paramInfos;
|
||||
PARAM::INFO paramInfo;
|
||||
|
@ -376,8 +376,8 @@ std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeDcParamInfos( wxString
|
|||
}
|
||||
|
||||
|
||||
std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeSinParamInfos( wxString aPrefix,
|
||||
wxString aUnit )
|
||||
std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeSinParamInfos( std::string aPrefix,
|
||||
std::string aUnit )
|
||||
{
|
||||
std::vector<PARAM::INFO> paramInfos;
|
||||
PARAM::INFO paramInfo;
|
||||
|
@ -437,8 +437,8 @@ std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeSinParamInfos( wxStrin
|
|||
}
|
||||
|
||||
|
||||
std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makePulseParamInfos( wxString aPrefix,
|
||||
wxString aUnit )
|
||||
std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makePulseParamInfos( std::string aPrefix,
|
||||
std::string aUnit )
|
||||
{
|
||||
std::vector<PARAM::INFO> paramInfos;
|
||||
PARAM::INFO paramInfo;
|
||||
|
@ -514,8 +514,8 @@ std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makePulseParamInfos( wxStr
|
|||
}
|
||||
|
||||
|
||||
std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeExpParamInfos( wxString aPrefix,
|
||||
wxString aUnit )
|
||||
std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeExpParamInfos( std::string aPrefix,
|
||||
std::string aUnit )
|
||||
{
|
||||
std::vector<PARAM::INFO> paramInfos;
|
||||
PARAM::INFO paramInfo;
|
||||
|
@ -573,7 +573,7 @@ std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeExpParamInfos( wxStrin
|
|||
}
|
||||
|
||||
|
||||
/*std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeSfamParamInfos( wxString aPrefix, wxString aUnit )
|
||||
/*std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeSfamParamInfos( std::string aPrefix, std::string aUnit )
|
||||
{
|
||||
std::vector<PARAM::INFO> paramInfos;
|
||||
PARAM::INFO paramInfo;
|
||||
|
@ -622,7 +622,7 @@ std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeExpParamInfos( wxStrin
|
|||
}
|
||||
|
||||
|
||||
std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeSffmParamInfos( wxString aPrefix, wxString aUnit )
|
||||
std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeSffmParamInfos( std::string aPrefix, std::string aUnit )
|
||||
{
|
||||
std::vector<PARAM::INFO> paramInfos;
|
||||
PARAM::INFO paramInfo;
|
||||
|
@ -688,9 +688,9 @@ std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeSffmParamInfos( wxStri
|
|||
}*/
|
||||
|
||||
|
||||
std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makePwlParamInfos( wxString aPrefix,
|
||||
wxString aQuantity,
|
||||
wxString aUnit )
|
||||
std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makePwlParamInfos( std::string aPrefix,
|
||||
std::string aQuantity,
|
||||
std::string aUnit )
|
||||
{
|
||||
std::vector<PARAM::INFO> paramInfos;
|
||||
PARAM::INFO paramInfo;
|
||||
|
@ -762,8 +762,8 @@ std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makePwlParamInfos( wxStrin
|
|||
}
|
||||
|
||||
|
||||
std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeWhiteNoiseParamInfos( wxString aPrefix,
|
||||
wxString aUnit )
|
||||
std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeWhiteNoiseParamInfos( std::string aPrefix,
|
||||
std::string aUnit )
|
||||
{
|
||||
std::vector<PARAM::INFO> paramInfos;
|
||||
PARAM::INFO paramInfo;
|
||||
|
@ -789,8 +789,8 @@ std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeWhiteNoiseParamInfos(
|
|||
}
|
||||
|
||||
|
||||
std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makePinkNoiseParamInfos( wxString aPrefix,
|
||||
wxString aUnit )
|
||||
std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makePinkNoiseParamInfos( std::string aPrefix,
|
||||
std::string aUnit )
|
||||
{
|
||||
std::vector<PARAM::INFO> paramInfos;
|
||||
PARAM::INFO paramInfo;
|
||||
|
@ -824,8 +824,8 @@ std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makePinkNoiseParamInfos( w
|
|||
}
|
||||
|
||||
|
||||
std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeBurstNoiseParamInfos( wxString aPrefix,
|
||||
wxString aUnit )
|
||||
std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeBurstNoiseParamInfos( std::string aPrefix,
|
||||
std::string aUnit )
|
||||
{
|
||||
std::vector<PARAM::INFO> paramInfos;
|
||||
PARAM::INFO paramInfo;
|
||||
|
@ -859,8 +859,8 @@ std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeBurstNoiseParamInfos(
|
|||
}
|
||||
|
||||
|
||||
std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeRandomUniformParamInfos( wxString aPrefix,
|
||||
wxString aUnit )
|
||||
std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeRandomUniformParamInfos( std::string aPrefix,
|
||||
std::string aUnit )
|
||||
{
|
||||
std::vector<PARAM::INFO> paramInfos;
|
||||
PARAM::INFO paramInfo;
|
||||
|
@ -902,8 +902,8 @@ std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeRandomUniformParamInfo
|
|||
}
|
||||
|
||||
|
||||
std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeRandomNormalParamInfos( wxString aPrefix,
|
||||
wxString aUnit )
|
||||
std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeRandomNormalParamInfos( std::string aPrefix,
|
||||
std::string aUnit )
|
||||
{
|
||||
std::vector<PARAM::INFO> paramInfos;
|
||||
PARAM::INFO paramInfo;
|
||||
|
@ -945,8 +945,8 @@ std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeRandomNormalParamInfos
|
|||
}
|
||||
|
||||
|
||||
std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeRandomExpParamInfos( wxString aPrefix,
|
||||
wxString aUnit )
|
||||
std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeRandomExpParamInfos( std::string aPrefix,
|
||||
std::string aUnit )
|
||||
{
|
||||
std::vector<PARAM::INFO> paramInfos;
|
||||
PARAM::INFO paramInfo;
|
||||
|
@ -988,8 +988,8 @@ std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeRandomExpParamInfos( w
|
|||
}
|
||||
|
||||
|
||||
std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeRandomPoissonParamInfos( wxString aPrefix,
|
||||
wxString aUnit )
|
||||
std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeRandomPoissonParamInfos( std::string aPrefix,
|
||||
std::string aUnit )
|
||||
{
|
||||
std::vector<PARAM::INFO> paramInfos;
|
||||
PARAM::INFO paramInfo;
|
||||
|
@ -1030,7 +1030,7 @@ std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_SOURCE::makeRandomPoissonParamInfo
|
|||
return paramInfos;
|
||||
}
|
||||
|
||||
void SIM_MODEL_SOURCE::appendAcParamInfos( std::vector<PARAM::INFO>& aParamInfos, wxString aUnit )
|
||||
void SIM_MODEL_SOURCE::appendAcParamInfos( std::vector<PARAM::INFO>& aParamInfos, std::string aUnit )
|
||||
{
|
||||
PARAM::INFO paramInfo;
|
||||
|
||||
|
|
|
@ -49,15 +49,15 @@ class SPICE_GENERATOR_SOURCE : public SPICE_GENERATOR
|
|||
public:
|
||||
using SPICE_GENERATOR::SPICE_GENERATOR;
|
||||
|
||||
wxString ModelLine( const wxString& aModelName ) const override;
|
||||
wxString ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const override;
|
||||
std::string ModelLine( const std::string& aModelName ) const override;
|
||||
std::string ItemLine( const std::string& aRefName,
|
||||
const std::string& aModelName,
|
||||
const std::vector<std::string>& aSymbolPinNumbers,
|
||||
const std::vector<std::string>& aPinNetNames ) const override;
|
||||
|
||||
private:
|
||||
wxString getParamValueString( const wxString& aParamName,
|
||||
const wxString& aDefaultValue ) const;
|
||||
std::string getParamValueString( const std::string& aParamName,
|
||||
const std::string& aDefaultValue ) const;
|
||||
};
|
||||
|
||||
|
||||
|
@ -69,40 +69,40 @@ public:
|
|||
void WriteDataSchFields( std::vector<SCH_FIELD>& aFields ) const override;
|
||||
void WriteDataLibFields( std::vector<LIB_FIELD>& aFields ) const override;
|
||||
|
||||
bool SetParamValue( unsigned aParamIndex, const wxString& aValue,
|
||||
bool SetParamValue( unsigned aParamIndex, const std::string& aValue,
|
||||
SIM_VALUE_GRAMMAR::NOTATION aNotation = SIM_VALUE_GRAMMAR::NOTATION::SI )
|
||||
override;
|
||||
|
||||
bool HasAutofill() const override { return true; }
|
||||
|
||||
protected:
|
||||
wxString GenerateParamValuePair( const PARAM& aParam, bool& aIsFirst ) const override;
|
||||
std::string GenerateParamValuePair( const PARAM& aParam, bool& aIsFirst ) const override;
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
void inferredWriteDataFields( std::vector<T>& aFields ) const;
|
||||
|
||||
std::vector<wxString> getPinNames() const override { return { "+", "-" }; }
|
||||
std::vector<std::string> getPinNames() const override { return { "+", "-" }; }
|
||||
|
||||
static const std::vector<PARAM::INFO>& makeParamInfos( TYPE aType );
|
||||
|
||||
static std::vector<PARAM::INFO> makeDcParamInfos( wxString aPrefix, wxString aUnit );
|
||||
static std::vector<PARAM::INFO> makeSinParamInfos( wxString aPrefix, wxString aUnit );
|
||||
static std::vector<PARAM::INFO> makePulseParamInfos( wxString aPrefix, wxString aUnit );
|
||||
static std::vector<PARAM::INFO> makeExpParamInfos( wxString aPrefix, wxString aUnit );
|
||||
//static std::vector<PARAM::INFO> makeSfamParamInfos( wxString aPrefix, wxString aUnit );
|
||||
//static std::vector<PARAM::INFO> makeSffmParamInfos( wxString aPrefix, wxString aUnit );
|
||||
static std::vector<PARAM::INFO> makePwlParamInfos( wxString aPrefix, wxString aQuantity,
|
||||
wxString aUnit );
|
||||
static std::vector<PARAM::INFO> makeWhiteNoiseParamInfos( wxString aPrefix, wxString aUnit );
|
||||
static std::vector<PARAM::INFO> makePinkNoiseParamInfos( wxString aPrefix, wxString aUnit );
|
||||
static std::vector<PARAM::INFO> makeBurstNoiseParamInfos( wxString aPrefix, wxString aUnit );
|
||||
static std::vector<PARAM::INFO> makeRandomUniformParamInfos( wxString aPrefix, wxString aUnit );
|
||||
static std::vector<PARAM::INFO> makeRandomNormalParamInfos( wxString aPrefix, wxString aUnit );
|
||||
static std::vector<PARAM::INFO> makeRandomExpParamInfos( wxString aPrefix, wxString aUnit );
|
||||
static std::vector<PARAM::INFO> makeRandomPoissonParamInfos( wxString aPrefix, wxString aUnit );
|
||||
static std::vector<PARAM::INFO> makeDcParamInfos( std::string aPrefix, std::string aUnit );
|
||||
static std::vector<PARAM::INFO> makeSinParamInfos( std::string aPrefix, std::string aUnit );
|
||||
static std::vector<PARAM::INFO> makePulseParamInfos( std::string aPrefix, std::string aUnit );
|
||||
static std::vector<PARAM::INFO> makeExpParamInfos( std::string aPrefix, std::string aUnit );
|
||||
//static std::vector<PARAM::INFO> makeSfamParamInfos( std::string aPrefix, std::string aUnit );
|
||||
//static std::vector<PARAM::INFO> makeSffmParamInfos( std::string aPrefix, std::string aUnit );
|
||||
static std::vector<PARAM::INFO> makePwlParamInfos( std::string aPrefix, std::string aQuantity,
|
||||
std::string aUnit );
|
||||
static std::vector<PARAM::INFO> makeWhiteNoiseParamInfos( std::string aPrefix, std::string aUnit );
|
||||
static std::vector<PARAM::INFO> makePinkNoiseParamInfos( std::string aPrefix, std::string aUnit );
|
||||
static std::vector<PARAM::INFO> makeBurstNoiseParamInfos( std::string aPrefix, std::string aUnit );
|
||||
static std::vector<PARAM::INFO> makeRandomUniformParamInfos( std::string aPrefix, std::string aUnit );
|
||||
static std::vector<PARAM::INFO> makeRandomNormalParamInfos( std::string aPrefix, std::string aUnit );
|
||||
static std::vector<PARAM::INFO> makeRandomExpParamInfos( std::string aPrefix, std::string aUnit );
|
||||
static std::vector<PARAM::INFO> makeRandomPoissonParamInfos( std::string aPrefix, std::string aUnit );
|
||||
|
||||
static void appendAcParamInfos( std::vector<PARAM::INFO>& aParamInfos, wxString aUnit );
|
||||
static void appendAcParamInfos( std::vector<PARAM::INFO>& aParamInfos, std::string aUnit );
|
||||
|
||||
|
||||
bool m_isInferred;
|
||||
|
|
|
@ -25,13 +25,14 @@
|
|||
#include <sim/sim_model_spice.h>
|
||||
#include <sim/sim_model_raw_spice.h>
|
||||
#include <sim/spice_model_parser.h>
|
||||
|
||||
#include <confirm.h>
|
||||
|
||||
#include <boost/algorithm/string/trim.hpp>
|
||||
|
||||
wxString SPICE_GENERATOR_SPICE::Preview( const wxString& aModelName ) const
|
||||
|
||||
std::string SPICE_GENERATOR_SPICE::Preview( const std::string& aModelName ) const
|
||||
{
|
||||
wxString spiceCode = ModelLine( aModelName );
|
||||
std::string spiceCode = ModelLine( aModelName );
|
||||
|
||||
if( spiceCode == "" )
|
||||
spiceCode = static_cast<const SIM_MODEL_SPICE&>( m_model ).m_spiceCode;
|
||||
|
@ -39,16 +40,17 @@ wxString SPICE_GENERATOR_SPICE::Preview( const wxString& aModelName ) const
|
|||
if( spiceCode == "" && m_model.GetBaseModel() )
|
||||
spiceCode = static_cast<const SIM_MODEL_SPICE*>( m_model.GetBaseModel() )->m_spiceCode;
|
||||
|
||||
wxString itemLine = ItemLine( "", aModelName );
|
||||
if( spiceCode != "" )
|
||||
spiceCode << "\n";
|
||||
std::string itemLine = ItemLine( "", aModelName );
|
||||
|
||||
spiceCode << itemLine;
|
||||
return spiceCode.Trim();
|
||||
if( spiceCode != "" )
|
||||
spiceCode.append( "\n" );
|
||||
|
||||
spiceCode.append( itemLine );
|
||||
return boost::trim_copy( spiceCode );
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<SIM_MODEL_SPICE> SIM_MODEL_SPICE::Create( const wxString& aSpiceCode )
|
||||
std::unique_ptr<SIM_MODEL_SPICE> SIM_MODEL_SPICE::Create( const std::string& aSpiceCode )
|
||||
{
|
||||
auto model = static_cast<SIM_MODEL_SPICE*>(
|
||||
SIM_MODEL::Create( SPICE_MODEL_PARSER::ReadType( aSpiceCode ) ).release() );
|
||||
|
@ -83,7 +85,7 @@ SIM_MODEL_SPICE::SIM_MODEL_SPICE( TYPE aType,
|
|||
}
|
||||
|
||||
|
||||
bool SIM_MODEL_SPICE::SetParamValue( unsigned aParamIndex, const wxString& aParamValue,
|
||||
bool SIM_MODEL_SPICE::SetParamValue( unsigned aParamIndex, const std::string& aParamValue,
|
||||
SIM_VALUE_GRAMMAR::NOTATION aNotation )
|
||||
{
|
||||
// Models sourced from a library are immutable.
|
||||
|
@ -94,8 +96,8 @@ bool SIM_MODEL_SPICE::SetParamValue( unsigned aParamIndex, const wxString& aPara
|
|||
}
|
||||
|
||||
|
||||
bool SIM_MODEL_SPICE::SetParamFromSpiceCode( const wxString& aParamName,
|
||||
const wxString& aParamValue,
|
||||
bool SIM_MODEL_SPICE::SetParamFromSpiceCode( const std::string& aParamName,
|
||||
const std::string& aParamValue,
|
||||
SIM_VALUE_GRAMMAR::NOTATION aNotation )
|
||||
{
|
||||
return SIM_MODEL::SetParamValue( aParamName, aParamValue, aNotation );
|
||||
|
|
|
@ -35,7 +35,7 @@ class SPICE_GENERATOR_SPICE : public SPICE_GENERATOR
|
|||
public:
|
||||
using SPICE_GENERATOR::SPICE_GENERATOR;
|
||||
|
||||
wxString Preview( const wxString& aModelName ) const override;
|
||||
std::string Preview( const std::string& aModelName ) const override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -45,7 +45,7 @@ public:
|
|||
friend class SPICE_GENERATOR_SPICE;
|
||||
friend class SPICE_MODEL_PARSER;
|
||||
|
||||
static std::unique_ptr<SIM_MODEL_SPICE> Create( const wxString& aSpiceCode );
|
||||
static std::unique_ptr<SIM_MODEL_SPICE> Create( const std::string& aSpiceCode );
|
||||
|
||||
SIM_MODEL_SPICE( TYPE aType,
|
||||
std::unique_ptr<SPICE_GENERATOR> aSpiceGenerator );
|
||||
|
@ -55,15 +55,16 @@ public:
|
|||
std::unique_ptr<SPICE_MODEL_PARSER> aSpiceModelParser );
|
||||
|
||||
protected:
|
||||
bool SetParamValue( unsigned aParamIndex, const wxString& aParamValue,
|
||||
bool SetParamValue( unsigned aParamIndex, const std::string& aParamValue,
|
||||
SIM_VALUE_GRAMMAR::NOTATION aNotation
|
||||
= SIM_VALUE_GRAMMAR::NOTATION::SI ) override;
|
||||
|
||||
virtual bool SetParamFromSpiceCode( const wxString& aParamName, const wxString& aParamValue,
|
||||
virtual bool SetParamFromSpiceCode( const std::string& aParamName,
|
||||
const std::string& aParamValue,
|
||||
SIM_VALUE_GRAMMAR::NOTATION aNotation
|
||||
= SIM_VALUE_GRAMMAR::NOTATION::SPICE );
|
||||
|
||||
wxString m_spiceCode;
|
||||
std::string m_spiceCode;
|
||||
|
||||
private:
|
||||
std::unique_ptr<SPICE_MODEL_PARSER> m_spiceModelParser;
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
|
||||
#include <sim/sim_model_subckt.h>
|
||||
#include <sim/spice_grammar.h>
|
||||
|
||||
#include <fmt/core.h>
|
||||
#include <pegtl.hpp>
|
||||
#include <pegtl/contrib/parse_tree.hpp>
|
||||
|
||||
|
@ -46,30 +48,26 @@ namespace SIM_MODEL_SUBCKT_SPICE_PARSER
|
|||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR_SUBCKT::ModelLine( const wxString& aModelName ) const
|
||||
std::string SPICE_GENERATOR_SUBCKT::ModelLine( const std::string& aModelName ) const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
std::vector<wxString> SPICE_GENERATOR_SUBCKT::CurrentNames( const wxString& aRefName ) const
|
||||
std::vector<std::string> SPICE_GENERATOR_SUBCKT::CurrentNames( const std::string& aRefName ) const
|
||||
{
|
||||
std::vector<wxString> currentNames;
|
||||
std::vector<std::string> currentNames;
|
||||
|
||||
for( const SIM_MODEL::PIN& pin : GetPins() )
|
||||
{
|
||||
currentNames.push_back( wxString::Format( "I(%s:%s)",
|
||||
ItemName( aRefName ),
|
||||
pin.name ) );
|
||||
}
|
||||
currentNames.push_back( fmt::format( "I({:s}:{:s})", ItemName( aRefName ), pin.name ) );
|
||||
|
||||
return currentNames;
|
||||
}
|
||||
|
||||
|
||||
void SPICE_MODEL_PARSER_SUBCKT::ReadModel( const wxString& aSpiceCode )
|
||||
void SPICE_MODEL_PARSER_SUBCKT::ReadModel( const std::string& aSpiceCode )
|
||||
{
|
||||
tao::pegtl::string_input<> in( aSpiceCode.ToUTF8(), "from_content" );
|
||||
tao::pegtl::string_input<> in( aSpiceCode, "from_content" );
|
||||
std::unique_ptr<tao::pegtl::parse_tree::node> root;
|
||||
|
||||
try
|
||||
|
@ -98,7 +96,7 @@ void SPICE_MODEL_PARSER_SUBCKT::ReadModel( const wxString& aSpiceCode )
|
|||
}
|
||||
else if( subnode->is_type<SIM_MODEL_SUBCKT_SPICE_PARSER::dotSubcktPinName>() )
|
||||
{
|
||||
model.AddPin( { subnode->string(), wxString::FromCDouble( model.GetPinCount() + 1 ) } );
|
||||
model.AddPin( { subnode->string(), fmt::format( "{:d}", model.GetPinCount() + 1 ) } );
|
||||
}
|
||||
else if( subnode->is_type<SIM_MODEL_SUBCKT_SPICE_PARSER::dotSubcktParams>() )
|
||||
{
|
||||
|
|
|
@ -34,8 +34,8 @@ class SPICE_GENERATOR_SUBCKT : public SPICE_GENERATOR
|
|||
public:
|
||||
using SPICE_GENERATOR::SPICE_GENERATOR;
|
||||
|
||||
wxString ModelLine( const wxString& aModelName ) const override;
|
||||
std::vector<wxString> CurrentNames( const wxString& aRefName ) const override;
|
||||
std::string ModelLine( const std::string& aModelName ) const override;
|
||||
std::vector<std::string> CurrentNames( const std::string& aRefName ) const override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -44,7 +44,7 @@ class SPICE_MODEL_PARSER_SUBCKT : public SPICE_MODEL_PARSER
|
|||
public:
|
||||
using SPICE_MODEL_PARSER::SPICE_MODEL_PARSER;
|
||||
|
||||
void ReadModel( const wxString& aSpiceCode ) override;
|
||||
void ReadModel( const std::string& aSpiceCode ) override;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
/* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2022 Mikolaj Wielgus
|
||||
* Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
|
@ -24,32 +23,33 @@
|
|||
|
||||
#include <sim/sim_model_switch.h>
|
||||
|
||||
#include <fmt/core.h>
|
||||
|
||||
wxString SPICE_GENERATOR_SWITCH::ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const
|
||||
|
||||
std::string SPICE_GENERATOR_SWITCH::ItemLine( const std::string& aRefName,
|
||||
const std::string& aModelName,
|
||||
const std::vector<std::string>& aSymbolPinNumbers,
|
||||
const std::vector<std::string>& aPinNetNames ) const
|
||||
{
|
||||
wxString result;
|
||||
std::string result;
|
||||
|
||||
switch( m_model.GetType() )
|
||||
{
|
||||
case SIM_MODEL::TYPE::SW_V:
|
||||
{
|
||||
result << SPICE_GENERATOR::ItemLine( aRefName, aModelName, aSymbolPinNumbers,
|
||||
aPinNetNames );
|
||||
result = SPICE_GENERATOR::ItemLine( aRefName, aModelName, aSymbolPinNumbers, aPinNetNames );
|
||||
break;
|
||||
}
|
||||
|
||||
case SIM_MODEL::TYPE::SW_I:
|
||||
{
|
||||
wxString vsourceName = "V__" + aRefName;
|
||||
std::string vsourceName = "V__" + aRefName;
|
||||
|
||||
// Current switches measure input current through a voltage source.
|
||||
result << vsourceName << " " << aPinNetNames[0] << " " << aPinNetNames[1] << " 0\n";
|
||||
|
||||
result << SPICE_GENERATOR::ItemLine( aRefName, vsourceName + " " + aModelName,
|
||||
aSymbolPinNumbers, aPinNetNames );
|
||||
result.append( fmt::format( "{0} {1} 0\n", aPinNetNames[0], aPinNetNames[1] ) );
|
||||
result.append( SPICE_GENERATOR::ItemLine( aRefName, fmt::format( "{0} {1}",
|
||||
vsourceName, aModelName ),
|
||||
aSymbolPinNumbers, aPinNetNames ) );
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -62,19 +62,17 @@ wxString SPICE_GENERATOR_SWITCH::ItemLine( const wxString& aRefName,
|
|||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR_SWITCH::ItemParams() const
|
||||
std::string SPICE_GENERATOR_SWITCH::ItemParams() const
|
||||
{
|
||||
wxString result;
|
||||
std::string result;
|
||||
|
||||
for( const SIM_MODEL::PARAM& param : GetInstanceParams() )
|
||||
{
|
||||
// The only instance param is "ic", which is positional.
|
||||
wxString value = param.value->ToSpiceString();
|
||||
std::string value = param.value->ToSpiceString();
|
||||
|
||||
if( value == "none" )
|
||||
result << "";
|
||||
else
|
||||
result << value;
|
||||
if( value != "none" )
|
||||
result.append( value );
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -125,7 +123,7 @@ SIM_MODEL_SWITCH::SIM_MODEL_SWITCH( TYPE aType ) :
|
|||
}
|
||||
|
||||
|
||||
wxString SIM_MODEL_SWITCH::GenerateParamValuePair( const PARAM& aParam, bool& aIsFirst ) const
|
||||
std::string SIM_MODEL_SWITCH::GenerateParamValuePair( const PARAM& aParam, bool& aIsFirst ) const
|
||||
{
|
||||
if( aParam.info.name == "ic" && aParam.value->ToString() == "none" )
|
||||
{
|
||||
|
|
|
@ -34,10 +34,10 @@ class SPICE_GENERATOR_SWITCH : public SPICE_GENERATOR
|
|||
public:
|
||||
using SPICE_GENERATOR::SPICE_GENERATOR;
|
||||
|
||||
wxString ItemLine( const wxString& aRefName, const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const override;
|
||||
wxString ItemParams() const override;
|
||||
std::string ItemLine( const std::string& aRefName, const std::string& aModelName,
|
||||
const std::vector<std::string>& aSymbolPinNumbers,
|
||||
const std::vector<std::string>& aPinNetNames ) const override;
|
||||
std::string ItemParams() const override;
|
||||
std::vector<std::reference_wrapper<const SIM_MODEL::PIN>> GetPins() const override;
|
||||
};
|
||||
|
||||
|
@ -48,10 +48,10 @@ public:
|
|||
SIM_MODEL_SWITCH( TYPE aType );
|
||||
|
||||
protected:
|
||||
wxString GenerateParamValuePair( const PARAM& aParam, bool& aIsFirst ) const override;
|
||||
std::string GenerateParamValuePair( const PARAM& aParam, bool& aIsFirst ) const override;
|
||||
|
||||
private:
|
||||
std::vector<wxString> getPinNames() const override
|
||||
std::vector<std::string> getPinNames() const override
|
||||
{
|
||||
return { "ctrl+", "ctrl-", "no+", "no-" };
|
||||
}
|
||||
|
|
|
@ -23,14 +23,15 @@
|
|||
*/
|
||||
|
||||
#include <sim/sim_model_tline.h>
|
||||
#include <locale_io.h>
|
||||
|
||||
#include <fmt/core.h>
|
||||
|
||||
using PARAM = SIM_MODEL::PARAM;
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR_TLINE::ModelLine( const wxString& aModelName ) const
|
||||
std::string SPICE_GENERATOR_TLINE::ModelLine( const std::string& aModelName ) const
|
||||
{
|
||||
wxString r, l, g, c, len;
|
||||
std::string r, l, g, c, len;
|
||||
|
||||
switch( m_model.GetType() )
|
||||
{
|
||||
|
@ -40,7 +41,7 @@ wxString SPICE_GENERATOR_TLINE::ModelLine( const wxString& aModelName ) const
|
|||
auto td = static_cast<const SIM_VALUE_FLOAT&>( *m_model.FindParam( "td" )->value );
|
||||
|
||||
if( !z0.HasValue() || !td.HasValue() )
|
||||
return wxString::Format( ".model %s LTRA()\n", aModelName );
|
||||
return fmt::format( ".model {} LTRA()\n", aModelName );
|
||||
|
||||
r = SIM_VALUE_FLOAT( 0 ).ToSpiceString();
|
||||
l = ( td * z0 ).ToSpiceString();
|
||||
|
@ -63,8 +64,8 @@ wxString SPICE_GENERATOR_TLINE::ModelLine( const wxString& aModelName ) const
|
|||
return "";
|
||||
}
|
||||
|
||||
return wxString::Format( ".model %s LTRA( r=%s l=%s g=%s c=%s len=%s )\n",
|
||||
aModelName, r, l, g, c, len );
|
||||
return fmt::format( ".model {} LTRA( r={} l={} g={} c={} len={} )\n",
|
||||
aModelName, r, l, g, c, len );
|
||||
}
|
||||
|
||||
|
||||
|
@ -116,7 +117,7 @@ void SIM_MODEL_TLINE::WriteDataLibFields( std::vector<LIB_FIELD>& aFields ) cons
|
|||
template <typename T>
|
||||
void SIM_MODEL_TLINE::inferredWriteDataFields( std::vector<T>& aFields ) const
|
||||
{
|
||||
wxString value = GetFieldValue( &aFields, PARAMS_FIELD );
|
||||
std::string value = GetFieldValue( &aFields, PARAMS_FIELD );
|
||||
|
||||
if( value == "" )
|
||||
value = GetDeviceTypeInfo().fieldValue;
|
||||
|
|
|
@ -34,7 +34,7 @@ class SPICE_GENERATOR_TLINE : public SPICE_GENERATOR
|
|||
public:
|
||||
using SPICE_GENERATOR::SPICE_GENERATOR;
|
||||
|
||||
wxString ModelLine( const wxString& aModelName ) const override;
|
||||
std::string ModelLine( const std::string& aModelName ) const override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -53,7 +53,7 @@ private:
|
|||
template <typename T>
|
||||
void inferredWriteDataFields( std::vector<T>& aFields ) const;
|
||||
|
||||
std::vector<wxString> getPinNames() const override { return { "1+", "1-", "2+", "2-" }; }
|
||||
std::vector<std::string> getPinNames() const override { return { "1+", "1-", "2+", "2-" }; }
|
||||
|
||||
static std::vector<PARAM::INFO> makeZ0ParamInfos();
|
||||
static std::vector<PARAM::INFO> makeRlgcParamInfos();
|
||||
|
|
|
@ -391,7 +391,7 @@ bool SIM_STRING_PROPERTY::StringToValue( wxVariant& aVariant, const wxString& aT
|
|||
}
|
||||
else
|
||||
{
|
||||
m_model->SetParamValue( m_paramIndex, aText );
|
||||
m_model->SetParamValue( m_paramIndex, std::string( aText.ToUTF8() ) );
|
||||
aVariant = GetParam().value->ToString();
|
||||
}
|
||||
|
||||
|
@ -399,6 +399,17 @@ bool SIM_STRING_PROPERTY::StringToValue( wxVariant& aVariant, const wxString& aT
|
|||
}
|
||||
|
||||
|
||||
static wxArrayString convertStringsToWx( const std::vector<std::string>& aStrings )
|
||||
{
|
||||
wxArrayString result;
|
||||
|
||||
for( const std::string& string : aStrings )
|
||||
result.Add( string );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
SIM_ENUM_PROPERTY::SIM_ENUM_PROPERTY( const wxString& aLabel, const wxString& aName,
|
||||
std::shared_ptr<SIM_LIBRARY> aLibrary,
|
||||
std::shared_ptr<SIM_MODEL> aModel,
|
||||
|
@ -406,8 +417,7 @@ SIM_ENUM_PROPERTY::SIM_ENUM_PROPERTY( const wxString& aLabel, const wxString& aN
|
|||
SIM_VALUE::TYPE aValueType,
|
||||
SIM_VALUE_GRAMMAR::NOTATION aNotation )
|
||||
: wxEnumProperty( aLabel, aName,
|
||||
wxArrayString( aModel->GetParam( aParamIndex ).info.enumValues.size(),
|
||||
&aModel->GetParam( aParamIndex ).info.enumValues[0] ) ),
|
||||
convertStringsToWx( aModel->GetParam( aParamIndex ).info.enumValues ) ),
|
||||
SIM_PROPERTY( aLibrary, aModel, aParamIndex )
|
||||
{
|
||||
auto it = std::find( GetParam().info.enumValues.begin(), GetParam().info.enumValues.end(),
|
||||
|
|
|
@ -69,7 +69,7 @@ private:
|
|||
SIM_VALUE_GRAMMAR::NOTATION m_notation;
|
||||
wxString m_prevText;
|
||||
long m_prevInsertionPoint;
|
||||
|
||||
|
||||
wxDECLARE_EVENT_TABLE();
|
||||
};
|
||||
|
||||
|
@ -112,7 +112,7 @@ public:
|
|||
int aParamIndex );
|
||||
|
||||
wxValidator* DoGetValidator() const override;
|
||||
|
||||
|
||||
void OnSetValue() override;
|
||||
};
|
||||
|
||||
|
|
|
@ -23,61 +23,63 @@
|
|||
*/
|
||||
|
||||
#include <sim/spice_generator.h>
|
||||
#include <locale_io.h>
|
||||
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/algorithm/string/trim.hpp>
|
||||
#include <fmt/core.h>
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ModelLine( const wxString& aModelName ) const
|
||||
std::string SPICE_GENERATOR::ModelLine( const std::string& aModelName ) const
|
||||
{
|
||||
LOCALE_IO toggle;
|
||||
|
||||
if( !m_model.HasSpiceNonInstanceOverrides() && !m_model.requiresSpiceModelLine() )
|
||||
return "";
|
||||
|
||||
wxString result = "";
|
||||
std::string result = "";
|
||||
|
||||
result << wxString::Format( ".model %s ", aModelName );
|
||||
size_t indentLength = result.Length();
|
||||
result.append( fmt::format( ".model {} ", aModelName ) );
|
||||
size_t indentLength = result.length();
|
||||
|
||||
result << wxString::Format( "%s \n", m_model.GetSpiceInfo().modelType );
|
||||
result.append( fmt::format( "{}\n", m_model.GetSpiceInfo().modelType ) );
|
||||
|
||||
for( const SIM_MODEL::PARAM& param : m_model.GetParams() )
|
||||
{
|
||||
if( param.info.isSpiceInstanceParam )
|
||||
continue;
|
||||
|
||||
wxString name = ( param.info.spiceModelName == "" ) ?
|
||||
std::string name = ( param.info.spiceModelName == "" ) ?
|
||||
param.info.name : param.info.spiceModelName;
|
||||
wxString value = param.value->ToSpiceString();
|
||||
std::string value = param.value->ToSpiceString();
|
||||
|
||||
if( value == "" )
|
||||
continue;
|
||||
|
||||
result << wxString::Format( "+%s%s=%s\n", wxString( ' ', indentLength - 1 ), name, value );
|
||||
result.append( fmt::format( "+{}{}={}\n", std::string( indentLength - 1, ' ' ),
|
||||
name, value ) );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName ) const
|
||||
std::string SPICE_GENERATOR::ItemLine( const std::string& aRefName,
|
||||
const std::string& aModelName ) const
|
||||
{
|
||||
// Use linear symbol pin numbers enumeration. Used in model preview.
|
||||
|
||||
std::vector<wxString> pinNumbers;
|
||||
std::vector<std::string> pinNumbers;
|
||||
|
||||
for( int i = 0; i < m_model.GetPinCount(); ++i )
|
||||
pinNumbers.push_back( wxString::FromCDouble( i + 1 ) );
|
||||
pinNumbers.push_back( fmt::format( "{}", i + 1 ) );
|
||||
|
||||
return ItemLine( aRefName, aModelName, pinNumbers );
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers ) const
|
||||
std::string SPICE_GENERATOR::ItemLine( const std::string& aRefName,
|
||||
const std::string& aModelName,
|
||||
const std::vector<std::string>& aSymbolPinNumbers ) const
|
||||
{
|
||||
std::vector<wxString> pinNetNames;
|
||||
std::vector<std::string> pinNetNames;
|
||||
|
||||
for( const SIM_MODEL::PIN& pin : GetPins() )
|
||||
pinNetNames.push_back( pin.name );
|
||||
|
@ -86,36 +88,36 @@ wxString SPICE_GENERATOR::ItemLine( const wxString& aRefName,
|
|||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const
|
||||
std::string SPICE_GENERATOR::ItemLine( const std::string& aRefName,
|
||||
const std::string& aModelName,
|
||||
const std::vector<std::string>& aSymbolPinNumbers,
|
||||
const std::vector<std::string>& aPinNetNames ) const
|
||||
{
|
||||
wxString result;
|
||||
result << ItemName( aRefName );
|
||||
result << ItemPins( aRefName, aModelName, aSymbolPinNumbers, aPinNetNames );
|
||||
result << ItemModelName( aModelName );
|
||||
result << ItemParams();
|
||||
result << "\n";
|
||||
std::string result;
|
||||
result.append( ItemName( aRefName ) );
|
||||
result.append( ItemPins( aRefName, aModelName, aSymbolPinNumbers, aPinNetNames ) );
|
||||
result.append( ItemModelName( aModelName ) );
|
||||
result.append( ItemParams() );
|
||||
result.append( "\n" );
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ItemName( const wxString& aRefName ) const
|
||||
std::string SPICE_GENERATOR::ItemName( const std::string& aRefName ) const
|
||||
{
|
||||
if( aRefName != "" && aRefName.StartsWith( m_model.GetSpiceInfo().itemType ) )
|
||||
if( aRefName != "" && boost::starts_with( aRefName, m_model.GetSpiceInfo().itemType ) )
|
||||
return aRefName;
|
||||
else
|
||||
return m_model.GetSpiceInfo().itemType + aRefName;
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ItemPins( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const
|
||||
std::string SPICE_GENERATOR::ItemPins( const std::string& aRefName,
|
||||
const std::string& aModelName,
|
||||
const std::vector<std::string>& aSymbolPinNumbers,
|
||||
const std::vector<std::string>& aPinNetNames ) const
|
||||
{
|
||||
wxString result;
|
||||
std::string result;
|
||||
int ncCounter = 0;
|
||||
|
||||
for( const SIM_MODEL::PIN& pin : GetPins() )
|
||||
|
@ -124,14 +126,11 @@ wxString SPICE_GENERATOR::ItemPins( const wxString& aRefName,
|
|||
pin.symbolPinNumber );
|
||||
|
||||
if( it == aSymbolPinNumbers.end() )
|
||||
{
|
||||
LOCALE_IO toggle;
|
||||
result << wxString::Format( " NC-%s-%u", aRefName, ncCounter++ );
|
||||
}
|
||||
result.append( fmt::format( " NC-{}-{}", aRefName, ncCounter++ ) );
|
||||
else
|
||||
{
|
||||
long symbolPinIndex = std::distance( aSymbolPinNumbers.begin(), it );
|
||||
result << " " << aPinNetNames.at( symbolPinIndex );
|
||||
result.append( " " + aPinNetNames.at( symbolPinIndex ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,54 +138,53 @@ wxString SPICE_GENERATOR::ItemPins( const wxString& aRefName,
|
|||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ItemModelName( const wxString& aModelName ) const
|
||||
std::string SPICE_GENERATOR::ItemModelName( const std::string& aModelName ) const
|
||||
{
|
||||
return " " + aModelName;
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::ItemParams() const
|
||||
std::string SPICE_GENERATOR::ItemParams() const
|
||||
{
|
||||
wxString result;
|
||||
std::string result;
|
||||
|
||||
for( const SIM_MODEL::PARAM& param : GetInstanceParams() )
|
||||
{
|
||||
wxString name = ( param.info.spiceInstanceName == "" ) ?
|
||||
std::string name = ( param.info.spiceInstanceName == "" ) ?
|
||||
param.info.name : param.info.spiceInstanceName;
|
||||
wxString value = param.value->ToSpiceString();
|
||||
std::string value = param.value->ToSpiceString();
|
||||
|
||||
if( value != "" )
|
||||
result << " " << name << "=" << value;
|
||||
result.append( fmt::format( " {}={}", name, value ) );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::TuningLine( const wxString& aSymbol ) const
|
||||
std::string SPICE_GENERATOR::TuningLine( const std::string& aSymbol ) const
|
||||
{
|
||||
// TODO.
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
std::vector<wxString> SPICE_GENERATOR::CurrentNames( const wxString& aRefName ) const
|
||||
std::vector<std::string> SPICE_GENERATOR::CurrentNames( const std::string& aRefName ) const
|
||||
{
|
||||
LOCALE_IO toggle;
|
||||
return { wxString::Format( "I(%s)", ItemName( aRefName ) ) };
|
||||
return { fmt::format( "I({})", ItemName( aRefName ) ) };
|
||||
}
|
||||
|
||||
|
||||
wxString SPICE_GENERATOR::Preview( const wxString& aModelName ) const
|
||||
std::string SPICE_GENERATOR::Preview( const std::string& aModelName ) const
|
||||
{
|
||||
wxString spiceCode = ModelLine( aModelName );
|
||||
std::string spiceCode = ModelLine( aModelName );
|
||||
|
||||
wxString itemLine = ItemLine( "", aModelName );
|
||||
std::string itemLine = ItemLine( "", aModelName );
|
||||
if( spiceCode != "" )
|
||||
spiceCode << "\n";
|
||||
spiceCode.append( "\n" );
|
||||
|
||||
spiceCode << itemLine;
|
||||
return spiceCode.Trim();
|
||||
spiceCode.append( itemLine );
|
||||
return boost::trim_copy( spiceCode );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -33,30 +33,30 @@ class SPICE_GENERATOR
|
|||
public:
|
||||
SPICE_GENERATOR( const SIM_MODEL& aModel ) : m_model( aModel ) {}
|
||||
|
||||
virtual wxString ModelLine( const wxString& aModelName ) const;
|
||||
virtual std::string ModelLine( const std::string& aModelName ) const;
|
||||
|
||||
wxString ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName ) const;
|
||||
wxString ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers ) const;
|
||||
virtual wxString ItemLine( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const;
|
||||
virtual wxString ItemName( const wxString& aRefName ) const;
|
||||
virtual wxString ItemPins( const wxString& aRefName,
|
||||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers,
|
||||
const std::vector<wxString>& aPinNetNames ) const;
|
||||
virtual wxString ItemModelName( const wxString& aModelName ) const;
|
||||
virtual wxString ItemParams() const;
|
||||
std::string ItemLine( const std::string& aRefName,
|
||||
const std::string& aModelName ) const;
|
||||
std::string ItemLine( const std::string& aRefName,
|
||||
const std::string& aModelName,
|
||||
const std::vector<std::string>& aSymbolPinNumbers ) const;
|
||||
virtual std::string ItemLine( const std::string& aRefName,
|
||||
const std::string& aModelName,
|
||||
const std::vector<std::string>& aSymbolPinNumbers,
|
||||
const std::vector<std::string>& aPinNetNames ) const;
|
||||
virtual std::string ItemName( const std::string& aRefName ) const;
|
||||
virtual std::string ItemPins( const std::string& aRefName,
|
||||
const std::string& aModelName,
|
||||
const std::vector<std::string>& aSymbolPinNumbers,
|
||||
const std::vector<std::string>& aPinNetNames ) const;
|
||||
virtual std::string ItemModelName( const std::string& aModelName ) const;
|
||||
virtual std::string ItemParams() const;
|
||||
|
||||
virtual wxString TuningLine( const wxString& aSymbol ) const;
|
||||
|
||||
virtual std::vector<wxString> CurrentNames( const wxString& aRefName ) const;
|
||||
virtual std::string TuningLine( const std::string& aSymbol ) const;
|
||||
|
||||
virtual wxString Preview( const wxString& aModelName ) const;
|
||||
virtual std::vector<std::string> CurrentNames( const std::string& aRefName ) const;
|
||||
|
||||
virtual std::string Preview( const std::string& aModelName ) const;
|
||||
|
||||
protected:
|
||||
virtual std::vector<std::reference_wrapper<const SIM_MODEL::PIN>> GetPins() const
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include <sim/spice_grammar.h>
|
||||
#include <sim/sim_model_spice.h>
|
||||
|
||||
#include <boost/algorithm/string/case_conv.hpp>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <pegtl.hpp>
|
||||
#include <pegtl/contrib/parse_tree.hpp>
|
||||
|
||||
|
@ -46,9 +48,9 @@ namespace SIM_MODEL_SPICE_PARSER
|
|||
}
|
||||
|
||||
|
||||
SIM_MODEL::TYPE SPICE_MODEL_PARSER::ReadType( const wxString& aSpiceCode )
|
||||
SIM_MODEL::TYPE SPICE_MODEL_PARSER::ReadType( const std::string& aSpiceCode )
|
||||
{
|
||||
tao::pegtl::string_input<> in( aSpiceCode.ToUTF8(), "Spice_Code" );
|
||||
tao::pegtl::string_input<> in( aSpiceCode, "Spice_Code" );
|
||||
std::unique_ptr<tao::pegtl::parse_tree::node> root;
|
||||
|
||||
try
|
||||
|
@ -69,10 +71,10 @@ SIM_MODEL::TYPE SPICE_MODEL_PARSER::ReadType( const wxString& aSpiceCode )
|
|||
{
|
||||
if( node->is_type<SIM_MODEL_SPICE_PARSER::dotModel>() )
|
||||
{
|
||||
wxString paramName;
|
||||
wxString typeString;
|
||||
wxString level;
|
||||
wxString version;
|
||||
std::string paramName;
|
||||
std::string typeString;
|
||||
std::string level;
|
||||
std::string version;
|
||||
|
||||
for( const auto& subnode : node->children )
|
||||
{
|
||||
|
@ -128,12 +130,12 @@ SIM_MODEL::TYPE SPICE_MODEL_PARSER::ReadType( const wxString& aSpiceCode )
|
|||
}
|
||||
|
||||
|
||||
void SPICE_MODEL_PARSER::ReadModel( const wxString& aSpiceCode )
|
||||
void SPICE_MODEL_PARSER::ReadModel( const std::string& aSpiceCode )
|
||||
{
|
||||
// The default behavior is to treat the Spice param=value pairs as the model parameters and
|
||||
// values (for many models the correspondence is not exact, so this function is overridden).
|
||||
|
||||
tao::pegtl::string_input<> in( aSpiceCode.ToUTF8(), "Spice_Code" );
|
||||
tao::pegtl::string_input<> in( aSpiceCode, "Spice_Code" );
|
||||
std::unique_ptr<tao::pegtl::parse_tree::node> root;
|
||||
|
||||
try
|
||||
|
@ -153,7 +155,7 @@ void SPICE_MODEL_PARSER::ReadModel( const wxString& aSpiceCode )
|
|||
{
|
||||
if( node->is_type<SIM_MODEL_SPICE_PARSER::dotModel>() )
|
||||
{
|
||||
wxString paramName = "";
|
||||
std::string paramName = "";
|
||||
|
||||
for( const auto& subnode : node->children )
|
||||
{
|
||||
|
@ -171,7 +173,7 @@ void SPICE_MODEL_PARSER::ReadModel( const wxString& aSpiceCode )
|
|||
}
|
||||
else if( subnode->is_type<SIM_MODEL_SPICE_PARSER::paramValue>() )
|
||||
{
|
||||
wxASSERT( !paramName.IsEmpty() );
|
||||
wxASSERT( paramName != "" );
|
||||
|
||||
if( !m_model.SetParamFromSpiceCode( paramName, subnode->string() ) )
|
||||
{
|
||||
|
@ -197,26 +199,25 @@ void SPICE_MODEL_PARSER::ReadModel( const wxString& aSpiceCode )
|
|||
}
|
||||
|
||||
|
||||
SIM_MODEL::TYPE SPICE_MODEL_PARSER::ReadTypeFromSpiceStrings( const wxString& aTypeString,
|
||||
const wxString& aLevel,
|
||||
const wxString& aVersion,
|
||||
SIM_MODEL::TYPE SPICE_MODEL_PARSER::ReadTypeFromSpiceStrings( const std::string& aTypeString,
|
||||
const std::string& aLevel,
|
||||
const std::string& aVersion,
|
||||
bool aSkipDefaultLevel )
|
||||
{
|
||||
std::unique_ptr<SIM_VALUE> readLevel = SIM_VALUE::Create( SIM_VALUE::TYPE_INT,
|
||||
aLevel.ToStdString() );
|
||||
std::unique_ptr<SIM_VALUE> readLevel = SIM_VALUE::Create( SIM_VALUE::TYPE_INT, aLevel );
|
||||
|
||||
for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
|
||||
{
|
||||
wxString typePrefix = SIM_MODEL::SpiceInfo( type ).modelType;
|
||||
wxString level = SIM_MODEL::SpiceInfo( type ).level;
|
||||
wxString version = SIM_MODEL::SpiceInfo( type ).version;
|
||||
std::string typePrefix = SIM_MODEL::SpiceInfo( type ).modelType;
|
||||
std::string level = SIM_MODEL::SpiceInfo( type ).level;
|
||||
std::string version = SIM_MODEL::SpiceInfo( type ).version;
|
||||
bool isDefaultLevel = SIM_MODEL::SpiceInfo( type ).isDefaultLevel;
|
||||
|
||||
if( typePrefix == "" )
|
||||
continue;
|
||||
|
||||
// Check if `aTypeString` starts with `typePrefix`.
|
||||
if( aTypeString.Upper().StartsWith( typePrefix )
|
||||
if( boost::starts_with( boost::to_upper_copy( aTypeString ), typePrefix )
|
||||
&& ( level == readLevel->ToString()
|
||||
|| ( !aSkipDefaultLevel && isDefaultLevel && aLevel == "" ) )
|
||||
&& version == aVersion )
|
||||
|
|
|
@ -33,16 +33,16 @@ class SIM_MODEL_SPICE;
|
|||
class SPICE_MODEL_PARSER
|
||||
{
|
||||
public:
|
||||
static SIM_MODEL::TYPE ReadType( const wxString& aSpiceCode );
|
||||
static SIM_MODEL::TYPE ReadType( const std::string& aSpiceCode );
|
||||
|
||||
SPICE_MODEL_PARSER( SIM_MODEL_SPICE& aModel ) : m_model( aModel ) {}
|
||||
|
||||
virtual void ReadModel( const wxString& aSpiceCode );
|
||||
virtual void ReadModel( const std::string& aSpiceCode );
|
||||
|
||||
protected:
|
||||
static SIM_MODEL::TYPE ReadTypeFromSpiceStrings( const wxString& aTypeString,
|
||||
const wxString& aLevel = "",
|
||||
const wxString& aVersion = "",
|
||||
static SIM_MODEL::TYPE ReadTypeFromSpiceStrings( const std::string& aTypeString,
|
||||
const std::string& aLevel = "",
|
||||
const std::string& aVersion = "",
|
||||
bool aSkipDefaultLevel = true );
|
||||
|
||||
SIM_MODEL_SPICE& m_model;
|
||||
|
|
|
@ -797,7 +797,7 @@ int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent )
|
|||
|
||||
try
|
||||
{
|
||||
library = SIM_LIBRARY::Create( path );
|
||||
library = SIM_LIBRARY::Create( std::string( path.ToUTF8() ) );
|
||||
}
|
||||
catch( const IO_ERROR& e )
|
||||
{
|
||||
|
@ -810,7 +810,7 @@ int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent )
|
|||
if( !nameField )
|
||||
return true;
|
||||
|
||||
SIM_MODEL* baseModel = library->FindModel( nameField->GetShownText() );
|
||||
SIM_MODEL* baseModel = library->FindModel( std::string( nameField->GetShownText().ToUTF8() ) );
|
||||
|
||||
if( !baseModel )
|
||||
return true;
|
||||
|
@ -823,8 +823,8 @@ int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent )
|
|||
model = SIM_MODEL::Create( static_cast<int>( pins.size() ),
|
||||
symbol->GetFields() );
|
||||
|
||||
wxString ref = symbol->GetRef( &m_frame->GetCurrentSheet() );
|
||||
std::vector<wxString> currentNames = model->SpiceGenerator().CurrentNames( ref );
|
||||
auto ref = std::string( symbol->GetRef( &m_frame->GetCurrentSheet() ).ToUTF8() );
|
||||
std::vector<std::string> currentNames = model->SpiceGenerator().CurrentNames( ref );
|
||||
|
||||
if( currentNames.size() == 0 )
|
||||
return true;
|
||||
|
@ -834,7 +834,7 @@ int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent )
|
|||
return true;
|
||||
}
|
||||
|
||||
int modelPinIndex = model->FindModelPinIndex( pin->GetNumber() );
|
||||
int modelPinIndex = model->FindModelPinIndex( std::string( pin->GetNumber().ToUTF8() ) );
|
||||
|
||||
if( modelPinIndex != SIM_MODEL::PIN::NOT_CONNECTED )
|
||||
{
|
||||
|
@ -846,7 +846,7 @@ int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent )
|
|||
{
|
||||
if( SCH_CONNECTION* conn = static_cast<SCH_ITEM*>( item )->Connection() )
|
||||
{
|
||||
wxString spiceNet = UnescapeString( conn->Name() );
|
||||
std::string spiceNet = std::string( UnescapeString( conn->Name() ).ToUTF8() );
|
||||
NETLIST_EXPORTER_SPICE::ReplaceForbiddenChars( spiceNet );
|
||||
|
||||
simFrame->AddVoltagePlot( wxString::Format( "V(%s)", spiceNet ) );
|
||||
|
|
|
@ -25,11 +25,14 @@
|
|||
#include <eeschema_test_utils.h>
|
||||
#include <sim/sim_library_spice.h>
|
||||
|
||||
#include <boost/algorithm/string/case_conv.hpp>
|
||||
#include <fmt/core.h>
|
||||
|
||||
|
||||
class TEST_SIM_LIBRARY_SPICE_FIXTURE
|
||||
{
|
||||
public:
|
||||
wxString GetLibraryPath( const wxString& aBaseName )
|
||||
std::string GetLibraryPath( const std::string& aBaseName )
|
||||
{
|
||||
wxFileName fn = KI_TEST::GetEeschemaTestDataDir();
|
||||
fn.AppendDir( "spice_netlists" );
|
||||
|
@ -37,22 +40,23 @@ public:
|
|||
fn.SetName( aBaseName );
|
||||
fn.SetExt( "lib.spice" );
|
||||
|
||||
return fn.GetFullPath();
|
||||
return std::string( fn.GetFullPath().ToUTF8() );
|
||||
}
|
||||
|
||||
void LoadLibrary( const wxString& aBaseName )
|
||||
void LoadLibrary( const std::string& aBaseName )
|
||||
{
|
||||
wxString path = GetLibraryPath( aBaseName );
|
||||
std::string path = GetLibraryPath( aBaseName );
|
||||
m_library = std::make_unique<SIM_LIBRARY_SPICE>();
|
||||
m_library->ReadFile( path );
|
||||
}
|
||||
|
||||
void CompareToUsualDiodeModel( const SIM_MODEL& aModel, const wxString& aModelName, int aModelIndex )
|
||||
void CompareToUsualDiodeModel( const SIM_MODEL& aModel, const std::string& aModelName, int aModelIndex )
|
||||
{
|
||||
BOOST_CHECK( aModel.GetType() == SIM_MODEL::TYPE::D );
|
||||
BOOST_CHECK_EQUAL( aModelName, aModel.GetSpiceInfo().modelType.Upper()
|
||||
+ wxString::FromCDouble( aModelIndex )
|
||||
+ "_Usual" );
|
||||
BOOST_CHECK_EQUAL( aModelName,
|
||||
fmt::format( "{}{}_Usual",
|
||||
boost::to_upper_copy( aModel.GetSpiceInfo().modelType ),
|
||||
aModelIndex ) );
|
||||
BOOST_CHECK_EQUAL( aModel.FindParam( "bv" )->value->ToString(), "1.1u" );
|
||||
BOOST_CHECK_EQUAL( aModel.FindParam( "cjo" )->value->ToString(), "2.2m" );
|
||||
BOOST_CHECK_EQUAL( aModel.FindParam( "ibv" )->value->ToString(), "3.3" );
|
||||
|
@ -61,13 +65,14 @@ public:
|
|||
BOOST_CHECK_EQUAL( aModel.FindParam( "n" )->value->ToString(), "6.6G" );
|
||||
}
|
||||
|
||||
void CompareToEmptyModel( const SIM_MODEL& aModel, const wxString& aModelName, int aModelIndex )
|
||||
void CompareToEmptyModel( const SIM_MODEL& aModel, const std::string& aModelName, int aModelIndex )
|
||||
{
|
||||
BOOST_TEST_CONTEXT( "Model index: " << aModelIndex )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( aModelName, aModel.GetSpiceInfo().modelType.Upper()
|
||||
+ wxString::FromCDouble( aModelIndex )
|
||||
+ "_Empty" );
|
||||
BOOST_CHECK_EQUAL( aModelName,
|
||||
fmt::format( "{}{}_Empty",
|
||||
boost::to_upper_copy( aModel.GetSpiceInfo().modelType ),
|
||||
aModelIndex ) );
|
||||
|
||||
for( unsigned i = 0; i < aModel.GetParamCount(); ++i )
|
||||
{
|
||||
|
@ -79,8 +84,8 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void TestTransistor( const SIM_MODEL& aModel, const wxString& aModelName, int aModelIndex,
|
||||
SIM_MODEL::TYPE aType, const std::vector<wxString>& aParamNames )
|
||||
void TestTransistor( const SIM_MODEL& aModel, const std::string& aModelName, int aModelIndex,
|
||||
SIM_MODEL::TYPE aType, const std::vector<std::string>& aParamNames )
|
||||
{
|
||||
BOOST_TEST_CONTEXT( "Model index: " << aModelIndex
|
||||
<< ", Model name: " << aModelName
|
||||
|
@ -88,25 +93,24 @@ public:
|
|||
<< ", Model type: " << aModel.GetTypeInfo().fieldValue )
|
||||
{
|
||||
BOOST_CHECK( aModel.GetType() == aType );
|
||||
BOOST_CHECK_EQUAL( aModelName, "_" + wxString::FromCDouble( aModelIndex )
|
||||
+ "_" + aModel.GetSpiceInfo().modelType.Upper()
|
||||
+ "_" + aModel.GetTypeInfo().fieldValue );
|
||||
BOOST_CHECK_EQUAL( aModelName,
|
||||
fmt::format( "_{}_{}_{}",
|
||||
aModelIndex,
|
||||
boost::to_upper_copy( aModel.GetSpiceInfo().modelType ),
|
||||
aModel.GetTypeInfo().fieldValue ) );
|
||||
|
||||
for( int i = 0; i < aParamNames.size(); ++i )
|
||||
{
|
||||
wxString paramName = aParamNames.at( i );
|
||||
std::string paramName = aParamNames.at( i );
|
||||
|
||||
BOOST_TEST_CONTEXT( "Param name: " << paramName )
|
||||
{
|
||||
if( i == 0 )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( aModel.FindParam( paramName )->value->ToString(), "0" );
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_CHECK_EQUAL( aModel.FindParam( paramName )->value->ToString(),
|
||||
wxString::FromCDouble( i ) + ".0000"
|
||||
+ wxString::FromCDouble( i ) + "G" );
|
||||
fmt::format( "{}.0000{}G", i, i ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -125,14 +129,14 @@ BOOST_AUTO_TEST_CASE( Diodes )
|
|||
LoadLibrary( "diodes" );
|
||||
|
||||
const std::vector<std::reference_wrapper<SIM_MODEL>> models = m_library->GetModels();
|
||||
const std::vector<wxString>& modelNames = m_library->GetModelNames();
|
||||
const std::vector<std::string>& modelNames = m_library->GetModelNames();
|
||||
|
||||
BOOST_CHECK_EQUAL( models.size(), 22 );
|
||||
|
||||
for( int i = 0; i < models.size(); ++i )
|
||||
{
|
||||
const SIM_MODEL& model = models.at( i );
|
||||
const wxString& modelName = modelNames.at( i );
|
||||
const std::string& modelName = modelNames.at( i );
|
||||
|
||||
switch( i )
|
||||
{
|
||||
|
@ -230,14 +234,14 @@ BOOST_AUTO_TEST_CASE( Bjts )
|
|||
LoadLibrary( "bjts" );
|
||||
|
||||
const std::vector<std::reference_wrapper<SIM_MODEL>> models = m_library->GetModels();
|
||||
const std::vector<wxString>& modelNames = m_library->GetModelNames();
|
||||
const std::vector<std::string>& modelNames = m_library->GetModelNames();
|
||||
|
||||
BOOST_CHECK_EQUAL( models.size(), 6 );
|
||||
|
||||
for( int i = 0; i < models.size(); ++i )
|
||||
{
|
||||
const SIM_MODEL& model = models.at( i );
|
||||
const wxString& modelName = modelNames.at( i );
|
||||
const std::string& modelName = modelNames.at( i );
|
||||
|
||||
switch( i )
|
||||
{
|
||||
|
@ -284,14 +288,14 @@ BOOST_AUTO_TEST_CASE( Fets )
|
|||
LoadLibrary( "fets" );
|
||||
|
||||
const std::vector<std::reference_wrapper<SIM_MODEL>> models = m_library->GetModels();
|
||||
const std::vector<wxString>& modelNames = m_library->GetModelNames();
|
||||
const std::vector<std::string>& modelNames = m_library->GetModelNames();
|
||||
|
||||
BOOST_CHECK_EQUAL( models.size(), 44 );
|
||||
|
||||
for( int i = 0; i < models.size(); ++i )
|
||||
{
|
||||
const SIM_MODEL& model = models.at( i );
|
||||
const wxString& modelName = modelNames.at( i );
|
||||
const std::string& modelName = modelNames.at( i );
|
||||
|
||||
switch( i )
|
||||
{
|
||||
|
|
|
@ -120,7 +120,7 @@ public:
|
|||
//ngspice->Init();
|
||||
ngspice->Command( "set ngbehavior=ps" );
|
||||
ngspice->Command( "setseed 1" );
|
||||
BOOST_REQUIRE( ngspice->LoadNetlist( netlist.ToStdString() ) );
|
||||
BOOST_REQUIRE( ngspice->LoadNetlist( std::string( netlist.ToUTF8() ) ) );
|
||||
BOOST_REQUIRE( ngspice->Run() );
|
||||
|
||||
// Test if ngspice cannot run a simulation (missing code models).
|
||||
|
|
Loading…
Reference in New Issue