diff options
author | Alex Merry <alex.merry@cs.ox.ac.uk> | 2013-02-04 11:55:17 +0000 |
---|---|---|
committer | Alex Merry <alex.merry@cs.ox.ac.uk> | 2013-02-04 11:55:17 +0000 |
commit | 5349460f6ba630d92ab61f4cbe1c04210e7684cc (patch) | |
tree | ffca8efdeb7e51477d6f90e93512f75432600c48 /tikzit/src | |
parent | f9bdbf93887313a79528696607d96140f33cbd84 (diff) | |
parent | 5afd392bb6ddde79f0518ffd913bd8c365bf39e6 (diff) |
Merge branch 'master' into multi-docs
Diffstat (limited to 'tikzit/src')
-rw-r--r-- | tikzit/src/common/Edge.h | 14 | ||||
-rw-r--r-- | tikzit/src/common/Edge.m | 23 | ||||
-rw-r--r-- | tikzit/src/common/EdgeStyle.m | 8 | ||||
-rw-r--r-- | tikzit/src/common/Graph.m | 23 | ||||
-rw-r--r-- | tikzit/src/common/Preambles.h | 2 | ||||
-rw-r--r-- | tikzit/src/common/Preambles.m | 16 | ||||
-rw-r--r-- | tikzit/src/common/TikzGraphAssembler.h | 5 | ||||
-rw-r--r-- | tikzit/src/common/TikzGraphAssembler.m | 69 | ||||
-rw-r--r-- | tikzit/src/common/test/parser.m | 11 | ||||
-rw-r--r-- | tikzit/src/common/test/test.m | 2 | ||||
-rw-r--r-- | tikzit/src/common/tikzlexer.lm | 61 | ||||
-rw-r--r-- | tikzit/src/common/tikzparser.ym | 42 | ||||
-rw-r--r-- | tikzit/src/osx/AppDelegate.m | 4 | ||||
-rw-r--r-- | tikzit/src/osx/PreambleController.h | 2 | ||||
-rw-r--r-- | tikzit/src/osx/PreambleController.m | 3 | ||||
-rw-r--r-- | tikzit/src/osx/PropertyInspectorController.h | 10 | ||||
-rw-r--r-- | tikzit/src/osx/PropertyInspectorController.m | 7 | ||||
-rw-r--r-- | tikzit/src/osx/TikzFormatter.h | 29 | ||||
-rw-r--r-- | tikzit/src/osx/TikzFormatter.m | 92 |
19 files changed, 358 insertions, 65 deletions
diff --git a/tikzit/src/common/Edge.h b/tikzit/src/common/Edge.h index 607fcc6..cc636dd 100644 --- a/tikzit/src/common/Edge.h +++ b/tikzit/src/common/Edge.h @@ -58,6 +58,8 @@ typedef enum { float weight; EdgeStyle *style; GraphElementData *data; + NSString *sourceAnchor; + NSString *targetAnchor; // When set to YES, lazily create the edge node, and keep it around when set // to NO (at least until saved/loaded). @@ -115,6 +117,18 @@ typedef enum { @property (retain) Node *edgeNode; /*! + @property sourceAnchor + @brief The source node anchor point, as in north or center. + */ +@property (copy) NSString *sourceAnchor; + +/*! + @property targetAnchor + @brief The target node anchor point, as in north or center. + */ +@property (copy) NSString *targetAnchor; + +/*! @property hasEdgeNode @brief A read/write property. When set to true, a new edge node is actually constructed. */ diff --git a/tikzit/src/common/Edge.m b/tikzit/src/common/Edge.m index 2514fc1..4ecb9bf 100644 --- a/tikzit/src/common/Edge.m +++ b/tikzit/src/common/Edge.m @@ -39,6 +39,8 @@ source = nil; target = nil; edgeNode = nil; + sourceAnchor = @""; + targetAnchor = @""; return self; } @@ -389,6 +391,25 @@ [self didChangeValueForKey:@"hasEdgeNode"]; } +@synthesize sourceAnchor; +@synthesize targetAnchor; + +- (void)setSourceAnchor:(NSString *)_sourceAnchor{ + if(_sourceAnchor != nil){ + sourceAnchor = _sourceAnchor; + }else{ + sourceAnchor = @""; + } +} + +- (void)setTargetAnchor:(NSString *)_targetAnchor{ + if(_targetAnchor != nil){ + targetAnchor = _targetAnchor; + }else{ + targetAnchor = @""; + } +} + @synthesize data; - (void) insertObject:(GraphElementProperty*)gep inDataAtIndex:(NSUInteger)index { @@ -587,6 +608,8 @@ [source release]; [target release]; [data release]; + [sourceAnchor release]; + [targetAnchor release]; [super dealloc]; } diff --git a/tikzit/src/common/EdgeStyle.m b/tikzit/src/common/EdgeStyle.m index 88b1f54..7a638c9 100644 --- a/tikzit/src/common/EdgeStyle.m +++ b/tikzit/src/common/EdgeStyle.m @@ -169,9 +169,11 @@ else if (headStyle == AH_Latex) [buf appendString:@"latex"]; - [buf appendString:@",draw="]; - [buf appendString:colorName]; - + if(colorName != nil){ + [buf appendString:@",draw="]; + [buf appendString:colorName]; + } + if (decorationStyle != ED_None) { [buf appendString:@",postaction={decorate},decoration={markings,mark="]; if (decorationStyle == ED_Arrow) diff --git a/tikzit/src/common/Graph.m b/tikzit/src/common/Graph.m index 7f7345c..767f307 100644 --- a/tikzit/src/common/Graph.m +++ b/tikzit/src/common/Graph.m @@ -722,14 +722,33 @@ } NSString *edata = [[e data] stringList]; + + NSString *srcAnchor; + NSString *tgtAnchor; + + if ([[e source] style] == nil) { + srcAnchor = @".center"; + } else if ([[e sourceAnchor] isEqual:@""]) { + srcAnchor = @""; + } else { + srcAnchor = [NSString stringWithFormat:@".%@", [e sourceAnchor]]; + } + + if ([[e target] style] == nil) { + tgtAnchor = @".center"; + } else 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], - ([[e source] style] == nil) ? @".center" : @"", + srcAnchor, nodeStr, ([e source] == [e target]) ? @"" : [[e target] name], - ([e source] != [e target] && [[e target] style] == nil) ? @".center" : @"" + tgtAnchor ]; } diff --git a/tikzit/src/common/Preambles.h b/tikzit/src/common/Preambles.h index d507ad9..95081c4 100644 --- a/tikzit/src/common/Preambles.h +++ b/tikzit/src/common/Preambles.h @@ -29,6 +29,7 @@ NSMutableDictionary *preambleDict; NSString *selectedPreambleName; NSArray *styles; + NSArray *edges; StyleManager *styleManager; } @@ -40,6 +41,7 @@ + (Preambles*)preambles; - (id)init; - (void)setStyles:(NSArray*)sty; +- (void)setEdges:(NSArray*)edg; - (NSString*)preambleForName:(NSString*)name; - (BOOL)setPreamble:(NSString*)content forName:(NSString*)name; diff --git a/tikzit/src/common/Preambles.m b/tikzit/src/common/Preambles.m index af3bbc4..5343127 100644 --- a/tikzit/src/common/Preambles.m +++ b/tikzit/src/common/Preambles.m @@ -64,6 +64,7 @@ static NSString *POSTAMBLE = preambleDict = [[NSMutableDictionary alloc] initWithCapacity:1]; [preambleDict setObject:[self defaultPreamble] forKey:@"custom"]; styles = nil; + edges = nil; styleManager = nil; return self; } @@ -96,6 +97,12 @@ static NSString *POSTAMBLE = styles = sty; } +- (void)setEdges:(NSArray*)edg { + [edg retain]; + [edges release]; + edges = edg; +} + - (NSString*)styleDefinitions { if (styleManager != nil) { [self setStyles:[styleManager nodeStyles]]; @@ -120,11 +127,16 @@ static NSString *POSTAMBLE = [stroke hexName], [stroke redFloat], [stroke greenFloat], [stroke blueFloat]]; } } + + if (styleManager != nil) { + [self setEdges:[styleManager edgeStyles]]; + } + [buf appendString:@"\n"]; - for (EdgeStyle *st in [styleManager edgeStyles]) { + for (EdgeStyle *st in edges) { [buf appendFormat:@"%@\n", [st tikz]]; ColorRGB *color = [st colorRGB]; - if ([color name] == nil && ![colors containsObject:color]) { + if (color != nil && [color name] == nil && ![colors containsObject:color]) { [colors addObject:color]; [colbuf appendFormat:@"\\definecolor{%@}{rgb}{%.3f,%.3f,%.3f}\n", [color hexName], [color redFloat], [color greenFloat], [color blueFloat]]; diff --git a/tikzit/src/common/TikzGraphAssembler.h b/tikzit/src/common/TikzGraphAssembler.h index 1b006dd..a0c8a0d 100644 --- a/tikzit/src/common/TikzGraphAssembler.h +++ b/tikzit/src/common/TikzGraphAssembler.h @@ -41,11 +41,14 @@ - (BOOL)parseTikz:(NSString*)tikz; - (BOOL)parseTikz:(NSString*)tikz forGraph:(Graph*)gr; +- (BOOL)testTikz:(NSString*)tikz; + - (void)prepareNode; - (void)finishNode; - (void)prepareEdge; -- (void)setEdgeSource:(NSString*)src target:(NSString*)targ; +- (void)setEdgeSource:(NSString*)edge anchor:(NSString*)anch; +- (void)setEdgeTarget:(NSString*)edge anchor:(NSString*)anch; - (void)finishEdge; - (void)invalidate; diff --git a/tikzit/src/common/TikzGraphAssembler.m b/tikzit/src/common/TikzGraphAssembler.m index 5e60b05..b07ee58 100644 --- a/tikzit/src/common/TikzGraphAssembler.m +++ b/tikzit/src/common/TikzGraphAssembler.m @@ -34,12 +34,20 @@ extern int yylex_destroy(void); static NSLock *parseLock = nil; static id currentAssembler = nil; +extern int yylineno; +extern int yyleng; +int lineno; +int tokenpos; +extern char *yystr; +char linebuff[500]; + + void yyerror(const char *str) { - NSLog(@"Parse error: %s", str); + NSLog(@"Parse error on line %i: %s\n%s\n%@\n", lineno, str, linebuff, [[@"" stringByPaddingToLength:(tokenpos-yyleng) withString: @" " startingAtIndex:0] stringByAppendingString:[@"" stringByPaddingToLength:yyleng withString: @"^" startingAtIndex:0]]); if (currentAssembler != nil) { - NSError *error = [NSError - errorWithMessage:[NSString stringWithCString:str] - code:TZ_ERR_PARSE]; + NSError *error = [NSError errorWithDomain:@"net.sourceforge.tikzit" + code:TZ_ERR_PARSE + userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithCString:str] forKey: NSLocalizedDescriptionKey]]; [currentAssembler invalidateWithError:error]; } } @@ -81,6 +89,10 @@ int yywrap() { - (BOOL)parseTikz:(NSString*)tikz forGraph:(Graph*)gr { [parseLock lock]; + + lineno = 1; + tokenpos = 0; + linebuff[0] = 0; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; currentAssembler = self; @@ -93,12 +105,14 @@ int yywrap() { // the node map keeps track of the mapping of names to nodes nodeMap = [[NSMutableDictionary alloc] init]; - - // do the parsing - yy_scan_string([tikz UTF8String]); - yyparse(); - yylex_destroy(); - + + // do the parsing if actual input + if([tikz length] > 0){ + yy_scan_string([tikz UTF8String]); + yyparse(); + yylex_destroy(); + } + [nodeMap release]; nodeMap = nil; @@ -110,6 +124,22 @@ int yywrap() { return (graph != nil); } +- (BOOL)testTikz:(NSString *)tikz{ + BOOL r; + + NSString * testTikz = [NSString stringWithFormat: @"{%@}", tikz]; + + yy_scan_string([testTikz UTF8String]); + yylex(); + + r = !(yyleng < [testTikz length]); + + [testTikz autorelease]; + yylex_destroy(); + + return r; +} + - (void)prepareNode { currentNode = [[Node alloc] init]; } @@ -137,14 +167,19 @@ int yywrap() { currentEdge = nil; } -- (void)setEdgeSource:(NSString*)src target:(NSString*)targ { - if (![targ isEqualToString:@""]) { - [currentEdge setSource:[nodeMap objectForKey:src]]; - [currentEdge setTarget:[nodeMap objectForKey:targ]]; +- (void)setEdgeSource:(NSString*)edge anchor:(NSString*)anch { + Node *s = [nodeMap objectForKey:edge]; + [currentEdge setSource:s]; + [currentEdge setSourceAnchor:anch]; +} + +- (void)setEdgeTarget:(NSString*)edge anchor:(NSString*)anch { + if (![edge isEqualToString:@""]) { + [currentEdge setTarget:[nodeMap objectForKey:edge]]; + [currentEdge setTargetAnchor:anch]; } else { - Node *s = [nodeMap objectForKey:src]; - [currentEdge setSource:s]; - [currentEdge setTarget:s]; + [currentEdge setTargetAnchor:anch]; + [currentEdge setTarget:[currentEdge source]]; } } diff --git a/tikzit/src/common/test/parser.m b/tikzit/src/common/test/parser.m index 29dabe7..3346acd 100644 --- a/tikzit/src/common/test/parser.m +++ b/tikzit/src/common/test/parser.m @@ -34,7 +34,7 @@ void testParser() { [TikzGraphAssembler setup]; - NodeStyle *rn = [NodeStyle defaultStyleWithName:@"rn"]; + NodeStyle *rn = [NodeStyle defaultNodeStyleWithName:@"rn"]; NSArray *styles = [NSArray arrayWithObject:rn]; NSString *tikz = @@ -74,9 +74,12 @@ void testParser() { TEST(@"Edge has edge node", [e1 edgeNode]!=nil); TEST(@"Edge node labeled correctly", [[[e1 edgeNode] label] isEqualToString:@"-"]); - NSString *sty = [[[[[e1 edgeNode] data] atoms] objectEnumerator] nextObject]; - TEST(@"Edge node styled correctly", sty!=nil && [sty isEqualToString:@"tick"]); - +// NSString *sty = [[[[[e1 edgeNode] data] atoms] objectEnumerator] nextObject]; +// TEST(@"Edge node styled correctly", sty!=nil && [sty isEqualToString:@"tick"]); + + PUTS(@"Source anchor: %@",[e1 sourceAnchor]); + PUTS(@"Target anchor: %@",[e1 targetAnchor]); + endTestBlock(@"parser"); [pool drain]; diff --git a/tikzit/src/common/test/test.m b/tikzit/src/common/test/test.m index 8437646..9afcd67 100644 --- a/tikzit/src/common/test/test.m +++ b/tikzit/src/common/test/test.m @@ -160,7 +160,7 @@ void runTests(); int main() { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - setColorEnabled (YES); + setColorEnabled (NO); startTests(); runTests(); diff --git a/tikzit/src/common/tikzlexer.lm b/tikzit/src/common/tikzlexer.lm index 9418d83..816d91c 100644 --- a/tikzit/src/common/tikzlexer.lm +++ b/tikzit/src/common/tikzlexer.lm @@ -1,4 +1,6 @@ %option nounput +%option yylineno + %{ // // tikzparser.l @@ -30,48 +32,61 @@ #include "tikzparser.h" #endif +extern char linebuff[500]; +extern int lineno; +extern int tokenpos; %} %% -\n /* ignore end of line */; -[ \t]+ /* ignore whitespace */; -\\begin return LATEXBEGIN; -\\end return LATEXEND; -\{tikzpicture\} return TIKZPICTURE; -\{pgfonlayer\} return PGFONLAYER; -\.center return ANCHORCENTER; -\( return LEFTPARENTHESIS; -\) return RIGHTPARENTHESIS; -\[ return LEFTBRACKET; -\] return RIGHTBRACKET; -; return SEMICOLON; -, return COMMA; -= return EQUALS; -\\draw return DRAW; -to return TO; -\\node return NODE; -\\path return PATH; -node return ALTNODE; -rectangle return RECTANGLE; -at return AT; +%\n /* ignore end of line */; +\n.* { strcpy(linebuff, yytext+1); + lineno++; + tokenpos = 0; + yyless(1); + } +[ ]+ { tokenpos += yyleng; } /* ignore whitespace */; +[\t]+ { tokenpos += 4*yyleng; } /* ignore whitespace */; +\\begin { tokenpos += yyleng; return LATEXBEGIN; } +\\end { tokenpos += yyleng; return LATEXEND; } +\{tikzpicture\} { tokenpos += yyleng; return TIKZPICTURE; } +\{pgfonlayer\} { tokenpos += yyleng; return PGFONLAYER; } +\( { tokenpos += yyleng; return LEFTPARENTHESIS; } +\) { tokenpos += yyleng; return RIGHTPARENTHESIS; } +\[ { tokenpos += yyleng; return LEFTBRACKET; } +\] { tokenpos += yyleng; return RIGHTBRACKET; } +; { tokenpos += yyleng; return SEMICOLON; } +, { tokenpos += yyleng; return COMMA; } +\. { tokenpos += yyleng; return FULLSTOP; } += { tokenpos += yyleng; return EQUALS; } +\\draw { tokenpos += yyleng; return DRAW; } +to { tokenpos += yyleng; return TO; } +\\node { tokenpos += yyleng; return NODE; } +\\path { tokenpos += yyleng; return PATH; } +node { tokenpos += yyleng; return ALTNODE; } +rectangle { tokenpos += yyleng; return RECTANGLE; } +at { tokenpos += yyleng; return AT; } [0-9]+ { + tokenpos += yyleng; yylval.nsstr=[NSString stringWithUTF8String:yytext]; return NATURALNUMBER; } (\-?[0-9]*\.[0-9]+)|(\-?[0-9]+) { + tokenpos += yyleng; yylval.nsstr=[NSString stringWithUTF8String:yytext]; return REALNUMBER; } -\\?[a-zA-Z<>\-\']+ { //' +\\?[a-zA-Z<>\-\'][a-zA-Z<>\-\'0-9]* { //' + tokenpos += yyleng; yylval.nsstr=[NSString stringWithUTF8String:yytext]; return LWORD; } \"[^\"]*\" /* " */ { + tokenpos += yyleng; yylval.nsstr=[NSString stringWithUTF8String:yytext]; return QUOTEDSTRING; } @@ -93,8 +108,10 @@ at return AT; } NSString *s = [buf copy]; + yyleng += 1 + [buf length]; [s autorelease]; yylval.nsstr = s; + tokenpos += yyleng; return DELIMITEDSTRING; } diff --git a/tikzit/src/common/tikzparser.ym b/tikzit/src/common/tikzparser.ym index 57f0600..487cfd4 100644 --- a/tikzit/src/common/tikzparser.ym +++ b/tikzit/src/common/tikzparser.ym @@ -29,6 +29,9 @@ #import "TikzGraphAssembler.h" #import "GraphElementProperty.h" +extern char* yystr; +extern int yylineno; +extern int tokenpos; extern int yylex(void); extern void yyerror(const char *str); @@ -39,17 +42,19 @@ extern void yyerror(const char *str); NSString *nsstr; }; +%error-verbose + %token LATEXBEGIN %token LATEXEND %token TIKZPICTURE %token PGFONLAYER -%token ANCHORCENTER %token LEFTPARENTHESIS %token RIGHTPARENTHESIS %token LEFTBRACKET %token RIGHTBRACKET %token SEMICOLON %token COMMA +%token FULLSTOP %token EQUALS %token DRAW %token TO @@ -65,9 +70,10 @@ extern void yyerror(const char *str); %token DELIMITEDSTRING %type<nsstr> nodename +%type<nsstr> anchor +%type<nsstr> optanchor %type<nsstr> nodeid %type<pt> coords -%type<nsstr> target %type<nsstr> propsym %type<nsstr> propsyms %type<nsstr> val @@ -119,6 +125,8 @@ propsym: nodecmd : NODE { [[TikzGraphAssembler currentAssembler] prepareNode]; }; +nodename: LEFTPARENTHESIS nodeid RIGHTPARENTHESIS { $$ = $<nsstr>2; }; + node: nodecmd optproperties nodename AT coords nodelabel SEMICOLON { @@ -135,8 +143,17 @@ nodelabel: [n setLabel:$<nsstr>1]; } -optanchor: | ANCHORCENTER; -nodename: LEFTPARENTHESIS nodeid optanchor RIGHTPARENTHESIS { $$ = $<nsstr>2; }; +anchor: LWORD { $$ = $<nsstr>1; } | NATURALNUMBER { $$ = $<nsstr>1; }; + +optanchor: { $$ = @""; } | FULLSTOP anchor { $$ = $<nsstr>2; }; + +source: LEFTPARENTHESIS nodeid optanchor RIGHTPARENTHESIS + { + TikzGraphAssembler *a = [TikzGraphAssembler currentAssembler]; + [a setEdgeSource:$<nsstr>2 + anchor:$<nsstr>3]; + }; + nodeid: LWORD { $$ = $<nsstr>1; } | NATURALNUMBER { $$ = $<nsstr>1; }; coords: @@ -147,14 +164,23 @@ coords: edgecmd : DRAW { [[TikzGraphAssembler currentAssembler] prepareEdge]; }; edge: - edgecmd optproperties nodename TO optedgenode target SEMICOLON + edgecmd optproperties source TO optedgenode target SEMICOLON { TikzGraphAssembler *a = [TikzGraphAssembler currentAssembler]; - [a setEdgeSource:$<nsstr>3 - target:$<nsstr>6]; [a finishEdge]; }; -target: nodename { $$=$<nsstr>1; } | selfloop { $$=@""; }; +target: LEFTPARENTHESIS nodeid optanchor RIGHTPARENTHESIS + { + TikzGraphAssembler *a = [TikzGraphAssembler currentAssembler]; + [a setEdgeTarget:$<nsstr>2 + anchor:$<nsstr>3]; + } + | selfloop + { + TikzGraphAssembler *a = [TikzGraphAssembler currentAssembler]; + [a setEdgeTarget:@"" + anchor:@""]; + }; selfloop: LEFTPARENTHESIS RIGHTPARENTHESIS; altnodecmd: ALTNODE { [[TikzGraphAssembler currentAssembler] prepareNode]; }; diff --git a/tikzit/src/osx/AppDelegate.m b/tikzit/src/osx/AppDelegate.m index edfaf19..bb1b5d6 100644 --- a/tikzit/src/osx/AppDelegate.m +++ b/tikzit/src/osx/AppDelegate.m @@ -51,7 +51,9 @@ preambleController = [[PreambleController alloc] initWithWindowNibName:@"Preamble" plist:preamblePlist - styles:[stylePaletteController nodeStyles]]; + styles:[stylePaletteController nodeStyles] + edges:[stylePaletteController edgeStyles]]; + char template[] = "/tmp/tikzit_tmp_XXXXXXX"; char *dir = mkdtemp(template); diff --git a/tikzit/src/osx/PreambleController.h b/tikzit/src/osx/PreambleController.h index 4f7fb33..2d5a8ab 100644 --- a/tikzit/src/osx/PreambleController.h +++ b/tikzit/src/osx/PreambleController.h @@ -44,7 +44,7 @@ @property (retain) NSAttributedString *preambleText; @property (retain) NSIndexSet *selectionIndexes; -- (id)initWithWindowNibName:(NSString *)windowNibName plist:(NSString*)plist styles:(NSArray*)sty; +- (id)initWithWindowNibName:(NSString *)windowNibName plist:(NSString*)plist styles:(NSArray*)sty edges:(NSArray*)edg; - (void)savePreambles:(NSString*)plist; - (NSString*)currentPreamble; - (NSString*)currentPostamble; diff --git a/tikzit/src/osx/PreambleController.m b/tikzit/src/osx/PreambleController.m index e09a3fc..e424e7b 100644 --- a/tikzit/src/osx/PreambleController.m +++ b/tikzit/src/osx/PreambleController.m @@ -28,11 +28,12 @@ @synthesize preambleText, preambles; -- (id)initWithWindowNibName:(NSString *)windowNibName plist:(NSString*)plist styles:(NSArray*)sty { +- (id)initWithWindowNibName:(NSString *)windowNibName plist:(NSString*)plist styles:(NSArray*)sty edges:(NSArray*)edg { [super initWithWindowNibName:windowNibName]; preambles = (Preambles*)[NSKeyedUnarchiver unarchiveObjectWithFile:plist]; [preambles setStyles:sty]; + [preambles setEdges:edg]; if (preambles == nil) preambles = [[Preambles alloc] init]; preambleText = nil; diff --git a/tikzit/src/osx/PropertyInspectorController.h b/tikzit/src/osx/PropertyInspectorController.h index cb14021..0625f9b 100644 --- a/tikzit/src/osx/PropertyInspectorController.h +++ b/tikzit/src/osx/PropertyInspectorController.h @@ -18,6 +18,8 @@ IBOutlet NSView *nodePropertiesView; IBOutlet NSView *graphPropertiesView; IBOutlet NSView *edgePropertiesView; + IBOutlet NSComboBox *sourceAnchorComboBox; + IBOutlet NSComboBox *targetAnchorComboBox; IBOutlet NSTextField *edgeNodeLabelField; IBOutlet NSButton *edgeNodeCheckbox; IBOutlet NSArrayController *nodeDataArrayController; @@ -25,6 +27,12 @@ IBOutlet NSArrayController *edgeDataArrayController; IBOutlet NSArrayController *edgeNodeDataArrayController; + NSMutableArray *sourceAnchorNames; + IBOutlet NSArrayController *sourceAnchorNamesArrayController; + + NSMutableArray *targetAnchorNames; + IBOutlet NSArrayController *targetAnchorNamesArrayController; + NSMutableArray *selectedNodes; IBOutlet NSArrayController *selectedNodesArrayController; @@ -46,6 +54,8 @@ //@property (readonly) BOOL enableEdgeDataControls; @property (retain) NSMutableArray *selectedNodes; @property (retain) NSMutableArray *selectedEdges; +@property (retain) NSMutableArray *sourceAnchorNames; +@property (retain) NSMutableArray *targetAnchorNames; @property (retain) StylePaletteController *stylePaletteController; - (id)initWithWindowNibName:(NSString *)windowNibName; diff --git a/tikzit/src/osx/PropertyInspectorController.m b/tikzit/src/osx/PropertyInspectorController.m index 8254949..1411549 100644 --- a/tikzit/src/osx/PropertyInspectorController.m +++ b/tikzit/src/osx/PropertyInspectorController.m @@ -22,6 +22,7 @@ @synthesize stylePaletteController; @synthesize selectedNodes, selectedEdges; +@synthesize sourceAnchorNames, targetAnchorNames; - (id)initWithWindowNibName:(NSString *)windowNibName { [super initWithWindowNibName:windowNibName]; @@ -50,8 +51,10 @@ name:@"NSWindowDidBecomeMainNotification" object:nil]; - - + [self setSourceAnchorNames: [[NSMutableArray alloc] initWithArray: [@"north south west east" componentsSeparatedByString:@" "]]]; + + [self setTargetAnchorNames: [[NSMutableArray alloc] initWithArray:[@"north south west east" componentsSeparatedByString:@" "]]]; + [[self window] setLevel:NSNormalWindowLevel]; [self showWindow:self]; diff --git a/tikzit/src/osx/TikzFormatter.h b/tikzit/src/osx/TikzFormatter.h new file mode 100644 index 0000000..4d9ec04 --- /dev/null +++ b/tikzit/src/osx/TikzFormatter.h @@ -0,0 +1,29 @@ +// +// NSTikzFormatter.h +// TikZiT +// +// Created by Karl Johan Paulsson on 27/01/2013. +// Copyright (c) 2013 Aleks Kissinger. All rights reserved. +// +// +// This file is part of TikZiT. +// +// TikZiT is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// TikZiT is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. +// + +#import <Foundation/Foundation.h> + +@interface TikzFormatter : NSFormatter + +@end diff --git a/tikzit/src/osx/TikzFormatter.m b/tikzit/src/osx/TikzFormatter.m new file mode 100644 index 0000000..ecbb0bc --- /dev/null +++ b/tikzit/src/osx/TikzFormatter.m @@ -0,0 +1,92 @@ +// +// NSTikzFormatter.m +// TikZiT +// +// Created by Karl Johan Paulsson on 27/01/2013. +// Copyright (c) 2013 Aleks Kissinger. All rights reserved. +// +// +// This file is part of TikZiT. +// +// TikZiT is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// TikZiT is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. +// + +#import "TikzFormatter.h" +#import "TikzGraphAssembler.h" + +@implementation TikzFormatter + +- (NSString *)stringForObjectValue:(id)obj{ + if (![obj isKindOfClass:[NSString class]]) { + return @""; + } + + return [NSString stringWithString:obj]; +} + +- (BOOL)getObjectValue:(out id *)obj forString:(NSString *)string errorDescription:(out NSString **)error{ + *obj = [NSString stringWithString:string]; + + TikzGraphAssembler *ass = [[TikzGraphAssembler alloc] init]; + BOOL r = [ass testTikz:string]; + + if (!r && error) + *error = NSLocalizedString(@"Invalid input, couldn't parse value.", @"tikz user input error"); + + return r; +} + +- (BOOL)isPartialStringValid:(NSString **)partialStringPtr proposedSelectedRange:(NSRangePointer)proposedSelRangePtr originalString:(NSString *)origString originalSelectedRange:(NSRange)origSelRange errorDescription:(NSString **)error{ + NSRange addedRange; + NSString *addedString; + + addedRange = NSMakeRange(origSelRange.location, proposedSelRangePtr->location - origSelRange.location); + addedString = [*partialStringPtr substringWithRange: addedRange]; + + if([addedString isEqualToString:@"{"]){ + NSString *s = [[NSString stringWithString:*partialStringPtr] stringByAppendingString:@"}"]; + *partialStringPtr = s; + + return NO; + } + + if([addedString isEqualToString:@"}"]){ + NSScanner *scanner = [NSScanner scannerWithString:*partialStringPtr]; + + NSCharacterSet *cs = [NSCharacterSet characterSetWithCharactersInString:@"{}"]; + NSMutableString *strippedString = [NSMutableString stringWithCapacity:[*partialStringPtr length]]; + + while ([scanner isAtEnd] == NO) { + NSString *buffer; + if ([scanner scanCharactersFromSet:cs intoString:&buffer]) { + [strippedString appendString:buffer]; + + } else { + [scanner setScanLocation:([scanner scanLocation] + 1)]; + } + } + + [cs autorelease]; + [scanner autorelease]; + [strippedString autorelease]; + + if([strippedString length] % 2 == 1){ + return NO; + } + } + + return YES; +} + +@end |