From bd6c301c136ca7dd8f0bc89a90ad85e0f01be01b Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Sun, 22 Jan 2017 17:05:37 +0100 Subject: tikz output --- tikzit/src/data/graph.cpp | 110 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) (limited to 'tikzit/src/data/graph.cpp') diff --git a/tikzit/src/data/graph.cpp b/tikzit/src/data/graph.cpp index 9307d62..2480507 100644 --- a/tikzit/src/data/graph.cpp +++ b/tikzit/src/data/graph.cpp @@ -1,8 +1,11 @@ #include "graph.h" +#include + Graph::Graph(QObject *parent) : QObject(parent) { _data = new GraphElementData(); + _bbox = QRectF(0,0,0,0); } Graph::~Graph() @@ -53,6 +56,113 @@ const QVector &Graph::edges() return _edges; } +QRectF Graph::bbox() const +{ + return _bbox; +} + +bool Graph::hasBbox() { + return !(_bbox == QRectF(0,0,0,0)); +} + +void Graph::clearBbox() { + _bbox = QRectF(0,0,0,0); +} + +QString Graph::tikz() +{ + QString str; + QTextStream code(&str); +// [NSMutableString +// stringWithFormat:@"\\begin{tikzpicture}%@\n", +// [[self data] tikzList]]; + +// if ([self hasBoundingBox]) { +// [code appendFormat:@"\t\\path [use as bounding box] (%@,%@) rectangle (%@,%@);\n", +// [NSNumber numberWithFloat:boundingBox.origin.x], +// [NSNumber numberWithFloat:boundingBox.origin.y], +// [NSNumber numberWithFloat:boundingBox.origin.x + boundingBox.size.width], +// [NSNumber numberWithFloat:boundingBox.origin.y + boundingBox.size.height]]; +// } + +// // NSArray *sortedNodeList = [[nodes allObjects] +// // sortedArrayUsingSelector:@selector(compareTo:)]; +// //NSMutableDictionary *nodeNames = [NSMutableDictionary dictionary]; + +// if ([nodes count] > 0) [code appendFormat:@"\t\\begin{pgfonlayer}{nodelayer}\n"]; + +// int i = 0; +// for (Node *n in nodes) { +// [n updateData]; +// [n setName:[NSString stringWithFormat:@"%d", i]]; +// [code appendFormat:@"\t\t\\node %@ (%d) at (%@, %@) {%@};\n", +// [[n data] tikzList], +// i, +// formatFloat([n point].x, 4), +// formatFloat([n point].y, 4), +// [n label] +// ]; +// i++; +// } + +// if ([nodes count] > 0) [code appendFormat:@"\t\\end{pgfonlayer}\n"]; +// if ([edges count] > 0) [code appendFormat:@"\t\\begin{pgfonlayer}{edgelayer}\n"]; + +// NSString *nodeStr; +// for (Edge *e in edges) { +// [e updateData]; + +// if ([e hasEdgeNode]) { +// nodeStr = [NSString stringWithFormat:@"node%@{%@} ", +// [[[e edgeNode] data] tikzList], +// [[e edgeNode] label] +// ]; +// } else { +// nodeStr = @""; +// } + +// NSString *edata = [[e data] tikzList]; + +// NSString *srcAnchor; +// NSString *tgtAnchor; + +// if ([[e sourceAnchor] isEqual:@""]) { +// srcAnchor = @""; +// } else { +// srcAnchor = [NSString stringWithFormat:@".%@", [e sourceAnchor]]; +// } + +// if ([[e targetAnchor] isEqual:@""]) { +// tgtAnchor = @""; +// } else { +// tgtAnchor = [NSString stringWithFormat:@".%@", [e targetAnchor]]; +// } + +// [code appendFormat:@"\t\t\\draw%@ (%@%@) to %@(%@%@);\n", +// ([edata isEqual:@""]) ? @"" : [NSString stringWithFormat:@" %@", edata], +// [[e source] name], +// srcAnchor, +// nodeStr, +// ([e source] == [e target]) ? @"" : [[e target] name], +// tgtAnchor +// ]; +// } + +// if ([edges count] > 0) [code appendFormat:@"\t\\end{pgfonlayer}\n"]; + +// [code appendString:@"\\end{tikzpicture}"]; + +// [graphLock unlock]; + +// return code; + return str; +} + +void Graph::setBbox(const QRectF &bbox) +{ + _bbox = bbox; +} + Node *Graph::addNode() { Node *n = new Node(this); _nodes << n; -- cgit v1.2.3