Provide popups for inductor references.

Also fixes a long-standing bug deleting the last field of
a symbol in the Symbol Editor.
This commit is contained in:
Jeff Young 2024-01-25 15:29:29 +00:00
parent 340d1b7fad
commit 70bca8bc4e
6 changed files with 66 additions and 29 deletions

View File

@ -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 );

View File

@ -43,6 +43,9 @@
#include <wx/filedlg.h>
#include <wx/textfile.h>
#include <fmt/format.h>
#include <sch_edit_frame.h>
#include <sim/sim_model_l_mutual.h>
#include <sim/spice_circuit_model.h>
using CATEGORY = SIM_MODEL::PARAM::CATEGORY;
@ -57,9 +60,11 @@ bool equivalent( SIM_MODEL::DEVICE_T a, SIM_MODEL::DEVICE_T b )
template <typename T_symbol, typename T_field>
DIALOG_SIM_MODEL<T_symbol, T_field>::DIALOG_SIM_MODEL( wxWindow* aParent, T_symbol& aSymbol,
std::vector<T_field>& aFields ) :\
DIALOG_SIM_MODEL<T_symbol, T_field>::DIALOG_SIM_MODEL( wxWindow* aParent, EDA_BASE_FRAME* aFrame,
T_symbol& aSymbol,
std::vector<T_field>& 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<T_symbol, T_field>::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<SIM_MODEL_L_MUTUAL*>( aModel ) != nullptr
&& ( param.info.name == "l1" || param.info.name == "l2" ) )
{
wxArrayString inductors;
if( SCH_EDIT_FRAME* schEditFrame = dynamic_cast<SCH_EDIT_FRAME*>( 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;

View File

@ -61,7 +61,8 @@ public:
MODEL
};
DIALOG_SIM_MODEL( wxWindow* aParent, T_symbol& aSymbol, std::vector<T_field>& aFields );
DIALOG_SIM_MODEL( wxWindow* aParent, EDA_BASE_FRAME* aFrame, T_symbol& aSymbol,
std::vector<T_field>& aFields );
~DIALOG_SIM_MODEL();
@ -120,6 +121,7 @@ private:
bool isIbisLoaded() { return dynamic_cast<const SIM_LIBRARY_KIBIS*>( library() ); }
private:
EDA_BASE_FRAME* m_frame;
T_symbol& m_symbol;
std::vector<T_field>& m_fields;

View File

@ -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;

View File

@ -217,21 +217,10 @@ bool SIM_STRING_PROPERTY::StringToValue( wxVariant& aVariant, const wxString& aT
}
static wxArrayString convertStringsToWx( const std::vector<std::string>& 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 );
}

View File

@ -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;
};