From e707060efcf1cb751b7f1a0e26051bc6b93b123f Mon Sep 17 00:00:00 2001 From: Alex Merry Date: Sun, 25 Aug 2013 20:34:38 +0100 Subject: Recalculate edge properties when shapes are refreshed Shape sizes can change (if you're actively editing a shape), which can mean that some edge properties need to be recalculated. We do this at the graph, rather than edge, level to avoid the overhead of installing a notification for every single edge. --- tikzit/src/common/Edge.h | 5 +++++ tikzit/src/common/Edge.m | 4 ++++ tikzit/src/common/Graph.m | 20 ++++++++++++++++++++ 3 files changed, 29 insertions(+) (limited to 'tikzit') diff --git a/tikzit/src/common/Edge.h b/tikzit/src/common/Edge.h index 64da138..accf38c 100644 --- a/tikzit/src/common/Edge.h +++ b/tikzit/src/common/Edge.h @@ -273,6 +273,11 @@ typedef enum { */ - (id)initWithSource:(Node*)s andTarget:(Node*)t; +/*! + @brief Force the recalculation of the derived properties. + */ +- (void)recalculateProperties; + /*! @brief Recompute the control points and midpoint. */ diff --git a/tikzit/src/common/Edge.m b/tikzit/src/common/Edge.m index ea20d2a..ba80aef 100644 --- a/tikzit/src/common/Edge.m +++ b/tikzit/src/common/Edge.m @@ -127,6 +127,10 @@ return NSMakePoint (pt.x + dx, pt.y + dy); } +- (void)recalculateProperties { + dirty = YES; +} + - (void)updateControls { // check for external modification to the node locations if (src.x != [source point].x || src.y != [source point].y || diff --git a/tikzit/src/common/Graph.m b/tikzit/src/common/Graph.m index 33a81f6..258ece4 100644 --- a/tikzit/src/common/Graph.m +++ b/tikzit/src/common/Graph.m @@ -23,6 +23,11 @@ #import "Graph.h" #import "TikzGraphAssembler.h" +#import "Shape.h" + +@interface Graph (Private) +- (void) shapeDictionaryReplaced:(NSNotification*)notification; +@end @implementation Graph @@ -36,6 +41,11 @@ edges = [[NSMutableArray alloc] initWithCapacity:10]; inEdges = nil; outEdges = nil; + [[NSNotificationCenter defaultCenter] + addObserver:self + selector:@selector(shapeDictionaryReplaced:) + name:@"ShapeDictionaryReplaced" + object:[Shape class]]; } return self; } @@ -56,6 +66,8 @@ } - (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; + [graphLock lock]; [inEdges release]; [outEdges release]; @@ -837,4 +849,12 @@ @end +@implementation Graph (Private) +- (void) shapeDictionaryReplaced:(NSNotification*)notification { + for (Edge *e in edges) { + [e recalculateProperties]; + } +} +@end + // vi:ft=objc:ts=4:noet:sts=4:sw=4 -- cgit v1.2.3