| 320 | } |
| 321 | |
| 322 | bool AppSession::focusPlaybackOnDatasets(const std::vector<DatasetId>& datasets) { |
| 323 | if (datasets.empty()) { |
| 324 | return false; |
| 325 | } |
| 326 | const DataReader reader = session_manager_->createReader(); |
| 327 | const ObjectStore& object_store = session_manager_->objectStore(); |
| 328 | |
| 329 | // Scalar series first: receive-time stamped, they ARE the user-visible |
| 330 | // window of an import. Object topics (tf, markers, pointclouds) often carry |
| 331 | // payload-embedded stamps that legitimately predate the import window |
| 332 | // (tf_static = node start, latched markers = creation time), so they only |
| 333 | // define the range when the import contains no scalar data at all. Bounds |
| 334 | // are tracked in DISPLAY-relative seconds, converting each item with its |
| 335 | // dataset's own offset (display_time = raw_time - offset) so the focused |
| 336 | // range matches the rendered axis — same boundary contract as |
| 337 | // seedPlaybackFromSession. |
| 338 | std::optional<DisplaySeconds> scalar_min; |
| 339 | std::optional<DisplaySeconds> scalar_max; |
| 340 | std::optional<DisplaySeconds> object_min; |
| 341 | std::optional<DisplaySeconds> object_max; |
| 342 | |
| 343 | for (const DatasetId dataset_id : datasets) { |
| 344 | const DisplayOffset offset = session_manager_->displayOffset(dataset_id); |
| 345 | for (const TopicId topic_id : reader.listTopics(dataset_id)) { |
| 346 | const auto metadata = reader.getMetadata(topic_id); |
| 347 | if (!metadata.has_value() || metadata->total_row_count == 0) { |
| 348 | continue; |
| 349 | } |
| 350 | const DisplaySeconds ds_min = rawToDisplaySeconds(metadata->time_range_min, offset); |
| 351 | const DisplaySeconds ds_max = rawToDisplaySeconds(metadata->time_range_max, offset); |
| 352 | scalar_min = scalar_min ? std::min(*scalar_min, ds_min) : ds_min; |
| 353 | scalar_max = scalar_max ? std::max(*scalar_max, ds_max) : ds_max; |
| 354 | } |
| 355 | for (const ObjectTopicId object_topic_id : object_store.listTopics(dataset_id)) { |
| 356 | if (object_store.entryCount(object_topic_id) == 0) { |
| 357 | continue; |
| 358 | } |
| 359 | const auto [o_min, o_max] = object_store.timeRange(object_topic_id); |
| 360 | const DisplaySeconds ds_min = rawToDisplaySeconds(o_min, offset); |
| 361 | const DisplaySeconds ds_max = rawToDisplaySeconds(o_max, offset); |
| 362 | object_min = object_min ? std::min(*object_min, ds_min) : ds_min; |
| 363 | object_max = object_max ? std::max(*object_max, ds_max) : ds_max; |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | const std::optional<DisplaySeconds> t_min = scalar_min ? scalar_min : object_min; |
| 368 | const std::optional<DisplaySeconds> t_max = scalar_min ? scalar_max : object_max; |
| 369 | if (!t_min) { |
| 370 | return false; |
| 371 | } |
| 372 | playback_engine_->setRange(DisplayRange{*t_min, *t_max}); |
| 373 | playback_engine_->setCurrentTime(*t_min); |
| 374 | playback_seeded_ = true; |
| 375 | return true; |
| 376 | } |
| 377 | |
| 378 | } // namespace PJ |