| 652 | } |
| 653 | |
| 654 | void Scene3DConfigPanel::onAddModelClicked() { |
| 655 | if (bound_dock_ == nullptr) { |
| 656 | return; |
| 657 | } |
| 658 | switch (model_source_combo_->currentIndex()) { |
| 659 | case 0: { // File |
| 660 | QSettings settings; |
| 661 | const QString start_dir = settings.value(QString::fromLatin1(kUrdfBrowseDirKey)).toString(); |
| 662 | const QString path = QFileDialog::getOpenFileName( |
| 663 | this, tr("Load URDF"), start_dir, tr("URDF files (*.urdf *.xml);;All files (*)")); |
| 664 | if (path.isEmpty()) { |
| 665 | return; |
| 666 | } |
| 667 | if (bound_dock_ == nullptr) { |
| 668 | return; // the modal event loop can outlive the dock |
| 669 | } |
| 670 | settings.setValue(QString::fromLatin1(kUrdfBrowseDirKey), QFileInfo(path).absolutePath()); |
| 671 | const uint32_t id = bound_dock_->addRobotModelLayer(path).id; |
| 672 | if (id != 0) { |
| 673 | addRobotRow(id, QFileInfo(path).fileName(), path); |
| 674 | } |
| 675 | break; |
| 676 | } |
| 677 | case 1: { // Topic |
| 678 | const auto topics = bound_dock_->robotDescriptionTopics(); |
| 679 | if (topics.isEmpty()) { |
| 680 | MessageBox::information(this, tr("Load robot model"), tr("No robot description topic in this dataset.")); |
| 681 | return; |
| 682 | } |
| 683 | const auto picked = pickRobotDescriptionTopic(this, topics); |
| 684 | if (!picked.has_value()) { |
| 685 | return; |
| 686 | } |
| 687 | if (bound_dock_ == nullptr) { |
| 688 | return; // the modal event loop can outlive the dock |
| 689 | } |
| 690 | // addRobotRow is idempotent, so the row created here is harmless when the |
| 691 | // layerAdded signal (or a pre-existing layer) would have added it anyway. |
| 692 | if (bound_dock_->addTopic(picked->first, sdk::BuiltinObjectType::kRobotDescription, picked->second)) { |
| 693 | addRobotRow(picked->first.id, picked->second, picked->second); |
| 694 | } |
| 695 | break; |
| 696 | } |
| 697 | case 2: { // URL |
| 698 | const auto url = promptUrdfUrl(this); |
| 699 | if (!url.has_value()) { |
| 700 | return; |
| 701 | } |
| 702 | if (bound_dock_ == nullptr) { |
| 703 | return; // the modal event loop can outlive the dock |
| 704 | } |
| 705 | const uint32_t id = bound_dock_->addRobotModelLayerFromUrl(*url).id; |
| 706 | if (id != 0) { |
| 707 | const QString file_name = QUrl(*url).fileName(); |
| 708 | addRobotRow(id, file_name.isEmpty() ? *url : file_name, *url); |
| 709 | } |
| 710 | break; |
| 711 | } |
nothing calls this directly
no test coverage detected