| 974 | } |
| 975 | |
| 976 | Document* ObjectIdentifier::getDocument(String name, bool* ambiguous) const |
| 977 | { |
| 978 | if (name.getString().empty()) { |
| 979 | name = getDocumentName(); |
| 980 | } |
| 981 | |
| 982 | App::Document* docById = nullptr; |
| 983 | |
| 984 | if (!name.isRealString()) { |
| 985 | docById = App::GetApplication().getDocument(name.toString().c_str()); |
| 986 | if (name.isForceIdentifier()) { |
| 987 | return docById; |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | App::Document* docByLabel = nullptr; |
| 992 | const std::vector<App::Document*> docs = App::GetApplication().getDocuments(); |
| 993 | |
| 994 | for (auto doc : docs) { |
| 995 | if (doc->Label.getValue() == name.getString()) { |
| 996 | /* Multiple hits for same label? */ |
| 997 | if (docByLabel) { |
| 998 | if (ambiguous) { |
| 999 | *ambiguous = true; |
| 1000 | } |
| 1001 | return nullptr; |
| 1002 | } |
| 1003 | docByLabel = doc; |
| 1004 | } |
| 1005 | } |
| 1006 | |
| 1007 | /* Not found on id? */ |
| 1008 | if (!docById) { |
| 1009 | return docByLabel; // Either not found at all, or on label |
| 1010 | } |
| 1011 | else { |
| 1012 | /* Not found on label? */ |
| 1013 | if (!docByLabel) { /* Then return doc by id */ |
| 1014 | return docById; |
| 1015 | } |
| 1016 | |
| 1017 | /* docByLabel and docById could be equal; that is ok */ |
| 1018 | if (docByLabel == docById) { |
| 1019 | return docById; |
| 1020 | } |
| 1021 | if (ambiguous) { |
| 1022 | *ambiguous = true; |
| 1023 | } |
| 1024 | return nullptr; |
| 1025 | } |
| 1026 | } |
| 1027 | |
| 1028 | DocumentObject* ObjectIdentifier::getDocumentObject() const |
| 1029 | { |
no test coverage detected