GraphRemove.mesa, Copyright © 1985 by Xerox Corporation. All rights reserved.
Last Edited by:
Sweetsun Chen, November 20, 1985 2:49:51 pm PST
DIRECTORY
Graph USING [Entity, EntityList, GraphHandle, GraphProc, Text, Texts],
GraphCleanUp USING [CleanUpEL, CleanUpSDL],
GraphPrivate USING [GraphAtomProc, PaintAll, PaintEntity, PaintLegend, PaintText],
GraphUtil USING [ControllerNotNil, SpecIndexedEntity, SpecIndexedText, RaiseError];
GraphRemove:
CEDAR
PROGRAM
IMPORTS GraphCleanUp, GraphPrivate, GraphUtil
EXPORTS GraphPrivate = { OPEN Graph, GraphPrivate, GraphUtil;
SpecRemove:
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, SpecIndexedText[controller, graph.texts]];
$Entity => RemoveEntity[handle, SpecIndexedEntity[controller, graph.entityList]];
ENDCASE => RaiseError[$UnknownAtom, "in SpecRemove"];
};
}; -- SpecRemove
RemoveText:
PUBLIC
PROC[handle: GraphHandle ←
NIL, text: Text ←
NIL] = {
OPEN handle;
IF text #
NIL
THEN {
painted: BOOL ← FALSE;
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;
Check if it is indeed plotted. If plotted then {Remove it from graph.entityList. If plot exits, erase it, and pack lengend.}.
IF entity #
NIL
THEN {
painted: BOOL ← FALSE;
FOR el: EntityList ← graph.entityList, el.rest
UNTIL el =
NIL
DO
IF el.first = entity THEN painted ← TRUE;
ENDLOOP;
IF painted
THEN {
next: Entity;
[graph.entityList, next] ← RemoveEntityFromList[entity, graph.entityList];
IF chart.viewer #
NIL
THEN {
PaintEntity[handle, erase, entity, TRUE];
PaintLegend[handle, paint, next, FALSE]; -- packing them
};
entity.segments ← GraphCleanUp.CleanUpSDL[entity.segments];
lets leave the x's segments there.
};
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, next: Entity ←
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;
next ← IF new = NIL THEN NIL ELSE new.first;
}
ELSE
UNTIL el =
NIL
DO
IF el.rest.first = entity
THEN {
el.rest ← el.rest.rest;
next ← IF el.rest = NIL THEN NIL ELSE el.rest.first;
EXIT;
};
el ← el.rest;
ENDLOOP;
};
}; -- RemoveEntityFromList
RemoveAllCurves:
PUBLIC GraphProc = {
OPEN handle;
clean up plotted curves from graph viewer.
FOR el: EntityList ← graph.entityList, el.rest
UNTIL el =
NIL
DO
el.first.segments ← GraphCleanUp.CleanUpSDL[el.first.segments];
ENDLOOP;
graph.entityList ← GraphCleanUp.CleanUpEL[graph.entityList, FALSE];
PaintAll[handle, TRUE];
}; -- RemoveAllCurves
RemoveEntityFromHash[entity, hash]
}.
LOG.
SChen, created at October 9, 1985 6:51:03 pm PDT.