diff --git a/eeschema/dialogs/dialog_lib_symbol_properties.cpp b/eeschema/dialogs/dialog_lib_symbol_properties.cpp index ca7b6cc1b9..743c9d6e55 100644 --- a/eeschema/dialogs/dialog_lib_symbol_properties.cpp +++ b/eeschema/dialogs/dialog_lib_symbol_properties.cpp @@ -638,7 +638,7 @@ void DIALOG_LIB_SYMBOL_PROPERTIES::OnEditSpiceModel( wxCommandEvent& event ) for( const LIB_FIELD& field : *m_fields ) fields.emplace_back( field ); - DIALOG_SIM_MODEL dialog( this, *m_libEntry, fields ); + DIALOG_SIM_MODEL dialog( this, m_parentFrame, *m_libEntry, fields ); if( dialog.ShowModal() != wxID_OK ) return; @@ -667,7 +667,7 @@ void DIALOG_LIB_SYMBOL_PROPERTIES::OnEditSpiceModel( wxCommandEvent& event ) } // Remove any deleted fields - for( int ii = (int) m_fields->size() - 1; ii >= 0; /* advance in loop */ ) + for( int ii = (int) m_fields->size() - 1; ii >= 0; --ii ) { LIB_FIELD& existingField = m_fields->at( ii ); bool found = false; @@ -681,11 +681,7 @@ void DIALOG_LIB_SYMBOL_PROPERTIES::OnEditSpiceModel( wxCommandEvent& event ) } } - if( found ) - { - ii--; - } - else + if( !found ) { m_fields->erase( m_fields->begin() + ii ); wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, ii, 1 ); diff --git a/eeschema/dialogs/dialog_sim_model.cpp b/eeschema/dialogs/dialog_sim_model.cpp index f5ceb0a569..d5c822ea77 100644 --- a/eeschema/dialogs/dialog_sim_model.cpp +++ b/eeschema/dialogs/dialog_sim_model.cpp @@ -43,6 +43,9 @@ #include #include #include +#include +#include +#include using CATEGORY = SIM_MODEL::PARAM::CATEGORY; @@ -57,9 +60,11 @@ bool equivalent( SIM_MODEL::DEVICE_T a, SIM_MODEL::DEVICE_T b ) template -DIALOG_SIM_MODEL::DIALOG_SIM_MODEL( wxWindow* aParent, T_symbol& aSymbol, - std::vector& aFields ) :\ +DIALOG_SIM_MODEL::DIALOG_SIM_MODEL( wxWindow* aParent, EDA_BASE_FRAME* aFrame, + T_symbol& aSymbol, + std::vector& aFields ) : DIALOG_SIM_MODEL_BASE( aParent ), + m_frame( aFrame ), m_symbol( aSymbol ), m_fields( aFields ), m_libraryModelsMgr( &Prj() ), @@ -953,14 +958,59 @@ wxPGProperty* DIALOG_SIM_MODEL::newParamProperty( SIM_MODEL* // break; case SIM_VALUE::TYPE_STRING: - if( param.info.enumValues.empty() ) + // Special case: K-line mutual inductance statement parameters l1 and l2 are references + // to other inductors in the circuit. + if( dynamic_cast( aModel ) != nullptr + && ( param.info.name == "l1" || param.info.name == "l2" ) ) + { + wxArrayString inductors; + + if( SCH_EDIT_FRAME* schEditFrame = dynamic_cast( m_frame ) ) + { + SPICE_CIRCUIT_MODEL circuit( &schEditFrame->Schematic() ); + NULL_REPORTER devNul; + + circuit.ReadSchematicAndLibraries( NETLIST_EXPORTER_SPICE::OPTION_DEFAULT_FLAGS, + devNul ); + + for( const SPICE_ITEM& item : circuit.GetItems() ) + { + if( item.model->GetDeviceType() == SIM_MODEL::DEVICE_T::L ) + inductors.push_back( item.refName ); + } + + inductors.Sort( + []( const wxString& a, const wxString& b ) -> int + { + return StrNumCmp( a, b, true ); + } ); + } + + if( inductors.empty() ) + { + prop = new SIM_STRING_PROPERTY( paramDescription, param.info.name, *aModel, + aParamIndex, SIM_VALUE::TYPE_STRING ); + } + else + { + prop = new SIM_ENUM_PROPERTY( paramDescription, param.info.name, *aModel, + aParamIndex, inductors ); + } + } + else if( param.info.enumValues.empty() ) { prop = new SIM_STRING_PROPERTY( paramDescription, param.info.name, *aModel, aParamIndex, SIM_VALUE::TYPE_STRING ); } else { - prop = new SIM_ENUM_PROPERTY( paramDescription, param.info.name, *aModel, aParamIndex ); + wxArrayString values; + + for( const std::string& string : aModel->GetParam( aParamIndex ).info.enumValues ) + values.Add( string ); + + prop = new SIM_ENUM_PROPERTY( paramDescription, param.info.name, *aModel, aParamIndex, + values ); } break; diff --git a/eeschema/dialogs/dialog_sim_model.h b/eeschema/dialogs/dialog_sim_model.h index ed9ba19269..de84ad0568 100644 --- a/eeschema/dialogs/dialog_sim_model.h +++ b/eeschema/dialogs/dialog_sim_model.h @@ -61,7 +61,8 @@ public: MODEL }; - DIALOG_SIM_MODEL( wxWindow* aParent, T_symbol& aSymbol, std::vector& aFields ); + DIALOG_SIM_MODEL( wxWindow* aParent, EDA_BASE_FRAME* aFrame, T_symbol& aSymbol, + std::vector& aFields ); ~DIALOG_SIM_MODEL(); @@ -120,6 +121,7 @@ private: bool isIbisLoaded() { return dynamic_cast( library() ); } private: + EDA_BASE_FRAME* m_frame; T_symbol& m_symbol; std::vector& m_fields; diff --git a/eeschema/dialogs/dialog_symbol_properties.cpp b/eeschema/dialogs/dialog_symbol_properties.cpp index 2efcf10c83..a92895bbdc 100644 --- a/eeschema/dialogs/dialog_symbol_properties.cpp +++ b/eeschema/dialogs/dialog_symbol_properties.cpp @@ -562,7 +562,7 @@ void DIALOG_SYMBOL_PROPERTIES::OnEditSpiceModel( wxCommandEvent& event ) for( const SCH_FIELD& field : *m_fields ) fields.emplace_back( field ); - DIALOG_SIM_MODEL dialog( this, *m_symbol, fields ); + DIALOG_SIM_MODEL dialog( this, m_parentFrame, *m_symbol, fields ); if( dialog.ShowModal() != wxID_OK ) return; diff --git a/eeschema/sim/sim_property.cpp b/eeschema/sim/sim_property.cpp index 408d82cdf2..0fc6baa86f 100644 --- a/eeschema/sim/sim_property.cpp +++ b/eeschema/sim/sim_property.cpp @@ -217,21 +217,10 @@ bool SIM_STRING_PROPERTY::StringToValue( wxVariant& aVariant, const wxString& aT } -static wxArrayString convertStringsToWx( const std::vector& 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, - SIM_MODEL& aModel, int aParamIndex ) : - wxEnumProperty( aLabel, aName, - convertStringsToWx( aModel.GetParam( aParamIndex ).info.enumValues ) ), + SIM_MODEL& aModel, int aParamIndex, + const wxArrayString& aValues ) : + wxEnumProperty( aLabel, aName, aValues ), SIM_PROPERTY( aModel, aParamIndex ) { for( int ii = 0; ii < (int) GetParam().info.enumValues.size(); ++ii ) @@ -252,6 +241,6 @@ bool SIM_ENUM_PROPERTY::IntToValue( wxVariant& aVariant, int aNumber, int aArgFl if( m_disabled ) return false; - m_model.SetParamValue( m_paramIndex, GetParam().info.enumValues.at( aNumber ) ); + m_model.SetParamValue( m_paramIndex, m_choices.GetLabel( aNumber ).ToStdString() ); return wxEnumProperty::IntToValue( aVariant, aNumber, aArgFlags ); } diff --git a/eeschema/sim/sim_property.h b/eeschema/sim/sim_property.h index 54f75de5ca..d9c633a92b 100644 --- a/eeschema/sim/sim_property.h +++ b/eeschema/sim/sim_property.h @@ -113,7 +113,7 @@ class SIM_ENUM_PROPERTY : public wxEnumProperty, public SIM_PROPERTY { public: SIM_ENUM_PROPERTY( const wxString& aLabel, const wxString& aName, SIM_MODEL& aModel, - int aParamIndex ); + int aParamIndex, const wxArrayString& aValues ); bool IntToValue( wxVariant& aVariant, int aNumber, int aArgFlags = 0 ) const override; };