ifw-fcf 6.0.0
Loading...
Searching...
No Matches
mainwindow.h
Go to the documentation of this file.
1
8#ifndef FCF_GUI_MAINWINDOW_HPP_
9#define FCF_GUI_MAINWINDOW_HPP_
10
11#include <any>
12#include <QMainWindow>
13#include <QTimer>
14#include <QMap>
15#include <QPair>
20#include <Fcfif.hpp>
21#include <Stdif.hpp>
22
23#include <mal/Cii.hpp>
24#include <mal/Mal.hpp>
25#include <mal/utility/LoadMal.hpp>
26#include <mal/rr/qos/ReplyTime.hpp>
27
28
29#include <utils/bat/dbInterface.hpp>
30
31#include <yaml-cpp/yaml.h>
32
33
34#include <QCloseEvent>
35#include <QApplication>
36#include <QThread>
37
38class QGroupBox;
39class QLabel;
40class QTextEdit;
41class QLineEdit;
42class QPushButton;
43class QCheckBox;
44class QComboBox;
45class QListWidget;
46class QString;
47
48class IfwLed;
49
50namespace Ui
51{
52 class MainWindow;
53}
54
55namespace fcf::devmgr::common
56{
57 class DeviceConfig;
58}
59
60//---------------------------------------------------------------------------------
61// MainWindow
62//---------------------------------------------------------------------------------
63class MainWindow : public QMainWindow
64{
65 Q_OBJECT
66
67 private:
68
69 // Enumaration for pages in tab widget
70 enum Page
71 {
72 Devices,
73 Sensors,
74 All
75 };
76
77 // Enumaration for dynamic state style
78 enum StateEnum
79 {
80 ERROR,
81 WARNING,
82 OK,
83 };
84
85 // Helper class
86 struct OverrideCursor
87 {
88 OverrideCursor(Qt::CursorShape shape = Qt::WaitCursor)
89 {
90 QApplication::setOverrideCursor(shape);
91 }
92
93 ~OverrideCursor()
94 {
95 QApplication::restoreOverrideCursor();
96 }
97 };
98
99 public:
100 MainWindow(QWidget *parent,
101 const QString uri,
102 int polling_interval);
103 virtual ~MainWindow() override;
104
105 void closeEvent(QCloseEvent *event) override;
106
107 private slots:
108 // NOTE:
109 // This is to explain the naming conventions of the slots methods.
110 // They do not follow ESO's naming convention to enable the automatic
111 // connection done by Qt for action signals following Qt naming convention.
112
113 // Updates triggered by timer
114 void UpdateFromDb();
115
116 // File menu
117 void on_actionExit_triggered();
118
119 // FCS menu
120 void on_actionInit_triggered();
121 void on_actionEnable_triggered();
122 void on_actionDisable_triggered();
123 void on_actionRecover_triggered();
124 void on_actionReset_triggered();
125 void on_actionLogError_triggered() { SetFcsLogLevel("ERROR"); };
126 void on_actionLogInfo_triggered() { SetFcsLogLevel("INFO"); };
127 void on_actionLogDebug_triggered() { SetFcsLogLevel("DEBUG"); };
128 void on_actionLogTrace_triggered() { SetFcsLogLevel("TRACE"); };
129
130 // Device menu
131 void on_actionSelect_All_triggered();
132 void on_actionDeselect_All_triggered();
133 void on_actionDevReset_triggered();
134 void on_actionDevInit_triggered();
135 void on_actionDevEnable_triggered();
136 void on_actionDevDisable_triggered();
137 void on_actionDevSimulate_triggered();
138 void on_actionDevStopSim_triggered();
139 void on_actionDevIgnore_triggered();
140 void on_actionDevStopIgn_triggered();
141
142 // Tools menu
143 void on_actionFCF_CLI_triggered();
144
145 // Help menu
146 void on_actionAbout_triggered();
147 void on_actionWhatsthis_triggered();
148 void onThemeActionTriggered();
149
150 // Other
151 void handleSetupButton();
152 void handleDeviceSetup(QString name);
153 void handleStopButton();
154 void addLogEntry(const QString& type,
155 const QString& cmd,
156 const QString& text);
157 void updateWindowState();
158
159 private:
160 void ApplUiSetup();
161 void CreateMalInterfaces(const QString uri);
162 void GetServerConfiguration();
163 void CreateDbClient();
164 void CreateDeviceWidgets();
165 AbstractDevice* AddDeviceWidget(const std::string &devname,
166 const std::string& devtype,
167 const std::string& server_id,
168 int cmd_timeout);
169 std::vector<std::string> selectedDevices(MainWindow::Page page = MainWindow::All) const;
170 void SetFcsLogLevel(const std::string &level);
171
172 template <class WorkerType>
173 void StartInThread(WorkerType* worker)
174 {
175 QThread* thread = new QThread;
176 worker->moveToThread(thread);
177 QObject::connect(thread, &QThread::started, worker, &WorkerType::process);
178 QObject::connect(thread, &QThread::finished, thread, &QThread::deleteLater);
179 QObject::connect(worker, &WorkerType::finished, thread, &QThread::quit);
180 QObject::connect(worker, &WorkerType::finished, worker, &WorkerType::deleteLater);
181 QObject::connect(worker, &WorkerType::LogReplyOut,
182 this, &MainWindow::addLogEntry,
183 Qt::QueuedConnection);
184 thread->start();
185 }
186
187 void ReadSettings();
188 void WriteSettings() const;
189
190 // Dynamic style change
191 void OnStateCurrentChanged(const StateEnum& state);
192
193 private:
194 static const QString org_name;
195 static const QString app_name;
196 static const int update_ms;
197 static const QString lamp_type;
198 static const QString shutter_type;
199 static const QString motor_type;
200 static const QString iodev_type;
201 static const QString drot_type;
202 static const QString adc_type;
203 static const QString piezo_type;
204 static const QString actuator_type;
205 static const QString smaract_type;
206 static const QString msm_type;
207
208 using WdgInfo = std::tuple<std::string, MainWindow::Page, AbstractDevice*>; // <devname, page, Pointer to widget>
209 using WdgInfoVec = std::vector<WdgInfo>;
210 WdgInfoVec m_wdgs;
211
212 Ui::MainWindow* ui;
213 QLabel* m_server_connection_label;
214 IfwLed* m_led;
215 QTimer* m_timer;
216 QString m_state;
217 QString m_substate;
218 fcf::devmgr::common::Config m_config_file;
219 std::unique_ptr<utils::bat::DbInterface> m_oldb;
220 std::shared_ptr<::elt::mal::Mal> m_mal_instance;
221 std::shared_ptr<::stdif::StdCmdsSync> m_mal_std;
222 std::shared_ptr<::fcfif::AppCmdsSync> m_mal_client;
223 elt::mal::Mal::Properties m_mal_properties;
224 elt::mal::Uri m_mal_uri;
225 elt::mal::Uri m_mal_uri2;
226 elt::mal::rr::ListenerRegistration m_connection_listener;
227};
228
229#endif // FCF_GUI_MAINWINDOW_HPP_
WDGLIB AbstractDevice class declaration file.
Definition: abstractDevice.h:21
Definition: mainwindow.hpp:12
void closeEvent(QCloseEvent *event) override
Definition: mainwindow.cpp:623
virtual ~MainWindow() override
Definition: config.hpp:56
Config class header file.
WDGLIB DeviceWdg class declaration file.
Definition: mainwindow.hpp:7
Definition: actionMgr.cpp:29
MSGLIB SubscribeCmdWorker class declaration file.