CDVCommands.mesa (part of Chipndale)
Copyright © 1983, 1984 by Xerox Corporation. All rights reserved.
by Christian Jacobi June 29, 1983 4:44 pm
last edited Christian Jacobi November 5, 1984 10:21:51 am PST
DIRECTORY
CD,
CDApplications,
CDBasics,
CDDraw,
CDExtras,
CDOps,
CDValue,
CDViewer,
CDVPrivate,
CDVScale,
CDVTicks,
CDSequencer,
TerminalIO,
ViewerOps USING [PaintViewer],
ViewerClasses USING [Viewer];
CDVCommands:
CEDAR
PROGRAM
IMPORTS CDApplications, CDDraw, CDExtras, CDOps, CDValue, CDViewer, CDVScale, CDVTicks, CDSequencer, TerminalIO, CDBasics, 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;
WriteLnScale:
PROC [me: MyGraphicRef] =
BEGIN
TerminalIO.WriteRope[" (scale: "];
TerminalIO.WriteInt[me.scale.nscale];
TerminalIO.WriteRope[")\n"];
END;
ChangeScale:
PROC [me: MyGraphicRef, newScale:
INT] =
BEGIN
newScale ← MIN[MAX[0, newScale], CDVScale.scaleNum-1];
IF me.scale.nscale = newScale THEN TerminalIO.WriteRope["No scale change"]
ELSE {
oldDesignCenterOffset, newDesignCenterOffset: CD.DesignPosition;
viewerCenterOffset: CD.Position ← [me.viewer.cw/2, me.viewer.ch/2];
off: CD.DesignPosition ← me.scale.off;
dscale: CDVScale.ScaleRec;
TerminalIO.WriteRope["Change scale"];
dscale ← CDVScale.MakeScale[nscale: me.scale.nscale, grid: me.scale.grid];
oldDesignCenterOffset ← CDVScale.ViewerToDesignPosition[dscale, viewerCenterOffset];
dscale ← CDVScale.MakeScale[nscale: newScale, grid: me.scale.grid];
newDesignCenterOffset ← CDVScale.ViewerToDesignPosition[dscale, viewerCenterOffset];
off ← CDBasics.SubPoints[
CDBasics.AddPoints[off, oldDesignCenterOffset],
newDesignCenterOffset
];
dscale ← CDVScale.MakeScale[off: off, nscale: newScale, grid: me.scale.grid];
me.scale ← dscale;
RepaintViewer[me];
};
WriteLnScale[me];
END;
ScaleUp:
PROC [comm: CDSequencer.Command] =
BEGIN
mySheet: MyGraphicRef = NARROW[comm.ref];
i: CARDINAL ← IF mySheet.scale.nscale>0 THEN mySheet.scale.nscale-1 ELSE 0;
ChangeScale[mySheet, i];
END;
ScaleDown:
PROC [comm: CDSequencer.Command] =
BEGIN
mySheet: MyGraphicRef = NARROW[comm.ref];
ChangeScale[mySheet, mySheet.scale.nscale+1];
END;
MoveScreen:
PROC [comm: CDSequencer.Command] =
BEGIN
mySheet: MyGraphicRef = NARROW[comm.ref];
off: CD.DesignPosition;
TerminalIO.WriteRope["Move window\n"];
off.x ← mySheet.scale.off.x-(comm.pos.x-comm.sPos.x);
off.y ← mySheet.scale.off.y-(comm.pos.y-comm.sPos.y);
mySheet.scale ← CDVScale.MakeScale[
off: off,
nscale: mySheet.scale.nscale,
grid: mySheet.scale.grid
];
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 {
mySheet.scale ← CDVScale.MakeScale[
off: mySheet.scale.off,
nscale: mySheet.scale.nscale,
grid: g
];
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", "all"],
label: "simplification treshold"
];
SELECT n
FROM
1 => mySheet.suppressFactorForCells ← 0.4;
2 => mySheet.suppressFactorForCells ← 0.7;
3 => mySheet.suppressFactorForCells ← 1;
4 => mySheet.suppressFactorForCells ← 1.6;
5 => mySheet.suppressFactorForCells ← 2.4;
6 => mySheet.suppressFactorForCells ← 0;
ENDCASE => mySheet.suppressFactorForCells ← 1;
RepaintViewer[mySheet]
END;
TicksInfoComm:
PROC[comm: CDSequencer.Command] =
BEGIN
mySheet: MyGraphicRef = NARROW[comm.ref];
n: INT;
ticks: INT ← 0;
TerminalIO.WriteRope["input ticks info\n"];
n ← TerminalIO.RequestSelection[
choice: LIST["off", " 4", " 8", " 16", " 32", "type"],
label: "Ticks"
];
SELECT n
FROM
1 => ticks ← 0;
2 => ticks ← 4*lambda;
3 => ticks ← 8*lambda;
4 => ticks ← 16*lambda;
5 => ticks ← 32*lambda;
6 =>
BEGIN
n: INT ← TerminalIO.RequestInt["Ticks: "];
IF n>=0 AND n<=LAST[INTEGER]/lambda-1 THEN ticks ← n*lambda
ELSE TerminalIO.WriteRope["value out of range\n"];
END;
ENDCASE;
CDVTicks.ShowTicks[mySheet, ticks];
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: CDBasics.ToRect[comm.pos, comm.sPos]];
END;
SmallScale:
PROC [comm: CDSequencer.Command]
RETURNS [
BOOL] =
BEGIN
min: CD.DesignNumber = 30;
RETURN [min>ABS[comm.pos.x-comm.sPos.x] AND min>ABS[comm.pos.y-comm.sPos.y]]
END;
ScaleToRect:
PROC [comm: CDSequencer.Command] =
BEGIN
mySheet: MyGraphicRef = NARROW[comm.ref];
TerminalIO.WriteRope["Scale viewer"];
IF SmallScale[comm] THEN CDViewer.ShowPosition[viewer: mySheet.viewer, pos: comm.sPos]
ELSE CDViewer.ShowAndScale[viewer: mySheet.viewer, rect: CDBasics.ToRect[comm.pos, comm.sPos]];
WriteLnScale[mySheet];
END;
ResetScaleComm:
PROC [comm: CDSequencer.Command] =
BEGIN
ResetScale:
PROC [mySheet: MyGraphicRef] =
BEGIN
b: CD.DesignRect;
TerminalIO.WriteRope["reset scale (view all)"];
b ← CDExtras.BoundingBox[mySheet.actualDesign];
IF CDBasics.NonEmpty[b] THEN CDViewer.ShowAndScale[viewer: mySheet.viewer, rect: b];
WriteLnScale[mySheet];
END;
mySheet: MyGraphicRef = NARROW[comm.ref];
ResetScale[mySheet];
END;
ResetScaleToSelectedComm:
PROC [comm: CDSequencer.Command] =
BEGIN
b: CD.DesignRect;
mySheet: MyGraphicRef = NARROW[comm.ref];
TerminalIO.WriteRope["reset scale to selection"];
b ← CDApplications.BoundingRect[list: CDOps.AppList[comm.design], selectedOnly: TRUE];
IF CDBasics.NonEmpty[b]
THEN {
CDViewer.ShowAndScale[viewer: mySheet.viewer, rect: b];
WriteLnScale[mySheet];
}
ELSE TerminalIO.WriteRope[" no selection\n"];
END;
ResetScaleToPushedComm:
PROC [comm: CDSequencer.Command] =
BEGIN
b: CD.DesignRect;
mySheet: MyGraphicRef = NARROW[comm.ref];
TerminalIO.WriteRope["reset scale (to view all of pushed cell)"];
b ← CDApplications.BoundingRect[list: CDOps.AppList[comm.design], selectedOnly: FALSE];
IF CDBasics.NonEmpty[b] THEN CDViewer.ShowAndScale[viewer: mySheet.viewer, rect: b];
WriteLnScale[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];
TerminalIO.WriteRope["show viewers\n"];
CDDraw.InsertCommand[mySheet.ct, CDDraw.Comm[cmd: ref, erase: FALSE, rect: CDBasics.universe, ref: $ShowViewers]]
END;
SplitViewer:
PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["split viewer\n"];
[] ← CDViewer.CreateViewer[comm.design]
END;
CDSequencer.ImplementCommand[$ScaleLessDetail, ScaleDown,, dontQueue];
CDSequencer.ImplementCommand[$ScaleMoreDetail, ScaleUp,, dontQueue];
CDSequencer.ImplementCommand[$MoveScreen, MoveScreen,, dontQueue];
CDSequencer.ImplementCommand[$DisplayNames, SignalNames,, doQueue];
CDSequencer.ImplementCommand[$ShowRectX, ShowRectX,, dontQueue];
CDSequencer.ImplementCommand[$ShowRect, ScaleToRect,, dontQueue];
CDSequencer.ImplementCommand[$ResetScaleAll, ResetScaleComm,, dontQueue];
CDSequencer.ImplementCommand[$ResetScaleTop, ResetScaleToPushedComm,, dontQueue];
CDSequencer.ImplementCommand[$ResetScaleSel, ResetScaleToSelectedComm,, dontQueue];
CDSequencer.ImplementCommand[$DisplayViewers, ShowViewers,, doQueue];
CDSequencer.ImplementCommand[$SplitViewer, SplitViewer,, dontQueue];
CDSequencer.ImplementCommand[$GridInfo, GridInfoComm,, dontQueue];
CDSequencer.ImplementCommand[$TicksInfo, TicksInfoComm,, doQueue];
CDSequencer.ImplementCommand[$DrawMode, DrawModeComm,, doQueue];
CDSequencer.ImplementCommand[$SetSimplification, SetSimplificationComm,, dontQueue];
END.