10 #include <QProgressDialog>
12 #include <QApplication>
16 #include <QFileDialog>
30 , _action_saveIntoRosbag(
nullptr)
48 _action_saveAny =
new QAction(QString(
"Store messages in memory for Re-publishing"));
51 settings.value(
"DataStreamROS/storemessagesInMemory",
_action_saveAny->isChecked() );
56 bool store_msg = settings.value(
"DataStreamROS/storemessagesInMemory",
false).toBool();
86 std::vector<uint8_t>
buffer;
125 std::lock_guard<std::mutex> lock(
mutex());
128 catch (std::runtime_error& ex)
132 QMessageBox::warning(
nullptr, tr(
"Error"),
133 QString(
"rosbag::open thrown an exception:\n") +
135 "\nThis message will be shown only once.");
139 const std::string prefixed_topic_name =
_prefix + topic_name;
150 std::piecewise_construct,
151 std::forward_as_tuple(prefixed_topic_name),
154 PlotDataAny& user_defined_data = plot_pair->second;
163 const std::string
key = prefixed_topic_name + (
"/_MSG_INDEX_");
175 using namespace std::chrono;
176 milliseconds wait_time_ms(1000);
178 QProgressDialog progress_dialog;
179 progress_dialog.setLabelText(
"Collecting ROS topic samples to understand data layout. ");
180 progress_dialog.setRange(0, wait_time_ms.count());
181 progress_dialog.setAutoClose(
true);
182 progress_dialog.setAutoReset(
true);
184 progress_dialog.show();
186 auto start_time = system_clock::now();
188 while (system_clock::now() - start_time < (wait_time_ms))
191 int i = duration_cast<milliseconds>(system_clock::now() - start_time).count();
192 progress_dialog.setValue(
i);
193 QApplication::processEvents();
194 if (progress_dialog.wasCanceled())
200 if (progress_dialog.wasCanceled() ==
false)
202 progress_dialog.cancel();
210 auto ret = QMessageBox::warning(
nullptr, tr(
"Disconnected!"),
211 tr(
"The roscore master is not reachable anymore.\n\n"
212 "Do you want to try reconnecting to it? \n"),
213 tr(
"Stop Streaming"), tr(
"Try reconnect"),
nullptr);
228 _spinner = std::make_shared<ros::AsyncSpinner>(1);
241 QMessageBox::warning(
nullptr, tr(
"ROS Stopped"),
"The plugin will be stopped");
252 QMessageBox::warning(
nullptr, tr(
"Warning"), tr(
"Your buffer is empty. Nothing to save.\n"));
256 QFileDialog saveDialog;
257 saveDialog.setAcceptMode(QFileDialog::AcceptSave);
258 saveDialog.setDefaultSuffix(
"bag");
261 if (saveDialog.result() != QDialog::Accepted || saveDialog.selectedFiles().empty())
266 QString fileName = saveDialog.selectedFiles().first();
268 if (fileName.size() > 0)
274 const std::string& topicname =
it.first;
275 const auto& plotdata =
it.second;
278 if (!registered_msg_type){
283 msg.morph(registered_msg_type->getMD5Sum(), registered_msg_type->getDataType(),
284 registered_msg_type->getMessageDefinition());
286 for (
int i = 0;
i < plotdata.size();
i++)
288 const auto& point = plotdata.at(
i);
289 const double msg_time = point.x;
290 const std::any& type_erased_buffer = point.y;
292 if (type_erased_buffer.type() !=
typeid(std::vector<uint8_t>))
298 std::vector<uint8_t> raw_buffer = std::any_cast<std::vector<uint8_t>>(type_erased_buffer);
309 args <<
"reindex" << fileName;
310 process.start(
"rosbag",
args);
347 std::lock_guard<std::mutex> lock(
mutex());
355 std::vector<std::pair<QString, QString>> all_topics;
360 all_topics.push_back(std::make_pair(QString(topic_info.name.c_str()), QString(topic_info.datatype.c_str())));
364 timer.setSingleShot(
false);
365 timer.setInterval(1000);
370 connect(&timer, &QTimer::timeout, [&]() {
376 all_topics.push_back({ QString::fromStdString(topic_info.name), QString::fromStdString(topic_info.datatype) });
381 int res = dialog.exec();
404 _spinner = std::make_shared<ros::AsyncSpinner>(1);