31 #include <QApplication>
41 static const std::string config_key_imrecman =
"imrecman_name";
42 static const std::string config_key_start_in =
"start_in";
54 m_poll_timer->setSingleShot(
false);
55 m_poll_timer->setInterval(50);
58 connect(m_poll_timer, &QTimer::timeout,
this, &this_class::poll_statuses);
59 connect(m_widget.add_image_provider, &QPushButton::clicked,
this, &this_class::add_image_provider);
60 connect(m_widget.copy_config_json, &QPushButton::clicked,
this, &this_class::copy_config_json_to_clipboard);
61 connect(m_widget.config_get, &QPushButton::clicked,
this, &this_class::get_config_from_imrecman);
62 connect(m_widget.config_set, &QPushButton::clicked,
this, &this_class::set_config_at_imrecman);
63 connect(m_widget.start_in, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
this, &this_class::update_start_rec_label);
64 connect(m_widget.start_rec, &QPushButton::clicked,
this, &this_class::start_recordings);
65 connect(m_widget.stop_rec, &QPushButton::clicked,
this, &this_class::stop_recordings);
66 connect(m_widget.edit_mode, &QCheckBox::stateChanged,
this, &this_class::edit_mode_changed);
67 connect(
this, &this_class::component_connected,
this, &this_class::init_gui);
68 connect(
this, &this_class::component_connected,
this, &this_class::get_config_from_imrecman);
69 connect(
this, &this_class::component_connected,
this, &this_class::update_start_rec_label);
70 connect(
this, &this_class::component_disconnected,
this, &this_class::uninit_gui);
72 edit_mode_changed(m_widget.edit_mode->checkState());
81 if (not m_imrecman_name.empty())
83 usingProxy(m_imrecman_name);
93 getProxy(m_imrecman, m_imrecman_name);
95 emit component_connected();
104 emit component_disconnected();
122 m_imrecman_name = settings->value(QString::fromStdString(::config_key_imrecman),
"ImageRecordingManager").toString().toStdString();
123 m_widget.start_in->setValue(settings->value(QString::fromStdString(::config_key_start_in), 1.0).toDouble());
132 settings->setValue(QString::fromStdString(::config_key_imrecman), QString::fromStdString(m_imrecman_name));
133 settings->setValue(QString::fromStdString(::config_key_start_in), m_widget.start_in->value());
142 if (not m_config_dialog)
145 m_config_dialog->
addProxyFinder<ImageRecordingManagerInterfacePrx>({::config_key_imrecman,
"Image recording manager",
"*"});
147 return qobject_cast<QDialog*>(m_config_dialog);
158 m_imrecman_name = m_config_dialog->getProxyName(::config_key_imrecman);
168 for (
const auto& [image_provider_name, config_widget] : m_config_widgets)
170 m_widget.image_providers->layout()->removeWidget(config_widget);
171 config_widget->deleteLater();
173 m_config_widgets.clear();
175 if (not configs.empty())
177 const imrec::Config& ref_config = configs.begin()->second;
178 m_widget.pp_package->setText(QString::fromStdString(ref_config.location.package));
179 m_widget.pp_path->setText(QString::fromStdString(ref_config.location.path));
180 m_widget.recording_name->setText(QString::fromStdString(ref_config.name));
183 for (
const auto& [image_provider_name, config] : configs)
185 add_image_provider_conf_widget(image_provider_name, config);
196 for (
const auto& [image_provider_name,
status] : statuses)
198 if (m_config_widgets.find(image_provider_name) != m_config_widgets.end())
200 m_config_widgets.at(image_provider_name)->setImageProviderStatus(
status);
206 std::optional<imrec::Status> empty_status;
207 for (
const auto& [image_provider_name, config_widget] : m_config_widgets)
209 if (statuses.find(image_provider_name) == statuses.end())
211 m_config_widgets.at(image_provider_name)->setImageProviderStatus(empty_status);
224 m_config_widgets[image_provider_name] = cw;
225 m_widget.image_providers->layout()->addWidget(cw);
230 if (m_widget.auto_sync->isChecked())
232 set_config_at_imrecman();
237 std::map<std::string, visionx::imrec::Config>
242 const IceUtil::Time start_in = IceUtil::Time::secondsDouble(m_widget.start_in->value());
243 const IceUtil::Time start_at = IceUtil::Time::now() + start_in;
245 std::map<std::string, visionx::imrec::Config> configs;
246 visionx::imrec::Config config_template;
247 config_template.location.package = m_widget.pp_package->text().toStdString();
248 config_template.location.path = m_widget.pp_path->text().toStdString();
249 config_template.name = m_widget.recording_name->text().toStdString();
251 if (config_template.name.empty())
253 config_template.name =
"rec_%TIMESTAMP%";
256 for (
const auto& [name, config_widget] : m_config_widgets)
258 config_template.channelConfigs = config_widget->toChannelConfigs();
259 configs[name] = config_template;
266 visionx::ImageRecorderWidgetController::init_gui()
271 m_widget.start_rec->setEnabled(
enabled);
272 m_widget.stop_rec->setEnabled(
enabled);
273 m_widget.config_get->setEnabled(
enabled);
274 m_widget.config_set->setEnabled(
enabled);
275 m_poll_timer->start();
280 visionx::ImageRecorderWidgetController::uninit_gui()
285 m_widget.start_rec->setEnabled(
enabled);
286 m_widget.stop_rec->setEnabled(
enabled);
287 m_widget.config_get->setEnabled(
enabled);
288 m_widget.config_set->setEnabled(
enabled);
289 m_poll_timer->stop();
294 visionx::ImageRecorderWidgetController::poll_statuses()
300 if (m_imrecman->isConfigured())
302 update_statuses(m_imrecman->getRecordingStatuses());
313 visionx::ImageRecorderWidgetController::get_config_from_imrecman()
319 if (m_imrecman->isConfigured())
321 build_ui_from_config(m_imrecman->getConfiguration());
332 visionx::ImageRecorderWidgetController::set_config_at_imrecman()
338 m_imrecman->configureRecordings(to_config_map());
348 visionx::ImageRecorderWidgetController::add_image_provider()
352 visionx::imrec::Config config;
353 add_image_provider_conf_widget(
"image_provider_" +
std::to_string(++m_image_provider_ctr), config);
358 visionx::ImageRecorderWidgetController::copy_config_json_to_clipboard()
362 nlohmann::json j = to_config_map();
363 const std::string config_map_json = j.dump();
364 QClipboard* clipboard = QGuiApplication::clipboard();
365 clipboard->setText(QString::fromStdString(config_map_json));
370 visionx::ImageRecorderWidgetController::update_start_rec_label()
374 QString text =
"Start recordings in ";
375 text += m_widget.start_in->cleanText();
377 m_widget.start_rec->setText(text);
382 visionx::ImageRecorderWidgetController::start_recordings()
388 m_imrecman->configureRecordings(to_config_map());
389 m_imrecman->startRecordings();
399 visionx::ImageRecorderWidgetController::stop_recordings()
407 m_imrecman->stopRecordings();
420 visionx::ImageRecorderWidgetController::edit_mode_changed(
const int state)
423 for (
const auto& [image_provider_name, config_widget] : m_config_widgets)
425 config_widget->setViewMode(viewMode);
431 m_widget.config_get->setEnabled(
true);
432 m_widget.config_set->setEnabled(
true);
433 m_widget.add_image_provider->show();
436 m_widget.config_get->setEnabled(
false);
437 m_widget.config_set->setEnabled(
false);
438 m_widget.add_image_provider->hide();
445 visionx::ImageRecorderWidgetController::rename_image_provider(
const std::string& old_name,
const std::string& new_name)
449 if (m_config_widgets.find(new_name) == m_config_widgets.end())
451 auto node_handler = m_config_widgets.extract(old_name);
452 node_handler.key() = new_name;
453 m_config_widgets.insert(std::move(node_handler));
454 m_config_widgets.at(new_name)->confirmImageProviderName(new_name);
456 if (m_widget.auto_sync->isChecked())
458 set_config_at_imrecman();
463 m_config_widgets.at(new_name)->rejectImageProviderName(new_name);
469 visionx::ImageRecorderWidgetController::remove_image_provider(
const std::string& name)
473 ImageProviderConfigWidget* config_widget = m_config_widgets.at(name);
474 m_widget.image_providers->layout()->removeWidget(config_widget);
475 config_widget->deleteLater();
476 m_config_widgets.erase(m_config_widgets.find(name));
478 if (m_widget.auto_sync->isChecked())
480 set_config_at_imrecman();