Use wx events to update simulator title, start tools and menu items grayed out

This commit is contained in:
Mikolaj Wielgus 2021-07-11 20:31:50 +02:00 committed by Wayne Stambaugh
parent 3bafe6d6c9
commit c6a4f25538
6 changed files with 86 additions and 79 deletions

View File

@ -185,6 +185,13 @@ 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 );
// Start all toolbar buttons except settings as disabled
m_toolSimulate->Enable( false );
m_toolAddSignals->Enable( false );
m_toolProbe->Enable( false );
m_toolTune->Enable( false );
m_toolSettings->Enable( true );
Connect( m_toolSimulate->GetId(), wxEVT_UPDATE_UI,
wxUpdateUIEventHandler( SIM_PLOT_FRAME::menuSimulateUpdate ), NULL, this );
Connect( m_toolAddSignals->GetId(), wxEVT_UPDATE_UI,
@ -205,6 +212,9 @@ SIM_PLOT_FRAME::SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
Connect( m_toolSettings->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
wxCommandEventHandler( SIM_PLOT_FRAME::onSettings ), NULL, this );
Bind( EVT_WORKBOOK_MODIFIED, &SIM_PLOT_FRAME::onWorkbookModified, this );
Bind( EVT_WORKBOOK_CLR_MODIFIED, &SIM_PLOT_FRAME::onWorkbookClrModified, 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() );
@ -233,13 +243,11 @@ SIM_PLOT_FRAME::SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
wxSafeYield();
setSubWindowsSashSize();
UpdateWindowUI();
// Ensure the window is on top
Raise();
initWorkbook();
updateFrame();
updateTitle();
}
@ -368,12 +376,6 @@ void SIM_PLOT_FRAME::updateTitle()
}
void SIM_PLOT_FRAME::updateFrame()
{
updateTitle();
}
// A small helper struct to handle bitmaps initialisation in menus
struct BM_MENU_INIT_ITEM
{
@ -529,7 +531,6 @@ SIM_PANEL_BASE* SIM_PLOT_FRAME::NewPlotPanel( wxString aSimCommand )
m_workbook->AddPage( dynamic_cast<wxWindow*>( plotPanel ), pageTitle, true );
updateFrame();
return plotPanel;
}
@ -691,7 +692,6 @@ void SIM_PLOT_FRAME::removePlot( const wxString& aPlotName )
updateSignalList();
wxCommandEvent dummy;
onCursorUpdate( dummy );
updateFrame();
}
@ -797,14 +797,12 @@ bool SIM_PLOT_FRAME::updatePlot( const wxString& aName, SIM_PLOT_TYPE aType, con
offset += inner;
}
updateFrame();
return true;
}
}
m_workbook->AddTrace( aPlotPanel, aName, size, data_x.data(), data_y.data(), aType, aParam );
updateFrame();
return true;
}
@ -924,10 +922,7 @@ bool SIM_PLOT_FRAME::loadWorkbook( const wxString& aPath )
file.GetCurrentLine()+1 ) )
if( !file.Open() )
{
updateFrame();
return false;
}
long plotsCount;
@ -936,7 +931,6 @@ bool SIM_PLOT_FRAME::loadWorkbook( const wxString& aPath )
DISPLAY_LOAD_ERROR( "Error loading workbook: Line %d is not an integer." );
file.Close();
updateFrame();
return false;
}
@ -949,7 +943,6 @@ bool SIM_PLOT_FRAME::loadWorkbook( const wxString& aPath )
DISPLAY_LOAD_ERROR( "Error loading workbook: Line %d is not an integer." );
file.Close();
updateFrame();
return false;
}
@ -969,7 +962,6 @@ bool SIM_PLOT_FRAME::loadWorkbook( const wxString& aPath )
DISPLAY_LOAD_ERROR( "Error loading workbook: Line %d is not an integer." );
file.Close();
updateFrame();
return false;
}
@ -984,7 +976,6 @@ bool SIM_PLOT_FRAME::loadWorkbook( const wxString& aPath )
);
file.Close();
updateFrame();
return false;
}
@ -995,7 +986,6 @@ bool SIM_PLOT_FRAME::loadWorkbook( const wxString& aPath )
DISPLAY_LOAD_ERROR( "Error loading workbook: Line %d is empty." );
file.Close();
updateFrame();
return false;
}
@ -1006,7 +996,6 @@ bool SIM_PLOT_FRAME::loadWorkbook( const wxString& aPath )
DISPLAY_LOAD_ERROR( "Error loading workbook: Line %d is empty." );
file.Close();
updateFrame();
return false;
}
@ -1018,8 +1007,6 @@ bool SIM_PLOT_FRAME::loadWorkbook( const wxString& aPath )
// Successfully loading a workbook does not count as modyfying it.
m_workbook->ClrModified();
updateFrame();
return true;
}
@ -1085,8 +1072,6 @@ bool SIM_PLOT_FRAME::saveWorkbook( const wxString& aPath )
m_simulator->Settings()->SetWorkbookFilename( filename.GetFullName() );
m_workbook->ClrModified();
updateFrame();
return res;
}
@ -1110,10 +1095,7 @@ void SIM_PLOT_FRAME::menuNewPlot( wxCommandEvent& aEvent )
SIM_TYPE type = m_exporter->GetSimType();
if( SIM_PANEL_BASE::IsPlottable( type ) )
{
NewPlotPanel( m_exporter->GetUsedSimCommand() );
updateFrame();
}
}
@ -1367,7 +1349,6 @@ void SIM_PLOT_FRAME::onPlotClose( wxAuiNotebookEvent& event )
void SIM_PLOT_FRAME::onPlotClosed( wxAuiNotebookEvent& event )
{
updateFrame();
}
@ -1376,14 +1357,11 @@ void SIM_PLOT_FRAME::onPlotChanged( wxAuiNotebookEvent& event )
updateSignalList();
wxCommandEvent dummy;
onCursorUpdate( dummy );
updateFrame();
}
void SIM_PLOT_FRAME::onPlotDragged( wxAuiNotebookEvent& event )
{
updateFrame();
}
@ -1415,6 +1393,18 @@ void SIM_PLOT_FRAME::onSignalRClick( wxListEvent& event )
}
void SIM_PLOT_FRAME::onWorkbookModified( wxCommandEvent& event )
{
updateTitle();
}
void SIM_PLOT_FRAME::onWorkbookClrModified( wxCommandEvent& event )
{
updateTitle();
}
void SIM_PLOT_FRAME::onSimulate( wxCommandEvent& event )
{
if( m_simulator->IsRunning() )
@ -1472,7 +1462,6 @@ void SIM_PLOT_FRAME::onSettings( wxCommandEvent& event )
}
m_simulator->Init();
updateFrame();
}
}
@ -1663,8 +1652,6 @@ void SIM_PLOT_FRAME::onCursorUpdate( wxCommandEvent& event )
m_cursors->SetItem( idx, Y_COL, SPICE_VALUE( coords.y ).ToSpiceString() );
}
}
updateFrame();
}
@ -1672,8 +1659,6 @@ void SIM_PLOT_FRAME::onSimStarted( wxCommandEvent& aEvent )
{
m_toolBar->SetToolNormalBitmap( ID_SIM_RUN, KiBitmap( BITMAPS::sim_stop ) );
SetCursor( wxCURSOR_ARROWWAIT );
updateFrame();
}
@ -1730,7 +1715,6 @@ void SIM_PLOT_FRAME::onSimFinished( wxCommandEvent& aEvent )
updateSignalList();
plotPanel->GetPlotWin()->UpdateAll();
plotPanel->ResetScales();
updateFrame();
}
else if( simType == ST_OP )
{
@ -1765,7 +1749,6 @@ void SIM_PLOT_FRAME::onSimFinished( wxCommandEvent& aEvent )
}
m_simFinished = true;
updateFrame();
}
@ -1789,8 +1772,6 @@ void SIM_PLOT_FRAME::onSimUpdate( wxCommandEvent& aEvent )
applyTuners();
m_simulator->Run();
}
updateFrame();
}
@ -1798,8 +1779,6 @@ void SIM_PLOT_FRAME::onSimReport( wxCommandEvent& aEvent )
{
m_simConsole->AppendText( aEvent.GetString() + "\n" );
m_simConsole->SetInsertionPointEnd();
updateFrame();
}

View File

@ -148,12 +148,6 @@ private:
*/
void updateTitle();
/**
* Update the frame to match the changes to the workbook. Should be always called after the
* workbook was modified.
*/
void updateFrame();
/**
* Give icons to menuitems of the main menubar.
*/
@ -290,6 +284,9 @@ private:
void onSignalDblClick( wxMouseEvent& event ) override;
void onSignalRClick( wxListEvent& event ) override;
void onWorkbookModified( wxCommandEvent& event );
void onWorkbookClrModified( wxCommandEvent& event );
void onSimulate( wxCommandEvent& event );
void onSettings( wxCommandEvent& event );
void onAddSignal( wxCommandEvent& event );

View File

@ -54,17 +54,21 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const
m_simulationMenu = new wxMenu();
m_runSimulation = new wxMenuItem( m_simulationMenu, ID_MENU_RUN_SIM, wxString( _("Run Simulation") ) + wxT('\t') + wxT("Ctrl+R"), wxEmptyString, wxITEM_NORMAL );
m_simulationMenu->Append( m_runSimulation );
m_runSimulation->Enable( false );
m_simulationMenu->AppendSeparator();
m_addSignals = new wxMenuItem( m_simulationMenu, ID_MENU_ADD_SIGNAL, wxString( _("Add Signals...") ) + wxT('\t') + wxT("Ctrl+A"), wxEmptyString, wxITEM_NORMAL );
m_simulationMenu->Append( m_addSignals );
m_addSignals->Enable( false );
m_probeSignals = new wxMenuItem( m_simulationMenu, ID_MENU_PROBE_SIGNALS, wxString( _("Probe from schematics") ) + wxT('\t') + wxT("Ctrl+P"), wxEmptyString, wxITEM_NORMAL );
m_simulationMenu->Append( m_probeSignals );
m_probeSignals->Enable( false );
m_tuneValue = new wxMenuItem( m_simulationMenu, ID_MENU_TUNE_SIGNALS, wxString( _("Tune Component Value") ) + wxT('\t') + wxT("Ctrl+T"), wxEmptyString, wxITEM_NORMAL );
m_simulationMenu->Append( m_tuneValue );
m_tuneValue->Enable( false );
m_simulationMenu->AppendSeparator();

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<wxFormBuilder_Project>
<FileVersion major="1" minor="15" />
<object class="Project" expanded="1">
<object class="Project" expanded="0">
<property name="class_decoration"></property>
<property name="code_generation">C++</property>
<property name="disconnect_events">1</property>
@ -27,7 +27,7 @@
<property name="ui_table">UI</property>
<property name="use_enum">0</property>
<property name="use_microsoft_bom">0</property>
<object class="Frame" expanded="1">
<object class="Frame" expanded="0">
<property name="aui_managed">0</property>
<property name="aui_manager_style">wxAUI_MGR_DEFAULT</property>
<property name="bg"></property>
@ -54,7 +54,7 @@
<property name="window_name">SIM_PLOT_FRAME</property>
<property name="window_style">wxTAB_TRAVERSAL</property>
<property name="xrc_skip_sizer">1</property>
<object class="wxMenuBar" expanded="1">
<object class="wxMenuBar" expanded="0">
<property name="bg"></property>
<property name="context_help"></property>
<property name="context_menu">1</property>
@ -76,7 +76,7 @@
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<object class="wxMenu" expanded="1">
<object class="wxMenu" expanded="0">
<property name="label">File</property>
<property name="name">m_fileMenu</property>
<property name="permission">protected</property>
@ -191,14 +191,14 @@
<event name="OnMenuSelection">menuExit</event>
</object>
</object>
<object class="wxMenu" expanded="1">
<object class="wxMenu" expanded="0">
<property name="label">Simulation</property>
<property name="name">m_simulationMenu</property>
<property name="permission">protected</property>
<object class="wxMenuItem" expanded="0">
<property name="bitmap"></property>
<property name="checked">0</property>
<property name="enabled">1</property>
<property name="enabled">0</property>
<property name="help"></property>
<property name="id">ID_MENU_RUN_SIM</property>
<property name="kind">wxITEM_NORMAL</property>
@ -216,7 +216,7 @@
<object class="wxMenuItem" expanded="0">
<property name="bitmap"></property>
<property name="checked">0</property>
<property name="enabled">1</property>
<property name="enabled">0</property>
<property name="help"></property>
<property name="id">ID_MENU_ADD_SIGNAL</property>
<property name="kind">wxITEM_NORMAL</property>
@ -230,7 +230,7 @@
<object class="wxMenuItem" expanded="0">
<property name="bitmap"></property>
<property name="checked">0</property>
<property name="enabled">1</property>
<property name="enabled">0</property>
<property name="help"></property>
<property name="id">ID_MENU_PROBE_SIGNALS</property>
<property name="kind">wxITEM_NORMAL</property>
@ -244,7 +244,7 @@
<object class="wxMenuItem" expanded="0">
<property name="bitmap"></property>
<property name="checked">0</property>
<property name="enabled">1</property>
<property name="enabled">0</property>
<property name="help"></property>
<property name="id">ID_MENU_TUNE_SIGNALS</property>
<property name="kind">wxITEM_NORMAL</property>
@ -290,7 +290,7 @@
<property name="unchecked_bitmap"></property>
</object>
</object>
<object class="wxMenu" expanded="1">
<object class="wxMenu" expanded="0">
<property name="label">View</property>
<property name="name">m_viewMenu</property>
<property name="permission">protected</property>

View File

@ -40,42 +40,63 @@ SIM_WORKBOOK::SIM_WORKBOOK( wxWindow* aParent, wxWindowID aId, const wxPoint& aP
bool SIM_WORKBOOK::AddPage( wxWindow* page, const wxString& caption, bool select, const wxBitmap& bitmap )
{
m_modified = true;
return wxAuiNotebook::AddPage( page, caption, select, bitmap );
bool res = wxAuiNotebook::AddPage( page, caption, select, bitmap );
setModified( res );
return res;
}
bool SIM_WORKBOOK::AddPage( wxWindow* page, const wxString& text, bool select, int imageId )
{
m_modified = true;
return wxAuiNotebook::AddPage( page, text, select, imageId );
bool res = wxAuiNotebook::AddPage( page, text, select, imageId );
setModified( res );
return res;
}
bool SIM_WORKBOOK::DeleteAllPages()
{
m_modified = true;
return wxAuiNotebook::DeleteAllPages();
bool res = wxAuiNotebook::DeleteAllPages();
setModified( res );
return res;
}
bool SIM_WORKBOOK::DeletePage( size_t page )
{
m_modified = true;
return wxAuiNotebook::DeletePage( page );
bool res = wxAuiNotebook::DeletePage( page );
setModified( res );
return res;
}
void SIM_WORKBOOK::AddTrace( SIM_PLOT_PANEL* aPlotPanel, const wxString& aName, int aPoints, const
bool SIM_WORKBOOK::AddTrace( SIM_PLOT_PANEL* aPlotPanel, const wxString& aName, int aPoints, const
double* aX, const double* aY, SIM_PLOT_TYPE aType, const wxString& aParam )
{
aPlotPanel->addTrace( aName, aPoints, aX, aY, aType, aParam );
m_modified = true;
bool res = aPlotPanel->addTrace( aName, aPoints, aX, aY, aType, aParam );
setModified( res );
return res;
}
void SIM_WORKBOOK::DeleteTrace( SIM_PLOT_PANEL* aPlotPanel, const wxString& aName )
bool SIM_WORKBOOK::DeleteTrace( SIM_PLOT_PANEL* aPlotPanel, const wxString& aName )
{
aPlotPanel->deleteTrace( aName );
m_modified = true;
bool res = aPlotPanel->deleteTrace( aName );
setModified( res );
return res;
}
void SIM_WORKBOOK::ClrModified()
{
m_modified = false;
wxPostEvent( GetParent(), wxCommandEvent( EVT_WORKBOOK_CLR_MODIFIED ) );
}
void SIM_WORKBOOK::setModified( bool value )
{
m_modified = value;
wxPostEvent( GetParent(), wxCommandEvent( EVT_WORKBOOK_MODIFIED ) );
}
wxDEFINE_EVENT( EVT_WORKBOOK_MODIFIED, wxCommandEvent );
wxDEFINE_EVENT( EVT_WORKBOOK_CLR_MODIFIED, wxCommandEvent );

View File

@ -25,7 +25,7 @@
#ifndef __SIM_WORKBOOK__
#define __SIM_WORKBOOK__
#include "dialog_sim_settings.h"
#include <dialog_sim_settings.h>
#include <sim/sim_panel_base.h>
#include <sim/sim_plot_panel.h>
@ -48,13 +48,14 @@ public:
// Custom methods
void AddTrace( SIM_PLOT_PANEL* aPlotPanel, const wxString& aName, int aPoints, const double*
aX, const double* aY, SIM_PLOT_TYPE aType, const wxString& aParam );
void DeleteTrace( SIM_PLOT_PANEL* aPlotPanel, const wxString& aName );
bool AddTrace( SIM_PLOT_PANEL* aPlotPanel, const wxString& aName, int aPoints, const double*
aX, const double* aY, SIM_PLOT_TYPE aType, const wxString& aParam );
bool DeleteTrace( SIM_PLOT_PANEL* aPlotPanel, const wxString& aName );
void SetSimCommand( SIM_PANEL_BASE* aPlotPanel, const wxString& aSimCommand )
{
aPlotPanel->setSimCommand( aSimCommand );
setModified();
}
const wxString& GetSimCommand( const SIM_PANEL_BASE* aPlotPanel )
@ -62,12 +63,17 @@ public:
return aPlotPanel->getSimCommand();
}
void ClrModified() { m_modified = false; }
void ClrModified();
bool IsModified() const { return m_modified; }
private:
void setModified( bool value = true );
///< Dirty bit, indicates something in the workbook has changed
bool m_modified;
};
wxDECLARE_EVENT( EVT_WORKBOOK_MODIFIED, wxCommandEvent );
wxDECLARE_EVENT( EVT_WORKBOOK_CLR_MODIFIED, wxCommandEvent );
#endif // __SIM_WORKBOOK__