From fdabaf692b8cae4126a463ffe35da560f3ec078e Mon Sep 17 00:00:00 2001 From: Aapo Lankinen <74315529+aapo-aapo@users.noreply.github.com> Date: Wed, 19 Jan 2022 02:14:13 +0200 Subject: [PATCH] [App] DocumentObject.cpp: Add more information to the error message ... (#5394) * [App] DocumentObject.cpp: Add more information to the error message printed to the console when links go out of allowed scope, namely linked object name(s), allowed scope name, invalid scope name(s). --- src/App/DocumentObject.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/App/DocumentObject.cpp b/src/App/DocumentObject.cpp index 250b4bab10..70a1e63a58 100644 --- a/src/App/DocumentObject.cpp +++ b/src/App/DocumentObject.cpp @@ -100,7 +100,38 @@ App::DocumentObjectExecReturn *DocumentObject::recompute(void) //check if the links are valid before making the recompute if(!GeoFeatureGroupExtension::areLinksValid(this)) { #if 1 - Base::Console().Warning("%s / %s: Links go out of the allowed scope\n", getTypeId().getName(), getNameInDocument()); + // Get objects that have invalid link scope, and print their names. + // Truncate the invalid object list name strings for readibility, if they happen to be very long. + std::vector invalid_linkobjs; + std::string objnames = "", scopenames = ""; + GeoFeatureGroupExtension::getInvalidLinkObjects(this, invalid_linkobjs); + for (auto& obj : invalid_linkobjs) { + objnames += obj->getNameInDocument(); + objnames += " "; + for (auto& scope : obj->getParents()) { + if (scopenames.length() > 80) { + scopenames += "... "; + break; + } + scopenames += scope.first->getNameInDocument(); + scopenames += " "; + } + if (objnames.length() > 80) { + objnames += "... "; + break; + } + } + if (objnames.empty()) { + objnames = "N/A"; + } else { + objnames.pop_back(); + } + if (scopenames.empty()) { + scopenames = "N/A"; + } else { + scopenames.pop_back(); + } + Base::Console().Warning("%s: Link(s) to object(s) '%s' go out of the allowed scope '%s'. Instead, the linked object(s) reside within '%s'.\n", getTypeId().getName(), objnames.c_str(), getNameInDocument(), scopenames.c_str()); #else return new App::DocumentObjectExecReturn("Links go out of the allowed scope", this); #endif