get rid of OGDF library
diff --git a/demo/chatdialog.cpp b/demo/chatdialog.cpp
index 10c7af0..0704ddd 100644
--- a/demo/chatdialog.cpp
+++ b/demo/chatdialog.cpp
@@ -7,6 +7,28 @@
#define BROADCAST_PREFIX_FOR_SYNC_DEMO "/ndn/broadcast/sync-demo"
+void
+ChatDialog::testDraw()
+{
+ std::string prefix[5] = {"/ndn/1", "/ndn/2", "/ndn/3", "/ndn/4", "/ndn/5"};
+ std::string nick[5] = {"tom", "jerry", "jason", "michael", "hurry"};
+ std::vector<Sync::MissingDataInfo> v;
+ for (int i = 0; i < 5; i++)
+ {
+ Sync::MissingDataInfo mdi = {prefix[i], Sync::SeqNo(0), Sync::SeqNo(i * (2 << i) )};
+ v.push_back(mdi);
+ }
+
+ m_scene->processUpdate(v, "12341234@!#%!@");
+
+ for (int i = 0; i < 5; i++)
+ {
+ m_scene-> msgReceived(prefix[i].c_str(), nick[i].c_str());
+ }
+
+ fitView();
+}
+
ChatDialog::ChatDialog(QWidget *parent)
: QDialog(parent), m_sock(NULL)
{
@@ -35,6 +57,7 @@
connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
connect(setButton, SIGNAL(pressed()), this, SLOT(buttonPressed()));
+ testDraw();
}
ChatDialog::~ChatDialog()
@@ -273,5 +296,7 @@
void
ChatDialog::fitView()
{
+ QRectF rect = m_scene->itemsBoundingRect();
+ m_scene->setSceneRect(rect);
treeViewer->fitInView(m_scene->itemsBoundingRect(), Qt::KeepAspectRatio);
}
diff --git a/demo/chatdialog.h b/demo/chatdialog.h
index 252144b..ea95873 100644
--- a/demo/chatdialog.h
+++ b/demo/chatdialog.h
@@ -32,6 +32,7 @@
void resizeEvent(QResizeEvent *);
void showEvent(QShowEvent *);
void fitView();
+ void testDraw();
private slots:
void returnPressed();
diff --git a/demo/digesttreescene.cpp b/demo/digesttreescene.cpp
index 0dd7a10..d987633 100644
--- a/demo/digesttreescene.cpp
+++ b/demo/digesttreescene.cpp
@@ -1,34 +1,13 @@
-#include "digesttreescene.h"
#include <QtGui>
-#include "ogdf/basic/Array.h"
-#include "ogdf/basic/Graph_d.h"
-#include "ogdf/tree/TreeLayout.h"
#include <vector>
#include <iostream>
#include <assert.h>
#include <boost/lexical_cast.hpp>
+#include <memory>
+#include "digesttreescene.h"
static const double Pi = 3.14159265358979323846264338327950288419717;
-static void
-testDraw(DigestTreeScene * scene)
-{
- std::string prefix[5] = {"/ndn/1", "/ndn/2", "/ndn/3", "/ndn/4", "/ndn/5"};
- std::string nick[5] = {"tom", "jerry", "jason", "michael", "hurry"};
- std::vector<Sync::MissingDataInfo> v;
- for (int i = 0; i < 5; i++)
- {
- Sync::MissingDataInfo mdi = {prefix[i], Sync::SeqNo(0), Sync::SeqNo(i * (2 << i) )};
- v.push_back(mdi);
- }
-
- scene->processUpdate(v, "12341234@!#%!@");
-
- for (int i = 0; i < 5; i++)
- {
- scene-> msgReceived(prefix[i].c_str(), nick[i].c_str());
- }
-}
DigestTreeScene::DisplayUserPtr DigestTreeScene::DisplayUserNullPtr;
@@ -36,7 +15,6 @@
: QGraphicsScene(parent)
{
previouslyUpdatedUser = DisplayUserNullPtr;
-// testDraw(this);
}
void
@@ -112,7 +90,6 @@
DigestTreeScene::clearAll()
{
clear();
- m_graph.clear();
m_roster.clear();
}
@@ -120,46 +97,33 @@
DigestTreeScene::plot(QString digest)
{
clear();
- m_graph.clear();
- int n = m_roster.size();
- ogdf::node root = m_graph.newNode();
- int rootIndex = root->index();
- for (int i = 0; i < n; i++) {
- ogdf::node leaf = m_graph.newNode();
- m_graph.newEdge(root, leaf);
- }
- ogdf::GraphAttributes GA(m_graph);
int nodeSize = 40;
+
int siblingDistance = 100, levelDistance = 100;
- ogdf::TreeLayout layout;
- layout.siblingDistance(siblingDistance);
- layout.levelDistance(levelDistance);
- layout.callSortByPositions(GA, m_graph);
+ std::auto_ptr<TreeLayout> layout(new OneLevelTreeLayout());
+ layout->setSiblingDistance(siblingDistance);
+ layout->setLevelDistance(levelDistance);
- int width = GA.boundingBox().width();
- int height = GA.boundingBox().height();
- //setSceneRect(QRect(- (width + nodeSize) / 2, - 50, width + nodeSize, height + nodeSize));
- GA.setAllWidth(nodeSize);
- GA.setAllHeight(nodeSize);
+ int n = m_roster.size();
+ std::vector<TreeLayout::Coordinate> childNodesCo(n);
- plotEdge(GA);
- plotNode(GA, rootIndex, digest);
+ layout->setOneLevelLayout(childNodesCo);
+
+ plotEdge(childNodesCo, nodeSize);
+ plotNode(childNodesCo, digest, nodeSize);
previouslyUpdatedUser = DisplayUserNullPtr;
}
void
-DigestTreeScene::plotEdge(ogdf::GraphAttributes &GA)
+DigestTreeScene::plotEdge(const std::vector<TreeLayout::Coordinate> &childNodesCo, int nodeSize)
{
- ogdf::edge e;
- forall_edges(e, m_graph) {
- ogdf::node source = e->source();
- ogdf::node target = e->target();
- int nodeSize = GA.width(target);
- int x1 = GA.x(source), y1 = -GA.y(source);
- int x2 = GA.x(target), y2 = -GA.y(target);
+ int n = childNodesCo.size();
+ for (int i = 0; i < n; i++) {
+ double x1 = 0.0, y1 = 0.0;
+ double x2 = childNodesCo[i].x, y2 = childNodesCo[i].y;
QPointF src(x1 + nodeSize/2, y1 + nodeSize/2);
QPointF dest(x2 + nodeSize/2, y2 + nodeSize/2);
QLineF line(src, dest);
@@ -178,69 +142,67 @@
}
void
-DigestTreeScene::plotNode(ogdf::GraphAttributes &GA, int rootIndex, QString digest)
+DigestTreeScene::plotNode(const std::vector<TreeLayout::Coordinate> &childNodesCo, QString digest, int nodeSize)
{
- ogdf::node n;
RosterIterator it(m_roster);
- forall_nodes(n, m_graph) {
- double x = GA.x(n);
- double y = -GA.y(n);
- double w = GA.width(n);
- double h = GA.height(n);
- int rim = 3;
- QRectF boundingRect(x, y, w, h);
- QRectF innerBoundingRect(x + rim, y + rim, w - rim * 2, h - rim * 2);
+ int n = childNodesCo.size();
+ int rim = 3;
- if (n->index() == rootIndex)
+ // plot root node
+ QRectF rootBoundingRect(0, 0, nodeSize, nodeSize);
+ QRectF rootInnerBoundingRect(rim, rim, nodeSize - rim * 2, nodeSize - rim * 2);
+ addRect(rootBoundingRect, QPen(Qt::black), QBrush(Qt::darkRed));
+ addRect(rootInnerBoundingRect, QPen(Qt::black), QBrush(Qt::lightGray));
+ QRectF digestRect(- nodeSize, - nodeSize, 3 * nodeSize, 30);
+ addRect(digestRect, QPen(Qt::darkCyan), QBrush(Qt::darkCyan));
+ QGraphicsTextItem *digestItem = addText(digest);
+ QRectF digestBoundingRect = digestItem->boundingRect();
+ digestItem->setDefaultTextColor(Qt::white);
+ digestItem->setFont(QFont("Cursive", 12, QFont::Bold));
+ digestItem->setPos(- nodeSize + (3 * nodeSize - digestBoundingRect.width()) / 2, - nodeSize + 5);
+ m_rootDigest = digestItem;
+
+ // plot child nodes
+ for (int i = 0; i < n; i++)
+ {
+ if (it.hasNext())
{
- addRect(boundingRect, QPen(Qt::black), QBrush(Qt::darkRed));
- addRect(innerBoundingRect, QPen(Qt::black), QBrush(Qt::lightGray));
-
- QRectF digestRect(x - w, y - h, 3 * w, 30);
- addRect(digestRect, QPen(Qt::darkCyan), QBrush(Qt::darkCyan));
- QGraphicsTextItem *digestItem = addText(digest);
- QRectF digestBoundingRect = digestItem->boundingRect();
- digestItem->setDefaultTextColor(Qt::white);
- digestItem->setFont(QFont("Cursive", 12, QFont::Bold));
- digestItem->setPos(x - w + (3 * w - digestBoundingRect.width()) / 2, y - h + 5);
- m_rootDigest = digestItem;
+ it.next();
}
- else
+ else
{
- if (it.hasNext())
- {
- it.next();
- }
- else
- {
- abort();
- }
- DisplayUserPtr p = it.value();
- QGraphicsRectItem *rectItem = addRect(boundingRect, QPen(Qt::black), QBrush(Qt::darkBlue));
- p->setRimRectItem(rectItem);
-
- QGraphicsRectItem *innerRectItem = addRect(innerBoundingRect, QPen(Qt::black), QBrush(Qt::lightGray));
- p->setInnerRectItem(innerRectItem);
-
- std::string s = boost::lexical_cast<std::string>(p->getSeqNo().getSeq());
- QGraphicsTextItem *seqItem = addText(s.c_str());
- seqItem->setFont(QFont("Cursive", 12, QFont::Bold));
- QRectF seqBoundingRect = seqItem->boundingRect();
- seqItem->setPos(x + w / 2 - seqBoundingRect.width() / 2, y + h / 2 - seqBoundingRect.height() / 2);
- p->setSeqTextItem(seqItem);
-
- QRectF textRect(x - w / 2, y + h, 2 * w, 30);
- QGraphicsRectItem *nickRectItem = addRect(textRect, QPen(Qt::darkCyan), QBrush(Qt::darkCyan));
- p->setNickRectItem(nickRectItem);
- QGraphicsTextItem *nickItem = addText(p->getNick());
- QRectF textBoundingRect = nickItem->boundingRect();
- nickItem->setDefaultTextColor(Qt::white);
- nickItem->setFont(QFont("Cursive", 12, QFont::Bold));
- nickItem->setPos(x + w / 2 - textBoundingRect.width() / 2, y + h + 5);
- p->setNickTextItem(nickItem);
+ abort();
}
+ double x = childNodesCo[i].x;
+ double y = childNodesCo[i].y;
+ QRectF boundingRect(x, y, nodeSize, nodeSize);
+ QRectF innerBoundingRect(x + rim, y + rim, nodeSize - rim * 2, nodeSize - rim * 2);
+ DisplayUserPtr p = it.value();
+ QGraphicsRectItem *rectItem = addRect(boundingRect, QPen(Qt::black), QBrush(Qt::darkBlue));
+ p->setRimRectItem(rectItem);
+
+ QGraphicsRectItem *innerRectItem = addRect(innerBoundingRect, QPen(Qt::black), QBrush(Qt::lightGray));
+ p->setInnerRectItem(innerRectItem);
+
+ std::string s = boost::lexical_cast<std::string>(p->getSeqNo().getSeq());
+ QGraphicsTextItem *seqItem = addText(s.c_str());
+ seqItem->setFont(QFont("Cursive", 12, QFont::Bold));
+ QRectF seqBoundingRect = seqItem->boundingRect();
+ seqItem->setPos(x + nodeSize / 2 - seqBoundingRect.width() / 2, y + nodeSize / 2 - seqBoundingRect.height() / 2);
+ p->setSeqTextItem(seqItem);
+
+ QRectF textRect(x - nodeSize / 2, y + nodeSize, 2 * nodeSize, 30);
+ QGraphicsRectItem *nickRectItem = addRect(textRect, QPen(Qt::darkCyan), QBrush(Qt::darkCyan));
+ p->setNickRectItem(nickRectItem);
+ QGraphicsTextItem *nickItem = addText(p->getNick());
+ QRectF textBoundingRect = nickItem->boundingRect();
+ nickItem->setDefaultTextColor(Qt::white);
+ nickItem->setFont(QFont("Cursive", 12, QFont::Bold));
+ nickItem->setPos(x + nodeSize / 2 - textBoundingRect.width() / 2, y + nodeSize + 5);
+ p->setNickTextItem(nickItem);
}
+
}
void
diff --git a/demo/digesttreescene.h b/demo/digesttreescene.h
index 91876e6..f041b11 100644
--- a/demo/digesttreescene.h
+++ b/demo/digesttreescene.h
@@ -2,8 +2,6 @@
#define DIGESTTREESCENE_H
#include <QtGui/QGraphicsScene>
-#include "ogdf/basic/GraphAttributes.h"
-#include "ogdf/basic/Graph.h"
#include <sync-seq-no.h>
#include <sync-logic.h>
#include <ctime>
@@ -11,6 +9,7 @@
#include <vector>
#include <tr1/memory>
#include <QColor>
+#include "treelayout.h"
class QGraphicsTextItem;
@@ -34,11 +33,10 @@
void clearAll();
void plot(QString digest);
private:
- void plotEdge(ogdf::GraphAttributes &GA);
- void plotNode(ogdf::GraphAttributes &GA, int rootIndex, QString digest);
+ void plotEdge(const std::vector<TreeLayout::Coordinate> &v, int nodeSize);
+ void plotNode(const std::vector<TreeLayout::Coordinate> &v, QString digest, int nodeSize);
void reDrawNode(DisplayUserPtr p, QColor rimColor);
private:
- ogdf::Graph m_graph;
Roster m_roster;
QGraphicsTextItem *m_rootDigest;
DisplayUserPtr previouslyUpdatedUser;
diff --git a/demo/sync-demo.pro b/demo/sync-demo.pro
index 96f6c7e..2eae1a3 100644
--- a/demo/sync-demo.pro
+++ b/demo/sync-demo.pro
@@ -2,12 +2,14 @@
TARGET = sync-demo
HEADERS = chatdialog.h \
digesttreescene.h \
- settingdialog.h
+ settingdialog.h \
+ treelayout.h
SOURCES = main.cpp \
chatdialog.cpp \
digesttreescene.cpp \
- settingdialog.cpp
+ settingdialog.cpp \
+ treelayout.cpp
FORMS = chatdialog.ui \
settingdialog.ui
@@ -15,9 +17,9 @@
QMAKE_CXXFLAGS *= -g
QMAKE_CFLAGS *= -g
-QMAKE_LIBDIR *= /opt/local/lib /usr/local/lib /usr/lib ../../../third_party/OGDF/_release ../build
-INCLUDEPATH *= /opt/local/include /usr/local/include ../../../third_party/OGDF ../include
-LIBS *= -lccn -lssl -lcrypto -lpthread -lOGDF -lprotobuf -lsync
+QMAKE_LIBDIR *= /opt/local/lib /usr/local/lib /usr/lib ../build
+INCLUDEPATH *= /opt/local/include /usr/local/include ../include
+LIBS *= -lccn -lssl -lcrypto -lpthread -lprotobuf -lsync
CONFIG += console
PROTOS = chatbuf.proto
diff --git a/demo/treelayout.h b/demo/treelayout.h
index e72ef0e..498210c 100644
--- a/demo/treelayout.h
+++ b/demo/treelayout.h
@@ -26,7 +26,7 @@
{
public:
OneLevelTreeLayout(){}
- virtual void setOneLevelLayout(std::vector<Coordinate> &v, int childNumber);
+ virtual void setOneLevelLayout(std::vector<Coordinate> &childNodesCo);
virtual ~OneLevelTreeLayout(){}
};
#endif