2 #include <QApplication> 4 #include <QDoubleValidator> 5 #include <QIntValidator> 17 #include <qmdisubwindow.h> 20 #include "rtxiConfig.h" 27 result = std::string(
"INIT");
30 result = std::string(
"MODIFIED PARAMETERS");
33 result = std::string(
"PERIOD CHANGE");
36 result = std::string(
"PLUGIN PAUSED");
39 result = std::string(
"PLUGIN UNPAUSED");
42 result = std::string(
"EXIT");
45 result = std::string(
"UNKNOWN STATE");
57 result = std::string(
"INTEGER");
60 result = std::string(
"DOUBLE");
63 result = std::string(
"UNSIGNED INTEGER");
66 result = std::string(
"STATE");
69 result = std::string(
"UNKNOWN PARAMETER TYPE");
79 this, SIGNAL(textChanged(
const QString&)),
this, SLOT(
redden()));
84 palette.setBrush(this->foregroundRole(),
85 QApplication::palette().color(QPalette::WindowText));
86 this->setPalette(palette);
93 palette.setBrush(this->foregroundRole(), Qt::red);
94 this->setPalette(palette);
100 const std::string& mod_name,
101 const std::vector<IO::channel_t>& channels,
102 const std::vector<Widgets::Variable::Info>& variables)
103 :
RT::Thread(mod_name, channels)
104 , hostPlugin(hplugin)
106 for (
const auto& var : variables) {
107 if (var.id != parameters.size()) {
108 ERROR_MSG(
"Error parsing variables in module \"{}\" while loading",
110 ERROR_MSG(
"Variable {} has id {} but was inserted in position {}",
116 this->parameters.push_back(var);
122 return this->parameters[var_id].description;
128 switch (this->parameters[var_id].vartype) {
131 std::to_string(std::get<uint64_t>(this->parameters[var_id].value));
134 value = std::to_string(std::get<int64_t>(this->parameters[var_id].value));
137 value = std::to_string(std::get<double>(this->parameters[var_id].value));
143 value = std::get<std::string>(this->parameters[var_id].value);
161 , event_manager(ev_manager)
163 setWindowTitle(QString(mod_name.c_str()));
165 auto* central_widget =
dynamic_cast<QMdiArea*
>(mw->centralWidget());
166 this->m_subwindow = central_widget->addSubWindow(
this);
167 this->m_subwindow->setWindowIcon(
168 QIcon(
"/usr/share/rtxi/RTXI-widget-icon.png"));
169 this->setAttribute(Qt::WA_DeleteOnClose);
170 this->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint
171 | Qt::WindowMinimizeButtonHint);
172 qRegisterMetaType<RT::State::state_t>();
173 QObject::connect(
this,
186 const std::vector<Widgets::Variable::Info>& vars,
187 const std::vector<Widgets::Variable::Id>& skip_ids)
190 auto* main_layout =
new QVBoxLayout;
193 auto* customParamArea =
new QGroupBox;
194 auto* customParamLayout =
new QGridLayout;
196 for (
const auto& varinfo : vars) {
198 if (std::count(skip_ids.begin(), skip_ids.end(), varinfo.id) != 0) {
202 param.label =
new QLabel(QString(varinfo.name.c_str()), customParamArea);
204 param.str_value = QString();
205 param.type = varinfo.vartype;
206 param.info = varinfo;
207 switch (varinfo.vartype) {
209 param.edit->setValidator(
new QDoubleValidator(param.edit));
210 param.edit->setText(QString::number(std::get<double>(varinfo.value)));
213 param.edit->setValidator(
new QIntValidator(param.edit));
214 param.edit->setText(QString::number(std::get<uint64_t>(varinfo.value)));
217 param.edit->setValidator(
new QIntValidator(param.edit));
218 param.edit->setText(QString::number(std::get<int64_t>(varinfo.value)));
221 param.edit->setReadOnly(
true);
222 palette.setBrush(param.edit->foregroundRole(), Qt::darkGray);
223 param.edit->setPalette(palette);
228 ERROR_MSG(
"Variable {} in Widget {} is of category UNKNOWN",
233 ERROR_MSG(
"Variable {} in Widget {} has undefined or broken category",
237 param.label->setToolTip(QString(varinfo.description.c_str()));
238 param.edit->setToolTip(QString(varinfo.description.c_str()));
239 param.str_value = param.edit->text();
240 parameter[varinfo.name] = param;
241 customParamLayout->addWidget(param.label, param_count, 0);
242 customParamLayout->addWidget(param.edit, param_count, 1);
246 customParamArea->setLayout(customParamLayout);
248 auto* buttonGroup =
new QGroupBox;
249 auto* buttonLayout =
new QHBoxLayout;
252 pauseButton =
new QPushButton(
"Pause",
this);
253 pauseButton->setCheckable(
true);
254 QObject::connect(pauseButton, SIGNAL(toggled(
bool)),
this, SLOT(pause(
bool)));
255 buttonLayout->addWidget(pauseButton);
257 modifyButton =
new QPushButton(
"Modify",
this);
258 QObject::connect(modifyButton, SIGNAL(clicked()),
this, SLOT(modify()));
259 buttonLayout->addWidget(modifyButton);
261 unloadButton =
new QPushButton(
"Unload",
this);
263 unloadButton, SIGNAL(clicked()), parentWidget(), SLOT(close()));
264 buttonLayout->addWidget(unloadButton);
266 buttonGroup->setLayout(buttonLayout);
268 main_layout->addWidget(customParamArea, 0);
270 main_layout->addWidget(buttonGroup, 1);
272 this->setLayout(main_layout);
283 m_subwindow->adjustSize();
288 this->event_manager->unregisterHandler(this->hostPlugin);
290 event.setParam(
"pluginPointer",
292 this->event_manager->postEvent(&event);
299 double double_value = 0.0;
300 int64_t int_value = 0;
301 uint64_t uint_value = 0ULL;
302 std::stringstream sstream;
303 for (
auto& i : this->parameter) {
304 switch (i.second.type) {
306 i.second.edit->setText(i.second.str_value);
307 palette.setBrush(i.second.edit->foregroundRole(), Qt::darkGray);
308 i.second.edit->setPalette(palette);
312 uint_value = this->hostPlugin->getComponentUIntParameter(param_id);
313 sstream << uint_value;
314 i.second.edit->setText(QString(sstream.str().c_str()));
318 int_value = this->hostPlugin->getComponentIntParameter(param_id);
319 sstream << int_value;
320 i.second.edit->setText(QString(sstream.str().c_str()));
324 double_value = this->hostPlugin->getComponentDoubleParameter(param_id);
325 sstream << double_value;
326 i.second.edit->setText(QString(sstream.str().c_str()));
329 ERROR_MSG(
"Unable to determine refresh type for component {}",
335 if (this->pauseButton !=
nullptr) {
336 pauseButton->setChecked(!(this->hostPlugin->getActive()));
343 double double_value = 0.0;
345 uint64_t uint_value = 0ULL;
346 std::stringstream sstream;
348 for (
auto& var : this->parameter) {
349 if (!var.second.edit->isModified()) {
352 switch (var.second.type) {
355 uint_value = var.second.edit->text().toUInt();
356 this->hostPlugin->setComponentParameter<uint64_t>(param_id, uint_value);
357 sstream << uint_value;
358 var.second.edit->setText(QString(sstream.str().c_str()));
359 var.second.edit->blacken();
363 int_value = var.second.edit->text().toInt();
364 this->hostPlugin->setComponentParameter<
int>(param_id, int_value);
365 sstream << int_value;
366 var.second.edit->setText(QString(sstream.str().c_str()));
367 var.second.edit->blacken();
371 double_value = var.second.edit->text().toDouble();
372 this->hostPlugin->setComponentParameter(param_id, double_value);
373 sstream << double_value;
374 var.second.edit->setText(QString(sstream.str().c_str()));
375 var.second.edit->blacken();
378 ERROR_MSG(
"Unable to determine refresh type for component {}",
388 auto n = parameter.find(var_name.toStdString());
390 n->second.edit->setText(comment);
391 const QByteArray textData = comment.toLatin1();
392 const char* text = textData.constData();
394 this->hostPlugin->setComponentParameter<std::string>(param_id, text);
400 auto n = parameter.find(var_name.toStdString());
401 if ((n != parameter.end())
404 n->second.edit->setText(QString::number(value));
405 n->second.str_value = n->second.edit->text();
407 this->hostPlugin->setComponentParameter<
double>(param_id, value);
414 auto n = parameter.find(var_name.toStdString());
415 if ((n != parameter.end())
418 n->second.edit->setText(QString::number(value));
419 n->second.str_value = n->second.edit->text();
421 this->hostPlugin->setComponentParameter<
int>(param_id, value);
428 auto n = parameter.find(var_name.toStdString());
429 if ((n != parameter.end())
432 n->second.edit->setText(QString::number(value));
433 n->second.str_value = n->second.edit->text();
435 this->hostPlugin->setComponentParameter<uint64_t>(param_id, value);
442 if (pauseButton->isChecked() != p) {
443 pauseButton->setDown(p);
458 : event_manager(ev_manager)
459 , name(std::move(mod_name))
465 if (this->plugin_component !=
nullptr) {
469 std::any(
static_cast<RT::Thread*
>(this->plugin_component.get())));
470 this->event_manager->postEvent(&unplug_block_event);
476 if (this->plugin_component ==
nullptr) {
480 event.setParam(
"thread",
481 static_cast<RT::Thread*
>(this->plugin_component.get()));
482 this->event_manager->postEvent(&event);
487 if (!this->plugin_component) {
494 event.setParam(
"state", std::any(state));
495 this->event_manager->postEvent(&event);
498 std::vector<Widgets::Variable::Info>
501 return this->plugin_component->getParametersInfo();
505 std::unique_ptr<Widgets::Component> component)
509 if (this->plugin_component !=
nullptr || component ==
nullptr) {
512 this->plugin_component = std::move(component);
515 this->plugin_component->setActive(
true);
516 this->registerComponent();
521 this->widget_panel = panel;
528 return this->plugin_component->getValue<int64_t>(parameter_id);
534 return this->plugin_component->getValue<uint64_t>(parameter_id);
540 return this->plugin_component->getValue<
double>(parameter_id);
548 if (this->widget_panel !=
nullptr) {
561 if (this->plugin_component !=
nullptr) {
562 active = this->plugin_component->getActive();
569 const int result = 0;
579 std::any(
static_cast<RT::Thread*
>(this->plugin_component.get())));
580 this->event_manager->postEvent(&event);
586 return this->plugin_component.get();
591 return this->event_manager;
596 return this->widget_panel;
void setParam(const std::string ¶m_name, const std::any ¶m_value)
Event::Type getType() const
std::string getName() const
void ERROR_MSG(const std::string &errmsg, Args... args)
@ RT_THREAD_UNPAUSE_EVENT
@ RT_WIDGET_STATE_CHANGE_EVENT