RumPi Linux Client 1.0
A wxWidgets desktop dashboard that visualizes a RumPi robot's live sensor data as a condition-reactive scene
MainWindow.h
Go to the documentation of this file.
1#pragma once
2
3#include <wx/artprov.h>
4#include <wx/xrc/xmlres.h>
5#include <wx/intl.h>
6#include <wx/panel.h>
7#include <wx/gdicmn.h>
8#include <wx/font.h>
9#include <wx/colour.h>
10#include <wx/settings.h>
11#include <wx/string.h>
12#include <wx/bitmap.h>
13#include <wx/image.h>
14#include <wx/icon.h>
15#include <wx/notebook.h>
16#include <wx/sizer.h>
17#include <wx/frame.h>
18#include <wx/menu.h>
19#include <wx/msgdlg.h>
20#include <wx/dataview.h>
21#include <wx/stattext.h>
22#include <wx/statbox.h>
23#include <RumPi/Data/SelectedSensorReadings.h>
24#include "../../Headers/LoggerEventForwarder.h"
25#include "../../Headers/GUI/ComponentData.h"
26#include "../../Headers/GUI/ComponentPanel.h"
27#include "../../Headers/GUI/HomeScenePanel.h"
28#include "../../Headers/GUI/LoggerListData.h"
29
30//Owned by pointer, so a forward declaration keeps wx/thread.h and the poll-loop details out of this header.
32
34wxDECLARE_EVENT(wxEVT_RUMPI_UPDATE, wxThreadEvent);
35
43{
44 ID_SHOW_LOGS = 52
45};
46
54class MainWindow : public wxFrame
55{
56protected:
57 wxNotebook* myNotebook;
59 wxPanel* mySummaryPanel;
60 wxPanel* myDevicesPanel;
61 wxPanel* myLoggerPanel;
62 wxPanel* mySettingsPanel;
63
64 //Devices Panel
65 wxGridSizer* myDataViewGridSizer;
66 wxScrolledWindow* myDevicesScrollWindow;
67
68 //Logger Panel
69 wxDataViewCtrl* myLoggerDataViewCtrl;
72
73 //Summary Panel: the live value label for each at-a-glance tile.
74 wxStaticText* myTemperatureValue;
75 wxStaticText* myHumidityValue;
76 wxStaticText* myAirQualityValue;
77 wxStaticText* myPmTwoPointFiveValue;
78 wxStaticText* myTVOCValue;
79 wxStaticText* myFormaldehydeValue;
80 wxStaticText* myCO2Value;
81 wxStaticText* myMotionValue;
82 wxStaticText* myWindSpeedValue;
83 wxStaticText* myLightValue;
84
85 //One panel per component instance, keyed by the component's unique name (multiple components can share a type,
86 //so the name - not the type - is the identity here).
87 std::unordered_map<std::string, ComponentPanel*> myComponentDataCollection;
88
89 //Background worker: polls RumPi and posts wxEVT_RUMPI_UPDATE to this window. Owned here so it can be stopped
90 //and freed before the window is destroyed - it holds a pointer to us and must not outlive us.
92
104
115 void ConstructNotebook();
116
127 void ConstructHomePanel();
128
141
153
165
177
190
207 wxStaticText* CreateSummaryTile(wxWindow* parent, wxSizer* tileGridSizer, const wxString& title);
208
222 void UpdateSummaryPanel(const RumPi::SelectedSensorReadings& readings);
223
237 virtual void OnClose(wxCloseEvent& event);
238
251 virtual void OnExit(wxCommandEvent& event);
252
265 virtual void OnAbout(wxCommandEvent& event);
266
280 virtual void OnShowLogs(wxCommandEvent& event);
281
295 virtual void OnRumPiUpdate(wxThreadEvent& event);
296
311 void RefreshDeviceTiles(const std::string& componentJson);
312
325 virtual void OnLoggerUpdate(wxThreadEvent& event);
326
327public:
347 MainWindow(wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize(500, 300), long style = wxDEFAULT_FRAME_STYLE | wxTAB_TRAVERSAL);
348
360 ~MainWindow();
361};
wxDECLARE_EVENT(wxEVT_RUMPI_UPDATE, wxThreadEvent)
Custom event carrying a component-data update from the manager thread to the UI.
RumPiMenuID
Menu / control command IDs for the main window.
Definition: MainWindow.h:43
@ ID_SHOW_LOGS
The "Show Log Files" menu item.
Definition: MainWindow.h:44
The Home tab's stylized, condition-reactive backdrop.
Definition: HomeScenePanel.h:26
Bridges the library's AlertManager to the wxWidgets event system: it subscribes to the AlertManager o...
Definition: LoggerEventForwarder.h:18
A virtual list model backing the on-screen log's data-view control, holding the log lines and colouri...
Definition: LoggerListData.h:27
The client's main window: a tabbed frame (Home scene, Summary tiles, Devices, Logger,...
Definition: MainWindow.h:55
wxStaticText * myAirQualityValue
The Air Quality tile's value label.
Definition: MainWindow.h:76
wxStaticText * myPmTwoPointFiveValue
The PM2.5 tile's value label.
Definition: MainWindow.h:77
void ConstructLoggerPanel()
Builds the Logger tab: a data-view control with icon/time/level/description columns,...
Definition: MainWindow.cpp:357
void ConstructMenuAndStatusBar()
Builds the menu bar and status bar and binds the window's menu, update, logger, and close events.
Definition: MainWindow.cpp:95
virtual void OnExit(wxCommandEvent &event)
Exit handler: closes the window.
Definition: MainWindow.cpp:473
void ConstructSummaryPanel()
Builds the Summary tab: a three-per-row grid of at-a-glance sensor tiles, stashing each tile's value ...
Definition: MainWindow.cpp:203
void ConstructSettingsPanel()
Builds the (currently empty) Settings tab and adds it to the notebook.
Definition: MainWindow.cpp:399
wxStaticText * myFormaldehydeValue
The Formaldehyde tile's value label.
Definition: MainWindow.h:79
wxStaticText * myTVOCValue
The TVOC tile's value label.
Definition: MainWindow.h:78
HomeScenePanel * myHomeScenePanel
The Home tab's condition-reactive backdrop.
Definition: MainWindow.h:58
wxPanel * myLoggerPanel
The Logger tab.
Definition: MainWindow.h:61
wxPanel * mySummaryPanel
The Summary tab (at-a-glance tiles).
Definition: MainWindow.h:59
wxStaticText * CreateSummaryTile(wxWindow *parent, wxSizer *tileGridSizer, const wxString &title)
Builds one titled summary tile with a large centered value label and adds it to the grid.
Definition: MainWindow.cpp:247
virtual void OnRumPiUpdate(wxThreadEvent &event)
RumPi-update handler (main thread): refreshes the Summary tiles and Home scene from the event's snaps...
Definition: MainWindow.cpp:549
void RefreshDeviceTiles(const std::string &componentJson)
Parses the component JSON payload and creates/refreshes one device tile per named component instance.
Definition: MainWindow.cpp:568
wxStaticText * myWindSpeedValue
The Wind Speed tile's value label.
Definition: MainWindow.h:82
LoggerListData * myLoggerListDataModel
The model backing the log control.
Definition: MainWindow.h:70
void ConstructNotebook()
Builds the notebook and its five tabs (Home, Summary, Devices, Logger, Settings) and adds it to the w...
Definition: MainWindow.cpp:139
wxStaticText * myHumidityValue
The Humidity tile's value label.
Definition: MainWindow.h:75
wxStaticText * myMotionValue
The Motion tile's value label.
Definition: MainWindow.h:81
std::unordered_map< std::string, ComponentPanel * > myComponentDataCollection
Definition: MainWindow.h:87
RumPiManagerThread * myRumPiManagerThread
Definition: MainWindow.h:91
wxDataViewCtrl * myLoggerDataViewCtrl
The data-view control showing the log.
Definition: MainWindow.h:69
MainWindow(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=wxEmptyString, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(500, 300), long style=wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL)
Builds the main window: sets up the menu/status bar and notebook, creates the alert forwarder,...
Definition: MainWindow.cpp:32
void ConstructDevicesPanel()
Builds the Devices tab: a scrollable, three-column grid that will hold one tile per component instanc...
Definition: MainWindow.cpp:320
LoggerEventForwarder * myLoggerEventForwarder
Forwards AlertManager alerts to the Logger tab.
Definition: MainWindow.h:71
void TeardownBackgroundWork()
Stops the background poll thread and then tears down the alert forwarder, in that order (stop the pro...
Definition: MainWindow.cpp:416
wxPanel * myDevicesPanel
The Devices tab.
Definition: MainWindow.h:60
wxStaticText * myTemperatureValue
The Temperature tile's value label.
Definition: MainWindow.h:74
virtual void OnLoggerUpdate(wxThreadEvent &event)
Logger-update handler (main thread): appends the event's log line to the logger model.
Definition: MainWindow.cpp:647
void UpdateSummaryPanel(const RumPi::SelectedSensorReadings &readings)
Refreshes every summary tile's value label from a sensor snapshot (temperature, humidity,...
Definition: MainWindow.cpp:284
wxPanel * mySettingsPanel
The Settings tab.
Definition: MainWindow.h:62
wxStaticText * myLightValue
The Light tile's value label.
Definition: MainWindow.h:83
void ConstructHomePanel()
Builds the Home tab's condition-reactive scene panel and adds it to the notebook.
Definition: MainWindow.cpp:182
wxGridSizer * myDataViewGridSizer
The grid sizer holding the device tiles.
Definition: MainWindow.h:65
virtual void OnShowLogs(wxCommandEvent &event)
"Show Log Files" handler: opens the log folder in the platform's file manager, falling back to a mess...
Definition: MainWindow.cpp:509
wxStaticText * myCO2Value
The CO2 tile's value label.
Definition: MainWindow.h:80
~MainWindow()
Destroys the window, tearing down the background work as a safety net for paths that bypass OnClose (...
Definition: MainWindow.cpp:78
wxScrolledWindow * myDevicesScrollWindow
The scrollable container for the device tiles.
Definition: MainWindow.h:66
virtual void OnAbout(wxCommandEvent &event)
About handler: shows the application's about dialog.
Definition: MainWindow.cpp:490
wxNotebook * myNotebook
The tab container.
Definition: MainWindow.h:57
virtual void OnClose(wxCloseEvent &event)
Close handler: tears down the background work before the window is destroyed (the worker and forwarde...
Definition: MainWindow.cpp:452
Background wxThread that runs the RumPi library's sensor loop and posts refreshed component data (and...
Definition: RumPiManagerThread.h:16