diff --git a/source/RobotAPI/libraries/armem/CMakeLists.txt b/source/RobotAPI/libraries/armem/CMakeLists.txt index 457c62565e215c4d76a686cc73647aeb71397190..b08141a6ef60148532ce3f1097eafacb6ae384b9 100644 --- a/source/RobotAPI/libraries/armem/CMakeLists.txt +++ b/source/RobotAPI/libraries/armem/CMakeLists.txt @@ -40,7 +40,7 @@ set(LIB_FILES core/base/detail/negative_index_semantics.cpp # core/base/CoreSegmentBase.cpp - core/base/EntityBase.cpp + # core/base/EntityBase.cpp core/base/EntityInstanceBase.cpp core/base/EntitySnapshotBase.cpp # core/base/MemoryBase.cpp diff --git a/source/RobotAPI/libraries/armem/core/base/EntitySnapshotBase.h b/source/RobotAPI/libraries/armem/core/base/EntitySnapshotBase.h index 36d7274acedb92271587e3ba941345254033d840..7653136447dbe968d3d53f878ba47619481594fc 100644 --- a/source/RobotAPI/libraries/armem/core/base/EntitySnapshotBase.h +++ b/source/RobotAPI/libraries/armem/core/base/EntitySnapshotBase.h @@ -2,8 +2,8 @@ #include <vector> -#include "../MemoryID.h" -#include "../Time.h" +#include <RobotAPI/libraries/armem/core/MemoryID.h> +#include <RobotAPI/libraries/armem/core/Time.h> #include "EntityInstanceBase.h" #include "detail/MemoryContainerBase.h" diff --git a/source/RobotAPI/libraries/armem/core/base/MemoryBase.h b/source/RobotAPI/libraries/armem/core/base/MemoryBase.h index 80b57801d0031c3b66a7e6b72573290ed8c05a5a..9865f6da1398ac78dda2c704eff1d621b00442f4 100644 --- a/source/RobotAPI/libraries/armem/core/base/MemoryBase.h +++ b/source/RobotAPI/libraries/armem/core/base/MemoryBase.h @@ -3,8 +3,6 @@ #include <map> #include <string> -#include <ArmarXCore/core/logging/Logging.h> - #include "CoreSegmentBase.h" #include "detail/EntityContainerBase.h" #include "detail/iteration_mixins.h" @@ -247,7 +245,7 @@ namespace armarx::armem::base } catch (const armem::error::ContainerEntryAlreadyExists& e) { - ARMARX_INFO << e.what() << "\nIgnoring multiple addition."; + // ARMARX_INFO << e.what() << "\nIgnoring multiple addition."; } } return segments; @@ -278,7 +276,7 @@ namespace armarx::armem::base { this->_checkContainerName(update.entityID.memoryName, this->name()); - auto [inserted, coreSeg] = addCoreSegmentIfMissing(update.entityID.coreSegmentName); + auto [inserted, coreSeg] = _addCoreSegmentIfMissing(update.entityID.coreSegmentName); // Update entry. UpdateResult ret(coreSeg->update(update)); @@ -293,30 +291,6 @@ namespace armarx::armem::base return ret; } - std::pair<bool, CoreSegmentT*> addCoreSegmentIfMissing(const std::string& coreSegmentName) - { - CoreSegmentT* coreSeg; - - auto it = this->_container.find(coreSegmentName); - if (it == this->_container.end()) - { - if (_addMissingCoreSegmentDuringUpdate) - { - // Insert into map. - coreSeg = &addCoreSegment(coreSegmentName); - return {true, coreSeg}; - } - else - { - throw error::MissingEntry::create<CoreSegmentT>(coreSegmentName, *this); - } - } - else - { - coreSeg = &it->second; - return {false, coreSeg}; - } - } /** * @brief Merge another memory into this one. Append all data @@ -324,7 +298,7 @@ namespace armarx::armem::base */ void append(const _Derived& m) { - ARMARX_INFO << "Memory: Merge name '" << m.name() << "' into '" << name() << "'"; + // ARMARX_INFO << "Memory: Merge name '" << m.name() << "' into '" << name() << "'"; m.forEachCoreSegment([this](const CoreSegmentT & coreSeg) { @@ -403,8 +377,8 @@ namespace armarx::armem::base template <class ...Args> CoreSegmentT& _addCoreSegment(const std::string& name, Args... args) { - auto [it, existed] = this->_container.try_emplace(name, args...); - if (existed) + auto [it, inserted] = this->_container.try_emplace(name, args...); + if (not inserted) { throw armem::error::ContainerEntryAlreadyExists( CoreSegmentT::getLevelName(), name, DerivedT::getLevelName(), this->name()); @@ -418,8 +392,36 @@ namespace armarx::armem::base } + std::pair<bool, CoreSegmentT*> _addCoreSegmentIfMissing(const std::string& coreSegmentName) + { + CoreSegmentT* coreSeg; + + auto it = this->_container.find(coreSegmentName); + if (it == this->_container.end()) + { + if (_addMissingCoreSegmentDuringUpdate) + { + // Insert into map. + coreSeg = &addCoreSegment(coreSegmentName); + return {true, coreSeg}; + } + else + { + throw error::MissingEntry::create<CoreSegmentT>(coreSegmentName, *this); + } + } + else + { + coreSeg = &it->second; + return {false, coreSeg}; + } + } + + public: + // ToDo: Remove from base structure - this should be specific to the server versions. + // If necessary at all. bool _addMissingCoreSegmentDuringUpdate = false; }; diff --git a/source/RobotAPI/libraries/armem/core/forward_declarations.h b/source/RobotAPI/libraries/armem/core/forward_declarations.h index 761a8513111d55de8b81ade1af62a60ee18f1f3c..e39274b7c332fe7ee4b0505c3aa7bce8c5c0a8ca 100644 --- a/source/RobotAPI/libraries/armem/core/forward_declarations.h +++ b/source/RobotAPI/libraries/armem/core/forward_declarations.h @@ -1,9 +1,15 @@ #pragma once +namespace IceUtil +{ + class Time; +} + namespace armarx::armem { - // class Time; // Cannot be forward declared (it's a typedef) + using Time = IceUtil::Time; + using Duration = IceUtil::Time; class MemoryID; class Commit; diff --git a/source/RobotAPI/libraries/armem_gui/MemoryViewer.cpp b/source/RobotAPI/libraries/armem_gui/MemoryViewer.cpp index 5e5431e41aa6a94ba8616247ec19a5529ca9927e..802de477cdd143051b6e45f8f2c4d995ebfa4e29 100644 --- a/source/RobotAPI/libraries/armem_gui/MemoryViewer.cpp +++ b/source/RobotAPI/libraries/armem_gui/MemoryViewer.cpp @@ -26,6 +26,8 @@ #include <QSettings> #include <filesystem> +#include <iomanip> + namespace armarx::armem::gui { @@ -218,12 +220,9 @@ namespace armarx::armem::gui { int errorCount = 0; - memoryReaders.clear(); memoryData.clear(); - memoryReaders = mns.getAllReaders(true); - bool dataChanged = false; std::filesystem::path path(memoryControlWidget->getEnteredPath().toStdString()); armem::client::QueryInput input = memoryGroup->queryWidget()->queryInput(); @@ -255,8 +254,6 @@ namespace armarx::armem::gui { ARMARX_WARNING << "Could not import a memory from '" << path << "'. Skipping import."; } - - dataChanged = true; // in any case we update the view (even if there was no result) } else { @@ -265,27 +262,13 @@ namespace armarx::armem::gui TIMING_START(MemoryQuery); { armem::client::QueryResult result = reader.query(input); - if (result) + if (result.success) { - if (auto it = memoryData.find(name); it != memoryData.end()) - { - result.memory.append(it->second); - if (result.memory.empty()) - { - ARMARX_ERROR << "A memory which had data before lost data. This indicates that there is something wrong."; - } - - memoryData[name] = std::move(result.memory); - } - else - { - ARMARX_INFO << "The memory " << name << " has no data after querying."; - } - dataChanged = true; // in any case we update the view (even if there was no result) + memoryData[name] = result.memory; } else { - ARMARX_WARNING << "A query for memory '" << name << "' produced an error: " << result.errorMessage; + ARMARX_INFO << "A query for memory '" << name << "' produced an error: " << result.errorMessage; errorCount++; } } @@ -298,29 +281,19 @@ namespace armarx::armem::gui } } - // Code to output status label information - std::stringstream ss; - auto now = std::chrono::system_clock::now(); - auto in_time_t = std::chrono::system_clock::to_time_t(now); - ss << "Last update: " ;// << std::put_time(std::localtime(&in_time_t), "%Y-%m-%d %X"); + emit memoryDataChanged(); - if (dataChanged) - { - emit memoryDataChanged(); - } - else + // Code to output status label information + if (statusLabel and errorCount > 0) { - ss << "- No query result. "; - } + auto now = std::chrono::system_clock::now(); + auto in_time_t = std::chrono::system_clock::to_time_t(now); - if (errorCount > 0) - { - ss << "The query produced " << errorCount << " errors! Please check log."; - } + std::stringstream ss; + ss << "Last update: " << std::put_time(std::localtime(&in_time_t), "%Y-%m-%d %X"); + ss << "\nThe query produced " << errorCount << " errors! Please check log."; - if (statusLabel) - { - statusLabel->setText(ss.str().c_str()); + statusLabel->setText(QString::fromStdString(ss.str())); } } @@ -447,17 +420,10 @@ namespace armarx::armem::gui std::map<std::string, const armem::wm::Memory*> convMap; for (auto& [name, data] : memoryData) { - /*if (data.has_value()) - { - convMap[name] = &data.value(); - }*/ convMap[name] = &data; } - if (convMap.empty()) - { - return; - } + // if convMap.empty(), we still need to update to remove existing entries. TIMING_START(GuiUpdate); memoryGroup->tree()->update(convMap);