| 376 | |
| 377 | |
| 378 | std::pair<AbsBehaviorTree, std::unordered_map<int, int>> |
| 379 | BuildTreeFromFlatbuffers(const Serialization::BehaviorTree *fb_behavior_tree) |
| 380 | { |
| 381 | AbsBehaviorTree tree; |
| 382 | std::unordered_map<int, int> uid_to_index; |
| 383 | |
| 384 | AbstractTreeNode abs_root; |
| 385 | abs_root.instance_name = "Root"; |
| 386 | abs_root.model.registration_ID = "Root"; |
| 387 | abs_root.model.registration_ID = "Root"; |
| 388 | abs_root.children_index.push_back( 1 ); |
| 389 | |
| 390 | tree.addNode( nullptr, std::move(abs_root) ); |
| 391 | |
| 392 | //----------------------------------------- |
| 393 | NodeModels models; |
| 394 | |
| 395 | for( const Serialization::NodeModel* model_node: *(fb_behavior_tree->node_models()) ) |
| 396 | { |
| 397 | NodeModel model; |
| 398 | model.registration_ID = model_node->registration_name()->c_str(); |
| 399 | model.type = convert( model_node->type() ); |
| 400 | |
| 401 | for( const Serialization::PortModel* port: *(model_node->ports()) ) |
| 402 | { |
| 403 | PortModel port_model; |
| 404 | QString port_name = port->port_name()->c_str(); |
| 405 | port_model.direction = convert( port->direction() ); |
| 406 | port_model.type_name = port->type_info()->c_str(); |
| 407 | port_model.description = port->description()->c_str(); |
| 408 | |
| 409 | model.ports.insert( { port_name, std::move(port_model) } ); |
| 410 | } |
| 411 | |
| 412 | models.insert( { model.registration_ID, std::move(model)} ); |
| 413 | } |
| 414 | |
| 415 | //----------------------------------------- |
| 416 | for( const Serialization::TreeNode* fb_node: *(fb_behavior_tree->nodes()) ) |
| 417 | { |
| 418 | AbstractTreeNode abs_node; |
| 419 | abs_node.instance_name = fb_node->instance_name()->c_str(); |
| 420 | const char* registration_ID = fb_node->registration_name()->c_str(); |
| 421 | abs_node.status = convert( fb_node->status() ); |
| 422 | abs_node.model = (models.at(registration_ID)); |
| 423 | |
| 424 | for( const Serialization::PortConfig* pair: *(fb_node->port_remaps()) ) |
| 425 | { |
| 426 | abs_node.ports_mapping.insert( { QString(pair->port_name()->c_str()), |
| 427 | QString(pair->remap()->c_str()) } ); |
| 428 | } |
| 429 | int index = tree.nodesCount(); |
| 430 | abs_node.index = index; |
| 431 | tree.nodes().push_back( std::move(abs_node) ); |
| 432 | uid_to_index.insert( { fb_node->uid(), index} ); |
| 433 | } |
| 434 | |
| 435 | for(size_t index = 0; index < fb_behavior_tree->nodes()->size(); index++ ) |
no test coverage detected