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

Method getDocumentObject

src/App/ObjectIdentifier.cpp:791–844  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

789};
790
791App::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
846void ObjectIdentifier::resolve(ResolveResults& results) const
847{

Callers 15

getIdMethod · 0.80
addMethod · 0.80
addEdgesMethod · 0.80
validateExpressionMethod · 0.80
importSubNamesMethod · 0.80
parseStringMethod · 0.80
itemSearchMethod · 0.80
isBoundMethod · 0.80
setExpressionMethod · 0.80
bindMethod · 0.80
getExpressionMethod · 0.80

Calls 8

isRealStringMethod · 0.80
isForceIdentifierMethod · 0.80
getDocumentFunction · 0.50
getObjectMethod · 0.45
setMethod · 0.45
getObjectsMethod · 0.45
getValueMethod · 0.45
getNameMethod · 0.45

Tested by

no test coverage detected