PresenterViewWidgetController.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 ArmarXGui::gui-plugins::PresenterViewWidgetController
19 * \author Leonie Leven
20 * \date 2024
21 * \copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
26
27#include <string>
28
29#include <QDebug>
30#include <QTimer>
31
36
37namespace armarx
38{
40 DEFAULT_SETTINGS_PLUGIN_NAME("PresenterViewWidgetGuiPlugin"),
41 DEFAULT_SETTINGS_CUSTOM_TEXT("custom text")
42 {
43 // init gui
44 // getWidget() returns a container into which this widget is embedded
45 widget.setupUi(getWidget());
46 this->updateTimer = new QTimer(this);
47 stopwatch.start();
48 this->updateTimer->start(50);
49
50
51 this->statusIndicationLabel = new StatusIndicationLabel(getWidget());
52 this->statusIndicationLabel->setTextWithScaling("testestset");
53
54
55 QLayout* existingLayout = getWidget()->layout();
56
57 existingLayout->addWidget(this->statusIndicationLabel);
58
59 ARMARX_INFO << " setup of ui finished" << flush;
60 }
61
62 void
64 {
66
67 demoStateProxyName =
68 settings->value("demoStateProxyName", QString::fromStdString(demoStateProxyName))
69 .toString()
70 .toStdString();
71 }
72
73 void
75 {
77
78 settings->setValue("demoStateProxyName", QString::fromStdString(demoStateProxyName));
79 }
80
81 void
83 {
84
85 // if you want to use proxies you can specify them here
86 //usingProxy(myProxyName);
88
89 usingProxy(demoStateProxyName);
90 }
91
92 void
94 {
96 getProxy(demoStateManagerPrx, demoStateProxyName);
97
98 stopCheckStateTask.store(false);
99 checkStateTask = std::thread([&] { checkState(); });
100
101 connect(this,
103 this,
105
106 connect(
107 updateTimer, &QTimer::timeout, this, &PresenterViewWidgetController::updateStopwatch);
108 }
109
110 void
112 {
114
115 while (not stopCheckStateTask.load())
116 {
117 try
118 {
119 // Might throw due to Ice.
120 auto stateAndSeverity = this->demoStateManagerPrx->getStateAndSeverity();
121 // /critical section
122
123 emit stateAndSeverityUpdated(QString::fromStdString(stateAndSeverity.state),
124 static_cast<int>(stateAndSeverity.severity));
125 }
126 catch (Ice::Exception const&)
127 {
128 ARMARX_WARNING << "Could not fetch current state and severity."
129 << deactivateSpam(10);
130 }
131
132 metronome.waitForNextTick();
133 }
134 }
135
136 void
138 {
139 //int textSize = widget.textSize->value();
140 std::string color = mapColor(static_cast<armarx::severity::SeverityEnum>(severity));
141 // QString styleSheet =
142 // QString("color: %1; font-size: %2px;").arg(QString::fromStdString(color)).arg(textSize);
143 // widget.label->setStyleSheet(styleSheet);
144 // widget.label->setText(QString::fromStdString(state.toStdString()));
145
146 QString styleSheet2 = QString("color: %1;").arg(QString::fromStdString(color));
147 this->statusIndicationLabel->setTextWithScaling(state);
148 this->statusIndicationLabel->setStyleSheet(styleSheet2);
149
150 // restart the stopwatch to indicate the update
151 this->stopwatch.restart();
152 }
153
154 void
156 {
157 qint64 elapsedMs = stopwatch.elapsed();
158 double elapsedMilliSeconds = elapsedMs;
159 if (elapsedMilliSeconds > 250)
160 {
161 QString styleSheet2 = QString("color: grey;");
162 this->statusIndicationLabel->setStyleSheet(styleSheet2);
163 }
164 }
165
166 std::string
167 PresenterViewWidgetController::mapColor(severity::SeverityEnum severity)
168 {
169 std::string color;
170 switch (severity)
171 {
172 case severity::SeverityEnum::normal:
173 color = "green";
174 break;
175 case severity::SeverityEnum::warning:
176 color = "orange";
177 break;
178 case severity::SeverityEnum::error:
179 color = "red";
180 break;
181 case severity::SeverityEnum::fatal:
182 color = "magenta";
183 break;
184 default:
185 color = "black";
186 }
187 return color;
188 }
189
190 void
192 {
193 stopCheckStateTask.store(true);
194 checkStateTask.join();
195 }
196
197 void
199 {
200 // implement cleanup
201 ARMARX_INFO << "Cleanup";
202 }
203
204 QPointer<QDialog>
206 {
208
209 if (not m_config_dialog)
210 {
211 m_config_dialog = new armarx::SimpleConfigDialog{parent};
212 m_config_dialog->addProxyFinder<DemoStateManagerInterfacePrx>(
213 {"DemoStateManager", "Demo State Manager", "*"});
214 }
215 return qobject_cast<QDialog*>(m_config_dialog);
216 }
217
218 void
220 {
222
223 if (m_config_dialog)
224 {
225 demoStateProxyName = m_config_dialog->getProxyName("DemoStateManager");
226 }
227 }
228
229
230} // namespace armarx
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition Logging.cpp:75
virtual QPointer< QWidget > getWidget()
getWidget returns a pointer to the a widget of this controller.
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)
virtual void saveSettings(QSettings *settings)
Implement to save the settings as part of the GUI configuration.
virtual void loadSettings(QSettings *settings)
Implement to load the settings that are part of the GUI configuration.
virtual void onInitComponent()
Pure virtual hook for the subclass.
void stateAndSeverityUpdated(QString state, int severity)
virtual void onDisconnectComponent()
Hook for subclass.
void configured() override
This function must be implemented by the user, if he supplies a config dialog.
virtual void onConnectComponent()
Pure virtual hook for the subclass.
QPointer< QDialog > getConfigDialog(QWidget *parent) override
getConfigDialog returns a pointer to the a configuration widget of this controller.
void updateStateAndSeverity(QString state, int severity)
A config-dialog containing one (or multiple) proxy finders.
void addProxyFinder(const std::vector< EntryData > &entryData)
static Frequency Hertz(std::int64_t hertz)
Definition Frequency.cpp:20
Simple rate limiter for use in loops to maintain a certain frequency given a clock.
Definition Metronome.h:57
#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.
const LogSender::manipulator flush
Definition LogSender.h:251
#define ARMARX_TRACE
Definition trace.h:77