Skip to content
Snippets Groups Projects
Commit 122989cc authored by Fabian Tërnava's avatar Fabian Tërnava
Browse files

Merge remote-tracking branch 'origin/feature/forgetting-in-wm-and-em'

parents 916d68b4 e2f30738
No related branches found
No related tags found
1 merge request!422Draft: Memory Viewer LTM Recording Progress bar
Pipeline #17404 passed
Showing
with 334 additions and 104 deletions
......@@ -393,7 +393,7 @@ namespace armarx::armem::server
output.success = true;
armem::wm::Memory m = armarx::fromIce<armem::wm::Memory>(directlStoreInput.memory);
longtermMemory->store(m);
longtermMemory->directlyStore(m);
return output;
}
......
......@@ -18,8 +18,7 @@ namespace armarx::armem::server::ltm
MongoDBStorageMixin::configureMixin(json);
}
Memory::Memory() :
Memory(std::filesystem::path("/tmp/ARMARX/LTM_Exports"), {}, "MemoryExport", "Test")
Memory::Memory() : Memory(std::filesystem::path("/tmp/ltm"), {}, "MemoryExport", "Test")
{
}
......@@ -64,7 +63,8 @@ namespace armarx::armem::server::ltm
{
BufferedBase::stop();
MongoDBStorageMixin::stop();
ARMARX_IMPORTANT << "Storing of data finished";
ARMARX_IMPORTANT << "Storing of data finished, starting to generate and save statistics...";
getAndSaveStatistics();
}
void
......@@ -159,7 +159,8 @@ namespace armarx::armem::server::ltm
processors);
}
void Memory::createPropertyDefinitions(PropertyDefinitionsPtr &defs, const std::string &prefix)
void
Memory::createPropertyDefinitions(PropertyDefinitionsPtr& defs, const std::string& prefix)
{
MemoryBase::createPropertyDefinitions(defs, prefix);
DiskMemoryBase::createPropertyDefinitions(defs, prefix);
......@@ -250,4 +251,59 @@ namespace armarx::armem::server::ltm
// 4. update cache
//CachedBase::addToCache(memory);
}
void
Memory::getAndSaveStatistics()
{
auto firstTimeStarted = this->statistics.firstStarted;
if (!firstTimeStarted.isValid())
{
//No statistics to be saved, as recording was never started
ARMARX_DEBUG << "No Statistics will be saved because firstStarted is invalid: "
<< VAROUT(this->statistics.firstStarted);
return;
}
ARMARX_INFO << "Preparing to save statistics for " << this->name();
try
{
auto first_stats = this->getFilterStatistics();
if (first_stats.empty())
{
//empty statistics mean no data was recorded and no statistics should be saved
ARMARX_DEBUG << "No Statistics will be saved because no actual data was recorded.";
return;
}
std::map<std::string,
std::map<std::string, ltm::processor::SnapshotFilter::FilterStatistics>>
information;
std::map<std::string, armarx::core::time::DateTime> times;
try
{
times["Started LTM1"] = this->getStatistics().lastStarted;
times["Stopped LTM1"] = this->getStatistics().lastStopped;
information["LTM"] = first_stats;
}
catch (...)
{
ARMARX_INFO << "Something went wrong after getting the statistics";
}
auto exportPath = this->getMemoryBasePath();
auto exportName = this->getExportName();
auto recording_started = this->getStatistics().lastStarted;
auto recording_stopped = this->getStatistics().lastStopped;
test::save_statistics(information,
times,
recording_started,
recording_stopped,
exportPath,
exportName,
this->name());
}
catch (...)
{
ARMARX_INFO << "Something went wrong with the statistics saving process";
}
}
} // namespace armarx::armem::server::ltm
......@@ -49,6 +49,11 @@ namespace armarx::armem::server::ltm
void createPropertyDefinitions(PropertyDefinitionsPtr& defs, const std::string& prefix) override;
/**
* @brief getAndSaveStatistics generates and saves statistics for a LTM recording
*/
void getAndSaveStatistics();
protected:
void _loadAllReferences(armem::wm::Memory&) final;
void _resolve(armem::wm::Memory&) final;
......
#include "MemoryBase.h"
namespace armarx::armem::server::ltm
namespace armarx::armem::server::ltm::detail
{
} // namespace armarx::armem::server::ltm
} // namespace armarx::armem::server::ltm::detail
......@@ -17,8 +17,8 @@
#include <RobotAPI/libraries/armem/core/operations.h>
#include <RobotAPI/libraries/armem/core/wm/aron_conversions.h>
#include <RobotAPI/libraries/armem/core/wm/memory_definitions.h>
#include <RobotAPI/libraries/armem/server/wm/memory_definitions.h>
#include <RobotAPI/libraries/armem/server/test/ForgettingExperiments.h>
#include <RobotAPI/libraries/armem/server/wm/memory_definitions.h>
namespace armarx::armem::server::ltm::detail
{
......@@ -35,6 +35,8 @@ namespace armarx::armem::server::ltm::detail
bool firstStop = true;
armarx::core::time::DateTime firstStarted = armarx::core::time::DateTime::Invalid();
armarx::core::time::DateTime firstStopped = armarx::core::time::DateTime::Invalid();
armarx::core::time::DateTime lastStarted = armarx::core::time::DateTime::Invalid();
armarx::core::time::DateTime lastStopped = armarx::core::time::DateTime::Invalid();
};
public:
......@@ -79,14 +81,18 @@ namespace armarx::armem::server::ltm::detail
void
enable()
{
processors->resetFilterStatisticsForNewEpisode(); //make sure the statistics are
//resetted before the recording starts
auto now = armarx::core::time::DateTime::Now();
ARMARX_INFO << "Enabling LTM " << id().str() << " at " << now.toDateTimeString();
ARMARX_INFO << "Storing information at " << this->getExportName();
enabled = true;
if(statistics.firstStart){
statistics.firstStarted = armarx::core::time::DateTime::Now();
if (statistics.firstStart)
{
statistics.firstStarted = now;
statistics.firstStart = false;
}
statistics.lastStarted = now;
this->_enable();
}
......@@ -97,10 +103,12 @@ namespace armarx::armem::server::ltm::detail
auto now = armarx::core::time::DateTime::Now();
ARMARX_INFO << "Disabling LTM " << id().str() << " at " << now.toDateTimeString();
enabled = false;
if(statistics.firstStop){
statistics.firstStopped = armarx::core::time::DateTime::Now();
if (statistics.firstStop)
{
statistics.firstStopped = now;
statistics.firstStop = false;
}
statistics.lastStopped = now;
this->_disable();
ARMARX_INFO << "Disabling of LTM finished";
}
......@@ -166,7 +174,7 @@ namespace armarx::armem::server::ltm::detail
return;
}
}
_store(memory);
_directlyStore(memory);
TIMING_END_STREAM(LTM_Memory_Append, ARMARX_DEBUG);
}
......@@ -193,7 +201,7 @@ namespace armarx::armem::server::ltm::detail
createPropertyDefinitions(PropertyDefinitionsPtr& defs, const std::string& prefix)
{
defs->optional(p.enabled_on_startup, prefix + "enabled");
defs->optional(p.configuration_on_startup, prefix + "configuration");
defs->optional(p.configuration_on_startup, prefix + "configuration");
defs->optional(p.export_name, prefix + "exportName");
}
......@@ -235,12 +243,20 @@ namespace armarx::armem::server::ltm::detail
}
std::map<std::string, processor::SnapshotFilter::FilterStatistics>
getFilterStatistics(){
try{
getFilterStatistics()
{
try
{
ARMARX_INFO << "Trying to save statistics";
auto stats = processors->getSnapshotFilterStatistics();
return stats;
}catch(...){
}
catch (InvalidArgumentException& e)
{ //no data was actually recorded
ARMARX_INFO << e.what();
}
catch (...)
{
ARMARX_WARNING << "Saving statistics did not work";
}
std::map<std::string, processor::SnapshotFilter::FilterStatistics> emptyStatistics;
......@@ -279,6 +295,7 @@ namespace armarx::armem::server::ltm::detail
virtual void _loadAllReferences(armem::wm::Memory& memory) = 0;
virtual void _resolve(armem::wm::Memory& memory) = 0;
virtual void _store(const armem::wm::Memory& memory) = 0;
virtual void _directlyStore(const armem::wm::Memory& memory) = 0;
public:
// stuff for scenario parameters
......@@ -286,9 +303,10 @@ namespace armarx::armem::server::ltm::detail
{
bool enabled_on_startup = false;
std::string configuration_on_startup =
"{ \"SnapshotFrequencyFilter\": {\"WaitingTimeInMsForFilter\" : 1000}, \"PngConverter\": {}}";
std::string export_name ="MemoryExport";
std::string export_path = "/tmp";
"{ \"SnapshotFrequencyFilter\": {\"WaitingTimeInMsForFilter\" : 50}, "
"\"PngConverter\": {}, \"ExrConverter\": {}}"; //record with 20 fps as standard
std::string export_name = "MemoryExport";
std::string export_path = "/tmp/ltm";
} p;
protected:
......
......@@ -24,13 +24,15 @@ namespace armarx::armem::server::ltm
f->configure(config[processor::filter::SnapshotFrequencyFilter::NAME]);
snapFilters.push_back(std::move(f));
}
if(config.contains(processor::filter::SnapshotSimilarityFilter::NAME)){
if (config.contains(processor::filter::SnapshotSimilarityFilter::NAME))
{
ARMARX_IMPORTANT << "ADDING SNAPSHOT SIMILARITY FILTER";
auto f = std::make_unique<processor::filter::SnapshotSimilarityFilter>();
f->configure(config[processor::filter::SnapshotSimilarityFilter::NAME]);
snapFilters.push_back(std::move(f));
}
if(config.contains(processor::filter::SnapshotImportanceFilter::NAME)){
if (config.contains(processor::filter::SnapshotImportanceFilter::NAME))
{
ARMARX_IMPORTANT << "ADDING SNAPSHOT IMPORTANCE FILTER";
auto f = std::make_unique<processor::filter::SnapshotImportanceFilter>();
f->configure(config[processor::filter::SnapshotImportanceFilter::NAME]);
......@@ -54,13 +56,36 @@ namespace armarx::armem::server::ltm
}
}
std::map<std::string, processor::SnapshotFilter::FilterStatistics> Processors::getSnapshotFilterStatistics()
std::map<std::string, processor::SnapshotFilter::FilterStatistics>
Processors::getSnapshotFilterStatistics()
{
std::map<std::string, processor::SnapshotFilter::FilterStatistics> stats;
bool recordedOverall = false;
ARMARX_INFO << "Number of active filters: " << snapFilters.size();
for(int i = 0; i < snapFilters.size(); i++){
stats[snapFilters.at(i)->getName()] = snapFilters.at(i)->getFilterStatistics();
for (int i = 0; i < snapFilters.size(); i++)
{
auto statistics = snapFilters.at(i)->getFilterStatistics();
auto recorded = statistics.accepted + statistics.rejected;
stats[snapFilters.at(i)->getName()] = statistics;
if (recorded > 0)
{
recordedOverall = true;
}
}
if (!recordedOverall)
{
throw InvalidArgumentException(
"NoFilters recorded any data being accepted or rejected, "
"cant store empty statistics");
}
return stats;
}
void Processors::resetFilterStatisticsForNewEpisode()
{
ARMARX_DEBUG << "Resetting statistics for filters";
for(const auto& filter_ptr: this->snapFilters){
filter_ptr->resetStatisticsForNewEpisode();
}
}
} // namespace armarx::armem::server::ltm
......@@ -25,6 +25,12 @@ namespace armarx::armem::server::ltm
std::map<std::string, processor::SnapshotFilter::FilterStatistics> getSnapshotFilterStatistics();
/**
* @brief resetFilterStatisticsForNewEpisode runs resetFilterStatisticsForNewEpisode on all
* snapshot filters
*/
void resetFilterStatisticsForNewEpisode();
public:
// Unique Memory Filters
std::vector<std::unique_ptr<processor::MemoryFilter>> memFilters;
......
......@@ -22,5 +22,12 @@ namespace armarx::armem::server::ltm::processor
return "Base_Filter";
}
void SnapshotFilter::resetStatisticsForNewEpisode()
{
stats.accepted = 0;
stats.rejected = 0;
stats.additional_time = std::chrono::duration<double>::zero();
}
} // namespace armarx::armem::server::ltm::processor
......@@ -46,5 +46,11 @@ namespace armarx::armem::server::ltm::processor
virtual FilterStatistics getFilterStatistics();
virtual std::string getName();
/**
* @brief resetStatisticsForNewEpisode resets the parts of the statistics that are unique
* to one recording cycle (episode)
*/
void resetStatisticsForNewEpisode();
};
} // namespace armarx::armem::server::ltm::processor
......@@ -8,28 +8,49 @@ namespace armarx::armem::server::ltm::processor::filter
bool
SnapshotFrequencyFilter::accept(const armem::wm::EntitySnapshot &e)
{
//accepting to many elements makes the filter slow and brings problems with the buffer with itself!
//accepting to many elements makes the filter slow and brings problems with the buffer with itself.
// set default values for used variables:
auto start = std::chrono::high_resolution_clock::now();
bool instances_accepted = false;
std::int64_t current;
std::int64_t current = 0;
// get entity id of this snapshot:
auto memID = e.id().getEntityID();
if(this->lastTime < 1){ //this is the first instance to be saved
lastTime = e.time().toMilliSecondsSinceEpoch();
auto end = std::chrono::high_resolution_clock::now();
stats.end_time = end;
stats.additional_time += (end - start);
stats.accepted += 1;
return true; //the first one is always accepted
}
if(this->lastTimesPerEntity.end() == this->lastTimesPerEntity.find(memID)){
//this happens if the key is not in the map, which means this is the first time this
//entity tries to save a snapshot
ARMARX_INFO << "First time this entity is saved";
auto firstIndex = e.getInstanceIndices()[0];
auto firstInsance = e.getInstance(firstIndex);
auto lastT = firstInsance.metadata().sentTime.toMilliSecondsSinceEpoch();
//for statistics sake:
auto end = std::chrono::high_resolution_clock::now();
stats.end_time = end;
stats.additional_time += (end - start);
stats.accepted += 1;
//add this last time to the map:
this->lastTimesPerEntity[memID] = lastT;
return true; //the first one is always accepted
} else {
auto lastTime = this->lastTimesPerEntity.at(memID);
e.forEachInstance([this, &instances_accepted, &current](armem::wm::EntityInstance& i){
int difference = std::abs(i.metadata().sentTime.toMilliSecondsSinceEpoch() - lastTime);
if(difference > this->maxDifference){ //at least one instance is older than the last saved instance
instances_accepted = true;
current = i.metadata().sentTime.toMilliSecondsSinceEpoch();
// check if any one of the instances for this snapshot were sent in the last x
// milliseconds since a snapshot was accepted last for this entity:
e.forEachInstance([this, &instances_accepted, &current, &lastTime](armem::wm::EntityInstance& i){
int difference = std::abs(i.metadata().sentTime.toMilliSecondsSinceEpoch() - lastTime);
if(difference > this->maxDifference){ //at least one instance is older than the last saved instance
instances_accepted = true;
current = i.metadata().sentTime.toMilliSecondsSinceEpoch();
}
});
if(instances_accepted){ //if one of the instances was accepted the time when an
//instance was accepted last needs to be changed
this->lastTimesPerEntity[memID] = current;
}
});
}
//set stats:
auto end = std::chrono::high_resolution_clock::now();
......@@ -37,7 +58,6 @@ namespace armarx::armem::server::ltm::processor::filter
stats.additional_time += (end - start);
if(instances_accepted){
lastTime = current;
this->stats.accepted += 1;
} else {
this->stats.rejected += 1;
......
......@@ -21,8 +21,7 @@ namespace armarx::armem::server::ltm::processor::filter
std::string getName() override;
private:
std::map<MemoryID, std::int64_t> lastTimesPerEntity;
int maxDifference = 0;
std::int64_t lastTime = 0;
};
} // namespace armarx::armem::server::ltm::processor::filter
#include "Plugin.h"
#include <chrono>
#include "ArmarXCore/util/CPPUtility/trace.h"
#include <ArmarXCore/core/Component.h>
#include <ArmarXCore/core/exceptions/local/ExpressionException.h>
......@@ -8,8 +10,6 @@
#include <RobotAPI/libraries/armem/client/util/MemoryListener.h>
#include <RobotAPI/libraries/armem/core/error.h>
#include <chrono>
namespace armarx::armem::server::plugins
{
......@@ -94,35 +94,60 @@ namespace armarx::armem::server::plugins
void
Plugin::preOnDisconnectComponent()
{
/*
ARMARX_INFO << "Preparing to save statistics for " << this->workingMemory.name();
try{
try
{
auto first_stats = longtermMemory.getFilterStatistics();
std::map<std::string, std::map<std::string, ltm::processor::SnapshotFilter::FilterStatistics>> information;
std::map<std::string,
std::map<std::string, ltm::processor::SnapshotFilter::FilterStatistics>>
information;
std::map<std::string, armarx::core::time::DateTime> times;
try{
try
{
times["Started LTM1"] = longtermMemory.getStatistics().firstStarted;
times["Stopped LTM1"] = longtermMemory.getStatistics().firstStopped;
information["LTM"] = first_stats;
} catch(...){
}
catch (...)
{
ARMARX_INFO << "Something went wrong after getting the statistics";
}
auto exportPath = longtermMemory.getMemoryBasePath();
auto exportName = longtermMemory.getExportName();
auto recording_started = longtermMemory.getStatistics().firstStarted;
auto recording_stopped = longtermMemory.getStatistics().firstStopped;
test::save_statistics(information, times, recording_started, recording_stopped,
exportPath, exportName, longtermMemory.name());
}catch (...){
test::save_statistics(information,
times,
recording_started,
recording_stopped,
exportPath,
exportName,
longtermMemory.name());
}
catch (...)
{
ARMARX_INFO << "Something went wrong with the statistics saving process";
}
}
statistics_saved = true;
*/
try{
if(longtermMemory.isRecording()){
ARMARX_INFO << "Recording still in progress, stopping component anyways. "
"Saving statistics...";
longtermMemory.getAndSaveStatistics();
}
} catch(...){
ARMARX_WARNING << "Statistics could not be saved for recording that was interrupted by "
"disconnecting the component";
}
if (clientPlugin->isMemoryNameSystemEnabled() and clientPlugin->getMemoryNameSystemClient())
{
removeServer();
}
}
}
void
......@@ -181,7 +206,6 @@ namespace armarx::armem::server::plugins
result.success = true;
ARMARX_DEBUG << "Removed memory server for " << id
<< " from the Memory Name System (MNS).";
}
catch (const armem::error::ServerRegistrationOrRemovalFailed& e)
{
......
......@@ -84,6 +84,7 @@ void save_statistics(
//get current date:
auto now = std::chrono::high_resolution_clock::now();
auto now_ax_datetime = DateTime::Now();
auto now_time = std::chrono::high_resolution_clock::to_time_t(now);
auto time = localtime(&now_time);
......@@ -97,6 +98,12 @@ void save_statistics(
bool ended_without_recording = false;
if(firstStoppedRecording.toMilliSecondsSinceEpoch() < firstStartedRecording.toMilliSecondsSinceEpoch()){
//this can happen if the recording is not propperly stopped but interrupted by stopping
//the component
firstStoppedRecording = now_ax_datetime;
}
for(const auto& filter: stats){
filter_statistics(filter.second, memoryName,firstStartedRecording, firstStoppedRecording, &jsonData);
}
......
......@@ -25,39 +25,38 @@
#include <map>
#include <vector>
#include <RobotAPI/libraries/aron/core/data/variant/All.h>
#include <RobotAPI/libraries/armem/server/ltm/processors/filter/Filter.h>
#include <RobotAPI/libraries/aron/core/data/variant/All.h>
namespace armarx::armem::server::test
{
void save_statistics(
std::map<std::string, std::map<std::string, ltm::processor::SnapshotFilter::FilterStatistics>> stats,
std::map<std::string, armarx::core::time::DateTime> time_stats,
armarx::core::time::DateTime firstStartedRecording,
armarx::core::time::DateTime firstStoppedRecording,
std::filesystem::path exportPath = "/tmp",
std::string exportName ="MemoryExports",
std::string memoryName = "",
std::string sim_json_data = "",
std::string object_memory_json_data = ""
);
std::map<std::string,
std::map<std::string, ltm::processor::SnapshotFilter::FilterStatistics>> stats,
std::map<std::string, armarx::core::time::DateTime> time_stats,
armarx::core::time::DateTime firstStartedRecording,
armarx::core::time::DateTime firstStoppedRecording,
std::filesystem::path exportPath = "/tmp/ltm",
std::string exportName = "MemoryExports",
std::string memoryName = "",
std::string sim_json_data = "",
std::string object_memory_json_data = "");
nlohmann::json load_scene_information(std::string om_or_sim);
nlohmann::json find_difference(nlohmann::json om, nlohmann::json sim);
std::filesystem::path getStatisticsDirectory(
std::filesystem::path exportPath = "/tmp",
std::string exportName ="MemoryExports",
std::string memoryName = "NoMemoryName");
std::filesystem::path getStatisticsDirectory(std::filesystem::path exportPath = "/tmp/ltm",
std::string exportName = "MemoryExports",
std::string memoryName = "NoMemoryName");
nlohmann::json filter_statistics_comparison();
void filter_statistics(
std::map<std::string, ltm::processor::SnapshotFilter::FilterStatistics> statistics_processors,
std::string memoryName,
armarx::core::time::DateTime firstStartedRecording,
armarx::core::time::DateTime firstStoppedRecording,
nlohmann::json* statistics);
void filter_statistics(std::map<std::string, ltm::processor::SnapshotFilter::FilterStatistics>
statistics_processors,
std::string memoryName,
armarx::core::time::DateTime firstStartedRecording,
armarx::core::time::DateTime firstStoppedRecording,
nlohmann::json* statistics);
}
} // namespace armarx::armem::server::test
......@@ -7,16 +7,16 @@
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QScrollArea>
#include <QSpinBox>
#include <QTabWidget>
#include <QVBoxLayout>
#include <QWidget>
#include <QScrollArea>
#include <ArmarXCore/core/exceptions/local/ExpressionException.h>
namespace armarx::armem::gui
{
......@@ -60,18 +60,49 @@ namespace armarx::armem::gui
vboxlayout->addWidget(_dropDisabledCheckBox);
auto* recDepthHLayout = new QHBoxLayout();
_recursionDepthLabel = new QLabel("Link resolution depth:");
recDepthHLayout->addWidget(_recursionDepthLabel);
_recursionDepthLabel->setFixedWidth(200);
_recursionDepthSpinner = new QSpinBox(); // NOLINT
_recursionDepthSpinner->setRange(-1, std::numeric_limits<int>::max());
_recursionDepthSpinner->setValue(0);
_recursionDepthSpinner->setEnabled(_dataCheckBox->isChecked());
_recursionDepthSpinner->setSpecialValueText(QString("Unlimited"));
recDepthHLayout->addWidget(_recursionDepthSpinner);
_recursionDepthLabel = new QLabel("Link resolution depth");
recDepthHLayout->addWidget(_recursionDepthLabel);
recDepthHLayout->addStretch();
vboxlayout->addLayout(recDepthHLayout);
/*
auto* exportPathHLayout = new QHBoxLayout();
_exportPathLabel = new QLabel("Export path:");
exportPathHLayout->addWidget(_exportPathLabel);
_exportPathLabel->setFixedWidth(200);
_exportPathLineEdit = new QLineEdit();
exportPathHLayout->addWidget(_exportPathLineEdit);
exportPathHLayout->setStretchFactor(_exportPathLineEdit, 4);
_exportPathConfirmButton = new QPushButton("Confirm Path");
exportPathHLayout->addWidget(_exportPathConfirmButton);
_exportPathConfirmButton->setFixedWidth(100);
vboxlayout->addLayout(exportPathHLayout);
auto* exportNameHLayout = new QHBoxLayout();
_exportNameLabel = new QLabel("Export name:");
exportNameHLayout->addWidget(_exportNameLabel);
_exportNameLabel->setFixedWidth(200);
_exportNameLineEdit = new QLineEdit();
exportNameHLayout->addWidget(_exportNameLineEdit);
exportNameHLayout->setStretchFactor(_exportNameLineEdit, 4);
_exportNameConfirmButton = new QPushButton("Confirm Name");
exportNameHLayout->addWidget(_exportNameConfirmButton);
_exportNameConfirmButton->setFixedWidth(100);
vboxlayout->addLayout(exportNameHLayout);
*/
auto ltmButtonsLayout = new QVBoxLayout();
_storeInLTMButton = new QPushButton("Query and store in LTM");
ltmButtonsLayout->addWidget(_storeInLTMButton);
......@@ -91,17 +122,27 @@ namespace armarx::armem::gui
vlayout->addLayout(hlayout);
// Public connections.
/*
connect(_exportPathConfirmButton, &QPushButton::pressed, this, [=]() {
confirmExportPath(_exportPathLineEdit->text().toStdString());
});
connect(_exportNameConfirmButton, &QPushButton::pressed, this, [=]() {
confirmExportPath(_exportNameLineEdit->text().toStdString());
});
*/
connect(_storeInLTMButton, &QPushButton::pressed, this, &This::storeInLTM);
connect(_startLTMRecordingButton, &QPushButton::pressed, this, &This::startRecording);
connect(_stopLTMRecordingButton, &QPushButton::pressed, this, &This::stopRecording);
// Private connections.
connect(_dataCheckBox, &QCheckBox::stateChanged, this, &This::setRecursionDepthSpinnerEnabled);
connect(
_dataCheckBox, &QCheckBox::stateChanged, this, &This::setRecursionDepthSpinnerEnabled);
setLayout(vlayout);
}
void QueryWidget::update(const std::vector<std::string>& activeMemoryNames)
void
QueryWidget::update(const std::vector<std::string>& activeMemoryNames)
{
std::scoped_lock l(enabledMemoriesMutex);
std::vector<std::string> alreadyPresentMemoryCheckboxes;
......@@ -113,14 +154,18 @@ namespace armarx::armem::gui
auto w = _availableMemoriesGroupBox->layout()->itemAt(i)->widget();
QCheckBox* box = static_cast<QCheckBox*>(w);
std::string memoryName = box->text().toStdString();
if (box->isEnabled() && std::find(activeMemoryNames.begin(), activeMemoryNames.end(), memoryName) == activeMemoryNames.end())
if (box->isEnabled() &&
std::find(activeMemoryNames.begin(), activeMemoryNames.end(), memoryName) ==
activeMemoryNames.end())
{
// checkbox is enabled but memory is not available anymore
box->setVisible(false);
box->setChecked(false);
box->setEnabled(false);
}
if (not(box->isEnabled()) && std::find(activeMemoryNames.begin(), activeMemoryNames.end(), memoryName) != activeMemoryNames.end())
if (not(box->isEnabled()) &&
std::find(activeMemoryNames.begin(), activeMemoryNames.end(), memoryName) !=
activeMemoryNames.end())
{
// checkbox is disabled but memory is available again
box->setVisible(true);
......@@ -133,7 +178,9 @@ namespace armarx::armem::gui
// Add checkboxes for new memories
for (const auto& memoryName : activeMemoryNames)
{
if (std::find(alreadyPresentMemoryCheckboxes.begin(), alreadyPresentMemoryCheckboxes.end(), memoryName) == alreadyPresentMemoryCheckboxes.end())
if (std::find(alreadyPresentMemoryCheckboxes.begin(),
alreadyPresentMemoryCheckboxes.end(),
memoryName) == alreadyPresentMemoryCheckboxes.end())
{
// new memory available
auto box = new QCheckBox(QString::fromStdString(memoryName));
......@@ -145,24 +192,27 @@ namespace armarx::armem::gui
}
}
armem::query::DataMode QueryWidget::dataMode() const
armem::query::DataMode
QueryWidget::dataMode() const
{
return _dataCheckBox->isChecked()
? armem::query::DataMode::WithData
: armem::query::DataMode::NoData;
return _dataCheckBox->isChecked() ? armem::query::DataMode::WithData
: armem::query::DataMode::NoData;
}
bool QueryWidget::dropRemovedMemories() const
bool
QueryWidget::dropRemovedMemories() const
{
return _dropRemovedCheckBox->isChecked();
}
bool QueryWidget::dropDisabledMemories() const
bool
QueryWidget::dropDisabledMemories() const
{
return _dropDisabledCheckBox->isChecked();
}
std::map<std::string, QueryWidget::ActiveMemoryState> QueryWidget::getAvailableMemoryStates() const
std::map<std::string, QueryWidget::ActiveMemoryState>
QueryWidget::getAvailableMemoryStates() const
{
std::scoped_lock l(enabledMemoriesMutex);
......@@ -189,8 +239,8 @@ namespace armarx::armem::gui
return states;
}
std::vector<std::string> QueryWidget::getEnabledMemories() const
std::vector<std::string>
QueryWidget::getEnabledMemories() const
{
std::scoped_lock l(enabledMemoriesMutex);
......@@ -210,7 +260,8 @@ namespace armarx::armem::gui
return enabledMemoryCheckboxes;
}
int QueryWidget::queryLinkRecursionDepth() const
int
QueryWidget::queryLinkRecursionDepth() const
{
return _recursionDepthSpinner->value();
}
......@@ -229,4 +280,4 @@ namespace armarx::armem::gui
break;
}
}
}
} // namespace armarx::armem::gui
......@@ -2,8 +2,8 @@
#include <mutex>
#include <RobotAPI/libraries/armem/core/query/DataMode.h>
#include <RobotAPI/libraries/armem/client/query/Builder.h>
#include <RobotAPI/libraries/armem/core/query/DataMode.h>
#include "SnapshotSelectorWidget.h"
......@@ -11,6 +11,7 @@ class QWidget;
class QTabWidget;
class QPushButton;
class QGroupBox;
class QLineEdit;
namespace armarx::armem::gui
{
......@@ -21,7 +22,6 @@ namespace armarx::armem::gui
using This = QueryWidget;
public:
enum class ActiveMemoryState
{
FoundAndChecked,
......@@ -51,6 +51,7 @@ namespace armarx::armem::gui
void storeInLTM();
void startRecording();
void stopRecording();
//void confirmExportPath(std::string path);
// ToDo:
// void queryChanged(armem::query::data::Input query);
......@@ -62,9 +63,7 @@ namespace armarx::armem::gui
signals:
private:
QCheckBox* _dataCheckBox;
QCheckBox* _dropRemovedCheckBox;
......@@ -73,6 +72,14 @@ namespace armarx::armem::gui
QLabel* _recursionDepthLabel;
QSpinBox* _recursionDepthSpinner;
QLabel* _exportPathLabel;
QLineEdit* _exportPathLineEdit;
QPushButton* _exportPathConfirmButton;
QLabel* _exportNameLabel;
QLineEdit* _exportNameLineEdit;
QPushButton* _exportNameConfirmButton;
QPushButton* _storeInLTMButton;
QPushButton* _startLTMRecordingButton;
QPushButton* _stopLTMRecordingButton;
......@@ -83,4 +90,4 @@ namespace armarx::armem::gui
mutable std::mutex enabledMemoriesMutex;
};
}
} // namespace armarx::armem::gui
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment