Skip to content

Commit aa57c5a

Browse files
committed
fix XML: Subtree should remember the remapped ports
1 parent 9cc0163 commit aa57c5a

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

include/behaviortree_cpp/xml_parsing.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ class XMLParser : public Parser
2626

2727
void loadFromText(const std::string& xml_text, bool add_includes = true) override;
2828

29-
std::vector<std::string> registeredBehaviorTrees() const override;
29+
[[nodiscard]] std::vector<std::string>
30+
registeredBehaviorTrees() const override;
3031

31-
Tree instantiateTree(const Blackboard::Ptr& root_blackboard,
32-
std::string main_tree_to_execute = {}) override;
32+
[[nodiscard]]Tree
33+
instantiateTree(const Blackboard::Ptr& root_blackboard,
34+
std::string main_tree_to_execute = {}) override;
3335

3436
void clearInternalState() override;
3537

@@ -41,9 +43,11 @@ class XMLParser : public Parser
4143
void VerifyXML(const std::string& xml_text,
4244
const std::unordered_map<std::string, NodeType>& registered_nodes);
4345

46+
[[nodiscard]]
4447
std::string writeTreeNodesModelXML(const BehaviorTreeFactory& factory,
4548
bool include_builtin = false);
4649

50+
[[nodiscard]]
4751
std::string WriteTreeToXML(const Tree& tree, bool add_metadata = false);
4852

4953
} // namespace BT

src/xml_parsing.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -530,19 +530,15 @@ TreeNode::Ptr XMLParser::Pimpl::createNodeFromXML(const XMLElement* element,
530530
std::string instance_name = attr_name ? attr_name : type_ID;
531531

532532
PortsRemapping port_remap;
533-
534-
if (node_type != NodeType::SUBTREE)
533+
for (const XMLAttribute* att = element->FirstAttribute(); att; att = att->Next())
535534
{
536-
// do this only if it NOT a Subtree
537-
for (const XMLAttribute* att = element->FirstAttribute(); att; att = att->Next())
535+
if (IsAllowedPortName(att->Name()))
538536
{
539-
if (IsAllowedPortName(att->Name()))
540-
{
541-
const std::string attribute_name = att->Name();
542-
port_remap[attribute_name] = att->Value();
543-
}
537+
const std::string attribute_name = att->Name();
538+
port_remap[attribute_name] = att->Value();
544539
}
545540
}
541+
546542
NodeConfig config;
547543
config.blackboard = blackboard;
548544
config.path = prefix_path + instance_name;
@@ -576,6 +572,7 @@ TreeNode::Ptr XMLParser::Pimpl::createNodeFromXML(const XMLElement* element,
576572

577573
if (node_type == NodeType::SUBTREE)
578574
{
575+
config.input_ports = port_remap;
579576
new_node = factory.instantiateTreeNode(instance_name,
580577
toStr(NodeType::SUBTREE),
581578
config);

0 commit comments

Comments
 (0)