//  Created by Joe Becker on 3/7/05.
//  Copyright 2005 __MyCompanyName__. All rights reserved.

#import "Segment.h"

@implementation Segment

- initFrom:(NSPoint)theStart to:(NSPoint)theEnd view:(id)theView record:(GmtShipTrackRecord *)obj
{
	[super init];         // Init the NSObject superclass!
	
	start = theStart;
	end   = theEnd;
	center= NSMakePoint((start.x+end.x)/2.0, (start.y+end.y)/2.0);

	color = [ [NSColor blackColor] retain];
	lineType = SOLID_LINE;
	view = theView;
	shipTrackRecord = obj;
	return self;
}

- (void)dealloc
{
	[color release];  // Release what you retain
	[super dealloc];  //  and dealloc the super class.
}

// Accessor methods
- (int)tag { return tag; }
- (void)setTag:(int)aTag { tag = aTag; }

- (void)setColor:(NSColor *)aColor
{
	[color release];
	color = [aColor retain];
}

- (NSColor *)color
{
	return color;
}

- (void)setLineType:(int)aType
{
	lineType = aType;
}

- (int)lineType
{
	return lineType;
}

- (GmtShipTrackRecord *)shipTrackRecord { return shipTrackRecord; }
- (void)setShipTrackRecord:(GmtShipTrackRecord *)aShipTrackRecord {	shipTrackRecord = aShipTrackRecord; }

// Methods that derive information for the caller

- (NSRect)bounds
{
	const float sloppyCoding = 0.01;
	
	return NSMakeRect( MIN(start.x,end.x)  - sloppyCoding, 
					   MIN(start.y,end.y)  - sloppyCoding, 
					   fabs(start.x-end.x) + sloppyCoding, 
					   fabs(start.y-end.y) + sloppyCoding);
	
//	return NSMakeRect( start.x, start.y, fabs(start.x-end.x) + FLT_MIN, fabs(start.y-end.y) + FLT_MIN);
}

- (NSPoint)start
{
	return start;
}

- (NSPoint)end
{
	return end;
}

- (NSPoint)center
{
	return center;
}

- (void)stroke
{	
	[color set];
	switch (lineType) {
		case DASHED_LINE: 
			//FIXME: this ticked stuff is a mess of converting say 10 pixels to say 0.01 hours...
			//			[self drawTickAt:end];
			//			break;
			//[NSBezierPath strokeLineFromPoint:center toPoint:end]; 
			//break;
		case TICKED_LINE:
			//FIXME: this ticked stuff is a mess of converting say 10 pixels to say 0.01 hours...
			//			[self drawTickAt:end];
			//			break;
		default:
			[NSBezierPath strokeLineFromPoint:start toPoint:end];
			//[NSBezierPath strokeRect:[self bounds]];

	}
}

@end

