Skip to content

Commit eede207

Browse files
authored
Merge pull request #2 from universal-field-robots/xml-port-order-fix
revert ordering logic in writeToXml()
2 parents 5f961ee + c1703f1 commit eede207

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/xml_parsing.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -983,8 +983,32 @@ void addNodeModelToXML(const TreeNodeManifest& model,
983983
XMLElement* element = doc.NewElement(toStr(model.type).c_str());
984984
element->SetAttribute("ID", model.registration_ID.c_str());
985985

986-
for (const auto& [port_name, port_info] : model.ports)
986+
std::vector<std::string> ordered_ports;
987+
PortDirection const directions[3] = {PortDirection::INPUT,
988+
PortDirection::OUTPUT,
989+
PortDirection::INOUT};
990+
for (PortDirection direction: directions)
987991
{
992+
std::set<std::string> port_names;
993+
for (auto& port : model.ports)
994+
{
995+
const auto& port_name = port.first;
996+
const auto& port_info = port.second;
997+
if (port_info.direction() == direction)
998+
{
999+
port_names.insert(port_name);
1000+
}
1001+
}
1002+
for (auto& port : port_names)
1003+
{
1004+
ordered_ports.push_back(port);
1005+
}
1006+
}
1007+
1008+
for (const auto& port_name : ordered_ports)
1009+
{
1010+
const auto& port_info = model.ports.at(port_name);
1011+
9881012
XMLElement* port_element = nullptr;
9891013
switch (port_info.direction())
9901014
{
@@ -1464,4 +1488,4 @@ std::string WriteTreeToXML(const Tree &tree, bool add_metadata, bool add_builtin
14641488
return std::string(printer.CStr(), size_t(printer.CStrSize() - 1));
14651489
}
14661490

1467-
} // namespace BT
1491+
} // namespace BT

0 commit comments

Comments
 (0)