From e9480e6a0927fb7b59d00fbb4ca753d092f29fc8 Mon Sep 17 00:00:00 2001 From: Eivind Kvedalen Date: Sat, 16 Jan 2016 21:48:32 +0100 Subject: [PATCH] ObjectIdentifier: Issue #2407: Fixed resolution of DocumentObject, to differentiate better between internal name and Label. --- src/App/ObjectIdentifier.cpp | 32 ++++++++++++++++++++++---------- src/App/ObjectIdentifier.h | 2 +- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/App/ObjectIdentifier.cpp b/src/App/ObjectIdentifier.cpp index 93cdbc283..5aa06af32 100644 --- a/src/App/ObjectIdentifier.cpp +++ b/src/App/ObjectIdentifier.cpp @@ -529,7 +529,7 @@ std::string ObjectIdentifier::Component::toString() const * @return Pointer to document object if a unique pointer is found, 0 otherwise. */ -App::DocumentObject * ObjectIdentifier::getDocumentObject(const App::Document * doc, const String & name) const +App::DocumentObject * ObjectIdentifier::getDocumentObject(const App::Document * doc, const String & name, bool & byIdentifier) const { DocumentObject * objectById = 0; DocumentObject * objectByLabel = 0; @@ -552,12 +552,18 @@ App::DocumentObject * ObjectIdentifier::getDocumentObject(const App::Document * if (objectByLabel == 0 && objectById == 0) // Not found at all return 0; - else if (objectByLabel == 0) // Found by name + else if (objectByLabel == 0) { // Found by name + byIdentifier = true; return objectById; - else if (objectById == 0) // Found by label + } + else if (objectById == 0) { // Found by label + byIdentifier = false; return objectByLabel; - else if (objectByLabel == objectById) // Found by both name and label, same object + } + else if (objectByLabel == objectById) { // Found by both name and label, same object + byIdentifier = false; return objectByLabel; + } else return 0; // Found by both name and label, two different objects } @@ -602,7 +608,9 @@ void ObjectIdentifier::resolve() const /* Document object name specified? */ if (documentObjectNameSet) { - docObject = getDocumentObject(doc, documentObjectName); + bool dummy; + + docObject = getDocumentObject(doc, documentObjectName, dummy); if (!docObject) return; if (components.size() > 0) { @@ -620,18 +628,20 @@ void ObjectIdentifier::resolve() const propertyIndex = 0; } else if (components.size() >= 2) { + bool byIdentifier; + if (!components[0].isSimple()) return; - docObject = getDocumentObject(doc, components[0].name); + docObject = getDocumentObject(doc, components[0].name, byIdentifier); if (docObject) { - documentObjectName = String(components[0].name, false, documentObjectName.isForceIdentifier()); + documentObjectName = String(components[0].name, false, byIdentifier); propertyName = components[1].name.getString(); propertyIndex = 1; } else { - documentObjectName = String(static_cast(owner)->getNameInDocument(), false, documentObjectName.isForceIdentifier()); + documentObjectName = String(static_cast(owner)->getNameInDocument(), false, true); propertyName = components[0].name.getString(); propertyIndex = 0; } @@ -690,11 +700,12 @@ Document * ObjectIdentifier::getDocument(String name) const DocumentObject *ObjectIdentifier::getDocumentObject() const { const App::Document * doc = getDocument(); + bool dummy; if (!doc) return 0; - return getDocumentObject(doc, documentObjectName); + return getDocumentObject(doc, documentObjectName, dummy); } /** @@ -782,11 +793,12 @@ ObjectIdentifier &ObjectIdentifier::operator <<(const ObjectIdentifier::Componen Property *ObjectIdentifier::getProperty() const { const App::Document * doc = getDocument(); + bool dummy; if (!doc) return 0; - App::DocumentObject * docObj = getDocumentObject(doc, documentObjectName); + App::DocumentObject * docObj = getDocumentObject(doc, documentObjectName, dummy); if (!docObj) return 0; diff --git a/src/App/ObjectIdentifier.h b/src/App/ObjectIdentifier.h index 28a4c4b59..9a27391ff 100644 --- a/src/App/ObjectIdentifier.h +++ b/src/App/ObjectIdentifier.h @@ -231,7 +231,7 @@ protected: void resolve() const; - App::DocumentObject *getDocumentObject(const App::Document *doc, const String &name) const; + App::DocumentObject *getDocumentObject(const App::Document *doc, const String &name, bool &byIdentifier) const; const App::PropertyContainer * owner; bool documentNameSet;