Graph : Added color for unconditionnal jmp (blue). As for conditionnal jump, green is used when jump is taken and red when it is not.
This commit is contained in:
parent
b828ed9fa9
commit
d0750e5beb
|
|
@ -1,9 +1,14 @@
|
|||
#include "GraphEdge.h"
|
||||
|
||||
|
||||
GraphEdge::GraphEdge(QPointF start, QPointF end, ogdf::DPolyline bends, QRectF sourceRect, QRectF targetRect, QBrush lineColor) : QAbstractGraphicsShapeItem()
|
||||
GraphEdge::GraphEdge(QPointF start, QPointF end, ogdf::DPolyline bends, QRectF sourceRect, QRectF targetRect, EDGE_TYPE edgeType) : QAbstractGraphicsShapeItem()
|
||||
{
|
||||
_edgeColor = lineColor;
|
||||
_edgeType = edgeType;
|
||||
|
||||
if(_edgeType == EDGE_LEFT)
|
||||
_edgeColor = Qt::red;
|
||||
else
|
||||
_edgeColor = Qt::green;
|
||||
|
||||
QList<QPointF> linePoints = calculateLine(start, end, bends, sourceRect, targetRect);
|
||||
// for(auto p : linePoints)
|
||||
|
|
@ -239,3 +244,13 @@ void GraphEdge::preparePainterPaths(const QList<QPointF> & linePoints, const QLi
|
|||
_arrow.addPolygon(polyArrow);
|
||||
}
|
||||
|
||||
void GraphEdge::setEdgeColor(QBrush edgeColor)
|
||||
{
|
||||
_edgeColor = edgeColor;
|
||||
}
|
||||
|
||||
GraphEdge::EDGE_TYPE GraphEdge::getEdgeType()
|
||||
{
|
||||
return _edgeType;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,13 @@
|
|||
class GraphEdge : public QAbstractGraphicsShapeItem
|
||||
{
|
||||
public:
|
||||
GraphEdge(QPointF start, QPointF end, ogdf::DPolyline bends, QRectF sourceRect, QRectF targetRect, QBrush lineColor = Qt::green);
|
||||
enum EDGE_TYPE
|
||||
{
|
||||
EDGE_RIGHT,
|
||||
EDGE_LEFT
|
||||
} ;
|
||||
|
||||
GraphEdge(QPointF start, QPointF end, ogdf::DPolyline bends, QRectF sourceRect, QRectF targetRect, EDGE_TYPE edgeType);
|
||||
QRectF boundingRect() const;
|
||||
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget);
|
||||
qreal calculateDistance(QPointF p1, QPointF p2);
|
||||
|
|
@ -18,12 +24,15 @@ public:
|
|||
QList<QPointF> calculateArrow(const QList<QPointF> & linePoints);
|
||||
QRectF calculateBoundingRect(const QList<QPointF> & linePoints, const QList<QPointF> & arrowPoints);
|
||||
void preparePainterPaths(const QList<QPointF> & linePoints, const QList<QPointF> & arrowPoints);
|
||||
void setEdgeColor(QBrush edgeColor);
|
||||
GraphEdge::EDGE_TYPE getEdgeType();
|
||||
|
||||
private:
|
||||
QPainterPath _line;
|
||||
QPainterPath _arrow;
|
||||
QRectF _boundingRect;
|
||||
QBrush _edgeColor;
|
||||
EDGE_TYPE _edgeType;
|
||||
};
|
||||
|
||||
#endif //_GRAPH_EDGE_H
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
|
||||
#include "GraphView.h"
|
||||
#include "ui_GraphView.h"
|
||||
#include "GraphEdge.h"
|
||||
#include "Configuration.h"
|
||||
#include <QDebug>
|
||||
|
||||
|
|
@ -21,6 +20,7 @@ GraphView::GraphView(QWidget *parent) :
|
|||
mParentsInfo = nullptr;
|
||||
mBasicBlockInfo = nullptr;
|
||||
mGraphNodeVector = new GRAPHNODEVECTOR;
|
||||
// mNodeGraphEdge = new GRAPHEDGEMAP;
|
||||
bProgramInitialized = false;
|
||||
|
||||
mScene->setBackgroundBrush(ConfigColor("DisassemblyBackgroundColor"));
|
||||
|
|
@ -41,7 +41,16 @@ void GraphView::startControlFlowAnalysis()
|
|||
|
||||
void GraphView::showEvent(QShowEvent *event)
|
||||
{
|
||||
// ui->graphicsView->fitInView(mScene->itemsBoundingRect(), Qt::KeepAspectRatio);
|
||||
// ui->graphicsView->fitInView(mScene->itemsBoundingRect(), Qt::KeepAspectRatio);
|
||||
}
|
||||
|
||||
void GraphView::setUnconditionalBranchEdgeColor()
|
||||
{
|
||||
for(auto const &nodeGraphEdge : mNodeGraphEdge)
|
||||
{
|
||||
if(nodeGraphEdge.second.size() == 1)
|
||||
nodeGraphEdge.second.at(0)->setEdgeColor(Qt::blue);
|
||||
}
|
||||
}
|
||||
|
||||
void GraphView::setupGraph()
|
||||
|
|
@ -155,6 +164,7 @@ void GraphView::addGraphToScene()
|
|||
{
|
||||
using namespace ogdf;
|
||||
|
||||
mNodeGraphEdge.clear();
|
||||
mScene->clear();
|
||||
|
||||
// adjust node size
|
||||
|
|
@ -208,21 +218,18 @@ void GraphView::addGraphToScene()
|
|||
|
||||
GraphEdge* edge = nullptr;
|
||||
if(mTree->findNode(source)->left() && mTree->findNode(source)->left()->data()->address() == targetGraphNode->address())
|
||||
edge = new GraphEdge(start, end, bends, sourceRect, targetRect, Qt::green);
|
||||
edge = new GraphEdge(start, end, bends, sourceRect, targetRect, GraphEdge::EDGE_LEFT);
|
||||
else
|
||||
edge = new GraphEdge(start, end, bends, sourceRect, targetRect, Qt::red);
|
||||
edge = new GraphEdge(start, end, bends, sourceRect, targetRect, GraphEdge::EDGE_RIGHT);
|
||||
|
||||
mNodeGraphEdge[source].push_back(edge);
|
||||
mScene->addItem(edge);
|
||||
}
|
||||
|
||||
// mScene->setSceneRect(mScene->itemsBoundingRect());
|
||||
setUnconditionalBranchEdgeColor();
|
||||
|
||||
// mScene->setSceneRect(0, 0, mGA->boundingBox().width(), mGA->boundingBox().height());
|
||||
QTextStream out(stdout);
|
||||
ui->graphicsView->ensureVisible(mScene->itemsBoundingRect());
|
||||
ui->graphicsView->setSceneRect(mScene->sceneRect());
|
||||
|
||||
// ui->graphicsView->fitInView(mScene->sceneRect(), Qt::KeepAspectRatio);
|
||||
}
|
||||
|
||||
void GraphView::addAllNodes(BASICBLOCKMAP::iterator it, Node<GraphNode *> *parentNode)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
#include <ogdf/layered/OptimalRanking.h>
|
||||
#include <ogdf/layered/MedianHeuristic.h>
|
||||
#include <ogdf/layered/OptimalHierarchyLayout.h>
|
||||
#include "GraphEdge.h"
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
|
|
@ -61,6 +62,7 @@ typedef std::map<duint, BasicBlock> BASICBLOCKMAP; //start of block -> block
|
|||
typedef std::map<duint, std::set<duint> > PARENTMAP; //start child -> parents
|
||||
typedef std::vector<GraphNode* > GRAPHNODEVECTOR;
|
||||
typedef std::map<duint, Node<GraphNode *> * > NODEMAP;
|
||||
typedef std::map<ogdf::node, std::vector<GraphEdge *> > GRAPHEDGEMAP;
|
||||
|
||||
class GraphView : public QWidget
|
||||
{
|
||||
|
|
@ -70,6 +72,7 @@ public:
|
|||
explicit GraphView(QWidget *parent = 0);
|
||||
void startControlFlowAnalysis();
|
||||
void showEvent(QShowEvent *event);
|
||||
void setUnconditionalBranchEdgeColor();
|
||||
~GraphView();
|
||||
|
||||
public slots:
|
||||
|
|
@ -89,6 +92,7 @@ private:
|
|||
PARENTMAP *mParentsInfo;
|
||||
BASICBLOCKMAP *mBasicBlockInfo;
|
||||
GRAPHNODEVECTOR *mGraphNodeVector;
|
||||
GRAPHEDGEMAP mNodeGraphEdge;
|
||||
ogdf::Graph *mG;
|
||||
ogdf::GraphAttributes *mGA;
|
||||
ogdf::SugiyamaLayout *mSL;
|
||||
|
|
|
|||
Loading…
Reference in New Issue