MCPcopy Create free account
hub / github.com/BehaviorTree/Groot / buildTreeNodeModelFromXML

Function buildTreeNodeModelFromXML

bt_editor/XML_utilities.cpp:12–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10using namespace QtNodes;
11
12NodeModel buildTreeNodeModelFromXML(const QDomElement& node)
13{
14 PortModels ports_list;
15
16 QString tag_name = node.tagName();
17 QString ID = tag_name;
18 if( node.hasAttribute("ID") )
19 {
20 ID = QString(node.attribute("ID"));
21 }
22
23 const auto node_type = BT::convertFromString<BT::NodeType>(tag_name.toStdString());
24
25 if( node_type == BT::NodeType::UNDEFINED )
26 {
27 return {};
28 }
29
30 // this make sense for ports inside the <BehaviorTree> tag
31 QDomNamedNodeMap attributes = node.attributes ();
32 for (int i=0; i< attributes.size(); i++ )
33 {
34 QDomAttr attr = attributes.item(i).toAttr();
35
36 QString attr_name( attr.name() );
37 if(attr_name != "ID" && attr_name != "name")
38 {
39 PortModel port_model;
40 port_model.direction = PortDirection::INOUT;
41 ports_list.insert( { attr_name, std::move(port_model)} );
42 }
43 }
44 // this is used for ports inside the <TreeNodesModel> tag
45 const std::vector<std::pair<QString, PortDirection>> portsTypes = {
46 {"input_port", PortDirection::INPUT},
47 {"output_port", PortDirection::OUTPUT},
48 {"inout_port", PortDirection::INPUT}
49 };
50
51 for(const auto& it: portsTypes)
52 {
53 for( QDomElement port_element = node.firstChildElement( it.first );
54 !port_element.isNull();
55 port_element = port_element.nextSiblingElement( it.first ) )
56 {
57 PortModel port_model;
58 port_model.direction = it.second;
59 port_model.description = port_element.text();
60
61 if( port_element.hasAttribute("type") )
62 {
63 port_model.type_name = port_element.attribute("type");
64 }
65 if( port_element.hasAttribute("default") )
66 {
67 port_model.default_value = port_element.attribute("default");
68 }
69

Callers 2

importFromXMLMethod · 0.85
ReadTreeNodesModelFunction · 0.85

Calls 1

nameMethod · 0.80

Tested by

no test coverage detected