Add reference material to SPICE model pin assignment tab.

Fixes https://gitlab.com/kicad/code/kicad/issues/13309
This commit is contained in:
Jeff Young 2022-12-31 16:53:37 +00:00
parent 84ad38fd5d
commit 77b361a077
7 changed files with 208 additions and 7 deletions

View File

@ -32,6 +32,7 @@
#include <sim/sim_model_kibis.h>
#include <sim/sim_model_raw_spice.h>
#include <sim/sim_model_spice_fallback.h>
#include <sim/sim_model_subckt.h>
#include <grid_tricks.h>
#include <widgets/grid_icon_text_helpers.h>
#include <widgets/std_bitmap_button.h>
@ -41,7 +42,7 @@
#include <locale_io.h>
#include <wx/filedlg.h>
#include <wx/textfile.h>
#include "fmt/format.h"
#include <fmt/format.h>
using CATEGORY = SIM_MODEL::PARAM::CATEGORY;
@ -103,6 +104,8 @@ DIALOG_SIM_MODEL<T_symbol, T_field>::DIALOG_SIM_MODEL( wxWindow* aParent, T_symb
m_pinAssignmentsGrid->PushEventHandler( new GRID_TRICKS( m_pinAssignmentsGrid ) );
m_subcktLabel->SetFont( KIUI::GetInfoFont( m_subcktLabel ) );
// Now all widgets have the size fixed, call FinishDialogSettings
finishDialogSettings();
}
@ -637,7 +640,19 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::updatePinAssignments()
}
// TODO: Show a preview of the symbol with the pin numbers shown.
// TODO: Maybe show a preview of the code for subcircuits and code models.
SIM_MODEL* model = &curModel();
if( model->GetType() == SIM_MODEL::TYPE::SUBCKT )
{
SIM_MODEL_SUBCKT* subckt = static_cast<SIM_MODEL_SUBCKT*>( model );
m_subckt->SetText( subckt->GetSpiceCode() );
}
else
{
m_subcktLabel->Show( false );
m_subckt->Show( false );
}
}
@ -653,7 +668,8 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::removeOrphanedPinAssignments()
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::loadLibrary( const wxString& aLibraryPath, bool aForceReload )
void DIALOG_SIM_MODEL<T_symbol, T_field>::loadLibrary( const wxString& aLibraryPath,
bool aForceReload )
{
auto libraries = m_libraryModelsMgr.GetLibraries();

View File

@ -249,13 +249,55 @@ DIALOG_SIM_MODEL_BASE::DIALOG_SIM_MODEL_BASE( wxWindow* parent, wxWindowID id, c
m_pinAssignmentsGrid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
bSizer10->Add( m_pinAssignmentsGrid, 1, wxALL|wxEXPAND, 5 );
m_subcktLabel = new wxStaticText( m_pinAssignmentsPanel, wxID_ANY, _("Reference"), wxDefaultPosition, wxDefaultSize, 0 );
m_subcktLabel->Wrap( -1 );
bSizer10->Add( m_subcktLabel, 0, wxTOP|wxRIGHT|wxLEFT, 8 );
m_subckt = new wxStyledTextCtrl( m_pinAssignmentsPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, wxEmptyString );
m_subckt->SetUseTabs( true );
m_subckt->SetTabWidth( 4 );
m_subckt->SetIndent( 4 );
m_subckt->SetTabIndents( true );
m_subckt->SetBackSpaceUnIndents( true );
m_subckt->SetViewEOL( false );
m_subckt->SetViewWhiteSpace( false );
m_subckt->SetMarginWidth( 2, 0 );
m_subckt->SetIndentationGuides( true );
m_subckt->SetReadOnly( false );
m_subckt->SetMarginType( 1, wxSTC_MARGIN_SYMBOL );
m_subckt->SetMarginMask( 1, wxSTC_MASK_FOLDERS );
m_subckt->SetMarginWidth( 1, 16);
m_subckt->SetMarginSensitive( 1, true );
m_subckt->SetProperty( wxT("fold"), wxT("1") );
m_subckt->SetFoldFlags( wxSTC_FOLDFLAG_LINEBEFORE_CONTRACTED | wxSTC_FOLDFLAG_LINEAFTER_CONTRACTED );
m_subckt->SetMarginType( 0, wxSTC_MARGIN_NUMBER );
m_subckt->SetMarginWidth( 0, m_subckt->TextWidth( wxSTC_STYLE_LINENUMBER, wxT("_99999") ) );
m_subckt->MarkerDefine( wxSTC_MARKNUM_FOLDER, wxSTC_MARK_BOXPLUS );
m_subckt->MarkerSetBackground( wxSTC_MARKNUM_FOLDER, wxColour( wxT("BLACK") ) );
m_subckt->MarkerSetForeground( wxSTC_MARKNUM_FOLDER, wxColour( wxT("WHITE") ) );
m_subckt->MarkerDefine( wxSTC_MARKNUM_FOLDEROPEN, wxSTC_MARK_BOXMINUS );
m_subckt->MarkerSetBackground( wxSTC_MARKNUM_FOLDEROPEN, wxColour( wxT("BLACK") ) );
m_subckt->MarkerSetForeground( wxSTC_MARKNUM_FOLDEROPEN, wxColour( wxT("WHITE") ) );
m_subckt->MarkerDefine( wxSTC_MARKNUM_FOLDERSUB, wxSTC_MARK_EMPTY );
m_subckt->MarkerDefine( wxSTC_MARKNUM_FOLDEREND, wxSTC_MARK_BOXPLUS );
m_subckt->MarkerSetBackground( wxSTC_MARKNUM_FOLDEREND, wxColour( wxT("BLACK") ) );
m_subckt->MarkerSetForeground( wxSTC_MARKNUM_FOLDEREND, wxColour( wxT("WHITE") ) );
m_subckt->MarkerDefine( wxSTC_MARKNUM_FOLDEROPENMID, wxSTC_MARK_BOXMINUS );
m_subckt->MarkerSetBackground( wxSTC_MARKNUM_FOLDEROPENMID, wxColour( wxT("BLACK") ) );
m_subckt->MarkerSetForeground( wxSTC_MARKNUM_FOLDEROPENMID, wxColour( wxT("WHITE") ) );
m_subckt->MarkerDefine( wxSTC_MARKNUM_FOLDERMIDTAIL, wxSTC_MARK_EMPTY );
m_subckt->MarkerDefine( wxSTC_MARKNUM_FOLDERTAIL, wxSTC_MARK_EMPTY );
m_subckt->SetSelBackground( true, wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
m_subckt->SetSelForeground( true, wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT ) );
bSizer10->Add( m_subckt, 1, wxEXPAND | wxALL, 5 );
m_pinAssignmentsPanel->SetSizer( bSizer10 );
m_pinAssignmentsPanel->Layout();
bSizer10->Fit( m_pinAssignmentsPanel );
m_notebook->AddPage( m_pinAssignmentsPanel, _("Pin Assignments"), false );
bSizer8->Add( m_notebook, 1, wxEXPAND|wxALL, 10 );
bSizer8->Add( m_notebook, 1, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 10 );
wxBoxSizer* bSizer81;
bSizer81 = new wxBoxSizer( wxHORIZONTAL );

View File

@ -63,7 +63,7 @@
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">10</property>
<property name="flag">wxEXPAND|wxALL</property>
<property name="flag">wxEXPAND|wxTOP|wxRIGHT|wxLEFT</property>
<property name="proportion">1</property>
<object class="wxNotebook" expanded="1">
<property name="BottomDockable">1</property>
@ -167,7 +167,7 @@
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="subclass">; ; forward_declare</property>
<property name="subclass"></property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
@ -1886,6 +1886,134 @@
<event name="OnSize">onPinAssignmentsGridSize</event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">8</property>
<property name="flag">wxTOP|wxRIGHT|wxLEFT</property>
<property name="proportion">0</property>
<object class="wxStaticText" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Reference</property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_subcktLabel</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<property name="wrap">-1</property>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND | wxALL</property>
<property name="proportion">1</property>
<object class="wxStyledTextCtrl" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="backspace_unindents">1</property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="folding">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="indentation_guides">1</property>
<property name="line_numbers">1</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_subckt</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="read_only">0</property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="subclass">; ; forward_declare</property>
<property name="tab_indents">1</property>
<property name="tab_width">4</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="use_tabs">1</property>
<property name="view_eol">0</property>
<property name="view_whitespace">0</property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
</object>
</object>
</object>
</object>
</object>

View File

@ -79,6 +79,8 @@ class DIALOG_SIM_MODEL_BASE : public DIALOG_SHIM
wxCheckBox* m_saveInValueCheckbox;
wxPanel* m_pinAssignmentsPanel;
WX_GRID* m_pinAssignmentsGrid;
wxStaticText* m_subcktLabel;
wxStyledTextCtrl* m_subckt;
wxStdDialogButtonSizer* m_sdbSizer1;
wxButton* m_sdbSizer1OK;
wxButton* m_sdbSizer1Cancel;

View File

@ -80,7 +80,7 @@ SIM_MODEL::DEVICE_INFO SIM_MODEL::DeviceInfo( DEVICE_T aDeviceType )
case DEVICE_T::V: return { "V", "Voltage Source", true };
case DEVICE_T::I: return { "I", "Current Source", true };
case DEVICE_T::KIBIS: return { "IBIS", "IBIS Model", false };
case DEVICE_T::KIBIS: return { "IBIS", "IBIS Model", false };
case DEVICE_T::SUBCKT: return { "SUBCKT", "Subcircuit", false };
case DEVICE_T::XSPICE: return { "XSPICE", "XSPICE Code Model", true };

View File

@ -155,3 +155,14 @@ void SIM_MODEL_SUBCKT::SetBaseModel( const SIM_MODEL& aBaseModel )
AddParam( param.info );
}
std::string SIM_MODEL_SUBCKT::GetSpiceCode() const
{
if( !m_spiceCode.empty() )
return m_spiceCode;
if( const SIM_MODEL_SUBCKT* baseModel = dynamic_cast<const SIM_MODEL_SUBCKT*>( m_baseModel ) )
return baseModel->GetSpiceCode();
return "";
}

View File

@ -57,6 +57,8 @@ public:
void SetBaseModel( const SIM_MODEL& aBaseModel ) override;
std::string GetSpiceCode() const;
private:
bool requiresSpiceModelLine() const override { return true; }