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 
37 static const std::string config_key_imrecman = "imrecman_name";
38 static const std::string config_key_start_in = "start_in";
39 
40 namespace armarx
41 {
43  DEFAULT_SETTINGS_PLUGIN_NAME("PresenterViewWidgetGuiPlugin"),
44  DEFAULT_SETTINGS_CUSTOM_TEXT("custom text")
45  {
46  // init gui
47  // getWidget() returns a container into which this widget is embedded
48  widget.setupUi(getWidget());
49  widget.timeSinceUpdate->setText("00 ms");
50  this->updateTimer = new QTimer(this);
51  stopwatch.start();
52  this->updateTimer->start(50);
53 
54 
55  this->statusIndicationLabel = new StatusIndicationLabel(getWidget());
56  this->statusIndicationLabel->setTextWithScaling("testestset");
57 
58 
59  QLayout* existingLayout = getWidget()->layout();
60 
61  existingLayout->addWidget(this->statusIndicationLabel);
62 
63  ARMARX_INFO << " setup of ui finished" << flush;
64  }
65 
66  void
68  {
70 
71  demoStateManagerName =
72  settings
73  ->value(QString::fromStdString(::config_key_imrecman), "DemoStateManagerInterface")
74  .toString()
75  .toStdString();
76  }
77 
78  void
80  {
82 
83  settings->setValue(QString::fromStdString(::config_key_imrecman),
84  QString::fromStdString(demoStateManagerName));
85  }
86 
87  void
89  {
90 
91  // if you want to use proxies you can specify them here
92  //usingProxy(myProxyName);
94 
95  if (not demoStateManagerName.empty())
96  {
97  usingProxy(demoStateManagerName);
98  }
99  }
100 
101  void
103  {
104  ARMARX_TRACE;
105  getProxy(demoStateManagerPrx, demoStateManagerName);
106 
107  stopCheckStateTask.store(false);
108  checkStateTask = std::thread([&] { checkState(); });
109 
110  connect(this,
112  this,
114 
115  connect(
116  updateTimer, &QTimer::timeout, this, &PresenterViewWidgetController::updateStopwatch);
117  }
118 
119  void
121  {
123 
124  while (not stopCheckStateTask.load())
125  {
126  try
127  {
128  // Might throw due to Ice.
129  auto stateAndSeverity = this->demoStateManagerPrx->getStateAndSeverity();
130  // /critical section
131 
132  emit stateAndSeverityUpdated(QString::fromStdString(stateAndSeverity.state),
133  static_cast<int>(stateAndSeverity.severity));
134  }
135  catch (Ice::Exception const&)
136  {
137  ARMARX_WARNING << "Could not fetch current state and severity."
138  << deactivateSpam(10);
139  }
140 
141  metronome.waitForNextTick();
142  }
143  }
144 
145  void
147  {
148  //int textSize = widget.textSize->value();
149  std::string color = mapColor(static_cast<armarx::severity::SeverityEnum>(severity));
150  // QString styleSheet =
151  // QString("color: %1; font-size: %2px;").arg(QString::fromStdString(color)).arg(textSize);
152  // widget.label->setStyleSheet(styleSheet);
153  // widget.label->setText(QString::fromStdString(state.toStdString()));
154 
155  QString styleSheet2 = QString("color: %1;").arg(QString::fromStdString(color));
156  this->statusIndicationLabel->setTextWithScaling(state);
157  this->statusIndicationLabel->setStyleSheet(styleSheet2);
158 
159 
160  this->stopwatch.restart();
161  }
162 
163  void
165  {
166  qint64 elapsedMs = stopwatch.elapsed();
167  double elapsedMilliSeconds = elapsedMs;
168  widget.timeSinceUpdate->setText(QString::number(elapsedMilliSeconds, 'f', 1) + " ms");
169  }
170 
171  std::string
172  PresenterViewWidgetController::mapColor(severity::SeverityEnum severity)
173  {
174  std::string color;
175  switch (severity)
176  {
177  case severity::SeverityEnum::normal:
178  color = "green";
179  break;
180  case severity::SeverityEnum::warning:
181  color = "orange";
182  break;
183  case severity::SeverityEnum::error:
184  color = "red";
185  break;
186  case severity::SeverityEnum::fatal:
187  color = "magenta";
188  break;
189  default:
190  color = "black";
191  }
192  return color;
193  }
194 
195  void
197  {
198  stopCheckStateTask.store(true);
199  checkStateTask.join();
200  }
201 
202  void
204  {
205  // implement cleanup
206  ARMARX_INFO << "Cleanup";
207  }
208 
209  QPointer<QDialog>
211  {
212  ARMARX_TRACE;
213 
214  if (not m_config_dialog)
215  {
216  m_config_dialog = new armarx::SimpleConfigDialog{parent};
217  m_config_dialog->addProxyFinder<DemoStateManagerInterfacePrx>(
218  {::config_key_imrecman, "Demo State Manager", "*"});
219  }
220  return qobject_cast<QDialog*>(m_config_dialog);
221  }
222 
223  void
225  {
226  ARMARX_TRACE;
227 
228  if (m_config_dialog)
229  {
230  demoStateManagerName = m_config_dialog->getProxyName(::config_key_imrecman);
231  }
232  }
233 
234 
235 } // namespace armarx
armarx::PresenterViewWidgetController::onExitComponent
virtual void onExitComponent()
Hook for subclass.
Definition: PresenterViewWidgetController.cpp:203
armarx::PresenterViewWidgetController::checkState
void checkState()
Definition: PresenterViewWidgetController.cpp:120
armarx::PresenterViewWidgetController::saveSettings
virtual void saveSettings(QSettings *settings)
Implement to save the settings as part of the GUI configuration.
Definition: PresenterViewWidgetController.cpp:79
armarx::PresenterViewWidgetController::getConfigDialog
QPointer< QDialog > getConfigDialog(QWidget *parent) override
getConfigDialog returns a pointer to the a configuration widget of this controller.
Definition: PresenterViewWidgetController.cpp:210
armarx::PresenterViewWidgetController::updateStopwatch
void updateStopwatch()
Definition: PresenterViewWidgetController.cpp:164
PresenterViewWidgetController.h
armarx::PresenterViewWidgetController::configured
void configured() override
This function must be implemented by the user, if he supplies a config dialog.
Definition: PresenterViewWidgetController.cpp:224
armarx::PresenterViewWidgetController::updateStateAndSeverity
void updateStateAndSeverity(QString state, int severity)
Definition: PresenterViewWidgetController.cpp:146
armarx::PresenterViewWidgetController::onDisconnectComponent
virtual void onDisconnectComponent()
Hook for subclass.
Definition: PresenterViewWidgetController.cpp:196
armarx::StatusIndicationLabel
Definition: StatusIndication.h:43
armarx::PresenterViewWidgetController::loadSettings
virtual void loadSettings(QSettings *settings)
Implement to load the settings that are part of the GUI configuration.
Definition: PresenterViewWidgetController.cpp:67
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:77
LocalTimeServer.h
armarx::PresenterViewWidgetController::onConnectComponent
virtual void onConnectComponent()
Pure virtual hook for the subclass.
Definition: PresenterViewWidgetController.cpp:102
armarx::flush
const LogSender::manipulator flush
Definition: LogSender.h:251
stopwatch
Definition: Stopwatch.cpp:3
armarx::PresenterViewWidgetController::PresenterViewWidgetController
PresenterViewWidgetController()
Definition: PresenterViewWidgetController.cpp:42
Metronome.h
armarx::PresenterViewWidgetController::stateAndSeverityUpdated
void stateAndSeverityUpdated(QString state, int severity)
armarx::SimpleConfigDialog::addProxyFinder
void addProxyFinder(const std::vector< EntryData > &entryData)
Definition: SimpleConfigDialog.h:103
TimeUtil.h
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::core::time::Metronome
Simple rate limiter for use in loops to maintain a certain frequency given a clock.
Definition: Metronome.h:34
DEFAULT_SETTINGS_PLUGIN_NAME
#define DEFAULT_SETTINGS_PLUGIN_NAME
Definition: PriorMemoryEditorPlugin.cpp:92
armarx::Logging::deactivateSpam
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
Definition: Logging.cpp:99
armarx::ArmarXWidgetController::getWidget
virtual QPointer< QWidget > getWidget()
getWidget returns a pointer to the a widget of this controller.
Definition: ArmarXWidgetController.cpp:54
armarx::core::time::Frequency::Hertz
static Frequency Hertz(std::int64_t hertz)
Definition: Frequency.cpp:20
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
armarx::ManagedIceObject::getProxy
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
Definition: ManagedIceObject.cpp:407
armarx::StatusIndicationLabel::setTextWithScaling
void setTextWithScaling(const QString &text)
Definition: StatusIndication.cpp:42
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:154
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
Application.h
armarx::SimpleConfigDialog
A config-dialog containing one (or multiple) proxy finders.
Definition: SimpleConfigDialog.h:84
armarx::PresenterViewWidgetController::onInitComponent
virtual void onInitComponent()
Pure virtual hook for the subclass.
Definition: PresenterViewWidgetController.cpp:88