summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomguy3 <randomguy3@7c02a99a-9b00-45e3-bf44-6f3dd7fddb64>2012-03-10 13:37:44 +0000
committerrandomguy3 <randomguy3@7c02a99a-9b00-45e3-bf44-6f3dd7fddb64>2012-03-10 13:37:44 +0000
commite6636042890e1dbfc442dfa0fedd9797c7cb8eff (patch)
tree20ce19e671bdd0e43fceed86172a41724c94926f
parent0cd05a572e48b1e649ecdc8b24920c497e40466e (diff)
Make common code KVC compliant, and implement NSCopying where relevant
git-svn-id: https://tikzit.svn.sourceforge.net/svnroot/tikzit/trunk@420 7c02a99a-9b00-45e3-bf44-6f3dd7fddb64
-rw-r--r--tikzit/src/common/ColorRGB.h2
-rw-r--r--tikzit/src/common/ColorRGB.m4
-rw-r--r--tikzit/src/common/Edge.h7
-rw-r--r--tikzit/src/common/Edge.m17
-rw-r--r--tikzit/src/common/EdgeStyle.h2
-rw-r--r--tikzit/src/common/EdgeStyle.m33
-rw-r--r--tikzit/src/common/Graph.h21
-rw-r--r--tikzit/src/common/Graph.m123
-rw-r--r--tikzit/src/common/GraphElementData.m18
-rw-r--r--tikzit/src/common/Grid.h2
-rw-r--r--tikzit/src/common/Grid.m17
-rw-r--r--tikzit/src/common/Node.h8
-rw-r--r--tikzit/src/common/Node.m12
-rw-r--r--tikzit/src/common/NodeStyle.h2
-rw-r--r--tikzit/src/common/NodeStyle.m39
-rw-r--r--tikzit/src/common/PickSupport.h12
-rw-r--r--tikzit/src/common/PickSupport.m52
-rw-r--r--tikzit/src/common/Transformer.m18
18 files changed, 276 insertions, 113 deletions
diff --git a/tikzit/src/common/ColorRGB.h b/tikzit/src/common/ColorRGB.h
index 1c9b27d..412a1f6 100644
--- a/tikzit/src/common/ColorRGB.h
+++ b/tikzit/src/common/ColorRGB.h
@@ -24,7 +24,7 @@
#import <Foundation/Foundation.h>
#import "RColor.h"
-@interface ColorRGB : NSObject {
+@interface ColorRGB : NSObject<NSCopying> {
unsigned short red, green, blue;
}
diff --git a/tikzit/src/common/ColorRGB.m b/tikzit/src/common/ColorRGB.m
index b6fc2e3..673a88d 100644
--- a/tikzit/src/common/ColorRGB.m
+++ b/tikzit/src/common/ColorRGB.m
@@ -263,8 +263,8 @@ static NSMapTable *colorHash = nil;
return dr*dr + dg*dg + db*db;
}
-- (id)copy {
- ColorRGB *col = [[ColorRGB alloc] initWithRed:red green:green blue:blue];
+- (id)copyWithZone:(NSZone*)zone {
+ ColorRGB *col = [[ColorRGB allocWithZone:zone] initWithRed:red green:green blue:blue];
return col;
}
diff --git a/tikzit/src/common/Edge.h b/tikzit/src/common/Edge.h
index 43c7b76..607fcc6 100644
--- a/tikzit/src/common/Edge.h
+++ b/tikzit/src/common/Edge.h
@@ -83,6 +83,13 @@ typedef enum {
*/
@property (copy) GraphElementData *data;
+// KVC methods
+- (void) insertObject:(GraphElementProperty*)gep
+ inDataAtIndex:(NSUInteger)index;
+- (void) removeObjectFromDataAtIndex:(NSUInteger)index;
+- (void) replaceObjectInDataAtIndex:(NSUInteger)index
+ withObject:(GraphElementProperty*)gep;
+
/*!
@property style
@brief Edge style.
diff --git a/tikzit/src/common/Edge.m b/tikzit/src/common/Edge.m
index ed25333..6791354 100644
--- a/tikzit/src/common/Edge.m
+++ b/tikzit/src/common/Edge.m
@@ -372,12 +372,17 @@
#endif
}
-- (GraphElementData*)data {return data;}
-- (void)setData:(GraphElementData*)dt {
- if (data != dt) {
- [data release];
- data = [dt copy];
- }
+@synthesize data;
+- (void) insertObject:(GraphElementProperty*)gep
+ inDataAtIndex:(NSUInteger)index {
+ [data insertObject:gep atIndex:index];
+}
+- (void) removeObjectFromDataAtIndex:(NSUInteger)index {
+ [data removeObjectAtIndex:index];
+}
+- (void) replaceObjectInDataAtIndex:(NSUInteger)index
+ withObject:(GraphElementProperty*)gep {
+ [data replaceObjectAtIndex:index withObject:gep];
}
- (void)updateData {
diff --git a/tikzit/src/common/EdgeStyle.h b/tikzit/src/common/EdgeStyle.h
index 66144f4..248d8f4 100644
--- a/tikzit/src/common/EdgeStyle.h
+++ b/tikzit/src/common/EdgeStyle.h
@@ -36,7 +36,7 @@ typedef enum {
ED_Tick = 2
} EdgeDectorationStyle;
-@interface EdgeStyle : PropertyHolder {
+@interface EdgeStyle : PropertyHolder <NSCopying> {
ArrowHeadStyle headStyle, tailStyle;
EdgeDectorationStyle decorationStyle;
float thickness;
diff --git a/tikzit/src/common/EdgeStyle.m b/tikzit/src/common/EdgeStyle.m
index 5314433..a9dbc9f 100644
--- a/tikzit/src/common/EdgeStyle.m
+++ b/tikzit/src/common/EdgeStyle.m
@@ -25,14 +25,14 @@
@implementation EdgeStyle
-- (id)init {
+- (id)initWithName:(NSString*)nm {
self = [super initWithNotificationName:@"EdgeStylePropertyChanged"];
if (self != nil) {
headStyle = AH_None;
tailStyle = AH_None;
decorationStyle = ED_None;
- name = @"new";
+ name = nm;
category = nil;
thickness = 1.0f;
}
@@ -40,14 +40,26 @@
return self;
}
-- (id)initWithName:(NSString*)nm {
- self = [self init];
+- (id)init {
+ self = [self initWithName:@"new"];
+ return self;
+}
- if (self != nil) {
- [self setName:nm];
- }
+- (id)copyWithZone:(NSZone*)zone {
+ EdgeStyle *style = [[EdgeStyle allocWithZone:zone] init];
+ [style setName:[self name]];
+ [style setCategory:[self category]];
+ [style setHeadStyle:[self headStyle]];
+ [style setTailStyle:[self tailStyle]];
+ [style setDecorationStyle:[self decorationStyle]];
+ [style setThickness:[self thickness]];
+ return style;
+}
- return self;
+- (void)dealloc {
+ [name release];
+ [category release];
+ [super dealloc];
}
+ (EdgeStyle*)defaultEdgeStyleWithName:(NSString*)nm {
@@ -136,11 +148,6 @@
return buf;
}
-- (void)dealloc {
- [name release];
- [super dealloc];
-}
-
@end
// vi:ft=objc:ts=4:noet:sts=4:sw=4
diff --git a/tikzit/src/common/Graph.h b/tikzit/src/common/Graph.h
index e629464..c680219 100644
--- a/tikzit/src/common/Graph.h
+++ b/tikzit/src/common/Graph.h
@@ -44,7 +44,7 @@
Graph changes can be re-done by calling applyGraphChange. They can be undone
by calling applyGraphChange on [change inverse].
*/
-@interface Graph : NSObject {
+@interface Graph : NSObject <NSCopying> {
NSRecursiveLock *graphLock;
BOOL dirty; // keep track of when inEdges and outEdges need an update
NSMutableArray *nodes;
@@ -63,6 +63,13 @@
*/
@property (copy) GraphElementData *data;
+// KVC methods
+- (void) insertObject:(GraphElementProperty*)gep
+ inDataAtIndex:(NSUInteger)index;
+- (void) removeObjectFromDataAtIndex:(NSUInteger)index;
+- (void) replaceObjectInDataAtIndex:(NSUInteger)index
+ withObject:(GraphElementProperty*)gep;
+
/*!
@property nodes
@brief The set of nodes.
@@ -129,6 +136,14 @@
- (Graph*)copyOfSubgraphWithNodes:(NSSet*)nds;
/*!
+ @brief Gives a copy of the full subgraph with the given nodes.
+ @param nds a set of nodes.
+ @param zone an allocation zone
+ @result A subgraph.
+ */
+- (Graph*)copyOfSubgraphWithNodes:(NSSet*)nds zone:(NSZone*)zone;
+
+/*!
@brief Gives a set of edge-arrays that partition all of the edges in the graph.
@result An NSet of NSArrays of edges.
*/
@@ -313,6 +328,8 @@
*/
+ (NSMapTable*)nodeTableForNodes:(NSSet*)nds;
++ (NSMapTable*)nodeTableForNodes:(NSSet*)nds withZone:(NSZone*)zone;
+
/*!
@brief Copy the edge set and return a table of copies, whose
keys are the original edges. This is used to save the state
@@ -322,6 +339,8 @@
*/
+ (NSMapTable*)edgeTableForEdges:(NSSet*)es;
++ (NSMapTable*)edgeTableForEdges:(NSSet*)es withZone:(NSZone*)zone;
+
/*!
@brief Compute the bounds for a set of nodes.
@param nds an enumerable collection of nodes.
diff --git a/tikzit/src/common/Graph.m b/tikzit/src/common/Graph.m
index 398b562..9b20948 100644
--- a/tikzit/src/common/Graph.m
+++ b/tikzit/src/common/Graph.m
@@ -26,17 +26,36 @@
@implementation Graph
- (Graph*)init {
- [super init];
- data = [[GraphElementData alloc] init];
- boundingBox = NSMakeRect(0, 0, 0, 0);
- graphLock = [[NSRecursiveLock alloc] init];
+ self = [super init];
+ if (self != nil) {
+ data = [[GraphElementData alloc] init];
+ boundingBox = NSMakeRect(0, 0, 0, 0);
+ graphLock = [[NSRecursiveLock alloc] init];
+ nodes = [[NSMutableArray alloc] initWithCapacity:10];
+ edges = [[NSMutableArray alloc] initWithCapacity:10];
+ inEdges = nil;
+ outEdges = nil;
+ }
+ return self;
+}
+
+- (id) copyWithZone:(NSZone*)zone {
+ Graph *newGraph = [self copyOfSubgraphWithNodes:[NSSet setWithArray:nodes] zone:zone];
+ [newGraph setData:[self data]];
+ return newGraph;
+}
+
+- (void)dealloc {
[graphLock lock];
- nodes = [[NSMutableArray alloc] initWithCapacity:10];
- edges = [[NSMutableArray alloc] initWithCapacity:10];
- inEdges = nil;
- outEdges = nil;
+ [nodes release];
+ [edges release];
+ [data release];
+ [inEdges release];
+ [outEdges release];
[graphLock unlock];
- return self;
+ [graphLock release];
+
+ [super dealloc];
}
- (void)sync {
@@ -75,13 +94,23 @@
[graphLock unlock];
}
-- (NSArray*)nodes {
- return nodes;
-}
+@synthesize nodes;
+@synthesize edges;
-- (NSArray*)edges {
- return edges;
+@synthesize data;
+- (void) insertObject:(GraphElementProperty*)gep
+ inDataAtIndex:(NSUInteger)index {
+ [data insertObject:gep atIndex:index];
+}
+- (void) removeObjectFromDataAtIndex:(NSUInteger)index {
+ [data removeObjectAtIndex:index];
}
+- (void) replaceObjectInDataAtIndex:(NSUInteger)index
+ withObject:(GraphElementProperty*)gep {
+ [data replaceObjectAtIndex:index withObject:gep];
+}
+
+@synthesize boundingBox;
- (NSRect)bounds {
[graphLock lock];
@@ -90,19 +119,6 @@
return b;
}
-- (GraphElementData*)data { return data; }
-- (void)setData:(GraphElementData *)dt {
- if (data != dt) {
- [data release];
- data = [dt copy];
- }
-}
-
-- (NSRect)boundingBox { return boundingBox; }
-- (void)setBoundingBox:(NSRect)r {
- boundingBox = r;
-}
-
- (BOOL)hasBoundingBox {
return !(
boundingBox.size.width == 0 &&
@@ -504,22 +520,22 @@
}
- (Graph*)copyOfSubgraphWithNodes:(NSSet*)nds {
+ return [self copyOfSubgraphWithNodes:nds zone:NSDefaultMallocZone()];
+}
+
+- (Graph*)copyOfSubgraphWithNodes:(NSSet*)nds zone:(NSZone*)zone {
[graphLock lock];
- NSMapTable *newNds = [Graph nodeTableForNodes:nds];
- Graph* newGraph = [[Graph graph] retain];
+ NSMapTable *newNds = [Graph nodeTableForNodes:nds withZone:zone];
+ Graph* newGraph = [[Graph allocWithZone:zone] init];
- NSEnumerator *en = [newNds objectEnumerator];
- Node *nd;
- while ((nd = [en nextObject])) {
+ for (Node *nd in newNds) {
[newGraph addNode:nd];
}
- en = [edges objectEnumerator];
- Edge *e;
- while ((e = [en nextObject])) {
+ for (Edge *e in edges) {
if ([nds containsObject:[e source]] && [nds containsObject:[e target]]) {
- Edge *e1 = [e copy];
+ Edge *e1 = [e copyWithZone:zone];
[e1 setSource:[newNds objectForKey:[e source]]];
[e1 setTarget:[newNds objectForKey:[e target]]];
[newGraph addEdge:e1];
@@ -721,27 +737,21 @@
return code;
}
-- (void)dealloc {
- [graphLock lock];
- [nodes release];
- [edges release];
- [data release];
- [inEdges release];
- [outEdges release];
- [graphLock unlock];
- [graphLock release];
-
- [super dealloc];
-}
-
+ (Graph*)graph {
return [[[self alloc] init] autorelease];
}
+ (NSMapTable*)nodeTableForNodes:(NSSet*)nds {
- NSMapTable *tab = [NSMapTable mapTableWithStrongToStrongObjects];
+ return [self nodeTableForNodes:nds withZone:NSDefaultMallocZone()];
+}
+
++ (NSMapTable*)nodeTableForNodes:(NSSet*)nds withZone:(NSZone*)zone {
+ NSMapTable *tab = [[NSMapTable allocWithZone:zone]
+ initWithKeyOptions:NSMapTableStrongMemory
+ valueOptions:NSMapTableStrongMemory
+ capacity:[nds count]];
for (Node *n in nds) {
- Node *ncopy = [n copy];
+ Node *ncopy = [n copyWithZone:zone];
[tab setObject:ncopy forKey:n];
[ncopy release]; // tab should still retain ncopy.
}
@@ -749,9 +759,16 @@
}
+ (NSMapTable*)edgeTableForEdges:(NSSet*)es {
- NSMapTable *tab = [NSMapTable mapTableWithStrongToStrongObjects];
+ return [self edgeTableForEdges:es withZone:NSDefaultMallocZone()];
+}
+
++ (NSMapTable*)edgeTableForEdges:(NSSet*)es withZone:(NSZone*)zone {
+ NSMapTable *tab = [[NSMapTable allocWithZone:zone]
+ initWithKeyOptions:NSMapTableStrongMemory
+ valueOptions:NSMapTableStrongMemory
+ capacity:[es count]];
for (Edge *e in es) {
- Edge *ecopy = [e copy];
+ Edge *ecopy = [e copyWithZone:zone];
[tab setObject:ecopy forKey:e];
[ecopy release]; // tab should still retain ecopy.
}
diff --git a/tikzit/src/common/GraphElementData.m b/tikzit/src/common/GraphElementData.m
index c05cb4b..7506941 100644
--- a/tikzit/src/common/GraphElementData.m
+++ b/tikzit/src/common/GraphElementData.m
@@ -39,6 +39,12 @@
- (id)objectAtIndex:(NSUInteger)index {
return [properties objectAtIndex:index];
}
+- (NSArray*)objectsAtIndexes:(NSIndexSet*)indexes {
+ return [properties objectsAtIndexes:indexes];
+}
+- (void) getObjects:(id*)buffer range:(NSRange)range {
+ [properties getObjects:buffer range:range];
+}
- (void)insertObject:(id)anObject atIndex:(NSUInteger)index {
[properties insertObject:anObject atIndex:index];
}
@@ -121,13 +127,11 @@
- (id)copyWithZone:(NSZone *)zone {
GraphElementData *cp = [[GraphElementData allocWithZone:zone] init];
- NSEnumerator *en = [properties objectEnumerator];
- GraphElementProperty *p, *p2;
- while ((p = [en nextObject]) != nil) {
- p2 = [p copy];
- [cp addObject:p2];
- [p2 release];
- }
+ for (GraphElementProperty *p in properties) {
+ GraphElementProperty *p2 = [p copy];
+ [cp addObject:p2];
+ [p2 release];
+ }
return cp;
}
diff --git a/tikzit/src/common/Grid.h b/tikzit/src/common/Grid.h
index 40bb91e..b267536 100644
--- a/tikzit/src/common/Grid.h
+++ b/tikzit/src/common/Grid.h
@@ -25,7 +25,7 @@
* The grid is divided into cells, and each cell is further subdivided.
* These subdivisions are the snap points for the grid.
*/
-@interface Grid: NSObject {
+@interface Grid: NSObject <NSCopying> {
Transformer *transformer;
float spacing;
int cellSubdivisions;
diff --git a/tikzit/src/common/Grid.m b/tikzit/src/common/Grid.m
index 4fb2ef8..f597a4a 100644
--- a/tikzit/src/common/Grid.m
+++ b/tikzit/src/common/Grid.m
@@ -37,6 +37,18 @@
return self;
}
+- (id) copyWithZone:(NSZone*)zone {
+ return [[Grid allocWithZone:zone]
+ initWithSpacing:spacing
+ subdivisions:cellSubdivisions
+ transformer:transformer];
+}
+
+- (void) dealloc {
+ [transformer release];
+ [super dealloc];
+}
+
- (int) cellSubdivisions {
return cellSubdivisions;
}
@@ -169,11 +181,6 @@
[context restoreState];
}
-- (void) dealloc {
- [transformer release];
- [super dealloc];
-}
-
@end
// vi:ft=objc:ts=4:noet:sts=4:sw=4
diff --git a/tikzit/src/common/Node.h b/tikzit/src/common/Node.h
index 844af83..e2d4520 100644
--- a/tikzit/src/common/Node.h
+++ b/tikzit/src/common/Node.h
@@ -29,6 +29,7 @@
#import "NodeStyle.h"
#import "GraphElementData.h"
+@class GraphElementProperty;
@class Shape;
@class Transformer;
@@ -83,6 +84,13 @@
*/
@property (copy) GraphElementData *data;
+// KVC methods
+- (void) insertObject:(GraphElementProperty*)gep
+ inDataAtIndex:(NSUInteger)index;
+- (void) removeObjectFromDataAtIndex:(NSUInteger)index;
+- (void) replaceObjectInDataAtIndex:(NSUInteger)index
+ withObject:(GraphElementProperty*)gep;
+
/*!
@brief Initialize a new node with the given point.
@param p a point.
diff --git a/tikzit/src/common/Node.m b/tikzit/src/common/Node.m
index 39b1e75..d4da82b 100644
--- a/tikzit/src/common/Node.m
+++ b/tikzit/src/common/Node.m
@@ -145,7 +145,19 @@
@synthesize name;
@synthesize label;
@synthesize point;
+
@synthesize data;
+- (void) insertObject:(GraphElementProperty*)gep
+ inDataAtIndex:(NSUInteger)index {
+ [data insertObject:gep atIndex:index];
+}
+- (void) removeObjectFromDataAtIndex:(NSUInteger)index {
+ [data removeObjectAtIndex:index];
+}
+- (void) replaceObjectInDataAtIndex:(NSUInteger)index
+ withObject:(GraphElementProperty*)gep {
+ [data replaceObjectAtIndex:index withObject:gep];
+}
- (NodeStyle*)style {
return style;
diff --git a/tikzit/src/common/NodeStyle.h b/tikzit/src/common/NodeStyle.h
index eed5b32..a78abaa 100644
--- a/tikzit/src/common/NodeStyle.h
+++ b/tikzit/src/common/NodeStyle.h
@@ -34,7 +34,7 @@
which should be implemented in a platform-specific category. For
OS X, this is NodeStyle+Coder.
*/
-@interface NodeStyle : PropertyHolder {
+@interface NodeStyle : PropertyHolder <NSCopying> {
int strokeThickness;
float scale;
ColorRGB *strokeColorRGB;
diff --git a/tikzit/src/common/NodeStyle.m b/tikzit/src/common/NodeStyle.m
index b3d9ab2..8d8b83f 100644
--- a/tikzit/src/common/NodeStyle.m
+++ b/tikzit/src/common/NodeStyle.m
@@ -28,7 +28,7 @@
+ (int) defaultStrokeThickness { return 1; }
-- (id)init {
+- (id)initWithName:(NSString*)nm {
self = [super initWithNotificationName:@"NodeStylePropertyChanged"];
if (self != nil) {
strokeThickness = [NodeStyle defaultStrokeThickness];
@@ -36,21 +36,41 @@
strokeColorRGB = [[ColorRGB alloc] initWithRed:0 green:0 blue:0];
fillColorRGB = [[ColorRGB alloc] initWithRed:255 green:255 blue:255];
- name = @"new";
+ name = nm;
category = nil;
shapeName = SHAPE_CIRCLE;
}
return self;
}
-- (id)initWithName:(NSString*)nm {
- self = [self init];
- if (self != nil) {
- [self setName:nm];
- }
+- (id)init {
+ self = [self initWithName:@"new"];
return self;
}
+- (id)copyWithZone:(NSZone*)zone {
+ NodeStyle *style = [[NodeStyle allocWithZone:zone] init];
+
+ [style setStrokeThickness:[self strokeThickness]];
+ [style setScale:[self scale]];
+ [style setStrokeColorRGB:[self strokeColorRGB]];
+ [style setFillColorRGB:[self fillColorRGB]];
+ [style setName:[self name]];
+ [style setShapeName:[self shapeName]];
+ [style setCategory:[self category]];
+
+ return style;
+}
+
+- (void)dealloc {
+ [name release];
+ [category release];
+ [shapeName release];
+ [strokeColorRGB release];
+ [fillColorRGB release];
+ [super dealloc];
+}
+
+ (NodeStyle*)defaultNodeStyleWithName:(NSString*)nm {
return [[[NodeStyle alloc] initWithName:nm] autorelease];
}
@@ -164,11 +184,6 @@
return ([fillColorRGB name] != nil);
}
-- (void)dealloc {
- [self setName:nil];
- [super dealloc];
-}
-
@end
// vi:ft=objc:ts=4:noet:sts=4:sw=4
diff --git a/tikzit/src/common/PickSupport.h b/tikzit/src/common/PickSupport.h
index 8e71325..0749649 100644
--- a/tikzit/src/common/PickSupport.h
+++ b/tikzit/src/common/PickSupport.h
@@ -45,12 +45,24 @@
*/
@property (readonly) NSSet *selectedNodes;
+// KVC methods
+- (void)addSelectedNodesObject:(Node*)node;
+- (void)addSelectedNodes:(NSSet*)nodes;
+- (void)removeSelectedNodesObject:(Node*)node;
+- (void)removeSelectedNodes:(NSSet*)nodes;
+
/*!
@property selectedEdges
@brief A set of selected edges.
*/
@property (readonly) NSSet *selectedEdges;
+// KVC methods
+- (void)addSelectedEdgesObject:(Edge*)edge;
+- (void)addSelectedEdges:(NSSet*)edges;
+- (void)removeSelectedEdgesObject:(Edge*)edge;
+- (void)removeSelectedEdges:(NSSet*)edges;
+
/*!
@brief Check if a node is selected.
@param nd a node.
diff --git a/tikzit/src/common/PickSupport.m b/tikzit/src/common/PickSupport.m
index 5ea13c0..6470214 100644
--- a/tikzit/src/common/PickSupport.m
+++ b/tikzit/src/common/PickSupport.m
@@ -53,8 +53,56 @@
return [[[PickSupport alloc] init] autorelease];
}
-- (NSSet*)selectedNodes { return selectedNodes; }
-- (NSSet*)selectedEdges { return selectedEdges; }
+@synthesize selectedNodes;
+- (void)addSelectedNodesObject:(Node*)node {
+ return [self selectNode:node];
+}
+- (void)addSelectedNodes:(NSSet*)nodes {
+ return [self selectAllNodes:nodes replacingSelection:NO];
+}
+- (void)removeSelectedNodesObject:(Node*)node {
+ return [self deselectNode:node];
+}
+- (void)removeSelectedNodes:(NSSet*)nodes {
+ if ([selectedNodes count] > 0) {
+ [selectedNodes minusSet:nodes];
+ [[NSNotificationCenter defaultCenter]
+ postNotificationName:@"NodeSelectionReplaced"
+ object:self];
+ [self postNodeSelectionChanged];
+ }
+}
+
+@synthesize selectedEdges;
+- (void)addSelectedEdgesObject:(Edge*)edge {
+ return [self selectEdge:edge];
+}
+- (void)addSelectedEdges:(NSSet*)edges {
+ if (selectedEdges == edges) {
+ return;
+ }
+ if ([edges count] == 0) {
+ return;
+ }
+
+ [selectedEdges unionSet:edges];
+ [[NSNotificationCenter defaultCenter]
+ postNotificationName:@"EdgeSelectionReplaced"
+ object:self];
+ [self postEdgeSelectionChanged];
+}
+- (void)removeSelectedEdgesObject:(Edge*)edge {
+ return [self deselectEdge:edge];
+}
+- (void)removeSelectedEdges:(NSSet*)edges {
+ if ([selectedEdges count] > 0 && [edges count] > 0) {
+ [selectedEdges minusSet:edges];
+ [[NSNotificationCenter defaultCenter]
+ postNotificationName:@"EdgeSelectionReplaced"
+ object:self];
+ [self postEdgeSelectionChanged];
+ }
+}
- (BOOL)isNodeSelected:(Node*)nd {
return [selectedNodes containsObject:nd];
diff --git a/tikzit/src/common/Transformer.m b/tikzit/src/common/Transformer.m
index fe4d135..403ae87 100644
--- a/tikzit/src/common/Transformer.m
+++ b/tikzit/src/common/Transformer.m
@@ -107,6 +107,16 @@ float const PIXELS_PER_UNIT = 50;
return self;
}
+- (id)copyWithZone:(NSZone *)zone {
+ Transformer *cp = [[[self class] allocWithZone:zone] init];
+ if (cp) {
+ cp->origin = origin;
+ cp->x_scale = x_scale;
+ cp->y_scale = y_scale;
+ }
+ return cp;
+}
+
- (NSPoint)origin { return origin; }
- (void)setOrigin:(NSPoint)o {
origin = o;
@@ -191,14 +201,6 @@ float const PIXELS_PER_UNIT = 50;
return r1;
}
-- (id)copyWithZone:(NSZone *)zone {
- Transformer *cp = [[[self class] allocWithZone:zone] init];
- cp->origin = origin;
- cp->x_scale = x_scale;
- cp->y_scale = y_scale;
- return cp;
-}
-
- (BOOL)isEqual:(id)object {
Transformer *t = (Transformer*)object;
return ([t origin].x == [self origin].x &&