HapticUnitGuiPlugin.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package
19 * @author
20 * @date
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24#include "HapticUnitGuiPlugin.h"
25
26#include <RobotAPI/gui-plugins/HapticUnitPlugin/ui_HapticUnitGuiPlugin.h>
27
28#include <IceUtil/Time.h>
29
34
35#include <RobotAPI/gui-plugins/HapticUnitPlugin/ui_HapticUnitConfigDialog.h>
36
38
39
40// Qt headers
41#include <QComboBox>
42#include <QInputDialog>
43#include <QMenu>
44#include <QPushButton>
45#include <Qt>
46#include <QtGlobal>
47
48namespace armarx
49{
54
56
58 {
59 // init gui
60 ui = std::make_unique<Ui::HapticUnitGuiPlugin>();
61 ui->setupUi(getWidget());
62 //ui->stateOpen->setChecked(true);
63 hapticObserverProxyName = "HapticUnitObserver";
64 hapticUnitProxyName = "WeissHapticUnit";
65
66 updateTimer = new QTimer(this);
67 }
68
69 void
71 {
72 usingProxy(hapticObserverProxyName);
73 usingProxy(hapticUnitProxyName);
74 }
75
76 void
78 {
79 hapticObserverProxy = getProxy<ObserverInterfacePrx>(hapticObserverProxyName);
80 weissHapticUnit = getProxy<WeissHapticUnitInterfacePrx>(hapticUnitProxyName);
81
83 createMatrixWidgets();
84 updateTimer->start(25); // 50 Hz
85 }
86
87 void
89 {
90 updateTimer->stop();
91 }
92
93 void
95 {
96 updateTimer->stop();
97 }
98
99 QPointer<QDialog>
101 {
102 if (!dialog)
103 {
104 dialog = new HapticUnitConfigDialog(parent);
105 }
106
107 return qobject_cast<HapticUnitConfigDialog*>(dialog);
108 }
109
110 void
114
115 void
117 {
118
119 for (std::pair<std::string, MatrixDatafieldDisplayWidget*> pair : matrixDisplays)
120 {
121 //MatrixFloatPtr matrix = VariantPtr::dynamicCast(hapticObserverProxy->getDataField(new DataFieldIdentifier(hapticObserverProxyName, pair.first, "matrix")))->get<MatrixFloat>();
122 std::string name = hapticObserverProxy
123 ->getDataField(new DataFieldIdentifier(
124 hapticObserverProxyName, pair.first, "name"))
125 ->getString();
126 std::string deviceName = hapticObserverProxy
127 ->getDataField(new DataFieldIdentifier(
128 hapticObserverProxyName, pair.first, "device"))
129 ->getString();
130 //float rate = hapticObserverProxy->getDataField(new DataFieldIdentifier(hapticObserverProxyName, pair.first, "rate"))->getFloat();
132 VariantPtr::dynamicCast(hapticObserverProxy->getDataField(new DataFieldIdentifier(
133 hapticObserverProxyName, pair.first, "timestamp")))
134 ->get<TimestampVariant>();
135 MatrixDatafieldDisplayWidget* matrixDisplay = pair.second;
136 matrixDisplay->setInfoOverlay(QString::fromStdString(deviceName) + ": " +
137 QString::fromStdString(name) + "\n" +
138 QString::fromStdString(timestamp->toTime().toDateTime()));
139 matrixDisplay->invokeUpdate();
140 }
141 }
142
143 void
145 {
146 QMenu* contextMenu = new QMenu(getWidget());
147 MatrixDatafieldDisplayWidget* matrixDisplay =
148 qobject_cast<MatrixDatafieldDisplayWidget*>(sender());
149
150 if (!matrixDisplay)
151 {
152 return;
153 }
154
155 QAction* setDeviceTag = contextMenu->addAction(tr("Set Device Tag"));
156
157 QAction* action = contextMenu->exec(matrixDisplay->mapToGlobal(point));
158
159 std::string channelName = channelNameReverseMap.at(matrixDisplay);
160 std::string deviceName = deviceNameReverseMap.at(matrixDisplay);
161
162 if (action == setDeviceTag)
163 {
164 std::string tag = hapticObserverProxy
165 ->getDataField(new DataFieldIdentifier(
166 hapticObserverProxyName, channelName, "name"))
167 ->getString();
168
169 bool ok;
170 QString newTag = QInputDialog::getText(
171 getWidget(),
172 tr("Set Device Tag"),
173 QString::fromStdString("New Tag for Device '" + deviceName + "'"),
174 QLineEdit::Normal,
175 QString::fromStdString(tag),
176 &ok);
177
178 if (ok && !newTag.isEmpty())
179 {
180 ARMARX_IMPORTANT_S << "requesting to set new device tag for " << deviceName << ": "
181 << newTag.toStdString();
182 weissHapticUnit->setDeviceTag(deviceName, newTag.toStdString());
183 }
184 }
185
186 delete contextMenu;
187 }
188
189 void
191 {
192 }
193
194 void
196 {
197 }
198
199 void
201 {
202 connect(this,
203 SIGNAL(doUpdateDisplayWidgets()),
204 SLOT(updateDisplayWidgets()),
205 Qt::QueuedConnection);
206 connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateData()));
207 connect(ui->checkBoxOffsetFilter,
208 SIGNAL(stateChanged(int)),
209 this,
210 SLOT(onCheckBoxOffsetFilterStateChanged(int)));
211 }
212
213 void
214 HapticUnitWidget::createMatrixWidgets()
215 {
216 //ARMARX_LOG << "HapticUnitWidget::createMatrixWidgets()";
218 }
219
220 void
221 HapticUnitWidget::updateDisplayWidgets()
222 {
223 QLayoutItem* child;
224
225 while ((child = ui->gridLayoutDisplay->takeAt(0)) != 0)
226 {
227 delete child;
228 }
229
230 int i = 0;
231 ChannelRegistry channels = hapticObserverProxy->getAvailableChannels(false);
232
233 for (std::pair<std::string, ChannelRegistryEntry> pair : channels)
234 {
235 std::string channelName = pair.first;
236 MatrixDatafieldDisplayWidget* matrixDisplay = new MatrixDatafieldDisplayWidget(
237 new DatafieldRef(hapticObserverProxy, channelName, "matrix"),
238 hapticObserverProxy,
239 getWidget());
240 matrixDisplay->setRange(0, 4095);
241 matrixDisplay->setContextMenuPolicy(Qt::CustomContextMenu);
242 connect(matrixDisplay,
243 SIGNAL(customContextMenuRequested(QPoint)),
244 this,
245 SLOT(onContextMenu(QPoint)));
246 matrixDisplays.insert(std::make_pair(pair.first, matrixDisplay));
247 std::string deviceName = hapticObserverProxy
248 ->getDataField(new DataFieldIdentifier(
249 hapticObserverProxyName, channelName, "device"))
250 ->getString();
251 channelNameReverseMap.insert(std::make_pair(matrixDisplay, channelName));
252 deviceNameReverseMap.insert(std::make_pair(matrixDisplay, deviceName));
253 ui->gridLayoutDisplay->addWidget(matrixDisplay, 0, i);
254 i++;
255 }
256 }
257
258 void
259 HapticUnitWidget::onCheckBoxOffsetFilterStateChanged(int state)
260 {
261 //ARMARX_IMPORTANT << "onCheckBoxOffsetFilterToggled: " << state;
262 for (std::pair<std::string, MatrixDatafieldDisplayWidget*> pair : matrixDisplays)
263 {
264 pair.second->enableOffsetFilter(ui->checkBoxOffsetFilter->isChecked());
265 }
266 }
267} // namespace armarx
std::string timestamp()
std::enable_if<!HasGetWidgetName< ArmarXWidgetType >::value >::type addWidget()
virtual QPointer< QWidget > getWidget()
getWidget returns a pointer to the a widget of this controller.
DataFieldIdentifier provide the basis to identify data field within a distributed ArmarX scenario.
void onInitComponent() override
Pure virtual hook for the subclass.
void onDisconnectComponent() override
Hook for subclass.
void loadSettings(QSettings *settings) override
Implement to load the settings that are part of the GUI configuration.
void saveSettings(QSettings *settings) override
Implement to save the settings as part of the GUI configuration.
std::unique_ptr< Ui::HapticUnitGuiPlugin > ui
QPointer< QDialog > getConfigDialog(QWidget *parent=0) override
getConfigDialog returns a pointer to the a configuration widget of this controller.
void onConnectComponent() override
Pure virtual hook for the subclass.
void configured() override
This function must be implemented by the user, if he supplies a config dialog.
void onExitComponent() override
Hook for subclass.
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
Implements a Variant type for timestamps.
#define ARMARX_IMPORTANT_S
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:208
const VariantTypeId DatafieldRef
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< TimestampVariant > TimestampVariantPtr