Allow editing of raw SPICE models through code tab.

This commit is contained in:
Jeff Young 2023-01-14 02:43:34 +00:00
parent f1aee2fa18
commit 4c5a344629
4 changed files with 27 additions and 19 deletions

View File

@ -341,6 +341,12 @@ bool DIALOG_SIM_MODEL<T_symbol, T_field>::TransferDataFromWindow()
}
}
if( curModel().GetType() == SIM_MODEL::TYPE::RAWSPICE )
{
wxString code = m_codePreview->GetText().Trim( true ).Trim( false );
curModel().SetParamValue( "model", std::string( code.ToUTF8() ) );
}
curModel().SetIsStoredInValue( m_saveInValueCheckbox->GetValue() );
curModel().WriteFields( m_fields );
@ -557,22 +563,14 @@ template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::updateModelCodeTab()
{
wxString text;
wxString pin( _( "Pin" ) );
SPICE_ITEM item;
item.modelName = m_modelNameChoice->GetStringSelection();
for( size_t ii = 1; ii <= m_symbol.GetFullPinCount(); ++ii )
{
item.pinNumbers.push_back( fmt::format( "{}", ii ) );
item.pinNetNames.push_back( pin.ToStdString() + fmt::format( "{}", ii ) );
}
item.modelName = m_modelNameChoice->GetStringSelection();
if( m_useInstanceModelRadioButton->GetValue() || item.modelName == "" )
item.modelName = m_fields.at( REFERENCE_FIELD ).GetText();
SIM_MODEL& model = curModel();
text << model.SpiceGenerator().Preview( item );
text << curModel().SpiceGenerator().Preview( item );
m_codePreview->SetText( text );
m_codePreview->SelectNone();

View File

@ -318,7 +318,7 @@ DIALOG_SIM_MODEL_BASE::DIALOG_SIM_MODEL_BASE( wxWindow* parent, wxWindowID id, c
bSizer81->Add( m_sdbSizer1, 0, wxEXPAND|wxALL, 5 );
bSizer8->Add( bSizer81, 0, wxEXPAND|wxLEFT, 5 );
bSizer8->Add( bSizer81, 0, wxEXPAND|wxTOP|wxLEFT, 5 );
this->SetSizer( bSizer8 );

View File

@ -2030,7 +2030,7 @@
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND|wxLEFT</property>
<property name="flag">wxEXPAND|wxTOP|wxLEFT</property>
<property name="proportion">0</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>

View File

@ -61,17 +61,27 @@ std::string SPICE_GENERATOR_RAW_SPICE::ItemPins( const SPICE_ITEM& aItem ) const
{
std::string result;
for( const SIM_MODEL::PIN& pin : GetPins() )
if( !GetPins().empty() )
{
auto it = std::find( aItem.pinNumbers.begin(), aItem.pinNumbers.end(),
pin.symbolPinNumber );
if( it != aItem.pinNumbers.end() )
for( const SIM_MODEL::PIN& pin : GetPins() )
{
long symbolPinIndex = std::distance( aItem.pinNumbers.begin(), it );
result.append( fmt::format( " {}", aItem.pinNetNames.at( symbolPinIndex ) ) );
auto it = std::find( aItem.pinNumbers.begin(), aItem.pinNumbers.end(),
pin.symbolPinNumber );
if( it != aItem.pinNumbers.end() )
{
long symbolPinIndex = std::distance( aItem.pinNumbers.begin(), it );
result.append( fmt::format( " {}", aItem.pinNetNames.at( symbolPinIndex ) ) );
}
}
}
else
{
// If we don't know what pins the model has, just output the symbol's pins
for( const std::string& pinNetName : aItem.pinNetNames )
result.append( fmt::format( " {}", pinNetName ) );
}
return result;
}