11 #include <QMessageBox>
14 #include <QProgressDialog>
16 #include <QInputDialog>
17 #include <QPushButton>
18 #include <QElapsedTimer>
19 #include <QStandardItemModel>
37 QDomElement elem = doc.createElement(
"parameters");
39 elem.setAttribute(
"use_timestamp",
int(params.use_timestamp));
40 elem.setAttribute(
"clamp_large_arrays",
int(params.clamp_large_arrays));
41 elem.setAttribute(
"max_array_size", params.max_array_size);
42 elem.setAttribute(
"selected_topics", params.selected_topics.join(
';'));
44 parent_element.appendChild(elem);
50 QDomElement elem = parent_element.firstChildElement(
"parameters");
57 params.
use_timestamp = bool(elem.attribute(
"use_timestamp").toInt());
67 static std::vector<const char*> ext = {
"mcap",
"MCAP" };
75 throw std::runtime_error(
"No parsing available");
83 QMessageBox::warning(
nullptr,
"Can't open file",
84 tr(
"Code: %0\n Message: %1")
85 .
arg(
int(status.code))
86 .arg(QString::fromStdString(status.message)));
93 QMessageBox::warning(
nullptr,
"Can't open summary of the file",
94 tr(
"Code: %0\n Message: %1")
95 .
arg(
int(status.code))
96 .arg(QString::fromStdString(status.message)));
99 auto statistics =
reader.statistics();
101 std::unordered_map<int, mcap::SchemaPtr> mcap_schemas;
102 std::unordered_map<int, mcap::ChannelPtr> channels;
103 std::unordered_map<int, MessageParserPtr> parsers_by_channel;
105 std::unordered_map<int, DataTamerParser::Schema> dt_schames;
106 int total_dt_schemas = 0;
108 std::unordered_set<mcap::ChannelId> channels_containing_datatamer_schema;
109 std::unordered_set<mcap::ChannelId> channels_containing_datatamer_data;
111 for (
const auto& [schema_id, schema_ptr] :
reader.schemas())
113 mcap_schemas.insert({ schema_id, schema_ptr });
116 std::set<QString> notified_encoding_problem;
121 for (
const auto& [channel_id, channel_ptr] :
reader.channels())
123 channels.insert({ channel_id, channel_ptr });
124 const auto& schema = mcap_schemas.at(channel_ptr->schemaId);
125 const auto& topic_name = channel_ptr->topic;
126 std::string
definition(
reinterpret_cast<const char*
>(schema->data.data()),
127 schema->data.size());
129 if (schema->name ==
"data_tamer_msgs/msg/Schemas")
131 channels_containing_datatamer_schema.insert(channel_id);
132 total_dt_schemas += statistics->channelMessageCounts.at(channel_id);
134 if (schema->name ==
"data_tamer_msgs/msg/Snapshot")
136 channels_containing_datatamer_data.insert(channel_id);
139 QString channel_encoding = QString::fromStdString(channel_ptr->messageEncoding);
140 QString schema_encoding = QString::fromStdString(schema->encoding);
152 if (notified_encoding_problem.count(schema_encoding) == 0)
154 notified_encoding_problem.insert(schema_encoding);
155 auto msg = QString(
"No parser available for encoding [%0] nor [%1]")
156 .arg(channel_encoding)
157 .arg(schema_encoding);
158 QMessageBox::warning(
nullptr,
"Encoding problem",
msg);
163 auto& parser_factory = it->second;
165 parser_factory->createParser(topic_name, schema->name,
definition, plot_data);
166 parsers_by_channel.insert({ channel_ptr->id,
parser });
178 auto ret = dialog.exec();
179 if (
ret != QDialog::Accepted)
186 std::unordered_set<int> enabled_channels;
188 for (
const auto& [channel_id,
parser] : parsers_by_channel)
194 QString topic_name = QString::fromStdString(channels[channel_id]->
topic);
197 enabled_channels.insert(channel_id);
205 qDebug() << QString::fromStdString(problem.message);
208 auto messages =
reader.readMessages(onProblem);
210 QProgressDialog progress_dialog(
"Loading... please wait",
"Cancel", 0, 0,
nullptr);
211 progress_dialog.setWindowTitle(
"Loading the MCAP file");
212 progress_dialog.setModal(
true);
213 progress_dialog.setAutoClose(
true);
214 progress_dialog.setAutoReset(
true);
215 progress_dialog.setMinimumDuration(0);
216 progress_dialog.show();
217 progress_dialog.setValue(0);
219 size_t msg_count = 0;
221 for (
const auto& msg_view : messages)
223 if (enabled_channels.count(msg_view.channel->id) == 0)
229 double timestamp_sec = double(msg_view.message.publishTime) * 1e-9;
230 auto parser_it = parsers_by_channel.find(msg_view.channel->id);
231 if (parser_it == parsers_by_channel.end())
233 qDebug() <<
"Skipping channeld id: " << msg_view.channel->id;
237 auto parser = parser_it->second;
238 MessageRef msg(msg_view.message.data, msg_view.message.dataSize);
239 parser->parseMessage(
msg, timestamp_sec);
241 if (msg_count++ % 1000 == 0)
243 QApplication::processEvents();
244 if (progress_dialog.wasCanceled())
252 qDebug() <<
"Loaded file in " << timer.elapsed() <<
"milliseconds";