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 <chrono>
26 #include <fstream>
27 #include <map>
28 #include <mutex>
29 #include <string>
30 
31 #include <QGroupBox>
32 #include <QPointer>
33 #include <QPushButton>
34 #include <QToolBar>
35 #include <QTreeWidget>
36 #include <QTreeWidgetItem>
37 #include <QWidget>
38 
40 
44 
45 #include <RobotAPI/gui-plugins/RobotUnitPlugin/ui_RobotUnitPluginWidget.h>
46 #include <RobotAPI/interface/units/RobotUnit/RobotUnitInterface.h>
49 
50 #include "../QWidgets/ControlDevicesWidget.h"
51 #include "../QWidgets/NJointControllerClassesWidget.h"
52 #include "../QWidgets/NJointControllersWidget.h"
53 #include "../QWidgets/SensorDevicesWidget.h"
54 
55 namespace armarx
56 {
57  /**
58  \page RobotAPI-GuiPlugins-RobotUnitPlugin RobotUnitPlugin
59  \brief The RobotUnitPlugin allows visualizing ...
60 
61  \image html RobotUnitPlugin.png
62  The user can
63 
64  API Documentation \ref RobotUnitPluginWidgetController
65 
66  \see RobotUnitPluginGuiPlugin
67  */
68 
69  /**
70  * \class RobotUnitPluginWidgetController
71  * \brief RobotUnitPluginWidgetController brief one line description
72  *
73  * Detailed description
74  */
76  public ArmarXComponentWidgetControllerTemplate<RobotUnitPluginWidgetController>,
77  public RobotUnitListener
78  {
79  Q_OBJECT
80  public:
81  /// @brief Controller Constructor
83 
84  /// @see ArmarXWidgetController::loadSettings()
85  void loadSettings(QSettings* settings) override;
86 
87  /// @see ArmarXWidgetController::saveSettings()
88  void saveSettings(QSettings* settings) override;
89 
90  /// @brief Returns the Widget name displayed in the ArmarXGui to create an instance of this class.
91  static QString
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
116  {
117  return QIcon(":/robotunitplugin/icons/robot_unit_icon.svg");
118  }
119 
120  static QIcon
122  {
123  return QIcon(":/robotunitplugin/icons/robot_unit_icon.svg");
124  }
125 
126  QPointer<QWidget> getCustomTitlebarWidget(QWidget* parent) override;
127 
128  // RobotUnitListener interface
129  public:
130  void nJointControllerStatusChanged(const NJointControllerStatusSeq& status,
131  const Ice::Current&) override;
132  void controlDeviceStatusChanged(const ControlDeviceStatusSeq& status,
133  const Ice::Current&) override;
134  void sensorDeviceStatusChanged(const SensorDeviceStatusSeq& status,
135  const Ice::Current&) override;
136  void nJointControllerClassAdded(const std::string& name, const Ice::Current&) override;
137  void nJointControllerCreated(const std::string& name, const Ice::Current&) override;
138  void nJointControllerDeleted(const std::string& name, const Ice::Current&) override;
139 
140  private slots:
141  void refreshNJointControllersClicked();
142  void refreshNJointControllerClassesClicked();
143  void refreshControlDevicesClicked();
144  void refreshSensorDevicesClicked();
145  void refreshLogging();
146 
147  void startOnConnectTimer();
148  void stopOnConnectTimer();
149 
150  //logging
151  void on_lineEditLoggingFilter_textChanged(const QString& arg1);
152  void on_pushButtonLoggingStop_clicked();
153  void on_pushButtonLoggingStart_clicked();
154  void on_treeWidgetLoggingNames_itemChanged(QTreeWidgetItem* item, int column);
155  void on_pushButtonLoggingMark1_clicked();
156  void on_pushButtonLoggingMark2_clicked();
157  void on_pushButtonLoggingMark3_clicked();
158 
159  private:
160  void timerEvent(QTimerEvent*) override;
161  void updateToolBarActionCheckedState();
162 
163  private:
164  /// @brief Widget Form
165  Ui::RobotUnitPluginWidget widget;
166  /// @brief The plugin's config dialog.
167  QPointer<SimpleConfigDialog> dialog;
168 
169  std::string robotUnitProxyName;
170  std::recursive_mutex robotUnitPrxMutex;
171  RobotUnitInterfacePrx robotUnitPrx;
172  std::string listenerTopicName;
173 
174  NJointControllerClassesWidget* nJointControllerClasses;
175  NJointControllersWidget* nJointControllers;
176  ControlDevicesWidget* controlDevices;
177  SensorDevicesWidget* sensorDevices;
178 
179  QPointer<QToolBar> customToolbar;
180 
181  QPointer<QAction> showCDevs;
182  QPointer<QAction> showSDevs;
183  QPointer<QAction> showNJoint;
184  QPointer<QAction> showNJointClasses;
185  QPointer<QAction> showLogging;
186 
187  struct LoggingData
188  {
189  QTreeWidgetItem* top;
190  std::vector<QTreeWidgetItem*> allItems;
191  SimpleRemoteReferenceCounterBasePtr handle;
192  RobotUnitDataStreamingReceiverPtr streamingHandler;
193  std::ofstream logStream;
194  static void updateCheckStateUpward(QTreeWidgetItem* item, bool recurseParents);
195  static void updateCheckStateDownward(QTreeWidgetItem* item,
196  Qt::CheckState state,
197  bool recurseChildren);
198  void localLogging();
199  };
200 
201  LoggingData loggingData;
202 
203  int timerId = 0;
204  std::atomic_bool timerLastIterationRuWasRunning = false;
205  };
206 } // namespace armarx
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:75
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:51
armarx::NJointControllersWidget
Definition: NJointControllersWidget.h:55
ArmarXGuiPlugin.h
RobotUnitDataStreamingReceiver.h
armarx::status
status
Definition: FiniteStateMachine.h:244
ArmarXComponentWidgetController.h
ARMARXCOMPONENT_IMPORT_EXPORT
#define ARMARXCOMPONENT_IMPORT_EXPORT
Definition: ImportExportComponent.h:38
armarx::RobotUnitPluginWidgetController::GetWidgetCategoryIcon
static QIcon GetWidgetCategoryIcon()
Definition: RobotUnitPluginWidgetController.h:121
armarx::NJointControllerClassesWidget
Definition: NJointControllerClassesWidget.h:52
IceInternal::ProxyHandle<::IceProxy::armarx::RobotUnitInterface >
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::RobotUnitPluginWidgetController::GetWidgetIcon
static QIcon GetWidgetIcon()
Definition: RobotUnitPluginWidgetController.h:115
ImportExportComponent.h