RobotImporterWidget.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #if !defined(Q_MOC_RUN)
  10. #include "Pages/CheckAssetPage.h"
  11. #include "Pages/FileSelectionPage.h"
  12. #include "Pages/IntroPage.h"
  13. #include "Pages/ModifiedURDFWindow.h"
  14. #include "Pages/PrefabMakerPage.h"
  15. #include "Pages/RobotDescriptionPage.h"
  16. #include "Pages/XacroParamsPage.h"
  17. #include "URDF/URDFPrefabMaker.h"
  18. #include "URDF/UrdfParser.h"
  19. #include <AzCore/Asset/AssetCommon.h>
  20. #include <AzCore/std/containers/unordered_map.h>
  21. #include <AzCore/std/parallel/thread.h>
  22. #include <AzCore/std/smart_ptr/shared_ptr.h>
  23. #include <RobotImporter/FixURDF/URDFModifications.h>
  24. #include <RobotImporter/Utils/RobotImporterUtils.h>
  25. #include <RobotImporter/xacro/XacroUtils.h>
  26. #include <AzToolsFramework/API/ToolsApplicationAPI.h>
  27. #include <AzToolsFramework/Prefab/PrefabFocusInterface.h>
  28. #include <QCheckBox>
  29. #include <QFileDialog>
  30. #include <QFileSystemModel>
  31. #include <QHeaderView>
  32. #include <QLabel>
  33. #include <QLineEdit>
  34. #include <QMessageBox>
  35. #include <QPushButton>
  36. #include <QTableWidget>
  37. #include <QTextEdit>
  38. #include <QTimer>
  39. #include <QVBoxLayout>
  40. #include <QWidget>
  41. #include <QWizard>
  42. #include <QWizardPage>
  43. #endif
  44. namespace ROS2RobotImporter
  45. {
  46. class RobotImporterWidget;
  47. class URDFPrefabMaker;
  48. //! Handles UI for the process of URDF importing
  49. class RobotImporterWidget : public QWizard
  50. {
  51. Q_OBJECT
  52. public:
  53. explicit RobotImporterWidget(QWidget* parent = nullptr);
  54. void CreatePrefab(AZStd::string prefabName);
  55. private:
  56. int nextId() const override;
  57. bool validateCurrentPage() override;
  58. void OpenUrdf();
  59. void OnUrdfCreated();
  60. void onCreateButtonPressed();
  61. void onSaveModifiedUrdfPressed();
  62. void onShowModifiedUrdfPressed();
  63. IntroPage* m_introPage;
  64. FileSelectionPage* m_fileSelectPage;
  65. RobotDescriptionPage* m_robotDescriptionPage;
  66. CheckAssetPage* m_assetPage;
  67. PrefabMakerPage* m_prefabMakerPage;
  68. XacroParamsPage* m_xacroParamsPage;
  69. ModifiedURDFWindow* m_modifiedUrdfWindow;
  70. AZ::IO::Path m_urdfPath;
  71. sdf::Root m_parsedSdf{};
  72. //! User's choice to copy meshes during urdf import
  73. bool m_importAssetWithUrdf{ false };
  74. /// mapping from urdf path to asset source
  75. AZStd::shared_ptr<Utils::UrdfAssetMap> m_urdfAssetsMapping;
  76. AZStd::shared_ptr<AZStd::thread> m_copyReferencedAssetsThread;
  77. AZStd::unique_ptr<URDFPrefabMaker> m_prefabMaker;
  78. Utils::AssetFilenameReferences m_assetNames;
  79. /// Xacro params
  80. Utils::xacro::Params m_params;
  81. // Assets ready to be processed by asset processor
  82. AZStd::set<AZ::IO::Path> m_toProcessAssets;
  83. void onCurrentIdChanged(int id);
  84. void FillAssetPage();
  85. void FillPrefabMakerPage();
  86. //! Checks if the asset is finished processing by asset processor.
  87. //! @param assetGlobalPath global path to the asset.
  88. //! @return True if asset is finished processing, false if it an error occurred, and AZ::Failure if the asset is not finished
  89. //! processing.
  90. static AZ::Outcome<bool> CheckIfAssetFinished(const AZStd::string& assetGlobalPath);
  91. //! Checks all assets that are in the m_toProcessAssets set and emits signals based on results.
  92. void CheckToProcessAssets();
  93. //! Checks if the asset is finished processing by asset processor. Timer callback.
  94. void RefreshTimerElapsed();
  95. QTimer* m_refreshTimerCheckAssets{};
  96. //! Variable used to start the timer as the timer start function cannot be called from a different thread.
  97. AZStd::atomic_bool m_shouldCheckAssets{ false };
  98. //! Checks if the importedPrefabFilename is the same as focused prefab name.
  99. //! @param importedPrefabFilename name of imported prefab
  100. //! @return True if names of prefabs are identical or an error occurred during validation
  101. bool CheckCyclicalDependency(AZ::IO::Path importedPrefabFilename);
  102. //! Report an error to the user.
  103. //! Populates the log, sets status information in the status label and shows an error popup with the message
  104. //! @param errorMessage error message to display to the user
  105. void ReportError(const QString& errorMessage);
  106. void AddModificationWarningsToReportString(QString& report, const UrdfParser::RootObjectOutcome& parsedSdfOutcome);
  107. static constexpr QWizard::WizardButton PrefabCreationButtonId{ QWizard::CustomButton1 };
  108. static constexpr QWizard::WizardOption HavePrefabCreationButton{ QWizard::HaveCustomButton1 };
  109. };
  110. } // namespace ROS2RobotImporter