From 1a111979e01a6081cbea69e40accebe16e6155e5 Mon Sep 17 00:00:00 2001 From: Alex Merry Date: Sun, 24 Mar 2013 15:52:33 +0000 Subject: Add methods to Graph to create from tikz These are just convenience wrappers for TikzGraphAssembler. As a result, non of the GTK code uses TikzGraphAssembler directly. --- tikzit/src/common/Graph.h | 35 +++++++++++++++++++++++++++++++++++ tikzit/src/common/Graph.m | 20 +++++++++++++++++++- tikzit/src/common/NSString+Tikz.m | 1 - tikzit/src/common/TikzShape.m | 3 +-- tikzit/src/gtk/TikzDocument.m | 5 ++--- tikzit/src/gtk/main.m | 1 - 6 files changed, 57 insertions(+), 8 deletions(-) diff --git a/tikzit/src/common/Graph.h b/tikzit/src/common/Graph.h index f5d8bed..1f98858 100644 --- a/tikzit/src/common/Graph.h +++ b/tikzit/src/common/Graph.h @@ -361,6 +361,41 @@ */ + (Graph*)graph; +/** + * Initialize an empty graph + */ +- (id)init; + +/** + * Constructs a graph from the given tikz code + * + * See TikzGraphAssembler for more information about the error argument. + */ ++ (Graph*)graphFromTikz:(NSString*)tikz error:(NSError**)e; + +/** + * Constructs a graph from the given tikz code + */ ++ (Graph*)graphFromTikz:(NSString*)tikz; + +/** + * Initialize an empty graph from the given tikz code + * + * Note that this may not return the same object it was called on, + * and will return nil if parsing failed. + * + * See TikzGraphAssembler for more information about the error argument. + */ +- (id)initFromTikz:(NSString*)tikz error:(NSError**)e; + +/** + * Initialize an empty graph from the given tikz code + * + * Note that this may not return the same object it was called on, + * and will return nil if parsing failed. + */ +- (id)initFromTikz:(NSString*)tikz; + @end // vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/Graph.m b/tikzit/src/common/Graph.m index d18e4db..2a01bae 100644 --- a/tikzit/src/common/Graph.m +++ b/tikzit/src/common/Graph.m @@ -22,10 +22,11 @@ // #import "Graph.h" +#import "TikzGraphAssembler.h" @implementation Graph -- (Graph*)init { +- (id)init { self = [super init]; if (self != nil) { data = [[GraphElementData alloc] init]; @@ -39,6 +40,15 @@ return self; } +- (id)initFromTikz:(NSString*)tikz error:(NSError**)e { + [self release]; + return [[TikzGraphAssembler parseTikz:tikz error:e] retain]; +} + +- (id)initFromTikz:(NSString*)tikz { + return [self initFromTikz:tikz error:NULL]; +} + - (id) copyWithZone:(NSZone*)zone { Graph *newGraph = [self copyOfSubgraphWithNodes:[NSSet setWithArray:nodes] zone:zone]; [newGraph setData:[self data]]; @@ -765,6 +775,14 @@ return [[[self alloc] init] autorelease]; } ++ (Graph*)graphFromTikz:(NSString*)tikz error:(NSError**)e { + return [TikzGraphAssembler parseTikz:tikz error:e]; +} + ++ (Graph*)graphFromTikz:(NSString*)tikz { + return [self graphFromTikz:tikz error:NULL]; +} + + (NSMapTable*)nodeTableForNodes:(NSSet*)nds { return [self nodeTableForNodes:nds withZone:NSDefaultMallocZone()]; } diff --git a/tikzit/src/common/NSString+Tikz.m b/tikzit/src/common/NSString+Tikz.m index 85a51d3..8b11ad2 100644 --- a/tikzit/src/common/NSString+Tikz.m +++ b/tikzit/src/common/NSString+Tikz.m @@ -16,7 +16,6 @@ */ #import "NSString+Tikz.h" -#import "TikzGraphAssembler.h" @implementation NSString (Tikz) diff --git a/tikzit/src/common/TikzShape.m b/tikzit/src/common/TikzShape.m index 722275c..8cf823b 100644 --- a/tikzit/src/common/TikzShape.m +++ b/tikzit/src/common/TikzShape.m @@ -22,7 +22,6 @@ // #import "TikzShape.h" -#import "TikzGraphAssembler.h" #import "Graph.h" @implementation TikzShape @@ -35,7 +34,7 @@ error:NULL]; if (tikz == nil) return nil; - Graph *graph = [TikzGraphAssembler parseTikz:tikz]; + Graph *graph = [Graph graphFromTikz:tikz]; if (graph == nil) return nil; NSRect graphBounds = ([graph hasBoundingBox]) ? [graph boundingBox] : [graph bounds]; diff --git a/tikzit/src/gtk/TikzDocument.m b/tikzit/src/gtk/TikzDocument.m index 78746f2..86b8afb 100644 --- a/tikzit/src/gtk/TikzDocument.m +++ b/tikzit/src/gtk/TikzDocument.m @@ -22,7 +22,6 @@ // #import "TikzDocument.h" -#import "TikzGraphAssembler.h" @interface TikzDocument (Private) - (void) styleRenamed:(NSNotification*)n; @@ -264,7 +263,7 @@ return YES; } - Graph *g = [TikzGraphAssembler parseTikz:t error:error]; + Graph *g = [Graph graphFromTikz:t error:error]; if (g) { // updateTikz actually generates a graph from the tikz, // and generates the final tikz from that @@ -310,7 +309,7 @@ } - (void) pasteFromTikz:(NSString*)t { - Graph *clipboard = [TikzGraphAssembler parseTikz:t]; + Graph *clipboard = [Graph graphFromTikz:t]; if (clipboard) { [self attachStylesToGraph:clipboard]; [self paste:clipboard]; diff --git a/tikzit/src/gtk/main.m b/tikzit/src/gtk/main.m index 10fa990..b6e297e 100644 --- a/tikzit/src/gtk/main.m +++ b/tikzit/src/gtk/main.m @@ -28,7 +28,6 @@ #import "tzstockitems.h" #import "Application.h" -#import "TikzGraphAssembler.h" static GOptionEntry entries[] = { -- cgit v1.2.3