diff --git a/source/RobotAPI/components/armem/server/GraspMemory/GraspMemory.cpp b/source/RobotAPI/components/armem/server/GraspMemory/GraspMemory.cpp index 2e42dc474eec6e9ce31bb1ff32ed9b7af9275cff..f173a22913b4d46432eaeebab90ab6ff8e254876 100644 --- a/source/RobotAPI/components/armem/server/GraspMemory/GraspMemory.cpp +++ b/source/RobotAPI/components/armem/server/GraspMemory/GraspMemory.cpp @@ -65,7 +65,7 @@ namespace armarx::armem::server::grasp { // This function is overloaded to trigger the remote gui rebuild. armem::data::CommitResult result = ReadWritePluginUser::commit(commit); - tab.rebuild = true; + gui.tab.rebuild = true; return result; } @@ -80,28 +80,188 @@ namespace armarx::armem::server::grasp void GraspMemory::createRemoteGuiTab() { + //add all instances to map + workingMemory().getCoreSegment("GraspCandidate").forEachInstance([this](const auto & instance) + { + if (gui.candidatesToDraw.find(instance.id().str()) == gui.candidatesToDraw.end()){ + gui.candidatesToDraw[instance.id().str()] = false; + } + }); + using namespace armarx::RemoteGui::Client; GridLayout root; { int row = 0; - - workingMemory().getCoreSegment("GraspCandidate").forEachInstance([this](const auto & instance) { - if (tab.checkBoxes.find(instance.id().str()) == tab.checkBoxes.end()){ - tab.checkBoxes[instance.id().str()] = CheckBox(); - } - }); - for(std::pair<std::string, CheckBox> element : tab.checkBoxes ) + root.add(Label("CoreSegment"), Pos{row, 0}); + row++; + std::vector<std::string> options = workingMemory().getCoreSegmentNames(); + if (options.empty()) + { + options.push_back("<None>"); + } + gui.tab.selectCoreSegment.setOptions(options); + if (gui.coreSegIndex >= 0 && gui.coreSegIndex < static_cast<int>(options.size())) + { + gui.tab.selectCoreSegment.setIndex(gui.coreSegIndex); + gui.coreSegment = options[gui.coreSegIndex]; + } + root.add(gui.tab.selectCoreSegment, Pos{row,0}); + row++; + } + if(workingMemory().hasCoreSegment(gui.coreSegment)) { - root.add(Label(element.first) , Pos{row, 0}); - root.add(element.second, Pos{row, 1}); - row += 1; + { + root.add(Label("Provider"), Pos{row, 0}); + row++; + std::vector<std::string> options = workingMemory().getCoreSegment(gui.coreSegment).getProviderSegmentNames(); + if (options.empty()) + { + options.push_back("<None>"); + } + gui.tab.selectProvider.setOptions(options); + if (gui.providerIndex >= 0 && gui.providerIndex < static_cast<int>(options.size())) + { + gui.tab.selectProvider.setIndex(gui.providerIndex); + gui.provider = options[gui.providerIndex]; + } + root.add(gui.tab.selectProvider, Pos{row, 0}); + row++; + } + + if(workingMemory().getCoreSegment(gui.coreSegment).hasProviderSegment(gui.provider)) + { + { + root.add(Label("Entity"), Pos{row,0}); + row++; + std::vector<std::string> options = workingMemory().getCoreSegment(gui.coreSegment).getProviderSegment(gui.provider).getEntityNames(); + if (options.empty()) + { + options.push_back("<None>"); + } + gui.tab.selectEntity.setOptions(options); + if (gui.entityIndex >= 0 && gui.entityIndex < static_cast<int>(options.size())) + { + gui.tab.selectEntity.setIndex(gui.entityIndex); + gui.entity = options[gui.entityIndex]; + } + root.add(gui.tab.selectEntity, Pos{row, 0}); + row++; + } + + if(workingMemory().getCoreSegment(gui.coreSegment).getProviderSegment(gui.provider).hasEntity(gui.entity)) + { + { + root.add(Label("Snapshot"), Pos{row, 0}); + row++; + std::vector<std::string> options; + options.reserve(workingMemory().getCoreSegment("GraspCandidate").getProviderSegment(gui.provider).getEntity(gui.entity).getTimestamps().size()); + workingMemory().getCoreSegment("GraspCandidate").getProviderSegment(gui.provider).getEntity(gui.entity).forEachSnapshot([&options](const auto & snapshot) + { + options.push_back(armem::toStringMicroSeconds(snapshot.time())); + }); + if (options.empty()) + { + options.push_back("<None>"); + } + gui.tab.selectSnapshot.setOptions(options); + if (gui.snapshotIndex >= 0 && gui.snapshotIndex < static_cast<int>(options.size())) + { + gui.tab.selectSnapshot.setIndex(gui.snapshotIndex); + if(options[gui.snapshotIndex] != "<None>") + { + gui.snapshot = armem::timeFromStringMicroSeconds(options[gui.snapshotIndex]); + } + } + root.add(gui.tab.selectSnapshot, Pos{row, 0}); + row++; + + } + + if(workingMemory().getCoreSegment(gui.coreSegment).getProviderSegment(gui.provider).getEntity(gui.entity).hasSnapshot(gui.snapshot)) + { + root.add(Label("Instances"), Pos{row,0}); + row++; + gui.tab.checkInstances.clear(); + workingMemory().getCoreSegment(gui.coreSegment).getProviderSegment(gui.provider).getEntity(gui.entity).getSnapshot(gui.snapshot).forEachInstance([this, &row, &root](const auto & instance) + { + root.add(Label(instance.id().str()) , Pos{row, 0}); + gui.tab.checkInstances[instance.id().str()] = CheckBox(); + if(gui.candidatesToDraw.at(instance.id().str())) + { + gui.tab.checkInstances.at(instance.id().str()).setValue(true); + } + root.add(gui.tab.checkInstances[instance.id().str()], Pos{row, 1}); + row++; + }); + } + } + else + { + gui.tab.checkInstances.clear(); + + std::vector<std::string> options = {"<None>"}; + + gui.tab.selectSnapshot.setOptions(options); + + root.add(Label("Snapshot"), Pos{row, 0}); + row++; + root.add(gui.tab.selectSnapshot, Pos{row, 0}); + row++; + } + } + else + { + gui.tab.checkInstances.clear(); + + std::vector<std::string> options = {"<None>"}; + + gui.tab.selectEntity.setOptions(options); + + root.add(Label("Entity"), Pos{row,0}); + row++; + root.add(gui.tab.selectEntity, Pos{row, 0}); + row++; + + gui.tab.selectSnapshot.setOptions(options); + + root.add(Label("Snapshot"), Pos{row, 0}); + row++; + root.add(gui.tab.selectSnapshot, Pos{row, 0}); + row++; + } + } + else { + gui.tab.checkInstances.clear(); + + std::vector<std::string> options = {"<None>"}; + gui.tab.selectProvider.setOptions(options); + + root.add(Label("Provider"), Pos{row, 0}); + row++; + root.add(gui.tab.selectProvider, Pos{row, 0}); + row++; + + gui.tab.selectEntity.setOptions(options); + + root.add(Label("Entity"), Pos{row,0}); + row++; + root.add(gui.tab.selectEntity, Pos{row, 0}); + row++; + + gui.tab.selectSnapshot.setOptions(options); + + root.add(Label("Snapshot"), Pos{row, 0}); + row++; + root.add(gui.tab.selectSnapshot, Pos{row, 0}); + row++; } } - RemoteGui_createTab(getName(), root, &tab); - tab.rebuild = false; + + RemoteGui_createTab(getName(), root, &gui.tab); + gui.tab.rebuild = false; } @@ -111,10 +271,39 @@ namespace armarx::armem::server::grasp grasping::GraspCandidateDict candidatesToVisualize; - for(std::pair<std::string, RemoteGui::Client::CheckBox> element : tab.checkBoxes ) + if (gui.tab.selectCoreSegment.hasValueChanged() || gui.tab.selectProvider.hasValueChanged() || gui.tab.selectEntity.hasValueChanged() || gui.tab.selectSnapshot.hasValueChanged()) + { + gui.tab.rebuild = true; + } + + gui.coreSegment = gui.tab.selectCoreSegment.getValue(); + + gui.provider = gui.tab.selectProvider.getValue(); + + gui.entity = gui.tab.selectEntity.getValue(); + + if(gui.tab.selectSnapshot.getValue() != "<None>" && gui.tab.selectSnapshot.getValue() != "") + { + gui.snapshot = armem::timeFromStringMicroSeconds(gui.tab.selectSnapshot.getValue()); + } + + gui.coreSegIndex = gui.tab.selectCoreSegment.getIndex(); + + gui.providerIndex = gui.tab.selectProvider.getIndex(); + + gui.entityIndex = gui.tab.selectEntity.getIndex(); + + gui.snapshotIndex = gui.tab.selectSnapshot.getIndex(); + + for(auto & element : gui.tab.checkInstances) + { + gui.candidatesToDraw.at(element.first) = element.second.getValue(); + } + + for(auto & element : gui.candidatesToDraw ) { //draw candidates - if (element.second.getValue()) + if (element.second) { armarx::grasping::GraspCandidate candidate; @@ -131,7 +320,7 @@ namespace armarx::armem::server::grasp } visu.visualize(candidatesToVisualize, arviz); - if (tab.rebuild) + if (gui.tab.rebuild) { createRemoteGuiTab(); } diff --git a/source/RobotAPI/components/armem/server/GraspMemory/GraspMemory.h b/source/RobotAPI/components/armem/server/GraspMemory/GraspMemory.h index 026d22fcc7e20048dae0bfaa1126d525da05cd3b..db09a940f92c343043e788fb9b1f78993573dd70 100644 --- a/source/RobotAPI/components/armem/server/GraspMemory/GraspMemory.h +++ b/source/RobotAPI/components/armem/server/GraspMemory/GraspMemory.h @@ -65,10 +65,31 @@ namespace armarx::armem::server::grasp { std::atomic_bool rebuild = false; - RemoteGui::Client::GroupBox memoryGroup; - std::map<std::string, RemoteGui::Client::CheckBox> checkBoxes; + RemoteGui::Client::ComboBox selectCoreSegment; + RemoteGui::Client::ComboBox selectProvider; + RemoteGui::Client::ComboBox selectEntity; + RemoteGui::Client::ComboBox selectSnapshot; + std::map<std::string, RemoteGui::Client::CheckBox> checkInstances; }; - RemoteGuiTab tab; + + + struct GuiInfo + { + int coreSegIndex = 0; + int providerIndex = 0; + int entityIndex = 0; + int snapshotIndex = 0; + + RemoteGuiTab tab; + + std::string coreSegment = ""; + std::string provider = ""; + std::string entity = ""; + Time snapshot; + + std::map<std::string, bool> candidatesToDraw; + }; + GuiInfo gui; }; }