GraphCleanUpImpl.mesa, copyright © 1985 by Xerox Corporation. All rights reserved.
Last Edited by:
Sweetsun Chen, November 15, 1985 5:46:49 pm PST
DIRECTORY
Graph USING [CaretIndex, Entity, EntityGroup, EntityGroupList, EntityHashSize, EntityList, GraphHandle, LastEntityColor, NestedEntities, NestedEntitiesList, SegmentDataList, Texts, ValueList, XY],
GraphCleanUp,
GraphPrivate USING [defaultColors, defaultFonts],
ViewerOps USING [DestroyViewer];
GraphCleanUpImpl: CEDAR PROGRAM
IMPORTS GraphPrivate, ViewerOps
EXPORTS GraphCleanUp = { OPEN Graph, GraphPrivate;
CleanUpHandle: PUBLIC PROC [handle: GraphHandle ← NIL, full: BOOLFALSE] RETURNS [GraphHandle] = {
in short,
full: both data and structure destroyed.
not full: the structure remains, but data destroyed, so that the handle is like a "vanilla" handle that may still be used.
RETURN[IF handle = NIL THEN NIL
ELSE IF full THEN DestroyHandle[handle]
ELSE RemoveFat[handle]
]
}; -- CleanUpHandle
RemoveFat: PROC [handle: GraphHandle ← NIL] RETURNS [GraphHandle] = {
IF handle # NIL THEN { OPEN handle;
allTexts ← CleanUpTexts[allTexts, TRUE];
entityGroupList ← CleanUpEGL[entityGroupList, TRUE];
FOR i: INT IN [0..EntityHashSize) DO
entityHash[i] ← CleanUpEL[entityHash[i], FALSE];
ENDLOOP;
chart
FOR i: CaretIndex IN CaretIndex DO chart.caretState[i]^ ← []; ENDLOOP;
chart^ ← [viewer: chart.viewer, caretState: chart.caretState];
controller
IF controller # NIL THEN {
ViewerOps.DestroyViewer[controller.table];
controller.table ← NIL;
};
graph
graph.entityList ← CleanUpEL[graph.entityList, FALSE];
FOR i: CaretIndex IN CaretIndex DO graph.caret[i]^ ← []; ENDLOOP;
FOR i: XY IN XY DO graph.target[i]^ ← []; ENDLOOP;
graph.color^ ← defaultColors^;
graph.font^ ← defaultFonts^;
graph^ ← [caret: graph.caret, target: graph.target, color: graph.color, font: graph.font];
lastEntityColor ← LastEntityColor;
lastTextId ← lastEntityId ← -1;
zoomPt1 ← [];
zoomPt2 ← [];
waitingGraph ← FALSE;
selectProcId ← 0;
Process.Abort[selectProc];
selectProc ← NIL;
};
RETURN[handle];
}; -- RemoveFat
DestroyHandle: PROC [handle: GraphHandle ← NIL] RETURNS [GraphHandle] = {
IF handle # NIL THEN { OPEN handle;
allTexts ← CleanUpTexts[allTexts, TRUE];
entityGroupList ← CleanUpEGL[entityGroupList, TRUE];
FOR i: INT IN [0..EntityHashSize) DO
entityHash[i] ← CleanUpEL[entityHash[i], FALSE];
ENDLOOP;
entityHash ← NIL;
chart
FOR i: CaretIndex IN CaretIndex DO chart.caretState[i]^ ← []; ENDLOOP;
chart^ ← [];
chart ← NIL;
controller
IF controller # NIL THEN {
controller^ ← [];
controller ← NIL;
};
graph
FOR i: CaretIndex IN CaretIndex DO graph.caret[i]^ ← []; ENDLOOP;
FOR i: XY IN XY DO graph.target[i]^ ← []; ENDLOOP;
graph.font^ ← ALL[];
graph^ ← [];
graph ← NIL;
imagerFonts ← ALL[NIL];
paintInfo ← NIL;
handle ← NIL;
};
RETURN[handle];
}; -- DestroyHandle
CleanUpVL: PUBLIC PROC [vl: ValueList] RETURNS [ValueList] = {
WHILE vl # NIL DO
next: ValueList ← vl.rest;
vl.rest ← NIL;
vl ← next;
ENDLOOP;
RETURN[vl];
}; -- CleanUpVL
CleanUpSDL: PUBLIC PROC [sdl: SegmentDataList] RETURNS [SegmentDataList] = {
WHILE sdl # NIL DO
next: SegmentDataList ← sdl.rest;
sdl.first ← NIL;
sdl.rest ← NIL;
sdl ← next;
ENDLOOP;
RETURN[sdl];
}; -- CleanUpSDL
In the following routines, if everything = false, destroy the first level data and structure only; otherwise all levels of data attached to it are destroyed.
CleanUpEGL: PROC [egl: EntityGroupList, everything: BOOLFALSE] RETURNS [EntityGroupList] = {
WHILE egl # NIL DO
next: EntityGroupList ← egl.rest;
egl.first ← CleanUpEG[egl.first, everything];
egl.rest ← NIL;
egl ← next;
ENDLOOP;
RETURN[egl];
}; -- CleanUpEGL
CleanUpEG: PROC [eg: EntityGroup, everything: BOOLFALSE] RETURNS [EntityGroup] = {
IF everything THEN {
eg.x ← CleanUpEntity[eg.x];
eg.ys ← CleanUpNE[eg.ys, TRUE];
}
ELSE eg^ ← [];
eg ← NIL;
RETURN[eg];
}; -- CleanUpEG
CleanUpNEL: PROC [nel: NestedEntitiesList, everything: BOOLFALSE] RETURNS [NestedEntitiesList] = {
WHILE nel # NIL DO
next: NestedEntitiesList ← nel.rest;
IF everything THEN nel.first ← CleanUpNE[nel.first, TRUE]
ELSE nel.first ← NIL;
nel.rest ← NIL;
nel ← next;
ENDLOOP;
RETURN[nel];
}; -- CleanUpEGL
CleanUpNE: PROC [ne: NestedEntities, everything: BOOLFALSE] RETURNS [NestedEntities] = {
IF everything THEN {
[] ← CleanUpEL[ne.entityList, TRUE];
[] ← CleanUpNEL[ne.children, TRUE];
};
ne^ ← [];
ne ← NIL;
RETURN[ne];
}; -- CleanUpNE
CleanUpEL: PUBLIC PROC [el: EntityList, everything: BOOLFALSE] RETURNS [EntityList] = {
WHILE el # NIL DO
next: EntityList ← el.rest;
IF everything THEN el.first ← CleanUpEntity[el.first]
ELSE el.first ← NIL;
el.rest ← NIL;
el ← next;
ENDLOOP;
RETURN[el];
}; -- CleanUpEL
CleanUpEntity: PROC [entity: Entity] RETURNS [Entity] = {
IF entity # NIL THEN {
entity.segments ← CleanUpSDL[entity.segments];
entity^ ← [];
entity ← NIL;
};
RETURN[entity];
}; -- CleanUpEntity
CleanUpTexts: PUBLIC PROC [texts: Texts, everything: BOOLFALSE] RETURNS [Texts] = {
WHILE texts # NIL DO
next: Texts ← texts.rest;
IF everything THEN texts.first^ ← [];
texts.first ← NIL;
texts.rest ← NIL;
texts ← next;
ENDLOOP;
RETURN[texts];
}; -- CleanUpTexts
}.
LOG.
Previous version erased 10/16/85 by a vandal.
SChen, October 16, 1985 1:35:55 pm PDT, recreated.