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 <IceUtil/Time.h>
27
32
33#include <RobotAPI/gui-plugins/HapticUnitPlugin/ui_HapticUnitConfigDialog.h>
34
36
37
38// Qt headers
39#include <QComboBox>
40#include <QInputDialog>
41#include <QMenu>
42#include <QPushButton>
43#include <Qt>
44#include <QtGlobal>
45
46namespace armarx
47{
52
54 {
55 // init gui
56 ui.setupUi(getWidget());
57 //ui.stateOpen->setChecked(true);
58 hapticObserverProxyName = "HapticUnitObserver";
59 hapticUnitProxyName = "WeissHapticUnit";
60
61 updateTimer = new QTimer(this);
62 }
63
64 void
66 {
67 usingProxy(hapticObserverProxyName);
68 usingProxy(hapticUnitProxyName);
69 }
70
71 void
73 {
74 hapticObserverProxy = getProxy<ObserverInterfacePrx>(hapticObserverProxyName);
75 weissHapticUnit = getProxy<WeissHapticUnitInterfacePrx>(hapticUnitProxyName);
76
78 createMatrixWidgets();
79 updateTimer->start(25); // 50 Hz
80 }
81
82 void
84 {
85 updateTimer->stop();
86 }
87
88 void
90 {
91 updateTimer->stop();
92 }
93
94 QPointer<QDialog>
96 {
97 if (!dialog)
98 {
99 dialog = new HapticUnitConfigDialog(parent);
100 }
101
102 return qobject_cast<HapticUnitConfigDialog*>(dialog);
103 }
104
105 void
109
110 void
112 {
113
114 for (std::pair<std::string, MatrixDatafieldDisplayWidget*> pair : matrixDisplays)
115 {
116 //MatrixFloatPtr matrix = VariantPtr::dynamicCast(hapticObserverProxy->getDataField(new DataFieldIdentifier(hapticObserverProxyName, pair.first, "matrix")))->get<MatrixFloat>();
117 std::string name = hapticObserverProxy
118 ->getDataField(new DataFieldIdentifier(
119 hapticObserverProxyName, pair.first, "name"))
120 ->getString();
121 std::string deviceName = hapticObserverProxy
122 ->getDataField(new DataFieldIdentifier(
123 hapticObserverProxyName, pair.first, "device"))
124 ->getString();
125 //float rate = hapticObserverProxy->getDataField(new DataFieldIdentifier(hapticObserverProxyName, pair.first, "rate"))->getFloat();
127 VariantPtr::dynamicCast(hapticObserverProxy->getDataField(new DataFieldIdentifier(
128 hapticObserverProxyName, pair.first, "timestamp")))
129 ->get<TimestampVariant>();
130 MatrixDatafieldDisplayWidget* matrixDisplay = pair.second;
131 matrixDisplay->setInfoOverlay(QString::fromStdString(deviceName) + ": " +
132 QString::fromStdString(name) + "\n" +
133 QString::fromStdString(timestamp->toTime().toDateTime()));
134 matrixDisplay->invokeUpdate();
135 }
136 }
137
138 void
140 {
141 QMenu* contextMenu = new QMenu(getWidget());
142 MatrixDatafieldDisplayWidget* matrixDisplay =
143 qobject_cast<MatrixDatafieldDisplayWidget*>(sender());
144
145 if (!matrixDisplay)
146 {
147 return;
148 }
149
150 QAction* setDeviceTag = contextMenu->addAction(tr("Set Device Tag"));
151
152 QAction* action = contextMenu->exec(matrixDisplay->mapToGlobal(point));
153
154 std::string channelName = channelNameReverseMap.at(matrixDisplay);
155 std::string deviceName = deviceNameReverseMap.at(matrixDisplay);
156
157 if (action == setDeviceTag)
158 {
159 std::string tag = hapticObserverProxy
160 ->getDataField(new DataFieldIdentifier(
161 hapticObserverProxyName, channelName, "name"))
162 ->getString();
163
164 bool ok;
165 QString newTag = QInputDialog::getText(
166 getWidget(),
167 tr("Set Device Tag"),
168 QString::fromStdString("New Tag for Device '" + deviceName + "'"),
169 QLineEdit::Normal,
170 QString::fromStdString(tag),
171 &ok);
172
173 if (ok && !newTag.isEmpty())
174 {
175 ARMARX_IMPORTANT_S << "requesting to set new device tag for " << deviceName << ": "
176 << newTag.toStdString();
177 weissHapticUnit->setDeviceTag(deviceName, newTag.toStdString());
178 }
179 }
180
181 delete contextMenu;
182 }
183
184 void
186 {
187 }
188
189 void
191 {
192 }
193
194 void
196 {
197 connect(this,
198 SIGNAL(doUpdateDisplayWidgets()),
199 SLOT(updateDisplayWidgets()),
200 Qt::QueuedConnection);
201 connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateData()));
202 connect(ui.checkBoxOffsetFilter,
203 SIGNAL(stateChanged(int)),
204 this,
205 SLOT(onCheckBoxOffsetFilterStateChanged(int)));
206 }
207
208 void
209 HapticUnitWidget::createMatrixWidgets()
210 {
211 //ARMARX_LOG << "HapticUnitWidget::createMatrixWidgets()";
213 }
214
215 void
216 HapticUnitWidget::updateDisplayWidgets()
217 {
218 QLayoutItem* child;
219
220 while ((child = ui.gridLayoutDisplay->takeAt(0)) != 0)
221 {
222 delete child;
223 }
224
225 int i = 0;
226 ChannelRegistry channels = hapticObserverProxy->getAvailableChannels(false);
227
228 for (std::pair<std::string, ChannelRegistryEntry> pair : channels)
229 {
230 std::string channelName = pair.first;
231 MatrixDatafieldDisplayWidget* matrixDisplay = new MatrixDatafieldDisplayWidget(
232 new DatafieldRef(hapticObserverProxy, channelName, "matrix"),
233 hapticObserverProxy,
234 getWidget());
235 matrixDisplay->setRange(0, 4095);
236 matrixDisplay->setContextMenuPolicy(Qt::CustomContextMenu);
237 connect(matrixDisplay,
238 SIGNAL(customContextMenuRequested(QPoint)),
239 this,
240 SLOT(onContextMenu(QPoint)));
241 matrixDisplays.insert(std::make_pair(pair.first, matrixDisplay));
242 std::string deviceName = hapticObserverProxy
243 ->getDataField(new DataFieldIdentifier(
244 hapticObserverProxyName, channelName, "device"))
245 ->getString();
246 channelNameReverseMap.insert(std::make_pair(matrixDisplay, channelName));
247 deviceNameReverseMap.insert(std::make_pair(matrixDisplay, deviceName));
248 ui.gridLayoutDisplay->addWidget(matrixDisplay, 0, i);
249 i++;
250 }
251 }
252
253 void
254 HapticUnitWidget::onCheckBoxOffsetFilterStateChanged(int state)
255 {
256 //ARMARX_IMPORTANT << "onCheckBoxOffsetFilterToggled: " << state;
257 for (std::pair<std::string, MatrixDatafieldDisplayWidget*> pair : matrixDisplays)
258 {
259 pair.second->enableOffsetFilter(ui.checkBoxOffsetFilter->isChecked());
260 }
261 }
262} // 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.
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.
Ui::HapticUnitGuiPlugin ui
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:210
const VariantTypeId DatafieldRef
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< TimestampVariant > TimestampVariantPtr