From 4c5a3446292ccc8347d18ce9539c26a55e133d20 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 14 Jan 2023 02:43:34 +0000 Subject: [PATCH] Allow editing of raw SPICE models through code tab. --- eeschema/dialogs/dialog_sim_model.cpp | 18 ++++++++-------- eeschema/dialogs/dialog_sim_model_base.cpp | 2 +- eeschema/dialogs/dialog_sim_model_base.fbp | 2 +- eeschema/sim/sim_model_raw_spice.cpp | 24 +++++++++++++++------- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/eeschema/dialogs/dialog_sim_model.cpp b/eeschema/dialogs/dialog_sim_model.cpp index 3af6689324..3a3239a1fc 100644 --- a/eeschema/dialogs/dialog_sim_model.cpp +++ b/eeschema/dialogs/dialog_sim_model.cpp @@ -341,6 +341,12 @@ bool DIALOG_SIM_MODEL::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 void DIALOG_SIM_MODEL::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(); diff --git a/eeschema/dialogs/dialog_sim_model_base.cpp b/eeschema/dialogs/dialog_sim_model_base.cpp index 17b5694869..7035518b17 100644 --- a/eeschema/dialogs/dialog_sim_model_base.cpp +++ b/eeschema/dialogs/dialog_sim_model_base.cpp @@ -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 ); diff --git a/eeschema/dialogs/dialog_sim_model_base.fbp b/eeschema/dialogs/dialog_sim_model_base.fbp index 0893bba32a..b81b9b0bf3 100644 --- a/eeschema/dialogs/dialog_sim_model_base.fbp +++ b/eeschema/dialogs/dialog_sim_model_base.fbp @@ -2030,7 +2030,7 @@ 5 - wxEXPAND|wxLEFT + wxEXPAND|wxTOP|wxLEFT 0 diff --git a/eeschema/sim/sim_model_raw_spice.cpp b/eeschema/sim/sim_model_raw_spice.cpp index ca2fe21dd5..294e357d03 100644 --- a/eeschema/sim/sim_model_raw_spice.cpp +++ b/eeschema/sim/sim_model_raw_spice.cpp @@ -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; }