From c71202d143d827d713c7e9912184843a25730bbd Mon Sep 17 00:00:00 2001 From: Jonatan Liljedahl Date: Thu, 7 Nov 2019 09:47:12 +0100 Subject: [PATCH] Eeschema: simulation: allow adding signals by name like V(/out) or I(R1) NEW: A text entry allows adding signals by name. This includes vectors not in the signal list, which is useful for plotting calculated vectors like `let AB=V(a)*V(b)`. It's also a faster way to add a signal if you know its name already. Fixes: lp:1851373 * https://bugs.launchpad.net/kicad/+bug/1851373 --- eeschema/dialogs/dialog_signal_list.cpp | 58 ++++-- eeschema/dialogs/dialog_signal_list.h | 1 + eeschema/dialogs/dialog_signal_list_base.cpp | 33 ++-- eeschema/dialogs/dialog_signal_list_base.fbp | 197 ++++++++++++------- eeschema/dialogs/dialog_signal_list_base.h | 24 +-- 5 files changed, 206 insertions(+), 107 deletions(-) diff --git a/eeschema/dialogs/dialog_signal_list.cpp b/eeschema/dialogs/dialog_signal_list.cpp index 425e69f801..1d57e4ac85 100644 --- a/eeschema/dialogs/dialog_signal_list.cpp +++ b/eeschema/dialogs/dialog_signal_list.cpp @@ -86,6 +86,37 @@ bool DIALOG_SIGNAL_LIST::TransferDataToWindow() } +bool DIALOG_SIGNAL_LIST::addSignalToPlotFrame( const wxString& aPlotName ) +{ + + // Get the part in the parentheses + wxString name = aPlotName.AfterFirst( '(' ).BeforeLast( ')' ); + + if( !name.IsEmpty() ) + { + wxUniChar firstChar = aPlotName[0]; + if( firstChar == 'V' || firstChar == 'v' ) + { + m_plotFrame->AddVoltagePlot( name ); + } + else if( firstChar == 'I' || firstChar == 'i' ) + { + m_plotFrame->AddCurrentPlot( name, aPlotName.BeforeFirst( '(' ) ); + } + else + { + return false; + } + } + else + { + return false; + } + + return true; +} + + void DIALOG_SIGNAL_LIST::addSelectionToPlotFrame() { for( unsigned int i = 0; i < m_signals->GetCount(); ++i ) @@ -93,22 +124,19 @@ void DIALOG_SIGNAL_LIST::addSelectionToPlotFrame() if( m_signals->IsSelected( i ) ) { const wxString& plotName = m_signals->GetString( i ); - - // Get the part in the parentheses - wxString name = plotName.AfterFirst( '(' ).BeforeLast( ')' ); - - if( plotName[0] == 'V' ) - { - m_plotFrame->AddVoltagePlot( name ); - } - else if( plotName[0] == 'I' ) - { - m_plotFrame->AddCurrentPlot( name, plotName.BeforeFirst( '(' ) ); - } - else - { + if( !addSignalToPlotFrame( plotName ) ) wxASSERT_MSG( false, "Unhandled plot type" ); - } } } + + // Add manually entered signal, if any + const wxString& plotName = m_signalEntry->GetValue(); + + if( !plotName.IsEmpty() ) + { + if( !addSignalToPlotFrame( plotName ) ) + m_plotFrame->AddVoltagePlot( plotName ); // Assume it's a V plot by default + + m_signalEntry->SetSelection( -1, -1 ); + } } diff --git a/eeschema/dialogs/dialog_signal_list.h b/eeschema/dialogs/dialog_signal_list.h index 402f8b1888..5e2eebd017 100644 --- a/eeschema/dialogs/dialog_signal_list.h +++ b/eeschema/dialogs/dialog_signal_list.h @@ -45,6 +45,7 @@ private: } void addSelectionToPlotFrame(); + bool addSignalToPlotFrame( const wxString& aPlotName ); SIM_PLOT_FRAME* m_plotFrame; NETLIST_EXPORTER_PSPICE_SIM* m_exporter; diff --git a/eeschema/dialogs/dialog_signal_list_base.cpp b/eeschema/dialogs/dialog_signal_list_base.cpp index 3f69d9f95a..f015c26b4a 100644 --- a/eeschema/dialogs/dialog_signal_list_base.cpp +++ b/eeschema/dialogs/dialog_signal_list_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Nov 22 2017) +// C++ code generated with wxFormBuilder (version Oct 26 2018) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -12,38 +12,47 @@ DIALOG_SIGNAL_LIST_BASE::DIALOG_SIGNAL_LIST_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style ) { this->SetSizeHints( wxSize( -1,-1 ), wxDefaultSize ); - + wxBoxSizer* bSizer6; bSizer6 = new wxBoxSizer( wxVERTICAL ); - - m_signals = new wxListBox( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_EXTENDED|wxLB_NEEDED_SB|wxLB_SORT ); + + m_signals = new wxListBox( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_EXTENDED|wxLB_NEEDED_SB|wxLB_SORT ); m_signals->SetMinSize( wxSize( 450,400 ) ); - + bSizer6->Add( m_signals, 1, wxALL|wxEXPAND, 5 ); - + + m_staticText1 = new wxStaticText( this, wxID_ANY, _("Add signal by name:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticText1->Wrap( -1 ); + bSizer6->Add( m_staticText1, 0, wxALL, 5 ); + + m_signalEntry = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER ); + bSizer6->Add( m_signalEntry, 0, wxALL|wxEXPAND, 5 ); + m_sdbSizer = new wxStdDialogButtonSizer(); m_sdbSizerOK = new wxButton( this, wxID_OK ); m_sdbSizer->AddButton( m_sdbSizerOK ); m_sdbSizerCancel = new wxButton( this, wxID_CANCEL ); m_sdbSizer->AddButton( m_sdbSizerCancel ); m_sdbSizer->Realize(); - + bSizer6->Add( m_sdbSizer, 0, wxEXPAND|wxALL, 5 ); - - + + this->SetSizer( bSizer6 ); this->Layout(); bSizer6->Fit( this ); - + this->Centre( wxBOTH ); - + // Connect Events m_signals->Connect( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEventHandler( DIALOG_SIGNAL_LIST_BASE::onSignalAdd ), NULL, this ); + m_signalEntry->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_SIGNAL_LIST_BASE::onSignalAdd ), NULL, this ); } DIALOG_SIGNAL_LIST_BASE::~DIALOG_SIGNAL_LIST_BASE() { // Disconnect Events m_signals->Disconnect( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEventHandler( DIALOG_SIGNAL_LIST_BASE::onSignalAdd ), NULL, this ); - + m_signalEntry->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_SIGNAL_LIST_BASE::onSignalAdd ), NULL, this ); + } diff --git a/eeschema/dialogs/dialog_signal_list_base.fbp b/eeschema/dialogs/dialog_signal_list_base.fbp index a2a6a6e182..8fdca5f295 100644 --- a/eeschema/dialogs/dialog_signal_list_base.fbp +++ b/eeschema/dialogs/dialog_signal_list_base.fbp @@ -1,6 +1,6 @@ - + C++ @@ -14,6 +14,7 @@ dialog_signal_list_base 1000 none + 1 DIALOG_SIGNAL_LIST_BASE @@ -52,42 +53,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bSizer6 @@ -154,31 +119,133 @@ - - - - - - - - - - - onSignalAdd - - - - - - - - - - - - - + + + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Add signal by name: + 0 + + 0 + + + 0 + + 1 + m_staticText1 + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 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_signalEntry + 1 + + + protected + 1 + + Resizable + 1 + + wxTE_PROCESS_ENTER + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + onSignalAdd @@ -197,14 +264,6 @@ m_sdbSizer protected - - - - - - - - diff --git a/eeschema/dialogs/dialog_signal_list_base.h b/eeschema/dialogs/dialog_signal_list_base.h index 5c55a00711..75d62d15e9 100644 --- a/eeschema/dialogs/dialog_signal_list_base.h +++ b/eeschema/dialogs/dialog_signal_list_base.h @@ -1,12 +1,11 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Nov 22 2017) +// C++ code generated with wxFormBuilder (version Oct 26 2018) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// -#ifndef __DIALOG_SIGNAL_LIST_BASE_H__ -#define __DIALOG_SIGNAL_LIST_BASE_H__ +#pragma once #include #include @@ -18,6 +17,8 @@ #include #include #include +#include +#include #include #include #include @@ -31,22 +32,23 @@ class DIALOG_SIGNAL_LIST_BASE : public DIALOG_SHIM { private: - + protected: wxListBox* m_signals; + wxStaticText* m_staticText1; + wxTextCtrl* m_signalEntry; wxStdDialogButtonSizer* m_sdbSizer; wxButton* m_sdbSizerOK; wxButton* m_sdbSizerCancel; - + // Virtual event handlers, overide them in your derived class virtual void onSignalAdd( wxCommandEvent& event ) { event.Skip(); } - - + + public: - - DIALOG_SIGNAL_LIST_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + + DIALOG_SIGNAL_LIST_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); ~DIALOG_SIGNAL_LIST_BASE(); - + }; -#endif //__DIALOG_SIGNAL_LIST_BASE_H__