Don't use std::string for things with wxString APIs.

It's too bug-prone.

Fixes https://gitlab.com/kicad/code/kicad/issues/13380
This commit is contained in:
Jeff Young 2023-01-05 14:16:06 +00:00
parent 3b021d98be
commit 7af718f1a5
8 changed files with 80 additions and 81 deletions

View File

@ -184,7 +184,7 @@ bool DIALOG_LIB_SYMBOL_PROPERTIES::TransferDataToWindow()
m_OptionPower->SetValue( m_libEntry->IsPower() ); m_OptionPower->SetValue( m_libEntry->IsPower() );
#ifdef KICAD_SPICE #ifdef KICAD_SPICE
LIB_FIELD* simEnableField = m_libEntry->FindField( SIM_MODEL::ENABLE_FIELD ); LIB_FIELD* simEnableField = m_libEntry->FindField( SIM_ENABLE_FIELD );
m_excludeFromSim->SetValue( simEnableField && simEnableField->GetText() == wxT( "0" ) ); m_excludeFromSim->SetValue( simEnableField && simEnableField->GetText() == wxT( "0" ) );
#endif #endif
@ -237,7 +237,7 @@ void DIALOG_LIB_SYMBOL_PROPERTIES::OnExcludeFromSimulation( wxCommandEvent& even
for( int ii = MANDATORY_FIELDS; ii < m_grid->GetNumberRows(); ++ii ) for( int ii = MANDATORY_FIELDS; ii < m_grid->GetNumberRows(); ++ii )
{ {
if( m_grid->GetCellValue( ii, FDC_NAME ) == SIM_MODEL::ENABLE_FIELD ) if( m_grid->GetCellValue( ii, FDC_NAME ) == SIM_ENABLE_FIELD )
simEnableFieldRow = ii; simEnableFieldRow = ii;
} }

View File

@ -147,19 +147,19 @@ bool DIALOG_SIM_MODEL<T_symbol, T_field>::TransferDataToWindow()
if( SIM_MODEL::InferSimModel( m_symbol, &m_fields, false, SIM_VALUE_GRAMMAR::NOTATION::SI, if( SIM_MODEL::InferSimModel( m_symbol, &m_fields, false, SIM_VALUE_GRAMMAR::NOTATION::SI,
&deviceType, &modelType, &modelParams, &pinMap ) ) &deviceType, &modelType, &modelParams, &pinMap ) )
{ {
m_fields.emplace_back( &m_symbol, -1, SIM_MODEL::DEVICE_TYPE_FIELD ); m_fields.emplace_back( &m_symbol, -1, SIM_DEVICE_TYPE_FIELD );
m_fields.back().SetText( deviceType ); m_fields.back().SetText( deviceType );
if( !modelType.IsEmpty() ) if( !modelType.IsEmpty() )
{ {
m_fields.emplace_back( &m_symbol, -1, SIM_MODEL::TYPE_FIELD ); m_fields.emplace_back( &m_symbol, -1, SIM_TYPE_FIELD );
m_fields.back().SetText( modelType ); m_fields.back().SetText( modelType );
} }
m_fields.emplace_back( &m_symbol, -1, SIM_MODEL::PARAMS_FIELD ); m_fields.emplace_back( &m_symbol, -1, SIM_PARAMS_FIELD );
m_fields.back().SetText( modelParams ); m_fields.back().SetText( modelParams );
m_fields.emplace_back( &m_symbol, -1, SIM_MODEL::PINS_FIELD ); m_fields.emplace_back( &m_symbol, -1, SIM_PINS_FIELD );
m_fields.back().SetText( pinMap ); m_fields.back().SetText( pinMap );
storeInValue = true; storeInValue = true;
@ -359,7 +359,7 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::updateWidgets()
updateModelCodeTab(); updateModelCodeTab();
updatePinAssignments(); updatePinAssignments();
std::string ref = SIM_MODEL::GetFieldValue( &m_fields, SIM_MODEL::REFERENCE_FIELD ); std::string ref = SIM_MODEL::GetFieldValue( &m_fields, SIM_REFERENCE_FIELD );
m_modelPanel->Layout(); m_modelPanel->Layout();
m_pinAssignmentsPanel->Layout(); m_pinAssignmentsPanel->Layout();

View File

@ -515,7 +515,7 @@ bool DIALOG_SYMBOL_PROPERTIES::TransferDataToWindow()
} }
#ifdef KICAD_SPICE #ifdef KICAD_SPICE
m_cbExcludeFromSim->SetValue( m_symbol->GetFieldText( SIM_MODEL::ENABLE_FIELD ) == "0" ); m_cbExcludeFromSim->SetValue( m_symbol->GetFieldText( SIM_ENABLE_FIELD ) == "0" );
#endif #endif
m_cbExcludeFromBom->SetValue( !m_symbol->GetIncludeInBom() ); m_cbExcludeFromBom->SetValue( !m_symbol->GetIncludeInBom() );
m_cbExcludeFromBoard->SetValue( !m_symbol->GetIncludeOnBoard() ); m_cbExcludeFromBoard->SetValue( !m_symbol->GetIncludeOnBoard() );
@ -545,7 +545,7 @@ void DIALOG_SYMBOL_PROPERTIES::OnExcludeFromSimulation( wxCommandEvent& event )
for( int ii = MANDATORY_FIELDS; ii < m_fieldsGrid->GetNumberRows(); ++ii ) for( int ii = MANDATORY_FIELDS; ii < m_fieldsGrid->GetNumberRows(); ++ii )
{ {
if( m_fieldsGrid->GetCellValue( ii, FDC_NAME ) == SIM_MODEL::ENABLE_FIELD ) if( m_fieldsGrid->GetCellValue( ii, FDC_NAME ) == SIM_ENABLE_FIELD )
simEnableFieldRow = ii; simEnableFieldRow = ii;
} }
@ -554,8 +554,7 @@ void DIALOG_SYMBOL_PROPERTIES::OnExcludeFromSimulation( wxCommandEvent& event )
if( simEnableFieldRow == -1 ) if( simEnableFieldRow == -1 )
{ {
simEnableFieldRow = (int) m_fields->size(); simEnableFieldRow = (int) m_fields->size();
m_fields->emplace_back( VECTOR2I( 0, 0 ), simEnableFieldRow, m_symbol, m_fields->emplace_back( VECTOR2I( 0, 0 ), simEnableFieldRow, m_symbol, SIM_ENABLE_FIELD );
SIM_MODEL::ENABLE_FIELD );
// notify the grid // notify the grid
wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 ); wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );

View File

@ -215,7 +215,7 @@ bool NETLIST_EXPORTER_SPICE::ReadSchematicAndLibraries( unsigned aNetlistOptions
{ {
SCH_SYMBOL* symbol = findNextSymbol( item, &sheet ); SCH_SYMBOL* symbol = findNextSymbol( item, &sheet );
if( !symbol || symbol->GetFieldText( SIM_MODEL::ENABLE_FIELD ) == wxT( "0" ) ) if( !symbol || symbol->GetFieldText( SIM_ENABLE_FIELD ) == wxT( "0" ) )
continue; continue;
CreatePinList( symbol, &sheet, true ); CreatePinList( symbol, &sheet, true );
@ -243,19 +243,19 @@ bool NETLIST_EXPORTER_SPICE::ReadSchematicAndLibraries( unsigned aNetlistOptions
SIM_VALUE_GRAMMAR::NOTATION::SPICE, &deviceType, SIM_VALUE_GRAMMAR::NOTATION::SPICE, &deviceType,
&modelType, &modelParams, &pinMap ) ) &modelType, &modelParams, &pinMap ) )
{ {
spiceItem.fields.emplace_back( symbol, -1, SIM_MODEL::DEVICE_TYPE_FIELD ); spiceItem.fields.emplace_back( symbol, -1, SIM_DEVICE_TYPE_FIELD );
spiceItem.fields.back().SetText( deviceType ); spiceItem.fields.back().SetText( deviceType );
if( !modelType.IsEmpty() ) if( !modelType.IsEmpty() )
{ {
spiceItem.fields.emplace_back( symbol, -1, SIM_MODEL::TYPE_FIELD ); spiceItem.fields.emplace_back( symbol, -1, SIM_TYPE_FIELD );
spiceItem.fields.back().SetText( modelType ); spiceItem.fields.back().SetText( modelType );
} }
spiceItem.fields.emplace_back( symbol, -1, SIM_MODEL::PARAMS_FIELD ); spiceItem.fields.emplace_back( symbol, -1, SIM_PARAMS_FIELD );
spiceItem.fields.back().SetText( modelParams ); spiceItem.fields.back().SetText( modelParams );
spiceItem.fields.emplace_back( symbol, -1, SIM_MODEL::PINS_FIELD ); spiceItem.fields.emplace_back( symbol, -1, SIM_PINS_FIELD );
spiceItem.fields.back().SetText( pinMap ); spiceItem.fields.back().SetText( pinMap );
} }

View File

@ -217,19 +217,19 @@ SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const SCH_SHEET_PATH* aSheetPath, S
if( SIM_MODEL::InferSimModel( aSymbol, &fields, true, SIM_VALUE_GRAMMAR::NOTATION::SI, if( SIM_MODEL::InferSimModel( aSymbol, &fields, true, SIM_VALUE_GRAMMAR::NOTATION::SI,
&deviceType, &modelType, &modelParams, &pinMap ) ) &deviceType, &modelType, &modelParams, &pinMap ) )
{ {
fields.emplace_back( &aSymbol, -1, SIM_MODEL::DEVICE_TYPE_FIELD ); fields.emplace_back( &aSymbol, -1, SIM_DEVICE_TYPE_FIELD );
fields.back().SetText( deviceType ); fields.back().SetText( deviceType );
if( !modelType.IsEmpty() ) if( !modelType.IsEmpty() )
{ {
fields.emplace_back( &aSymbol, -1, SIM_MODEL::TYPE_FIELD ); fields.emplace_back( &aSymbol, -1, SIM_TYPE_FIELD );
fields.back().SetText( modelType ); fields.back().SetText( modelType );
} }
fields.emplace_back( &aSymbol, -1, SIM_MODEL::PARAMS_FIELD ); fields.emplace_back( &aSymbol, -1, SIM_PARAMS_FIELD );
fields.back().SetText( modelParams ); fields.back().SetText( modelParams );
fields.emplace_back( &aSymbol, -1, SIM_MODEL::PINS_FIELD ); fields.emplace_back( &aSymbol, -1, SIM_PINS_FIELD );
fields.back().SetText( pinMap ); fields.back().SetText( pinMap );
storeInValue = true; storeInValue = true;

View File

@ -367,8 +367,8 @@ template TYPE SIM_MODEL::ReadTypeFromFields( const std::vector<LIB_FIELD>& aFiel
template <typename T> template <typename T>
TYPE SIM_MODEL::ReadTypeFromFields( const std::vector<T>& aFields ) TYPE SIM_MODEL::ReadTypeFromFields( const std::vector<T>& aFields )
{ {
std::string deviceTypeFieldValue = GetFieldValue( &aFields, DEVICE_TYPE_FIELD ); std::string deviceTypeFieldValue = GetFieldValue( &aFields, SIM_DEVICE_TYPE_FIELD );
std::string typeFieldValue = GetFieldValue( &aFields, TYPE_FIELD ); std::string typeFieldValue = GetFieldValue( &aFields, SIM_TYPE_FIELD );
if( deviceTypeFieldValue != "" ) if( deviceTypeFieldValue != "" )
{ {
@ -575,17 +575,17 @@ std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const std::vector<T>& aFields,
// Just because we can't parse it doesn't mean that a SPICE interpreter can't. Fall // Just because we can't parse it doesn't mean that a SPICE interpreter can't. Fall
// back to a raw spice code model. // back to a raw spice code model.
std::string modelData = GetFieldValue( &aFields, PARAMS_FIELD ); std::string modelData = GetFieldValue( &aFields, SIM_PARAMS_FIELD );
if( modelData.empty() ) if( modelData.empty() )
modelData = GetFieldValue( &aFields, VALUE_FIELD ); modelData = GetFieldValue( &aFields, SIM_VALUE_FIELD );
model = std::make_unique<SIM_MODEL_RAW_SPICE>( modelData ); model = std::make_unique<SIM_MODEL_RAW_SPICE>( modelData );
try try
{ {
model->createPins( aPins ); model->createPins( aPins );
model->m_serializer->ParsePins( GetFieldValue( &aFields, PINS_FIELD ) ); model->m_serializer->ParsePins( GetFieldValue( &aFields, SIM_PINS_FIELD ) );
} }
catch( const IO_ERROR& err ) catch( const IO_ERROR& err )
{ {
@ -609,7 +609,7 @@ template std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const std::vector<LIB_FIE
template <typename T> template <typename T>
std::string SIM_MODEL::GetFieldValue( const std::vector<T>* aFields, const std::string& aFieldName, std::string SIM_MODEL::GetFieldValue( const std::vector<T>* aFields, const wxString& aFieldName,
bool aResolve ) bool aResolve )
{ {
static_assert( std::is_same<T, SCH_FIELD>::value || std::is_same<T, LIB_FIELD>::value ); static_assert( std::is_same<T, SCH_FIELD>::value || std::is_same<T, LIB_FIELD>::value );
@ -629,15 +629,15 @@ std::string SIM_MODEL::GetFieldValue( const std::vector<T>* aFields, const std::
// This specialization is used when no fields are passed. // This specialization is used when no fields are passed.
template <> template <>
std::string SIM_MODEL::GetFieldValue( const std::vector<void>* aFields, std::string SIM_MODEL::GetFieldValue( const std::vector<void>* aFields, const wxString& aFieldName,
const std::string& aFieldName, bool aResolve ) bool aResolve )
{ {
return ""; return "";
} }
template <typename T> template <typename T>
void SIM_MODEL::SetFieldValue( std::vector<T>& aFields, const std::string& aFieldName, void SIM_MODEL::SetFieldValue( std::vector<T>& aFields, const wxString& aFieldName,
const std::string& aValue ) const std::string& aValue )
{ {
static_assert( std::is_same<T, SCH_FIELD>::value || std::is_same<T, LIB_FIELD>::value ); static_assert( std::is_same<T, SCH_FIELD>::value || std::is_same<T, LIB_FIELD>::value );
@ -678,10 +678,10 @@ void SIM_MODEL::SetFieldValue( std::vector<T>& aFields, const std::string& aFiel
template void SIM_MODEL::SetFieldValue<SCH_FIELD>( std::vector<SCH_FIELD>& aFields, template void SIM_MODEL::SetFieldValue<SCH_FIELD>( std::vector<SCH_FIELD>& aFields,
const std::string& aFieldName, const wxString& aFieldName,
const std::string& aValue ); const std::string& aValue );
template void SIM_MODEL::SetFieldValue<LIB_FIELD>( std::vector<LIB_FIELD>& aFields, template void SIM_MODEL::SetFieldValue<LIB_FIELD>( std::vector<LIB_FIELD>& aFields,
const std::string& aFieldName, const wxString& aFieldName,
const std::string& aValue ); const std::string& aValue );
SIM_MODEL::~SIM_MODEL() = default; SIM_MODEL::~SIM_MODEL() = default;
@ -1032,12 +1032,12 @@ void SIM_MODEL::doReadDataFields( const std::vector<T>* aFields,
bool diffMode = GetFieldValue( aFields, SIM_LIBRARY_KIBIS::DIFF_FIELD ) == "1"; bool diffMode = GetFieldValue( aFields, SIM_LIBRARY_KIBIS::DIFF_FIELD ) == "1";
SwitchSingleEndedDiff( diffMode ); SwitchSingleEndedDiff( diffMode );
m_serializer->ParseEnable( GetFieldValue( aFields, ENABLE_FIELD ) ); m_serializer->ParseEnable( GetFieldValue( aFields, SIM_ENABLE_FIELD ) );
createPins( aPins ); createPins( aPins );
m_serializer->ParsePins( GetFieldValue( aFields, PINS_FIELD ) ); m_serializer->ParsePins( GetFieldValue( aFields, SIM_PINS_FIELD ) );
std::string paramsField = GetFieldValue( aFields, PARAMS_FIELD ); std::string paramsField = GetFieldValue( aFields, SIM_PARAMS_FIELD );
if( !m_serializer->ParseParams( paramsField ) ) if( !m_serializer->ParseParams( paramsField ) )
{ {
@ -1047,7 +1047,7 @@ void SIM_MODEL::doReadDataFields( const std::vector<T>* aFields,
// but don't be belligerent about it. // but don't be belligerent about it.
try try
{ {
m_serializer->ParseValue( GetFieldValue( aFields, VALUE_FIELD ) ); m_serializer->ParseValue( GetFieldValue( aFields, SIM_VALUE_FIELD ) );
} }
catch( ... ) catch( ... )
{ {
@ -1059,16 +1059,16 @@ void SIM_MODEL::doReadDataFields( const std::vector<T>* aFields,
template <typename T> template <typename T>
void SIM_MODEL::doWriteFields( std::vector<T>& aFields ) const void SIM_MODEL::doWriteFields( std::vector<T>& aFields ) const
{ {
SetFieldValue( aFields, DEVICE_TYPE_FIELD, m_serializer->GenerateDevice() ); SetFieldValue( aFields, SIM_DEVICE_TYPE_FIELD, m_serializer->GenerateDevice() );
SetFieldValue( aFields, TYPE_FIELD, m_serializer->GenerateType() ); SetFieldValue( aFields, SIM_TYPE_FIELD, m_serializer->GenerateType() );
SetFieldValue( aFields, ENABLE_FIELD, m_serializer->GenerateEnable() ); SetFieldValue( aFields, SIM_ENABLE_FIELD, m_serializer->GenerateEnable() );
SetFieldValue( aFields, PINS_FIELD, m_serializer->GeneratePins() ); SetFieldValue( aFields, SIM_PINS_FIELD, m_serializer->GeneratePins() );
SetFieldValue( aFields, PARAMS_FIELD, m_serializer->GenerateParams() ); SetFieldValue( aFields, SIM_PARAMS_FIELD, m_serializer->GenerateParams() );
if( IsStoredInValue() ) if( IsStoredInValue() )
SetFieldValue( aFields, VALUE_FIELD, m_serializer->GenerateValue() ); SetFieldValue( aFields, SIM_VALUE_FIELD, m_serializer->GenerateValue() );
} }
@ -1184,13 +1184,13 @@ bool SIM_MODEL::InferSimModel( T_symbol& aSymbol, std::vector<T_field>* aFields,
}; };
wxString prefix = aSymbol.GetPrefix(); wxString prefix = aSymbol.GetPrefix();
wxString value = GetFieldValue( aFields, VALUE_FIELD, aResolve ); wxString value = GetFieldValue( aFields, SIM_VALUE_FIELD, aResolve );
std::vector<LIB_PIN*> pins = aSymbol.GetAllLibPins(); std::vector<LIB_PIN*> pins = aSymbol.GetAllLibPins();
*aDeviceType = GetFieldValue( aFields, DEVICE_TYPE_FIELD, aResolve ); *aDeviceType = GetFieldValue( aFields, SIM_DEVICE_TYPE_FIELD, aResolve );
*aModelType = GetFieldValue( aFields, TYPE_FIELD, aResolve ); *aModelType = GetFieldValue( aFields, SIM_TYPE_FIELD, aResolve );
*aModelParams = GetFieldValue( aFields, PARAMS_FIELD, aResolve ); *aModelParams = GetFieldValue( aFields, SIM_PARAMS_FIELD, aResolve );
*aPinMap = GetFieldValue( aFields, PINS_FIELD, aResolve ); *aPinMap = GetFieldValue( aFields, SIM_PINS_FIELD, aResolve );
if( pins.size() != 2 ) if( pins.size() != 2 )
return false; return false;
@ -1341,10 +1341,10 @@ template bool SIM_MODEL::InferSimModel<LIB_SYMBOL, LIB_FIELD>( LIB_SYMBOL& aSymb
template <typename T_symbol, typename T_field> template <typename T_symbol, typename T_field>
void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject ) void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
{ {
if( aSymbol.FindField( SIM_MODEL::DEVICE_TYPE_FIELD ) if( aSymbol.FindField( SIM_DEVICE_TYPE_FIELD )
|| aSymbol.FindField( SIM_MODEL::TYPE_FIELD ) || aSymbol.FindField( SIM_TYPE_FIELD )
|| aSymbol.FindField( SIM_MODEL::PINS_FIELD ) || aSymbol.FindField( SIM_PINS_FIELD )
|| aSymbol.FindField( SIM_MODEL::PARAMS_FIELD ) ) || aSymbol.FindField( SIM_PARAMS_FIELD ) )
{ {
// Has a V7 model field -- skip. // Has a V7 model field -- skip.
return; return;
@ -1494,7 +1494,7 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
|| netlistEnabled.StartsWith( wxT( "n" ) ) || netlistEnabled.StartsWith( wxT( "n" ) )
|| netlistEnabled.StartsWith( wxT( "f" ) ) ) || netlistEnabled.StartsWith( wxT( "f" ) ) )
{ {
netlistEnabledField->SetName( SIM_MODEL::ENABLE_FIELD ); netlistEnabledField->SetName( SIM_ENABLE_FIELD );
netlistEnabledField->SetText( wxT( "0" ) ); netlistEnabledField->SetText( wxT( "0" ) );
} }
else else
@ -1515,12 +1515,12 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
if( T_field* legacyType = aSymbol.FindField( wxT( "Sim_Type" ) ) ) if( T_field* legacyType = aSymbol.FindField( wxT( "Sim_Type" ) ) )
{ {
legacyType->SetName( SIM_MODEL::TYPE_FIELD ); legacyType->SetName( SIM_TYPE_FIELD );
} }
if( T_field* legacyDevice = aSymbol.FindField( wxT( "Sim_Device" ) ) ) if( T_field* legacyDevice = aSymbol.FindField( wxT( "Sim_Device" ) ) )
{ {
legacyDevice->SetName( SIM_MODEL::DEVICE_TYPE_FIELD ); legacyDevice->SetName( SIM_DEVICE_TYPE_FIELD );
} }
if( T_field* legacyPins = aSymbol.FindField( wxT( "Sim_Pins" ) ) ) if( T_field* legacyPins = aSymbol.FindField( wxT( "Sim_Pins" ) ) )
@ -1563,13 +1563,13 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
} }
} }
legacyPins->SetName( SIM_MODEL::PINS_FIELD ); legacyPins->SetName( SIM_PINS_FIELD );
legacyPins->SetText( pinMap ); legacyPins->SetText( pinMap );
} }
if( T_field* legacyParams = aSymbol.FindField( wxT( "Sim_Params" ) ) ) if( T_field* legacyParams = aSymbol.FindField( wxT( "Sim_Params" ) ) )
{ {
legacyParams->SetName( SIM_MODEL::PARAMS_FIELD ); legacyParams->SetName( SIM_PARAMS_FIELD );
} }
return; return;
@ -1680,16 +1680,16 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
if( libraryModel ) if( libraryModel )
{ {
T_field libraryField = spiceLibInfo.CreateField( &aSymbol, SIM_MODEL::LIBRARY_FIELD ); T_field libraryField = spiceLibInfo.CreateField( &aSymbol, SIM_LIBRARY_FIELD );
aSymbol.AddField( libraryField ); aSymbol.AddField( libraryField );
T_field nameField = spiceModelInfo.CreateField( &aSymbol, SIM_MODEL::NAME_FIELD ); T_field nameField = spiceModelInfo.CreateField( &aSymbol, SIM_NAME_FIELD );
aSymbol.AddField( nameField ); aSymbol.AddField( nameField );
// Don't write a paramsField unless we actually have overrides // Don't write a paramsField unless we actually have overrides
if( !spiceParamsInfo.IsEmpty() ) if( !spiceParamsInfo.IsEmpty() )
{ {
T_field paramsField = spiceParamsInfo.CreateField( &aSymbol, SIM_MODEL::PARAMS_FIELD ); T_field paramsField = spiceParamsInfo.CreateField( &aSymbol, SIM_PARAMS_FIELD );
aSymbol.AddField( paramsField ); aSymbol.AddField( paramsField );
} }
@ -1703,15 +1703,15 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
} }
else if( internalModel ) else if( internalModel )
{ {
T_field deviceField = spiceDeviceInfo.CreateField( &aSymbol, SIM_MODEL::DEVICE_TYPE_FIELD ); T_field deviceField = spiceDeviceInfo.CreateField( &aSymbol, SIM_DEVICE_TYPE_FIELD );
aSymbol.AddField( deviceField ); aSymbol.AddField( deviceField );
T_field typeField = spiceTypeInfo.CreateField( &aSymbol, SIM_MODEL::TYPE_FIELD ); T_field typeField = spiceTypeInfo.CreateField( &aSymbol, SIM_TYPE_FIELD );
aSymbol.AddField( typeField ); aSymbol.AddField( typeField );
if( !spiceParamsInfo.IsEmpty() ) if( !spiceParamsInfo.IsEmpty() )
{ {
T_field paramsField = spiceParamsInfo.CreateField( &aSymbol, SIM_MODEL::PARAMS_FIELD ); T_field paramsField = spiceParamsInfo.CreateField( &aSymbol, SIM_PARAMS_FIELD );
aSymbol.AddField( paramsField ); aSymbol.AddField( paramsField );
} }
@ -1732,10 +1732,10 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
spiceDeviceInfo.m_Text = SIM_MODEL::DeviceInfo( SIM_MODEL::DEVICE_T::SPICE ).fieldValue; spiceDeviceInfo.m_Text = SIM_MODEL::DeviceInfo( SIM_MODEL::DEVICE_T::SPICE ).fieldValue;
T_field deviceField = spiceDeviceInfo.CreateField( &aSymbol, SIM_MODEL::DEVICE_TYPE_FIELD ); T_field deviceField = spiceDeviceInfo.CreateField( &aSymbol, SIM_DEVICE_TYPE_FIELD );
aSymbol.AddField( deviceField ); aSymbol.AddField( deviceField );
T_field paramsField = spiceParamsInfo.CreateField( &aSymbol, SIM_MODEL::PARAMS_FIELD ); T_field paramsField = spiceParamsInfo.CreateField( &aSymbol, SIM_PARAMS_FIELD );
aSymbol.AddField( paramsField ); aSymbol.AddField( paramsField );
if( modelFromValueField ) if( modelFromValueField )
@ -1756,7 +1756,7 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
if( !pinMapInfo.IsEmpty() ) if( !pinMapInfo.IsEmpty() )
{ {
T_field pinsField = pinMapInfo.CreateField( &aSymbol, SIM_MODEL::PINS_FIELD ); T_field pinsField = pinMapInfo.CreateField( &aSymbol, SIM_PINS_FIELD );
aSymbol.AddField( pinsField ); aSymbol.AddField( pinsField );
} }
} }

View File

@ -45,6 +45,18 @@ class SIM_MODEL_SERIALIZER;
class PROJECT; class PROJECT;
#define SIM_REFERENCE_FIELD wxT( "Reference" )
#define SIM_VALUE_FIELD wxT( "Value" )
#define SIM_DEVICE_TYPE_FIELD wxT( "Sim.Device" )
#define SIM_TYPE_FIELD wxT( "Sim.Type" )
#define SIM_PINS_FIELD wxT( "Sim.Pins" )
#define SIM_PARAMS_FIELD wxT( "Sim.Params" )
#define SIM_ENABLE_FIELD wxT( "Sim.Enable" )
#define SIM_LIBRARY_FIELD wxT( "Sim.Library" )
#define SIM_NAME_FIELD wxT( "Sim.Name" )
class SIM_MODEL class SIM_MODEL
{ {
public: public:
@ -54,18 +66,6 @@ public:
struct PIN; struct PIN;
struct PARAM; struct PARAM;
static constexpr auto REFERENCE_FIELD = "Reference";
static constexpr auto VALUE_FIELD = "Value";
static constexpr auto DEVICE_TYPE_FIELD = "Sim.Device";
static constexpr auto TYPE_FIELD = "Sim.Type";
static constexpr auto PINS_FIELD = "Sim.Pins";
static constexpr auto PARAMS_FIELD = "Sim.Params";
static constexpr auto ENABLE_FIELD = "Sim.Enable";
static constexpr auto LIBRARY_FIELD = "Sim.Library";
static constexpr auto NAME_FIELD = "Sim.Name";
// There's a trailing '_' because `DEVICE_TYPE` collides with something in Windows headers. // There's a trailing '_' because `DEVICE_TYPE` collides with something in Windows headers.
DEFINE_ENUM_CLASS_WITH_ITERATOR( DEVICE_T, DEFINE_ENUM_CLASS_WITH_ITERATOR( DEVICE_T,
NONE, NONE,
@ -420,11 +420,11 @@ public:
bool aResolved, REPORTER* aReporter ); bool aResolved, REPORTER* aReporter );
template <typename T> template <typename T>
static std::string GetFieldValue( const std::vector<T>* aFields, const std::string& aFieldName, static std::string GetFieldValue( const std::vector<T>* aFields, const wxString& aFieldName,
bool aResolve = true ); bool aResolve = true );
template <typename T> template <typename T>
static void SetFieldValue( std::vector<T>& aFields, const std::string& aFieldName, static void SetFieldValue( std::vector<T>& aFields, const wxString& aFieldName,
const std::string& aValue ); const std::string& aValue );
const SPICE_GENERATOR& SpiceGenerator() const { return *m_spiceGenerator; } const SPICE_GENERATOR& SpiceGenerator() const { return *m_spiceGenerator; }

View File

@ -175,7 +175,7 @@ void SIM_MODEL_SERIALIZER::ParseValue( const std::string& aValue )
{ {
try try
{ {
tao::pegtl::string_input<> in( aValue, SIM_MODEL::VALUE_FIELD ); tao::pegtl::string_input<> in( aValue, "'Value' symbol field" );
auto root = auto root =
tao::pegtl::parse_tree::parse<SIM_MODEL_SERIALIZER_PARSER::fieldInferValueGrammar, tao::pegtl::parse_tree::parse<SIM_MODEL_SERIALIZER_PARSER::fieldInferValueGrammar,
SIM_MODEL_SERIALIZER_PARSER::fieldInferValueSelector, SIM_MODEL_SERIALIZER_PARSER::fieldInferValueSelector,
@ -206,7 +206,7 @@ void SIM_MODEL_SERIALIZER::ParseValue( const std::string& aValue )
bool SIM_MODEL_SERIALIZER::ParseParams( const std::string& aParams ) bool SIM_MODEL_SERIALIZER::ParseParams( const std::string& aParams )
{ {
tao::pegtl::string_input<> in( aParams, SIM_MODEL::PARAMS_FIELD ); tao::pegtl::string_input<> in( aParams, "'Sim.Params' symbol field" );
std::unique_ptr<tao::pegtl::parse_tree::node> root; std::unique_ptr<tao::pegtl::parse_tree::node> root;
try try
@ -270,7 +270,7 @@ void SIM_MODEL_SERIALIZER::ParsePins( const std::string& aPins )
if( aPins == "" ) if( aPins == "" )
return; return;
tao::pegtl::string_input<> in( aPins, PINS_FIELD ); tao::pegtl::string_input<> in( aPins, "'Sim.Pins' symbol field" );
std::unique_ptr<tao::pegtl::parse_tree::node> root; std::unique_ptr<tao::pegtl::parse_tree::node> root;
try try