From 8b4c46a01eab8f390ff4ab8ec5b78d8055ff4f34 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 8 Oct 2010 19:57:21 +0000 Subject: =?UTF-8?q?=E2=80=A2=20some=20further=20work=20on=20displaying=20g?= =?UTF-8?q?eometry=20fields=20as=20image=20-=20to=20enable=20the=20very=20?= =?UTF-8?q?first=20approach=20simply=20uncomment=20code=20in=20SPTableCont?= =?UTF-8?q?ent=20tableView:toolTipForCell:rect:tableColumn:row:mouseLocati?= =?UTF-8?q?on:=20for=20MCPGeometryData=20class?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPGeometryDataView.h | 16 ++++++- Source/SPGeometryDataView.m | 114 +++++++++++++++++++++++++++++++++++++++++++- Source/SPTableContent.m | 10 +++- 3 files changed, 136 insertions(+), 4 deletions(-) (limited to 'Source') diff --git a/Source/SPGeometryDataView.h b/Source/SPGeometryDataView.h index a2a620bb..3ff72110 100644 --- a/Source/SPGeometryDataView.h +++ b/Source/SPGeometryDataView.h @@ -27,7 +27,21 @@ @interface SPGeometryDataView : NSView { - + NSString *type; + NSArray *coordinates; + double x_min; + double x_max; + double y_min; + double y_max; + double width; + double height; + double zoom_factor; + double margin_offset; } +- (id)initWithCoordinates:(NSDictionary*)coord; +- (void)setMax:(NSArray*)bbox; +- (NSPoint)normalizePoint:(NSPoint)aPoint; +- (NSImage*)image; + @end diff --git a/Source/SPGeometryDataView.m b/Source/SPGeometryDataView.m index 8cfaf767..45d9632b 100644 --- a/Source/SPGeometryDataView.m +++ b/Source/SPGeometryDataView.m @@ -30,15 +30,125 @@ /** * Initialize SPGeometryDataView object */ -- (id)initWithFrame:(NSRect)frame +- (id)initWithCoordinates:(NSDictionary*)coord { - if ( self = [super initWithFrame:frame] ) + + margin_offset = 5.0; + + type = [coord objectForKey:@"type"]; + coordinates = [coord objectForKey:@"coordinates"]; + x_min = [[[coord objectForKey:@"bbox"] objectAtIndex:0] doubleValue] - margin_offset; + x_max = [[[coord objectForKey:@"bbox"] objectAtIndex:1] doubleValue] + margin_offset; + y_min = [[[coord objectForKey:@"bbox"] objectAtIndex:2] doubleValue] - margin_offset; + y_max = [[[coord objectForKey:@"bbox"] objectAtIndex:3] doubleValue] + margin_offset; + + zoom_factor = 1.0; + + width = x_max - x_min; + height = y_max - y_min; + + + if ( self = [super initWithFrame:NSMakeRect(0,0,width,height)] ) { ; } return self; } +- (NSPoint)normalizePoint:(NSPoint)aPoint +{ + return aPoint; +} + +- (void)drawRect:(NSRect)dirtyRect +{ + + if(!type || ![type length] || !coordinates || ![coordinates count]) return; + + NSBezierPath *path, *circlePath; + NSColor *polyFillColor = [NSColor colorWithCalibratedRed:.5 green:.5 blue:0.5 alpha:0.05]; + BOOL isFirst = YES; + + NSPoint aPoint; + + path = [NSBezierPath bezierPathWithRect:[self bounds]]; + [path setLineWidth:0.1]; + [[NSColor whiteColor] set]; + [path fill]; + [[NSColor grayColor] set]; + [path stroke]; + + path = [NSBezierPath bezierPath]; + [[NSColor blackColor] set]; + [path setLineWidth:1]; + + if ([type isEqualToString:@"POINT"]) { + circlePath = [NSBezierPath bezierPath]; + [circlePath appendBezierPathWithOvalInRect:NSMakeRect(width/2-2,height/2-2,4,4)]; + [[NSColor grayColor] setStroke]; + [[NSColor redColor] setFill]; + [circlePath stroke]; + [circlePath fill]; + } + else if([type isEqualToString:@"LINESTRING"]) { + + for(NSString* coord in coordinates) { + aPoint = [self normalizePoint:NSPointFromString(coord)]; + if(isFirst) { + [path moveToPoint:aPoint]; + isFirst = NO; + } else { + [path lineToPoint:aPoint]; + } + circlePath = [NSBezierPath bezierPath]; + [circlePath appendBezierPathWithOvalInRect:NSMakeRect(aPoint.x-2,aPoint.y-2,4,4)]; + [[NSColor grayColor] setStroke]; + [[NSColor redColor] setFill]; + [circlePath stroke]; + [circlePath fill]; + } + [[NSColor blackColor] setStroke]; + [path stroke]; + + } + else if([type isEqualToString:@"POLYGON"]) { + for(NSArray* polygon in coordinates) { + isFirst = YES; + for(NSString* coord in polygon) { + aPoint = [self normalizePoint:NSPointFromString(coord)]; + if(isFirst) { + [path moveToPoint:aPoint]; + isFirst = NO; + } else { + [path lineToPoint:aPoint]; + } + circlePath = [NSBezierPath bezierPath]; + [circlePath appendBezierPathWithOvalInRect:NSMakeRect(aPoint.x-2,aPoint.y-2,4,4)]; + [[NSColor grayColor] setStroke]; + [[NSColor redColor] setFill]; + [circlePath stroke]; + [circlePath fill]; + } + [[NSColor blackColor] setStroke]; + [polyFillColor setFill]; + [path fill]; + [path stroke]; + } + + } +} + +- (NSImage*)image +{ + + [self drawRect:[self bounds]]; + + NSImage *image = [[[NSImage alloc] initWithSize:[self bounds].size] autorelease]; + NSBitmapImageRep *bitmap = [[[NSBitmapImageRep alloc] initWithFocusedViewRect:[self bounds]] autorelease]; + [image addRepresentation:bitmap]; + return image; +} + /** * dealloc */ diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m index 50ce0617..3aa154a7 100644 --- a/Source/SPTableContent.m +++ b/Source/SPTableContent.m @@ -51,6 +51,7 @@ #import "SPAlertSheets.h" #import "SPMainThreadTrampoline.h" #import "SPHistoryController.h" +#import "SPGeometryDataView.h" @implementation SPTableContent @@ -3349,7 +3350,14 @@ } } else if ([theValue isKindOfClass:[MCPGeometryData class]]) { - ; // TODO + // SPGeometryDataView *v = [[SPGeometryDataView alloc] initWithCoordinates:[theValue coordinates]]; + // image = [v image]; + // if(image) { + // [SPTooltip showWithObject:image atLocation:pos ofType:@"image"]; + // [v release]; + // return nil; + // } + // [v release]; } // Show the cell string value as tooltip (including line breaks and tabs) -- cgit v1.2.3