ifw-fcf  4.1.0-pre2
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>
19 #include "fcf/gui/wdglib/device.h"
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 
38 class QGroupBox;
39 class QLabel;
40 class QTextEdit;
41 class QLineEdit;
42 class QPushButton;
43 class QCheckBox;
44 class QComboBox;
45 class QListWidget;
46 class QString;
47 
48 namespace Ui
49 {
50  class MainWindow;
51 }
52 
53 namespace fcf::devmgr::common
54 {
55  class DeviceConfig;
56 }
57 
58 //---------------------------------------------------------------------------------
59 // MainWindow
60 //---------------------------------------------------------------------------------
61 class MainWindow : public QMainWindow
62 {
63  Q_OBJECT
64 
65  private:
66 
67  // Enumaration for pages in tab widget
68  enum Page
69  {
70  Devices,
71  Sensors,
72  All
73  };
74 
75  // Enumaration for dynamic state style
76  enum StateEnum
77  {
78  ERROR,
79  WARNING,
80  OK,
81  };
82 
83  // Helper class
84  struct OverrideCursor
85  {
86  OverrideCursor(Qt::CursorShape shape = Qt::WaitCursor)
87  {
88  QApplication::setOverrideCursor(shape);
89  }
90 
91  ~OverrideCursor()
92  {
93  QApplication::restoreOverrideCursor();
94  }
95  };
96 
97  public:
98  MainWindow(QWidget *parent,
99  const QString uri,
100  int polling_interval);
101  virtual ~MainWindow() override;
102 
103  void closeEvent(QCloseEvent *event) override;
104 
105  private slots:
106  // NOTE:
107  // This is to explain the naming conventions of the slots methods.
108  // They do not follow ESO's naming convention to enable the automatic
109  // connection done by Qt for action signals following Qt naming convention.
110 
111  // Updates triggered by timer
112  void UpdateFromDb();
113 
114  // File menu
115  void on_actionExit_triggered();
116 
117  // FCS menu
118  void on_actionInit_triggered();
119  void on_actionEnable_triggered();
120  void on_actionDisable_triggered();
121  void on_actionRecover_triggered();
122  void on_actionReset_triggered();
123  void on_actionLogError_triggered() { SetFcsLogLevel("ERROR"); };
124  void on_actionLogInfo_triggered() { SetFcsLogLevel("INFO"); };
125  void on_actionLogDebug_triggered() { SetFcsLogLevel("DEBUG"); };
126  void on_actionLogTrace_triggered() { SetFcsLogLevel("TRACE"); };
127 
128  // Device menu
129  void on_actionSelect_All_triggered();
130  void on_actionDeselect_All_triggered();
131  void on_actionDevReset_triggered();
132  void on_actionDevInit_triggered();
133  void on_actionDevEnable_triggered();
134  void on_actionDevDisable_triggered();
135  void on_actionDevSimulate_triggered();
136  void on_actionDevStopSim_triggered();
137  void on_actionDevIgnore_triggered();
138  void on_actionDevStopIgn_triggered();
139 
140  // Settings menu
141  void on_actionLoadLayout_triggered();
142  void on_actionSaveLayout_triggered();
143  void on_actionResetLayout_triggered();
144 
145  // Tools menu
146  void on_actionFCF_CLI_triggered();
147 
148  // Help menu
149  void on_actionAbout_triggered();
150  void on_actionWhatsthis_triggered();
151 
152  // Other
153  void handleSetupButton();
154  void handleDeviceSetup(QString name);
155  void handleStopButton();
156  void addLogEntry(const QString& type,
157  const QString& cmd,
158  const QString& text);
159  void updateWindowState();
160 
161  private:
162  void CreateMalInterfaces(const QString uri);
163  void GetServerConfiguration();
164  void CreateDbClient();
165  void CreateDeviceWidgets();
166  AbstractDevice* AddDeviceWidget(const std::string &devname,
167  const std::string& devtype,
168  const std::string& server_id,
169  int cmd_timeout);
170  std::vector<std::string> selectedDevices(MainWindow::Page page = MainWindow::All) const;
171  void SetFcsLogLevel(const std::string &level);
172 
173  template <class WorkerType>
174  void StartInThread(WorkerType* worker)
175  {
176  QThread* thread = new QThread;
177  worker->moveToThread(thread);
178  QObject::connect(thread, &QThread::started, worker, &WorkerType::process);
179  QObject::connect(thread, &QThread::finished, thread, &QThread::deleteLater);
180  QObject::connect(worker, &WorkerType::finished, thread, &QThread::quit);
181  QObject::connect(worker, &WorkerType::finished, worker, &WorkerType::deleteLater);
182  QObject::connect(worker, &WorkerType::LogReplyOut,
183  this, &MainWindow::addLogEntry,
184  Qt::QueuedConnection);
185  thread->start();
186  }
187 
188  void ReadSettings();
189  void WriteSettings() const;
190 
191  // Dynamic style change
192  void OnStateCurrentChanged(const StateEnum& state);
193 
194  private:
195  static const QString org_name;
196  static const QString app_name;
197  static const int update_ms;
198  static const QString lamp_type;
199  static const QString shutter_type;
200  static const QString motor_type;
201  static const QString iodev_type;
202  static const QString drot_type;
203  static const QString adc_type;
204  static const QString piezo_type;
205  static const QString actuator_type;
206  static const QString smaract_type;
207  static const QString msm_type;
208 
209  using WdgInfo = std::tuple<std::string, MainWindow::Page, AbstractDevice*>; // <devname, page, Pointer to widget>
210  using WdgInfoVec = std::vector<WdgInfo>;
211  WdgInfoVec m_wdgs;
212 
213  Ui::MainWindow* ui;
214  QLabel* m_server_connection_label;
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_
MainWindow::~MainWindow
virtual ~MainWindow() override
config.hpp
Config class header file.
AbstractDevice
Definition: abstractDevice.h:21
device.h
WDGLIB DeviceWdg class declaration file.
fcf::devmgr::common
Definition: actionMgr.cpp:29
Ui
Definition: mainwindow.hpp:7
MainWindow
Definition: mainwindow.hpp:12
MainWindow::MainWindow
MainWindow(QWidget *parent=nullptr)
Definition: mainwindow.cpp:8
fcf::devmgr::common::Config
Definition: config.hpp:56
abstractDevice.h
WDGLIB AbstractDevice class declaration file.
subscribeCmdWorker.h
MSGLIB SubscribeCmdWorker class declaration file.
MainWindow::closeEvent
void closeEvent(QCloseEvent *event) override
Definition: mainwindow.cpp:600
fcfcli.type
type
Definition: fcfcli.py:32