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,
CDApplications,
CDDraw,
CDExtras,
CDOps,
CDValue,
CDViewer,
CDVPrivate,
CDSequencer,
TerminalIO,
ViewerOps USING [PaintViewer],
ViewerClasses USING [Viewer],
CDInline;
CDVCommands:
CEDAR
PROGRAM
IMPORTS CDApplications, CDDraw, CDExtras, CDOps, 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", "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;
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;
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;
ResetScaleToSelectedComm:
PROC [comm: CDSequencer.Command] =
BEGIN
b: CD.DesignRect;
mySheet: MyGraphicRef = NARROW[comm.ref];
TerminalIO.WriteRope["reset scale to selection\n"];
b ← CDApplications.BoundingRect[list: CDOps.AppList[comm.design], selectedOnly: TRUE];
IF CDInline.NonEmpty[b] THEN CDViewer.ShowAndScale[viewer: mySheet.viewer, rect: b]
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 pused level\n"];
b ← CDApplications.BoundingRect[list: CDOps.AppList[comm.design], selectedOnly: FALSE];
IF CDInline.NonEmpty[b] THEN CDViewer.ShowAndScale[viewer: mySheet.viewer, rect: b];
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,, doQueue];
CDSequencer.ImplementCommand[$ScaleMoreDetail, ScaleUp,, doQueue];
CDSequencer.ImplementCommand[$MoveScreen, MoveScreen,, doQueue];
CDSequencer.ImplementCommand[$DisplayNames, SignalNames,, doQueue];
CDSequencer.ImplementCommand[$ShowRectX, ShowRectX,, doQueue];
CDSequencer.ImplementCommand[$ShowRect, ScaleToRect,, doQueue];
--old-- CDSequencer.ImplementCommand[$ResetScale, ResetScaleComm,, doQueue];
CDSequencer.ImplementCommand[$ResetScaleAll, ResetScaleComm,, doQueue];
CDSequencer.ImplementCommand[$ResetScaleTop, ResetScaleToPushedComm,, doQueue];
CDSequencer.ImplementCommand[$ResetScaleSel, ResetScaleToSelectedComm,, doQueue];
CDSequencer.ImplementCommand[$DisplayViewers, ShowViewers,, doQueue];
CDSequencer.ImplementCommand[$SplitViewer, SplitViewer,, doQueue];
CDSequencer.ImplementCommand[$GridInfo, GridInfoComm,, doQueue];
CDSequencer.ImplementCommand[$TicksInfo, TicksInfoComm,, doQueue];
CDSequencer.ImplementCommand[$DrawMode, DrawModeComm,, doQueue];
CDSequencer.ImplementCommand[$SetSimplification, SetSimplificationComm,, doQueue];
END;
Impl[];
END.