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