Gray out unavailable simulator menu items, use wxUpdateUIEvent

This commit is contained in:
Mikolaj Wielgus 2021-07-11 02:06:11 +02:00 committed by Wayne Stambaugh
parent 4f2856b345
commit 3bafe6d6c9
5 changed files with 64 additions and 25 deletions

View File

@ -185,6 +185,15 @@ SIM_PLOT_FRAME::SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
m_toolSettings = m_toolBar->AddTool( wxID_ANY, _( "Sim Parameters" ),
KiBitmap( BITMAPS::config ), _( "Simulation parameters and settings" ), wxITEM_NORMAL );
Connect( m_toolSimulate->GetId(), wxEVT_UPDATE_UI,
wxUpdateUIEventHandler( SIM_PLOT_FRAME::menuSimulateUpdate ), NULL, this );
Connect( m_toolAddSignals->GetId(), wxEVT_UPDATE_UI,
wxUpdateUIEventHandler( SIM_PLOT_FRAME::menuAddSignalsUpdate ), NULL, this );
Connect( m_toolProbe->GetId(), wxEVT_UPDATE_UI,
wxUpdateUIEventHandler( SIM_PLOT_FRAME::menuProbeUpdate ), NULL, this );
Connect( m_toolTune->GetId(), wxEVT_UPDATE_UI,
wxUpdateUIEventHandler( SIM_PLOT_FRAME::menuTuneUpdate ), NULL, this );
Connect( m_toolSimulate->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
wxCommandEventHandler( SIM_PLOT_FRAME::onSimulate ), NULL, this );
Connect( m_toolAddSignals->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
@ -204,9 +213,8 @@ SIM_PLOT_FRAME::SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
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() );
Bind( wxEVT_COMMAND_MENU_SELECTED, &SIM_PLOT_FRAME::onSettings, this, m_toolSettings->GetId() );
updateToolbar();
m_toolBar->Realize();
#ifndef wxHAS_NATIVE_TABART
@ -225,6 +233,8 @@ SIM_PLOT_FRAME::SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
wxSafeYield();
setSubWindowsSashSize();
UpdateWindowUI();
// Ensure the window is on top
Raise();
@ -360,7 +370,6 @@ void SIM_PLOT_FRAME::updateTitle()
void SIM_PLOT_FRAME::updateFrame()
{
updateToolbar();
updateTitle();
}
@ -800,16 +809,6 @@ bool SIM_PLOT_FRAME::updatePlot( const wxString& aName, SIM_PLOT_TYPE aType, con
}
void SIM_PLOT_FRAME::updateToolbar()
{
m_toolBar->EnableTool( ID_SIM_RUN,
m_exporter->CommandToSimType( getCurrentSimCommand() ) != ST_UNKNOWN );
m_toolBar->EnableTool( ID_SIM_ADD_SIGNALS, m_simFinished );
m_toolBar->EnableTool( ID_SIM_PROBE, m_simFinished );
m_toolBar->EnableTool( ID_SIM_TUNE, m_simFinished );
}
void SIM_PLOT_FRAME::updateSignalList()
{
m_signals->ClearAll();
@ -1330,6 +1329,30 @@ void SIM_PLOT_FRAME::menuWhiteBackground( wxCommandEvent& event )
}
void SIM_PLOT_FRAME::menuSimulateUpdate( wxUpdateUIEvent& event )
{
event.Enable( m_exporter->CommandToSimType( getCurrentSimCommand() ) != ST_UNKNOWN );
}
void SIM_PLOT_FRAME::menuAddSignalsUpdate( wxUpdateUIEvent& event )
{
event.Enable( m_simFinished );
}
void SIM_PLOT_FRAME::menuProbeUpdate( wxUpdateUIEvent& event )
{
event.Enable( m_simFinished );
}
void SIM_PLOT_FRAME::menuTuneUpdate( wxUpdateUIEvent& event )
{
event.Enable( m_simFinished );
}
void SIM_PLOT_FRAME::onPlotClose( wxAuiNotebookEvent& event )
{
int idx = event.GetSelection();

View File

@ -191,11 +191,6 @@ private:
bool updatePlot( const wxString& aName, SIM_PLOT_TYPE aType, const wxString& aParam,
SIM_PLOT_PANEL* aPlotPanel );
/**
* Update the toolbar.
*/
void updateToolbar();
/**
* Update the list of currently plotted signals.
*/
@ -275,12 +270,17 @@ private:
void menuShowLegendUpdate( wxUpdateUIEvent& event ) override;
void menuShowDotted( wxCommandEvent& event ) override;
void menuShowDottedUpdate( wxUpdateUIEvent& event ) override;
void menuWhiteBackground( wxCommandEvent& event ) override;
void menuShowWhiteBackgroundUpdate( wxUpdateUIEvent& event ) override
void menuWhiteBackground( wxCommandEvent& event ) override;
void menuShowWhiteBackgroundUpdate( wxUpdateUIEvent& event ) override
{
event.Check( m_plotUseWhiteBg );
}
void menuSimulateUpdate( wxUpdateUIEvent& event ) override;
void menuAddSignalsUpdate( wxUpdateUIEvent& event ) override;
void menuProbeUpdate( wxUpdateUIEvent& event ) override;
void menuTuneUpdate( wxUpdateUIEvent& event ) override;
// Event handlers
void onPlotClose( wxAuiNotebookEvent& event ) override;
void onPlotClosed( wxAuiNotebookEvent& event ) override;

View File

@ -73,8 +73,8 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const
m_simulationMenu->AppendSeparator();
m_settings = new wxMenuItem( m_simulationMenu, ID_MENU_SET_SIMUL, wxString( _("Settings...") ) , wxEmptyString, wxITEM_NORMAL );
m_simulationMenu->Append( m_settings );
m_boardAdapter = new wxMenuItem( m_simulationMenu, ID_MENU_SET_SIMUL, wxString( _("Settings...") ) , wxEmptyString, wxITEM_NORMAL );
m_simulationMenu->Append( m_boardAdapter );
m_mainMenu->Append( m_simulationMenu, _("Simulation") );
@ -279,6 +279,10 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const
m_fileMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuSaveImage ), this, m_saveImage->GetId());
m_fileMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuSaveCsv ), this, m_saveCsv->GetId());
m_fileMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuExit ), this, m_exitSim->GetId());
this->Connect( m_runSimulation->GetId(), wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuSimulateUpdate ) );
this->Connect( m_addSignals->GetId(), wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuAddSignalsUpdate ) );
this->Connect( m_probeSignals->GetId(), wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuProbeUpdate ) );
this->Connect( m_tuneValue->GetId(), wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuTuneUpdate ) );
m_viewMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuZoomIn ), this, m_zoomIn->GetId());
m_viewMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuZoomOut ), this, m_zoomOut->GetId());
m_viewMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuZoomFit ), this, m_zoomFit->GetId());
@ -301,6 +305,10 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const
SIM_PLOT_FRAME_BASE::~SIM_PLOT_FRAME_BASE()
{
// Disconnect Events
this->Disconnect( ID_MENU_RUN_SIM, wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuSimulateUpdate ) );
this->Disconnect( ID_MENU_ADD_SIGNAL, wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuAddSignalsUpdate ) );
this->Disconnect( ID_MENU_PROBE_SIGNALS, wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuProbeUpdate ) );
this->Disconnect( ID_MENU_TUNE_SIGNALS, wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuTuneUpdate ) );
this->Disconnect( ID_MENU_SHOW_GRID, wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuShowGridUpdate ) );
this->Disconnect( ID_MENU_SHOW_LEGEND, wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuShowLegendUpdate ) );
this->Disconnect( ID_MENU_DOTTED, wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuShowDottedUpdate ) );

View File

@ -191,7 +191,7 @@
<event name="OnMenuSelection">menuExit</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>
@ -207,6 +207,7 @@
<property name="permission">protected</property>
<property name="shortcut">Ctrl+R</property>
<property name="unchecked_bitmap"></property>
<event name="OnUpdateUI">menuSimulateUpdate</event>
</object>
<object class="separator" expanded="0">
<property name="name">m_separator31</property>
@ -224,6 +225,7 @@
<property name="permission">protected</property>
<property name="shortcut">Ctrl+A</property>
<property name="unchecked_bitmap"></property>
<event name="OnUpdateUI">menuAddSignalsUpdate</event>
</object>
<object class="wxMenuItem" expanded="0">
<property name="bitmap"></property>
@ -237,6 +239,7 @@
<property name="permission">protected</property>
<property name="shortcut">Ctrl+P</property>
<property name="unchecked_bitmap"></property>
<event name="OnUpdateUI">menuProbeUpdate</event>
</object>
<object class="wxMenuItem" expanded="0">
<property name="bitmap"></property>
@ -250,6 +253,7 @@
<property name="permission">protected</property>
<property name="shortcut">Ctrl+T</property>
<property name="unchecked_bitmap"></property>
<event name="OnUpdateUI">menuTuneUpdate</event>
</object>
<object class="separator" expanded="0">
<property name="name">m_separator7</property>
@ -286,7 +290,7 @@
<property name="unchecked_bitmap"></property>
</object>
</object>
<object class="wxMenu" expanded="0">
<object class="wxMenu" expanded="1">
<property name="label">View</property>
<property name="name">m_viewMenu</property>
<property name="permission">protected</property>

View File

@ -62,7 +62,7 @@ class SIM_PLOT_FRAME_BASE : public KIWAY_PLAYER
wxMenuItem* m_probeSignals;
wxMenuItem* m_tuneValue;
wxMenuItem* m_showNetlist;
wxMenuItem* m_settings;
wxMenuItem* m_boardAdapter;
wxMenu* m_viewMenu;
wxBoxSizer* m_sizerMain;
wxToolBar* m_toolBar;
@ -99,6 +99,10 @@ class SIM_PLOT_FRAME_BASE : public KIWAY_PLAYER
virtual void menuSaveImage( wxCommandEvent& event ) { event.Skip(); }
virtual void menuSaveCsv( wxCommandEvent& event ) { event.Skip(); }
virtual void menuExit( wxCommandEvent& event ) { event.Skip(); }
virtual void menuSimulateUpdate( wxUpdateUIEvent& event ) { event.Skip(); }
virtual void menuAddSignalsUpdate( wxUpdateUIEvent& event ) { event.Skip(); }
virtual void menuProbeUpdate( wxUpdateUIEvent& event ) { event.Skip(); }
virtual void menuTuneUpdate( wxUpdateUIEvent& event ) { event.Skip(); }
virtual void menuZoomIn( wxCommandEvent& event ) { event.Skip(); }
virtual void menuZoomOut( wxCommandEvent& event ) { event.Skip(); }
virtual void menuZoomFit( wxCommandEvent& event ) { event.Skip(); }