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:
Manuel Dobusch
2014-07-09 16:32:15 +02:00
parent 2009b7526a
commit d12fd3edf3
14 changed files with 338 additions and 64 deletions
@@ -22,6 +22,8 @@ void GraphController::handleMessage(MessageActivateToken* message)
if (view != NULL)
{
std::string name = m_graphAccess->getNameForNodeWithId(message->tokenId);
std::vector<std::pair<Id, Id> > rawEdges = m_graphAccess->getConnectedEdges(message->tokenId);
std::vector<Id> neighbourIds = m_graphAccess->getIdsOfNeighbours(message->tokenId);
DummyNode node(name, message->tokenId, Vec2i(0,0));
@@ -30,6 +32,48 @@ void GraphController::handleMessage(MessageActivateToken* message)
std::vector<DummyEdge> edges;
int offset = 20; // temporary
for(unsigned int i = 0; i < rawEdges.size(); i++)
{
edges.push_back(DummyEdge(rawEdges[i].first, rawEdges[i].second));
Id newId = 0;
if (rawEdges[i].first != message->tokenId)
{
name = m_graphAccess->getNameForNodeWithId(rawEdges[i].first);
newId = rawEdges[i].first;
}
else
{
name = m_graphAccess->getNameForNodeWithId(rawEdges[i].second);
newId = rawEdges[i].second;
}
nodes.push_back(DummyNode(name, newId, Vec2i(0, offset)));
offset += 20;
}
// find edges between neighbour nodes
for(unsigned int i = 1; i < nodes.size(); i++)
{
std::vector<std::pair<Id, Id>> newEdges = m_graphAccess->getConnectedEdges(nodes[i].tokenId);
for(unsigned int j = 0; j < newEdges.size(); j++)
{
if (std::find(neighbourIds.begin(), neighbourIds.end(), newEdges[j].first) != neighbourIds.end() &&
std::find(neighbourIds.begin(), neighbourIds.end(), newEdges[j].second) != neighbourIds.end())
{
DummyEdge newEdge(newEdges[j].first, newEdges[j].second);
if (std::find(edges.begin(), edges.end(), newEdge) == edges.end())
{
edges.push_back(newEdge);
}
}
}
}
view->rebuildGraph(nodes, edges);
}
}
@@ -3,6 +3,8 @@
#include <memory>
#include "utility/types.h"
class GraphNode;
class GraphEdge
@@ -13,20 +15,39 @@ public:
virtual void ownerMoved() = 0;
virtual void targetMoved() = 0;
virtual void removeEdgeFromScene() = 0;
virtual std::weak_ptr<GraphNode> getOwner() = 0;
virtual std::weak_ptr<GraphNode> getTarget() = 0;
};
// temporary data structure for (visual) graph creation process
struct DummyEdge
{
public:
DummyEdge(const std::weak_ptr<GraphNode> o, const std::weak_ptr<GraphNode> t)
: owner(o)
, target(t)
DummyEdge(const Id o, const Id t)
: ownerId(o)
, targetId(t)
{
}
std::weak_ptr<GraphNode> owner;
std::weak_ptr<GraphNode> target;
Id ownerId;
Id targetId;
bool operator==(const DummyEdge& other) const
{
if(ownerId == other.ownerId && targetId == other.targetId)
{
return true;
}
return false;
}
bool operator!=(const DummyEdge& other) const
{
return !(*this == other);
}
};
#endif // GRAPH_EDGE_H
@@ -18,10 +18,12 @@ public:
Id getTokenId();
virtual Vec2i getPosition() = 0;
virtual void addOutEdge(const std::shared_ptr<GraphEdge>& edge) = 0;
virtual void addInEdge(const std::weak_ptr<GraphEdge>& edge) = 0;
virtual bool addOutEdge(const std::shared_ptr<GraphEdge>& edge) = 0;
virtual bool addInEdge(const std::weak_ptr<GraphEdge>& edge) = 0;
virtual void removeOutEdge(const std::shared_ptr<GraphEdge>& edge) = 0;
virtual void removeOutEdge(GraphEdge* edge) = 0;
virtual void addSubNode(const std::shared_ptr<GraphNode>& node) = 0;
protected:
Id m_tokenId;