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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
|
/*
Copyright (c) 1998--2005 Benhur Stein
This file is part of Paj.
Paj is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
Paj is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
for more details.
You should have received a copy of the GNU Lesser General Public License
along with Paj; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
/*
*/
#include "STController.h"
#include "DrawView.h"
#include "STEntityTypeLayoutController.h"
#include "../Paje/PajeTraceController.h"
#include "../General/Macros.h"
@implementation STController
- (id)initWithController:(PajeTraceController *)c
{
self = [super initWithController:c];
if (self != nil) {
if (![NSBundle loadNibNamed:@"SpaceTime" owner:self]) {
NSRunAlertPanel(@"SpaceTime", @"Couldn't load interface file",
@"Abort", nil, nil);
//[self release];
//return nil;
//} else {
} [self adjustInterface];
//}
layoutDescriptors = [[NSMutableDictionary alloc] init];
layoutController = [[STEntityTypeLayoutController alloc]
initWithDelegate:self];
// register the tools with the controller
[self registerTool:self];
[self registerTool:layoutController];
}
return self;
}
- (void)dealloc
{
// super's implementation will grant disconnection
#ifdef GNUSTEP
// workaround GNUstep bug #13382
{
int rc;
rc = [drawView retainCount];
[drawView retain];
[hierarchyRuler release];
if ([drawView retainCount] > rc) {
[drawView release];
}
}
#else
[hierarchyRuler release];
#endif
[super dealloc];
}
- (void)disconnectComponent
{
Assign(layoutDescriptors, nil);
Assign(layoutController, nil);
[super disconnectComponent];
}
// set some things that weren't set when main nib file was loaded
- (void)adjustInterface
{
// set rulers
[scrollView setHasVerticalRuler:YES];
hierarchyRuler = [[HierarchyRuler alloc] initWithScrollView:scrollView
controller:self];
[scrollView setVerticalRulerView:hierarchyRuler];
[hierarchyRuler setClientView:drawView];
[scrollView setHasHorizontalRuler:YES];
[[scrollView horizontalRulerView] setClientView:drawView];
[[scrollView horizontalRulerView] setReservedThicknessForMarkers:0.0];
[scrollView setRulersVisible:NO/*YES*/];
[window setDelegate:self];
[window setFrameAutosaveName:@"SpaceTime"];
[window makeKeyAndOrderFront:self];
}
- (void)windowDidBecomeKey:(NSNotification *)notification
{
// tell controller that we are key (to change filter menus)
// TODO: find a cleaner way of doing this
[controller windowIsKey];
}
- (void)windowWillClose:(NSNotification *)notification
{
[controller removeComponent:self];
}
- (void)windowDidResize:(NSNotification *)notification
{
[drawView windowDidResize:notification];
}
- (NSString *)toolName
{
return @"Space Time Diagram";
}
- (void)setInputComponent:(PajeFilter *)filter
{
[super setInputComponent:filter];
[drawView setFilter:self/*(PajeFilter *)filter*/];
}
- (STEntityTypeLayout *)descriptorForEntityType:(PajeEntityType *)entityType
{
return [layoutDescriptors objectForKey:entityType];
}
- (STEntityTypeLayout *)createDescriptorForEntityType:(PajeEntityType *)eType
containerDescriptor:(STContainerTypeLayout *)cDesc
{
STEntityTypeLayout *layoutDescriptor;
PajeDrawingType drawingType;
NSEnumerator *subtypeEnum;
PajeEntityType *subtype;
drawingType = [self drawingTypeForEntityType:eType];
layoutDescriptor = [STEntityTypeLayout
descriptorWithEntityType:eType
drawingType:drawingType
containerDescriptor:cDesc
controller:self];
if (drawingType == PajeVariableDrawingType) {
[(STVariableTypeLayout*)layoutDescriptor setMinValue:[self minValueForEntityType:eType]];
[(STVariableTypeLayout*)layoutDescriptor setMaxValue:[self maxValueForEntityType:eType]];
}
[layoutDescriptors setObject:layoutDescriptor forKey:eType];
subtypeEnum = [[self containedTypesForContainerType:eType]
objectEnumerator];
while ((subtype = [subtypeEnum nextObject]) != nil) {
STEntityTypeLayout *subdescriptor;
subdescriptor = [self createDescriptorForEntityType:subtype
containerDescriptor:(STContainerTypeLayout *)layoutDescriptor];
}
return layoutDescriptor;
}
- (STContainerTypeLayout *)rootLayout
{
id rootInstance;
PajeEntityType *rootEntityType;
STEntityTypeLayout *rootLayout;
rootInstance = [self rootInstance];
rootEntityType = [self entityTypeForEntity:rootInstance];
rootLayout = [self descriptorForEntityType:rootEntityType];
return (STContainerTypeLayout *)rootLayout;
}
- (void)renewLayoutDescriptors
{
id rootInstance;
PajeEntityType *rootEntityType;
STContainerTypeLayout *rootLayout;
[layoutDescriptors removeAllObjects];
rootInstance = [self rootInstance];
rootEntityType = [self entityTypeForEntity:rootInstance];
rootLayout = (STContainerTypeLayout *)
[self createDescriptorForEntityType:rootEntityType
containerDescriptor:nil];
[rootLayout setOffsets];
[self calcRectOfInstance:rootInstance
ofLayoutDescriptor:rootLayout
minY:0];
}
- (NSArray *)layoutDescriptors
{
return [layoutDescriptors allValues];
}
- (void)timeLimitsChanged
{
[self hierarchyChanged];
}
- (void)hierarchyChanged
{
[window setTitleWithRepresentedFilename:[self nameForContainer:[self rootInstance]]];
if ([self startTime] == nil) return;
[drawView saveMiddleTime];
[drawView adjustTimeLimits];
[self renewLayoutDescriptors];
[drawView adjustSize];
[hierarchyRuler refreshSizes];
[scrollView setRulersVisible:YES];
[drawView doubleTimeScale:self];
[drawView halveTimeScale:self];
[layoutController reset];
}
- (void)dataChangedForEntityType:(PajeEntityType *)entityType
{
//FIXME
// [self hierarchyChanged];
// return;
[drawView saveMiddleTime];
[drawView adjustTimeLimits];
[[self rootLayout] setOffsets];
[self calcRectOfInstance:[self rootInstance]
ofLayoutDescriptor:[self rootLayout]
minY:0];
[drawView adjustSize];
[hierarchyRuler refreshSizes];
//[scrollView setNeedsDisplay:YES];
}
- (void)limitsChangedForEntityType:(PajeEntityType *)entityType
{
STEntityTypeLayout *layoutDescriptor;
layoutDescriptor = [layoutDescriptors objectForKey:entityType];
if (layoutDescriptor != nil
&& [layoutDescriptor drawingType] == PajeVariableDrawingType) {
[(STVariableTypeLayout*)layoutDescriptor
setMinValue:[self minValueForEntityType:entityType]];
[(STVariableTypeLayout*)layoutDescriptor
setMaxValue:[self maxValueForEntityType:entityType]];
}
// FIXME: redrawing could be limeted to rects of this entityType.
[drawView setNeedsDisplay:YES];
}
- (void)changedTimeScale
{
[self calcRectOfInstance:[self rootInstance]
ofLayoutDescriptor:[self rootLayout]
minY:0];
[drawView adjustSize];
}
- (void)colorChangedForEntityType:(PajeEntityType *)entityType
{
[drawView setNeedsDisplay:YES];
}
- (void)orderChangedForContainerType:(PajeEntityType *)containerType;
{
//FIXME
[self hierarchyChanged];
}
- (void)timeSelectionChanged
{
[drawView timeSelectionChanged];
}
- (void)containerSelectionChanged
{
[drawView setNeedsDisplay:YES];
[hierarchyRuler setNeedsDisplay:YES];
}
- (void)activateTool:(id)sender
/* sent by PajeController when the user selects this Tool */
{
[window makeKeyAndOrderFront:self];
}
- (void)print:(id)sender
{
// [[NSPrintOperation printOperationWithView:[window contentView]] runOperation];
[window print:sender];
}
- (BOOL)isSelectedEntity:(id)entity
{
id highlightedEntities;
highlightedEntities = [drawView highlightedEntities];
if (highlightedEntities != nil) {
if ([highlightedEntities containsObject:entity]) {
return YES;
}
}
return [super isSelectedEntity:entity];
}
@end
|