CDVCommands.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, January 16, 1985 4:01:39 pm PST
DIRECTORY
CD,
CDApplications,
CDBasics,
CDDraw,
CDExtras,
CDOps,
CDValue,
CDViewer,
CDVPrivate,
CDPanel,
CDVScale,
CDVTicks,
CDSequencer,
TerminalIO,
ViewerOps USING [PaintViewer],
ViewerClasses USING [Viewer];
CDVCommands: CEDAR PROGRAM
IMPORTS CDApplications, CDDraw, CDExtras, CDOps, CDValue, CDViewer, CDVScale, CDVTicks, CDPanel, 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: CARDINALIF 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 (currently"];
TerminalIO.WriteRope[CDExtras.ToLambda[mySheet.scale.grid]];
TerminalIO.WriteRope[")\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[1300], TerminalIO.RequestInt["grid: "]]*lambda;
ENDCASE =>
g ← CDValue.FetchInt[boundTo: mySheet.actualDesign, key: $CDxInitGrid, propagation: global];
IF g>0 AND g<=2600 THEN {
mySheet.scale ← CDVScale.MakeScale[
off: mySheet.scale.off,
nscale: mySheet.scale.nscale,
grid: g
];
RepaintViewer[mySheet];
TerminalIO.WriteRope[" set to"];
TerminalIO.WriteRope[CDExtras.ToLambda[mySheet.scale.grid]];
TerminalIO.WriteLn[];
}
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;
InstanceNames: PROC [comm: CDSequencer.Command] =
BEGIN
v: ViewerClasses.Viewer = GetViewer[comm];
TerminalIO.WriteRope["display instance names\n"];
IF v#NIL THEN
ViewerOps.PaintViewer[v, client, FALSE, $DrawInstanceNames]
END;
SignalNames: PROC [comm: CDSequencer.Command] =
BEGIN
v: ViewerClasses.Viewer = GetViewer[comm];
TerminalIO.WriteRope["display signal names\n"];
IF v#NIL THEN
ViewerOps.PaintViewer[v, client, FALSE, $DrawSignalNames]
END;
GetViewer: PROC[comm: CDSequencer.Command] RETURNS [v: ViewerClasses.Viewer ← NIL] =
BEGIN
IF comm#NIL THEN
WITH comm.ref SELECT FROM
my: MyGraphicRef => RETURN [my.viewer]
ENDCASE => NULL
END;
GetOppositViewer: PROC[comm: CDSequencer.Command] RETURNS [ViewerClasses.Viewer] =
--gets viewer on different screen if possible,
--else different viewer, if possible...
BEGIN
vl: CDViewer.ViewerList = CDViewer.ViewersOf[comm.design];
viewer: ViewerClasses.Viewer = GetViewer[comm];
onColor: BOOL = (viewer=NIL OR viewer.column=color);
FOR l: CDViewer.ViewerList ← vl, l.rest WHILE l#NIL DO
IF ~l.first.iconic THEN IF (l.first.column=color)#onColor 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;
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;
ShowRectX: PROC [comm: CDSequencer.Command] =
BEGIN
viewer: ViewerClasses.Viewer = GetOppositViewer[comm];
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;
ShowRect: 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.BoundingRectO[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.BoundingRectO[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 drawing modes\n"];
n ← TerminalIO.RequestSelection[
choice: LIST["draw environment", "dont draw env.", "draw symbolic ob", "dont draw sym."],
label: "drawing modes"
];
SELECT n FROM
1 => mySheet.environment ← TRUE;
2 => mySheet.environment ← FALSE;
3 => mySheet.symbolics ← TRUE;
4 => mySheet.symbolics ← FALSE;
5 => mySheet.b1 ← TRUE;
6 => mySheet.b1 ← FALSE;
6 => mySheet.b2 ← TRUE;
7 => mySheet.b2 ← 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;
CDPanel.DefineButton[tech: NIL, name: "new view", proc: SplitViewer, queue: dontQueue, topLine: TRUE];
CDSequencer.ImplementCommand[$ScaleLessDetail, ScaleDown,, dontQueue];
CDSequencer.ImplementCommand[$ScaleMoreDetail, ScaleUp,, dontQueue];
CDSequencer.ImplementCommand[$MoveScreen, MoveScreen,, dontQueue];
CDSequencer.ImplementCommand[$DisplayNames, SignalNames,, doQueue];
CDSequencer.ImplementCommand[$DisplayInstanceNames, InstanceNames,, doQueue];
CDSequencer.ImplementCommand[$ShowRectX, ShowRectX,, dontQueue];
CDSequencer.ImplementCommand[$ShowRect, ShowRect,, 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.