-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAQTModel.m
137 lines (114 loc) · 2.45 KB
/
AQTModel.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//
// AQTModel.m
// AquaTerm
//
// Created by per on Fri Nov 02 2001.
// Copyright (c) 2001 Aquaterm. All rights reserved.
//
#import "AQTModel.h"
@implementation AQTModel
/**"
*** A class representing a collection of objects making up the plot.
"**/
-(id)initWithCanvasSize:(NSSize)size
{
self = [super init];
if (self)
{
modelObjects = [[NSMutableArray alloc] initWithCapacity:1024];
[self setTitle:@"Untitled"];
canvasSize = size;
}
return self;
}
-(id)init
{
return [self initWithCanvasSize:NSMakeSize(200,200)];
}
-(void)dealloc
{
#ifdef MEM_DEBUG
NSLog(@"[%@(0x%x) %@] %s:%d", NSStringFromClass([self class]), self, NSStringFromSelector(_cmd), __FILE__, __LINE__);
#endif
[title release];
[modelObjects release];
[super dealloc];
}
- (void)encodeWithCoder:(NSCoder *)coder
{
AQTSize s;
[super encodeWithCoder:coder];
[coder encodeObject:modelObjects];
[coder encodeObject:title];
// 64bit compatibility
s.width = canvasSize.width; s.height = canvasSize.height;
[coder encodeValueOfObjCType:@encode(AQTSize) at:&s];
}
-(id)initWithCoder:(NSCoder *)coder
{
AQTSize s;
self = [super initWithCoder:coder];
modelObjects = [[coder decodeObject] retain];
title = [[coder decodeObject] retain];
[coder decodeValueOfObjCType:@encode(AQTSize) at:&s];
canvasSize.width = s.width; canvasSize.height = s.height;
return self;
}
-(NSString *)description
{
return [NSString stringWithFormat:@"[AQTModel description] =\nTitle %@\nCanvasSize %@\nCount %d\nBounds %@", title, NSStringFromSize(canvasSize), [modelObjects count], NSStringFromRect(_bounds)];
}
-(NSSize)canvasSize
{
return canvasSize;
}
-(void)setCanvasSize:(NSSize)cs
{
canvasSize = cs;
}
-(BOOL)isDirty
{
return isDirty;
}
-(NSRect)dirtyRect
{
return dirtyRect;
}
-(int32_t)count
{
return [modelObjects count];
}
/**"
*** Add any subclass of AQTGraphic to the collection of objects.
"**/
-(void)addObject:(AQTGraphic *)graphic
{
[modelObjects addObject:graphic];
}
-(void)addObjectsFromArray:(NSArray *)graphics
{
[modelObjects addObjectsFromArray:graphics];
}
-(NSArray *)modelObjects
{
return modelObjects;
}
-(void)removeAllObjects
{
[modelObjects removeAllObjects];
}
-(void)removeObjectAtIndex:(uint32_t)i
{
[modelObjects removeObjectAtIndex:i];
}
-(void)setTitle:(NSString *)newTitle
{
[newTitle retain];
[title release];
title = newTitle;
}
-(NSString *)title
{
return [[title copy] autorelease];
}
@end