RobotUnitPluginWidgetController.cpp
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 
24 #include "../QWidgets/StyleSheets.h"
25 
26 #include <string>
27 #include <regex>
28 #include <filesystem>
29 
30 #include <QDir>
31 #include <QSortFilterProxyModel>
32 #include <QAction>
33 
37 
38 using namespace armarx;
39 
41 {
42  widget.setupUi(getWidget());
43 
44  //add subwidget ControlDevices
45  {
46  controlDevices = new ControlDevicesWidget;
47  widget.groupBoxCDev->layout()->addWidget(controlDevices);
48  widget.groupBoxCDev->setVisible(false);
49  controlDevices->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
50  controlDevices->setVisible(false);
51  }
52  //add subwidget SensorDevices
53  {
54  sensorDevices = new SensorDevicesWidget;
55  widget.groupBoxSDev->layout()->addWidget(sensorDevices);
56  widget.groupBoxSDev->setVisible(false);
57  sensorDevices->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
58  sensorDevices->setVisible(false);
59  }
60  //add subwidget NJointControllers
61  {
62  nJointControllers = new NJointControllersWidget;
63  widget.groupBoxNJointCtrl->layout()->addWidget(nJointControllers);
64  widget.groupBoxNJointCtrl->setVisible(true);
65  nJointControllers->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
66  nJointControllers->setVisible(true);
67  }
68  //add subwidget NJointControllerClasses
69  {
70  nJointControllerClasses = new NJointControllerClassesWidget;
71  widget.groupBoxNJointCtrlClasses->layout()->addWidget(nJointControllerClasses);
72  widget.groupBoxNJointCtrlClasses->setVisible(false);
73  nJointControllerClasses->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
74  nJointControllerClasses->setVisible(false);
75  }
76  //update logging
77  {
78  widget.groupBoxLogging->setVisible(false);
79  widget.groupBoxLogging->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
80 
81  connect(widget.pushButtonLoggingStart, SIGNAL(clicked()), this, SLOT(on_pushButtonLoggingStart_clicked()));
82  connect(widget.pushButtonLoggingStop, SIGNAL(clicked()), this, SLOT(on_pushButtonLoggingStop_clicked()));
83  connect(widget.pushButtonLoggingMark1, SIGNAL(clicked()), this, SLOT(on_pushButtonLoggingMark1_clicked()));
84  connect(widget.pushButtonLoggingMark2, SIGNAL(clicked()), this, SLOT(on_pushButtonLoggingMark2_clicked()));
85  connect(widget.pushButtonLoggingMark3, SIGNAL(clicked()), this, SLOT(on_pushButtonLoggingMark3_clicked()));
86  connect(widget.lineEditLoggingFilter, SIGNAL(textChanged(const QString&)),
87  this, SLOT(on_lineEditLoggingFilter_textChanged(const QString&)));
88  connect(widget.treeWidgetLoggingNames, SIGNAL(itemChanged(QTreeWidgetItem*, int)),
89  this, SLOT(on_treeWidgetLoggingNames_itemChanged(QTreeWidgetItem*, int)));
90  }
91  updateToolBarActionCheckedState();
92 }
93 
94 
96 {
97  robotUnitProxyName = settings->value("robotUnitProxyName", QString::fromStdString(robotUnitProxyName)).toString().toStdString();
98  nJointControllerClasses->loadSettings(settings);
99  nJointControllers->loadSettings(settings);
100  controlDevices->loadSettings(settings);
101  sensorDevices->loadSettings(settings);
102  widget.groupBoxCDev->setVisible(settings->value("cdevVisible", false).toBool());
103  widget.groupBoxSDev->setVisible(settings->value("sdevVisible", false).toBool());
104  widget.groupBoxNJointCtrl->setVisible(settings->value("ctrlVisible", true).toBool());
105  widget.groupBoxNJointCtrlClasses->setVisible(settings->value("classVisible", false).toBool());
106  updateToolBarActionCheckedState();
107 }
108 
110 {
111  settings->setValue("robotUnitProxyName", QString::fromStdString(robotUnitProxyName));
112  nJointControllerClasses->saveSettings(settings);
113  nJointControllers->saveSettings(settings);
114  controlDevices->saveSettings(settings);
115  sensorDevices->saveSettings(settings);
116  settings->setValue("cdevVisible", widget.groupBoxCDev->isVisible());
117  settings->setValue("sdevVisible", widget.groupBoxSDev->isVisible());
118  settings->setValue("ctrlVisible", widget.groupBoxNJointCtrl->isVisible());
119  settings->setValue("classVisible", widget.groupBoxNJointCtrlClasses->isVisible());
120 }
121 
123 {
124  usingProxy(robotUnitProxyName);
125  ARMARX_INFO << "RobotUnitPluginWidgetController::onInitComponent()" << std::flush;
126  QMetaObject::invokeMethod(this, "startOnConnectTimer", Qt::QueuedConnection);
127 }
129 {
130  QMetaObject::invokeMethod(this, "stopOnConnectTimer", Qt::QueuedConnection);
131 }
132 
134 {
135  std::lock_guard guard{robotUnitPrxMutex};
136  robotUnitPrx = getProxy<RobotUnitInterfacePrx>(robotUnitProxyName);
137  listenerTopicName = robotUnitPrx->getRobotUnitListenerTopicName();
138  usingTopic(listenerTopicName);
139  updateToolBarActionCheckedState();
140  timerLastIterationRuWasRunning = false;
141 }
142 
144 {
145  std::lock_guard guard{robotUnitPrxMutex};
146  unsubscribeFromTopic(listenerTopicName);
147  robotUnitPrx = nullptr;
148  QMetaObject::invokeMethod(this, "refreshNJointControllersClicked", Qt::QueuedConnection);
149  QMetaObject::invokeMethod(this, "refreshNJointControllerClassesClicked", Qt::QueuedConnection);
150  QMetaObject::invokeMethod(this, "refreshControlDevicesClicked", Qt::QueuedConnection);
151  QMetaObject::invokeMethod(this, "refreshSensorDevicesClicked", Qt::QueuedConnection);
152 }
153 
154 QPointer<QDialog> RobotUnitPluginWidgetController::getConfigDialog(QWidget* parent)
155 {
156  if (!dialog)
157  {
158  dialog = new SimpleConfigDialog(parent);
159  dialog->addProxyFinder<RobotUnitInterfacePrx>({"RobotUnit", "The RobotUnit", "*"});
160  }
161  return qobject_cast<SimpleConfigDialog*>(dialog);
162 }
163 
165 {
166  robotUnitProxyName = dialog->getProxyName("RobotUnit");
167 }
168 
170 {
171  if (customToolbar)
172  {
173  customToolbar->setParent(parent);
174  }
175  else
176  {
177  customToolbar = new QToolBar(parent);
178  customToolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
179  customToolbar->setIconSize(QSize(16, 16));
180  customToolbar->addAction(QIcon(":/icons/view-refresh-7.png"), "", this, SLOT(refreshControlDevicesClicked()))
181  ->setToolTip("Update the list of Control Devices");
182  showCDevs = new QAction {"Control Devices", customToolbar};
183  showCDevs->setCheckable(true);
184  showCDevs->setToolTip("Hide/Show the list of Control Devices");
185  connect(showCDevs, SIGNAL(toggled(bool)), widget.groupBoxCDev, SLOT(setVisible(bool)));
186  connect(showCDevs, SIGNAL(toggled(bool)), controlDevices, SLOT(setVisible(bool)));
187  customToolbar->addAction(showCDevs);
188  customToolbar->addSeparator();
189 
190  customToolbar->addAction(QIcon(":/icons/view-refresh-7.png"), "", this, SLOT(refreshSensorDevicesClicked()))
191  ->setToolTip("Update the list of Sensor Devices");
192  showSDevs = new QAction {"Sensor Devices", customToolbar};
193  showSDevs->setCheckable(true);
194  showSDevs->setToolTip("Hide/Show the list of Sensor Devices");
195  connect(showSDevs, SIGNAL(toggled(bool)), widget.groupBoxSDev, SLOT(setVisible(bool)));
196  connect(showSDevs, SIGNAL(toggled(bool)), sensorDevices, SLOT(setVisible(bool)));
197  customToolbar->addAction(showSDevs);
198  customToolbar->addSeparator();
199 
200  customToolbar->addAction(QIcon(":/icons/view-refresh-7.png"), "", this, SLOT(refreshNJointControllersClicked()))
201  ->setToolTip("Update the list of NJointControllers");
202  showNJoint = new QAction {"NJointControllers", customToolbar};
203  showNJoint->setCheckable(true);
204  showNJoint->setToolTip("Hide/Show the list of NJointControllers");
205  connect(showNJoint, SIGNAL(toggled(bool)), widget.groupBoxNJointCtrl, SLOT(setVisible(bool)));
206  connect(showNJoint, SIGNAL(toggled(bool)), nJointControllers, SLOT(setVisible(bool)));
207  customToolbar->addAction(showNJoint);
208  customToolbar->addSeparator();
209 
210  customToolbar->addAction(QIcon(":/icons/view-refresh-7.png"), "", this, SLOT(refreshNJointControllerClassesClicked()))
211  ->setToolTip("Update the list of NJointController Classes");
212  showNJointClasses = new QAction {"NJointController Classes", customToolbar};
213  showNJointClasses->setCheckable(true);
214  showNJointClasses->setToolTip("Hide/Show the list of NJointControllers Classes");
215  connect(showNJointClasses, SIGNAL(toggled(bool)), widget.groupBoxNJointCtrlClasses, SLOT(setVisible(bool)));
216  connect(showNJointClasses, SIGNAL(toggled(bool)), nJointControllerClasses, SLOT(setVisible(bool)));
217  customToolbar->addAction(showNJointClasses);
218  customToolbar->addSeparator();
219 
220  customToolbar->addAction(QIcon(":/icons/view-refresh-7.png"), "", this, SLOT(refreshLogging()));
221  showLogging = new QAction {"Logging", customToolbar};
222  showLogging->setCheckable(true);
223  showLogging->setToolTip("Hide/Show the logging pane");
224  connect(showLogging, SIGNAL(toggled(bool)), widget.groupBoxLogging, SLOT(setVisible(bool)));
225  customToolbar->addAction(showLogging);
226  customToolbar->addSeparator();
227 
228  customToolbar->addAction(
229  QIcon(":/icons/document-save.svg"), "Write log",
230  [&]
231  {
232  std::lock_guard guard{robotUnitPrxMutex};
233  robotUnitPrx->writeRecentIterationsToFile("/tmp/RobotUnitLog-{DateTime}");
234  }
235  )
236  ->setToolTip("Writes the log to /tmp/");
237  }
238  updateToolBarActionCheckedState();
239  return customToolbar.data();
240 }
241 
242 void RobotUnitPluginWidgetController::nJointControllerStatusChanged(const NJointControllerStatusSeq& status, const Ice::Current&)
243 {
244  nJointControllers->nJointControllerStatusChanged(status);
245 }
246 
247 void RobotUnitPluginWidgetController::controlDeviceStatusChanged(const ControlDeviceStatusSeq& status, const Ice::Current&)
248 {
249  controlDevices->controlDeviceStatusChanged(status);
250 }
251 
252 void RobotUnitPluginWidgetController::sensorDeviceStatusChanged(const SensorDeviceStatusSeq& status, const Ice::Current&)
253 {
254  sensorDevices->sensorDeviceStatusChanged(status);
255 }
256 
257 void RobotUnitPluginWidgetController::nJointControllerClassAdded(const std::string& name, const Ice::Current&)
258 {
259  nJointControllerClasses->nJointControllerClassAdded(name);
260 }
261 
262 void RobotUnitPluginWidgetController::nJointControllerCreated(const std::string& name, const Ice::Current&)
263 {
264  nJointControllers->nJointControllerCreated(name);
265 }
266 
267 void RobotUnitPluginWidgetController::nJointControllerDeleted(const std::string& name, const Ice::Current&)
268 {
269  nJointControllers->nJointControllerDeleted(name);
270 }
271 
272 void RobotUnitPluginWidgetController::refreshNJointControllersClicked()
273 {
274  std::lock_guard guard{robotUnitPrxMutex};
275  nJointControllers->reset(robotUnitPrx);
276 }
277 
278 void RobotUnitPluginWidgetController::refreshNJointControllerClassesClicked()
279 {
280  std::lock_guard guard{robotUnitPrxMutex};
281  nJointControllerClasses->reset(robotUnitPrx);
282 }
283 
284 void RobotUnitPluginWidgetController::refreshControlDevicesClicked()
285 {
286  std::lock_guard guard{robotUnitPrxMutex};
287  controlDevices->reset(robotUnitPrx);
288 }
289 
290 void RobotUnitPluginWidgetController::refreshSensorDevicesClicked()
291 {
292  std::lock_guard guard{robotUnitPrxMutex};
293  sensorDevices->reset(robotUnitPrx);
294 }
295 
296 void RobotUnitPluginWidgetController::startOnConnectTimer()
297 {
298  if (!timerId)
299  {
300  timerId = startTimer(100);
301  }
302 }
303 void RobotUnitPluginWidgetController::stopOnConnectTimer()
304 {
305  if (timerId)
306  {
307  killTimer(timerId);
308  timerId = 0;
309  }
310 }
311 
312 void RobotUnitPluginWidgetController::updateToolBarActionCheckedState()
313 {
314  if (customToolbar)
315  {
316  showCDevs->setChecked(widget.groupBoxCDev->isVisible());
317  showSDevs->setChecked(widget.groupBoxSDev->isVisible());
318  showNJoint->setChecked(widget.groupBoxNJointCtrl->isVisible());
319  showNJointClasses->setChecked(widget.groupBoxNJointCtrlClasses->isVisible());
320  }
321 }
322 
323 void armarx::RobotUnitPluginWidgetController::timerEvent(QTimerEvent*)
324 {
325  std::lock_guard guard{robotUnitPrxMutex};
326  if (robotUnitPrx && robotUnitPrx->isRunning())
327  {
328  ARMARX_DEBUG << "timerEvent: RobotUnit is running";
329  if (!timerLastIterationRuWasRunning)
330  {
331  refreshNJointControllersClicked();
332  refreshNJointControllerClassesClicked();
333  refreshControlDevicesClicked();
334  refreshSensorDevicesClicked();
335  refreshLogging();
336  }
337  else
338  {
339  loggingData.localLogging();
340  }
341  timerLastIterationRuWasRunning = true;
342  }
343  else
344  {
345  timerLastIterationRuWasRunning = false;
346  ARMARX_DEBUG << "timerEvent: RobotUnit is not running";
347  }
348 }
349 
350 void armarx::RobotUnitPluginWidgetController::refreshLogging()
351 {
352  std::lock_guard guard{robotUnitPrxMutex};
353  on_pushButtonLoggingStop_clicked();
354 
355  widget.treeWidgetLoggingNames->clear();
356  loggingData.allItems.clear();
357 
358  const auto allLoggingNames = robotUnitPrx->getLoggingNames();
359 
360  std::map<std::string, QTreeWidgetItem*> separators;
361  auto add = [&](const std::string & name, const std::string & display, auto parent)
362  {
363  QTreeWidgetItem* i = new QTreeWidgetItem(parent);
364  i->setText(0, QString::fromStdString(display) + "*");
365  i->setData(0, Qt::ToolTipRole, QString::fromStdString(name));
366  separators[name] = i;
367  loggingData.allItems.emplace_back(i);
368  i->setCheckState(0, Qt::Unchecked);
369  };
370  add("", "", widget.treeWidgetLoggingNames);
371  loggingData.top = loggingData.allItems.front();
372 
373  for (const auto& name : allLoggingNames)
374  {
375  const auto parts = Split(name, ".", true, true);
376  std::string reassembled;
377  for (const auto& p : parts)
378  {
379  ARMARX_CHECK_EXPRESSION(separators.count(reassembled));
380  auto parent = separators.at(reassembled);
381  reassembled += (reassembled.empty() ? p : "." + p) ;
382  if (!separators.count(reassembled))
383  {
384  add(reassembled, p, parent);
385  }
386  }
387  loggingData.allItems.back()->setText(0, QString::fromStdString(parts.back()));
388  }
389 
390 }
391 
392 void armarx::RobotUnitPluginWidgetController::on_pushButtonLoggingStart_clicked()
393 {
394  std::lock_guard guard{robotUnitPrxMutex};
395  if (!robotUnitPrx || loggingData.handle || loggingData.streamingHandler)
396  {
397  return;
398  }
399  std::vector<std::string> loggingNames;
400  std::function<void(QTreeWidgetItem*)> recurseChildren = [&](auto it)
401  {
402  switch (it->checkState(0))
403  {
404  case Qt::Checked:
405  if (it->childCount() == 0)
406  {
407  loggingNames.emplace_back(it->data(0, Qt::ToolTipRole).toString().toStdString());
408  }
409  else
410  {
411  for (int i = 0; i < it->childCount(); ++i)
412  {
413  recurseChildren(it->child(i));
414  }
415  }
416  break;
417  case Qt::Unchecked:
418  break;
419  case Qt::PartiallyChecked:
420  for (int i = 0; i < it->childCount(); ++i)
421  {
422  recurseChildren(it->child(i));
423  }
424  break;
425  }
426  };
427  recurseChildren(loggingData.top);
428  const std::string saveFormatString = widget.lineEditLoggingPath->text().toStdString();
429  if (widget.checkBoxLoggingStream->isChecked())
430  {
431  ARMARX_INFO << "start streaming " << loggingNames;
432  RobotUnitDataStreaming::Config cfg;
433  cfg.loggingNames = loggingNames;
434  loggingData.streamingHandler =
435  make_shared<RobotUnitDataStreamingReceiver>(this, robotUnitPrx, cfg);
436 
437  FileSystemPathBuilder pb {saveFormatString};
438  loggingData.logStream.open(pb.getPath());
439  loggingData.logStream << ";iteration;timestamp;TimeSinceLastIteration";
440  const auto& entries = loggingData.streamingHandler->getDataDescription().entries;
441  std::stringstream str;
442  str << "stream " << entries.size() << " values\n";
443  for (const auto& [name, desc] : entries)
444  {
445  loggingData.logStream << ';' << name;
446  str << " " << name
447  << " -> type " << desc.type
448  << ", index " << desc.index << '\n';
449  }
450  loggingData.logStream << std::endl;
451  ARMARX_INFO << str.str();
452  }
453  else
454  {
455  ARMARX_INFO << "start logging " << loggingNames;
456  loggingData.handle = robotUnitPrx->startRtLogging(saveFormatString, loggingNames);
457  widget.pushButtonLoggingMark1->setEnabled(true);
458  widget.pushButtonLoggingMark2->setEnabled(true);
459  widget.pushButtonLoggingMark3->setEnabled(true);
460  }
461  widget.pushButtonLoggingStart->setEnabled(false);
462  widget.pushButtonLoggingStop->setEnabled(true);
463 }
464 
465 void armarx::RobotUnitPluginWidgetController::on_pushButtonLoggingStop_clicked()
466 {
467  std::lock_guard guard{robotUnitPrxMutex};
468  widget.pushButtonLoggingStart->setEnabled(true);
469  widget.pushButtonLoggingStop->setEnabled(false);
470  widget.pushButtonLoggingMark1->setEnabled(false);
471  widget.pushButtonLoggingMark2->setEnabled(false);
472  widget.pushButtonLoggingMark3->setEnabled(false);
473  if (loggingData.handle)
474  {
475  robotUnitPrx->stopRtLogging(loggingData.handle);
476  }
477  if (loggingData.logStream.is_open())
478  {
479  loggingData.logStream.close();
480  }
481  loggingData.handle = nullptr;
482  loggingData.streamingHandler = nullptr;
483 }
484 
485 void armarx::RobotUnitPluginWidgetController::on_lineEditLoggingFilter_textChanged(const QString& arg1)
486 {
487  std::regex reg;
488  try
489  {
490  reg = std::regex{arg1.toStdString()};
491  }
492  catch (...)
493  {
494  //broken regex
495  widget.lineEditLoggingFilter->setStyleSheet("QLineEdit { background: rgb(255, 150, 150); selection-background-color: rgb(255, 0, 0); }");
496  return;
497  }
498  widget.lineEditLoggingFilter->setStyleSheet("QLineEdit {}");
499 
500  std::function<void(QTreeWidgetItem* item)> setVisible = [&](auto it)
501  {
502  it->setHidden(false);
503  auto parent = it->parent();
504  //set parent state depending on its childrens state
505  if (!parent)
506  {
507  return;
508  }
509  setVisible(parent);
510  };
511  for (auto item : loggingData.allItems)
512  {
513  item->setHidden(true);
514  }
515  for (auto item : loggingData.allItems)
516  {
517  const auto str = item->data(0, Qt::ToolTipRole).toString().toStdString();
518  std::smatch match;
519  if (std::regex_search(str, match, reg))
520  {
521  setVisible(item);
522  }
523  }
524  widget.treeWidgetLoggingNames->blockSignals(true);
525  // Iterate in reverse order
526  for (auto iter = loggingData.allItems.rbegin(); iter != loggingData.allItems.rend(); ++iter)
527  {
528  QTreeWidgetItem* item = *iter;
529  loggingData.updateCheckStateUpward(item, false);
530  }
531  widget.treeWidgetLoggingNames->blockSignals(false);
532 }
533 
534 void armarx::RobotUnitPluginWidgetController::on_treeWidgetLoggingNames_itemChanged(QTreeWidgetItem* item, int)
535 {
536  widget.treeWidgetLoggingNames->blockSignals(true);
537  loggingData.updateCheckStateDownward(item, item->checkState(0), true);
538  loggingData.updateCheckStateUpward(item->parent(), true);
539  widget.treeWidgetLoggingNames->blockSignals(false);
540 }
541 
542 void armarx::RobotUnitPluginWidgetController::on_pushButtonLoggingMark1_clicked()
543 {
544  if (!loggingData.handle)
545  {
546  return;
547  }
548  const auto mark = widget.lineEditLoggingMark1->text().toStdString();
549  ARMARX_INFO << "set mark " << mark;
550  robotUnitPrx->addMarkerToRtLog(loggingData.handle, mark);
551 }
552 
553 void armarx::RobotUnitPluginWidgetController::on_pushButtonLoggingMark2_clicked()
554 {
555  if (!loggingData.handle)
556  {
557  return;
558  }
559  const auto mark = widget.lineEditLoggingMark2->text().toStdString();
560  ARMARX_INFO << "set mark " << mark;
561  robotUnitPrx->addMarkerToRtLog(loggingData.handle, mark);
562 }
563 
564 void armarx::RobotUnitPluginWidgetController::on_pushButtonLoggingMark3_clicked()
565 {
566  if (!loggingData.handle)
567  {
568  return;
569  }
570  const auto mark = widget.lineEditLoggingMark3->text().toStdString();
571  ARMARX_INFO << "set mark " << mark;
572  robotUnitPrx->addMarkerToRtLog(loggingData.handle, mark);
573 }
574 
575 void RobotUnitPluginWidgetController::LoggingData::updateCheckStateUpward(QTreeWidgetItem* item, bool recurseParents)
576 {
577  //set item state depending on its childrens state and maybe recurse parent
578  for (; item; item = recurseParents ? item->parent() : nullptr)
579  {
580  if (item->isHidden())
581  {
582  continue;
583  }
584  bool anyChecked = false;
585  bool anyUnchecked = false;
586  bool anyTri = false;
587  for (int i = 0; i < item->childCount(); ++i)
588  {
589  auto c = item->child(i);
590  if (c->isHidden())
591  {
592  continue;
593  }
594  switch (c->checkState(0))
595  {
596  case Qt::Checked:
597  anyChecked = true;
598  break;
599  case Qt::Unchecked:
600  anyUnchecked = true;
601  break;
602  case Qt::PartiallyChecked:
603  anyTri = true;
604  break;
605  }
606  if (anyChecked + anyUnchecked + anyTri > 1 || anyTri)
607  {
608  item->setCheckState(0, Qt::PartiallyChecked);
609  }
610  else if (anyChecked)
611  {
612  item->setCheckState(0, Qt::Checked);
613  }
614  else if (anyUnchecked)
615  {
616  item->setCheckState(0, Qt::Unchecked);
617  }
618  //case all false -> leaf -> do nothing
619  }
620  }
621 }
622 
623 void RobotUnitPluginWidgetController::LoggingData::updateCheckStateDownward(
624  QTreeWidgetItem* item,
625  Qt::CheckState state,
626  bool recurseChildren)
627 {
628  if (item->isHidden())
629  {
630  return;
631  }
632  item->setCheckState(0, state);
633 
634  if (!recurseChildren)
635  {
636  return;
637  }
638  for (int i = 0; i < item->childCount(); ++i)
639  {
640  auto c = item->child(i);
641  if (c->isHidden())
642  {
643  continue;
644  }
645  c->setCheckState(0, state);
646  updateCheckStateDownward(c, state, true);
647  }
648 }
649 
650 void RobotUnitPluginWidgetController::LoggingData::localLogging()
651 {
652  if (!streamingHandler)
653  {
654  ARMARX_DEBUG_S << "localLogging -> no local logging";
655  return;
656  }
657  ARMARX_DEBUG_S << "localLogging -> do local logging";
658  auto& data = streamingHandler->getDataBuffer();
659  if (data.empty())
660  {
662  << "No streaming data received!";
663  return;
664  }
666  << "Writing " << data.size() << " timesteps";
667  const auto& descr = streamingHandler->getDataDescription();
668  for (const auto& step : data)
669  {
670  for (const auto& [name, desc] : descr.entries)
671  {
672  logStream << ';' << step.iterationId
673  << ';' << step.timestampUSec
674  << ';' << step.timesSinceLastIterationUSec;
675  using enum_t = RobotUnitDataStreaming::DataEntryType;
676  switch (desc.type)
677  {
678  case enum_t::NodeTypeBool :
679  logStream << ';' << step.bools .at(desc.index);
680  break;
681  case enum_t::NodeTypeByte :
682  logStream << ';' << step.bytes .at(desc.index);
683  break;
684  case enum_t::NodeTypeShort :
685  logStream << ';' << step.shorts .at(desc.index);
686  break;
687  case enum_t::NodeTypeInt :
688  logStream << ';' << step.ints .at(desc.index);
689  break;
690  case enum_t::NodeTypeLong :
691  logStream << ';' << step.longs .at(desc.index);
692  break;
693  case enum_t::NodeTypeFloat :
694  logStream << ';' << step.floats .at(desc.index);
695  break;
696  case enum_t::NodeTypeDouble:
697  logStream << ';' << step.doubles.at(desc.index);
698  break;
699  };
700  }
701  logStream << std::endl;
702  }
703  data.clear();
704 }
str
std::string str(const T &t)
Definition: UserAssistedSegmenterGuiWidgetController.cpp:42
armarx::NJointControllerClassesWidget::nJointControllerClassAdded
virtual void nJointControllerClassAdded(std::string name)
Definition: NJointControllerClassesWidget.cpp:90
armarx::RobotUnitPluginWidgetController::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: RobotUnitPluginWidgetController.cpp:128
armarx::RobotUnitPluginWidgetController::saveSettings
void saveSettings(QSettings *settings) override
Definition: RobotUnitPluginWidgetController.cpp:109
armarx::NJointControllerClassesWidget::loadSettings
void loadSettings(QSettings *settings) override
Definition: NJointControllerClassesWidget.cpp:128
armarx::RobotUnitPluginWidgetController::nJointControllerDeleted
void nJointControllerDeleted(const std::string &name, const Ice::Current &) override
Definition: RobotUnitPluginWidgetController.cpp:267
armarx::SensorDevicesWidget
Definition: SensorDevicesWidget.h:49
armarx::RobotUnitPluginWidgetController::controlDeviceStatusChanged
void controlDeviceStatusChanged(const ControlDeviceStatusSeq &status, const Ice::Current &) override
Definition: RobotUnitPluginWidgetController.cpp:247
armarx::Split
std::vector< std::string > Split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
Definition: StringHelperTemplates.h:35
display
Use of this software is granted under one of the following two to be chosen freely by the user Boost Software License Version Marcin Kalicinski Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this display
Definition: license.txt:11
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::RobotUnitPluginWidgetController::onConnectComponent
void onConnectComponent() override
Definition: RobotUnitPluginWidgetController.cpp:133
armarx::NJointControllerClassesWidget::saveSettings
void saveSettings(QSettings *settings) override
Definition: NJointControllerClassesWidget.cpp:135
armarx::RobotUnitPluginWidgetController::configured
void configured() override
Callback called when the config dialog is closed.
Definition: RobotUnitPluginWidgetController.cpp:164
armarx::RobotUnitPluginWidgetController::sensorDeviceStatusChanged
void sensorDeviceStatusChanged(const SensorDeviceStatusSeq &status, const Ice::Current &) override
Definition: RobotUnitPluginWidgetController.cpp:252
armarx::ControlDevicesWidget
Definition: ControlDevicesWidget.h:50
armarx::NJointControllersWidget
Definition: NJointControllersWidget.h:53
armarx::RobotUnitPluginWidgetController::nJointControllerStatusChanged
void nJointControllerStatusChanged(const NJointControllerStatusSeq &status, const Ice::Current &) override
Definition: RobotUnitPluginWidgetController.cpp:242
armarx::RobotUnitPluginWidgetController::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: RobotUnitPluginWidgetController.cpp:143
armarx::ControlDevicesWidget::controlDeviceStatusChanged
void controlDeviceStatusChanged(const ControlDeviceStatusSeq &allStatus)
Definition: ControlDevicesWidget.cpp:69
armarx::NJointControllersWidget::loadSettings
void loadSettings(QSettings *settings) override
Definition: NJointControllersWidget.cpp:175
deactivateSpam
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition: Logging.cpp:72
armarx::status
status
Definition: FiniteStateMachine.h:259
armarx::RobotUnitPluginWidgetController::nJointControllerClassAdded
void nJointControllerClassAdded(const std::string &name, const Ice::Current &) override
Definition: RobotUnitPluginWidgetController.cpp:257
armarx::RobotUnitWidgetBase::saveSettings
virtual void saveSettings(QSettings *)
Definition: RobotUnitWidgetBase.h:57
ARMARX_DEBUG_S
#define ARMARX_DEBUG_S
Definition: Logging.h:198
armarx::NJointControllersWidget::nJointControllerDeleted
virtual void nJointControllerDeleted(std::string name)
Definition: NJointControllersWidget.cpp:165
armarx::RobotUnitPluginWidgetController::getCustomTitlebarWidget
QPointer< QWidget > getCustomTitlebarWidget(QWidget *parent) override
getTitleToolbar returns a pointer to the a toolbar widget of this controller.
Definition: RobotUnitPluginWidgetController.cpp:169
armarx::RobotUnitPluginWidgetController::getConfigDialog
QPointer< QDialog > getConfigDialog(QWidget *parent) override
Definition: RobotUnitPluginWidgetController.cpp:154
armarx::flush
const LogSender::manipulator flush
Definition: LogSender.h:251
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
RobotUnitPluginWidgetController.h
armarx::RobotUnitPluginWidgetController::RobotUnitPluginWidgetController
RobotUnitPluginWidgetController()
Controller Constructor.
Definition: RobotUnitPluginWidgetController.cpp:40
armarx::RobotUnitPluginWidgetController::onInitComponent
void onInitComponent() override
Definition: RobotUnitPluginWidgetController.cpp:122
armarx::ManagedIceObject::unsubscribeFromTopic
bool unsubscribeFromTopic(const std::string &name)
Unsubscribe from a topic.
Definition: ManagedIceObject.cpp:271
armarx::RobotUnitWidgetBase::loadSettings
virtual void loadSettings(QSettings *)
Definition: RobotUnitWidgetBase.h:56
armarx::RobotUnitWidgetBase::setVisible
void setVisible(bool visible) override
Definition: RobotUnitWidgetBase.cpp:70
armarx::NJointControllersWidget::saveSettings
void saveSettings(QSettings *settings) override
Definition: NJointControllersWidget.cpp:183
ExpressionException.h
armarx::ManagedIceObject::usingTopic
void usingTopic(const std::string &name, bool orderedPublishing=false)
Registers a proxy for subscription after initialization.
Definition: ManagedIceObject.cpp:248
CMakePackageFinder.h
armarx::SensorDevicesWidget::sensorDeviceStatusChanged
void sensorDeviceStatusChanged(const SensorDeviceStatusSeq &allStatus)
Definition: SensorDevicesWidget.cpp:53
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::NJointControllersWidget::nJointControllerStatusChanged
void nJointControllerStatusChanged(const NJointControllerStatusSeq &allStatus)
Definition: NJointControllersWidget.cpp:90
armarx::NJointControllerClassesWidget
Definition: NJointControllerClassesWidget.h:51
IceInternal::ProxyHandle<::IceProxy::armarx::RobotUnitInterface >
armarx::RobotUnitPluginWidgetController::nJointControllerCreated
void nJointControllerCreated(const std::string &name, const Ice::Current &) override
Definition: RobotUnitPluginWidgetController.cpp:262
armarx::ArmarXWidgetController::getWidget
virtual QPointer< QWidget > getWidget()
getWidget returns a pointer to the a widget of this controller.
Definition: ArmarXWidgetController.cpp:54
ARMARX_INFO_S
#define ARMARX_INFO_S
Definition: Logging.h:195
armarx::RobotUnitWidgetBase::reset
void reset(RobotUnitInterfacePrx ru)
Definition: RobotUnitWidgetBase.cpp:61
armarx::RobotUnitPluginWidgetController::loadSettings
void loadSettings(QSettings *settings) override
Definition: RobotUnitPluginWidgetController.cpp:95
armarx::NJointControllersWidget::nJointControllerCreated
virtual void nJointControllerCreated(std::string name)
Definition: NJointControllersWidget.cpp:143
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
FileSystemPathBuilder.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::FileSystemPathBuilder
Helps to build a path via format strings: All format strings are of the form '{[^{}]+}' If the result...
Definition: FileSystemPathBuilder.h:63
armarx::SimpleConfigDialog
A config-dialog containing one (or multiple) proxy finders.
Definition: SimpleConfigDialog.h:84