Sim Model Editor: Don't provide library-only models as builtins

This commit is contained in:
Mikolaj Wielgus 2022-11-20 22:06:21 +01:00
parent d89745ca21
commit 6969362813
7 changed files with 63 additions and 43 deletions

View File

@ -69,9 +69,6 @@ DIALOG_SIM_MODEL<T>::DIALOG_SIM_MODEL( wxWindow* aParent, SCH_SYMBOL& aSymbol,
m_typeChoice->Clear();
for( SIM_MODEL::DEVICE_TYPE_ deviceType : SIM_MODEL::DEVICE_TYPE__ITERATOR() )
m_deviceTypeChoice->Append( SIM_MODEL::DeviceTypeInfo( deviceType ).description );
m_scintillaTricks = new SCINTILLA_TRICKS( m_codePreview, wxT( "{}" ), false );
m_paramGridMgr->Bind( wxEVT_PG_SELECTED, &DIALOG_SIM_MODEL::onParamGridSelectionChange, this );
@ -338,7 +335,27 @@ void DIALOG_SIM_MODEL<T>::updateInstanceWidgets()
// Change the Type choice to match the current device type.
if( !m_prevModel || m_prevModel != &curModel() )
{
m_deviceTypeChoice->SetSelection( static_cast<int>( curModel().GetDeviceType() ) );
m_deviceTypeChoice->Clear();
if( m_useLibraryModelRadioButton->GetValue() )
{
m_deviceTypeChoice->Append( curModel().GetDeviceInfo().description );
m_deviceTypeChoice->SetSelection( 0 );
}
else
{
for( SIM_MODEL::DEVICE_TYPE_ deviceType : SIM_MODEL::DEVICE_TYPE__ITERATOR() )
{
if( !SIM_MODEL::DeviceInfo( deviceType ).isBuiltin )
continue;
m_deviceTypeChoice->Append( SIM_MODEL::DeviceInfo( deviceType ).description );
if( deviceType == curModel().GetDeviceType() )
m_deviceTypeChoice->SetSelection( m_deviceTypeChoice->GetCount() - 1 );
}
}
m_typeChoice->Clear();
for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
@ -504,9 +521,7 @@ void DIALOG_SIM_MODEL<T>::updatePinAssignments()
m_pinAssignmentsGrid->AppendRows( static_cast<int>( m_sortedSymbolPins.size() ) );
for( int row = 0; row < m_pinAssignmentsGrid->GetNumberRows(); ++row )
{
m_pinAssignmentsGrid->SetCellValue( row, PIN_COLUMN::MODEL, _( "Not Connected" ) );
}
// Now set up the grid values in the Model column.
for( int modelPinIndex = 0; modelPinIndex < curModel().GetPinCount(); ++modelPinIndex )
@ -1037,6 +1052,7 @@ void DIALOG_SIM_MODEL<T>::onDifferentialCheckbox( wxCommandEvent& aEvent )
bool diff = m_differentialCheckbox->GetValue() && modelkibis->CanDifferential();
modelkibis->SwitchSingleEndedDiff( diff );
}
updateWidgets();
}
@ -1044,10 +1060,14 @@ void DIALOG_SIM_MODEL<T>::onDifferentialCheckbox( wxCommandEvent& aEvent )
template <typename T>
void DIALOG_SIM_MODEL<T>::onDeviceTypeChoice( wxCommandEvent& aEvent )
{
SIM_MODEL::DEVICE_TYPE_ deviceType =
static_cast<SIM_MODEL::DEVICE_TYPE_>( m_deviceTypeChoice->GetSelection() );
m_curModelType = m_curModelTypeOfDeviceType.at( deviceType );
for( SIM_MODEL::DEVICE_TYPE_ deviceType : SIM_MODEL::DEVICE_TYPE__ITERATOR() )
{
if( SIM_MODEL::DeviceInfo( deviceType ).description == m_deviceTypeChoice->GetStringSelection() )
{
m_curModelType = m_curModelTypeOfDeviceType.at( deviceType );
break;
}
}
updateWidgets();
}
@ -1056,8 +1076,7 @@ void DIALOG_SIM_MODEL<T>::onDeviceTypeChoice( wxCommandEvent& aEvent )
template <typename T>
void DIALOG_SIM_MODEL<T>::onTypeChoice( wxCommandEvent& aEvent )
{
SIM_MODEL::DEVICE_TYPE_ deviceType =
static_cast<SIM_MODEL::DEVICE_TYPE_>( m_deviceTypeChoice->GetSelection() );
SIM_MODEL::DEVICE_TYPE_ deviceType = curModel().GetDeviceType();
wxString typeDescription = m_typeChoice->GetString( m_typeChoice->GetSelection() );
for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )

View File

@ -1338,7 +1338,7 @@ void SCH_SHEET_LIST::MigrateSimModelNameFields()
SCH_FIELD deviceTypeField( VECTOR2I( 0, 0 ), symbol->GetFieldCount(), symbol,
SIM_MODEL::DEVICE_TYPE_FIELD );
deviceTypeField.SetText(
SIM_MODEL::DeviceTypeInfo( SIM_MODEL::DEVICE_TYPE_::SPICE ).fieldValue );
SIM_MODEL::DeviceInfo( SIM_MODEL::DEVICE_TYPE_::SPICE ).fieldValue );
symbol->AddField( deviceTypeField );
SCH_FIELD modelParamsField( VECTOR2I( 0, 0 ), symbol->GetFieldCount(), symbol,

View File

@ -54,37 +54,37 @@ using DEVICE_TYPE = SIM_MODEL::DEVICE_TYPE_;
using TYPE = SIM_MODEL::TYPE;
SIM_MODEL::DEVICE_INFO SIM_MODEL::DeviceTypeInfo( DEVICE_TYPE_ aDeviceType )
SIM_MODEL::DEVICE_INFO SIM_MODEL::DeviceInfo( DEVICE_TYPE_ aDeviceType )
{
switch( aDeviceType )
{
case DEVICE_TYPE_::NONE: return { "", "" };
case DEVICE_TYPE_::R: return { "R", "Resistor" };
case DEVICE_TYPE_::C: return { "C", "Capacitor" };
case DEVICE_TYPE_::L: return { "L", "Inductor" };
case DEVICE_TYPE_::TLINE: return { "TLINE", "Transmission Line" };
case DEVICE_TYPE_::SW: return { "SW", "Switch" };
case DEVICE_TYPE_::NONE: return { "", "", true };
case DEVICE_TYPE_::R: return { "R", "Resistor", true };
case DEVICE_TYPE_::C: return { "C", "Capacitor", true };
case DEVICE_TYPE_::L: return { "L", "Inductor", true };
case DEVICE_TYPE_::TLINE: return { "TLINE", "Transmission Line", true };
case DEVICE_TYPE_::SW: return { "SW", "Switch", true };
case DEVICE_TYPE_::D: return { "D", "Diode" };
case DEVICE_TYPE_::NPN: return { "NPN", "NPN BJT" };
case DEVICE_TYPE_::PNP: return { "PNP", "PNP BJT" };
case DEVICE_TYPE_::D: return { "D", "Diode", true };
case DEVICE_TYPE_::NPN: return { "NPN", "NPN BJT", true };
case DEVICE_TYPE_::PNP: return { "PNP", "PNP BJT", true };
case DEVICE_TYPE_::NJFET: return { "NJFET", "N-channel JFET" };
case DEVICE_TYPE_::PJFET: return { "PJFET", "P-channel JFET" };
case DEVICE_TYPE_::NJFET: return { "NJFET", "N-channel JFET", true };
case DEVICE_TYPE_::PJFET: return { "PJFET", "P-channel JFET", true };
case DEVICE_TYPE_::NMOS: return { "NMOS", "N-channel MOSFET" };
case DEVICE_TYPE_::PMOS: return { "PMOS", "P-channel MOSFET" };
case DEVICE_TYPE_::NMES: return { "NMES", "N-channel MESFET" };
case DEVICE_TYPE_::PMES: return { "PMES", "P-channel MESFET" };
case DEVICE_TYPE_::NMOS: return { "NMOS", "N-channel MOSFET", true };
case DEVICE_TYPE_::PMOS: return { "PMOS", "P-channel MOSFET", true };
case DEVICE_TYPE_::NMES: return { "NMES", "N-channel MESFET", true };
case DEVICE_TYPE_::PMES: return { "PMES", "P-channel MESFET", true };
case DEVICE_TYPE_::V: return { "V", "Voltage Source" };
case DEVICE_TYPE_::I: return { "I", "Current Source" };
case DEVICE_TYPE_::V: return { "V", "Voltage Source", true };
case DEVICE_TYPE_::I: return { "I", "Current Source", true };
case DEVICE_TYPE_::KIBIS: return { "IBIS", "Ibis Model" };
case DEVICE_TYPE_::KIBIS: return { "IBIS", "IBIS Model", false };
case DEVICE_TYPE_::SUBCKT: return { "SUBCKT", "Subcircuit" };
case DEVICE_TYPE_::XSPICE: return { "XSPICE", "XSPICE Code Model" };
case DEVICE_TYPE_::SPICE: return { "SPICE", "Raw Spice Element" };
case DEVICE_TYPE_::SUBCKT: return { "SUBCKT", "Subcircuit", false };
case DEVICE_TYPE_::XSPICE: return { "XSPICE", "XSPICE Code Model", true };
case DEVICE_TYPE_::SPICE: return { "SPICE", "Raw Spice Element", true };
case DEVICE_TYPE_::_ENUM_END: break;
}
@ -386,7 +386,7 @@ TYPE SIM_MODEL::ReadTypeFromFields( const std::vector<T>& aFields, int aSymbolPi
{
if( typeFieldValue == TypeInfo( type ).fieldValue )
{
if( deviceTypeFieldValue == DeviceTypeInfo( TypeInfo( type ).deviceType ).fieldValue )
if( deviceTypeFieldValue == DeviceInfo( TypeInfo( type ).deviceType ).fieldValue )
return type;
}
}

View File

@ -99,6 +99,7 @@ public:
{
std::string fieldValue;
std::string description;
bool isBuiltin;
};
@ -380,7 +381,7 @@ public:
};
static DEVICE_INFO DeviceTypeInfo( DEVICE_TYPE_ aDeviceType );
static DEVICE_INFO DeviceInfo( DEVICE_TYPE_ aDeviceType );
static INFO TypeInfo( TYPE aType );
static SPICE_INFO SpiceInfo( TYPE aType );
@ -446,7 +447,7 @@ public:
int FindModelPinIndex( const std::string& aSymbolPinNumber );
void AddParam( const PARAM::INFO& aInfo, bool aIsOtherVariant = false );
DEVICE_INFO GetDeviceTypeInfo() const { return DeviceTypeInfo( GetDeviceType() ); }
DEVICE_INFO GetDeviceInfo() const { return DeviceInfo( GetDeviceType() ); }
INFO GetTypeInfo() const { return TypeInfo( GetType() ); }
DEVICE_TYPE_ GetDeviceType() const { return GetTypeInfo().deviceType; }

View File

@ -54,7 +54,7 @@ namespace SIM_SERDE_PARSER
std::string SIM_SERDE::GenerateDevice() const
{
return m_model.GetDeviceTypeInfo().fieldValue;
return m_model.GetDeviceInfo().fieldValue;
}
@ -90,7 +90,7 @@ std::string SIM_SERDE::GenerateValue() const
}
if( result == "" )
result = m_model.GetDeviceTypeInfo().fieldValue;
result = m_model.GetDeviceInfo().fieldValue;
return result;
}
@ -158,7 +158,7 @@ SIM_MODEL::TYPE SIM_SERDE::ParseDeviceAndType( const std::string& aDevice,
for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
{
if( aType == SIM_MODEL::TypeInfo( type ).fieldValue
&& aDevice == SIM_MODEL::DeviceTypeInfo( SIM_MODEL::TypeInfo( type ).deviceType ).fieldValue )
&& aDevice == SIM_MODEL::DeviceInfo( SIM_MODEL::TypeInfo( type ).deviceType ).fieldValue )
{
return type;
}

View File

@ -61,7 +61,7 @@ TUNER_SLIDER::TUNER_SLIDER( SIM_PLOT_FRAME* aFrame, wxWindow* aParent, SCH_SYMBO
throw KI_PARAM_ERROR( wxString::Format(
_( "Symbol '%s' has simulation model of type '%s %s', which cannot be tuned" ),
ref,
m_item->model->GetDeviceTypeInfo().fieldValue,
m_item->model->GetDeviceInfo().fieldValue,
m_item->model->GetTypeInfo().fieldValue ) );

View File

@ -90,7 +90,7 @@ public:
{
BOOST_TEST_CONTEXT( "Model index: " << aModelIndex
<< ", Model name: " << aModelName
<< ", Model device type: " << aModel.GetDeviceTypeInfo().fieldValue
<< ", Model device type: " << aModel.GetDeviceInfo().fieldValue
<< ", Model type: " << aModel.GetTypeInfo().fieldValue )
{
BOOST_CHECK( aModel.GetType() == aType );