CDVCommands.mesa (part of Chipndale)
by Christian Jacobi June 29, 1983 4:44 pm
last edited Christian Jacobi November 23, 1983 9:55 am
DIRECTORY
CD,
CDDraw,
CDExtras,
CDValue,
CDViewer,
CDVPrivate,
CDSequencer,
TerminalIO,
ViewerOps USING [PaintViewer],
ViewerClasses USING [Viewer],
CDInline;
CDVCommands:
CEDAR
PROGRAM
IMPORTS CDDraw, CDExtras, CDValue, CDVPrivate, CDViewer, CDSequencer, TerminalIO, CDInline, ViewerOps =
BEGIN
MyGraphicRef: TYPE = CDVPrivate.MyGraphicRef;
lambda: CD.DesignNumber = CD.lambda;
RepaintViewer:
PROC[mySheet: MyGraphicRef] =
INLINE BEGIN
ViewerOps.PaintViewer[mySheet.viewer, client, FALSE, NIL]
END;
ChangeScale:
PROC [me: MyGraphicRef, newScale:
INT] =
BEGIN
newScale ← MIN[MAX[0, newScale], CDVPrivate.scaleNum-1];
IF me.nscale = newScale THEN TerminalIO.WriteRope["No scale change\n"]
ELSE
BEGIN
off: CD.DesignPosition ← me.noff;
viewerCenterOffset: CD.Position ← [me.viewer.cw/2, me.viewer.ch/2];
oldDesignCenterOffset, newDesignCenterOffset: CD.DesignPosition;
me.noff ← [0, 0];
oldDesignCenterOffset ← CDVPrivate.ViewerToDesignPosition[me, viewerCenterOffset];
CDVPrivate.SetScale[me, newScale, me.ngrid, me.noff];
newDesignCenterOffset ← CDVPrivate.ViewerToDesignPosition[me, viewerCenterOffset];
TerminalIO.WriteRope["Change scale\n"];
off ← CDInline.AddPoints[off, oldDesignCenterOffset];
CDVPrivate.SetScale[me, newScale, me.ngrid, CDInline.SubPoints[off, newDesignCenterOffset]];
ViewerOps.PaintViewer[me.viewer, client, FALSE, NIL];
END
END;
ScaleUp:
PROC [comm: CDSequencer.Command] =
BEGIN
mySheet: MyGraphicRef = NARROW[comm.ref];
i: CARDINAL ← IF mySheet.nscale>0 THEN mySheet.nscale-1 ELSE 0;
ChangeScale[mySheet, i];
END;
ScaleDown:
PROC [comm: CDSequencer.Command] =
BEGIN
mySheet: MyGraphicRef = NARROW[comm.ref];
ChangeScale[mySheet, mySheet.nscale+1];
END;
MoveScreen:
PROC [comm: CDSequencer.Command] =
BEGIN
mySheet: MyGraphicRef = NARROW[comm.ref];
TerminalIO.WriteRope["Move window\n"];
mySheet.noff.x ← mySheet.noff.x-(comm.pos.x-comm.sPos.x);
mySheet.noff.y ← mySheet.noff.y-(comm.pos.y-comm.sPos.y);
RepaintViewer[mySheet];
END;
GridInfoComm:
PROC [comm: CDSequencer.Command] =
BEGIN
mySheet: MyGraphicRef = NARROW[comm.ref];
g: INTEGER ← 1;
n: INT;
TerminalIO.WriteRope["input grid info\n"];
n ← TerminalIO.RequestSelection[
choice: LIST["1/2", "1", " 2", " 4", " 8", "16", "32", "type"],
label: "grid"];
SELECT n
FROM
1 => g ← lambda/2;
2 => g ← lambda;
3 => g ← 2*lambda;
4 => g ← 4*lambda;
5 => g ← 8*lambda;
6 => g ← 16*lambda;
7 => g ← 32*lambda;
8 => g ← MIN[INT[1000], TerminalIO.RequestInt["Grid :"]]*lambda;
ENDCASE =>
g ← CDValue.FetchInt[boundTo: mySheet.actualDesign, key: $CDxInitGrid, propagation: global];
IF g>0
AND g<=256
THEN {
CDVPrivate.SetScale[mySheet, mySheet.nscale, g, mySheet.noff];
--to force grid position on viewer origin
RepaintViewer[mySheet];
}
ELSE TerminalIO.WriteRope["value out of range\n"];
END;
SetSimplificationComm:
PROC[comm: CDSequencer.Command] =
BEGIN
mySheet: MyGraphicRef = NARROW[comm.ref];
n: INT;
TerminalIO.WriteRope["input viewer simplification profile\n"];
n ← TerminalIO.RequestSelection[
choice: LIST["very simplified", " simplified", " standard", " detailed", "very detailed"],
label: "simplification treshold"
];
SELECT n
FROM
1 => mySheet.suppressFactorForCells ← 0.5;
2 => mySheet.suppressFactorForCells ← 0.75;
3 => mySheet.suppressFactorForCells ← 1;
4 => mySheet.suppressFactorForCells ← 1.5;
5 => mySheet.suppressFactorForCells ← 2;
ENDCASE => mySheet.suppressFactorForCells ← 1;
RepaintViewer[mySheet]
END;
TicksInfoComm:
PROC[comm: CDSequencer.Command] =
BEGIN
mySheet: MyGraphicRef = NARROW[comm.ref];
n: INT;
TerminalIO.WriteRope["input ticks info\n"];
n ← TerminalIO.RequestSelection[
choice: LIST["off", " 4", " 8", " 16", " 32", "type"],
label: "Ticks"
];
SELECT n
FROM
1 => mySheet.ticks ← 0;
2 => mySheet.ticks ← 4*lambda;
3 => mySheet.ticks ← 8*lambda;
4 => mySheet.ticks ← 16*lambda;
5 => mySheet.ticks ← 32*lambda;
6 =>
BEGIN
n: INT ← TerminalIO.RequestInt["Ticks: "];
IF n>=0 AND n<=LAST[INTEGER]/lambda-1 THEN mySheet.ticks ← n*lambda
ELSE TerminalIO.WriteRope["value out of range\n"];
END;
ENDCASE;
RepaintViewer[mySheet]
END;
ViewerMenu:
PROC [comm: CDSequencer.Command] =
BEGIN
ENABLE TerminalIO.UserAbort => GOTO userAbort;
SwitchScaleUp:
PROC[mySheet: MyGraphicRef, n:
INT ← 1] =
-- you see more detail
BEGIN
ChangeScale[mySheet, mySheet.nscale-n];
END;
SwitchScaleDown:
PROC[mySheet: MyGraphicRef, n:
INT ← 1] =
-- you see more overview
BEGIN
ChangeScale[mySheet, mySheet.nscale+n];
END;
--ViewerMenu
n: INT;
mySheet: MyGraphicRef = NARROW[comm.ref];
n ← TerminalIO.RequestSelection[
label: "Viewer options",
choice: LIST["split", "grid", "ticks", "reset", "drawmode", "simplification", " quickgrow", " grow", " shrink", " quickshrink"]];
SELECT n
FROM
1 => SplitViewer[comm];
2 => GridInfoComm[comm];
3 => TicksInfoComm[comm];
4 => ResetScaleComm[comm];
5 => DrawModeComm[comm];
6 => SetSimplificationComm[comm];
7 => SwitchScaleUp[mySheet, 4];
8 => SwitchScaleUp[mySheet];
9 => SwitchScaleDown[mySheet];
10 => SwitchScaleDown[mySheet, 4];
ENDCASE => TerminalIO.WriteRope["skipped\n"];
EXITS
userAbort => {TerminalIO.WriteRope["discarded\n"]}
END;
SignalNames:
PROC [comm: CDSequencer.Command] =
BEGIN
mySheet: MyGraphicRef = NARROW[comm.ref];
ViewerOps.PaintViewer[mySheet.viewer, client, FALSE, $DrawSignalNames]
END;
ShowRectX:
PROC [comm: CDSequencer.Command] =
BEGIN
GetOpposit:
PROC[vl: CDViewer.ViewerList, viewer: ViewerClasses.Viewer]
RETURNS [ViewerClasses.Viewer] =
--gets viewer on different screen if possible,
--else different viewer, if possible...
BEGIN
iscolor: BOOL = (viewer.column=color);
FOR l: CDViewer.ViewerList ← vl, l.rest
WHILE l#
NIL
DO
IF ~l.first.iconic THEN IF (l.first.column=color) # iscolor THEN RETURN [l.first];
ENDLOOP;
FOR l: CDViewer.ViewerList ← vl, l.rest
WHILE l#
NIL
DO
IF ~l.first.iconic THEN IF l.first.column#viewer.column THEN RETURN [l.first];
ENDLOOP;
FOR l: CDViewer.ViewerList ← vl, l.rest
WHILE l#
NIL
DO
IF ~l.first.iconic THEN IF l.first#viewer THEN RETURN [l.first];
ENDLOOP;
RETURN [viewer];
END;
--ShowRectX
mySheet: MyGraphicRef = NARROW[comm.ref];
vl: CDViewer.ViewerList = CDViewer.ViewersOf[comm.design];
viewer: ViewerClasses.Viewer = GetOpposit[vl, mySheet.viewer];
TerminalIO.WriteRope["Position a viewer\n"];
IF viewer#
NIL
THEN
IF SmallScale[comm] THEN CDViewer.ShowPosition[viewer: viewer, pos: comm.sPos]
ELSE CDViewer.ShowAndScale[viewer: viewer, rect: CDInline.ToRect[comm.pos, comm.sPos]];
END;
SmallScale:
PROC [comm: CDSequencer.Command]
RETURNS [
BOOL] =
BEGIN
RETURN [CDInline.OrderedIncreasing[CDInline.SubPoints[comm.pos, comm.sPos], [20, 20]]];
END;
ScaleToRect:
PROC [comm: CDSequencer.Command] =
BEGIN
mySheet: MyGraphicRef = NARROW[comm.ref];
TerminalIO.WriteRope["Scale viewer\n"];
IF SmallScale[comm] THEN CDViewer.ShowPosition[viewer: mySheet.viewer, pos: comm.sPos]
ELSE CDViewer.ShowAndScale[viewer: mySheet.viewer, rect: CDInline.ToRect[comm.pos, comm.sPos]]
END;
ResetScale:
PROC [mySheet: MyGraphicRef] =
BEGIN
b: CD.DesignRect;
TerminalIO.WriteRope["reset scale\n"];
b ← CDExtras.BoundingBox[mySheet.actualDesign];
IF CDInline.NonEmpty[b] THEN CDViewer.ShowAndScale[viewer: mySheet.viewer, rect: b];
END;
ResetScaleComm:
PROC [comm: CDSequencer.Command] =
BEGIN
mySheet: MyGraphicRef = NARROW[comm.ref];
ResetScale[mySheet];
END;
DrawModeComm:
PROC [comm: CDSequencer.Command] =
BEGIN
mySheet: MyGraphicRef = NARROW[comm.ref];
n: INT;
TerminalIO.WriteRope["input clip outside current cell mode\n"];
n
← TerminalIO.RequestSelection[
label: "clip outside current cell",
choice: LIST["yes", "no"]
];
SELECT n
FROM
1 => mySheet.suppressOutsidePushedCell ← TRUE;
2 => mySheet.suppressOutsidePushedCell ← FALSE;
ENDCASE => TerminalIO.WriteRope["skipped\n"];
IF n#0 THEN RepaintViewer[mySheet]
END;
ShowViewers:
PROC [comm: CDSequencer.Command] =
BEGIN
mySheet: MyGraphicRef = NARROW[comm.ref];
CDDraw.InsertCommand[mySheet.ct, CDDraw.Comm[cmd: ref, erase: FALSE, rect: CDInline.universe, ref: $ShowViewers]]
END;
SplitViewer:
PROC [comm: CDSequencer.Command] =
BEGIN
[] ← CDViewer.CreateViewer[comm.design]
END;
Impl:
PROC [] =
BEGIN
CDSequencer.ImplementCommand[$ScaleLessDetail, ScaleDown];
CDSequencer.ImplementCommand[$ScaleMoreDetail, ScaleUp];
CDSequencer.ImplementCommand[$MoveScreen, MoveScreen];
CDSequencer.ImplementCommand[$ViewerMenu, ViewerMenu];
CDSequencer.ImplementCommand[$DisplayNames, SignalNames];
CDSequencer.ImplementCommand[$ShowRectX, ShowRectX];
CDSequencer.ImplementCommand[$ShowRect, ScaleToRect];
CDSequencer.ImplementCommand[$ResetScale, ResetScaleComm];
CDSequencer.ImplementCommand[$DisplayViewers, ShowViewers];
CDSequencer.ImplementCommand[$SplitViewer, SplitViewer];
CDSequencer.ImplementCommand[$GridInfo, GridInfoComm];
CDSequencer.ImplementCommand[$TicksInfo, TicksInfoComm];
CDSequencer.ImplementCommand[$DrawMode, DrawModeComm];
CDSequencer.ImplementCommand[$SetSimplification, SetSimplificationComm];
END;
Impl[];
END.