RobotUnitWidgetBase.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::RobotUnitPlugin
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 #include "RobotUnitWidgetBase.h"
25 
26 #include <thread>
27 
28 namespace armarx
29 {
30  RobotUnitWidgetBase::RobotUnitWidgetBase(QString name, QWidget* parent) :
31  QWidget(parent)
32  {
33  setObjectName(name);
34  }
35 
37  {
38  while (_resetThread.joinable() && ! _resetThread.try_join_for(boost::chrono::milliseconds{100}))
39  {
40  ARMARX_INFO << "Joining reset thread";
41  }
42  }
43 
45  {
46  if (isResetting)
47  {
48  return;
49  }
50  std::unique_lock<std::recursive_timed_mutex> guard {mutex};
51  resetCount = 0;
52  getResettigLabel().setText("Resetting... " + QString::number(resetCount));
53  getStackedWidget().setCurrentIndex(0);
54  if (!robotUnit)
55  {
56  return;
57  }
59  }
60 
62  {
63  isResetting = true;
64  gotResetData = false;
65  std::unique_lock<std::recursive_timed_mutex> guard {mutex};
66  robotUnit = ru;
67  QMetaObject::invokeMethod(this, "doReset", Qt::QueuedConnection);
68  }
69 
71  {
72  doMetaCall = visible;
73  if (visible)
74  {
75  QMetaObject::invokeMethod(this, "updateContent", Qt::QueuedConnection);
76  }
77  QWidget::setVisible(visible);
78  }
79 
80  void RobotUnitWidgetBase::doReset()
81  {
82  std::unique_lock<std::recursive_timed_mutex> guard {mutex};
83  clearAll();
84  getTreeWidget().clear();
85  addFilter();
86  if (robotUnit)
87  {
88  if (!_resetThread.joinable() || _resetThread.try_join_for(boost::chrono::milliseconds{10}))
89  {
90  resetTimerId = startTimer(0);
91  getStackedWidget().setCurrentIndex(1);
92  _resetThread = boost::thread
93  {
94  [&]
95  {
96  ARMARX_INFO << "Resetting of widget '" << objectName().toStdString() << "' started";
97  try
98  {
99  getResetData();
100  }
101  catch (...)
102  {
103  ARMARX_WARNING << "Resetting of widget '" << objectName().toStdString() << "' failed: "
105  }
106  gotResetData = true;
107  if (doMetaCall)
108  {
109  QMetaObject::invokeMethod(this, "updateContent", Qt::QueuedConnection);
110  }
111  ARMARX_INFO << "Resetting of widget '" << objectName().toStdString() << "' done!";
112  }
113  };
114  }
115  }
116  else
117  {
118  gotResetData = true;
119  if (doMetaCall)
120  {
121  QMetaObject::invokeMethod(this, "updateContent", Qt::QueuedConnection);
122  }
123  }
124  }
125 
127  {
128  if (isResetting && gotResetData)
129  {
130  getResettigLabel().setText("Resetting... " + QString::number(++resetCount));
132  if (!isResetting)
133  {
134  killTimer(resetTimerId);
135  resetTimerId = 0;
136  if (doMetaCall)
137  {
138  QMetaObject::invokeMethod(this, "updateContent", Qt::QueuedConnection);
139  }
140  }
141  }
142  }
143 }
RobotUnitWidgetBase.h
armarx::RobotUnitWidgetBase::doContentUpdate
virtual void doContentUpdate()=0
armarx::RobotUnitWidgetBase::addFilter
virtual void addFilter()
Definition: RobotUnitWidgetBase.h:69
armarx::RobotUnitWidgetBase::addOneFromResetData
virtual bool addOneFromResetData()=0
armarx::RobotUnitWidgetBase::~RobotUnitWidgetBase
~RobotUnitWidgetBase()
Definition: RobotUnitWidgetBase.cpp:36
armarx::RobotUnitWidgetBase::doMetaCall
std::atomic_bool doMetaCall
Definition: RobotUnitWidgetBase.h:87
armarx::GetHandledExceptionString
std::string GetHandledExceptionString()
Definition: Exception.cpp:147
armarx::RobotUnitWidgetBase::resetTimerId
int resetTimerId
Definition: RobotUnitWidgetBase.h:84
armarx::RobotUnitWidgetBase::robotUnit
RobotUnitInterfacePrx robotUnit
Definition: RobotUnitWidgetBase.h:81
armarx::RobotUnitWidgetBase::updateContent
void updateContent()
Definition: RobotUnitWidgetBase.cpp:44
armarx::RobotUnitWidgetBase::gotResetData
std::atomic_bool gotResetData
Definition: RobotUnitWidgetBase.h:83
armarx::RobotUnitWidgetBase::mutex
std::recursive_timed_mutex mutex
Definition: RobotUnitWidgetBase.h:82
armarx::RobotUnitWidgetBase::getStackedWidget
virtual QStackedWidget & getStackedWidget()=0
armarx::RobotUnitWidgetBase::timerEvent
void timerEvent(QTimerEvent *) override
Definition: RobotUnitWidgetBase.cpp:126
armarx::RobotUnitWidgetBase::RobotUnitWidgetBase
RobotUnitWidgetBase(QString name, QWidget *parent)
Definition: RobotUnitWidgetBase.cpp:30
armarx::RobotUnitWidgetBase::getResettigLabel
virtual QLabel & getResettigLabel()=0
armarx::RobotUnitWidgetBase::setVisible
void setVisible(bool visible) override
Definition: RobotUnitWidgetBase.cpp:70
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::RobotUnitWidgetBase::getTreeWidget
virtual QTreeWidget & getTreeWidget()=0
IceInternal::ProxyHandle<::IceProxy::armarx::RobotUnitInterface >
armarx::RobotUnitWidgetBase::isResetting
std::atomic_bool isResetting
Definition: RobotUnitWidgetBase.h:86
armarx::RobotUnitWidgetBase::clearAll
virtual void clearAll()=0
armarx::RobotUnitWidgetBase::reset
void reset(RobotUnitInterfacePrx ru)
Definition: RobotUnitWidgetBase.cpp:61
Logging.h
armarx::RobotUnitWidgetBase::resetCount
int resetCount
Definition: RobotUnitWidgetBase.h:85
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::RobotUnitWidgetBase::getResetData
virtual void getResetData()=0
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
Exception.h