@@ -789,7 +789,8 @@ void XMLParser::Pimpl::getPortsRecursively(const XMLElement *element,
789
789
}
790
790
791
791
792
- std::string writeTreeNodesModelXML (const BehaviorTreeFactory& factory)
792
+ std::string writeTreeNodesModelXML (const BehaviorTreeFactory& factory,
793
+ bool include_builtin)
793
794
{
794
795
using namespace BT_TinyXML2 ;
795
796
@@ -801,27 +802,51 @@ std::string writeTreeNodesModelXML(const BehaviorTreeFactory& factory)
801
802
XMLElement* model_root = doc.NewElement (" TreeNodesModel" );
802
803
rootXML->InsertEndChild (model_root);
803
804
805
+ std::set<std::string> ordered_names;
806
+
804
807
for (auto & model_it : factory.manifests ())
805
808
{
806
- const auto & registration_ID = model_it.first ;
807
- const auto & model = model_it.second ;
809
+ const auto & registration_ID = model_it.first ;
810
+ if ( !include_builtin &&
811
+ factory.builtinNodes ().count ( registration_ID ) != 0 )
812
+ {
813
+ continue ;
814
+ }
815
+ ordered_names.insert ( registration_ID );
816
+ }
808
817
809
- if ( factory.builtinNodes ().count ( registration_ID ) != 0 )
810
- {
811
- continue ;
812
- }
818
+ for (auto & registration_ID : ordered_names)
819
+ {
820
+ const auto & model = factory.manifests ().at (registration_ID);
813
821
814
- if (model.type == NodeType::CONTROL)
815
- {
816
- continue ;
817
- }
818
822
XMLElement* element = doc.NewElement ( toStr (model.type ).c_str () );
819
823
element->SetAttribute (" ID" , model.registration_ID .c_str ());
820
824
821
- for (auto & port : model.ports )
825
+ std::vector<std::string> ordered_ports;
826
+ PortDirection directions[3 ] = { PortDirection::INPUT,
827
+ PortDirection::OUTPUT,
828
+ PortDirection::INOUT };
829
+ for (int d=0 ; d<3 ; d++)
822
830
{
831
+ std::set<std::string> port_names;
832
+ for (auto & port : model.ports )
833
+ {
823
834
const auto & port_name = port.first ;
824
835
const auto & port_info = port.second ;
836
+ if ( port_info.direction () == directions[d] )
837
+ {
838
+ port_names.insert (port_name);
839
+ }
840
+ }
841
+ for (auto & port : port_names)
842
+ {
843
+ ordered_ports.push_back (port);
844
+ }
845
+ }
846
+
847
+ for (const auto & port_name : ordered_ports)
848
+ {
849
+ const auto & port_info = model.ports .at (port_name);
825
850
826
851
XMLElement* port_element = nullptr ;
827
852
switch ( port_info.direction () )
0 commit comments