ui: graph view layouting and member rendering
Added simple layouting functions (implementations for simple grid and circle layout). Also the graph displays class members and connections (edges) to or from them "correctly" now. fortune cookie message = Your exotic ideas will lead you to many exciting new adventures.
This commit is contained in:
@@ -13,10 +13,6 @@ y fooy();
|
||||
z fooz();
|
||||
*/
|
||||
|
||||
class A {};
|
||||
class B : public A {};
|
||||
typedef A* C;
|
||||
|
||||
const bool *ab(int a, int b);
|
||||
|
||||
bool const *abc(int a, int b);
|
||||
@@ -27,3 +23,66 @@ int main();
|
||||
void foo();
|
||||
int sum(int a, int b);
|
||||
int diff(int a, int b);
|
||||
|
||||
void funk();
|
||||
|
||||
class A
|
||||
{
|
||||
public:
|
||||
A()
|
||||
: m_importantValue(42)
|
||||
, m_importanterValue('r')
|
||||
, m_importantestValue(3.14159265359f)
|
||||
{
|
||||
}
|
||||
|
||||
~A()
|
||||
{
|
||||
}
|
||||
|
||||
void doImportantStuff()
|
||||
{
|
||||
m_importantValue *= 1;
|
||||
}
|
||||
|
||||
void doModeratelyImportantStuff()
|
||||
{
|
||||
m_importanterValue = 'R';
|
||||
|
||||
sum(21, 21);
|
||||
}
|
||||
|
||||
private:
|
||||
int m_importantValue;
|
||||
char m_importanterValue;
|
||||
float m_importantestValue;
|
||||
};
|
||||
|
||||
class B : public A {};
|
||||
|
||||
class C
|
||||
{
|
||||
public:
|
||||
C()
|
||||
: m_valuable(0)
|
||||
{
|
||||
}
|
||||
|
||||
~C()
|
||||
{
|
||||
}
|
||||
|
||||
void solveAllProblems()
|
||||
{
|
||||
A aInstance;
|
||||
aInstance.doImportantStuff();
|
||||
aInstance.doModeratelyImportantStuff();
|
||||
}
|
||||
|
||||
private:
|
||||
int m_valuable;
|
||||
};
|
||||
|
||||
A globalA;
|
||||
|
||||
typedef A* C;
|
||||
|
||||
@@ -7,6 +7,9 @@ int diff(int a, int b);
|
||||
|
||||
int main()
|
||||
{
|
||||
A aInstance;
|
||||
aInstance.doImportantStuff();
|
||||
|
||||
int a = sum(1, 2);
|
||||
int b = diff(a, 3);
|
||||
int c = a * b;
|
||||
@@ -33,3 +36,9 @@ int diff(int a, int b)
|
||||
{
|
||||
return a - b;
|
||||
}
|
||||
|
||||
void funk()
|
||||
{
|
||||
A aInstance;
|
||||
aInstance.doModeratelyImportantStuff();
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ add_files(
|
||||
qt/view/graphElements/QtGraphEdge.h
|
||||
qt/view/graphElements/QtGraphNode.cpp
|
||||
qt/view/graphElements/QtGraphNode.h
|
||||
qt/view/graphElements/QtGraphNodeMovable.cpp
|
||||
qt/view/graphElements/QtGraphNodeMovable.h
|
||||
qt/view/graphElements/QtGraphNodeMouseMovable.cpp
|
||||
qt/view/graphElements/QtGraphNodeMouseMovable.h
|
||||
|
||||
qt/view/QtCodeView.cpp
|
||||
qt/view/QtCodeView.h
|
||||
|
||||
+114
-14
@@ -12,7 +12,7 @@
|
||||
#include "qt/QtWidgetWrapper.h"
|
||||
#include "qt/view/graphElements/QtGraphEdge.h"
|
||||
#include "qt/view/graphElements/QtGraphNode.h"
|
||||
#include "qt/view/graphElements/QtGraphNodeMovable.h"
|
||||
#include "qt/view/graphElements/QtGraphNodeMouseMovable.h"
|
||||
|
||||
QtGraphView::QtGraphView(ViewLayout* viewLayout)
|
||||
: GraphView(viewLayout)
|
||||
@@ -83,6 +83,7 @@ void QtGraphView::doRebuildGraph(const std::vector<DummyNode>& nodes, const std:
|
||||
for(unsigned int i = 0; i < nodes.size(); i++)
|
||||
{
|
||||
std::shared_ptr<GraphNode> newNode = findOrCreateNode(view, nodes[i]);
|
||||
newNode->setPosition(nodes[i].position);
|
||||
newNodes.push_back(newNode);
|
||||
weakNodes[nodes[i].tokenId] = newNode;
|
||||
}
|
||||
@@ -90,8 +91,17 @@ void QtGraphView::doRebuildGraph(const std::vector<DummyNode>& nodes, const std:
|
||||
doClear();
|
||||
m_nodes = newNodes;
|
||||
|
||||
// create edges
|
||||
for(unsigned int i = 0; i < edges.size(); i++)
|
||||
{
|
||||
std::shared_ptr<GraphEdge> edge = createEdge(view, edges[i]);
|
||||
if(edge != NULL)
|
||||
{
|
||||
m_edges.push_back(edge);
|
||||
}
|
||||
}
|
||||
|
||||
// create edges
|
||||
/*for(unsigned int i = 0; i < edges.size(); i++)
|
||||
{
|
||||
if (weakNodes.find(edges[i].ownerId) != weakNodes.end() && weakNodes.find(edges[i].targetId) != weakNodes.end())
|
||||
{
|
||||
@@ -106,7 +116,7 @@ void QtGraphView::doRebuildGraph(const std::vector<DummyNode>& nodes, const std:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -124,7 +134,7 @@ std::shared_ptr<GraphNode> QtGraphView::findOrCreateNode(QGraphicsView* view, co
|
||||
{
|
||||
std::shared_ptr<GraphNode> result;
|
||||
|
||||
result = findNode(node);
|
||||
result = findNode(node.tokenId);
|
||||
|
||||
if(result == NULL)
|
||||
{
|
||||
@@ -134,41 +144,131 @@ std::shared_ptr<GraphNode> QtGraphView::findOrCreateNode(QGraphicsView* view, co
|
||||
return result;
|
||||
}
|
||||
|
||||
std::shared_ptr<GraphNode> QtGraphView::findNode(const DummyNode& node)
|
||||
std::shared_ptr<GraphNode> QtGraphView::findNode(const Id id)
|
||||
{
|
||||
std::list<std::shared_ptr<GraphNode>>::iterator it = m_nodes.begin();
|
||||
|
||||
for(it; it != m_nodes.end(); it++)
|
||||
{
|
||||
if((*it)->getTokenId() == node.tokenId)
|
||||
if((*it)->getTokenId() == id)
|
||||
{
|
||||
return *it;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::shared_ptr<GraphNode> result = findSubNode(*it, id);
|
||||
if(result != NULL)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return std::shared_ptr<GraphNode>();
|
||||
}
|
||||
|
||||
std::shared_ptr<GraphNode> QtGraphView::findSubNode(const std::shared_ptr<GraphNode> node, const Id id)
|
||||
{
|
||||
std::list<std::shared_ptr<GraphNode>> subNodes = node->getSubNodes();
|
||||
|
||||
std::list<std::shared_ptr<GraphNode>>::iterator it = subNodes.begin();
|
||||
for(it; it != subNodes.end(); it++)
|
||||
{
|
||||
if((*it)->getTokenId() == id)
|
||||
{
|
||||
return *it;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::shared_ptr<GraphNode> result = findSubNode(*it, id);
|
||||
if(result != NULL)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return std::shared_ptr<GraphNode>();
|
||||
}
|
||||
|
||||
std::shared_ptr<GraphNode> QtGraphView::createNode(QGraphicsView* view, const DummyNode& node)
|
||||
{
|
||||
if(view != NULL)
|
||||
{
|
||||
std::shared_ptr<QtGraphNodeMovable> newNode = std::make_shared<QtGraphNodeMovable>(node.position, node.name, node.tokenId);
|
||||
std::shared_ptr<QtGraphNodeMouseMovable> newNode = std::make_shared<QtGraphNodeMouseMovable>(Vec2i(0, 0), node.name, node.tokenId);
|
||||
view->scene()->addItem(newNode.get());
|
||||
m_nodes.push_back(newNode);
|
||||
|
||||
// create debug sub node
|
||||
std::shared_ptr<QtGraphNode> subNode = std::make_shared<QtGraphNode>(Vec2i(10, 30), node.name + " member", 666);
|
||||
subNode->setParentItem(newNode.get());
|
||||
view->scene()->addItem(subNode.get());
|
||||
newNode->addSubNode(subNode);
|
||||
for(unsigned int i = 0; i < node.subNodes.size(); i++)
|
||||
{
|
||||
std::shared_ptr<QtGraphNode> subNode = createSubNode(view, node.subNodes[i]);
|
||||
subNode->setParentItem(newNode.get());
|
||||
newNode->addSubNode(subNode);
|
||||
subNode->setRect(0, 0, 80, 20);
|
||||
subNode->moveBy(10, (i+1)*30);
|
||||
}
|
||||
|
||||
subNode->setRect(0, 0, 80, 20);
|
||||
newNode->setRect(0, 0, 100, 40 + (node.subNodes.size() * 30));
|
||||
|
||||
return newNode;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_WARNING("Received pointer to QGraphicsView was NULL. No node created.");
|
||||
return std::shared_ptr<QtGraphNode>();
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<QtGraphNode> QtGraphView::createSubNode(QGraphicsView* view, const DummyNode& node)
|
||||
{
|
||||
if(view != NULL)
|
||||
{
|
||||
std::shared_ptr<QtGraphNode> newNode = std::make_shared<QtGraphNode>(Vec2i(0, 0), node.name, node.tokenId);
|
||||
view->scene()->addItem(newNode.get());
|
||||
|
||||
for(unsigned int i = 0; i < node.subNodes.size(); i++)
|
||||
{
|
||||
std::shared_ptr<QtGraphNode> subNode = createSubNode(view, node.subNodes[i]);
|
||||
subNode->setParentItem(newNode.get());
|
||||
newNode->addSubNode(subNode);
|
||||
subNode->setRect(0, 0, 80, 20);
|
||||
subNode->moveBy(10, (i+1)*30);
|
||||
}
|
||||
|
||||
return newNode;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_WARNING("Received pointer to QGraphicsView was NULL. No node created.");
|
||||
return std::shared_ptr<QtGraphNode>();
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<QtGraphEdge> QtGraphView::createEdge(QGraphicsView* view, const DummyEdge& edge)
|
||||
{
|
||||
if(view != NULL)
|
||||
{
|
||||
std::shared_ptr<GraphNode> owner = findNode(edge.ownerId);
|
||||
std::shared_ptr<GraphNode> target = findNode(edge.targetId);
|
||||
|
||||
if(owner != NULL && target != NULL)
|
||||
{
|
||||
std::shared_ptr<QtGraphEdge> edge = std::make_shared<QtGraphEdge>(owner, target);
|
||||
owner->addOutEdge(edge);
|
||||
target->addInEdge(edge);
|
||||
view->scene()->addItem(edge.get());
|
||||
|
||||
return edge;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_WARNING("Couldn't find owner or target node.");
|
||||
return std::shared_ptr<QtGraphEdge>();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_WARNING("Received pointer to QGraphicsView was NULL. No node created.");
|
||||
return std::shared_ptr<QtGraphEdge>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,15 @@
|
||||
|
||||
#include "qt/utility/QtThreadedFunctor.h"
|
||||
|
||||
#include "utility/types.h"
|
||||
|
||||
#include "component/view/GraphView.h"
|
||||
|
||||
struct DummyEdge;
|
||||
struct DummyNode;
|
||||
class QGraphicsView;
|
||||
class QtGraphEdge;
|
||||
class QtGraphNode;
|
||||
|
||||
class QtGraphView : public GraphView
|
||||
{
|
||||
@@ -30,8 +34,12 @@ private:
|
||||
void doClear();
|
||||
|
||||
std::shared_ptr<GraphNode> findOrCreateNode(QGraphicsView* view, const DummyNode& node);
|
||||
std::shared_ptr<GraphNode> findNode(const DummyNode& node);
|
||||
std::shared_ptr<GraphNode> findNode(const Id id);
|
||||
std::shared_ptr<GraphNode> findSubNode(const std::shared_ptr<GraphNode> node, const Id id);
|
||||
std::shared_ptr<GraphNode> createNode(QGraphicsView* view, const DummyNode& node);
|
||||
std::shared_ptr<QtGraphNode> createSubNode(QGraphicsView* view, const DummyNode& node);
|
||||
|
||||
std::shared_ptr<QtGraphEdge> createEdge(QGraphicsView* view, const DummyEdge& edge);
|
||||
|
||||
QtThreadedFunctor<const std::vector<DummyNode>&, const std::vector<DummyEdge>&> m_rebuildGraph;
|
||||
QtThreadedFunctor<void> m_clear;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "qt/view/graphElements/QtGraphNode.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "qgraphicsscene.h"
|
||||
#include "qgraphicssceneevent.h"
|
||||
|
||||
@@ -15,7 +17,9 @@ QtGraphNode::QtGraphNode(const Vec2i& position, const std::string& name, const I
|
||||
|
||||
m_text = new QGraphicsTextItem(this);
|
||||
m_text->setPos(0, 0);
|
||||
m_text->setPlainText(QString(name.c_str()));
|
||||
std::stringstream text;
|
||||
text << m_tokenId << " -> " << name;
|
||||
m_text->setPlainText(QString(text.str().c_str()));
|
||||
}
|
||||
|
||||
QtGraphNode::~QtGraphNode()
|
||||
@@ -31,16 +35,28 @@ QtGraphNode::~QtGraphNode()
|
||||
}
|
||||
}
|
||||
|
||||
std::string QtGraphNode::getName()
|
||||
std::string QtGraphNode::getName() const
|
||||
{
|
||||
return m_text->toPlainText().toStdString();
|
||||
}
|
||||
|
||||
Vec2i QtGraphNode::getPosition()
|
||||
Vec2i QtGraphNode::getPosition() const
|
||||
{
|
||||
return Vec2i(this->scenePos().x(), this->scenePos().y());
|
||||
}
|
||||
|
||||
void QtGraphNode::setPosition(const Vec2i& position)
|
||||
{
|
||||
Vec2i currentPosition = getPosition();
|
||||
Vec2i offset = position - currentPosition;
|
||||
|
||||
if(offset.getLength() > 0.0f)
|
||||
{
|
||||
this->moveBy(offset.x, offset.y);
|
||||
notifyEdgesAfterMove();
|
||||
}
|
||||
}
|
||||
|
||||
bool QtGraphNode::addOutEdge(const std::shared_ptr<GraphEdge>& edge)
|
||||
{
|
||||
std::list<std::shared_ptr<GraphEdge> >::iterator it = m_outEdges.begin();
|
||||
@@ -91,6 +107,11 @@ void QtGraphNode::removeOutEdge(GraphEdge* edge)
|
||||
}
|
||||
}
|
||||
|
||||
std::list<std::shared_ptr<GraphNode> > QtGraphNode::getSubNodes() const
|
||||
{
|
||||
return m_subNodes;
|
||||
}
|
||||
|
||||
void QtGraphNode::addSubNode(const std::shared_ptr<GraphNode>& node)
|
||||
{
|
||||
m_subNodes.push_back(node);
|
||||
@@ -101,3 +122,38 @@ void QtGraphNode::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event)
|
||||
MessageActivateToken message(m_tokenId);
|
||||
message.dispatch();
|
||||
}
|
||||
|
||||
void QtGraphNode::notifyParentMoved()
|
||||
{
|
||||
notifyEdgesAfterMove();
|
||||
}
|
||||
|
||||
void QtGraphNode::notifyEdgesAfterMove()
|
||||
{
|
||||
std::list<std::shared_ptr<GraphEdge> >::iterator it = m_outEdges.begin();
|
||||
for(it; it != m_outEdges.end(); it++)
|
||||
{
|
||||
(*it)->ownerMoved();
|
||||
}
|
||||
|
||||
std::list<std::weak_ptr<GraphEdge> >::iterator it2 = m_inEdges.begin();
|
||||
while(it2 != m_inEdges.end())
|
||||
{
|
||||
std::shared_ptr<GraphEdge> edge = it2->lock();
|
||||
if(edge.get() != NULL)
|
||||
{
|
||||
edge->targetMoved();
|
||||
++it2;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_inEdges.erase(it2++);
|
||||
}
|
||||
}
|
||||
|
||||
std::list<std::shared_ptr<GraphNode> >::iterator it3 = m_subNodes.begin();
|
||||
for(it3; it3 != m_subNodes.end(); it3++)
|
||||
{
|
||||
(*it3)->notifyParentMoved();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,19 +18,25 @@ public:
|
||||
QtGraphNode(const Vec2i& position, const std::string& name, const Id tokenId);
|
||||
virtual ~QtGraphNode();
|
||||
|
||||
virtual std::string getName();
|
||||
virtual Vec2i getPosition();
|
||||
virtual std::string getName() const;
|
||||
virtual Vec2i getPosition() const;
|
||||
virtual void setPosition(const Vec2i& position);
|
||||
|
||||
virtual bool addOutEdge(const std::shared_ptr<GraphEdge>& edge);
|
||||
virtual bool addInEdge(const std::weak_ptr<GraphEdge>& edge);
|
||||
|
||||
virtual void removeOutEdge(GraphEdge* edge);
|
||||
|
||||
virtual std::list<std::shared_ptr<GraphNode> > getSubNodes() const;
|
||||
virtual void addSubNode(const std::shared_ptr<GraphNode>& node);
|
||||
|
||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event);
|
||||
|
||||
virtual void notifyParentMoved();
|
||||
|
||||
protected:
|
||||
void notifyEdgesAfterMove();
|
||||
|
||||
std::list<std::shared_ptr<GraphEdge> > m_outEdges;
|
||||
std::list<std::weak_ptr<GraphEdge> > m_inEdges;
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#include "qt/view/graphElements/QtGraphNodeMouseMovable.h"
|
||||
|
||||
#include "qgraphicssceneevent.h"
|
||||
|
||||
#include "qt/view/graphElements/QtGraphEdge.h"
|
||||
|
||||
QtGraphNodeMouseMovable::QtGraphNodeMouseMovable(const Vec2i& position, const std::string& name, const Id tokenId)
|
||||
: QtGraphNode(position, name, tokenId)
|
||||
{
|
||||
}
|
||||
|
||||
QtGraphNodeMouseMovable::~QtGraphNodeMouseMovable()
|
||||
{
|
||||
}
|
||||
|
||||
void QtGraphNodeMouseMovable::mousePressEvent(QGraphicsSceneMouseEvent* event)
|
||||
{
|
||||
m_mouseOffset.x = event->pos().x();
|
||||
m_mouseOffset.y = event->pos().y();
|
||||
}
|
||||
|
||||
void QtGraphNodeMouseMovable::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
|
||||
{
|
||||
this->setPos(event->scenePos().x() - m_mouseOffset.x, event->scenePos().y() - m_mouseOffset.y);
|
||||
|
||||
Vec2i p(event->scenePos().x(), event->scenePos().y());
|
||||
|
||||
notifyEdgesAfterMove();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef QT_GRAPH_NODE_MOUSE_MOVABLE_H
|
||||
#define QT_GRAPH_NODE_MOUSE_MOVABLE_H
|
||||
|
||||
#include "qt/view/graphElements/QtGraphNode.h"
|
||||
|
||||
class QtGraphNodeMouseMovable : public QtGraphNode
|
||||
{
|
||||
public:
|
||||
QtGraphNodeMouseMovable(const Vec2i& position, const std::string& name, const Id tokenId);
|
||||
virtual ~QtGraphNodeMouseMovable();
|
||||
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent* event);
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
|
||||
|
||||
private:
|
||||
Vec2i m_mouseOffset;
|
||||
};
|
||||
|
||||
#endif // QT_GRAPH_NODE_MOUSE_MOVABLE_H
|
||||
@@ -1,48 +0,0 @@
|
||||
#include "qt/view/graphElements/QtGraphNodeMovable.h"
|
||||
|
||||
#include "qgraphicssceneevent.h"
|
||||
|
||||
#include "qt/view/graphElements/QtGraphEdge.h"
|
||||
|
||||
QtGraphNodeMovable::QtGraphNodeMovable(const Vec2i& position, const std::string& name, const Id tokenId)
|
||||
: QtGraphNode(position, name, tokenId)
|
||||
{
|
||||
}
|
||||
|
||||
QtGraphNodeMovable::~QtGraphNodeMovable()
|
||||
{
|
||||
}
|
||||
|
||||
void QtGraphNodeMovable::mousePressEvent(QGraphicsSceneMouseEvent* event)
|
||||
{
|
||||
m_mouseOffset.x = event->pos().x();
|
||||
m_mouseOffset.y = event->pos().y();
|
||||
}
|
||||
|
||||
void QtGraphNodeMovable::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
|
||||
{
|
||||
this->setPos(event->scenePos().x() - m_mouseOffset.x, event->scenePos().y() - m_mouseOffset.y);
|
||||
|
||||
Vec2i p(event->scenePos().x(), event->scenePos().y());
|
||||
|
||||
std::list<std::shared_ptr<GraphEdge> >::iterator it = m_outEdges.begin();
|
||||
for(it; it != m_outEdges.end(); it++)
|
||||
{
|
||||
(*it)->ownerMoved();
|
||||
}
|
||||
|
||||
std::list<std::weak_ptr<GraphEdge> >::iterator it2 = m_inEdges.begin();
|
||||
while(it2 != m_inEdges.end())
|
||||
{
|
||||
std::shared_ptr<GraphEdge> edge = it2->lock();
|
||||
if(edge.get() != NULL)
|
||||
{
|
||||
edge->targetMoved();
|
||||
++it2;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_inEdges.erase(it2++);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
#ifndef QT_GRAPH_NODE_MOVABLE_H
|
||||
#define QT_GRAPH_NODE_MOVABLE_H
|
||||
|
||||
#include "qt/view/graphElements/QtGraphNode.h"
|
||||
|
||||
class QtGraphNodeMovable : public QtGraphNode
|
||||
{
|
||||
public:
|
||||
QtGraphNodeMovable(const Vec2i& position, const std::string& name, const Id tokenId);
|
||||
virtual ~QtGraphNodeMovable();
|
||||
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent* event);
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
|
||||
|
||||
private:
|
||||
Vec2i m_mouseOffset;
|
||||
};
|
||||
|
||||
#endif // QT_GRAPH_NODE_MOVABLE_H
|
||||
@@ -28,6 +28,8 @@ add_files(
|
||||
component/controller/Controller.h
|
||||
component/controller/GraphController.cpp
|
||||
component/controller/GraphController.h
|
||||
component/controller/GraphLayouter.cpp
|
||||
component/controller/GraphLayouter.h
|
||||
component/controller/SearchController.cpp
|
||||
component/controller/SearchController.h
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "component/controller/GraphController.h"
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
#include "component/view/graphElements/GraphEdge.h"
|
||||
#include "component/view/graphElements/GraphNode.h"
|
||||
#include "component/view/GraphView.h"
|
||||
@@ -18,67 +20,235 @@ GraphController::~GraphController()
|
||||
|
||||
void GraphController::handleMessage(MessageActivateToken* message)
|
||||
{
|
||||
GraphView* view = getView();
|
||||
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));
|
||||
|
||||
std::vector<DummyNode> nodes;
|
||||
nodes.push_back(node);
|
||||
|
||||
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);
|
||||
}
|
||||
createDummyGraph(message->tokenId, &GraphLayouter::layoutSimpleRing);
|
||||
}
|
||||
|
||||
GraphView* GraphController::getView()
|
||||
{
|
||||
return Controller::getView<GraphView>();
|
||||
}
|
||||
|
||||
void GraphController::createDummyGraph(const Id activeId, const LayoutFunction layoutFunction)
|
||||
{
|
||||
GraphView* view = getView();
|
||||
if (view != NULL)
|
||||
{
|
||||
std::vector<DummyNode> nodes;
|
||||
std::vector<DummyEdge> edges;
|
||||
|
||||
nodes.push_back(createDummyNode(activeId));
|
||||
|
||||
std::vector<DummyNode> neighbours = createNeighbourNodes(nodes[0]);
|
||||
nodes.insert(nodes.end(), neighbours.begin(), neighbours.end());
|
||||
|
||||
layoutFunction(nodes);
|
||||
|
||||
edges = createEdges(nodes);
|
||||
|
||||
view->rebuildGraph(nodes, edges);
|
||||
}
|
||||
}
|
||||
|
||||
DummyNode GraphController::createDummyNode(const Id nodeId)
|
||||
{
|
||||
DummyNode result("invalid", 0, Vec2i());
|
||||
|
||||
Id topLevelId = findTopLevelNode(nodeId);
|
||||
|
||||
result = buildNodeTopDown(topLevelId);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Id GraphController::findTopLevelNode(const Id nodeId)
|
||||
{
|
||||
std::vector<std::pair<Id, Id>> memberEdges = m_graphAccess->getMemberEdgesOfNode(nodeId);
|
||||
|
||||
for(unsigned int i = 0; i < memberEdges.size(); i++)
|
||||
{
|
||||
if(memberEdges[i].first != nodeId)
|
||||
{
|
||||
return findTopLevelNode(memberEdges[i].first);
|
||||
}
|
||||
}
|
||||
|
||||
return nodeId;
|
||||
}
|
||||
|
||||
DummyNode GraphController::buildNodeTopDown(const Id nodeId)
|
||||
{
|
||||
DummyNode result("invalid", 0, Vec2i());
|
||||
|
||||
result.name = m_graphAccess->getNameForNodeWithId(nodeId);
|
||||
result.tokenId = nodeId;
|
||||
|
||||
std::vector<std::pair<Id, Id>> memberEdges = m_graphAccess->getMemberEdgesOfNode(nodeId);
|
||||
|
||||
for(unsigned int i = 0; i < memberEdges.size(); i++)
|
||||
{
|
||||
if(memberEdges[i].second != nodeId)
|
||||
{
|
||||
result.subNodes.push_back(buildNodeTopDown(memberEdges[i].second));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<DummyNode> GraphController::createNeighbourNodes(const Id nodeId)
|
||||
{
|
||||
std::vector<DummyNode> result;
|
||||
|
||||
std::vector<std::pair<Id, Id>> edges;
|
||||
std::vector<std::pair<Id, Id>> callEdges = m_graphAccess->getCallEdgesOfNode(nodeId);
|
||||
std::vector<std::pair<Id, Id>> usageEdges = m_graphAccess->getUsageEdgesOfNode(nodeId);
|
||||
std::vector<std::pair<Id, Id>> typeOfEdges = m_graphAccess->getTypeOfEdgesOfNode(nodeId);
|
||||
std::vector<std::pair<Id, Id>> returnTypeEdges = m_graphAccess->getReturnTypeOfEdgesOfNode(nodeId);
|
||||
std::vector<std::pair<Id, Id>> parameterEdges = m_graphAccess->getParameterOfEdgesOfNode(nodeId);
|
||||
|
||||
if(callEdges.size() > 0)
|
||||
{
|
||||
edges.insert(edges.end(), callEdges.begin(), callEdges.end());
|
||||
}
|
||||
if(usageEdges.size() > 0)
|
||||
{
|
||||
edges.insert(edges.end(), usageEdges.begin(), usageEdges.end());
|
||||
}
|
||||
if(typeOfEdges.size() > 0)
|
||||
{
|
||||
edges.insert(edges.end(), typeOfEdges.begin(), typeOfEdges.end());
|
||||
}
|
||||
if(returnTypeEdges.size() > 0)
|
||||
{
|
||||
edges.insert(edges.end(), returnTypeEdges.begin(), returnTypeEdges.end());
|
||||
}
|
||||
if(parameterEdges.size() > 0)
|
||||
{
|
||||
edges.insert(edges.end(), parameterEdges.begin(), parameterEdges.end());
|
||||
}
|
||||
|
||||
for(unsigned int i = 0; i < edges.size(); i++)
|
||||
{
|
||||
if(edges[i].first == nodeId)
|
||||
{
|
||||
result.push_back(createDummyNode(edges[i].second));
|
||||
}
|
||||
else
|
||||
{
|
||||
result.push_back(createDummyNode(edges[i].first));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<DummyNode> GraphController::createNeighbourNodes(const DummyNode& node)
|
||||
{
|
||||
std::vector<DummyNode> result;
|
||||
|
||||
std::set<DummyNode> tmpNodes; // to make it easier to keep the nodes unique
|
||||
|
||||
result = createNeighbourNodes(node.tokenId);
|
||||
for(unsigned int i = 0; i < result.size(); i++)
|
||||
{
|
||||
tmpNodes.insert(result[i]);
|
||||
}
|
||||
|
||||
for(unsigned int i = 0; i < node.subNodes.size(); i++)
|
||||
{
|
||||
std::vector<DummyNode> tmpNeighbours = createNeighbourNodes(node.subNodes[i].tokenId);
|
||||
for(unsigned int j = 0; j < tmpNeighbours.size(); j++)
|
||||
{
|
||||
tmpNodes.insert(tmpNeighbours[j]);
|
||||
}
|
||||
}
|
||||
|
||||
result.clear();
|
||||
std::set<DummyNode>::iterator it = tmpNodes.begin();
|
||||
for(it; it != tmpNodes.end(); it++)
|
||||
{
|
||||
result.push_back(*it);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<DummyEdge> GraphController::createEdges(const std::vector<DummyNode>& nodes)
|
||||
{
|
||||
std::vector<DummyEdge> result;
|
||||
|
||||
std::unordered_set<Id> nodeIds; // to help discard edges that point to non-existing nodes in the sub-graph
|
||||
for(unsigned int i = 0; i < nodes.size(); i++)
|
||||
{
|
||||
nodeIds.insert(nodes[i].tokenId);
|
||||
}
|
||||
|
||||
std::set<DummyEdge> tmpEdges; // to make it easier to keep the edges unique
|
||||
for(unsigned int i = 0; i < nodes.size(); i++)
|
||||
{
|
||||
std::set<DummyEdge> tmp = getNeighbourEdgesOfNode(nodes[i]);
|
||||
|
||||
std::set<DummyEdge>::iterator it = tmp.begin();
|
||||
for(it; it != tmp.end(); it++)
|
||||
{
|
||||
if(nodeIds.find(it->ownerId) != nodeIds.end() && nodeIds.find(it->targetId) != nodeIds.end())
|
||||
{
|
||||
tmpEdges.insert(tmp.begin(), tmp.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::set<DummyEdge>::iterator it = tmpEdges.begin();
|
||||
for(it; it != tmpEdges.end(); it++)
|
||||
{
|
||||
result.push_back(*it);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::set<DummyEdge> GraphController::getNeighbourEdgesOfNode(const DummyNode& node)
|
||||
{
|
||||
std::set<DummyEdge> result;
|
||||
|
||||
std::vector<std::pair<Id, Id>> rawEdges;
|
||||
std::vector<std::pair<Id, Id>> callEdges = m_graphAccess->getCallEdgesOfNode(node.tokenId);
|
||||
std::vector<std::pair<Id, Id>> usageEdges = m_graphAccess->getUsageEdgesOfNode(node.tokenId);
|
||||
std::vector<std::pair<Id, Id>> typeOfEdges = m_graphAccess->getTypeOfEdgesOfNode(node.tokenId);
|
||||
std::vector<std::pair<Id, Id>> returnTypeEdges = m_graphAccess->getReturnTypeOfEdgesOfNode(node.tokenId);
|
||||
std::vector<std::pair<Id, Id>> parameterEdges = m_graphAccess->getParameterOfEdgesOfNode(node.tokenId);
|
||||
|
||||
if(callEdges.size() > 0)
|
||||
{
|
||||
rawEdges.insert(rawEdges.end(), callEdges.begin(), callEdges.end());
|
||||
}
|
||||
if(usageEdges.size() > 0)
|
||||
{
|
||||
rawEdges.insert(rawEdges.end(), usageEdges.begin(), usageEdges.end());
|
||||
}
|
||||
if(typeOfEdges.size() > 0)
|
||||
{
|
||||
rawEdges.insert(rawEdges.end(), typeOfEdges.begin(), typeOfEdges.end());
|
||||
}
|
||||
if(returnTypeEdges.size() > 0)
|
||||
{
|
||||
rawEdges.insert(rawEdges.end(), returnTypeEdges.begin(), returnTypeEdges.end());
|
||||
}
|
||||
if(parameterEdges.size() > 0)
|
||||
{
|
||||
rawEdges.insert(rawEdges.end(), parameterEdges.begin(), parameterEdges.end());
|
||||
}
|
||||
|
||||
for(unsigned int i = 0; i < rawEdges.size(); i++)
|
||||
{
|
||||
result.insert(DummyEdge(rawEdges[i].first, rawEdges[i].second));
|
||||
}
|
||||
|
||||
for(unsigned int i = 0; i < node.subNodes.size(); i++)
|
||||
{
|
||||
std::set<DummyEdge> tmpNeighbours = getNeighbourEdgesOfNode(node.subNodes[i]);
|
||||
result.insert(tmpNeighbours.begin(), tmpNeighbours.end());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
#ifndef GRAPH_CONTROLLER_H
|
||||
#define GRAPH_CONTROLLER_H
|
||||
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
#include "utility/messaging/MessageListener.h"
|
||||
#include "utility/messaging/type/MessageActivateToken.h"
|
||||
|
||||
#include "component/controller/Controller.h"
|
||||
#include "component/controller/GraphLayouter.h"
|
||||
|
||||
struct DummyNode;
|
||||
struct DummyEdge;
|
||||
class GraphView;
|
||||
class GraphAccess;
|
||||
|
||||
@@ -20,6 +26,17 @@ public:
|
||||
private:
|
||||
virtual void handleMessage(MessageActivateToken* message);
|
||||
GraphView* getView();
|
||||
void createDummyGraph(const Id activeId, const LayoutFunction layoutFunction);
|
||||
|
||||
DummyNode createDummyNode(const Id nodeId);
|
||||
Id findTopLevelNode(const Id nodeId);
|
||||
DummyNode buildNodeTopDown(const Id nodeId);
|
||||
|
||||
std::vector<DummyNode> createNeighbourNodes(const Id nodeId);
|
||||
std::vector<DummyNode> createNeighbourNodes(const DummyNode& node);
|
||||
|
||||
std::vector<DummyEdge> createEdges(const std::vector<DummyNode>& nodes);
|
||||
std::set<DummyEdge> getNeighbourEdgesOfNode(const DummyNode& node);
|
||||
|
||||
GraphAccess* m_graphAccess;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
#include "component/controller/GraphLayouter.h"
|
||||
|
||||
#include "component/view/graphElements/GraphNode.h"
|
||||
|
||||
void GraphLayouter::layoutSimpleRaster(std::vector<DummyNode>& nodes)
|
||||
{
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int offset = 150;
|
||||
|
||||
for(unsigned int i = 0; i < nodes.size(); i++)
|
||||
{
|
||||
nodes[i].position = Vec2i(x, y);
|
||||
|
||||
if(x > 0)
|
||||
{
|
||||
y += offset;
|
||||
x = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
x += offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GraphLayouter::layoutSimpleRing(std::vector<DummyNode>& nodes)
|
||||
{
|
||||
if(nodes.size() >= 1)
|
||||
{
|
||||
nodes[0].position = Vec2i(0, 0);
|
||||
|
||||
if(nodes.size() > 1)
|
||||
{
|
||||
int offset = 150;
|
||||
|
||||
for(unsigned int i = 1; i < nodes.size(); i++)
|
||||
{
|
||||
float rad = ((2.0f*3.14159265359f) / float(nodes.size()-1)) * i-1;
|
||||
|
||||
int x = (int)((float)offset * std::cos(rad));
|
||||
int y = (int)((float)offset * std::sin(rad));
|
||||
|
||||
nodes[i].position = Vec2i(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef GRAPH_LAYOUTER_H
|
||||
#define GRAPH_LAYOUTER_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
class DummyNode;
|
||||
|
||||
typedef void (*LayoutFunction)(std::vector<DummyNode>&);
|
||||
|
||||
class GraphLayouter
|
||||
{
|
||||
public:
|
||||
static void layoutSimpleRaster(std::vector<DummyNode>& nodes);
|
||||
static void layoutSimpleRing(std::vector<DummyNode>& nodes);
|
||||
};
|
||||
|
||||
#endif // GRAPH_LAYOUTER_H
|
||||
@@ -32,9 +32,6 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
Id ownerId;
|
||||
Id targetId;
|
||||
|
||||
bool operator==(const DummyEdge& other) const
|
||||
{
|
||||
if(ownerId == other.ownerId && targetId == other.targetId)
|
||||
@@ -48,6 +45,27 @@ public:
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
bool operator<(const DummyEdge& other) const
|
||||
{
|
||||
if(ownerId < other.ownerId )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if(ownerId == other.ownerId)
|
||||
{
|
||||
return (targetId < other.targetId);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator>(const DummyEdge& other) const
|
||||
{
|
||||
return !(*this < other);
|
||||
}
|
||||
|
||||
Id ownerId;
|
||||
Id targetId;
|
||||
};
|
||||
|
||||
#endif // GRAPH_EDGE_H
|
||||
@@ -9,7 +9,7 @@ GraphNode::~GraphNode()
|
||||
{
|
||||
}
|
||||
|
||||
Id GraphNode::getTokenId()
|
||||
Id GraphNode::getTokenId() const
|
||||
{
|
||||
return m_tokenId;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef GRAPH_NODE_H
|
||||
#define GRAPH_NODE_H
|
||||
|
||||
#include <list>
|
||||
#include <memory>
|
||||
|
||||
#include "utility/math/Vector2.h"
|
||||
@@ -14,17 +15,21 @@ public:
|
||||
GraphNode(const Id tokenId);
|
||||
virtual ~GraphNode();
|
||||
|
||||
virtual std::string getName() = 0;
|
||||
Id getTokenId();
|
||||
virtual Vec2i getPosition() = 0;
|
||||
virtual std::string getName() const = 0;
|
||||
Id getTokenId() const;
|
||||
virtual Vec2i getPosition() const = 0;
|
||||
virtual void setPosition(const Vec2i& position) = 0;
|
||||
|
||||
virtual bool addOutEdge(const std::shared_ptr<GraphEdge>& edge) = 0;
|
||||
virtual bool addInEdge(const std::weak_ptr<GraphEdge>& edge) = 0;
|
||||
|
||||
virtual void removeOutEdge(GraphEdge* edge) = 0;
|
||||
|
||||
virtual std::list<std::shared_ptr<GraphNode> > getSubNodes() const = 0;
|
||||
virtual void addSubNode(const std::shared_ptr<GraphNode>& node) = 0;
|
||||
|
||||
virtual void notifyParentMoved() = 0;
|
||||
|
||||
protected:
|
||||
Id m_tokenId;
|
||||
};
|
||||
@@ -36,13 +41,56 @@ public:
|
||||
: name(n)
|
||||
, tokenId(tId)
|
||||
, position(p)
|
||||
, subNodes()
|
||||
, actualNode()
|
||||
{
|
||||
}
|
||||
|
||||
bool operator==(const DummyNode& other) const
|
||||
{
|
||||
if(tokenId == other.tokenId
|
||||
&& name == other.name
|
||||
&& position == position)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator!=(const DummyNode& other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
bool operator<(const DummyNode& other) const
|
||||
{
|
||||
if(tokenId < other.tokenId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator>(const DummyNode& other) const
|
||||
{
|
||||
return !(*this < other);
|
||||
}
|
||||
|
||||
void operator=(DummyNode& other)
|
||||
{
|
||||
name = other.name;
|
||||
tokenId = other.tokenId;
|
||||
position = other.position;
|
||||
subNodes = other.subNodes;
|
||||
actualNode = other.actualNode;
|
||||
}
|
||||
|
||||
std::string name;
|
||||
Id tokenId;
|
||||
Vec2i position;
|
||||
|
||||
std::vector<DummyNode> subNodes;
|
||||
|
||||
std::weak_ptr<GraphNode> actualNode;
|
||||
};
|
||||
|
||||
|
||||
@@ -289,7 +289,7 @@ std::vector<Id> Storage::getIdsOfNeighbours(const Id id) const
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::pair<Id, Id>> Storage::getConnectedEdges(const Id id) const
|
||||
std::vector<std::pair<Id, Id>> Storage::getNeighbourEdgesOfNode(const Id id) const
|
||||
{
|
||||
std::vector<std::pair<Id, Id>> result;
|
||||
|
||||
@@ -300,7 +300,7 @@ std::vector<std::pair<Id, Id>> Storage::getConnectedEdges(const Id id) const
|
||||
if (node != NULL)
|
||||
{
|
||||
node->forEachEdge(
|
||||
[&result, &id](Edge* e)
|
||||
[&result](Edge* e)
|
||||
{
|
||||
result.push_back(std::pair<Id, Id>(e->getFrom()->getId(), e->getTo()->getId()));
|
||||
}
|
||||
@@ -310,6 +310,36 @@ std::vector<std::pair<Id, Id>> Storage::getConnectedEdges(const Id id) const
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::pair<Id, Id>> Storage::getMemberEdgesOfNode(const Id id) const
|
||||
{
|
||||
return getEdgesOfTypeOfNode(id, Edge::EdgeType::EDGE_MEMBER);
|
||||
}
|
||||
|
||||
std::vector<std::pair<Id, Id>> Storage::getUsageEdgesOfNode(const Id id) const
|
||||
{
|
||||
return getEdgesOfTypeOfNode(id, Edge::EdgeType::EDGE_USAGE);
|
||||
}
|
||||
|
||||
std::vector<std::pair<Id, Id>> Storage::getCallEdgesOfNode(const Id id) const
|
||||
{
|
||||
return getEdgesOfTypeOfNode(id, Edge::EdgeType::EDGE_CALL);
|
||||
}
|
||||
|
||||
std::vector<std::pair<Id, Id>> Storage::getTypeOfEdgesOfNode(const Id id) const
|
||||
{
|
||||
return getEdgesOfTypeOfNode(id, Edge::EdgeType::EDGE_TYPE_OF);
|
||||
}
|
||||
|
||||
std::vector<std::pair<Id, Id>> Storage::getReturnTypeOfEdgesOfNode(const Id id) const
|
||||
{
|
||||
return getEdgesOfTypeOfNode(id, Edge::EdgeType::EDGE_RETURN_TYPE_OF);
|
||||
}
|
||||
|
||||
std::vector<std::pair<Id, Id>> Storage::getParameterOfEdgesOfNode(const Id id) const
|
||||
{
|
||||
return getEdgesOfTypeOfNode(id, Edge::EdgeType::EDGE_PARAMETER_TYPE_OF);
|
||||
}
|
||||
|
||||
TokenLocationCollection Storage::getTokenLocationsForTokenId(Id id) const
|
||||
{
|
||||
TokenLocationCollection ret;
|
||||
@@ -430,3 +460,27 @@ void Storage::log(std::string type, std::string str, const ParseLocation& locati
|
||||
info << location.endLineNumber << ":" << location.endColumnNumber << ">";
|
||||
LOG_INFO(info.str());
|
||||
}
|
||||
|
||||
std::vector<std::pair<Id, Id>> Storage::getEdgesOfTypeOfNode(const Id id, const Edge::EdgeType type) 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, &type](Edge* e)
|
||||
{
|
||||
if(e->getType() == type)
|
||||
{
|
||||
result.push_back(std::pair<Id, Id>(e->getFrom()->getId(), e->getTo()->getId()));
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,13 @@ public:
|
||||
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;
|
||||
virtual std::vector<std::pair<Id, Id>> getNeighbourEdgesOfNode(const Id id) const;
|
||||
virtual std::vector<std::pair<Id, Id>> getMemberEdgesOfNode(const Id id) const;
|
||||
virtual std::vector<std::pair<Id, Id>> getUsageEdgesOfNode(const Id id) const;
|
||||
virtual std::vector<std::pair<Id, Id>> getCallEdgesOfNode(const Id id) const;
|
||||
virtual std::vector<std::pair<Id, Id>> getTypeOfEdgesOfNode(const Id id) const;
|
||||
virtual std::vector<std::pair<Id, Id>> getReturnTypeOfEdgesOfNode(const Id id) const;
|
||||
virtual std::vector<std::pair<Id, Id>> getParameterOfEdgesOfNode(const Id id) const;
|
||||
|
||||
// LocationAccess implementation
|
||||
virtual TokenLocationCollection getTokenLocationsForTokenId(Id locationId) const;
|
||||
@@ -78,6 +84,8 @@ private:
|
||||
|
||||
void log(std::string type, std::string str, const ParseLocation& location) const;
|
||||
|
||||
std::vector<std::pair<Id, Id>> getEdgesOfTypeOfNode(const Id id, const Edge::EdgeType type) const;
|
||||
|
||||
Graph m_graph;
|
||||
TokenLocationCollection m_locationCollection;
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "utility/types.h"
|
||||
|
||||
class Edge;
|
||||
class Token;
|
||||
|
||||
class GraphAccess
|
||||
@@ -17,7 +18,13 @@ public:
|
||||
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;
|
||||
virtual std::vector<std::pair<Id, Id>> getNeighbourEdgesOfNode(const Id id) const = 0;
|
||||
virtual std::vector<std::pair<Id, Id>> getMemberEdgesOfNode(const Id id) const = 0;
|
||||
virtual std::vector<std::pair<Id, Id>> getUsageEdgesOfNode(const Id id) const = 0;
|
||||
virtual std::vector<std::pair<Id, Id>> getCallEdgesOfNode(const Id id) const = 0;
|
||||
virtual std::vector<std::pair<Id, Id>> getTypeOfEdgesOfNode(const Id id) const = 0;
|
||||
virtual std::vector<std::pair<Id, Id>> getReturnTypeOfEdgesOfNode(const Id id) const = 0;
|
||||
virtual std::vector<std::pair<Id, Id>> getParameterOfEdgesOfNode(const Id id) const = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -67,11 +67,71 @@ std::vector<Id> GraphAccessProxy::getIdsOfNeighbours(const Id id) const
|
||||
return std::vector<Id>();
|
||||
}
|
||||
|
||||
std::vector<std::pair<Id, Id>> GraphAccessProxy::getConnectedEdges(const Id id) const
|
||||
std::vector<std::pair<Id, Id>> GraphAccessProxy::getNeighbourEdgesOfNode(const Id id) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getConnectedEdges(id);
|
||||
return m_subject->getNeighbourEdgesOfNode(id);
|
||||
}
|
||||
|
||||
return std::vector<std::pair<Id, Id>>();
|
||||
}
|
||||
|
||||
std::vector<std::pair<Id, Id>> GraphAccessProxy::getMemberEdgesOfNode(const Id id) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getMemberEdgesOfNode(id);
|
||||
}
|
||||
|
||||
return std::vector<std::pair<Id, Id>>();
|
||||
}
|
||||
|
||||
std::vector<std::pair<Id, Id>> GraphAccessProxy::getUsageEdgesOfNode(const Id id) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getUsageEdgesOfNode(id);
|
||||
}
|
||||
|
||||
return std::vector<std::pair<Id, Id>>();
|
||||
}
|
||||
|
||||
std::vector<std::pair<Id, Id>> GraphAccessProxy::getCallEdgesOfNode(const Id id) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getCallEdgesOfNode(id);
|
||||
}
|
||||
|
||||
return std::vector<std::pair<Id, Id>>();
|
||||
}
|
||||
|
||||
std::vector<std::pair<Id, Id>> GraphAccessProxy::getTypeOfEdgesOfNode(const Id id) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getTypeOfEdgesOfNode(id);
|
||||
}
|
||||
|
||||
return std::vector<std::pair<Id, Id>>();
|
||||
}
|
||||
|
||||
std::vector<std::pair<Id, Id>> GraphAccessProxy::getReturnTypeOfEdgesOfNode(const Id id) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getReturnTypeOfEdgesOfNode(id);
|
||||
}
|
||||
|
||||
return std::vector<std::pair<Id, Id>>();
|
||||
}
|
||||
|
||||
std::vector<std::pair<Id, Id>> GraphAccessProxy::getParameterOfEdgesOfNode(const Id id) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getParameterOfEdgesOfNode(id);
|
||||
}
|
||||
|
||||
return std::vector<std::pair<Id, Id>>();
|
||||
|
||||
@@ -17,7 +17,13 @@ public:
|
||||
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;
|
||||
virtual std::vector<std::pair<Id, Id>> getNeighbourEdgesOfNode(const Id id) const;
|
||||
virtual std::vector<std::pair<Id, Id>> getMemberEdgesOfNode(const Id id) const;
|
||||
virtual std::vector<std::pair<Id, Id>> getUsageEdgesOfNode(const Id id) const;
|
||||
virtual std::vector<std::pair<Id, Id>> getCallEdgesOfNode(const Id id) const;
|
||||
virtual std::vector<std::pair<Id, Id>> getTypeOfEdgesOfNode(const Id id) const;
|
||||
virtual std::vector<std::pair<Id, Id>> getReturnTypeOfEdgesOfNode(const Id id) const;
|
||||
virtual std::vector<std::pair<Id, Id>> getParameterOfEdgesOfNode(const Id id) const;
|
||||
|
||||
private:
|
||||
GraphAccess* m_subject;
|
||||
|
||||
Reference in New Issue
Block a user