From 0d764741f90d2221b01a1796afcb35beef8e3c09 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 11 Aug 2016 14:41:16 +0200 Subject: [PATCH] Simulation commands moved from eeschema menu to SIM_PLOT_FRAME buttons --- eeschema/eeschema_id.h | 3 +-- eeschema/menubar.cpp | 28 +++++++---------------- eeschema/schframe.cpp | 4 ++-- eeschema/schframe.h | 3 +-- eeschema/sim/sim_plot_frame.cpp | 40 ++++++++++++++++++++++++++++----- eeschema/sim/sim_plot_frame.h | 17 ++++++++++---- eeschema/sim/simulate.cpp | 9 +------- 7 files changed, 61 insertions(+), 43 deletions(-) diff --git a/eeschema/eeschema_id.h b/eeschema/eeschema_id.h index de486b3b71..2e94e51e5a 100644 --- a/eeschema/eeschema_id.h +++ b/eeschema/eeschema_id.h @@ -256,8 +256,7 @@ enum id_eeschema_frm ID_UPDATE_PCB_FROM_SCH, ID_UPDATE_SCH_FROM_PCB, - ID_SIM_RUN, - ID_SIM_STOP, + ID_SIM_SHOW, ID_SIM_ADD_PROBE }; diff --git a/eeschema/menubar.cpp b/eeschema/menubar.cpp index 480f9da1f4..b0962d3350 100644 --- a/eeschema/menubar.cpp +++ b/eeschema/menubar.cpp @@ -422,25 +422,6 @@ void SCH_EDIT_FRAME::ReCreateMenuBar() _( "Import and export settings" ), KiBitmap( save_setup_xpm ) ); - - wxMenu* simMenu = new wxMenu; - - AddMenuItem( simMenu, - ID_SIM_RUN, - _("Run simulation"), _( "Run simulation" ), - KiBitmap( pcbnew_xpm ) ); - - AddMenuItem( simMenu, - ID_SIM_STOP, - _( "Stop simulation" ), _( "Stop simulation" ), - KiBitmap( pcbnew_xpm ) ); - - AddMenuItem( simMenu, - ID_SIM_ADD_PROBE, - _( "Add probe" ), _( "Add probe" ), - KiBitmap( pcbnew_xpm ) ); - - // Menu Tools: wxMenu* toolsMenu = new wxMenu; @@ -511,6 +492,14 @@ void SCH_EDIT_FRAME::ReCreateMenuBar() _( "Run CvPcb" ), KiBitmap( cvpcb_xpm ) ); + toolsMenu->AppendSeparator(); + + // Simulator + AddMenuItem( toolsMenu, + ID_SIM_SHOW, + _("Simula&te"), _( "Simulate the circuit" ), + wxNullBitmap ); + // Help Menu: wxMenu* helpMenu = new wxMenu; @@ -545,7 +534,6 @@ void SCH_EDIT_FRAME::ReCreateMenuBar() menuBar->Append( viewMenu, _( "&View" ) ); menuBar->Append( placeMenu, _( "&Place" ) ); menuBar->Append( preferencesMenu, _( "P&references" ) ); - menuBar->Append( simMenu, _( "&Simulate" ) ); menuBar->Append( toolsMenu, _( "&Tools" ) ); menuBar->Append( helpMenu, _( "&Help" ) ); diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index eb46bda90b..ccd1180859 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -264,8 +264,7 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME ) EVT_TOOL( ID_GET_ERC, SCH_EDIT_FRAME::OnErc ) EVT_TOOL( ID_GET_NETLIST, SCH_EDIT_FRAME::OnCreateNetlist ) EVT_TOOL( ID_UPDATE_PCB_FROM_SCH, SCH_EDIT_FRAME::OnUpdatePCB ) - EVT_TOOL( ID_SIM_RUN, SCH_EDIT_FRAME::OnSimulationRun ) - EVT_TOOL( ID_SIM_STOP, SCH_EDIT_FRAME::OnSimulationStop ) + EVT_TOOL( ID_SIM_SHOW, SCH_EDIT_FRAME::OnSimulate ) EVT_TOOL( ID_GET_TOOLS, SCH_EDIT_FRAME::OnCreateBillOfMaterials ) EVT_TOOL( ID_FIND_ITEMS, SCH_EDIT_FRAME::OnFindItems ) EVT_TOOL( wxID_REPLACE, SCH_EDIT_FRAME::OnFindItems ) @@ -281,6 +280,7 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME ) EVT_TOOL( ID_ZOOM_SELECTION, SCH_EDIT_FRAME::OnSelectTool ) EVT_TOOL_RANGE( ID_SCHEMATIC_VERTICAL_TOOLBAR_START, ID_SCHEMATIC_VERTICAL_TOOLBAR_END, SCH_EDIT_FRAME::OnSelectTool ) + EVT_TOOL( ID_SIM_ADD_PROBE, SCH_EDIT_FRAME::OnSelectTool ) EVT_MENU( ID_CANCEL_CURRENT_COMMAND, SCH_EDIT_FRAME::OnCancelCurrentCommand ) diff --git a/eeschema/schframe.h b/eeschema/schframe.h index 1cdec7b898..7c7938f65d 100644 --- a/eeschema/schframe.h +++ b/eeschema/schframe.h @@ -813,8 +813,7 @@ private: void OnErc( wxCommandEvent& event ); void OnCreateNetlist( wxCommandEvent& event ); void OnUpdatePCB( wxCommandEvent& event ); - void OnSimulationRun( wxCommandEvent& event ); - void OnSimulationStop( wxCommandEvent& event ); + void OnSimulate( wxCommandEvent& event ); void OnCreateBillOfMaterials( wxCommandEvent& event ); void OnFindItems( wxCommandEvent& event ); void OnFindDialogClose( wxFindDialogEvent& event ); diff --git a/eeschema/sim/sim_plot_frame.cpp b/eeschema/sim/sim_plot_frame.cpp index 67b9619299..de287f846a 100644 --- a/eeschema/sim/sim_plot_frame.cpp +++ b/eeschema/sim/sim_plot_frame.cpp @@ -24,6 +24,7 @@ */ #include +#include #include #include @@ -35,11 +36,6 @@ #include "sim_plot_panel.h" #include "spice_simulator.h" -#ifdef KICAD_SCRIPTING - #include -#endif - - class SIM_THREAD_REPORTER : public REPORTER { public: @@ -229,6 +225,40 @@ void SIM_PLOT_FRAME::AddVoltagePlot( const wxString& aNetName ) } +bool SIM_PLOT_FRAME::isSimulationRunning() +{ + wxCriticalSectionLocker lock( m_simThreadCS ); + + return ( m_simThread != NULL ); + +} + + +void SIM_PLOT_FRAME::onSimulate( wxCommandEvent& event ) +{ + if( isSimulationRunning() ) + { + StopSimulation(); + m_simulateBtn->SetLabel( wxT( "Simulate" ) ); + } + else + { + StartSimulation(); + m_simulateBtn->SetLabel( wxT( "Stop" ) ); + } +} + + +void SIM_PLOT_FRAME::onPlaceProbe( wxCommandEvent& event ) +{ + if( m_schematicFrame == NULL ) + return; + + wxCommandEvent* placeProbe = new wxCommandEvent( wxEVT_TOOL, ID_SIM_ADD_PROBE ); + wxQueueEvent( m_schematicFrame, placeProbe ); +} + + void SIM_PLOT_FRAME::onClose( wxCloseEvent& aEvent ) { { diff --git a/eeschema/sim/sim_plot_frame.h b/eeschema/sim/sim_plot_frame.h index 79b8c91dc6..3dee6e70ce 100644 --- a/eeschema/sim/sim_plot_frame.h +++ b/eeschema/sim/sim_plot_frame.h @@ -63,10 +63,19 @@ class SIM_PLOT_FRAME : public SIM_PLOT_FRAME_BASE void AddVoltagePlot( const wxString& aNetName ); private: - virtual void onClose( wxCloseEvent& aEvent ); - virtual void onNewPlot( wxCommandEvent& aEvent ) { NewPlot(); } - virtual void onSimReport( wxThreadEvent& aEvent ); - virtual void onSimFinished( wxThreadEvent& aEvent ); + bool isSimulationRunning(); + + void onNewPlot( wxCommandEvent& aEvent ) override + { + NewPlot(); + } + + void onSimulate( wxCommandEvent& event ) override; + void onPlaceProbe( wxCommandEvent& event ) override; + + void onClose( wxCloseEvent& aEvent ); + void onSimReport( wxThreadEvent& aEvent ); + void onSimFinished( wxThreadEvent& aEvent ); SCH_EDIT_FRAME* m_schematicFrame; NETLIST_EXPORTER_PSPICE* m_exporter; diff --git a/eeschema/sim/simulate.cpp b/eeschema/sim/simulate.cpp index efd5e316f4..68d1ee5daf 100644 --- a/eeschema/sim/simulate.cpp +++ b/eeschema/sim/simulate.cpp @@ -26,7 +26,7 @@ #include #include "sim_plot_frame.h" -void SCH_EDIT_FRAME::OnSimulationRun( wxCommandEvent& event ) +void SCH_EDIT_FRAME::OnSimulate( wxCommandEvent& event ) { SIM_PLOT_FRAME* simFrame = (SIM_PLOT_FRAME*) Kiway().Player( FRAME_SIMULATOR, true ); simFrame->Show( true ); @@ -36,14 +36,7 @@ void SCH_EDIT_FRAME::OnSimulationRun( wxCommandEvent& event ) simFrame->Iconize( false ); simFrame->Raise(); - simFrame->SetSchFrame( this ); - simFrame->StartSimulation(); -} - - -void SCH_EDIT_FRAME::OnSimulationStop( wxCommandEvent& event ) -{ }