Temporary policy: ChatGPT is banned for linebreak add 2 spaces at end indent code by 4 spaces put returns between paragraphs
ClientChartsViewer.hpp
/*!
* ClientChartsViewer class declaration
*/
#pragma once
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include <wx/frame.h>
#include <wx/tglbtn.h>
#include <wx/scrolbar.h>
#include <wx/checkbox.h>
#include "wxchartviewer.h"
#include <vector>
#include <map>
#define SYMBOL_REALTIMEMEASURE_STYLE wxCAPTION|wxSYSTEM_MENU|wxCLOSE_BOX
#define SYMBOL_REALTIMEMEASURE_TITLE _("Real-Time Chart with Measurement Cursors")
#define SYMBOL_REALTIMEMEASURE_IDNAME ID_REALTIMEMEASURE
#define SYMBOL_REALTIMEMEASURE_SIZE wxSize(800, 420)
#define SYMBOL_REALTIMEMEASURE_POSITION wxDefaultPosition
class ClientChartsViewer : public wxFrame {
public:
/// Constructors
ClientChartsViewer();
ClientChartsViewer(wxWindow* parent, wxWindowID id = SYMBOL_REALTIMEMEASURE_IDNAME, const wxString& caption = SYMBOL_REALTIMEMEASURE_TITLE, const wxPoint& pos = SYMBOL_REALTIMEMEASURE_POSITION, const wxSize& size = SYMBOL_REALTIMEMEASURE_SIZE, long style = SYMBOL_REALTIMEMEASURE_STYLE);
bool Create(wxWindow* parent, wxWindowID id = SYMBOL_REALTIMEMEASURE_IDNAME, const wxString& caption = SYMBOL_REALTIMEMEASURE_TITLE, const wxPoint& pos = SYMBOL_REALTIMEMEASURE_POSITION, const wxSize& size = SYMBOL_REALTIMEMEASURE_SIZE, long style = SYMBOL_REALTIMEMEASURE_STYLE);
/// Destructor
~ClientChartsViewer();
/// Initialises member variables
void Init();
/// Creates the controls and sizers
void CreateControls(wxWindow* parent);
// Draw chart
void DrawChart(wxChartViewer* viewer);
// Draw track lines
void TrackLineLabel(XYChart* c);
void DrawTrackLine(XYChart* c, int i, std::map<std::string, double>& log);
void DrawTrackDiff(XYChart* c, std::map<std::string, double>& log0, std::map<std::string, double>& log1);
void UpdateControls(wxChartViewer* viewer);
// Event handler declarations
// ..............................\\\
};
ClientChartsViewer.cpp
#include "../include/ClientChartsViewer.hpp"
//#include <wx/sizer.h>
#include <sstream>
/*
* ClientChartsViewer type definition
*/
static const int gs_dataInterval = 250;
static const int gs_chartUpdateInterval = 250;
// The mouse can drag the track line if it is within the GrabDistance to the line.
static const int gs_grabDistance = 8;
/*
* ClientChartsViewer constructors
*/
ClientChartsViewer::ClientChartsViewer() {
Init();
}
ClientChartsViewer::ClientChartsViewer(wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style) {
Init();
Create(parent, id, caption, pos, size, style);
}
/*
* ClientChartsViewer creator
*/
bool
ClientChartsViewer::Create(wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style) {
wxFrame::Create(parent, id, caption, pos, size, style);
CreateControls(parent);
if (GetSizer())
{
GetSizer()->SetSizeHints(this);
}
Centre();
return true;
}
/*
* ClientChartsViewer destructor
*/
ClientChartsViewer::~ClientChartsViewer() {
m_dataRateTimer.Stop();
m_chartUpdateTimer.Stop();
if (m_chartViewer->getChart() != NULL) {
delete m_chartViewer->getChart();
}
}
void ClientChartsViewer::CreateControls(wxWindow* parent)
{
m_parent = parent;
//SetIcon(wxICON(mondrian));
//ClientChartsViewer* itemFrame1 = this;
wxBoxSizer* itemBoxSizer1 = new wxBoxSizer(wxVERTICAL);
//itemFrame1->SetSizer(itemBoxSizer1);
parent->SetSizer(itemBoxSizer1);
wxPanel* itemPanel2 = new wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER | wxTAB_TRAVERSAL);
itemPanel2->SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);
itemBoxSizer1->Add(itemPanel2, 1, wxGROW | wxALL, 0);
m_bgColour = itemPanel2->GetBackgroundColour();
wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
itemPanel2->SetSizer(itemBoxSizer3);
wxStaticBox* itemStaticBoxSizer1Static = new wxStaticBox(itemPanel2, wxID_ANY, wxEmptyString);
wxStaticBoxSizer* itemStaticBoxSizer1 = new wxStaticBoxSizer(itemStaticBoxSizer1Static, wxVERTICAL);
itemBoxSizer3->Add(itemStaticBoxSizer1, 0, wxGROW | wxALL, parent->FromDIP(3));
m_pointerButton = new wxToggleButton(itemPanel2, ID_POINTER, _(" &Pointer"), wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
m_pointerButton->SetBitmap(GetBitmapResource("pointer.png"));
m_pointerButton->SetBitmapMargins(parent->FromDIP(10), parent->FromDIP(0));
// Initially set the mouse to drag to scroll mode
m_pointerButton->SetValue(true);
itemStaticBoxSizer1->Add(m_pointerButton, 0, wxGROW | wxALL, parent->FromDIP(3));
m_zoominButton = new wxToggleButton(itemPanel2, wxID_ZOOM_IN, _(" Zoom &In"), wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
m_zoominButton->SetBitmap(GetBitmapResource("zoomin.png"));
m_zoominButton->SetBitmapMargins(parent->FromDIP(10), parent->FromDIP(0));
m_zoominButton->SetValue(false);
itemStaticBoxSizer1->Add(m_zoominButton, 0, wxGROW | wxALL, parent->FromDIP(3));
m_zoomoutButton = new wxToggleButton(itemPanel2, wxID_ZOOM_OUT, _(" Zoom &Out"), wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
m_zoomoutButton->SetBitmap(GetBitmapResource("zoomout.png"));
m_zoomoutButton->SetBitmapMargins(parent->FromDIP(10), parent->FromDIP(0));
m_zoomoutButton->SetValue(false);
itemStaticBoxSizer1->Add(m_zoomoutButton, 0, wxGROW | wxALL, parent->FromDIP(3));
itemStaticBoxSizer1->Add(3, 3, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, parent->FromDIP(3));
m_saveButton = new wxButton(itemPanel2, wxID_SAVE, _(" &Save"), wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
m_saveButton->SetBitmap(GetBitmapResource("save.png"));
m_saveButton->SetBitmapMargins(parent->FromDIP(10), parent->FromDIP(0));
itemStaticBoxSizer1->Add(m_saveButton, 0, wxGROW | wxALL, parent->FromDIP(3));
itemStaticBoxSizer1->Add(3, 3, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, parent->FromDIP(3));
m_trackLine1 = new wxCheckBox(itemPanel2, ID_TRACKLINE1, _("Track Line 1"), wxDefaultPosition, wxDefaultSize, 0);
m_trackLine1->SetValue(true);
itemStaticBoxSizer1->Add(m_trackLine1, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, parent->FromDIP(3));
m_trackLine2 = new wxCheckBox(itemPanel2, ID_TRACKLINE2, _("Track Line 2"), wxDefaultPosition, wxDefaultSize, 0);
m_trackLine2->SetValue(true);
itemStaticBoxSizer1->Add(m_trackLine2, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, parent->FromDIP(3));
wxBoxSizer* itemBoxSizer8 = new wxBoxSizer(wxVERTICAL);
itemBoxSizer3->Add(itemBoxSizer8, 1, wxGROW | wxALL, parent->FromDIP(3));
m_chartViewer = new wxChartViewer(itemPanel2, ID_CHARTVIEWER, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL | wxNO_BORDER);
m_chartViewer->SetMinSize(parent->FromDIP(wxSize(650, 350)));
m_chartViewer->SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);
itemBoxSizer8->Add(m_chartViewer, 1, wxGROW | wxALL, parent->FromDIP(3));
m_scrollBar = new wxScrollBar(itemPanel2, ID_SCROLLBAR, wxDefaultPosition, wxDefaultSize, wxSB_HORIZONTAL);
m_scrollBar->SetScrollbar(0, 0, 1000000000, 200000000);
itemBoxSizer8->Add(m_scrollBar, 0, wxGROW | wxALL, parent->FromDIP(3));
// Clear data arrays to Chart::NoValue
for (int i = 0; i < sampleSize; ++i)
{
m_timeStamps[i] = m_dataSeriesA[i] = m_dataSeriesB[i] = Chart::NoValue;
}
m_currentIndex = 0;
m_firstChartTime = m_chartTimeLimit = Chart::NoValue;
// Variables to keep track of the mouse for dragging track lines
m_nearestTrackLine = -1;
m_nearestDistance = 0;
// Set m_nextDataTime to the current time. It is used by the real time random number
// generator so it knows what timestamp should be used for the next data point.
m_nextDataTime = wxDateTime::Now();
// Enable mouse wheel zooming by setting the zoom ratio to 1.1 per wheel event
m_chartViewer->setMouseWheelZoomRatio(1.1);
// Set m_nextDataTime to the current time. It is used by the real time random number
// generator so it knows what timestamp should be used for the next data point.
m_nextDataTime = wxDateTime::Now();
// Set up the data acquisition mechanism. In this demo, we just use a timer to get a
// sample every 250ms.
//m_dataRateTimer = new wxTimer(parent, ID_DATA_TIMER);
m_dataRateTimer.Connect(wxEVT_TIMER, (wxObjectEventFunction)&ClientChartsViewer::OnDataTimer);
m_dataRateTimer.Start(gs_dataInterval);
// Set up the chart update timer
//m_chartUpdateTimer = new wxTimer(parent, ID_UPDATE_TIMER);
m_chartUpdateTimer.Connect(wxEVT_TIMER, (wxObjectEventFunction)&ClientChartsViewer::OnChartUpdateTimer);
m_chartUpdateTimer.Start(gs_chartUpdateInterval);
m_zoomoutButton->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction)&ClientChartsViewer::OnZoomOutClick);
m_pointerButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&ClientChartsViewer::OnPointerClick);
m_zoominButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&ClientChartsViewer::OnZoomInClick);
m_trackLine1->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction)&ClientChartsViewer::OnTrackline1Click);
m_trackLine2->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction)&ClientChartsViewer::OnTrackline2Click);
m_saveButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&ClientChartsViewer::OnSave);
m_chartViewer->Connect(wxEVT_CHARTVIEWER_MOUSEMOVE_PLOTAREA, (wxObjectEventFunction)&ClientChartsViewer::OnMouseMovePlotArea);
m_chartViewer->Connect(wxEVT_CHARTVIEWER_VIEWPORT_CHANGED, (wxObjectEventFunction)&ClientChartsViewer::OnViewPortChanged);
m_scrollBar->Connect(wxEVT_COMMAND_SCROLLBAR_UPDATED, (wxObjectEventFunction)&ClientChartsViewer::OnScrollbarUpdated);
}
/*
* Member initialisation
*/
void ClientChartsViewer::Init() {
m_trackLine1 = nullptr;
m_trackLine2 = nullptr;
}
That is, I want to place a graph on my wxAuiNotebook* PanelViewData. In my code I did the following:
wxAuiNotebook* PanelViewData = new wxAuiNotebook(this, wxID_ANY,
wxDefaultPosition, wxSize(200, 150),
wxAUI_NB_TAB_MOVE | wxAUI_NB_WINDOWLIST_BUTTON | wxAUI_NB_CLOSE_ON_ACTIVE_TAB | wxNO_BORDER);
// Charts
ChartsViewer_ = new ClientChartsViewer(PanelViewData);
I pass a pointer to the PanelViewData to the ClientChartsViewer() constructor.
You don't seem to be calling the base class ctor, which means that the actual
ClientChartsViewer
window is never created. You must either call the non-default ctor orCreate()
later for anywxWindow
-derived class (which I assume this one is, although I could be wrong because you don't show its declaration explicitly).