From a8a8dfb90d6a51ae369c042c95162f45754c7c4b Mon Sep 17 00:00:00 2001 From: randomguy3 Date: Mon, 9 Jan 2012 11:00:50 +0000 Subject: Move tikzit into "trunk" directory git-svn-id: https://tikzit.svn.sourceforge.net/svnroot/tikzit/trunk@365 7c02a99a-9b00-45e3-bf44-6f3dd7fddb64 --- tikzit/src/common/Node.m | 173 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 tikzit/src/common/Node.m (limited to 'tikzit/src/common/Node.m') diff --git a/tikzit/src/common/Node.m b/tikzit/src/common/Node.m new file mode 100644 index 0000000..3421325 --- /dev/null +++ b/tikzit/src/common/Node.m @@ -0,0 +1,173 @@ +// +// Node.m +// TikZiT +// +// Copyright 2010 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 . +// + +#import "Node.h" + + +@implementation Node + +- (id)initWithPoint:(NSPoint)p { + [super init]; + data = [[GraphElementData alloc] init]; + style = nil; + label = @""; + point = p; + //[self updateData]; + return self; +} + +- (id)init { + [self initWithPoint:NSMakePoint(0.0f, 0.0f)]; + return self; +} + +- (BOOL)attachStyleFromTable:(NSArray*)styles { + NSString *style_name = [[[data propertyForKey:@"style"] retain] autorelease]; + + [self setStyle:nil]; + + // 'none' is a reserved style + if (style_name == nil || [style_name isEqualToString:@"none"]) return YES; + + for (NodeStyle *s in styles) { + if ([[s name] compare:style_name]==NSOrderedSame) { + [self setStyle:s]; + return YES; + } + } + + // if we didn't find a style, fill in a default one + [self setStyle:[NodeStyle defaultNodeStyleWithName:style_name]]; + return NO; +} + +- (void)updateData { + if (style == nil) { + [data setProperty:@"none" forKey:@"style"]; + } else { + [data setProperty:[style name] forKey:@"style"]; + } +} + +- (void)setPropertiesFromNode:(Node*)nd { + [self setPoint:[nd point]]; + [self setStyle:[nd style]]; + [self setName:[nd name]]; + [self setData:[nd data]]; + [self setLabel:[nd label]]; +} + +- (id)copy { + Node *cp = [[Node alloc] init]; + [cp setPropertiesFromNode:self]; + return cp; +} + ++ (Node*)nodeWithPoint:(NSPoint)p { + return [[[Node alloc] initWithPoint:p] autorelease]; +} + ++ (Node*)node { + return [[[Node alloc] init] autorelease]; +} + + +// perform a lexicographic ordering (-y, x) on coordinates. +- (NSComparisonResult)compareTo:(id)nd { + Node *node = (Node*)nd; + if (point.y > [node point].y) return NSOrderedAscending; + else if (point.y < [node point].y) return NSOrderedDescending; + else { + if (point.x < [node point].x) return NSOrderedAscending; + else if (point.x > [node point].x) return NSOrderedDescending; + else return NSOrderedSame; + } +} + + +- (NSString*)name { + return name; +} + +- (void)setName:(NSString *)s { + if (name != s) { + [name release]; + name = [s copy]; + } +} + +- (NSString*)label { + return label; +} + +- (void)setLabel:(NSString *)s { + if (label != s) { + [label release]; + label = [s copy]; + } +} + +- (GraphElementData*)data { + return data; +} + +- (void)setData:(GraphElementData*)dt { + if (data != dt) { + [data release]; + data = [dt copy]; + } +} + +- (NSPoint)point { + return point; +} + +- (void)setPoint:(NSPoint)value { + point = value; +} + +- (NodeStyle*)style { + return style; +} + +- (void)setStyle:(NodeStyle *)st { + NodeStyle *oldStyle = style; + style = [st retain]; + [oldStyle release]; + [self updateData]; +} + +- (void)dealloc { + [self setName:nil]; + [self setStyle:nil]; + [self setData:nil]; + [super dealloc]; +} + +- (id)copyWithZone:(NSZone*)z { + return nil; +} + +@end + +// vi:ft=objc:ts=4:noet:sts=4:sw=4 -- cgit v1.2.3