summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Merry <alex.merry@cs.ox.ac.uk>2012-05-23 17:39:58 +0100
committerAlex Merry <alex.merry@cs.ox.ac.uk>2012-05-23 17:39:58 +0100
commit5dcbea7d268bf1be9548226665bce6a24e2e9d55 (patch)
treea317534bb0682eb53621c2a163bb776a2851b7c7
parent33a1af9afed49f43f3577acb213ab0469035730f (diff)
Start fixing shapes in the preamble
RegularPolyShape needs fixing still, and the tikz shapes need sorting out.
-rw-r--r--tikzit/src/Makefile.am1
-rw-r--r--tikzit/src/common/CircleShape.m2
-rw-r--r--tikzit/src/common/DiamondShape.h34
-rw-r--r--tikzit/src/common/DiamondShape.m63
-rw-r--r--tikzit/src/common/NodeStyle.m6
-rw-r--r--tikzit/src/common/Preambles.m1
-rw-r--r--tikzit/src/common/RectangleShape.m2
-rw-r--r--tikzit/src/common/RegularPolyShape.m8
-rw-r--r--tikzit/src/common/Shape.h15
-rw-r--r--tikzit/src/common/Shape.m12
10 files changed, 136 insertions, 8 deletions
diff --git a/tikzit/src/Makefile.am b/tikzit/src/Makefile.am
index 29b4cb6..3a32f8d 100644
--- a/tikzit/src/Makefile.am
+++ b/tikzit/src/Makefile.am
@@ -64,6 +64,7 @@ tikzit_SOURCES = gtk/CairoRenderContext.m \
gtk/main.m \
common/CircleShape.m \
common/ColorRGB.m \
+ common/DiamondShape.m \
common/Edge.m \
common/EdgeStyle.m \
common/GraphChange.m \
diff --git a/tikzit/src/common/CircleShape.m b/tikzit/src/common/CircleShape.m
index b154e8f..954cff2 100644
--- a/tikzit/src/common/CircleShape.m
+++ b/tikzit/src/common/CircleShape.m
@@ -45,6 +45,8 @@
e3 = [Edge edgeWithSource:n3 andTarget:n0]; [e3 setBend:-45];
paths = [[NSSet alloc] initWithObjects:[NSArray arrayWithObjects:e0,e1,e2,e3,nil],nil];
+
+ styleTikz = @"circle";
return self;
}
diff --git a/tikzit/src/common/DiamondShape.h b/tikzit/src/common/DiamondShape.h
new file mode 100644
index 0000000..da5932e
--- /dev/null
+++ b/tikzit/src/common/DiamondShape.h
@@ -0,0 +1,34 @@
+//
+// RectangleShape.h
+// TikZiT
+//
+// Copyright 2012 Alex Merry
+// 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>
+#import "Shape.h"
+
+@interface DiamondShape : Shape {
+}
+
+@end
+
+// vi:ft=objc:noet:ts=4:sts=4:sw=4
+
diff --git a/tikzit/src/common/DiamondShape.m b/tikzit/src/common/DiamondShape.m
new file mode 100644
index 0000000..580bea9
--- /dev/null
+++ b/tikzit/src/common/DiamondShape.m
@@ -0,0 +1,63 @@
+//
+// RectangleShape.m
+// TikZiT
+//
+// Copyright 2011 Aleks Kissinger
+// Copyright 2012 Alex Merry
+// 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 "DiamondShape.h"
+
+#import "Node.h"
+#import "Edge.h"
+
+@implementation DiamondShape
+
+- (id)init {
+ self = [super init];
+
+ if (!self)
+ return nil;
+
+ Node *n0,*n1,*n2,*n3;
+ float sz = 0.25f;
+
+ n0 = [Node nodeWithPoint:NSMakePoint(0, sz)];
+ n1 = [Node nodeWithPoint:NSMakePoint(sz, 0)];
+ n2 = [Node nodeWithPoint:NSMakePoint(0,-sz)];
+ n3 = [Node nodeWithPoint:NSMakePoint(-sz,0)];
+
+ Edge *e0,*e1,*e2,*e3;
+
+ e0 = [Edge edgeWithSource:n0 andTarget:n1];
+ e1 = [Edge edgeWithSource:n1 andTarget:n2];
+ e2 = [Edge edgeWithSource:n2 andTarget:n3];
+ e3 = [Edge edgeWithSource:n3 andTarget:n0];
+
+ paths = [[NSSet alloc] initWithObjects:[NSArray arrayWithObjects:e0,e1,e2,e3,nil],nil];
+
+ styleTikz = @"shape=diamond";
+
+ return self;
+}
+
+@end
+
+// vi:ft=objc:ts=4:noet:sts=4:sw=4
diff --git a/tikzit/src/common/NodeStyle.m b/tikzit/src/common/NodeStyle.m
index 0794b6a..268715b 100644
--- a/tikzit/src/common/NodeStyle.m
+++ b/tikzit/src/common/NodeStyle.m
@@ -22,6 +22,7 @@
//
#import "NodeStyle.h"
+#import "Shape.h"
#import "ShapeNames.h"
@implementation NodeStyle
@@ -191,9 +192,12 @@
if (fillName == nil) fillName = [fillColorRGB hexName];
if (strokeName == nil) strokeName = [strokeColorRGB hexName];
+ NSString *shapeDesc = [[Shape shapeForName:shapeName] styleTikz];
+ if (shapeDesc == nil) shapeDesc = shapeName;
+
return [NSString stringWithFormat:@"\\tikzstyle{%@}=[%@,fill=%@,draw=%@%@]",
name,
- shapeName,
+ shapeDesc,
fillName,
strokeName,
stroke];
diff --git a/tikzit/src/common/Preambles.m b/tikzit/src/common/Preambles.m
index e107d5e..af3bbc4 100644
--- a/tikzit/src/common/Preambles.m
+++ b/tikzit/src/common/Preambles.m
@@ -30,6 +30,7 @@ static NSString *PREAMBLE_HEAD =
@"\\usepackage[svgnames]{xcolor}\n"
@"\\usepackage{tikz}\n"
@"\\usetikzlibrary{decorations.markings}\n"
+@"\\usetikzlibrary{shapes.geometric}\n"
@"\\pagestyle{empty}\n"
@"\n"
@"\\pgfdeclarelayer{edgelayer}\n"
diff --git a/tikzit/src/common/RectangleShape.m b/tikzit/src/common/RectangleShape.m
index 0b3baa0..e332d40 100644
--- a/tikzit/src/common/RectangleShape.m
+++ b/tikzit/src/common/RectangleShape.m
@@ -45,6 +45,8 @@
e3 = [Edge edgeWithSource:n3 andTarget:n0];
paths = [[NSSet alloc] initWithObjects:[NSArray arrayWithObjects:e0,e1,e2,e3,nil],nil];
+
+ styleTikz = @"rectangle";
return self;
}
diff --git a/tikzit/src/common/RegularPolyShape.m b/tikzit/src/common/RegularPolyShape.m
index cd5858c..e5aac7a 100644
--- a/tikzit/src/common/RegularPolyShape.m
+++ b/tikzit/src/common/RegularPolyShape.m
@@ -60,8 +60,14 @@
[edges addObject:[Edge edgeWithSource:[nodes objectAtIndex:i]
andTarget:[nodes objectAtIndex:(i+1)%sides]]];
}
-
+
paths = [[NSSet alloc] initWithObjects:edges,nil];
+
+ int degRot = (int)radiansToDegrees(rotation);
+ styleTikz = [[NSString alloc] initWithFormat:
+ @"regular polygon,regular polygon sides=%d,shape border rotate=%d",
+ sides, degRot];
+
return self;
}
diff --git a/tikzit/src/common/Shape.h b/tikzit/src/common/Shape.h
index 194a88b..b401a87 100644
--- a/tikzit/src/common/Shape.h
+++ b/tikzit/src/common/Shape.h
@@ -25,12 +25,19 @@
#import "Transformer.h"
@interface Shape : NSObject <NSCopying> {
- NSSet *paths;
- NSRect boundingRect; // cache
+ NSSet *paths;
+ NSRect boundingRect; // cache
+ NSString *styleTikz;
}
-@property (retain) NSSet *paths;
-@property (readonly) NSRect boundingRect;
+@property (retain) NSSet *paths;
+@property (readonly) NSRect boundingRect;
+/**
+ * The tikz code to use in style properties for this shape
+ *
+ * This can return nil, in which case the shape name should be used
+ */
+@property (retain) NSString *styleTikz;
- (id)init;
+ (void)refreshShapeDictionary;
diff --git a/tikzit/src/common/Shape.m b/tikzit/src/common/Shape.m
index 8714031..b74a9fc 100644
--- a/tikzit/src/common/Shape.m
+++ b/tikzit/src/common/Shape.m
@@ -21,14 +21,18 @@
// along with TikZiT. If not, see <http://www.gnu.org/licenses/>.
//
-#import "Edge.h"
#import "Shape.h"
+
+#import "Edge.h"
#import "SupportDir.h"
#import "ShapeNames.h"
+
#import "CircleShape.h"
+#import "DiamondShape.h"
#import "RectangleShape.h"
#import "RegularPolyShape.h"
#import "TikzShape.h"
+
#import "util.h"
@implementation Shape
@@ -63,14 +67,18 @@
- (NSRect)boundingRect { return boundingRect; }
+@synthesize styleTikz;
+
- (id)copyWithZone:(NSZone*)zone {
Shape *cp = [[[self class] allocWithZone:zone] init];
[cp setPaths:paths];
+ [cp setStyleTikz:styleTikz];
return cp;
}
- (void)dealloc {
[paths release];
+ [styleTikz release];
[super dealloc];
}
@@ -101,7 +109,7 @@ NSDictionary *shapeDictionary = nil;
Shape *shapes[5] = {
[[CircleShape alloc] init],
[[RectangleShape alloc] init],
- [[RegularPolyShape alloc] initWithSides:4 rotation:(M_PI/2.0f)],
+ [[DiamondShape alloc] init],
[[RegularPolyShape alloc] initWithSides:3 rotation:(M_PI/2.0f)],
[[RegularPolyShape alloc] initWithSides:3 rotation:(-M_PI/2.0f)]};
NSMutableDictionary *shapeDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys: