diff options
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/Graph.m | 4 | ||||
-rw-r--r-- | tikzit/src/common/TikzGraphAssembler.h | 3 | ||||
-rw-r--r-- | tikzit/src/common/TikzGraphAssembler.m | 25 | ||||
-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 | 4 | ||||
-rw-r--r-- | tikzit/src/common/tikzparser.ym | 39 | ||||
-rw-r--r-- | tikzit/src/osx/PropertyInspectorController.h | 10 | ||||
-rw-r--r-- | tikzit/src/osx/PropertyInspectorController.m | 7 |
11 files changed, 112 insertions, 30 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..3e25888 100644 --- a/tikzit/src/common/Edge.m +++ b/tikzit/src/common/Edge.m @@ -39,6 +39,8 @@ source = nil; target = nil; edgeNode = nil; + sourceAnchor = [[NSString alloc] initWithString:@""]; + targetAnchor = [[NSString alloc] initWithString:@""]; 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/Graph.m b/tikzit/src/common/Graph.m index 7f7345c..c8da128 100644 --- a/tikzit/src/common/Graph.m +++ b/tikzit/src/common/Graph.m @@ -726,10 +726,10 @@ [code appendFormat:@"\t\t\\draw%@ (%@%@) to %@(%@%@);\n", ([edata isEqual:@""]) ? @"" : [NSString stringWithFormat:@" %@", edata], [[e source] name], - ([[e source] style] == nil) ? @".center" : @"", + ([[e source] style] == nil) ? @".center" : ([e sourceAnchor] == @"") ? @"" : [NSString stringWithFormat:@".%@", [e sourceAnchor]], nodeStr, ([e source] == [e target]) ? @"" : [[e target] name], - ([e source] != [e target] && [[e target] style] == nil) ? @".center" : @"" + ([e source] != [e target] && [[e target] style] == nil) ? @".center" : ([e targetAnchor] == @"") ? @"" : [NSString stringWithFormat:@".%@", [e targetAnchor]] ]; } diff --git a/tikzit/src/common/TikzGraphAssembler.h b/tikzit/src/common/TikzGraphAssembler.h index 1b006dd..adaf443 100644 --- a/tikzit/src/common/TikzGraphAssembler.h +++ b/tikzit/src/common/TikzGraphAssembler.h @@ -45,7 +45,8 @@ - (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..7d8d0e7 100644 --- a/tikzit/src/common/TikzGraphAssembler.m +++ b/tikzit/src/common/TikzGraphAssembler.m @@ -37,9 +37,9 @@ static id currentAssembler = nil; void yyerror(const char *str) { NSLog(@"Parse error: %s", str); 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]; } } @@ -137,14 +137,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..9af0c8d 100644 --- a/tikzit/src/common/tikzlexer.lm +++ b/tikzit/src/common/tikzlexer.lm @@ -39,13 +39,13 @@ \\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 FULLSTOP; = return EQUALS; \\draw return DRAW; to return TO; @@ -65,7 +65,7 @@ at return AT; return REALNUMBER; } -\\?[a-zA-Z<>\-\']+ { //' +\\?[a-zA-Z<>\-\'][a-zA-Z<>\-\'0-9]* { //' yylval.nsstr=[NSString stringWithUTF8String:yytext]; return LWORD; } diff --git a/tikzit/src/common/tikzparser.ym b/tikzit/src/common/tikzparser.ym index 57f0600..532b6c8 100644 --- a/tikzit/src/common/tikzparser.ym +++ b/tikzit/src/common/tikzparser.ym @@ -39,17 +39,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 +67,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 +122,8 @@ propsym: nodecmd : NODE { [[TikzGraphAssembler currentAssembler] prepareNode]; }; +nodename: LEFTPARENTHESIS nodeid RIGHTPARENTHESIS { $$ = $<nsstr>2; }; + node: nodecmd optproperties nodename AT coords nodelabel SEMICOLON { @@ -135,8 +140,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 +161,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/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]; |