Skip to content

Commit

Permalink
ObjectIdentifier: Issue #2407: Fixed resolution of DocumentObject, to…
Browse files Browse the repository at this point in the history
… differentiate better between internal name and Label.
  • Loading branch information
eivindkv authored and wwmayer committed Jan 26, 2016
1 parent ed29d8e commit e9480e6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
32 changes: 22 additions & 10 deletions src/App/ObjectIdentifier.cpp
Expand Up @@ -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;
Expand All @@ -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
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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<const DocumentObject*>(owner)->getNameInDocument(), false, documentObjectName.isForceIdentifier());
documentObjectName = String(static_cast<const DocumentObject*>(owner)->getNameInDocument(), false, true);
propertyName = components[0].name.getString();
propertyIndex = 0;
}
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/App/ObjectIdentifier.h
Expand Up @@ -231,7 +231,7 @@ class AppExport ObjectIdentifier {

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;
Expand Down

0 comments on commit e9480e6

Please sign in to comment.