diff --git a/src/App/Document.cpp b/src/App/Document.cpp index 04b625add..737b2fed7 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -1175,6 +1175,20 @@ std::vector Document::getInList(const DocumentObject* me) return result; } +namespace boost { +// recursive helper function to get all dependencies +void out_edges_recursive(const Vertex& v, const DependencyList& g, std::set& out) +{ + DependencyList::out_edge_iterator j, jend; + for (boost::tie(j, jend) = boost::out_edges(v, g); j != jend; ++j) { + Vertex n = boost::target(*j, g); + std::pair::iterator, bool> i = out.insert(n); + if (i.second) + out_edges_recursive(n, g, out); + } +} +} + std::vector Document::getDependencyList(const std::vector& objs) const { @@ -1183,18 +1197,20 @@ Document::getDependencyList(const std::vector& objs) const std::map VertexMap; // Filling up the adjacency List - for (std::map::const_iterator It = d->objectMap.begin(); It != d->objectMap.end();++It) { + for (std::vector::const_iterator it = d->objectArray.begin(); it != d->objectArray.end();++it) { // add the object as Vertex and remember the index Vertex v = add_vertex(DepList); - ObjectMap[It->second] = v; - VertexMap[v] = It->second; + ObjectMap[*it] = v; + VertexMap[v] = *it; } + // add the edges - for (std::map::const_iterator It = d->objectMap.begin(); It != d->objectMap.end();++It) { - std::vector OutList = It->second->getOutList(); - for (std::vector::const_iterator It2=OutList.begin();It2!=OutList.end();++It2) { - if (*It2) - add_edge(ObjectMap[It->second],ObjectMap[*It2],DepList); + for (std::vector::const_iterator it = d->objectArray.begin(); it != d->objectArray.end();++it) { + std::vector outList = (*it)->getOutList(); + for (std::vector::const_iterator jt = outList.begin(); jt != outList.end();++jt) { + if (*jt) { + add_edge(ObjectMap[*it],ObjectMap[*jt],DepList); + } } } @@ -1209,21 +1225,20 @@ Document::getDependencyList(const std::vector& objs) const return std::vector(); } - //std::vector out; - boost::unordered_set out; + std::set out; for (std::vector::const_iterator it = objs.begin(); it != objs.end(); ++it) { std::map::iterator jt = ObjectMap.find(*it); // ok, object is part of this graph if (jt != ObjectMap.end()) { - for (boost::tie(j, jend) = boost::out_edges(jt->second, DepList); j != jend; ++j) { - out.insert(VertexMap[boost::target(*j, DepList)]); - } - out.insert(*it); + out.insert(jt->second); + out_edges_recursive(jt->second, DepList, out); } } std::vector ary; - ary.insert(ary.end(), out.begin(), out.end()); + ary.reserve(out.size()); + for (std::set::iterator it = out.begin(); it != out.end(); ++it) + ary.push_back(VertexMap[*it]); return ary; }