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
|
/*
Copyright (c) 1997-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 "StatViewer.h"
#include "../General/Macros.h"
#include "StatArray.h"
@implementation StatViewer
- initWithController:(PajeTraceController *)c
{
self = [super initWithController:c];
if (self != nil) {
if (![NSBundle loadNibNamed:@"StatViewer" owner:self])
NSRunAlertPanel(@"StatViewer", @"Couldn't load interface file",
nil, nil, nil);
}
return self;
}
- (void)awakeFromNib
{
PieCell *cell;
NSSize cellSize = NSZeroSize;
NSString *cellSizeString;
[window setFrameAutosaveName:NSStringFromClass([self class])];
cellSizeString = [[NSUserDefaults standardUserDefaults]
stringForKey:@"StatViewerCellSize"];
if (cellSizeString != nil) {
cellSize = NSSizeFromString(cellSizeString);
}
if (!NSEqualSizes(cellSize, NSZeroSize)) {
[matrix setCellSize:cellSize];
}
cell = [[PieCell alloc] initImageCell:nil];
[cell setRepresentedObject:nil];
[cell setDataProvider:self];
[matrix setPrototype:cell];
[matrix putCell:cell atRow:0 column:0];
[matrix setIntercellSpacing:NSMakeSize(0, 0)];
[cell release];
// notify that we are a Tool
[self registerTool:self];
}
- (void)dealloc
{
Assign(startTime, nil);
Assign(endTime, nil);
[entityTypeSelector removeAllItems];
[[matrix cells] makeObjectsPerformSelector:@selector(setRepresentedObject:)
withObject:nil];
[matrix removeFromSuperview];
[window release];
[super dealloc];
}
- (NSString *)toolName
{
return @"Stat Viewer";
}
- (void)activateTool:(id)sender
{
[window makeKeyAndOrderFront:self];
}
- (void)hierarchyChanged
{
[self invalidateValues];
}
- (void)dataChangedForEntityType:(PajeEntityType *)entityType
{
if ([entityType isEqual:[self selectedEntityType]]) {
[self invalidateValues];
}
}
- (void)colorChangedForEntityType:(PajeEntityType *)entityType
{
if ([entityType isEqual:[self selectedEntityType]]) {
[self invalidateCellCaches];
}
}
- (void)setStartTime:(NSDate *)time
{
Assign(startTime, time);
}
- (void)setEndTime:(NSDate *)time
{
Assign(endTime, time);
}
- (void)timeSelectionChanged
{
[self setStartTime:[self selectionStartTime]];
[self setEndTime:[self selectionEndTime]];
[durationField setStringValue:[NSString stringWithFormat:@"%.6f s", [endTime timeIntervalSinceDate:startTime]]];
[self invalidateValues];
}
- (PajeEntityType *)selectedEntityType
{
return [[entityTypeSelector selectedItem] representedObject];
}
- (PajeEntityType *)selectedContainerType
{
return [self containerTypeForType:[self selectedEntityType]];
}
- (void)fillEntityTypeSelector
{
PajeEntityType *entityType;
PajeEntityType *selectedEntityType;
NSEnumerator *typeEnum;
selectedEntityType = [self selectedEntityType];
[entityTypeSelector removeAllItems];
typeEnum = [[self allEntityTypes] objectEnumerator];
while ((entityType = [typeEnum nextObject]) != nil) {
PajeDrawingType drawingType;
drawingType = [self drawingTypeForEntityType:entityType];
if (drawingType == PajeStateDrawingType
|| drawingType == PajeEventDrawingType) {
NSString *entityTypeDescription;
entityTypeDescription = [self descriptionForEntityType:entityType];
[entityTypeSelector addItemWithTitle:entityTypeDescription];
[[entityTypeSelector lastItem] setRepresentedObject:entityType];
if ([entityType isEqual:selectedEntityType]) {
[entityTypeSelector selectItemAtIndex:
[entityTypeSelector numberOfItems] - 1];
}
}
}
}
- (void)invalidateValues
{
int i=0;
NSEnumerator *nn;
id container;
PieCell *cell;
[self fillEntityTypeSelector];
nn = [self enumeratorOfContainersTyped:[self selectedContainerType]
inContainer:[self rootInstance]];
while ((container = [nn nextObject]) != nil) {
[matrix renewRows:i+1 columns:1];
cell = [matrix cellAtRow:i column:0];
[cell setRepresentedObject:container];
[cell setData:nil];
[cell setDataProvider:self];
i++;
}
[matrix setIntercellSpacing:NSMakeSize(0, 0)];
[matrix sizeToCells];
[matrix setNeedsDisplay];
}
- (void)invalidateCellCaches
{
[[matrix cells] makeObjectsPerformSelector:@selector(discardCache)];
[matrix setNeedsDisplay];
}
- (BOOL)isEntity:(PajeEntity *)internalEntity
inEntity:(PajeEntity *)externalEntity
{
if ([self imbricationLevelForEntity:internalEntity]
<= [self imbricationLevelForEntity:externalEntity]) {
return NO;
}
if ([[self startTimeForEntity:internalEntity]
isEarlierThanDate:[self startTimeForEntity:externalEntity]]) {
return NO;
}
if ([[self endTimeForEntity:internalEntity]
isLaterThanDate:[self endTimeForEntity:externalEntity]]) {
return NO;
}
return YES;
}
- (void)provideDataForCell:(PieCell *)cell
{
NSEnumerator *enumerator;
id array;
PajeContainer *container;
double minDuration;
if (startTime == nil) {
[self setStartTime:[super startTime]];
}
if (endTime == nil) {
[self setEndTime:[super endTime]];
}
container = [cell representedObject];
//NSAssert(container, @"Invalid container in StatViewer cell");
if (container == nil) return;
minDuration = [endTime timeIntervalSinceDate:startTime]/500;
enumerator = [self enumeratorOfEntitiesTyped:[self selectedEntityType]
inContainer:container
fromTime:startTime
toTime:endTime
minDuration:minDuration];
array = [[StatArray stateArrayWithName:[container name]
type:[self selectedEntityType]
startTime:startTime
endTime:endTime
filter:self
entityEnumerator:enumerator] retain];
[cell setData:array];
[cell setGraphType:[[graphTypeSelector selectedItem] tag]];
[array release];
}
- (IBAction)entityTypeSelectorChanged:(id)sender
{
[self invalidateValues];
}
- (IBAction)graphTypeSelectorChanged:(id)sender
{
NSInteger rows, cols;
PieCell *cell;
int i;
[matrix getNumberOfRows:&rows columns:&cols];
for (i=0; i<rows; i++) {
cell = [matrix cellAtRow:i column:0];
[cell setGraphType:[[graphTypeSelector selectedItem] tag]];
}
[matrix setNeedsDisplay];
}
- (void)changeInitialAngle:(id)sender;
{
[[matrix cells] makeObjectsPerformSelector:@selector(setInitialAngle:)
withObject:sender];
[self invalidateCellCaches];
}
- (void)windowDidResize:(NSNotification *)notification
{
NSSize cellSize;
NSRect matrixFrame;
if (![window isVisible]) return;
#if 1
matrixFrame = [[matrix superview] frame];
cellSize.width = NSWidth(matrixFrame);
cellSize.height = 3 * cellSize.width / 5;
[matrix setCellSize:cellSize];
[matrix setIntercellSpacing:NSMakeSize(0, 0)];
[matrix sizeToCells];
[self invalidateCellCaches];
#else
[matrix setAutosizesCells:YES];
[matrix setValidateSize:NO];
#endif
[matrix setNeedsDisplay];
cellSize = [matrix cellSize];
[[NSUserDefaults standardUserDefaults] setObject:NSStringFromSize(cellSize) forKey:@"StatViewerCellSize"];
}
- (void)print:(id)sender
{
// [[NSPrintOperation printOperationWithView:[window contentView]] runOperation];
[window print:sender];
}
@end
|