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, February 19, 1986 7:46:00 pm PST
DIRECTORY
CD,
CDBasics,
CDDrawQueue,
CDCells,
CDCommandOps,
CDExtras,
CDInstances,
CDMenus,
CDOps,
CDPanel,
CDProperties,
CDSequencer,
CDValue,
CDViewer,
CDVPrivate,
CDVScale,
IO,
Rope,
TerminalIO,
ViewerClasses USING [Viewer],
ViewerOps USING [PaintViewer, GetViewer, SetViewer];
CDVCommands:
CEDAR
PROGRAM
IMPORTS CDBasics, CDDrawQueue, CDCells, CDCommandOps, CDExtras, CDInstances, CDMenus, CDOps, CDPanel, CDProperties, CDSequencer, CDValue, CDViewer, CDVScale, IO, TerminalIO, ViewerOps =
BEGIN
VRef: TYPE = CDVPrivate.VRef;
RepaintViewer:
PROC[vRef: VRef] =
INLINE BEGIN
CDDrawQueue.Flush[vRef.ct];
CDDrawQueue.QueueInsertDrawCommand[vRef.ct, CDDrawQueue.Request[$changeScale, CDBasics.universe]];
END;
WriteLnScale:
PROC [v:
REF] =
BEGIN
WITH v
SELECT
FROM
viewer: ViewerClasses.Viewer => WriteLnScale[viewer.data];
me: VRef => TerminalIO.WriteF1[" (scale: %g)\n", IO.int[me.scale.nscale]];
ENDCASE => TerminalIO.WriteLn[];
END;
ChangeScale:
PROC [me: VRef, 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.Position;
viewerCenterOffset: CD.Position ← [me.viewer.cw/2, me.viewer.ch/2];
off: CD.Position ← me.scale.off;
dscale: CDVScale.ScaleRec;
CDDrawQueue.Flush[me.ct];
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.intendedScale ← dscale;
RepaintViewer[me];
};
WriteLnScale[me.viewer];
END;
ScaleUp:
PROC [comm: CDSequencer.Command] =
BEGIN
vRef: VRef = NARROW[comm.ref];
i: INT ← vRef.scale.nscale;
i ← IF i>0 THEN i-1 ELSE 0;
ChangeScale[vRef, i];
END;
ScaleDown:
PROC [comm: CDSequencer.Command] =
BEGIN
vRef: VRef = NARROW[comm.ref];
ChangeScale[vRef, vRef.scale.nscale+1];
END;
MoveScreen:
PROC [comm: CDSequencer.Command] =
BEGIN
vRef: VRef = NARROW[comm.ref];
off: CD.Position;
CDDrawQueue.Flush[vRef.ct];
TerminalIO.WriteRope["Move window\n"];
off.x ← vRef.scale.off.x-(comm.pos.x-comm.sPos.x);
off.y ← vRef.scale.off.y-(comm.pos.y-comm.sPos.y);
vRef.intendedScale ← CDVScale.MakeScale[
off: off,
nscale: vRef.scale.nscale,
grid: vRef.scale.grid
];
RepaintViewer[vRef];
END;
GetViewerInt:
PROC [viewer: ViewerClasses.Viewer, at:
ATOM]
RETURNS [i:
INT ← -1] = {
WITH ViewerOps.GetViewer[viewer, at]
SELECT
FROM
ri: REF INT => i ← ri^;
ENDCASE => NULL;
};
GridInfoComm:
PROC [comm: CDSequencer.Command] =
BEGIN
newGrid: INT ← -1;
lambda: INT ← comm.design.technology.lambda;
viewer: ViewerClasses.Viewer ← CDViewer.GetViewer[comm];
IF viewer#
NIL
THEN {
g: INT;
TerminalIO.WriteF1["input grid info (currently%g)\n", IO.rope[CDExtras.ToLambda[GetViewerInt[viewer, $Grid], lambda]]];
SELECT TerminalIO.RequestSelection[choice:
LIST["1", " 2", " 4", " 8", "16", "32", "default", "type lambda", "type int"], label: "grid"]
FROM
1 => g ← lambda;
2 => g ← 2*lambda;
3 => g ← 4*lambda;
4 => g ← 8*lambda;
5 => g ← 16*lambda;
6 => g ← 32*lambda;
7 => g ← CDValue.FetchInt[boundTo: CDViewer.DesignOf[viewer], key: $CDxInitGrid, propagation: global];
8 => g ← MIN[INT[2600/lambda], TerminalIO.RequestInt["grid: "]]*lambda;
9 => g ← MIN[INT[2600], TerminalIO.RequestInt["grid: "]];
ENDCASE => g ← -1;
IF g>0
AND g<=2600
THEN {
ViewerOps.SetViewer[viewer: viewer, data: NEW[INT←g], op: $Grid];
newGrid ← GetViewerInt[viewer, $Grid];
}
};
IF newGrid<=0 THEN TerminalIO.WriteRope["failed\n"]
ELSE TerminalIO.WriteF1[" grid set to %g \n", IO.rope[CDExtras.ToLambda[newGrid, lambda]]]
END;
SetSimplificationComm:
PROC[comm: CDSequencer.Command] =
BEGIN
vRef: VRef = NARROW[comm.ref];
n: INT;
TerminalIO.WriteRope["input viewer simplification profile\n"];
CDDrawQueue.Flush[vRef.ct];
n ← TerminalIO.RequestSelection[
choice: LIST["very simplified", "simplified", "standard", "detailed", "very detailed", "all"],
label: "simplification treshold"
];
SELECT n
FROM
1 => vRef.suppressFactorForCells ← 0.4;
2 => vRef.suppressFactorForCells ← 0.7;
3 => vRef.suppressFactorForCells ← 1;
4 => vRef.suppressFactorForCells ← 1.6;
5 => vRef.suppressFactorForCells ← 2.6;
6 => vRef.suppressFactorForCells ← 0;
ENDCASE => vRef.suppressFactorForCells ← 1;
RepaintViewer[vRef]
END;
TicksInfoComm:
PROC[comm: CDSequencer.Command] =
BEGIN
newTick: INT ← -2;
lambda: INT ← comm.design.technology.lambda;
viewer: ViewerClasses.Viewer ← CDViewer.GetViewer[comm];
IF viewer#
NIL
THEN {
n: INT;
ticks: INT ← GetViewerInt[viewer, $Ticks];
TerminalIO.WriteF1["input tick (currently%g)\n", IO.rope[CDExtras.ToLambda[ticks, lambda]]];
n ← TerminalIO.RequestSelection[choice: LIST["off", " 4", " 8", " 16", " 32", "type", "type int"], 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 => {
n: INT ← TerminalIO.RequestInt["Ticks: "];
IF n>=0 AND n<=LAST[INTEGER]/lambda-1 THEN ticks ← n*lambda
};
7 => {
n: INT ← TerminalIO.RequestInt["Ticks (int): "];
IF n>=0 AND n<=LAST[INTEGER]-1 THEN ticks ← n
};
ENDCASE => NULL;
ViewerOps.SetViewer[viewer: viewer, data: NEW[INT←ticks], op: $Ticks];
newTick ← GetViewerInt[viewer, $Ticks];
};
IF newTick<-1 THEN TerminalIO.WriteRope[" failed\n"]
ELSE IF newTick<=0 THEN TerminalIO.WriteRope[" ticks off\n"]
ELSE TerminalIO.WriteF1[" ticks set to %g \n", IO.rope[CDExtras.ToLambda[newTick, lambda]]]
END;
InstanceNames:
PROC [comm: CDSequencer.Command] =
BEGIN
v: ViewerClasses.Viewer = CDViewer.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 = CDViewer.GetViewer[comm];
TerminalIO.WriteRope["display signal names\n"];
IF v#NIL THEN ViewerOps.PaintViewer[v, client, FALSE, $DrawSignalNames]
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 = CDViewer.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;
ShowRectX:
PROC [comm: CDSequencer.Command] =
BEGIN
SmallScale:
PROC [comm: CDSequencer.Command]
RETURNS [
BOOL] =
BEGIN
min: CD.Number = 30;
RETURN [min>ABS[comm.pos.x-comm.sPos.x] AND min>ABS[comm.pos.y-comm.sPos.y]]
END;
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;
savedScale: CDVScale.ScaleRec ← CDVScale.MakeScale[];
secondarySave: CDVScale.ScaleRec ← CDVScale.MakeScale[];
RestoreViewComm:
PROC [comm: CDSequencer.Command] =
BEGIN
scale: CDVScale.ScaleRec ← savedScale;
viewer: ViewerClasses.Viewer = CDViewer.GetViewer[comm];
TerminalIO.WriteRope["restore view\n"];
IF viewer#
NIL
THEN {
vRef: VRef = NARROW[viewer.data];
CDDrawQueue.Flush[vRef.ct];
--SaveScale[viewer]; NO you don't want that, its better to have one fixed point
IF vRef.scale.off=scale.off
AND vRef.scale.nscale=scale.nscale
THEN
scale ← secondarySave;
secondarySave ← vRef.scale;
vRef.intendedScale ← CDVScale.MakeScale[off: scale.off, nscale: scale.nscale, grid: vRef.scale.grid];
RepaintViewer[vRef];
}
END;
SaveScale :
PROC [viewer: ViewerClasses.Viewer] =
BEGIN
vRef: VRef = NARROW[viewer.data];
savedScale ← vRef.scale
END;
ShowRect:
PROC [comm: CDSequencer.Command] =
BEGIN
viewer: ViewerClasses.Viewer = CDViewer.GetViewer[comm];
TerminalIO.WriteRope["Scale viewer"];
SaveScale[viewer];
IF comm.pos=comm.sPos THEN CDViewer.ShowPosition[viewer: viewer, pos: comm.pos]
ELSE CDViewer.ShowAndScale[viewer: viewer, rect: CDBasics.ToRect[comm.pos, comm.sPos]];
WriteLnScale[viewer];
END;
ResetScaleComm:
PROC [comm: CDSequencer.Command] =
BEGIN
ResetScale:
PROC [viewer: ViewerClasses.Viewer] =
BEGIN
b: CD.Rect;
TerminalIO.WriteRope["reset scale (view all)"];
b ← CDExtras.BoundingBox[CDViewer.DesignOf[viewer]];
IF CDBasics.NonEmpty[b] THEN CDViewer.ShowAndScale[viewer: viewer, rect: b];
WriteLnScale[viewer];
END;
viewer: ViewerClasses.Viewer ← CDViewer.GetViewer[comm];
SaveScale[viewer];
ResetScale[viewer];
END;
ResetScaleToSelectedComm:
PROC [comm: CDSequencer.Command] =
BEGIN
b: CD.Rect;
viewer: ViewerClasses.Viewer = CDViewer.GetViewer[comm];
TerminalIO.WriteRope["reset scale to selection"];
b ← CDInstances.BoundingRectO[list: CDOps.InstList[comm.design], selectedOnly: TRUE];
IF CDBasics.NonEmpty[b]
THEN {
SaveScale[viewer];
CDViewer.ShowAndScale[viewer: viewer, rect: b];
WriteLnScale[viewer];
}
ELSE TerminalIO.WriteRope[" no selection\n"];
END;
ResetScaleToPushedComm:
PROC [comm: CDSequencer.Command] =
BEGIN
b: CD.Rect;
viewer: ViewerClasses.Viewer = CDViewer.GetViewer[comm];
SaveScale[viewer];
TerminalIO.WriteRope["reset scale (to view all of pushed cell)"];
b ← CDInstances.BoundingRectO[list: CDOps.InstList[comm.design], selectedOnly: FALSE];
IF CDBasics.NonEmpty[b] THEN CDViewer.ShowAndScale[viewer: viewer, rect: b];
WriteLnScale[viewer];
END;
DrawModeComm:
PROC [comm: CDSequencer.Command] =
BEGIN
vRef: VRef = 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.", "draw borders", "dont draw borders"],
label: "drawing modes"
];
SELECT n
FROM
1 => {
vRef.environment ← TRUE;
CDProperties.PutProp[comm.design, $CDxDrawEnvironment, NIL]
};
2 => {
vRef.environment ← FALSE;
CDProperties.PutProp[comm.design, $CDxDrawEnvironment, $FALSE]
};
3 => {
vRef.symbolics ← TRUE;
CDProperties.PutProp[comm.design, $CDxDrawSymbolics, NIL]
};
4 => {
vRef.symbolics ← FALSE;
CDProperties.PutProp[comm.design, $CDxDrawSymbolics, $FALSE]
};
5 => {
vRef.b4 ← FALSE;
CDProperties.PutProp[comm.design, $CDxSkipBorder, $FALSE]
};
6 => {
vRef.b4 ← TRUE;
CDProperties.PutProp[comm.design, $CDxSkipBorder, NIL]
};
6 => vRef.b2 ← TRUE;
7 => vRef.b2 ← FALSE;
ENDCASE => TerminalIO.WriteRope["skipped\n"];
IF n#0 THEN RepaintViewer[vRef]
END;
ShowViewers:
PROC [comm: CDSequencer.Command] =
BEGIN
vRef: VRef = NARROW[comm.ref];
TerminalIO.WriteRope["show viewers\n"];
CDDrawQueue.QueueInsertDrawCommand[vRef.ct, CDDrawQueue.Request[$ShowViewers, CDBasics.universe]]
END;
SplitViewer:
PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["split viewer\n"];
[] ← CDViewer.CreateViewer[comm.design]
END;
SetCellSimplification:
PROC [comm: CDSequencer.Command] =
BEGIN
scale: CDVScale.ScaleRec ← NARROW[comm.ref, VRef].scale;
TerminalIO.WriteRope["make selected cells barely visible\n"];
FOR l:
CD.InstanceList ← CDOps.InstList[comm.design], l.rest
WHILE l#
NIL
DO
IF l.first.selected
AND CDCells.IsCell[l.first.ob]
THEN {
cptr: CD.CellPtr ~ NARROW[l.first.ob.specificRef];
simplifyOn: CD.Number ← CDVScale.DesignToViewerScalar[scale, l.first.ob.size.y];
cptr.simplifyOn ← simplifyOn;
CDCommandOps.RedrawInstance[comm.design, l.first];
};
ENDLOOP;
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];
CDSequencer.ImplementCommand[$RestoreView, RestoreViewComm,, dontQueue];
CDSequencer.ImplementCommand[$SetCellSimplification, SetCellSimplification];
CDMenus.CreateEntry[$CellMenu, "visibility #", $CellSimplification];
CDMenus.CreateEntry[$CellMenu, "set visible", $SetCellSimplification];
END.