📄 plot.cpp
字号:
m_curves.Append( curve );
if (!m_current) m_current = curve;
ResetScrollbar();
}
size_t wxPlotWindow::GetCount()
{
return m_curves.GetCount();
}
wxPlotCurve *wxPlotWindow::GetAt( size_t n )
{
wxList::compatibility_iterator node = m_curves.Item( n );
if (!node)
return (wxPlotCurve*) NULL;
return (wxPlotCurve*) node->GetData();
}
void wxPlotWindow::SetCurrentCurve( wxPlotCurve* current )
{
m_current = current;
m_area->Refresh( false );
RedrawYAxis();
wxPlotEvent event( wxEVT_PLOT_SEL_CHANGED, GetId() );
event.SetEventObject( this );
event.SetZoom( GetZoom() );
event.SetCurve( m_current );
GetEventHandler()->ProcessEvent( event );
}
void wxPlotWindow::Delete( wxPlotCurve* curve )
{
wxList::compatibility_iterator node = m_curves.Find( curve );
if (!node) return;
m_curves.DeleteObject( curve );
m_area->DeleteCurve( curve );
m_area->Refresh( false );
if (curve == m_current) m_current = (wxPlotCurve *) NULL;
}
wxPlotCurve *wxPlotWindow::GetCurrentCurve()
{
return m_current;
}
void wxPlotWindow::Add( wxPlotOnOffCurve *curve )
{
m_onOffCurves.Append( curve );
}
void wxPlotWindow::Delete( wxPlotOnOffCurve* curve )
{
wxList::compatibility_iterator node = m_onOffCurves.Find( curve );
if (!node) return;
m_onOffCurves.DeleteObject( curve );
}
size_t wxPlotWindow::GetOnOffCurveCount()
{
return m_onOffCurves.GetCount();
}
wxPlotOnOffCurve *wxPlotWindow::GetOnOffCurveAt( size_t n )
{
wxList::compatibility_iterator node = m_onOffCurves.Item( n );
if (!node)
return (wxPlotOnOffCurve*) NULL;
return (wxPlotOnOffCurve*) node->GetData();
}
void wxPlotWindow::Move( wxPlotCurve* curve, int pixels_up )
{
m_area->DeleteCurve( curve );
curve->SetOffsetY( curve->GetOffsetY() + pixels_up );
m_area->Refresh( false );
RedrawYAxis();
}
void wxPlotWindow::OnMoveUp( wxCommandEvent& WXUNUSED(event) )
{
if (!m_current) return;
Move( m_current, 25 );
}
void wxPlotWindow::OnMoveDown( wxCommandEvent& WXUNUSED(event) )
{
if (!m_current) return;
Move( m_current, -25 );
}
void wxPlotWindow::Enlarge( wxPlotCurve *curve, double factor )
{
m_area->DeleteCurve( curve );
int client_width;
int client_height;
m_area->GetClientSize( &client_width, &client_height);
double offset = (double)curve->GetOffsetY() / (double)client_height;
double range = curve->GetEndY() - curve->GetStartY();
offset *= range;
double new_range = range / factor;
double new_offset = offset / factor;
if (m_enlargeAroundWindowCentre)
{
double middle = curve->GetStartY() - offset + range/2;
curve->SetStartY( middle - new_range / 2 + new_offset );
curve->SetEndY( middle + new_range / 2 + new_offset );
}
else
{
curve->SetStartY( (curve->GetStartY() - offset)/factor + new_offset );
curve->SetEndY( (curve->GetEndY() - offset)/factor + new_offset );
}
m_area->Refresh( false );
RedrawYAxis();
}
void wxPlotWindow::SetUnitsPerValue( double upv )
{
m_xUnitsPerValue = upv;
RedrawXAxis();
}
void wxPlotWindow::SetZoom( double zoom )
{
double old_zoom = m_xZoom;
m_xZoom = zoom;
int view_x = 0;
int view_y = 0;
GetViewStart( &view_x, &view_y );
wxInt32 max = 0;
wxList::compatibility_iterator node = m_curves.GetFirst();
while (node)
{
wxPlotCurve *curve = (wxPlotCurve*) node->GetData();
if (curve->GetEndX() > max)
max = curve->GetEndX();
node = node->GetNext();
}
SetScrollbars( wxPLOT_SCROLL_STEP, wxPLOT_SCROLL_STEP,
(int)((max*m_xZoom)/wxPLOT_SCROLL_STEP)+1, 0,
(int)(view_x*zoom/old_zoom), 0,
true );
RedrawXAxis();
m_area->Refresh( true );
}
void wxPlotWindow::ResetScrollbar()
{
wxInt32 max = 0;
wxList::compatibility_iterator node = m_curves.GetFirst();
while (node)
{
wxPlotCurve *curve = (wxPlotCurve*) node->GetData();
if (curve->GetEndX() > max)
max = curve->GetEndX();
node = node->GetNext();
}
SetScrollbars( wxPLOT_SCROLL_STEP, wxPLOT_SCROLL_STEP,
(int)(((max*m_xZoom)/wxPLOT_SCROLL_STEP)+1), 0 );
}
void wxPlotWindow::AddChartTitle(const wxString& title, wxFont font,
wxColour colour)
{
m_title = title;
m_titleFont = font;
m_titleColour = colour;
DrawChartTitle();
}
void wxPlotWindow::DrawChartTitle()
{
if(m_title.size() != 0)
{
//If it is already added, remove child and delete
if(m_titleStaticText)
{
RemoveChild( m_titleStaticText );
m_titleStaticText->Destroy();
}
//Create the text control and set the font, colour
m_titleStaticText = new wxStaticText( this, -1, m_title );
m_titleStaticText->SetFont( m_titleFont );
m_titleStaticText->SetForegroundColour( m_titleColour );
//Create a sizer for the title. Prepend it to the Plot + Title sizer.
wxBoxSizer* titleSizer = new wxBoxSizer( wxHORIZONTAL );
titleSizer->Add( m_titleStaticText, 0, wxALIGN_CENTER | wxALL, 10 );
m_plotAndTitleSizer->Prepend( titleSizer, 0, wxALIGN_CENTER_HORIZONTAL );
//Finally, force layout
m_plotAndTitleSizer->Layout();
}
}
void wxPlotWindow::RedrawXAxis()
{
if (m_xaxis)
m_xaxis->Refresh( true );
}
void wxPlotWindow::RedrawYAxis()
{
if (m_yaxis)
m_yaxis->Refresh( true );
}
void wxPlotWindow::RedrawEverything()
{
if (m_xaxis)
m_xaxis->Refresh( true );
if (m_yaxis)
m_yaxis->Refresh( true );
m_area->Refresh( true );
DrawChartTitle();
}
void wxPlotWindow::OnZoomIn( wxCommandEvent& WXUNUSED(event) )
{
SetZoom( m_xZoom * 1.5 );
}
void wxPlotWindow::OnZoomOut( wxCommandEvent& WXUNUSED(event) )
{
SetZoom( m_xZoom * 0.6666 );
}
void wxPlotWindow::OnEnlarge( wxCommandEvent& WXUNUSED(event) )
{
if (!m_current) return;
Enlarge( m_current, 1.5 );
}
void wxPlotWindow::OnShrink( wxCommandEvent& WXUNUSED(event) )
{
if (!m_current) return;
Enlarge( m_current, 0.6666666 );
}
void wxPlotWindow::OnScroll2( wxScrollWinEvent& event )
{
if ((!m_scrollOnThumbRelease) || (event.GetEventType() != wxEVT_SCROLLWIN_THUMBTRACK))
{
wxScrolledWindow::OnScroll( event );
RedrawXAxis();
}
}
// ----------------------------------------------------------------------------
// global functions
// ----------------------------------------------------------------------------
// FIXME MT-UNSAFE
static wxBitmap *GetEnlargeBitmap()
{
static wxBitmap* s_bitmap = (wxBitmap *) NULL;
static bool s_loaded = false;
if ( !s_loaded )
{
s_loaded = true; // set it to true anyhow, we won't try again
#if defined(__WXMSW__) || defined(__WXPM__)
s_bitmap = new wxBitmap(_T("plot_enl_bmp"), wxBITMAP_TYPE_RESOURCE);
#else
s_bitmap = new wxBitmap( plot_enl_xpm );
#endif
}
return s_bitmap;
}
static wxBitmap *GetShrinkBitmap()
{
static wxBitmap* s_bitmap = (wxBitmap *) NULL;
static bool s_loaded = false;
if ( !s_loaded )
{
s_loaded = true; // set it to true anyhow, we won't try again
#if defined(__WXMSW__) || defined(__WXPM__)
s_bitmap = new wxBitmap(_T("plot_shr_bmp"), wxBITMAP_TYPE_RESOURCE);
#else
s_bitmap = new wxBitmap( plot_shr_xpm );
#endif
}
return s_bitmap;
}
static wxBitmap *GetZoomInBitmap()
{
static wxBitmap* s_bitmap = (wxBitmap *) NULL;
static bool s_loaded = false;
if ( !s_loaded )
{
s_loaded = true; // set it to true anyhow, we won't try again
#if defined(__WXMSW__) || defined(__WXPM__)
s_bitmap = new wxBitmap(_T("plot_zin_bmp"), wxBITMAP_TYPE_RESOURCE);
#else
s_bitmap = new wxBitmap( plot_zin_xpm );
#endif
}
return s_bitmap;
}
static wxBitmap *GetZoomOutBitmap()
{
static wxBitmap* s_bitmap = (wxBitmap *) NULL;
static bool s_loaded = false;
if ( !s_loaded )
{
s_loaded = true; // set it to true anyhow, we won't try again
#if defined(__WXMSW__) || defined(__WXPM__)
s_bitmap = new wxBitmap(_T("plot_zot_bmp"), wxBITMAP_TYPE_RESOURCE);
#else
s_bitmap = new wxBitmap( plot_zot_xpm );
#endif
}
return s_bitmap;
}
static wxBitmap *GetUpBitmap()
{
static wxBitmap* s_bitmap = (wxBitmap *) NULL;
static bool s_loaded = false;
if ( !s_loaded )
{
s_loaded = true; // set it to true anyhow, we won't try again
#if defined(__WXMSW__) || defined(__WXPM__)
s_bitmap = new wxBitmap(_T("plot_up_bmp"), wxBITMAP_TYPE_RESOURCE);
#else
s_bitmap = new wxBitmap( plot_up_xpm );
#endif
}
return s_bitmap;
}
static wxBitmap *GetDownBitmap()
{
static wxBitmap* s_bitmap = (wxBitmap *) NULL;
static bool s_loaded = false;
if ( !s_loaded )
{
s_loaded = true; // set it to true anyhow, we won't try again
#if defined(__WXMSW__) || defined(__WXPM__)
s_bitmap = new wxBitmap(_T("plot_dwn_bmp"), wxBITMAP_TYPE_RESOURCE);
#else
s_bitmap = new wxBitmap( plot_dwn_xpm );
#endif
}
return s_bitmap;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -