Skip to content
Snippets Groups Projects
Commit 4f11aa1c authored by Rainer Kartmann's avatar Rainer Kartmann
Browse files

Merge branch 'untyped-attributes' into 'master'

Show data attributes not in the aron type in MemoryViewer

See merge request ArmarX/RobotAPI!214
parents dce4402d 63bd3f76
No related branches found
No related tags found
1 merge request!214Show data attributes not in the aron type in MemoryViewer
...@@ -174,6 +174,10 @@ namespace armarx ...@@ -174,6 +174,10 @@ namespace armarx
{ {
//commitExampleImages(); //commitExampleImages();
} }
if (true)
{
commitExamplesWithUntypedData();
}
CycleUtil c(static_cast<int>(1000 / p.commitFrequency)); CycleUtil c(static_cast<int>(1000 / p.commitFrequency));
while (!task->isStopped()) while (!task->isStopped())
...@@ -602,6 +606,37 @@ namespace armarx ...@@ -602,6 +606,37 @@ namespace armarx
} }
} }
void ExampleMemoryClient::commitExamplesWithUntypedData()
{
const armem::Time time = armem::Time::now();
armem::Commit commit;
{
armem::EntityUpdate& update = commit.add();
update.entityID = exampleDataProviderID.withEntityName("unexpected_data");
update.timeCreated = time;
armem::example::ExampleData data;
toAron(data.memoryLink, armem::MemoryID()); // ////1/1
aron::data::DictPtr aron = data.toAron();
aron->addElement("unexpectedString", std::make_shared<aron::data::String>("unexpected value"));
aron->addElement("unexpectedDict", std::make_shared<aron::data::Dict>(
std::map<std::string, aron::data::VariantPtr>{
{ "key43", std::make_shared<aron::data::Int>(43) },
{ "keyABC", std::make_shared<aron::data::String>("ABC") },
}
));
update.instancesData = { aron };
}
armem::CommitResult commitResult = memoryWriter.commit(commit);
if (!commitResult.allSuccess())
{
ARMARX_WARNING << commitResult.allErrorMessages();
}
}
void ExampleMemoryClient::processExampleEntityUpdate( void ExampleMemoryClient::processExampleEntityUpdate(
const armem::MemoryID& subscriptionID, const std::vector<armem::MemoryID>& snapshotIDs) const armem::MemoryID& subscriptionID, const std::vector<armem::MemoryID>& snapshotIDs)
......
...@@ -102,6 +102,8 @@ namespace armarx ...@@ -102,6 +102,8 @@ namespace armarx
void commitExampleImages(); void commitExampleImages();
void commitExamplesWithUntypedData();
private: private:
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <RobotAPI/libraries/armem_gui/instance/sanitize_typename.h> #include <RobotAPI/libraries/armem_gui/instance/sanitize_typename.h>
#include <RobotAPI/libraries/armem_gui/instance/display_visitors/TypedDataDisplayVisitor.h> #include <RobotAPI/libraries/armem_gui/instance/display_visitors/TypedDataDisplayVisitor.h>
#include <RobotAPI/libraries/armem_gui/instance/MemoryIDTreeWidgetItem.h> #include <RobotAPI/libraries/armem_gui/instance/MemoryIDTreeWidgetItem.h>
#include <RobotAPI/libraries/armem_gui/instance/tree_builders/DataTreeBuilder.h>
namespace armarx::armem::gui::instance namespace armarx::armem::gui::instance
...@@ -28,21 +29,18 @@ namespace armarx::armem::gui::instance ...@@ -28,21 +29,18 @@ namespace armarx::armem::gui::instance
const aron::data::Dict& data) const aron::data::Dict& data)
{ {
auto childType = type.getAcceptedType(); auto childType = type.getAcceptedType();
if (childType) DictBuilder builder = getDictBuilder();
builder.setUpdateItemFn([this, &childType, &data](const std::string & key, QTreeWidgetItem * item)
{ {
DictBuilder builder = getDictBuilder(); auto childData = data.getElement(key);
builder.setUpdateItemFn([this, &childType, &data](const std::string & key, QTreeWidgetItem * item) if (childData)
{ {
auto childData = data.getElement(key); this->updateDispatch(item, key, childType, childData);
if (childData) }
{ return true;
this->update(item, key, childType, childData); });
}
return true; builder.updateTreeWithContainer(parent, data.getAllKeys());
});
builder.updateTreeWithContainer(parent, data.getAllKeys());
}
} }
...@@ -54,7 +52,8 @@ namespace armarx::armem::gui::instance ...@@ -54,7 +52,8 @@ namespace armarx::armem::gui::instance
DictBuilder builder = getDictBuilder(); DictBuilder builder = getDictBuilder();
builder.setMakeItemFn([this, &type](const std::string & key) -> QTreeWidgetItem* builder.setMakeItemFn([this, &type](const std::string & key) -> QTreeWidgetItem*
{ {
if (type.getMemberType(key)->getFullName() == instance::rawMemoryIDTypeName) if (type.hasMemberType(key)
&& type.getMemberType(key)->getFullName() == instance::rawMemoryIDTypeName)
{ {
MemoryIDTreeWidgetItem* item = new MemoryIDTreeWidgetItem({QString::fromStdString(key)}); MemoryIDTreeWidgetItem* item = new MemoryIDTreeWidgetItem({QString::fromStdString(key)});
item->addKeyChildren(); item->addKeyChildren();
...@@ -67,17 +66,22 @@ namespace armarx::armem::gui::instance ...@@ -67,17 +66,22 @@ namespace armarx::armem::gui::instance
}); });
builder.setUpdateItemFn([this, &type, &data](const std::string & key, QTreeWidgetItem * item) builder.setUpdateItemFn([this, &type, &data](const std::string & key, QTreeWidgetItem * item)
{ {
auto childType = type.getMemberType(key);
auto childData = data.getElement(key); auto childData = data.getElement(key);
if (childType) // We need this check here because getMemberType(key) throws
// instead of returning nullptr if the type doesn't have the key.
if (type.hasMemberType(key))
{ {
this->update(item, key, childType, childData); this->updateDispatch(item, key, type.getMemberType(key), childData);
}
else
{
this->updateDispatch(item, key, nullptr, childData);
} }
return true; return true;
}); });
builder.updateTreeWithContainer(parent, type.getAllKeys()); builder.updateTreeWithContainer(parent, data.getAllKeys());
} }
...@@ -86,22 +90,19 @@ namespace armarx::armem::gui::instance ...@@ -86,22 +90,19 @@ namespace armarx::armem::gui::instance
const aron::data::List& data) const aron::data::List& data)
{ {
auto childType = type.getAcceptedType(); auto childType = type.getAcceptedType();
if (childType) auto children = data.getChildren();
{
auto children = data.getChildren();
ListBuilder builder = getListBuilder(); ListBuilder builder = getListBuilder();
builder.setUpdateItemFn([this, &children, &childType](size_t key, QTreeWidgetItem * item) builder.setUpdateItemFn([this, &children, &childType](size_t key, QTreeWidgetItem * item)
{
if (auto childData = children.at(key))
{ {
if (auto childData = children.at(key)) this->updateDispatch(item, std::to_string(key), childType, childData);
{ }
this->update(item, std::to_string(key), childType, childData); return true;
} });
return true;
}); builder.updateTreeWithContainer(parent, getIndex(children.size()));
builder.updateTreeWithContainer(parent, getIndex(children.size()));
}
} }
...@@ -119,10 +120,7 @@ namespace armarx::armem::gui::instance ...@@ -119,10 +120,7 @@ namespace armarx::armem::gui::instance
auto childType = i == 0 ? childTypes.first : childTypes.second; auto childType = i == 0 ? childTypes.first : childTypes.second;
auto childData = data.getElement(static_cast<unsigned int>(i)); auto childData = data.getElement(static_cast<unsigned int>(i));
if (childType) this->updateDispatch(item, std::to_string(i), childType, childData);
{
this->update(item, std::to_string(i), childType, childData);
}
return true; return true;
}); });
...@@ -135,22 +133,43 @@ namespace armarx::armem::gui::instance ...@@ -135,22 +133,43 @@ namespace armarx::armem::gui::instance
const aron::type::Tuple& type, const aron::type::Tuple& type,
const aron::data::List& data) const aron::data::List& data)
{ {
// Allows tuples where the data list is longer than the type tuple -
// is that desired behavior?
auto childTypes = type.getAcceptedTypes(); auto childTypes = type.getAcceptedTypes();
ListBuilder builder = getListBuilder(); ListBuilder builder = getListBuilder();
builder.setUpdateItemFn([this, &data, &childTypes](size_t i, QTreeWidgetItem * item) builder.setUpdateItemFn([this, &data, &childTypes](size_t i, QTreeWidgetItem * item)
{ {
auto childType = childTypes.at(i); auto childType = (i < childTypes.size()) ? childTypes.at(i) : nullptr;
auto childData = data.getElement(static_cast<unsigned int>(i)); auto childData = data.getElement(static_cast<unsigned int>(i));
if (childType) this->updateDispatch(item, std::to_string(i), childType, childData);
{
this->update(item, std::to_string(i), childType, childData);
}
return true; return true;
}); });
builder.updateTreeWithContainer(parent, getIndex(type.getAcceptedTypes().size())); builder.updateTreeWithContainer(parent, getIndex(data.childrenSize()));
}
/*! Used so that elements in the data that don't appear in the type
* can still be shown in the GUI if type information is enabled
* (otherwise, they would be hidden).
*/
void TypedDataTreeBuilder::updateDispatch(
QTreeWidgetItem* item,
const std::string& key,
const aron::type::VariantPtr& type,
const aron::data::VariantPtr& data)
{
if (type)
{
this->update(item, key, type, data);
}
else
{
this->update(item, key, data);
}
} }
...@@ -217,6 +236,33 @@ namespace armarx::armem::gui::instance ...@@ -217,6 +236,33 @@ namespace armarx::armem::gui::instance
_updateTree(item, *t, *d); _updateTree(item, *t, *d);
} }
// else??? // else???
// phesch: else we stop here, since there's no container to recurse into.
}
}
void TypedDataTreeBuilder::update(QTreeWidgetItem* item,
const std::string& key,
const aron::data::VariantPtr& data)
{
if (data)
{
this->setRowTexts(item, key, data);
if (auto cast = aron::data::Dict::DynamicCast(data))
{
DataTreeBuilder builder;
builder.updateTree(item, cast);
}
else if (auto cast = aron::data::List::DynamicCast(data))
{
DataTreeBuilder builder;
builder.updateTree(item, cast);
}
}
else
{
this->setRowTexts(item, key, "(none)");
} }
} }
......
...@@ -49,11 +49,20 @@ namespace armarx::armem::gui::instance ...@@ -49,11 +49,20 @@ namespace armarx::armem::gui::instance
protected: protected:
void updateDispatch(QTreeWidgetItem* item,
const std::string& key,
const aron::type::VariantPtr& type,
const aron::data::VariantPtr& data);
void update(QTreeWidgetItem* item, void update(QTreeWidgetItem* item,
const std::string& key, const std::string& key,
const aron::type::VariantPtr& type, const aron::type::VariantPtr& type,
const aron::data::VariantPtr& data); const aron::data::VariantPtr& data);
void update(QTreeWidgetItem* item,
const std::string& key,
const aron::data::VariantPtr& data);
template <class DataT, class TypeT> template <class DataT, class TypeT>
void _updateTree(QTreeWidgetItem* item, TypeT& type, DataT& data); void _updateTree(QTreeWidgetItem* item, TypeT& type, DataT& data);
......
...@@ -105,7 +105,7 @@ namespace armarx::aron::type ...@@ -105,7 +105,7 @@ namespace armarx::aron::type
VariantPtr Object::getMemberType(const std::string& s) const VariantPtr Object::getMemberType(const std::string& s) const
{ {
if (memberTypes.find(s) == memberTypes.end() and !extends->hasMemberType(s)) if (memberTypes.find(s) == memberTypes.end() and not (extends and extends->hasMemberType(s)))
{ {
throw error::ValueNotValidException("ObjectNavigator", "getMemberType", "Member not set. The list of all members is: " + simox::alg::to_string(simox::alg::get_keys(memberTypes)), s); throw error::ValueNotValidException("ObjectNavigator", "getMemberType", "Member not set. The list of all members is: " + simox::alg::to_string(simox::alg::get_keys(memberTypes)), s);
} }
......
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