ui: graph showing neighbours
The graph view can now display the n1 neighbours of the active node, including connections between neighbours.
This commit is contained in:
@@ -239,6 +239,63 @@ std::vector<std::string> Storage::getNamesForNodesWithNamePrefix(const std::stri
|
||||
return names;
|
||||
}
|
||||
|
||||
std::vector<Id> Storage::getIdsOfNeighbours(const Id id) const
|
||||
{
|
||||
std::vector<Id> result;
|
||||
|
||||
Node* node = m_graph.findNode([&](Node* node){
|
||||
return node->getId() == id;
|
||||
});
|
||||
|
||||
if (node != NULL)
|
||||
{
|
||||
std::map<Id, bool> addedIds;
|
||||
addedIds[id] = true;
|
||||
|
||||
node->forEachEdge(
|
||||
[&result, &addedIds](Edge* e)
|
||||
{
|
||||
Id fromId = e->getFrom()->getId();
|
||||
if (addedIds.find(fromId) == addedIds.end())
|
||||
{
|
||||
result.push_back(fromId);
|
||||
addedIds[fromId] = true;
|
||||
}
|
||||
|
||||
Id toId = e->getTo()->getId();
|
||||
if (addedIds.find(toId) == addedIds.end())
|
||||
{
|
||||
result.push_back(toId);
|
||||
addedIds[toId] = true;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::pair<Id, Id>> Storage::getConnectedEdges(const Id id) const
|
||||
{
|
||||
std::vector<std::pair<Id, Id>> result;
|
||||
|
||||
Node* node = m_graph.findNode([&](Node* node){
|
||||
return node->getId() == id;
|
||||
});
|
||||
|
||||
if (node != NULL)
|
||||
{
|
||||
node->forEachEdge(
|
||||
[&result, &id](Edge* e)
|
||||
{
|
||||
result.push_back(std::pair<Id, Id>(e->getFrom()->getId(), e->getTo()->getId()));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
TokenLocationCollection Storage::getTokenLocationsForTokenId(Id id) const
|
||||
{
|
||||
TokenLocationCollection ret;
|
||||
|
||||
@@ -57,6 +57,8 @@ public:
|
||||
virtual Id getIdForNodeWithName(const std::string& name) const;
|
||||
virtual std::string getNameForNodeWithId(Id id) const;
|
||||
virtual std::vector<std::string> getNamesForNodesWithNamePrefix(const std::string& prefix) const;
|
||||
virtual std::vector<Id> getIdsOfNeighbours(const Id id) const;
|
||||
virtual std::vector<std::pair<Id, Id>> getConnectedEdges(const Id id) const;
|
||||
|
||||
// LocationAccess implementation
|
||||
virtual TokenLocationCollection getTokenLocationsForTokenId(Id locationId) const;
|
||||
|
||||
@@ -16,6 +16,8 @@ public:
|
||||
virtual Id getIdForNodeWithName(const std::string& name) const = 0;
|
||||
virtual std::string getNameForNodeWithId(Id id) const = 0;
|
||||
virtual std::vector<std::string> getNamesForNodesWithNamePrefix(const std::string& prefix) const = 0;
|
||||
virtual std::vector<Id> getIdsOfNeighbours(const Id id) const = 0;
|
||||
virtual std::vector<std::pair<Id, Id>> getConnectedEdges(const Id id) const = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user