Menu entries to toggle legend & coordinates

This commit is contained in:
Maciej Suminski 2016-08-11 14:41:27 +02:00
parent a35e324c3f
commit 1d4fe279db
7 changed files with 167 additions and 59 deletions

View File

@ -205,15 +205,43 @@ void SIM_PLOT_FRAME::menuZoomFit( wxCommandEvent& event )
void SIM_PLOT_FRAME::menuShowGrid( wxCommandEvent& event )
{
CurrentPlot()->ShowGrid( !CurrentPlot()->IsGridShown() );
SIM_PLOT_PANEL* plot = CurrentPlot();
plot->ShowGrid( !plot->IsGridShown() );
}
void SIM_PLOT_FRAME::menuShowGridState( wxUpdateUIEvent& event )
void SIM_PLOT_FRAME::menuShowGridUpdate( wxUpdateUIEvent& event )
{
SIM_PLOT_PANEL* plotPanel = CurrentPlot();
SIM_PLOT_PANEL* plot = CurrentPlot();
event.Check( plot ? plot->IsGridShown() : false );
}
event.Check( plotPanel ? plotPanel->IsGridShown() : false );
void SIM_PLOT_FRAME::menuShowLegend( wxCommandEvent& event )
{
SIM_PLOT_PANEL* plot = CurrentPlot();
plot->ShowLegend( !plot->IsLegendShown() );
}
void SIM_PLOT_FRAME::menuShowLegendUpdate( wxUpdateUIEvent& event )
{
SIM_PLOT_PANEL* plot = CurrentPlot();
event.Check( plot ? plot->IsLegendShown() : false );
}
void SIM_PLOT_FRAME::menuShowCoords( wxCommandEvent& event )
{
SIM_PLOT_PANEL* plot = CurrentPlot();
plot->ShowCoords( !plot->IsCoordsShown() );
}
void SIM_PLOT_FRAME::menuShowCoordsUpdate( wxUpdateUIEvent& event )
{
SIM_PLOT_PANEL* plot = CurrentPlot();
event.Check( plot ? plot->IsCoordsShown() : false );
}

View File

@ -91,13 +91,17 @@ class SIM_PLOT_FRAME : public SIM_PLOT_FRAME_BASE
Close();
}
// Event handlers
void menuZoomIn( wxCommandEvent& event ) override;
void menuZoomOut( wxCommandEvent& event ) override;
void menuZoomFit( wxCommandEvent& event ) override;
void menuShowGrid( wxCommandEvent& event ) override;
void menuShowGridState( wxUpdateUIEvent& event ) override;
void menuShowGridUpdate( wxUpdateUIEvent& event ) override;
void menuShowLegend( wxCommandEvent& event ) override;
void menuShowLegendUpdate( wxUpdateUIEvent& event ) override;
void menuShowCoords( wxCommandEvent& event ) override;
void menuShowCoordsUpdate( wxUpdateUIEvent& event ) override;
// Event handlers
void onPlotChanged( wxNotebookEvent& event ) override;
void onSignalDblClick( wxCommandEvent& event ) override;

View File

@ -38,23 +38,31 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const
m_mainMenu->Append( m_fileMenu, _("File") );
m_viewMenu = new wxMenu();
wxMenuItem* m_menuItem3;
m_menuItem3 = new wxMenuItem( m_viewMenu, wxID_ZOOM_IN, wxString( _("Zoom In") ) , wxEmptyString, wxITEM_NORMAL );
m_viewMenu->Append( m_menuItem3 );
wxMenuItem* m_zoomIn;
m_zoomIn = new wxMenuItem( m_viewMenu, wxID_ZOOM_IN, wxString( _("Zoom In") ) , wxEmptyString, wxITEM_NORMAL );
m_viewMenu->Append( m_zoomIn );
wxMenuItem* m_menuItem4;
m_menuItem4 = new wxMenuItem( m_viewMenu, wxID_ZOOM_OUT, wxString( _("Zoom Out") ) , wxEmptyString, wxITEM_NORMAL );
m_viewMenu->Append( m_menuItem4 );
wxMenuItem* m_zoomOut;
m_zoomOut = new wxMenuItem( m_viewMenu, wxID_ZOOM_OUT, wxString( _("Zoom Out") ) , wxEmptyString, wxITEM_NORMAL );
m_viewMenu->Append( m_zoomOut );
wxMenuItem* m_menuItem5;
m_menuItem5 = new wxMenuItem( m_viewMenu, wxID_ZOOM_FIT, wxString( _("Fit on Screen") ) , wxEmptyString, wxITEM_NORMAL );
m_viewMenu->Append( m_menuItem5 );
wxMenuItem* m_zoomFit;
m_zoomFit = new wxMenuItem( m_viewMenu, wxID_ZOOM_FIT, wxString( _("Fit on Screen") ) , wxEmptyString, wxITEM_NORMAL );
m_viewMenu->Append( m_zoomFit );
m_viewMenu->AppendSeparator();
wxMenuItem* m_menuShowGrid;
m_menuShowGrid = new wxMenuItem( m_viewMenu, wxID_ANY, wxString( _("Show grid") ) , wxEmptyString, wxITEM_CHECK );
m_viewMenu->Append( m_menuShowGrid );
wxMenuItem* m_showGrid;
m_showGrid = new wxMenuItem( m_viewMenu, wxID_ANY, wxString( _("Show &grid") ) , wxEmptyString, wxITEM_CHECK );
m_viewMenu->Append( m_showGrid );
wxMenuItem* m_showLegend;
m_showLegend = new wxMenuItem( m_viewMenu, wxID_ANY, wxString( _("Show &legend") ) , wxEmptyString, wxITEM_CHECK );
m_viewMenu->Append( m_showLegend );
wxMenuItem* m_showCoords;
m_showCoords = new wxMenuItem( m_viewMenu, wxID_ANY, wxString( _("Show &coordinates") ) , wxEmptyString, wxITEM_CHECK );
m_viewMenu->Append( m_showCoords );
m_mainMenu->Append( m_viewMenu, _("View") );
@ -67,8 +75,10 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const
bSizer5 = new wxBoxSizer( wxHORIZONTAL );
m_plotNotebook = new wxNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
m_plotNotebook->SetMinSize( wxSize( 400,-1 ) );
bSizer5->Add( m_plotNotebook, 4, wxEXPAND | wxALL, 5 );
bSizer5->Add( m_plotNotebook, 6, wxEXPAND | wxALL, 5 );
wxBoxSizer* bSizer7;
bSizer7 = new wxBoxSizer( wxVERTICAL );
@ -126,11 +136,15 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const
this->Connect( m_menuItem8->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuOpenWorkbook ) );
this->Connect( m_menuItem2->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuSaveWorkbook ) );
this->Connect( m_menuItem1->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuExit ) );
this->Connect( m_menuItem3->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuZoomIn ) );
this->Connect( m_menuItem4->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuZoomOut ) );
this->Connect( m_menuItem5->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuZoomFit ) );
this->Connect( m_menuShowGrid->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuShowGrid ) );
this->Connect( m_menuShowGrid->GetId(), wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuShowGridState ) );
this->Connect( m_zoomIn->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuZoomIn ) );
this->Connect( m_zoomOut->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuZoomOut ) );
this->Connect( m_zoomFit->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuZoomFit ) );
this->Connect( m_showGrid->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuShowGrid ) );
this->Connect( m_showGrid->GetId(), wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuShowGridUpdate ) );
this->Connect( m_showLegend->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuShowLegend ) );
this->Connect( m_showLegend->GetId(), wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuShowLegendUpdate ) );
this->Connect( m_showCoords->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuShowCoords ) );
this->Connect( m_showCoords->GetId(), wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuShowCoordsUpdate ) );
m_plotNotebook->Connect( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, wxNotebookEventHandler( SIM_PLOT_FRAME_BASE::onPlotChanged ), NULL, this );
m_signals->Connect( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::onSignalDblClick ), NULL, this );
m_signals->Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( SIM_PLOT_FRAME_BASE::onSignalRClick ), NULL, this );
@ -150,7 +164,11 @@ SIM_PLOT_FRAME_BASE::~SIM_PLOT_FRAME_BASE()
this->Disconnect( wxID_ZOOM_OUT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuZoomOut ) );
this->Disconnect( wxID_ZOOM_FIT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuZoomFit ) );
this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuShowGrid ) );
this->Disconnect( wxID_ANY, wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuShowGridState ) );
this->Disconnect( wxID_ANY, wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuShowGridUpdate ) );
this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuShowLegend ) );
this->Disconnect( wxID_ANY, wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuShowLegendUpdate ) );
this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuShowCoords ) );
this->Disconnect( wxID_ANY, wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuShowCoordsUpdate ) );
m_plotNotebook->Disconnect( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, wxNotebookEventHandler( SIM_PLOT_FRAME_BASE::onPlotChanged ), NULL, this );
m_signals->Disconnect( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::onSignalDblClick ), NULL, this );
m_signals->Disconnect( wxEVT_RIGHT_UP, wxMouseEventHandler( SIM_PLOT_FRAME_BASE::onSignalRClick ), NULL, this );

View File

@ -218,7 +218,7 @@
<property name="id">wxID_ZOOM_IN</property>
<property name="kind">wxITEM_NORMAL</property>
<property name="label">Zoom In</property>
<property name="name">m_menuItem3</property>
<property name="name">m_zoomIn</property>
<property name="permission">none</property>
<property name="shortcut"></property>
<property name="unchecked_bitmap"></property>
@ -233,7 +233,7 @@
<property name="id">wxID_ZOOM_OUT</property>
<property name="kind">wxITEM_NORMAL</property>
<property name="label">Zoom Out</property>
<property name="name">m_menuItem4</property>
<property name="name">m_zoomOut</property>
<property name="permission">none</property>
<property name="shortcut"></property>
<property name="unchecked_bitmap"></property>
@ -248,7 +248,7 @@
<property name="id">wxID_ZOOM_FIT</property>
<property name="kind">wxITEM_NORMAL</property>
<property name="label">Fit on Screen</property>
<property name="name">m_menuItem5</property>
<property name="name">m_zoomFit</property>
<property name="permission">none</property>
<property name="shortcut"></property>
<property name="unchecked_bitmap"></property>
@ -266,13 +266,43 @@
<property name="help"></property>
<property name="id">wxID_ANY</property>
<property name="kind">wxITEM_CHECK</property>
<property name="label">Show grid</property>
<property name="name">m_menuShowGrid</property>
<property name="label">Show &amp;grid</property>
<property name="name">m_showGrid</property>
<property name="permission">none</property>
<property name="shortcut"></property>
<property name="unchecked_bitmap"></property>
<event name="OnMenuSelection">menuShowGrid</event>
<event name="OnUpdateUI">menuShowGridState</event>
<event name="OnUpdateUI">menuShowGridUpdate</event>
</object>
<object class="wxMenuItem" expanded="1">
<property name="bitmap"></property>
<property name="checked">0</property>
<property name="enabled">1</property>
<property name="help"></property>
<property name="id">wxID_ANY</property>
<property name="kind">wxITEM_CHECK</property>
<property name="label">Show &amp;legend</property>
<property name="name">m_showLegend</property>
<property name="permission">none</property>
<property name="shortcut"></property>
<property name="unchecked_bitmap"></property>
<event name="OnMenuSelection">menuShowLegend</event>
<event name="OnUpdateUI">menuShowLegendUpdate</event>
</object>
<object class="wxMenuItem" expanded="1">
<property name="bitmap"></property>
<property name="checked">0</property>
<property name="enabled">1</property>
<property name="help"></property>
<property name="id">wxID_ANY</property>
<property name="kind">wxITEM_CHECK</property>
<property name="label">Show &amp;coordinates</property>
<property name="name">m_showCoords</property>
<property name="permission">none</property>
<property name="shortcut"></property>
<property name="unchecked_bitmap"></property>
<event name="OnMenuSelection">menuShowCoords</event>
<event name="OnUpdateUI">menuShowCoordsUpdate</event>
</object>
</object>
</object>
@ -293,7 +323,7 @@
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxEXPAND | wxALL</property>
<property name="proportion">4</property>
<property name="proportion">6</property>
<object class="wxNotebook" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
@ -328,7 +358,7 @@
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="minimum_size">400,-1</property>
<property name="moveable">1</property>
<property name="name">m_plotNotebook</property>
<property name="pane_border">1</property>

View File

@ -65,7 +65,11 @@ class SIM_PLOT_FRAME_BASE : public KIWAY_PLAYER
virtual void menuZoomOut( wxCommandEvent& event ) { event.Skip(); }
virtual void menuZoomFit( wxCommandEvent& event ) { event.Skip(); }
virtual void menuShowGrid( wxCommandEvent& event ) { event.Skip(); }
virtual void menuShowGridState( wxUpdateUIEvent& event ) { event.Skip(); }
virtual void menuShowGridUpdate( wxUpdateUIEvent& event ) { event.Skip(); }
virtual void menuShowLegend( wxCommandEvent& event ) { event.Skip(); }
virtual void menuShowLegendUpdate( wxUpdateUIEvent& event ) { event.Skip(); }
virtual void menuShowCoords( wxCommandEvent& event ) { event.Skip(); }
virtual void menuShowCoordsUpdate( wxUpdateUIEvent& event ) { event.Skip(); }
virtual void onPlotChanged( wxNotebookEvent& event ) { event.Skip(); }
virtual void onSignalDblClick( wxCommandEvent& event ) { event.Skip(); }
virtual void onSignalRClick( wxMouseEvent& event ) { event.Skip(); }

View File

@ -110,11 +110,13 @@ SIM_PLOT_PANEL::SIM_PLOT_PANEL( wxWindow* parent, wxWindowID id, const wxPoint&
m_axis_y->SetTicks( false );
AddLayer( m_axis_y );
m_legend = new mpInfoLegend( wxRect( 0, 0, 40, 40 ), wxWHITE_BRUSH );
AddLayer( m_legend );
m_coords = new mpInfoCoords( wxRect( 0, 0, 100, 40 ), wxWHITE_BRUSH );
AddLayer( m_coords );
m_topLevel.push_back( m_coords );
//m_coords = new mpInfoCoords( wxRect( 80, 20, 10, 10 ), wxWHITE_BRUSH );
//AddLayer( m_coords );
m_legend = new mpInfoLegend( wxRect( 0, 40, 40, 40 ), wxWHITE_BRUSH );
AddLayer( m_legend );
m_topLevel.push_back( m_legend );
}
@ -140,10 +142,14 @@ bool SIM_PLOT_PANEL::AddTrace( const wxString& aSpiceName, const wxString& aName
t->SetPen( wxPen( generateColor(), 1, wxSOLID ) );
m_traces[aName] = t;
// It is a trick to keep legend always on the top
DelLayer( m_legend );
// It is a trick to keep legend & coords always on the top
for( mpLayer* l : m_topLevel )
DelLayer( l );
AddLayer( t );
AddLayer( m_legend );
for( mpLayer* l : m_topLevel )
AddLayer( l );
}
else
{
@ -189,21 +195,6 @@ void SIM_PLOT_PANEL::DeleteAllTraces()
}
void SIM_PLOT_PANEL::ShowGrid( bool aEnable )
{
m_axis_x->SetTicks( !aEnable );
m_axis_y->SetTicks( !aEnable );
UpdateAll();
}
bool SIM_PLOT_PANEL::IsGridShown() const
{
assert( m_axis_x->GetTicks() == m_axis_y->GetTicks() );
return !m_axis_x->GetTicks();
}
bool SIM_PLOT_PANEL::HasCursorEnabled( const wxString& aName ) const
{
TRACE* t = GetTrace( aName );

View File

@ -182,9 +182,40 @@ public:
return trace == m_traces.end() ? NULL : trace->second;
}
void ShowGrid( bool aEnable = true );
void ShowGrid( bool aEnable )
{
m_axis_x->SetTicks( !aEnable );
m_axis_y->SetTicks( !aEnable );
UpdateAll();
}
bool IsGridShown() const;
bool IsGridShown() const
{
assert( m_axis_x->GetTicks() == m_axis_y->GetTicks() );
return !m_axis_x->GetTicks();
}
void ShowLegend( bool aEnable )
{
m_legend->SetVisible( aEnable );
UpdateAll();
}
bool IsLegendShown() const
{
return m_legend->IsVisible();
}
void ShowCoords( bool aEnable )
{
m_coords->SetVisible( aEnable );
UpdateAll();
}
bool IsCoordsShown() const
{
return m_coords->IsVisible();
}
bool HasCursorEnabled( const wxString& aName ) const;
@ -201,7 +232,9 @@ private:
mpScaleX* m_axis_x;
mpScaleY* m_axis_y;
mpInfoLegend* m_legend;
//mpInfoCoords* m_coords;
mpInfoCoords* m_coords;
std::vector<mpLayer*> m_topLevel;
};
wxDECLARE_EVENT( EVT_SIM_CURSOR_UPDATE, wxCommandEvent );