RobotUnitPluginWidgetController.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package RobotAPI::gui-plugins::RobotUnitPluginWidgetController
17  * @author Raphael Grimm ( raphael dot grimm at kit dot edu )
18  * @date 2017
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
25 #include <RobotAPI/gui-plugins/RobotUnitPlugin/ui_RobotUnitPluginWidget.h>
26 
27 #include <mutex>
28 #include <map>
29 #include <string>
30 #include <chrono>
31 #include <fstream>
32 
33 #include <QWidget>
34 #include <QPushButton>
35 #include <QTreeWidget>
36 #include <QTreeWidgetItem>
37 #include <QPointer>
38 #include <QToolBar>
39 #include <QGroupBox>
40 
43 
46 
47 #include <RobotAPI/interface/units/RobotUnit/RobotUnitInterface.h>
50 
51 #include "../QWidgets/NJointControllerClassesWidget.h"
52 #include "../QWidgets/NJointControllersWidget.h"
53 #include "../QWidgets/ControlDevicesWidget.h"
54 #include "../QWidgets/SensorDevicesWidget.h"
55 
56 namespace armarx
57 {
58  /**
59  \page RobotAPI-GuiPlugins-RobotUnitPlugin RobotUnitPlugin
60  \brief The RobotUnitPlugin allows visualizing ...
61 
62  \image html RobotUnitPlugin.png
63  The user can
64 
65  API Documentation \ref RobotUnitPluginWidgetController
66 
67  \see RobotUnitPluginGuiPlugin
68  */
69 
70  /**
71  * \class RobotUnitPluginWidgetController
72  * \brief RobotUnitPluginWidgetController brief one line description
73  *
74  * Detailed description
75  */
77  public ArmarXComponentWidgetControllerTemplate<RobotUnitPluginWidgetController>,
78  public RobotUnitListener
79  {
80  Q_OBJECT
81  public:
82  /// @brief Controller Constructor
84 
85  /// @see ArmarXWidgetController::loadSettings()
86  void loadSettings(QSettings* settings) override;
87 
88  /// @see ArmarXWidgetController::saveSettings()
89  void saveSettings(QSettings* settings) override;
90 
91  /// @brief Returns the Widget name displayed in the ArmarXGui to create an instance of this class.
92  static QString GetWidgetName()
93  {
94  return "RobotControl.RobotUnitGUI";
95  }
96 
97  /// @see armarx::Component::onInitComponent()
98  void onInitComponent() override;
99 
100  /// @see armarx::Component::onConnectComponent()
101  void onConnectComponent() override;
102 
103  void onDisconnectComponent() override;
104  void onExitComponent() override;
105  /**
106  * @param parent The dialog's parent.
107  * @return The plugin's config dialog.
108  */
109  QPointer<QDialog> getConfigDialog(QWidget* parent) override;
110 
111  /// @brief Callback called when the config dialog is closed.
112  void configured() override;
113 
114  static QIcon GetWidgetIcon()
115  {
116  return QIcon(":/robotunitplugin/icons/robot_unit_icon.svg");
117  }
118  static QIcon GetWidgetCategoryIcon()
119  {
120  return QIcon(":/robotunitplugin/icons/robot_unit_icon.svg");
121  }
122  QPointer<QWidget> getCustomTitlebarWidget(QWidget* parent) override;
123 
124  // RobotUnitListener interface
125  public:
126  void nJointControllerStatusChanged(const NJointControllerStatusSeq& status, const Ice::Current&) override;
127  void controlDeviceStatusChanged(const ControlDeviceStatusSeq& status, const Ice::Current&) override;
128  void sensorDeviceStatusChanged(const SensorDeviceStatusSeq& status, const Ice::Current&) override;
129  void nJointControllerClassAdded(const std::string& name, const Ice::Current&) override;
130  void nJointControllerCreated(const std::string& name, const Ice::Current&) override;
131  void nJointControllerDeleted(const std::string& name, const Ice::Current&) override;
132 
133  private slots:
134  void refreshNJointControllersClicked();
135  void refreshNJointControllerClassesClicked();
136  void refreshControlDevicesClicked();
137  void refreshSensorDevicesClicked();
138  void refreshLogging();
139 
140  void startOnConnectTimer();
141  void stopOnConnectTimer();
142 
143  //logging
144  void on_lineEditLoggingFilter_textChanged(const QString& arg1);
145  void on_pushButtonLoggingStop_clicked();
146  void on_pushButtonLoggingStart_clicked();
147  void on_treeWidgetLoggingNames_itemChanged(QTreeWidgetItem* item, int column);
148  void on_pushButtonLoggingMark1_clicked();
149  void on_pushButtonLoggingMark2_clicked();
150  void on_pushButtonLoggingMark3_clicked();
151 
152  private:
153  void timerEvent(QTimerEvent*) override;
154  void updateToolBarActionCheckedState();
155 
156  private:
157  /// @brief Widget Form
158  Ui::RobotUnitPluginWidget widget;
159  /// @brief The plugin's config dialog.
160  QPointer<SimpleConfigDialog> dialog;
161 
162  std::string robotUnitProxyName;
163  std::recursive_mutex robotUnitPrxMutex;
164  RobotUnitInterfacePrx robotUnitPrx;
165  std::string listenerTopicName;
166 
167  NJointControllerClassesWidget* nJointControllerClasses;
168  NJointControllersWidget* nJointControllers;
169  ControlDevicesWidget* controlDevices;
170  SensorDevicesWidget* sensorDevices;
171 
172  QPointer<QToolBar> customToolbar;
173 
174  QPointer<QAction> showCDevs;
175  QPointer<QAction> showSDevs;
176  QPointer<QAction> showNJoint;
177  QPointer<QAction> showNJointClasses;
178  QPointer<QAction> showLogging;
179 
180  struct LoggingData
181  {
182  QTreeWidgetItem* top;
183  std::vector<QTreeWidgetItem*> allItems;
184  SimpleRemoteReferenceCounterBasePtr handle;
185  RobotUnitDataStreamingReceiverPtr streamingHandler;
186  std::ofstream logStream;
187  static void updateCheckStateUpward(QTreeWidgetItem* item, bool recurseParents);
188  static void updateCheckStateDownward(QTreeWidgetItem* item, Qt::CheckState state, bool recurseChildren);
189  void localLogging();
190  };
191  LoggingData loggingData;
192 
193  int timerId = 0;
194  std::atomic_bool timerLastIterationRuWasRunning = false;
195  };
196 }
197 
armarx::RobotUnitDataStreamingReceiverPtr
std::shared_ptr< class RobotUnitDataStreamingReceiver > RobotUnitDataStreamingReceiverPtr
Definition: RobotUnitReader.h:30
armarx::SensorDevicesWidget
Definition: SensorDevicesWidget.h:49
armarx::RobotUnitPluginWidgetController
RobotUnitPluginWidgetController brief one line description.
Definition: RobotUnitPluginWidgetController.h:76
RobotAPIVariantWidget.h
armarx::RobotUnitPluginWidgetController::GetWidgetName
static QString GetWidgetName()
Returns the Widget name displayed in the ArmarXGui to create an instance of this class.
Definition: RobotUnitPluginWidgetController.h:92
armarx::ArmarXComponentWidgetControllerTemplate
Definition: ArmarXComponentWidgetController.h:69
SimpleConfigDialog.h
armarx::ControlDevicesWidget
Definition: ControlDevicesWidget.h:50
armarx::NJointControllersWidget
Definition: NJointControllersWidget.h:53
ArmarXGuiPlugin.h
RobotUnitDataStreamingReceiver.h
armarx::status
status
Definition: FiniteStateMachine.h:259
ArmarXComponentWidgetController.h
ARMARXCOMPONENT_IMPORT_EXPORT
#define ARMARXCOMPONENT_IMPORT_EXPORT
Definition: ImportExportComponent.h:38
armarx::RobotUnitPluginWidgetController::GetWidgetCategoryIcon
static QIcon GetWidgetCategoryIcon()
Definition: RobotUnitPluginWidgetController.h:118
armarx::NJointControllerClassesWidget
Definition: NJointControllerClassesWidget.h:51
IceInternal::ProxyHandle<::IceProxy::armarx::RobotUnitInterface >
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::RobotUnitPluginWidgetController::GetWidgetIcon
static QIcon GetWidgetIcon()
Definition: RobotUnitPluginWidgetController.h:114
ImportExportComponent.h