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 #include "HapticUnitConfigDialog.h"
26 #include <RobotAPI/gui-plugins/HapticUnitPlugin/ui_HapticUnitConfigDialog.h>
27 
32 #include <IceUtil/Time.h>
33 
34 
35 // Qt headers
36 #include <QInputDialog>
37 #include <Qt>
38 #include <QtGlobal>
39 #include <QPushButton>
40 #include <QComboBox>
41 #include <QMenu>
42 
43 namespace armarx
44 {
46  {
47  addWidget<HapticUnitWidget>();
48  }
49 
50 
52  {
53  // init gui
54  ui.setupUi(getWidget());
55  //ui.stateOpen->setChecked(true);
56  hapticObserverProxyName = "HapticUnitObserver";
57  hapticUnitProxyName = "WeissHapticUnit";
58 
59  updateTimer = new QTimer(this);
60 
61 
62 
63 
64  }
65 
66 
68  {
69  usingProxy(hapticObserverProxyName);
70  usingProxy(hapticUnitProxyName);
71 
72  }
73 
74 
76  {
77  hapticObserverProxy = getProxy<ObserverInterfacePrx>(hapticObserverProxyName);
78  weissHapticUnit = getProxy<WeissHapticUnitInterfacePrx>(hapticUnitProxyName);
79 
80  connectSlots();
81  createMatrixWidgets();
82  updateTimer->start(25); // 50 Hz
83 
84  }
85 
86 
88  {
89  updateTimer->stop();
90  }
91 
93  {
94  updateTimer->stop();
95  }
96 
97 
98  QPointer<QDialog> HapticUnitWidget::getConfigDialog(QWidget* parent)
99  {
100  if (!dialog)
101  {
102  dialog = new HapticUnitConfigDialog(parent);
103  }
104 
105  return qobject_cast<HapticUnitConfigDialog*>(dialog);
106  }
107 
108 
110  {
111 
112  }
113 
115  {
116 
117  for (std::pair<std::string, MatrixDatafieldDisplayWidget*> pair : matrixDisplays)
118  {
119  //MatrixFloatPtr matrix = VariantPtr::dynamicCast(hapticObserverProxy->getDataField(new DataFieldIdentifier(hapticObserverProxyName, pair.first, "matrix")))->get<MatrixFloat>();
120  std::string name = hapticObserverProxy->getDataField(new DataFieldIdentifier(hapticObserverProxyName, pair.first, "name"))->getString();
121  std::string deviceName = hapticObserverProxy->getDataField(new DataFieldIdentifier(hapticObserverProxyName, pair.first, "device"))->getString();
122  //float rate = hapticObserverProxy->getDataField(new DataFieldIdentifier(hapticObserverProxyName, pair.first, "rate"))->getFloat();
123  TimestampVariantPtr timestamp = VariantPtr::dynamicCast(hapticObserverProxy->getDataField(new DataFieldIdentifier(hapticObserverProxyName, pair.first, "timestamp")))->get<TimestampVariant>();
124  MatrixDatafieldDisplayWidget* matrixDisplay = pair.second;
125  matrixDisplay->setInfoOverlay(QString::fromStdString(deviceName) + ": " + QString::fromStdString(name) + "\n" + QString::fromStdString(timestamp->toTime().toDateTime()));
126  matrixDisplay->invokeUpdate();
127  }
128 
129  }
130 
132  {
133  QMenu* contextMenu = new QMenu(getWidget());
134  MatrixDatafieldDisplayWidget* matrixDisplay = qobject_cast<MatrixDatafieldDisplayWidget*>(sender());
135 
136  if (!matrixDisplay)
137  {
138  return;
139  }
140 
141  QAction* setDeviceTag = contextMenu->addAction(tr("Set Device Tag"));
142 
143  QAction* action = contextMenu->exec(matrixDisplay->mapToGlobal(point));
144 
145  std::string channelName = channelNameReverseMap.at(matrixDisplay);
146  std::string deviceName = deviceNameReverseMap.at(matrixDisplay);
147 
148  if (action == setDeviceTag)
149  {
150  std::string tag = hapticObserverProxy->getDataField(new DataFieldIdentifier(hapticObserverProxyName, channelName, "name"))->getString();
151 
152  bool ok;
153  QString newTag = QInputDialog::getText(getWidget(), tr("Set Device Tag"),
154  QString::fromStdString("New Tag for Device '" + deviceName + "'"), QLineEdit::Normal,
155  QString::fromStdString(tag), &ok);
156 
157  if (ok && !newTag.isEmpty())
158  {
159  ARMARX_IMPORTANT_S << "requesting to set new device tag for " << deviceName << ": " << newTag.toStdString();
160  weissHapticUnit->setDeviceTag(deviceName, newTag.toStdString());
161  }
162  }
163 
164  delete contextMenu;
165  }
166 
167 
168  void HapticUnitWidget::loadSettings(QSettings* settings)
169  {
170  }
171 
172 
173  void HapticUnitWidget::saveSettings(QSettings* settings)
174  {
175  }
176 
177 
179  {
180  connect(this, SIGNAL(doUpdateDisplayWidgets()), SLOT(updateDisplayWidgets()), Qt::QueuedConnection);
181  connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateData()));
182  connect(ui.checkBoxOffsetFilter, SIGNAL(stateChanged(int)), this, SLOT(onCheckBoxOffsetFilterStateChanged(int)));
183  }
184 
185  void HapticUnitWidget::createMatrixWidgets()
186  {
187  //ARMARX_LOG << "HapticUnitWidget::createMatrixWidgets()";
188  emit doUpdateDisplayWidgets();
189  }
190 
191  void HapticUnitWidget::updateDisplayWidgets()
192  {
193  QLayoutItem* child;
194 
195  while ((child = ui.gridLayoutDisplay->takeAt(0)) != 0)
196  {
197  delete child;
198  }
199 
200  int i = 0;
201  ChannelRegistry channels = hapticObserverProxy->getAvailableChannels(false);
202 
203  for (std::pair<std::string, ChannelRegistryEntry> pair : channels)
204  {
205  std::string channelName = pair.first;
206  MatrixDatafieldDisplayWidget* matrixDisplay = new MatrixDatafieldDisplayWidget(new DatafieldRef(hapticObserverProxy, channelName, "matrix"), hapticObserverProxy, getWidget());
207  matrixDisplay->setRange(0, 4095);
208  matrixDisplay->setContextMenuPolicy(Qt::CustomContextMenu);
209  connect(matrixDisplay, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onContextMenu(QPoint)));
210  matrixDisplays.insert(std::make_pair(pair.first, matrixDisplay));
211  std::string deviceName = hapticObserverProxy->getDataField(new DataFieldIdentifier(hapticObserverProxyName, channelName, "device"))->getString();
212  channelNameReverseMap.insert(std::make_pair(matrixDisplay, channelName));
213  deviceNameReverseMap.insert(std::make_pair(matrixDisplay, deviceName));
214  ui.gridLayoutDisplay->addWidget(matrixDisplay, 0, i);
215  i++;
216  }
217  }
218 
219  void HapticUnitWidget::onCheckBoxOffsetFilterStateChanged(int state)
220  {
221  //ARMARX_IMPORTANT << "onCheckBoxOffsetFilterToggled: " << state;
222  for (std::pair<std::string, MatrixDatafieldDisplayWidget*> pair : matrixDisplays)
223  {
224  pair.second->enableOffsetFilter(ui.checkBoxOffsetFilter->isChecked());
225  }
226  }
227 }
armarx::MatrixDatafieldDisplayWidget::setInfoOverlay
void setInfoOverlay(QString infoOverlay)
Definition: MatrixDatafieldDisplayWidget.h:71
ARMARX_IMPORTANT_S
#define ARMARX_IMPORTANT_S
Definition: Logging.h:203
SingleTypeVariantList.h
armarx::MatrixDatafieldDisplayWidget
Definition: MatrixDatafieldDisplayWidget.h:43
armarx::HapticUnitWidget::connectSlots
void connectSlots()
Definition: HapticUnitGuiPlugin.cpp:178
armarx::HapticUnitWidget::updateData
void updateData()
Definition: HapticUnitGuiPlugin.cpp:114
MatrixVariant.h
armarx::HapticUnitWidget::ui
Ui::HapticUnitGuiPlugin ui
Definition: HapticUnitGuiPlugin.h:109
armarx::TimestampVariant
Definition: TimestampVariant.h:54
armarx::HapticUnitWidget::getConfigDialog
QPointer< QDialog > getConfigDialog(QWidget *parent=0) override
getConfigDialog returns a pointer to the a configuration widget of this controller.
Definition: HapticUnitGuiPlugin.cpp:98
armarx::HapticUnitWidget::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: HapticUnitGuiPlugin.cpp:92
armarx::HapticUnitWidget::onContextMenu
void onContextMenu(QPoint pos)
Definition: HapticUnitGuiPlugin.cpp:131
armarx::HapticUnitWidget::configured
void configured() override
This function must be implemented by the user, if he supplies a config dialog.
Definition: HapticUnitGuiPlugin.cpp:109
armarx::HapticUnitWidget::saveSettings
void saveSettings(QSettings *settings) override
Implement to save the settings as part of the GUI configuration.
Definition: HapticUnitGuiPlugin.cpp:173
visionx::imrecman::ok
@ ok
Definition: ImageRecordingManagerInterface.ice:46
armarx::HapticUnitWidget::loadSettings
void loadSettings(QSettings *settings) override
Implement to load the settings that are part of the GUI configuration.
Definition: HapticUnitGuiPlugin.cpp:168
IceInternal::Handle< TimestampVariant >
armarx::HapticUnitWidget::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: HapticUnitGuiPlugin.cpp:75
HapticUnitConfigDialog.h
TimestampVariant.h
armarx::HapticUnitWidget::HapticUnitWidget
HapticUnitWidget()
Definition: HapticUnitGuiPlugin.cpp:51
armarx::VariantType::DatafieldRef
const VariantTypeId DatafieldRef
Definition: DatafieldRef.h:169
armarx::HapticUnitWidget::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: HapticUnitGuiPlugin.cpp:67
armarx::HapticUnitGuiPlugin::HapticUnitGuiPlugin
HapticUnitGuiPlugin()
Definition: HapticUnitGuiPlugin.cpp:45
armarx::HapticUnitWidget::doUpdateDisplayWidgets
void doUpdateDisplayWidgets()
armarx::HapticUnitWidget::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: HapticUnitGuiPlugin.cpp:87
armarx::Logging::tag
LogTag tag
Definition: Logging.h:271
armarx::ArmarXWidgetController::getWidget
virtual QPointer< QWidget > getWidget()
getWidget returns a pointer to the a widget of this controller.
Definition: ArmarXWidgetController.cpp:54
HapticUnitGuiPlugin.h
ArmarXDataPath.h
armarx::ManagedIceObject::usingProxy
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Definition: ManagedIceObject.cpp:151
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::HapticUnitConfigDialog
Definition: HapticUnitConfigDialog.h:34
armarx::DataFieldIdentifier
DataFieldIdentifier provide the basis to identify data field within a distributed ArmarX scenario.
Definition: DataFieldIdentifier.h:48