MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / getDocument

Method getDocument

src/App/ObjectIdentifier.cpp:976–1026  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

974}
975
976Document* 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
1028DocumentObject* ObjectIdentifier::getDocumentObject() const
1029{

Callers 7

replaceObjectMethod · 0.45
updateLabelReferenceMethod · 0.45
resolveMethod · 0.45
setDocumentObjectNameMethod · 0.45
checkImportMethod · 0.45
importSubNamesMethod · 0.45
resolveAmbiguityMethod · 0.45

Calls 8

isRealStringMethod · 0.80
isForceIdentifierMethod · 0.80
getDocumentsMethod · 0.80
emptyMethod · 0.45
getStringMethod · 0.45
c_strMethod · 0.45
toStringMethod · 0.45
getValueMethod · 0.45

Tested by

no test coverage detected