diff --git a/eeschema/sim/ngspice.cpp b/eeschema/sim/ngspice.cpp index fb8d032064..19b7305039 100644 --- a/eeschema/sim/ngspice.cpp +++ b/eeschema/sim/ngspice.cpp @@ -194,11 +194,14 @@ bool NGSPICE::LoadNetlist( const string& aNetlist ) vector 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; diff --git a/eeschema/sim/ngspice.h b/eeschema/sim/ngspice.h index 7f0a5e5bf8..0e0ab13c6b 100644 --- a/eeschema/sim/ngspice.h +++ b/eeschema/sim/ngspice.h @@ -73,6 +73,9 @@ public: ///> @copydoc SPICE_SIMULATOR::GetPhasePlot() std::vector 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 */ diff --git a/eeschema/sim/sim_plot_frame.cpp b/eeschema/sim/sim_plot_frame.cpp index 017adccdfc..3ec9ce71c6 100644 --- a/eeschema/sim/sim_plot_frame.cpp +++ b/eeschema/sim/sim_plot_frame.cpp @@ -24,6 +24,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ +#include + #include #include #include @@ -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 ) { diff --git a/eeschema/sim/sim_plot_frame.h b/eeschema/sim/sim_plot_frame.h index 898ab3c2a2..208db4dde7 100644 --- a/eeschema/sim/sim_plot_frame.h +++ b/eeschema/sim/sim_plot_frame.h @@ -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 ); diff --git a/eeschema/sim/sim_plot_frame_base.cpp b/eeschema/sim/sim_plot_frame_base.cpp index 9ecce9087a..acc7dbf357 100644 --- a/eeschema/sim/sim_plot_frame_base.cpp +++ b/eeschema/sim/sim_plot_frame_base.cpp @@ -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 ); diff --git a/eeschema/sim/sim_plot_frame_base.fbp b/eeschema/sim/sim_plot_frame_base.fbp index 2cd9ec647b..fd7b129ce3 100644 --- a/eeschema/sim/sim_plot_frame_base.fbp +++ b/eeschema/sim/sim_plot_frame_base.fbp @@ -88,7 +88,7 @@ - + 1 @@ -240,7 +240,7 @@ - + Simulation m_simulationMenu protected @@ -308,6 +308,21 @@ + + + 0 + 1 + Shows current simulation's netlist. Useful for debugging SPICE errors. + wxID_ANY + wxITEM_NORMAL + Show SPICE Netlist... + m_showNetlist + protected + + + + + m_separator41 none diff --git a/eeschema/sim/sim_plot_frame_base.h b/eeschema/sim/sim_plot_frame_base.h index 4e6bbe14bc..5d746b801c 100644 --- a/eeschema/sim/sim_plot_frame_base.h +++ b/eeschema/sim/sim_plot_frame_base.h @@ -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; diff --git a/eeschema/sim/spice_simulator.h b/eeschema/sim/spice_simulator.h index a3a460a23a..af5250405a 100644 --- a/eeschema/sim/spice_simulator.h +++ b/eeschema/sim/spice_simulator.h @@ -134,6 +134,12 @@ public: */ virtual std::vector 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;