Added library contents preview to Spice model editor dialog

This commit is contained in:
Maciej Suminski 2017-10-26 23:59:56 +02:00
parent 162d445ce4
commit 2b052265b2
4 changed files with 697 additions and 583 deletions

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

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