| 506 | } |
| 507 | |
| 508 | static std::vector<std::pair<long, Data::MappedName>> getElementSource( |
| 509 | App::DocumentObject* owner, |
| 510 | TopoShape shape, |
| 511 | const Data::MappedName& name, |
| 512 | char type |
| 513 | ) |
| 514 | { |
| 515 | std::set<std::pair<App::Document*, long>> tagSet; |
| 516 | std::vector<std::pair<long, Data::MappedName>> ret; |
| 517 | ret.emplace_back(0, name); |
| 518 | int depth = 0; |
| 519 | while (1) { |
| 520 | Data::MappedName original; |
| 521 | std::vector<Data::MappedName> history; |
| 522 | // It is possible the name does not belong to the shape, e.g. when user |
| 523 | // changes modeling order in PartDesign. So we try to assign the |
| 524 | // document hasher here in case getElementHistory() needs to de-hash |
| 525 | if (!shape.Hasher && owner) { |
| 526 | shape.Hasher = owner->getDocument()->getStringHasher(); |
| 527 | } |
| 528 | long tag = shape.getElementHistory(ret.back().second, &original, &history); |
| 529 | if (!tag) { |
| 530 | break; |
| 531 | } |
| 532 | auto obj = owner; |
| 533 | App::Document* doc = nullptr; |
| 534 | if (owner) { |
| 535 | doc = owner->getDocument(); |
| 536 | for (;; ++depth) { |
| 537 | auto linked = owner->getLinkedObject(false, nullptr, false, depth); |
| 538 | if (linked == owner) { |
| 539 | break; |
| 540 | } |
| 541 | owner = linked; |
| 542 | if (owner->getDocument() != doc) { |
| 543 | doc = owner->getDocument(); |
| 544 | break; |
| 545 | } |
| 546 | } |
| 547 | if (owner->isDerivedFrom<App::GeoFeature>()) { |
| 548 | auto ownerGeoFeature = static_cast<App::GeoFeature*>(owner)->getElementOwner( |
| 549 | ret.back().second |
| 550 | ); |
| 551 | if (ownerGeoFeature) { |
| 552 | doc = ownerGeoFeature->getDocument(); |
| 553 | } |
| 554 | } |
| 555 | obj = doc->getObjectByID(tag < 0 ? -tag : tag); |
| 556 | if (type) { |
| 557 | for (auto& hist : history) { |
| 558 | if (shape.elementType(hist) != type) { |
| 559 | return ret; |
| 560 | } |
| 561 | } |
| 562 | } |
| 563 | } |
| 564 | owner = 0; |
| 565 | if (!obj) { |
no test coverage detected