GraphRemove.mesa, Copyright © 1985 by Xerox Corporation. All rights reserved.
Last Edited by:
Sweetsun Chen, October 16, 1985 4:12:38 pm PDT
DIRECTORY
Graph USING [Entity, EntityList, Text, Texts],
GraphCleanUp USING [CleanUpSDL],
GraphPrivate USING [GraphAtomProc, GraphHandle, PaintEntity, PaintText],
GraphUtil USING [ControllerNotNil, PanelIndexedEntity, PanelIndexedText, RaiseError];
GraphRemove: CEDAR PROGRAM
IMPORTS GraphCleanUp, GraphPrivate, GraphUtil
EXPORTS GraphPrivate = { OPEN Graph, GraphPrivate, GraphUtil;
PanelRemove: PUBLIC GraphAtomProc = { -- invoked by buttons on panel.
If handle = nil or controller = nil then error; otherwise:
removes text or entity from graph data,
and, if chart.viewer # nil, erase it from display.
IF ControllerNotNil[handle.controller] THEN { OPEN handle;
SELECT atom FROM
$Text => RemoveText[handle, PanelIndexedText[controller, graph.texts]];
$Entity => RemoveEntity[handle, PanelIndexedEntity[controller, graph.entityList]];
ENDCASE => RaiseError[$UnknownAtom, "in PanelRemove"];
};
}; -- PanelRemove
RemoveText: PUBLIC PROC[handle: GraphHandle ← NIL, text: Text ← NIL] = { OPEN handle;
IF text # NIL THEN {
painted: BOOLFALSE;
FOR ts: Texts ← graph.texts, ts.rest UNTIL ts = NIL DO
IF ts.first = text THEN painted ← TRUE;
ENDLOOP;
IF painted THEN {
graph.texts ← RemoveTextFromList[text, graph.texts];
IF chart.viewer # NIL THEN PaintText[handle, erase, text];
};
IF controller # NIL THEN {
ViewerTools.SetContents[controller.textId, Convert.RopeFromInt[text.id]];
Resume[handle, $Text];
};
};
}; -- RemoveText
RemoveEntity: PUBLIC PROC[handle: GraphHandle ← NIL, entity: Entity ← NIL] = { OPEN handle;
IF entity # NIL THEN {
painted: BOOLFALSE;
FOR el: EntityList ← graph.entityList, el.rest UNTIL el = NIL DO
IF el.first = entity THEN painted ← TRUE;
ENDLOOP;
IF painted THEN {
graph.entityList ← RemoveEntityFromList[entity, graph.entityList];
IF chart.viewer # NIL THEN PaintEntity[handle, erase, entity];
entity.segments ← GraphCleanUp.CleanUpSDL[entity.segments];
};
IF controller # NIL THEN {
ViewerTools.SetContents[controller.entityId, Convert.RopeFromInt[entity.id]];
Resume[handle, $Entity];
};
};
}; -- RemoveEntity
RemoveTextFromList: PROC [text: Text ← NIL, old: Texts ← NIL] RETURNS [new: Texts ← NIL] = {
ts: Texts ← new ← old;
IF ts # NIL THEN {
IF ts.first = text THEN new ← ts.rest ELSE UNTIL ts.rest = NIL DO
IF ts.rest.first = text THEN {ts.rest ← ts.rest.rest; EXIT};
ts ← ts.rest;
ENDLOOP;
};
}; -- RemoveTextFromList
RemoveEntityFromList: PROC [entity: Entity ← NIL, old: EntityList ← NIL] RETURNS [new: EntityList ← NIL]= {
noop if either entity or entityList is nil; or if entity is not on old.
el: EntityList ← new ← old;
IF el # NIL THEN {
IF el.first = entity THEN new ← el.rest ELSE UNTIL el = NIL DO
IF el.rest.first = entity THEN {el.rest ← el.rest.rest; EXIT};
el ← el.rest;
ENDLOOP;
};
}; -- RemoveEntityFromList
RemoveEntityFromHash[entity, hash]
}.
LOG.
SChen, created at October 9, 1985 6:51:03 pm PDT.