Added 'show spice netlist' menu option in the simulator
Fixes: lp:1745887 * https://bugs.launchpad.net/kicad/+bug/1745887
This commit is contained in:
parent
d3b259cc09
commit
919b449595
|
@ -194,11 +194,14 @@ bool NGSPICE::LoadNetlist( const string& aNetlist )
|
|||
vector<char*> lines;
|
||||
stringstream ss( aNetlist );
|
||||
|
||||
m_netlist = "";
|
||||
|
||||
while( !ss.eof() )
|
||||
{
|
||||
char line[1024];
|
||||
ss.getline( line, sizeof( line ) );
|
||||
lines.push_back( strdup( line ) );
|
||||
m_netlist += std::string( line ) + std::string( "\n" );
|
||||
}
|
||||
|
||||
lines.push_back( nullptr );
|
||||
|
@ -430,5 +433,10 @@ int NGSPICE::cbControlledExit( int status, bool immediate, bool exit_upon_quit,
|
|||
return 0;
|
||||
}
|
||||
|
||||
const std::string NGSPICE::GetNetlist() const
|
||||
{
|
||||
return m_netlist;
|
||||
}
|
||||
|
||||
|
||||
bool NGSPICE::m_initialized = false;
|
||||
|
|
|
@ -73,6 +73,9 @@ public:
|
|||
///> @copydoc SPICE_SIMULATOR::GetPhasePlot()
|
||||
std::vector<double> GetPhasePlot( const std::string& aName, int aMaxLen = -1 ) override;
|
||||
|
||||
///> @copydoc SPICE_SIMULATOR::GetNetlist()
|
||||
virtual const std::string GetNetlist() const override;
|
||||
|
||||
private:
|
||||
void init();
|
||||
|
||||
|
@ -96,6 +99,9 @@ private:
|
|||
|
||||
///> NGspice should be initialized only once
|
||||
static bool m_initialized;
|
||||
|
||||
///> current netlist
|
||||
std::string m_netlist;
|
||||
};
|
||||
|
||||
#endif /* NGSPICE_H */
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include <wx/stc/stc.h>
|
||||
|
||||
#include <sch_edit_frame.h>
|
||||
#include <eeschema_id.h>
|
||||
#include <kiway.h>
|
||||
|
@ -181,11 +183,12 @@ SIM_PLOT_FRAME::SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent )
|
|||
wxCommandEventHandler( SIM_PLOT_FRAME::onSettings ), NULL, this );
|
||||
|
||||
// Bind toolbar buttons event to existing menu event handlers, so they behave the same
|
||||
Bind( wxEVT_COMMAND_MENU_SELECTED, &SIM_PLOT_FRAME::onSimulate, this, m_runSimulation->GetId() );
|
||||
Bind( wxEVT_COMMAND_MENU_SELECTED, &SIM_PLOT_FRAME::onAddSignal, this, m_addSignals->GetId() );
|
||||
Bind( wxEVT_COMMAND_MENU_SELECTED, &SIM_PLOT_FRAME::onProbe, this, m_probeSignals->GetId() );
|
||||
Bind( wxEVT_COMMAND_MENU_SELECTED, &SIM_PLOT_FRAME::onTune, this, m_tuneValue->GetId() );
|
||||
Bind( wxEVT_COMMAND_MENU_SELECTED, &SIM_PLOT_FRAME::onSettings, this, m_settings->GetId() );
|
||||
Bind( wxEVT_COMMAND_MENU_SELECTED, &SIM_PLOT_FRAME::onSimulate, this, m_runSimulation->GetId() );
|
||||
Bind( wxEVT_COMMAND_MENU_SELECTED, &SIM_PLOT_FRAME::onAddSignal, this, m_addSignals->GetId() );
|
||||
Bind( wxEVT_COMMAND_MENU_SELECTED, &SIM_PLOT_FRAME::onProbe, this, m_probeSignals->GetId() );
|
||||
Bind( wxEVT_COMMAND_MENU_SELECTED, &SIM_PLOT_FRAME::onTune, this, m_tuneValue->GetId() );
|
||||
Bind( wxEVT_COMMAND_MENU_SELECTED, &SIM_PLOT_FRAME::onShowNetlist, this, m_showNetlist->GetId() );
|
||||
Bind( wxEVT_COMMAND_MENU_SELECTED, &SIM_PLOT_FRAME::onSettings, this, m_settings->GetId() );
|
||||
|
||||
m_toolBar->Realize();
|
||||
m_plotNotebook->SetPageText( 0, _( "Welcome!" ) );
|
||||
|
@ -1074,6 +1077,57 @@ void SIM_PLOT_FRAME::onTune( wxCommandEvent& event )
|
|||
m_schematicFrame->Raise();
|
||||
}
|
||||
|
||||
void SIM_PLOT_FRAME::onShowNetlist( wxCommandEvent& event )
|
||||
{
|
||||
class NETLIST_VIEW_DIALOG : public wxDialog
|
||||
{
|
||||
public:
|
||||
enum
|
||||
{
|
||||
MARGIN_LINE_NUMBERS
|
||||
};
|
||||
|
||||
void onClose( wxCloseEvent& evt )
|
||||
{
|
||||
EndModal( GetReturnCode() );
|
||||
}
|
||||
|
||||
NETLIST_VIEW_DIALOG(wxWindow* parent, wxString source) :
|
||||
wxDialog(parent, wxID_ANY, "SPICE Netlist",
|
||||
wxDefaultPosition, wxSize(1500,900),
|
||||
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
|
||||
{
|
||||
wxStyledTextCtrl* text = new wxStyledTextCtrl(this, wxID_ANY);
|
||||
|
||||
text->SetMarginWidth (MARGIN_LINE_NUMBERS, 50);
|
||||
text->StyleSetForeground (wxSTC_STYLE_LINENUMBER, wxColour (75, 75, 75) );
|
||||
text->StyleSetBackground (wxSTC_STYLE_LINENUMBER, wxColour (220, 220, 220));
|
||||
text->SetMarginType (MARGIN_LINE_NUMBERS, wxSTC_MARGIN_NUMBER);
|
||||
|
||||
text->SetWrapMode (wxSTC_WRAP_WORD);
|
||||
|
||||
text->SetText( source );
|
||||
|
||||
text->StyleClearAll();
|
||||
text->SetLexer(wxSTC_LEX_SPICE);
|
||||
|
||||
wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
|
||||
sizer->Add(text, 1, wxEXPAND);
|
||||
SetSizer(sizer);
|
||||
|
||||
Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(NETLIST_VIEW_DIALOG::onClose), NULL, this);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
if( m_schematicFrame == NULL || m_simulator == NULL )
|
||||
return;
|
||||
|
||||
NETLIST_VIEW_DIALOG dlg( this, m_simulator->GetNetlist() );
|
||||
|
||||
dlg.ShowModal();
|
||||
}
|
||||
|
||||
|
||||
void SIM_PLOT_FRAME::onClose( wxCloseEvent& aEvent )
|
||||
{
|
||||
|
|
|
@ -261,6 +261,7 @@ private:
|
|||
void onAddSignal( wxCommandEvent& event );
|
||||
void onProbe( wxCommandEvent& event );
|
||||
void onTune( wxCommandEvent& event );
|
||||
void onShowNetlist( wxCommandEvent& event );
|
||||
|
||||
void onClose( wxCloseEvent& aEvent );
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
// C++ code generated with wxFormBuilder (version Jan 2 2018)
|
||||
// C++ code generated with wxFormBuilder (version Nov 10 2017)
|
||||
// http://www.wxformbuilder.org/
|
||||
//
|
||||
// PLEASE DO *NOT* EDIT THIS FILE!
|
||||
|
@ -62,6 +62,9 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const
|
|||
m_tuneValue = new wxMenuItem( m_simulationMenu, wxID_ANY, wxString( _("Tune component value") ) , wxEmptyString, wxITEM_NORMAL );
|
||||
m_simulationMenu->Append( m_tuneValue );
|
||||
|
||||
m_showNetlist = new wxMenuItem( m_simulationMenu, wxID_ANY, wxString( _("Show SPICE Netlist...") ) , _("Shows current simulation's netlist. Useful for debugging SPICE errors."), wxITEM_NORMAL );
|
||||
m_simulationMenu->Append( m_showNetlist );
|
||||
|
||||
m_simulationMenu->AppendSeparator();
|
||||
|
||||
m_settings = new wxMenuItem( m_simulationMenu, wxID_ANY, wxString( _("Settings...") ) , wxEmptyString, wxITEM_NORMAL );
|
||||
|
|
|
@ -88,7 +88,7 @@
|
|||
<event name="OnSetFocus"></event>
|
||||
<event name="OnSize"></event>
|
||||
<event name="OnUpdateUI"></event>
|
||||
<object class="wxMenuBar" expanded="0">
|
||||
<object class="wxMenuBar" expanded="1">
|
||||
<property name="bg"></property>
|
||||
<property name="context_help"></property>
|
||||
<property name="context_menu">1</property>
|
||||
|
@ -240,7 +240,7 @@
|
|||
<event name="OnUpdateUI"></event>
|
||||
</object>
|
||||
</object>
|
||||
<object class="wxMenu" expanded="0">
|
||||
<object class="wxMenu" expanded="1">
|
||||
<property name="label">Simulation</property>
|
||||
<property name="name">m_simulationMenu</property>
|
||||
<property name="permission">protected</property>
|
||||
|
@ -308,6 +308,21 @@
|
|||
<event name="OnMenuSelection"></event>
|
||||
<event name="OnUpdateUI"></event>
|
||||
</object>
|
||||
<object class="wxMenuItem" expanded="1">
|
||||
<property name="bitmap"></property>
|
||||
<property name="checked">0</property>
|
||||
<property name="enabled">1</property>
|
||||
<property name="help">Shows current simulation's netlist. Useful for debugging SPICE errors.</property>
|
||||
<property name="id">wxID_ANY</property>
|
||||
<property name="kind">wxITEM_NORMAL</property>
|
||||
<property name="label">Show SPICE Netlist...</property>
|
||||
<property name="name">m_showNetlist</property>
|
||||
<property name="permission">protected</property>
|
||||
<property name="shortcut"></property>
|
||||
<property name="unchecked_bitmap"></property>
|
||||
<event name="OnMenuSelection"></event>
|
||||
<event name="OnUpdateUI"></event>
|
||||
</object>
|
||||
<object class="separator" expanded="0">
|
||||
<property name="name">m_separator41</property>
|
||||
<property name="permission">none</property>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
// C++ code generated with wxFormBuilder (version Jan 2 2018)
|
||||
// C++ code generated with wxFormBuilder (version Nov 10 2017)
|
||||
// http://www.wxformbuilder.org/
|
||||
//
|
||||
// PLEASE DO *NOT* EDIT THIS FILE!
|
||||
|
@ -50,6 +50,7 @@ class SIM_PLOT_FRAME_BASE : public KIWAY_PLAYER
|
|||
wxMenuItem* m_addSignals;
|
||||
wxMenuItem* m_probeSignals;
|
||||
wxMenuItem* m_tuneValue;
|
||||
wxMenuItem* m_showNetlist;
|
||||
wxMenuItem* m_settings;
|
||||
wxMenu* m_viewMenu;
|
||||
wxBoxSizer* m_sizerMain;
|
||||
|
|
|
@ -134,6 +134,12 @@ public:
|
|||
*/
|
||||
virtual std::vector<double> GetPhasePlot( const std::string& aName, int aMaxLen = -1 ) = 0;
|
||||
|
||||
/**
|
||||
* @brief Returns current SPICE netlist used by the simulator.
|
||||
* @return The netlist.
|
||||
*/
|
||||
virtual const std::string GetNetlist() const = 0;
|
||||
|
||||
protected:
|
||||
///> Reporter object to receive simulation log
|
||||
SPICE_REPORTER* m_reporter;
|
||||
|
|
Loading…
Reference in New Issue