SBB Host
Host communication with the self balancing bike.
Loading...
Searching...
No Matches
SBBHostApp.h
Go to the documentation of this file.
1
2#ifndef SBBHOSTWIN_H
3#define SBBHOSTWIN_H
4
5#include <gtkmm.h>
6#include <string>
7#include <vector>
8#include <filesystem>
9#include <iomanip>
10#include "Params.h"
11#include "plotter.hpp"
12#include "StreamTreeView.h"
13#include "PlotTreeView.h"
14#include "EntryLabel.h"
15#include "config.h"
16#include "SBBHostCore.h"
17#include "SettingsDialog.h"
18#include "HostControl.h"
19#include "IniReader.h"
20#include "SBBUtils.h"
21
22#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) || defined(__WIN32__) || defined(WIN64) || defined(_WIN64) || defined(__WIN64) || defined(__WIN64__)
23#ifndef OS_WIN
24#define OS_WIN
25#endif
26#elif defined(linux) || defined(__linux) || defined(__linux__) || defined(__GNUC__) || defined(__GNUG__) || defined(unix) || defined(__unix) || defined(__unix__)
27#ifndef OS_LINUX
28#define OS_LINUX
29#endif
30#else
31#error OS not supported
32#endif
33
34/*
35* Main class of the GUI of the SBBHost application
36*/
37
44class SBBHostApp : public Gtk::Application {
45public:
50
54 virtual ~SBBHostApp();
55
61 static Glib::RefPtr<SBBHostApp> create();
62
63 static constexpr int EXIT_RESTART = 1;
64 static constexpr int EXIT_QUIT = 0;
66
67protected:
68
70
71 //conf .ini file
73
74 //pointer to app builder
75 Glib::RefPtr<Gtk::Builder> p_builder;
76 //gtk objects (pointers not necessary, C++ suggests to avoid using them when unnecessary)
77 Gtk::ApplicationWindow mainWin;
78 //Gtk::Notebook noteBook; //!< Gtk::Notebook object for the stream and plot tabs.
79 Gtk::HeaderBar headerbar;
80 Gtk::Label headerbarlabel;
81 Gtk::MenuButton menubutton;
82 Gtk::StackSwitcher switcher;
83 Gtk::Stack stack;
84 Gtk::Paned streamPaned;
85 Gtk::Paned plotPaned;
86 Gtk::Box streamBox0;
87 Gtk::Box streamBox1;
88 Gtk::Box streamBox2;
89 Gtk::Box plotBox1;
90 Gtk::Box fftBox;
91 Gtk::Overlay plotGraphOverlay;
92 Gtk::Frame streamTreeFrame;
93 Gtk::Frame plotTreeFrame;
94 Gtk::Frame streamGraphFrame;
95 Gtk::Label streamTimeLabel;
96 Gtk::ToggleButton buttonRun;
97 Gtk::ToggleButton buttonLog;
98 Gtk::AboutDialog aboutDialog;
99 Glib::ustring def_dir;
101 Gtk::Switch darkModeSwitch;
102 //Gtk::Switch streamModeSwitch; //!< Gtk::Switch object to switch the stream mode (serial/socket).
103 Gtk::ScrolledWindow scrolledWinStream;
104 Gtk::ScrolledWindow scrolledWinPlot;
107 Glib::Timer timer;
110
111 //pointer to Gtk objects (initialized to nullptr to ensure being empty) - objects cannot be directly used for them (?)
112 Glib::RefPtr<Gio::Menu> p_winmenu = nullptr;
113 Glib::RefPtr<Gio::Menu> p_filemenu = nullptr;
114 Glib::RefPtr<Gio::Menu> p_editmenu = nullptr;
115 Glib::RefPtr<Gio::Menu> p_helpmenu = nullptr;
116 Glib::RefPtr<Gio::Menu> p_conntype = nullptr;
117 Glib::RefPtr<Gio::SimpleAction> p_menuRun = nullptr;
118 Glib::RefPtr<Gio::SimpleAction> p_menuLog = nullptr;
119 Glib::RefPtr<Gio::SimpleAction> p_conn = nullptr;
120 std::unique_ptr<Gtk::MessageDialog> p_messageDialog = nullptr;
121#ifdef USE_NATIVE_DIALOG
122 Glib::RefPtr<Gtk::FileChooserNative> p_fileSaveAsDialog = nullptr;
123 Glib::RefPtr<Gtk::FileChooserNative> p_fileOpenDialog = nullptr;
124 Glib::RefPtr<Gtk::FileChooserNative> p_cfgLoadDialog = nullptr;
125 Glib::RefPtr<Gtk::FileChooserNative> p_setFolderDialog = nullptr;
126#else
127 Gtk::FileChooserDialog* p_fileSaveAsDialog = nullptr;
128 Gtk::FileChooserDialog* p_fileOpenDialog = nullptr;
129 Gtk::FileChooserDialog* p_cfgLoadDialog = nullptr;
130 Gtk::FileChooserDialog* p_setFolderDialog = nullptr;
131#endif
132 CGraph::CairoGraph* p_streamGraph = nullptr;
133 CGraph::CairoGraph* p_plotGraph = nullptr;
134 CGraph::CairoGraph* p_magfftGraph = nullptr;
135 CGraph::CairoGraph* p_phfftGraph = nullptr;
136
137 //Overrides of default signal handlers
138
143 void on_startup() override;
144
149 void on_activate() override;
150
151 //Signal handlers
152
158
163
169
174
179
185
192
199
205
211
217
224
230
235
241
246
251
256 void on_app_restart(int id_response);
257
264 void on_setting_dialog(int id_response);
265
271 void on_file_setfolder_dialog(int id_response);
272
278 void on_file_saveAs_dialog(int id_response);
279
285 void on_file_open_dialog(int id_response);
286
292 void on_cfg_load_dialog(int id_response);
293
300 void on_quit_confirmation(int id_response);
301
309 bool on_file_drag_and_drop(const Glib::ValueBase& value, double x, double y);
310
318
324
325 //other
330 void warning(int type);
331
336 void info(int type);
337
344 int open(std::string filename);
345
346private:
347 //class variables
348 int id = NULL_ID;
349 bool force_close = false;
351 double streamTimer;
353
354 //group params settable in settings in a struct
356
357 //class funs
362
367
372
377 void parse_ini();
378
383
387 void set_graph();
388
393 void set_tree();
394
398 void set_streamTimer(int secs);
399
404
409
414
416};
417
418#endif
A class with a Gtk::ComboBoxText and Gtk::Label. Slightly different from ComboEntryLabel.
Definition: EntryLabel.h:134
A class for host control widget.
Definition: HostControl.h:84
A class for configuration-file reading.
Definition: IniReader.h:41
A class for the application setting parameters.
Definition: Params.h:16
A class for the plot tree view.
Definition: PlotTreeView.h:42
A class for SBB Host application GUI.
Definition: SBBHostApp.h:44
Glib::RefPtr< Gio::Menu > p_filemenu
Pointer to Gio::Menu object for the file menu.
Definition: SBBHostApp.h:113
void on_menu_settings()
Signal handler called on settings menu button.
void info(int type)
Show information dialog.
void on_menu_stream_connect()
Signal handler called on connect menu button.
CGraph::CairoGraph * p_phfftGraph
Pointer to CGraph::CairoGraph object for the phase-spectra graph in the plot tab.
Definition: SBBHostApp.h:135
void on_menu_loadcfg()
Signal handler called on load config menu button.
void on_darkModeSwitch_switched()
Signal handler called on darkmode button switched.
void warning(int type)
Show warning dialog.
void on_menu_stream_run()
Signal handler called on run menu button.
Gtk::Overlay plotGraphOverlay
Gtk::Overlay object to overlay graph in the plot tab.
Definition: SBBHostApp.h:91
Gtk::ScrolledWindow scrolledWinStream
Gtk::ScrolledWindow object containing a StreamTreeView object.
Definition: SBBHostApp.h:103
static Glib::RefPtr< SBBHostApp > create()
Create the object.
CGraph::CairoGraph * p_plotGraph
Pointer to CGraph::CairoGraph object for the sample-domain graph in the plot tab.
Definition: SBBHostApp.h:133
SettingsDialog settingsDialog
SettingsDialog object for the setting dialog.
Definition: SBBHostApp.h:100
void on_menu_file_setfolder()
Signal handler called on set folder menu button.
static constexpr int EXIT_RESTART
Exitcode for app restarting.
Definition: SBBHostApp.h:63
Gtk::Paned streamPaned
Gtk::Paned object for the adjustable horizontal panes in the stream tab.
Definition: SBBHostApp.h:84
void on_menu_file_quit()
Signal handler called on quit menu button.
void on_menu_file_saveas()
Signal handler called on saveas menu button.
Glib::RefPtr< Gio::Menu > p_helpmenu
Pointer to Gio::Menu object for the help menu.
Definition: SBBHostApp.h:115
Gtk::Frame plotTreeFrame
Gtk::Frame object containing a PlotTreeView object.
Definition: SBBHostApp.h:93
int open(std::string filename)
Open a file and update the plot tree view.
bool on_read_serial()
Signal handler called during streaming.
Glib::RefPtr< Gtk::FileChooserNative > p_fileSaveAsDialog
Pointer to Gtk::FileChooserDialog object for the file saveas dialog.
Definition: SBBHostApp.h:122
double streamGraphTimer
Value of the stream-graph timer.
Definition: SBBHostApp.h:352
void set_graph()
Set graph.
CGraph::CairoGraph * p_streamGraph
Pointer to CGraph::CairoGraph object for the graph in the stream tab.
Definition: SBBHostApp.h:132
void on_plotType_changed()
Signal handler called on plot type changed.
Glib::RefPtr< Gio::Menu > p_conntype
Pointer to Gio::Menu object for the conn type menu.
Definition: SBBHostApp.h:116
bool force_close
Force the application to close.
Definition: SBBHostApp.h:349
Gtk::ApplicationWindow mainWin
Gtk::ApplicationWindow object for the main application window.
Definition: SBBHostApp.h:77
Glib::RefPtr< Gio::SimpleAction > p_menuLog
Pointer to Gio::SimpleAction object for the toolbar log button.
Definition: SBBHostApp.h:118
void parse_ini()
Parse the configuration file.
void on_menu_help_about()
Signal handler called on about menu button.
Gtk::Switch darkModeSwitch
Gtk::Switch object for the switch to enable/disable the dark mode.
Definition: SBBHostApp.h:101
Gtk::Label streamTimeLabel
Gtk::Label object for the elapsed time during the signal streaming.
Definition: SBBHostApp.h:95
Gtk::Frame streamTreeFrame
Gtk::Frame object containing a StreamTreeView object.
Definition: SBBHostApp.h:92
void clear_stream_graph()
Clear stream graph.
IniReader * p_cfg
Pointer to IniReader object to read the configuration file when application starts.
Definition: SBBHostApp.h:72
void on_conntype_radio_button(int i)
void on_menu_help_help()
Signal handler called on help menu button.
virtual ~SBBHostApp()
Destructor.
Glib::RefPtr< Gtk::FileChooserNative > p_cfgLoadDialog
Pointer to Gtk::FileChooserDialog object for the config load dialog.
Definition: SBBHostApp.h:124
std::unique_ptr< Gtk::MessageDialog > p_messageDialog
Pointer to Gtk::MessageDialog object for message dialogs.
Definition: SBBHostApp.h:120
void on_file_saveAs_dialog(int id_response)
Signal handler called on saveAs dialog close.
void on_buttonRun_toggled()
Signal handler called on run button toggled.
void set_tooltips()
Set tooltips.
ComboChoiceEntryLabel plotTypeComboEntry
ComboChoiceEntryLabel object to choose the plot type in the plot tab.
Definition: SBBHostApp.h:109
Gtk::Box streamBox2
Gtk::Box object for a horizontal box in the stream tab.
Definition: SBBHostApp.h:88
Gtk::MenuButton menubutton
Gtk::MenuButton object for the menu button.
Definition: SBBHostApp.h:81
Gtk::StackSwitcher switcher
Gtk::StackSwitcher object for the tab switcher.
Definition: SBBHostApp.h:82
void on_menu_stream_log()
Signal handler called on log menu button.
bool on_win_close()
Signal handler called for close request.
Gtk::AboutDialog aboutDialog
Gtk::AboutDialog object for the about dialog of the application.
Definition: SBBHostApp.h:98
void set_tree()
Set tree view.
Gtk::Box streamBox0
Gtk::Box object for a vertical box in the stream tab.
Definition: SBBHostApp.h:86
Glib::RefPtr< Gtk::Builder > p_builder
Pointer to Gtk::Builder to read the XML file for the toolbase.
Definition: SBBHostApp.h:75
Gtk::Paned plotPaned
Gtk::Paned object for the adjustable horizontal panes in the plot tab.
Definition: SBBHostApp.h:85
static constexpr int EXIT_QUIT
Exitcode for application quit (default).
Definition: SBBHostApp.h:64
CGraph::CairoGraph * p_magfftGraph
Pointer to CGraph::CairoGraph object for the magnitude-spectra graph in the plot tab.
Definition: SBBHostApp.h:134
void on_activate() override
Signal handler called on activate.
void on_menu_file_save()
Signal handler called on save menu button.
void on_cfg_load_dialog(int id_response)
Signal handler called on config load dialog close.
Glib::RefPtr< Gtk::FileChooserNative > p_setFolderDialog
Pointer to Gtk::FileChooserDialog object for the setfolder dialog.
Definition: SBBHostApp.h:125
Glib::RefPtr< Gio::Menu > p_winmenu
Pointer to Gio::Menu object for the menu.
Definition: SBBHostApp.h:112
double streamTimer
Value of the stream timer.
Definition: SBBHostApp.h:351
void on_buttonLog_toggled()
Signal handler called on log button toggled.
Gtk::Box plotBox1
Gtk::Box object for a vertical box in the plot tab.
Definition: SBBHostApp.h:89
void on_menu_file_open()
Signal handler called on open menu button.
PlotTreeView plotTreeView
PlotTreeView object for the tree view in the plot tab.
Definition: SBBHostApp.h:106
Gtk::Label headerbarlabel
Gtk::Label object for the label of the window header bar.
Definition: SBBHostApp.h:80
void set_drag_and_drop()
Set drag and drop.
HostControl hostControl
HostControl object for the host control.
Definition: SBBHostApp.h:108
StreamTreeView streamTreeView
StreamTreeView object for the tree view in the stream tab.
Definition: SBBHostApp.h:105
Glib::RefPtr< Gio::Menu > p_editmenu
Pointer to Gio::Menu object for the edit menu.
Definition: SBBHostApp.h:114
SBBHostCore core
SBBHostCore object for the core management of the application.
Definition: SBBHostApp.h:69
void on_file_open_dialog(int id_response)
Signal handler called on open dialog close.
Glib::RefPtr< Gio::SimpleAction > p_menuRun
Pointer to Gio::SimpleAction object for the toolbar run button.
Definition: SBBHostApp.h:117
bool on_file_drag_and_drop(const Glib::ValueBase &value, double x, double y)
Signal handler called drag-and-drop files into application.
int exitFlag
Exit flag (see config.h for details).
Definition: SBBHostApp.h:350
SBBHostApp()
Constructor.
void set_host_control()
Set host control.
Gtk::Box streamBox1
Gtk::Box object for a vertical box in the stream tab.
Definition: SBBHostApp.h:87
Gtk::ScrolledWindow scrolledWinPlot
Gtk::ScrolledWindow object containing a PlotTreeView object.
Definition: SBBHostApp.h:104
Params params
Params object to save application parameters.
Definition: SBBHostApp.h:355
Glib::RefPtr< Gtk::FileChooserNative > p_fileOpenDialog
Pointer to Gtk::FileChooserDialog object for the file open dialog.
Definition: SBBHostApp.h:123
void on_quit_confirmation(int id_response)
Signal handler called on quit confirmation.
Glib::Timer timer
Glib::Timer object to count the elased time.
Definition: SBBHostApp.h:107
Gtk::Frame streamGraphFrame
Gtk::Frame object containing the stream graph.
Definition: SBBHostApp.h:94
void create_graph()
Create graph.
Gtk::HeaderBar headerbar
Gtk::HeaderBar object for the window header bar.
Definition: SBBHostApp.h:79
void on_streamModeSwitch_switched()
Signal handler called on streamMode button switched.
void on_startup() override
Signal handler called on sturtup.
Gtk::ToggleButton buttonLog
Gtk::ToggleButton object for the log button.
Definition: SBBHostApp.h:97
Gtk::Box fftBox
Gtk::Box object for a horizontal box for the fft graph.
Definition: SBBHostApp.h:90
void on_setting_dialog(int id_response)
Signal handler called on setting dialog close.
void on_app_restart(int id_response)
Ask the user to restart the application.
void on_file_setfolder_dialog(int id_response)
Signal handler called on setfolder dialog close.
int exitcode
Exit code for the application.
Definition: SBBHostApp.h:65
void create_toolbar()
Create toolbar.
Gtk::ToggleButton buttonRun
Gtk::ToggleButton object for the run/stop button.
Definition: SBBHostApp.h:96
Glib::ustring def_dir
Default path where to save the log files.
Definition: SBBHostApp.h:99
void set_streamTimer(int secs)
Set timer.
void create_dialogs()
Create dialogs.
Glib::RefPtr< Gio::SimpleAction > p_conn
Definition: SBBHostApp.h:119
Gtk::Stack stack
Gtk::Stack object for the stream and plot tabs.
Definition: SBBHostApp.h:83
A class for the core of the SBB Host application.
Definition: SBBHostCore.h:46
A class for the setting dialog.
Definition: SettingsDialog.h:29
A class for the stream tree view.
Definition: StreamTreeView.h:34
A configuration file for the source code.
#define EXIT_DEFAULT
Default exit flag (no issues).
Definition: config.h:168
#define NULL_ID
Null log ID.
Definition: config.h:74