| 695 | } |
| 696 | |
| 697 | Tree XMLParser::instantiateTree(const Blackboard::Ptr& root_blackboard, |
| 698 | std::string main_tree_ID) |
| 699 | { |
| 700 | Tree output_tree; |
| 701 | |
| 702 | // use the main_tree_to_execute argument if it was provided by the user |
| 703 | // or the one in the FIRST document opened |
| 704 | if(main_tree_ID.empty()) |
| 705 | { |
| 706 | XMLElement* first_xml_root = _p->opened_documents.front()->RootElement(); |
| 707 | |
| 708 | if(auto main_tree_attribute = first_xml_root->Attribute("main_tree_to_execute")) |
| 709 | { |
| 710 | main_tree_ID = main_tree_attribute; |
| 711 | } |
| 712 | else if(_p->tree_roots.size() == 1) |
| 713 | { |
| 714 | // special case: there is only one registered BT. |
| 715 | main_tree_ID = _p->tree_roots.begin()->first; |
| 716 | } |
| 717 | else |
| 718 | { |
| 719 | throw RuntimeError("[main_tree_to_execute] was not specified correctly"); |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | //-------------------------------------- |
| 724 | if(!root_blackboard) |
| 725 | { |
| 726 | throw RuntimeError("XMLParser::instantiateTree needs a non-empty " |
| 727 | "root_blackboard"); |
| 728 | } |
| 729 | |
| 730 | std::unordered_set<std::string> ancestors; |
| 731 | _p->recursivelyCreateSubtree(main_tree_ID, {}, {}, output_tree, root_blackboard, |
| 732 | TreeNode::Ptr(), ancestors); |
| 733 | output_tree.initialize(); |
| 734 | return output_tree; |
| 735 | } |
| 736 | |
| 737 | void XMLParser::clearInternalState() |
| 738 | { |
no test coverage detected