Skip to content
Snippets Groups Projects
Commit 09a041bf authored by Christoph Pohl's avatar Christoph Pohl
Browse files

Add Remote Gui factory helper functions

parent fb32f562
No related branches found
No related tags found
No related merge requests found
......@@ -25,6 +25,7 @@
#include <ArmarXGui/libraries/RemoteGui/RemoteGui.h>
#include <RobotAPI/libraries/aron/core/data/variant/All.h>
#include <ArmarXCore/util/CPPUtility/Iterator.h>
#include <RobotAPI/libraries/aron_component_config/TypeDescriptorFactories/PropertyHelper.h>
#include "Util.h"
#define INPUT_GUARD(i) \
......@@ -130,24 +131,18 @@ namespace armarx::aron::component_config
void
MakeConfigGuiVisitor::visitListOnEnter(DataInput& o, TypeInput& t)
{
in_list_ = true;
auto group = RemoteGui::makeSimpleGridLayout(pathToName(o) + "_grid").cols(20);
auto data = data::List::DynamicCastAndCheck(o);
auto type = type::List::DynamicCast(t);
auto type = type::List::DynamicCast(t)->getAcceptedType()->getDescriptor();
if (type == type::Descriptor::OBJECT)
{
return;
}
for (const auto& el: data->getElements())
{
switch (type->getAcceptedType()->getDescriptor())
{
case type::Descriptor::STRING:
group.addChild(RemoteGui::makeLineEdit(pathToName(el)).value(data::String::DynamicCast(el)->getValue()),
10);
break;
case type::Descriptor::INT:
group.addChild(RemoteGui::makeLineEdit(pathToName(el)).value(std::to_string(data::Int::DynamicCast(
el)->getValue())), 10);
break;
default:
throw armarx::NotImplementedYetException();
}
group.addChild(RemoteGui::makeLineEdit(pathToName(el)).value(factories::PropertyHelper::make(type)->to_string(
el)), 10);
group.addHSpacer(8);
group.addChild(RemoteGui::makeButton(pathToName(el) + "_button").label("-").toolTip("Remove List Element"),
2);
......@@ -161,7 +156,6 @@ namespace armarx::aron::component_config
"_add").label("+")
.toolTip(
"Add new list entry.")));
in_list_ = true;
}
void
......@@ -185,26 +179,20 @@ namespace armarx::aron::component_config
MakeConfigGuiVisitor::visitDictOnEnter(const std::shared_ptr<data::Variant>& o,
const std::shared_ptr<type::Variant>& t)
{
in_list_ = true;
auto group = RemoteGui::makeSimpleGridLayout(pathToName(o) + "_grid").cols(20);
auto data = data::Dict::DynamicCastAndCheck(o);
auto type = type::Dict::DynamicCast(t);
auto type = type::Dict::DynamicCast(t)->getAcceptedType()->getDescriptor();
if (type == type::Descriptor::OBJECT)
{
return;
}
for (const auto& el: data->getElements())
{
group.addChild(RemoteGui::makeLineEdit(pathToName(el.second) + "_lbl").value(el.first), 5);
group.addHSpacer(2);
switch (type->getAcceptedType()->getDescriptor())
{
case type::Descriptor::STRING:
group.addChild(RemoteGui::makeLineEdit(pathToName(el.second)).value(data::String::DynamicCast(el.second)
->getValue()), 5);
break;
case type::Descriptor::INT:
group.addChild(RemoteGui::makeLineEdit(pathToName(el.second)).value(std::to_string(data::Int::DynamicCast(
el.second)->getValue())), 5);
break;
default:
throw armarx::NotImplementedYetException();
}
group.addChild(RemoteGui::makeLineEdit(pathToName(el.second)).value(factories::PropertyHelper::make(type)->to_string(
el.second)), 5);
group.addHSpacer(6);
group.addChild(RemoteGui::makeButton(pathToName(el.second) + "_button").label("-")
.toolTip("Remove List Element"), 2);
......@@ -218,7 +206,6 @@ namespace armarx::aron::component_config
"_add").label("+")
.toolTip(
"Add new dict entry.")));
in_list_ = true;
}
void
......@@ -395,8 +382,13 @@ namespace armarx::aron::component_config
void
GetValueFromMapVisitor::visitListOnEnter(DataInput& o, TypeInput& t)
{
in_list_ = true;
auto data = data::List::DynamicCastAndCheck(o);
auto type = type::List::DynamicCast(t);
auto type = type::List::DynamicCast(t)->getAcceptedType()->getDescriptor();
if (type == type::Descriptor::OBJECT)
{
return;
}
const auto& elements = data->getElements();
for (const auto& [idx, el]: armarx::MakeIndexedContainer(elements))
{
......@@ -405,41 +397,16 @@ namespace armarx::aron::component_config
data->removeElement(idx);
tab_rebuild_required_ = true;
}
switch (type->getAcceptedType()->getDescriptor())
{
case type::Descriptor::STRING:
{
proxy_->getValue(data::String::DynamicCast(el)->getValue(), pathToName(el));
break;
}
case type::Descriptor::INT:
{
std::string str;
proxy_->getValue(str, pathToName(el));
data::Int::DynamicCast(el)->getValue() = std::stoi(str);
break;
}
default:
throw armarx::NotImplementedYetException();
}
auto gui_value = proxy_->getValue<std::string>(pathToName(el)).get();
factories::PropertyHelper::make(type)->set_value_from_string(el, gui_value);
}
if (proxy_->getButtonClicked(pathToName(o) + "_add"))
{
switch (type->getAcceptedType()->getDescriptor())
{
case type::Descriptor::STRING:
data->addElement(make_string("", o->getPath().withIndex(data->childrenSize())));
break;
case type::Descriptor::INT:
data->addElement(make_int(0, o->getPath().withIndex(data->childrenSize())));
break;
default:
throw armarx::NotImplementedYetException();
}
data->addElement(factories::PropertyHelper::make(type)->from_string("",
o->getPath()
.withIndex(data->childrenSize())));
tab_rebuild_required_ = true;
}
in_list_ = true;
}
void
......@@ -457,8 +424,13 @@ namespace armarx::aron::component_config
void
GetValueFromMapVisitor::visitDictOnEnter(std::shared_ptr<data::Variant>& o, const std::shared_ptr<type::Variant>& t)
{
in_list_ = true;
auto data = data::Dict::DynamicCastAndCheck(o);
auto type = type::Dict::DynamicCast(t);
auto type = type::Dict::DynamicCast(t)->getAcceptedType()->getDescriptor();
if (type == type::Descriptor::OBJECT)
{
return;
}
const auto& elements = data->getElements();
std::map<std::string, std::string> changed_labels;
for (const auto& [idx, el]: elements)
......@@ -469,63 +441,28 @@ namespace armarx::aron::component_config
data->removeElement(idx);
tab_rebuild_required_ = true;
}
switch (type->getAcceptedType()->getDescriptor())
auto gui_value = proxy_->getValue<std::string>(name).get();
auto gui_key = proxy_->getValue<std::string>(name + "_lbl").get();
auto config_value = factories::PropertyHelper::make(type)->to_string(el);
if (gui_value != config_value)
{
case type::Descriptor::STRING:
if (proxy_->hasValueChanged(name))
{
factories::PropertyHelper::make(type)->set_value_from_string(el, gui_value);
} else
{
auto gui_value = proxy_->getValue<std::string>(name).get();
auto gui_key = proxy_->getValue<std::string>(name + "_lbl").get();
if (gui_value != data::String::DynamicCast(el)->getValue())
{
if (proxy_->hasValueChanged(name))
{
data::String::DynamicCast(el)->getValue() = gui_value;
} else
{
proxy_->setValue(data::String::DynamicCast(el)->getValue(), name);
}
}
if (gui_key != idx)
{
if (proxy_->hasValueChanged(name + "_lbl"))
{
changed_labels.emplace(idx, gui_key);
} else
{
proxy_->setValue(idx, name + "_lbl");
}
}
break;
proxy_->setValue(config_value, name);
}
case type::Descriptor::INT:
}
if (gui_key != idx)
{
if (proxy_->hasValueChanged(name + "_lbl"))
{
changed_labels.emplace(idx, gui_key);
} else
{
auto gui_value = std::stoi(proxy_->getValue<std::string>(name).get());
auto gui_key = proxy_->getValue<std::string>(name + "_lbl").get();
if (gui_value != data::Int::DynamicCast(el)->getValue())
{
if (proxy_->hasValueChanged(name))
{
data::Int::DynamicCast(el)->getValue() = gui_value;
} else
{
proxy_->setValue(std::to_string(data::Int::DynamicCast(el)->getValue()), name);
}
}
if (gui_key != idx)
{
if (proxy_->hasValueChanged(name + "_lbl"))
{
changed_labels.emplace(idx, gui_key);
} else
{
proxy_->setValue(idx, name + "_lbl");
}
}
break;
proxy_->setValue(idx, name + "_lbl");
}
default:
throw armarx::NotImplementedYetException();
}
}
// replace changed keys in map
......@@ -533,40 +470,22 @@ namespace armarx::aron::component_config
{
auto element = data->getElement(old_label);
data->removeElement(old_label);
switch (type->getAcceptedType()->getDescriptor())
{
case type::Descriptor::STRING:
data->addElement(new_label,
make_string(data::String::DynamicCast(element)->getValue(),
o->getPath().withDetachedLastElement().withElement(new_label)));
break;
case type::Descriptor::INT:
data->addElement(new_label,
make_int(data::Int::DynamicCast(element)->getValue(),
o->getPath().withDetachedLastElement().withElement(new_label)));
break;
default:
throw armarx::NotImplementedYetException();
}
auto variantHelper = factories::PropertyHelper::make(type);
data->addElement(new_label,
variantHelper->from_string(variantHelper->to_string(element),
o->getPath().withDetachedLastElement().withElement(new_label)));
tab_rebuild_required_ = true;
}
if (proxy_->getButtonClicked(pathToName(o) + "_add"))
{
switch (type->getAcceptedType()->getDescriptor())
{
case type::Descriptor::STRING:
data->addElement("defaultKey", make_string("", o->getPath().withElement("defaultKey")));
break;
case type::Descriptor::INT:
data->addElement("defaultKey", make_int(0, o->getPath().withElement("defaultKey")));
break;
default:
throw armarx::NotImplementedYetException();
}
data->addElement("defaultKey",
factories::PropertyHelper::make(type)->from_string("",
o->getPath()
.withElement("defaultKey")));
tab_rebuild_required_ = true;
}
in_list_ = true;
}
void
......
......@@ -126,6 +126,48 @@ namespace armarx::aron::component_config::products
return make_string(string, path);
}
template <>
void
products::PropertyHelper<type::Descriptor::INT>::set_value_from_string(const armarx::aron::data::VariantPtr& variant,
const std::string& string) const
{
data::Int::DynamicCast(variant)->getValue() = std::stoi(string);
}
template <>
void
products::PropertyHelper<type::Descriptor::FLOAT>::set_value_from_string(const armarx::aron::data::VariantPtr& variant,
const std::string& string) const
{
data::Float::DynamicCast(variant)->getValue() = std::stof(string);
}
template <>
void
products::PropertyHelper<type::Descriptor::DOUBLE>::set_value_from_string(const armarx::aron::data::VariantPtr& variant,
const std::string& string) const
{
data::Double::DynamicCast(variant)->getValue() = std::stod(string);
}
template <>
void
products::PropertyHelper<type::Descriptor::BOOL>::set_value_from_string(const armarx::aron::data::VariantPtr& variant,
const std::string& string) const
{
data::Bool::DynamicCast(variant)->getValue() = string == "true";
}
template <>
void
products::PropertyHelper<type::Descriptor::STRING>::set_value_from_string(const armarx::aron::data::VariantPtr& variant,
const std::string& string) const
{
data::String::DynamicCast(variant)->getValue() = string;
}
template <>
void
products::PropertyHelper<type::Descriptor::INT_ENUM>::set_value_from_string(const armarx::aron::data::VariantPtr& variant,
const std::string& string) const
{
data::Int::DynamicCast(variant)->getValue() = std::stoi(string);
}
template struct products::PropertyHelper<type::Descriptor::INT>;
......
......@@ -40,6 +40,10 @@ namespace armarx::aron::component_config
virtual ~PropertyHelper() = default;
virtual std::string to_string(const armarx::aron::data::VariantPtr&) const = 0;
virtual void
set_value_from_string(const armarx::aron::data::VariantPtr&, const std::string& string) const = 0;
virtual aron::data::VariantPtr from_string(const std::string&, const armarx::aron::Path& path) const = 0;
};
}
......@@ -56,7 +60,12 @@ namespace armarx::aron::component_config
};
[[nodiscard]] std::string to_string(const data::VariantPtr& ptr) const override;
[[nodiscard]] aron::data::VariantPtr from_string(const std::string&, const armarx::aron::Path& path) const override;
void set_value_from_string(const armarx::aron::data::VariantPtr& variant,
const std::string& string) const override;
[[nodiscard]] aron::data::VariantPtr
from_string(const std::string&, const armarx::aron::Path& path) const override;
};
......@@ -65,39 +74,86 @@ namespace armarx::aron::component_config
template <>
std::string
products::PropertyHelper<type::Descriptor::INT>::to_string(const data::VariantPtr& ptr) const;
template <>
aron::data::VariantPtr
products::PropertyHelper<type::Descriptor::INT>::from_string(const std::string&, const armarx::aron::Path& path) const;
products::PropertyHelper<type::Descriptor::INT>::from_string(const std::string&,
const armarx::aron::Path& path) const;
template <>
void
products::PropertyHelper<type::Descriptor::INT>::set_value_from_string(const armarx::aron::data::VariantPtr&,
const std::string&) const;
template <>
std::string
products::PropertyHelper<type::Descriptor::FLOAT>::to_string(const data::VariantPtr& ptr) const;
template <>
aron::data::VariantPtr
products::PropertyHelper<type::Descriptor::FLOAT>::from_string(const std::string&, const armarx::aron::Path& path) const;
products::PropertyHelper<type::Descriptor::FLOAT>::from_string(const std::string&,
const armarx::aron::Path& path) const;
template <>
void
products::PropertyHelper<type::Descriptor::FLOAT>::set_value_from_string(const armarx::aron::data::VariantPtr&,
const std::string&) const;
template <>
std::string
products::PropertyHelper<type::Descriptor::BOOL>::to_string(const data::VariantPtr& ptr) const;
template <>
aron::data::VariantPtr
products::PropertyHelper<type::Descriptor::BOOL>::from_string(const std::string&, const armarx::aron::Path& path) const;
products::PropertyHelper<type::Descriptor::BOOL>::from_string(const std::string&,
const armarx::aron::Path& path) const;
template <>
void
products::PropertyHelper<type::Descriptor::BOOL>::set_value_from_string(const armarx::aron::data::VariantPtr&,
const std::string&) const;
template <>
std::string
products::PropertyHelper<type::Descriptor::STRING>::to_string(const data::VariantPtr& ptr) const;
template <>
aron::data::VariantPtr
products::PropertyHelper<type::Descriptor::STRING>::from_string(const std::string&, const armarx::aron::Path& path) const;
products::PropertyHelper<type::Descriptor::STRING>::from_string(const std::string&,
const armarx::aron::Path& path) const;
template <>
void
products::PropertyHelper<type::Descriptor::STRING>::set_value_from_string(const armarx::aron::data::VariantPtr&,
const std::string&) const;
template <>
std::string
products::PropertyHelper<type::Descriptor::DOUBLE>::to_string(const data::VariantPtr& ptr) const;
template <>
aron::data::VariantPtr
products::PropertyHelper<type::Descriptor::DOUBLE>::from_string(const std::string&, const armarx::aron::Path& path) const;
products::PropertyHelper<type::Descriptor::DOUBLE>::from_string(const std::string&,
const armarx::aron::Path& path) const;
template <>
void
products::PropertyHelper<type::Descriptor::DOUBLE>::set_value_from_string(const armarx::aron::data::VariantPtr&,
const std::string&) const;
template <>
std::string
products::PropertyHelper<type::Descriptor::INT_ENUM>::to_string(const data::VariantPtr& ptr) const;
template <>
aron::data::VariantPtr
products::PropertyHelper<type::Descriptor::INT_ENUM>::from_string(const std::string&, const armarx::aron::Path& path) const;
products::PropertyHelper<type::Descriptor::INT_ENUM>::from_string(const std::string&,
const armarx::aron::Path& path) const;
template <>
void
products::PropertyHelper<type::Descriptor::INT_ENUM>::set_value_from_string(const armarx::aron::data::VariantPtr&,
const std::string&) const;
extern template struct products::PropertyHelper<type::Descriptor::INT>;
......
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