Skip to content

Commit

Permalink
App: fix recursive App::getLinksTo()
Browse files Browse the repository at this point in the history
  • Loading branch information
realthunder authored and wwmayer committed Sep 27, 2020
1 parent 25fbb95 commit f9aed76
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/App/Application.h
Expand Up @@ -398,7 +398,7 @@ class AppExport Application
/** Return the links to a given object
*
* @param obj: the linked object. If NULL, then all links are returned.
* @param option: @sa App::GetLinkOptions
* @param option: @sa App::GetLinkOption
* @param maxCount: limit the number of links returned, 0 means no limit
*/
std::set<DocumentObject*> getLinksTo(
Expand Down
20 changes: 12 additions & 8 deletions src/App/Document.cpp
Expand Up @@ -2943,7 +2943,7 @@ void Document::getLinksTo(std::set<DocumentObject*> &links,
const DocumentObject *obj, int options, int maxCount,
const std::vector<DocumentObject*> &objs) const
{
std::map<const App::DocumentObject*,App::DocumentObject*> linkMap;
std::map<const App::DocumentObject*, std::vector<App::DocumentObject*> > linkMap;

for(auto o : objs.size()?objs:d->objectArray) {
if(o == obj) continue;
Expand All @@ -2960,7 +2960,7 @@ void Document::getLinksTo(std::set<DocumentObject*> &links,

if(linked && linked!=o) {
if(options & GetLinkRecursive)
linkMap[linked] = o;
linkMap[linked].push_back(o);
else if(linked == obj || !obj) {
if((options & GetLinkExternal)
&& linked->getDocument()==o->getDocument())
Expand All @@ -2983,15 +2983,19 @@ void Document::getLinksTo(std::set<DocumentObject*> &links,
if(!GetApplication().checkLinkDepth(depth,true))
break;
std::vector<const DocumentObject*> next;
for(auto o : current) {
for(const App::DocumentObject *o : current) {
auto iter = linkMap.find(o);
if(iter!=linkMap.end() && links.insert(iter->second).second) {
if(maxCount && maxCount<=(int)links.size())
return;
next.push_back(iter->second);
if(iter==linkMap.end())
continue;
for (App::DocumentObject *link : iter->second) {
if (links.insert(link).second) {
if(maxCount && maxCount<=(int)links.size())
return;
next.push_back(link);
}
}
}
current.swap(next);
current = std::move(next);
}
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/App/Document.h
Expand Up @@ -477,7 +477,7 @@ class AppExport Document : public App::PropertyContainer
*
* @param links: holds the links found
* @param obj: the linked object. If NULL, then all links are returned.
* @param option: @sa App::GetLinkOptions
* @param option: @sa App::GetLinkOption
* @param maxCount: limit the number of links returned, 0 means no limit
* @param objs: optional objects to search for, if empty, then all objects
* of this document are searched.
Expand Down

0 comments on commit f9aed76

Please sign in to comment.