| 789 | }; |
| 790 | |
| 791 | App::DocumentObject* ObjectIdentifier::getDocumentObject(const App::Document* doc, |
| 792 | const String& name, |
| 793 | std::bitset<32>& flags) |
| 794 | { |
| 795 | DocumentObject* objectById = nullptr; |
| 796 | DocumentObject* objectByLabel = nullptr; |
| 797 | |
| 798 | if (!name.isRealString()) { |
| 799 | // No object found with matching label, try using name directly |
| 800 | objectById = doc->getObject(static_cast<const char*>(name)); |
| 801 | |
| 802 | if (objectById) { |
| 803 | flags.set(ResolveByIdentifier); |
| 804 | return objectById; |
| 805 | } |
| 806 | if (name.isForceIdentifier()) { |
| 807 | return nullptr; |
| 808 | } |
| 809 | } |
| 810 | |
| 811 | std::vector<DocumentObject*> docObjects = doc->getObjects(); |
| 812 | for (auto docObject : docObjects) { |
| 813 | if (strcmp(docObject->Label.getValue(), static_cast<const char*>(name)) == 0) { |
| 814 | // Found object with matching label |
| 815 | if (objectByLabel) { |
| 816 | FC_WARN("duplicate object label " << doc->getName() << '#' |
| 817 | << static_cast<const char*>(name)); |
| 818 | return nullptr; |
| 819 | } |
| 820 | objectByLabel = docObject; |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | if (!objectByLabel && !objectById) { // Not found at all |
| 825 | return nullptr; |
| 826 | } |
| 827 | else if (!objectByLabel) { // Found by name |
| 828 | flags.set(ResolveByIdentifier); |
| 829 | return objectById; |
| 830 | } |
| 831 | else if (!objectById) { // Found by label |
| 832 | flags.set(ResolveByLabel); |
| 833 | return objectByLabel; |
| 834 | } |
| 835 | else if (objectByLabel == objectById) { // Found by both name and label, same object |
| 836 | flags.set(ResolveByIdentifier); |
| 837 | flags.set(ResolveByLabel); |
| 838 | return objectByLabel; |
| 839 | } |
| 840 | else { |
| 841 | flags.set(ResolveAmbiguous); |
| 842 | return nullptr; // Found by both name and label, two different objects |
| 843 | } |
| 844 | } |
| 845 | |
| 846 | void ObjectIdentifier::resolve(ResolveResults& results) const |
| 847 | { |
no test coverage detected