CDBasicCommands.mesa (part of ChipNDale)
Copyright © 1983, 1985 by Xerox Corporation. All rights reserved.
by Christian Jacobi, June 29, 1983 4:44 pm
last edited Christian Jacobi, March 14, 1986 8:15:04 pm PST
DIRECTORY
BasicTime,
CD,
CDBasics,
CDCommandOps,
CDInstances,
CDSimpleOps,
CDOps,
CDOrient,
CDRects,
CDSequencer,
TerminalIO;
CDBasicCommands: CEDAR PROGRAM
IMPORTS BasicTime, CDCommandOps, CDInstances, CDSimpleOps, CDOps, CDSequencer, TerminalIO, CDRects, CDBasics =
BEGIN
AddARect: PROC[design: CD.Design, r: CD.Rect, l: CD.Layer] =
BEGIN
ob: CD.Object;
sz: CD.Position ← CDBasics.SizeOfRect[r];
orient: CD.Orientation ← CDOrient.original;
IF sz.y<sz.x THEN {
w: CD.Number ← sz.x;
sz.x ← sz.y;
sz.y ← w;
orient ← CDOrient.rotate90
};
IF sz.x<=0 THEN {TerminalIO.WriteRope["Empty object not included\n"]; RETURN};
ob ← CDRects.CreateRect[sz, l];
CDOps.IncludeObjectI[
design: design,
ob: ob,
location: CDBasics.BaseOfRect[r],
orientation: orient]
END;
AddRect: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["Add rect\n"];
AddARect[comm.design, CDBasics.ToRect[comm.sPos, comm.pos], comm.l];
END;
AddWire: PROC [comm: CDSequencer.Command] =
--uses pos, sPos, n (for width), b (for firstHorizontal), l (for layer)
BEGIN
InternalAddWire[comm: comm, firstOnly: FALSE]
END;
ContinueWire: PROC [comm: CDSequencer.Command] =
BEGIN
InternalAddWire[comm: comm, firstOnly: TRUE]
END;
InternalAddWire: PROC [comm: CDSequencer.Command, firstOnly: BOOLFALSE] =
--this procedure knows EXACTLY the algorithm used for showing
--temporary wires in the cursor part
BEGIN
start: CD.Position ← comm.sPos;
stop: CD.Position ← comm.pos;
wireWidth: CD.Number ← comm.n;
IF wireWidth=0 THEN {AddRect[comm]; RETURN};
TerminalIO.WriteRope["Add wire\n"];
IF --firstHorizontal-- comm.b THEN {
IF stop.x<=start.x AND stop.x>=start.x-wireWidth
AND (stop.y<start.y OR stop.y>start.y+wireWidth) THEN { --crazy vertical wire
IF ABS[start.y-stop.y]<comm.design.technology.lambda THEN
{TerminalIO.WriteRope[" Empty Wire not added\n"]; RETURN};
stop.x ← start.x+wireWidth;
AddARect[comm.design, CDBasics.ToRect[start, stop], comm.l];
RETURN
};
--not only crazy vertical
IF stop.y>=start.y AND stop.y<=start.y+wireWidth THEN { --horizontal wire
stop.y ← start.y+wireWidth;
AddARect[comm.design, CDBasics.ToRect[start, stop], comm.l]
}
ELSE { --L shaped (firsthorizontal)
IF start.x<=stop.x THEN {stop.x ← stop.x+wireWidth}
ELSE {t: CD.Number=stop.x; stop.x ← start.x; start.x ← t};
stop.y ← start.y+wireWidth;
AddARect[comm.design, CDBasics.ToRect[start, stop], comm.l];
IF firstOnly THEN RETURN;
start.x ← comm.pos.x; stop.y ← comm.pos.y; stop.x ← start.x+wireWidth;
AddARect[comm.design, CDBasics.ToRect[start, stop], comm.l];
}
}
ELSE { -- NOT firstHorizontalVC --
IF stop.y<=start.y AND stop.y>=start.y-wireWidth
AND (stop.x<start.x OR stop.x>start.x+wireWidth) THEN { --crazy horizontal wire
IF ABS[stop.x-start.x]<comm.design.technology.lambda THEN
{TerminalIO.WriteRope[" Empty Wire not added\n"]; RETURN};
stop.y ← start.y+wireWidth;
AddARect[comm.design, CDBasics.ToRect[start, stop], comm.l];
RETURN
};
-- not only crazy horizontal
IF stop.x>=start.x AND stop.x<=start.x+wireWidth THEN { --vertical wire
stop.x ← start.x+wireWidth;
AddARect[comm.design, CDBasics.ToRect[start, stop], comm.l]
}
ELSE { --L shaped (firstVertical)
IF start.y<=stop.y THEN {stop.y ← stop.y+wireWidth}
ELSE {t: CD.Number = stop.y; stop.y ← start.y; start.y ← t};
stop.x ← start.x+wireWidth;
AddARect[comm.design, CDBasics.ToRect[start, stop], comm.l];
IF firstOnly THEN RETURN;
start.y ← comm.pos.y; stop.y ← start.y+wireWidth; stop.x ← comm.pos.x;
AddARect[comm.design, CDBasics.ToRect[start, stop], comm.l];
}
}
END;
DeleteSelected: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["Delete selected "];
CDSimpleOps.DeleteSelected[comm.design];
TerminalIO.WriteLn[];
END;
Undelete: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["Undelete\n"];
CDSimpleOps.Undelete[comm.design]
END;
AbortCommand: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["Try to abort current command\n"];
CDSequencer.AbortDesignsCommand[comm.design]
END;
SelectExclusive: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["Select pointed"];
CDSimpleOps.DeselectAll[comm.design];
CDSimpleOps.Select[comm.design, comm.pos];
TerminalIO.WriteLn[];
END;
ReSelectExclusive: PROC [design: CD.Design, pos: CD.Position, verbose: BOOLTRUE] RETURNS [done: BOOL←TRUE] =
BEGIN
Deselect: PROC[i: CD.Instance] =
INLINE BEGIN
IF i.selected THEN {
i.selected ← FALSE;
CDOps.RedrawInstance[design, i]
}
END;
DeselectList: PROC[list: CD.InstanceList] =
BEGIN
FOR w: CD.InstanceList ← list, w.rest WHILE w#NIL DO
Deselect[w.first]
ENDLOOP
END;
inst: CD.Instance ← NIL; --any application where pos points to
FOR w: CD.InstanceList ← CDOps.InstList[design], w.rest WHILE w#NIL DO
IF CDInstances.PointToI[pos, w.first] THEN {
--hit
IF w.first.selected THEN {
DeselectList[w.rest];
CDOps.ReOrderInstance[design, w.first];
IF verbose THEN TerminalIO.WriteRope[CDCommandOps.InstRope[w.first]];
RETURN
}
ELSE IF inst=NIL THEN inst ← w.first
}
ELSE Deselect[w.first]
ENDLOOP;
--if a selected inst is pointed we already did return
IF inst#NIL THEN {
inst.selected ← TRUE;
CDOps.ReOrderInstance[design, inst];
CDOps.RedrawInstance[design, inst, FALSE];
IF verbose THEN TerminalIO.WriteRope[CDCommandOps.InstRope[inst]]
}
ELSE {
done ← FALSE;
IF verbose THEN TerminalIO.WriteRope[" (no object)"];
}
END;
RectDist: PROC[pos: CD.Position, r: CD.Rect] RETURNS [CD.Number] =
--Distance between a point and a rectangle
BEGIN
RETURN [MAX[
(IF pos.x<r.x1 THEN (r.x1-pos.x) ELSE IF pos.x>r.x2 THEN (pos.x-r.x2) ELSE 0),
(IF pos.y<r.y1 THEN (r.y1-pos.y) ELSE IF pos.y>r.y2 THEN (pos.y-r.y2) ELSE 0)
]]
END;
CloseReSelectExclusive: PROC [design: CD.Design, pos: CD.Position, verbose: BOOLTRUE, dist: CD.Number�] =
BEGIN
IF ~ReSelectExclusive[design, pos, verbose] THEN {
inst: CD.Instance ← NIL;
FOR w: CD.InstanceList ← CDOps.InstList[design], w.rest WHILE w#NIL DO
d: CD.Number = RectDist[pos, CDInstances.InstRectI[w.first]];
IF d<dist THEN {inst ← w.first; dist ← d}
ENDLOOP;
IF inst#NIL THEN {
inst.selected ← TRUE;
CDOps.RedrawInstance[design, inst, FALSE];
IF verbose THEN {
TerminalIO.WriteRopes[" found close object ", CDCommandOps.InstRope[inst]];
}
}
}
END;
ReSelectExclusiveComm: PROC [comm: CDSequencer.Command] =
--select pointed application exclusive;
--(but dont select an other application if the pointed one is already the right one)
BEGIN
TerminalIO.WriteRope["Select"];
[] ← ReSelectExclusive[comm.design, comm.pos];
TerminalIO.WriteLn[];
END;
--crazy heuristics to determine which kind of selection is wanted
lastPos: CD.Position;
lastKey: REFNIL;
lastTime: BasicTime.GMT ← BasicTime.earliestGMT;
SameAsLast: PROC[comm: CDSequencer.Command] RETURNS [yes: BOOL] =
BEGIN
lambda: CD.Number = comm.design.technology.lambda;
ReallyClose: PROC [p1, p2: CD.Position] RETURNS [BOOL] = INLINE {
RETURN [ABS[p1.x-p2.x]<=lambda AND ABS[p1.y-p2.y]<=lambda]
};
now: BasicTime.GMT ← BasicTime.Now[];
yes ← ReallyClose[lastPos, comm.pos] AND lastKey=comm.key AND BasicTime.Period[lastTime, now]<=2;
lastPos ← comm.pos;
lastKey ← comm.key;
lastTime ← now;
END;
CloseReSelectComm: PROC [comm: CDSequencer.Command] =
--select pointed application exclusive;
--(but dont select an other application if the pointed one is already the right one)
--if there is none, select closest
--cycle through if exactly sme position
BEGIN
TerminalIO.WriteRope["select "];
IF SameAsLast[comm] THEN CDSimpleOps.DeselectAll[comm.design];
[] ← CloseReSelectExclusive[comm.design, comm.pos, TRUE, 50];
TerminalIO.WriteLn[];
END;
MultiOnlySelectComm: PROC [comm: CDSequencer.Command] =
BEGIN
NotRect: PROC [p1, p2: CD.Position] RETURNS [BOOL] = INLINE
BEGIN
RETURN [ABS[p1.x-p2.x]<=lambda OR ABS[p1.y-p2.y]<=lambda]
END;
lambda: CD.Number = comm.design.technology.lambda;
IF NotRect[comm.pos, comm.sPos] THEN CloseReSelectComm[comm]
ELSE AreaOnlySelect[comm];
END;
DoubleAddSelectComm: PROC [comm: CDSequencer.Command] =
BEGIN
IF SameAsLast[comm] THEN {
TerminalIO.WriteRope["Change selection "];
[] ← DeSelectLast[comm.design, comm.pos, TRUE];
}
ELSE TerminalIO.WriteRope["Add selection "];
CDSimpleOps.Select[comm.design, comm.pos];
TerminalIO.WriteLn[];
END;
DeselectPointed: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["Remove selection "];
CDSimpleOps.DeSelect[comm.design, comm.pos];
TerminalIO.WriteLn[];
END;
DeSelectLast: PROC [design: CD.Design, pos: CD.Position, usePos: BOOLTRUE] RETURNS [done: BOOLFALSE] =
BEGIN
sel: CD.Instance ← NIL;
FOR w: CD.InstanceList ← CDOps.InstList[design], w.rest WHILE w#NIL DO
IF w.first.selected THEN {
IF ~usePos OR CDInstances.PointToI[pos, w.first] THEN sel ← w.first;
};
ENDLOOP;
IF sel#NIL THEN {
sel.selected ← FALSE;
done ← TRUE;
CDOps.RedrawInstance[design, sel]
}
END;
DeselectLastSelected: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["Remove selection "];
[] ← DeSelectLast[comm.design, comm.pos, TRUE];
TerminalIO.WriteLn[];
END;
AddSelection: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["Add selection "];
CDSimpleOps.Select[comm.design, comm.pos];
TerminalIO.WriteLn[];
END;
DeselectAll: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["Deselect all\n"];
CDSimpleOps.DeselectAll[comm.design]
END;
SelectAll: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["Select all\n"];
CDSimpleOps.SelectAll[comm.design]
END;
AreaAddSelect: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["Inclusive select area\n"];
CDSimpleOps.AreaSelect[comm.design, CDBasics.ToRect[comm.pos, comm.sPos]]
END;
MultiAddSelect: PROC [comm: CDSequencer.Command] =
--Auto select area or pointed or changed
BEGIN
NotRect: PROC [p1, p2: CD.Position] RETURNS [BOOL] = INLINE
BEGIN
RETURN [ABS[p1.x-p2.x]<=lambda OR ABS[p1.y-p2.y]<=lambda]
END;
lambda: CD.Number = comm.design.technology.lambda;
IF NotRect[comm.pos, comm.sPos] THEN DoubleAddSelectComm[comm]
ELSE {
TerminalIO.WriteRope["select inclusive area\n"];
CDSimpleOps.AreaSelect[comm.design, CDBasics.ToRect[comm.pos, comm.sPos]]
}
END;
AreaAddSelectTouching: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["select inclusive touching\n"];
CDSimpleOps.AreaSelect[comm.design, CDBasics.ToRect[comm.pos, comm.sPos], TRUE]
END;
AreaOnlySelect: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["Select area\n"];
CDSimpleOps.DeselectAll[comm.design];
CDSimpleOps.AreaSelect[comm.design, CDBasics.ToRect[comm.pos, comm.sPos]]
END;
ADeSelect: PROC [comm: CDSequencer.Command] =
--Auto deselect area or pointed
BEGIN
TerminalIO.WriteRope["Deselect "];
IF comm.pos=comm.sPos THEN CDSimpleOps.DeSelect[comm.design, comm.pos]
ELSE CDSimpleOps.AreaDeSelect[comm.design, CDBasics.ToRect[comm.pos, comm.sPos]];
TerminalIO.WriteLn[];
END;
AreaDeSelect: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["Deselect area\n"];
CDSimpleOps.AreaDeSelect[comm.design, CDBasics.ToRect[comm.pos, comm.sPos]]
END;
AreaDeSelectTouching: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["Deselect touching\n"];
CDSimpleOps.AreaDeSelect[comm.design, CDBasics.ToRect[comm.pos, comm.sPos], TRUE]
END;
CDSequencer.ImplementCommand[$AbortCommand, AbortCommand,, dontQueue];
CDSequencer.ImplementCommand[$DrawRect, AddRect];
CDSequencer.ImplementCommand[$DrawWire, AddWire];
CDSequencer.ImplementCommand[$ContinueWire, ContinueWire];
CDSequencer.ImplementCommand[$DeleteS, DeleteSelected];
CDSequencer.ImplementCommand[$Undel, Undelete];
CDSequencer.ImplementCommand[$OnlySelectP, SelectExclusive,, doQueue];
CDSequencer.ImplementCommand[$ReSelectOnlyP, ReSelectExclusiveComm,, doQueue];
CDSequencer.ImplementCommand[$CloseReSelectOnlyP, CloseReSelectComm,, doQueue];
CDSequencer.ImplementCommand[$AddSelectP, AddSelection,, doQueue];
CDSequencer.ImplementCommand[$DeSelectLP, DeselectLastSelected,, doQueue];
CDSequencer.ImplementCommand[$DeSelectFP, DeselectPointed,, doQueue];
CDSequencer.ImplementCommand[$DeSelectS, DeselectAll,, doQueue];
CDSequencer.ImplementCommand[$SelectAll, SelectAll,, doQueue];
CDSequencer.ImplementCommand[$AreaOnlySelect, AreaOnlySelect,, doQueue];
CDSequencer.ImplementCommand[$MultiOnlySelect, MultiOnlySelectComm,, doQueue];
CDSequencer.ImplementCommand[$AreaAddSelect, AreaAddSelect,, doQueue];
CDSequencer.ImplementCommand[$AreaAddSelectTouching, AreaAddSelectTouching,, doQueue];
CDSequencer.ImplementCommand[$MultiAddSelect, MultiAddSelect,, doQueue];
CDSequencer.ImplementCommand[$DoubleAddSelect, DoubleAddSelectComm,, doQueue];
CDSequencer.ImplementCommand[$AreaDeSelect, AreaDeSelect,, doQueue];
CDSequencer.ImplementCommand[$AreaDeSelectTouching, AreaDeSelectTouching,, doQueue];
CDSequencer.ImplementCommand[$ADeSelect, ADeSelect,, doQueue];
END.