diff --git a/eeschema/dialogs/dialog_spice_model.cpp b/eeschema/dialogs/dialog_spice_model.cpp
index 526e6db514..a281583a6a 100644
--- a/eeschema/dialogs/dialog_spice_model.cpp
+++ b/eeschema/dialogs/dialog_spice_model.cpp
@@ -596,23 +596,22 @@ void DIALOG_SPICE_MODEL::loadLibrary( const wxString& aFilePath )
wxFileName filePath( aFilePath );
bool in_subckt = false; // flag indicating that the parser is inside a .subckt section
+ // Look for the file in the project path
if( !filePath.Exists() )
{
- // Look for the file in the project path
filePath.SetPath( Prj().GetProjectPath() + filePath.GetPath() );
+
+ if( !filePath.Exists() )
+ return;
}
- wxTextFile file;
- int line_counter = 0;
-
- if( !file.Open( filePath.GetFullPath() ) )
- return;
+ // Display the library contents
+ m_libraryContents->LoadFile( filePath.GetFullPath() );
// Process the file, looking for components
- for( wxString line = file.GetFirstLine().Lower(); !file.Eof(); line = file.GetNextLine() )
+ for( int line_nr = 0; line_nr < m_libraryContents->GetNumberOfLines(); ++line_nr )
{
- ++line_counter;
- wxStringTokenizer tokenizer( line, wxDEFAULT_DELIMITERS );
+ wxStringTokenizer tokenizer( m_libraryContents->GetLineText( line_nr ) );
while( tokenizer.HasMoreTokens() )
{
@@ -631,7 +630,7 @@ void DIALOG_SPICE_MODEL::loadLibrary( const wxString& aFilePath )
MODEL::TYPE type = MODEL::parseModelType( token );
if( type != MODEL::UNKNOWN )
- m_models.emplace( name, MODEL( line_counter, type ) );
+ m_models.emplace( name, MODEL( line_nr, type ) );
}
else if( token == ".subckt" )
@@ -644,7 +643,7 @@ void DIALOG_SPICE_MODEL::loadLibrary( const wxString& aFilePath )
if( name.IsEmpty() )
break;
- m_models.emplace( name, MODEL( line_counter, MODEL::SUBCKT ) );
+ m_models.emplace( name, MODEL( line_nr, MODEL::SUBCKT ) );
}
else if( token == ".ends" )
@@ -745,9 +744,19 @@ void DIALOG_SPICE_MODEL::onModelSelected( wxCommandEvent& event )
auto it = m_models.find( m_modelName->GetValue() );
if( it != m_models.end() )
+ {
m_modelType->SetSelection( (int) it->second.model );
+
+ // scroll to the bottom, so the model definition is shown in the first line
+ m_libraryContents->ShowPosition(
+ m_libraryContents->XYToPosition( 0, m_libraryContents->GetNumberOfLines() ) );
+ m_libraryContents->ShowPosition( m_libraryContents->XYToPosition( 0, it->second.line ) );
+ }
else
+ {
m_modelType->SetSelection( wxNOT_FOUND );
+ m_libraryContents->ShowPosition( 0 );
+ }
}
diff --git a/eeschema/dialogs/dialog_spice_model_base.cpp b/eeschema/dialogs/dialog_spice_model_base.cpp
index bb579fb8fe..60417c34ca 100644
--- a/eeschema/dialogs/dialog_spice_model_base.cpp
+++ b/eeschema/dialogs/dialog_spice_model_base.cpp
@@ -198,8 +198,11 @@ DIALOG_SPICE_MODEL_BASE::DIALOG_SPICE_MODEL_BASE( wxWindow* parent, wxWindowID i
bSizer41->Fit( m_passive );
m_notebook->AddPage( m_passive, _("Passive"), false );
m_model = new wxPanel( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
+ wxBoxSizer* bSizer6;
+ bSizer6 = new wxBoxSizer( wxVERTICAL );
+
wxFlexGridSizer* fgSizer3;
- fgSizer3 = new wxFlexGridSizer( 0, 3, 0, 0 );
+ fgSizer3 = new wxFlexGridSizer( 0, 2, 0, 0 );
fgSizer3->AddGrowableCol( 1 );
fgSizer3->SetFlexibleDirection( wxBOTH );
fgSizer3->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
@@ -208,11 +211,17 @@ DIALOG_SPICE_MODEL_BASE::DIALOG_SPICE_MODEL_BASE( wxWindow* parent, wxWindowID i
m_staticText7->Wrap( -1 );
fgSizer3->Add( m_staticText7, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
+ wxBoxSizer* bSizer7;
+ bSizer7 = new wxBoxSizer( wxHORIZONTAL );
+
m_modelLibrary = new wxTextCtrl( m_model, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY );
- fgSizer3->Add( m_modelLibrary, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 5 );
+ bSizer7->Add( m_modelLibrary, 1, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 5 );
m_selectLibrary = new wxButton( m_model, wxID_ANY, _("Select file..."), wxDefaultPosition, wxDefaultSize, 0 );
- fgSizer3->Add( m_selectLibrary, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
+ bSizer7->Add( m_selectLibrary, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
+
+
+ fgSizer3->Add( bSizer7, 1, wxEXPAND, 5 );
m_staticText5 = new wxStaticText( m_model, wxID_ANY, _("Model"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText5->Wrap( -1 );
@@ -221,9 +230,6 @@ DIALOG_SPICE_MODEL_BASE::DIALOG_SPICE_MODEL_BASE( wxWindow* parent, wxWindowID i
m_modelName = new wxComboBox( m_model, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_SORT );
fgSizer3->Add( m_modelName, 0, wxALL|wxEXPAND, 5 );
-
- fgSizer3->Add( 0, 0, 0, 0, 5 );
-
m_staticText4 = new wxStaticText( m_model, wxID_ANY, _("Type"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText4->Wrap( -1 );
fgSizer3->Add( m_staticText4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
@@ -236,12 +242,17 @@ DIALOG_SPICE_MODEL_BASE::DIALOG_SPICE_MODEL_BASE( wxWindow* parent, wxWindowID i
fgSizer3->Add( m_modelType, 0, wxALL|wxEXPAND, 5 );
- fgSizer3->Add( 0, 0, 0, 0, 5 );
+ bSizer6->Add( fgSizer3, 0, wxEXPAND, 5 );
+
+ m_libraryContents = new wxTextCtrl( m_model, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_DONTWRAP|wxTE_MULTILINE|wxTE_READONLY );
+ m_libraryContents->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxEmptyString ) );
+
+ bSizer6->Add( m_libraryContents, 1, wxALL|wxEXPAND, 5 );
- m_model->SetSizer( fgSizer3 );
+ m_model->SetSizer( bSizer6 );
m_model->Layout();
- fgSizer3->Fit( m_model );
+ bSizer6->Fit( m_model );
m_notebook->AddPage( m_model, _("Model"), true );
m_power = new wxPanel( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
m_power->SetMinSize( wxSize( 650,-1 ) );
diff --git a/eeschema/dialogs/dialog_spice_model_base.fbp b/eeschema/dialogs/dialog_spice_model_base.fbp
index f28b13f919..8e01069e32 100644
--- a/eeschema/dialogs/dialog_spice_model_base.fbp
+++ b/eeschema/dialogs/dialog_spice_model_base.fbp
@@ -262,7 +262,7 @@
5
wxEXPAND|wxALL
0
-
-
+
5
wxALL
0
-
+
1
1
1
@@ -705,11 +705,11 @@
-
+
5
wxALL
0
-
+
1
1
1
@@ -875,16 +875,16 @@
5
wxALIGN_CENTER_HORIZONTAL
0
-
+
bSizer5
wxVERTICAL
none
-
+
5
wxALL
0
-
+
1
1
1
@@ -963,11 +963,11 @@
-
+
5
wxTOP|wxRIGHT|wxLEFT
0
-
+
1
1
1
@@ -1046,7 +1046,7 @@
-
+
5
wxEXPAND
1
@@ -3388,106 +3388,655 @@
-
- 3
- wxBOTH
- 1
-
- 0
+
- fgSizer3
- wxFLEX_GROWMODE_SPECIFIED
+ bSizer6
+ wxVERTICAL
none
- 0
- 0
-
+
5
- wxALIGN_CENTER_VERTICAL|wxALL
+ wxEXPAND
0
-
- 1
- 1
- 1
- 1
-
-
-
-
-
-
-
- 1
- 0
- 1
-
- 1
- 0
- Dock
- 0
- Left
- 1
-
- 1
-
- 0
- 0
- wxID_ANY
- Library
-
- 0
-
-
- 0
+
+ 2
+ wxBOTH
+ 1
+
+ 0
- 1
- m_staticText7
- 1
-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
+
+ -1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 5
+ wxALL|wxEXPAND
+ 0
+
+ 1
+ 1
+ 1
+ 1
+
+
+
+
+
+
+
+ 1
+ 0
+ "Subcircuit" "BJT" "MOSFET" "Diode"
+ 1
+
+ 1
+ 0
+ Dock
+ 0
+ Left
+ 1
+
+ 1
+
+ 0
+ 0
+ wxID_ANY
+
+ 0
+
+
+ 0
+
+ 1
+ m_modelType
+ 1
+
+
+ protected
+ 1
+
+ Resizable
+ -1
+ 1
+
+ wxCB_READONLY
+
+ 0
+
+
+ wxFILTER_NONE
+ wxDefaultValidator
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
5
- wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND
- 0
-
+ wxALL|wxEXPAND
+ 1
+
1
1
1
@@ -3511,19 +4060,19 @@
1
1
-
+ ,90,90,-1,76,0
0
0
wxID_ANY
0
- 0
+
0
1
- m_modelLibrary
+ m_libraryContents
1
@@ -3533,7 +4082,7 @@
Resizable
1
- wxTE_READONLY
+ wxTE_DONTWRAP|wxTE_MULTILINE|wxTE_READONLY
0
@@ -3574,462 +4123,6 @@
-
- 5
- wxALIGN_CENTER_VERTICAL|wxALL
- 0
-
- 1
- 1
- 1
- 1
-
-
-
-
-
-
-
- 1
- 0
- 1
-
- 1
- 0
- 0
- Dock
- 0
- Left
- 1
-
- 1
-
- 0
- 0
- wxID_ANY
- Select file...
-
- 0
-
-
- 0
-
- 1
- m_selectLibrary
- 1
-
-
- protected
- 1
-
- Resizable
- 1
-
-
-
- 0
-
-
- wxFILTER_NONE
- wxDefaultValidator
-
-
-
-
- onSelectLibrary
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 5
- wxALIGN_CENTER_VERTICAL|wxALL
- 0
-
- 1
- 1
- 1
- 1
-
-
-
-
-
-
-
- 1
- 0
- 1
-
- 1
- 0
- Dock
- 0
- Left
- 1
-
- 1
-
- 0
- 0
- wxID_ANY
- Model
-
- 0
-
-
- 0
-
- 1
- m_staticText5
- 1
-
-
- protected
- 1
-
- Resizable
- 1
-
-
-
- 0
-
-
-
-
- -1
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 5
- wxALL|wxEXPAND
- 0
-
- 1
- 1
- 1
- 1
-
-
-
-
-
-
-
- 1
- 0
-
- 1
-
- 1
- 0
- Dock
- 0
- Left
- 1
-
- 1
-
- 0
- 0
- wxID_ANY
-
- 0
-
-
- 0
-
- 1
- m_modelName
- 1
-
-
- protected
- 1
-
- Resizable
- -1
- 1
-
- wxCB_SORT
-
- 0
-
-
- wxFILTER_NONE
- wxDefaultValidator
-
-
-
-
-
-
- onModelSelected
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- onModelSelected
-
-
-
-
-
- 5
-
- 0
-
- 0
- protected
- 0
-
-
-
- 5
- wxALIGN_CENTER_VERTICAL|wxALL
- 0
-
- 1
- 1
- 1
- 1
-
-
-
-
-
-
-
- 1
- 0
- 1
-
- 1
- 0
- Dock
- 0
- Left
- 1
-
- 1
-
- 0
- 0
- wxID_ANY
- Type
-
- 0
-
-
- 0
-
- 1
- m_staticText4
- 1
-
-
- protected
- 1
-
- Resizable
- 1
-
-
-
- 0
-
-
-
-
- -1
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 5
- wxALL|wxEXPAND
- 0
-
- 1
- 1
- 1
- 1
-
-
-
-
-
-
-
- 1
- 0
- "Subcircuit" "BJT" "MOSFET" "Diode"
- 1
-
- 1
- 0
- Dock
- 0
- Left
- 1
-
- 1
-
- 0
- 0
- wxID_ANY
-
- 0
-
-
- 0
-
- 1
- m_modelType
- 1
-
-
- protected
- 1
-
- Resizable
- -1
- 1
-
- wxCB_READONLY
-
- 0
-
-
- wxFILTER_NONE
- wxDefaultValidator
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 5
-
- 0
-
- 0
- protected
- 0
-
-
diff --git a/eeschema/dialogs/dialog_spice_model_base.h b/eeschema/dialogs/dialog_spice_model_base.h
index 1294aea3b5..c4c7a34a8b 100644
--- a/eeschema/dialogs/dialog_spice_model_base.h
+++ b/eeschema/dialogs/dialog_spice_model_base.h
@@ -93,6 +93,7 @@ class DIALOG_SPICE_MODEL_BASE : public DIALOG_SHIM
wxComboBox* m_modelName;
wxStaticText* m_staticText4;
wxComboBox* m_modelType;
+ wxTextCtrl* m_libraryContents;
wxPanel* m_power;
wxStaticText* m_staticText10;
wxTextCtrl* m_genDc;