mirror of
https://github.com/moveit/moveit_task_constructor.git
synced 2025-11-04 14:49:57 +08:00
ContainerBase::exposePropertiesOfChild
This commit is contained in:
parent
8152614d33
commit
e9d1742337
@ -61,6 +61,12 @@ public:
|
|||||||
virtual bool remove(int pos);
|
virtual bool remove(int pos);
|
||||||
virtual void clear();
|
virtual void clear();
|
||||||
|
|
||||||
|
/// declare all given variables of child and configure child to inherit them from parent
|
||||||
|
void exposePropertiesOfChild(int child, const std::initializer_list<std::string>& names);
|
||||||
|
/// declare given child property with another name and configure child to inherit it from parent
|
||||||
|
void exposePropertyOfChildAs(int child, const std::string& child_property_name,
|
||||||
|
const std::string& parent_property_name);
|
||||||
|
|
||||||
void reset() override;
|
void reset() override;
|
||||||
void init(const moveit::core::RobotModelConstPtr& robot_model) override;
|
void init(const moveit::core::RobotModelConstPtr& robot_model) override;
|
||||||
/// validate connectivity of children (after init() was done)
|
/// validate connectivity of children (after init() was done)
|
||||||
|
|||||||
@ -199,6 +199,11 @@ public:
|
|||||||
const std::string& description = "") {
|
const std::string& description = "") {
|
||||||
return declare(name, typeid(T), description, default_value, &Property::serialize<T>);
|
return declare(name, typeid(T), description, default_value, &Property::serialize<T>);
|
||||||
}
|
}
|
||||||
|
/// declare all given properties also in other PropertyMap
|
||||||
|
void exposeTo(PropertyMap& other, const std::set<std::string>& properties);
|
||||||
|
|
||||||
|
/// declare given property name as other_name in other PropertyMap
|
||||||
|
void exposeTo(PropertyMap& other, const std::string& name, const std::string& other_name);
|
||||||
|
|
||||||
bool hasProperty(const std::string &name) const;
|
bool hasProperty(const std::string &name) const;
|
||||||
|
|
||||||
|
|||||||
@ -181,6 +181,37 @@ void ContainerBase::clear()
|
|||||||
pimpl()->children_.clear();
|
pimpl()->children_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ContainerBase::exposePropertiesOfChild(int child, const std::initializer_list<std::string>& names)
|
||||||
|
{
|
||||||
|
auto impl = pimpl();
|
||||||
|
// for negative child index, return last child for -1, next to last for -2, etc
|
||||||
|
ContainerBasePrivate::const_iterator child_it = impl->position(child < 0 ? child-1 : child);
|
||||||
|
if (child_it == impl->children().end())
|
||||||
|
throw std::runtime_error("invalid child index");
|
||||||
|
|
||||||
|
auto &child_props = (*child_it)->properties();
|
||||||
|
// declare variables
|
||||||
|
child_props.exposeTo(impl->properties_, names);
|
||||||
|
// configure inheritance
|
||||||
|
child_props.configureInitFrom(Stage::PARENT, names);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ContainerBase::exposePropertyOfChildAs(int child, const std::string& child_property_name,
|
||||||
|
const std::string& parent_property_name)
|
||||||
|
{
|
||||||
|
auto impl = pimpl();
|
||||||
|
// for negative child index, return last child for -1, next to last for -2, etc
|
||||||
|
ContainerBasePrivate::const_iterator child_it = impl->position(child < 0 ? child-1 : child);
|
||||||
|
if (child_it == impl->children().end())
|
||||||
|
throw std::runtime_error("invalid child index");
|
||||||
|
|
||||||
|
auto &child_props = (*child_it)->properties();
|
||||||
|
// declare variables
|
||||||
|
child_props.exposeTo(impl->properties_, child_property_name, parent_property_name);
|
||||||
|
// configure inheritance
|
||||||
|
child_props.property(child_property_name).configureInitFrom(Stage::PARENT, parent_property_name);
|
||||||
|
}
|
||||||
|
|
||||||
void ContainerBase::reset()
|
void ContainerBase::reset()
|
||||||
{
|
{
|
||||||
auto impl = pimpl();
|
auto impl = pimpl();
|
||||||
|
|||||||
@ -131,6 +131,18 @@ Property& PropertyMap::property(const std::string &name)
|
|||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PropertyMap::exposeTo(PropertyMap& other, const std::set<std::string> &properties)
|
||||||
|
{
|
||||||
|
for (const std::string& name : properties)
|
||||||
|
exposeTo(other, name, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PropertyMap::exposeTo(PropertyMap& other, const std::string& name, const std::string& other_name)
|
||||||
|
{
|
||||||
|
const Property& p = property(name);
|
||||||
|
other.declare(name, p.type_index_, p.description_, p.default_, p.serialize_);
|
||||||
|
}
|
||||||
|
|
||||||
void PropertyMap::configureInitFrom(Property::SourceId source, const std::set<std::string> &properties)
|
void PropertyMap::configureInitFrom(Property::SourceId source, const std::set<std::string> &properties)
|
||||||
{
|
{
|
||||||
for (auto &pair : props_) {
|
for (auto &pair : props_) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user