toolbox_widget.h
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * Software License Agreement
4  *
5  * Copyright (c) 2020,
6  * TU Dortmund - Institute of Control Theory and Systems Engineering.
7  * All rights reserved.
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  *
22  * Authors: Christoph Rösmann
23  *********************************************************************/
24 
25 #ifndef SRC_GUI_INCLUDE_CORBO_GUI_TOOLBOX_WIDGET_H_
26 #define SRC_GUI_INCLUDE_CORBO_GUI_TOOLBOX_WIDGET_H_
27 
29 #include <corbo-communication/messages/corbo_parameters.pb.h>
33 
34 #include <QDateTime>
35 #include <QPushButton>
36 #include <QString>
37 #include <QThread>
38 #include <QToolBox>
39 #include <QVector>
40 
41 #include <memory>
42 
43 namespace corbo {
44 namespace gui {
45 
46 class ToolboxWidget : public QWidget
47 {
48  Q_OBJECT
49 
50  public:
51  explicit ToolboxWidget(SignalHelper::Ptr signal_helper, std::shared_ptr<MasterServiceClient> rpc, QWidget* parent = 0);
52  virtual ~ToolboxWidget();
53 
54  QSize sizeHint() const override;
55 
56  QVector<ParameterWidget*> getParameterWidgets() { return _param_widgets; }
57 
58  void setSignalAutoRequest(bool active) { _signal_auto_update = active; }
59 
60  void setRpcClient(std::shared_ptr<MasterServiceClient> rpc_client);
61 
62  void fromMessage(const google::protobuf::Message& parameters);
63  void toMessage(google::protobuf::Message& parameters) const;
64 
65  void clearParameters();
66 
67  signals:
68  void taskCompleted(const QDateTime& time);
69  void parameterLoadedFromFile(const QString& filename);
70  void parameterSavedToFile(const QString& filename);
71 
72  public slots:
73  void getAvailableSignals();
75  void restoreTaskParameters(int task_id);
76  void removeFromTaskCache(int task_id);
78  void saveParametersToFile(int task_id);
80  void loadParametersFromFile(const QString& filepath);
81 
82  protected:
83  void createToolboxContent();
84  void initializeToolboxes();
86  bool sendParametersToService(bool suppress_warning = false);
87  void saveParametersToFile(const google::protobuf::Message& params);
88 
89  void setTaskRunningFlag(bool running);
90 
91  protected slots:
92  void performTask();
93  void rpcTaskFinished(bool success, const QString& msg);
94 
95  private:
96  QToolBox* _toolbox;
97  QPushButton* _btn_perform_task;
98 
99  std::unique_ptr<google::protobuf::Message> _param_message;
100  QVector<ParameterWidget*> _param_widgets;
101 
103  ParameterCache _task_cache; // caches paramters that belongs to a single task run
104 
106  std::shared_ptr<MasterServiceClient> _rpc_client;
107 
108  bool _signal_auto_update = false; // this should be false for the initial messages parsing, but enabled afterwards
109 
111  bool _task_running = false;
112 
113  const QString _task_button_label_active = "Perform Task";
114  const QString _task_button_label_inactive = "Stop Task";
115 };
116 
117 } // namespace gui
118 } // namespace corbo
119 
120 #endif // SRC_GUI_INCLUDE_CORBO_GUI_TOOLBOX_WIDGET_H_
void toMessage(google::protobuf::Message &parameters) const
bool sendParametersToService(bool suppress_warning=false)
ToolboxWidget(SignalHelper::Ptr signal_helper, std::shared_ptr< MasterServiceClient > rpc, QWidget *parent=0)
void parameterLoadedFromFile(const QString &filename)
void saveParametersToFile(int task_id)
void setRpcClient(std::shared_ptr< MasterServiceClient > rpc_client)
std::shared_ptr< SignalHelper > Ptr
Definition: signal_helper.h:45
void fromMessage(const google::protobuf::Message &parameters)
const QString _task_button_label_active
void rpcTaskFinished(bool success, const QString &msg)
QSize sizeHint() const override
QPushButton * _btn_perform_task
void restoreTaskParameters(int task_id)
std::shared_ptr< MasterServiceClient > _rpc_client
void taskCompleted(const QDateTime &time)
void setSignalAutoRequest(bool active)
void removeFromTaskCache(int task_id)
void setTaskRunningFlag(bool running)
bool _task_running
Keep track if a task is currently running.
void parameterSavedToFile(const QString &filename)
const QString _task_button_label_inactive
SignalHelper::Ptr _signal_helper
std::unique_ptr< google::protobuf::Message > _param_message
Internal cache of the current parameter setting/message.
QVector< ParameterWidget * > _param_widgets
QVector< ParameterWidget * > getParameterWidgets()


control_box_rst
Author(s): Christoph Rösmann
autogenerated on Mon Feb 28 2022 22:07:52