Gets the representation of the current geometrical entity.
| 534 | |
| 535 | /// Gets the representation of the current geometrical entity. |
| 536 | IfcGeom::Element* IfcGeom::Iterator::get() |
| 537 | { |
| 538 | validate_iterator_state(); |
| 539 | |
| 540 | auto ret = *task_result_iterator_; |
| 541 | |
| 542 | // If we want to organize the element considering their hierarchy |
| 543 | if (settings_.get<ifcopenshell::geometry::settings::UseElementHierarchy>().get()) { |
| 544 | // We are going to build a vector with the element parents. |
| 545 | // First, create the parent vector |
| 546 | std::vector<const IfcGeom::Element*> parents; |
| 547 | |
| 548 | // if the element has a parent |
| 549 | if (ret->parent_id() != -1) { |
| 550 | const IfcGeom::Element* parent_object = NULL; |
| 551 | bool hasParent = true; |
| 552 | |
| 553 | // get the parent |
| 554 | try { |
| 555 | parent_object = get_object(ret->parent_id()); |
| 556 | } catch (const std::exception& e) { |
| 557 | Logger::Error(e); |
| 558 | hasParent = false; |
| 559 | } |
| 560 | |
| 561 | // Add the previously found parent to the vector |
| 562 | if (hasParent) parents.insert(parents.begin(), parent_object); |
| 563 | |
| 564 | // We need to find all the parents |
| 565 | while (parent_object != NULL && hasParent && parent_object->parent_id() != -1) { |
| 566 | // Find the next parent |
| 567 | auto pid = parent_object->parent_id(); |
| 568 | auto ifc_product = ifc_file->instance_by_id(pid)->as<IfcUtil::IfcBaseEntity>(); |
| 569 | if (ifc_product->declaration().name() == "IfcProject") { |
| 570 | hasParent = false; |
| 571 | } else { |
| 572 | try { |
| 573 | parent_object = get_object(pid); |
| 574 | } catch (const std::exception& e) { |
| 575 | Logger::Error(e); |
| 576 | hasParent = false; |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | // Add the previously found parent to the vector |
| 581 | if (hasParent) parents.insert(parents.begin(), parent_object); |
| 582 | |
| 583 | hasParent = hasParent && parent_object->parent_id() != -1; |
| 584 | } |
| 585 | |
| 586 | // when done push the parent list in the Element object |
| 587 | ret->SetParents(parents); |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | return ret; |
| 592 | } |
| 593 |
no test coverage detected