Ver código fonte

Adjust Qt integration with recent changes in sdf importer (#569)

Signed-off-by: Michał Pełka <[email protected]>
Michał Pełka 1 ano atrás
pai
commit
f1e7ff0d38

+ 36 - 34
Gems/ROS2/Code/Source/RobotImporter/Pages/CheckAssetPage.cpp

@@ -102,8 +102,8 @@ namespace ROS2
         const AZStd::optional<AZ::Crc32>& crc32,
         const AZStd::optional<AZStd::string>& resolvedSdfPath)
     {
-        int i = m_table->rowCount();
-        m_table->setRowCount(i + 1);
+        int rowId = m_table->rowCount();
+        m_table->setRowCount(rowId + 1);
 
         // The Asset ID GUID must not be null(all zeros) and the asset source path must not be empty
         bool isOk = (assetSourcePath.has_value() && !assetSourcePath->empty() && assetSourcePath != "not found")
@@ -123,45 +123,43 @@ namespace ROS2
         {
             p->setToolTip(tr("CRC for file : ") + QString::fromUtf8(crcStr.data(), crcStr.size()));
         }
-        m_table->setItem(i, Columns::SdfMeshPath, p);
+        m_table->setItem(rowId, Columns::SdfMeshPath, p);
 
         if (resolvedSdfPath)
         {
             m_table->setItem(
-                i, Columns::ResolvedMeshPath, createCell(true, QString::fromUtf8(resolvedSdfPath->data(), resolvedSdfPath->size())));
+                rowId, Columns::ResolvedMeshPath, createCell(true, QString::fromUtf8(resolvedSdfPath->data(), resolvedSdfPath->size())));
         }
         else
         {
-            m_table->setItem(i, Columns::ResolvedMeshPath, createCell(false, tr("Not found")));
+            m_table->setItem(rowId, Columns::ResolvedMeshPath, createCell(false, tr("Not found")));
         }
 
-        m_table->setItem(i, Columns::Type, createCell(isOk, type));
+        m_table->setItem(rowId, Columns::Type, createCell(isOk, type));
 
         if (assetSourcePath && !assetSourcePath->empty())
         {
             m_table->setItem(
-                i, Columns::SourceAsset, createCell(true, QString::fromUtf8(assetSourcePath->data(), assetSourcePath->size())));
+                rowId, Columns::SourceAsset, createCell(true, QString::fromUtf8(assetSourcePath->data(), assetSourcePath->size())));
+            m_assetsPaths[assetUuid] = *assetSourcePath;
         }
         else
         {
-            m_table->setItem(i, Columns::SourceAsset, createCell(false, tr("Not found")));
+            m_table->setItem(rowId, Columns::SourceAsset, createCell(false, tr("Not found")));
         }
 
         if (isOk)
         {
-            m_table->item(i, Columns::ResolvedMeshPath)->setIcon(m_okIcon);
+            m_table->item(rowId, Columns::ResolvedMeshPath)->setIcon(m_okIcon);
         }
         else
         {
-            m_table->item(i, Columns::ResolvedMeshPath)->setIcon(m_failureIcon);
-            m_table->setItem(i, Columns::ProductAsset, createCell(false, QString()));
+            m_table->item(rowId, Columns::ResolvedMeshPath)->setIcon(m_failureIcon);
+            m_table->setItem(rowId, Columns::ProductAsset, createCell(false, QString()));
         }
-
-        // Don't add an empty asset path to the list of resolved assets
         if (isOk)
         {
-            m_assetsPaths.push_back(AZStd::move(*assetSourcePath));
-            m_assetsUuids.push_back(assetUuid);
+            m_assetsUuidsToColumnIndex[assetUuid] = rowId;
         }
     }
 
@@ -184,7 +182,7 @@ namespace ROS2
 
     void CheckAssetPage::ClearAssetsList()
     {
-        m_assetsUuids.clear();
+        m_assetsUuidsToColumnIndex.clear();
         m_assetsUuidsFinished.clear();
         m_assetsPaths.clear();
         m_table->setRowCount(0);
@@ -195,27 +193,30 @@ namespace ROS2
 
     bool CheckAssetPage::IsEmpty() const
     {
-        return m_assetsUuids.empty();
+        return m_assetsUuidsToColumnIndex.empty();
     }
 
     void CheckAssetPage::DoubleClickRow(int row, [[maybe_unused]] int col)
     {
-        AZ_Printf("CheckAssetPage", "Clicked on row", row);
-        if (row < m_assetsPaths.size())
+        for (const auto& [assetUuid, columnId] : m_assetsUuidsToColumnIndex)
         {
-            AzFramework::AssetSystemRequestBus::Broadcast(
-                &AzFramework::AssetSystem::AssetSystemRequests::ShowInAssetProcessor, m_assetsPaths[row]);
+            if (columnId == row && m_assetsPaths.contains(assetUuid))
+            {
+                AzFramework::AssetSystemRequestBus::Broadcast(
+                    &AzFramework::AssetSystem::AssetSystemRequests::ShowInAssetProcessor, m_assetsPaths[assetUuid]);
+            }
+
         }
     }
 
     void CheckAssetPage::RefreshTimerElapsed()
     {
-        for (int i = 0; i < m_assetsUuids.size(); i++)
+        for (const auto& [assetUuid, rowId] : m_assetsUuidsToColumnIndex)
         {
-            const AZ::Uuid& assetUuid = m_assetsUuids[i];
-            const AZStd::string& sourceAssetFullPath = m_assetsPaths[i];
-            if (!m_assetsUuidsFinished.contains(assetUuid))
+            if (m_assetsPaths.contains(assetUuid) && !m_assetsUuidsFinished.contains(assetUuid))
             {
+                // Execute for all found source assets that are not finished yet.
+                const AZStd::string& sourceAssetFullPath = m_assetsPaths[assetUuid];
                 using namespace AzToolsFramework;
                 using namespace AzToolsFramework::AssetSystem;
 
@@ -225,7 +226,7 @@ namespace ROS2
                 if (result)
                 {
                     bool allFinished = true;
-                    bool failed = false;
+                    bool productAssetFailed = false;
                     JobInfoContainer& allJobs = result.GetValue();
                     for (const JobInfo& job : allJobs)
                     {
@@ -235,13 +236,12 @@ namespace ROS2
                         }
                         if (job.m_status == JobStatus::Failed)
                         {
-                            failed = true;
-                            m_failedCount++;
+                            productAssetFailed = true;
                         }
                     }
                     if (allFinished)
                     {
-                        if (!failed)
+                        if (!productAssetFailed)
                         {
                             const AZStd::vector<AZStd::string> productPaths = Utils::GetProductAssets(assetUuid);
                             QString text;
@@ -249,20 +249,22 @@ namespace ROS2
                             {
                                 text += QString::fromUtf8(productPath.data(), productPath.size()) + " ";
                             }
-                            m_table->setItem(i, Columns::ProductAsset, createCell(true, text));
-                            m_table->item(i, Columns::ProductAsset)->setIcon(m_okIcon);
+                            m_table->setItem(rowId, Columns::ProductAsset, createCell(true, text));
+                            m_table->item(rowId, Columns::ProductAsset)->setIcon(m_okIcon);
                         }
                         else
                         {
-                            m_table->setItem(i, Columns::ProductAsset, createCell(false, tr("Failed")));
-                            m_table->item(i, Columns::ProductAsset)->setIcon(m_failureIcon);
+                            m_table->setItem(rowId, Columns::ProductAsset, createCell(false, tr("Failed")));
+                            m_table->item(rowId, Columns::ProductAsset)->setIcon(m_failureIcon);
+                            m_failedCount++;
                         }
                         m_assetsUuidsFinished.insert(assetUuid);
                     }
                 }
             }
         }
-        if (m_assetsUuidsFinished.size() == m_assetsUuids.size())
+
+        if (m_assetsUuidsFinished.size() == m_assetsUuidsToColumnIndex.size())
         {
             m_refreshTimer->stop();
             if (m_failedCount == 0 && m_missingCount == 0)

+ 3 - 3
Gems/ROS2/Code/Source/RobotImporter/Pages/CheckAssetPage.h

@@ -53,9 +53,9 @@ namespace ROS2
         unsigned int m_missingCount{ 0 };
         unsigned int m_failedCount{ 0 };
         void SetTitle();
-        AZStd::vector<AZ::Uuid> m_assetsUuids;
-        AZStd::vector<AZStd::string> m_assetsPaths;
-        AZStd::unordered_set<AZ::Uuid> m_assetsUuidsFinished;
+        AZStd::unordered_map<AZ::Uuid, int> m_assetsUuidsToColumnIndex; //!< Map of asset UUIDs to column index in the table.
+        AZStd::unordered_map<AZ::Uuid, AZStd::string> m_assetsPaths; //! Map of asset UUIDs to asset source paths.
+        AZStd::unordered_set<AZ::Uuid> m_assetsUuidsFinished; //!< Set of asset UUIDs that have been processed by asset processor.
         void DoubleClickRow(int row, int col);
         void RefreshTimerElapsed();
         QIcon m_failureIcon;