CDDisplayInX.mesa
Copyright Ó 1989 by Xerox Corporation. All rights reserved.
Created by Bryan Preas, May 23, 1989 4:37:54 pm PDT
DIRECTORY
CD,
CDBasics,
CDColors,
CDIO,
CDOps,
CDViewer,
Commander,
Convert,
Imager,
ImagerBackdoor,
ImagerBox,
ImagerSample,
Process,
Rope,
SF,
TerminalIO,
Vector2,
ViewerClasses,
X11,
X11Access,
X11BitmapWidgets,
X11Tk,
X11Widgets;
CDDisplayInX:
CEDAR
MONITOR
IMPORTS CD, CDColors, CDIO, CDOps, CDViewer, Commander, Convert, Imager, ImagerBackdoor, ImagerBox, ImagerSample, Process, Rope, TerminalIO, Vector2, X11, X11Access, X11BitmapWidgets, X11Tk, X11Widgets =
Widget: TYPE = X11Widgets.Widget;
initialSize: REAL ← 1.0;
-- global frame varibles
connection: X11.Connection ← NIL;
globalSpec: XSpec ← NIL;
--these three lines are for debugging reasons, and should not be in a sample tool
synchronized: BOOL ← FALSE;
screen: INT ← 0;
server: Rope.ROPE ← "dana";
server: Rope.ROPE ← "clarissa";
XSpec: TYPE = REF XSpecRec;
XSpecRec:
TYPE =
RECORD [
connection: X11.Connection ← NIL,
name: Rope.ROPE ← NIL,
design: CD.Design ← NIL,
layers: ARRAY CD.Layer OF BOOLEAN ← ALL[TRUE],
bitmap: Widget ← NIL,
magnification: Widget ← NIL,
moveVector: Imager.VEC ← [0.0, 0.0]
];
LayerSpec: TYPE = REF LayerRec;
LayerRec:
TYPE =
RECORD [
layerKey: ATOM ← NIL,
statusKey: ATOM ← NIL
];
DestroyHit: X11Widgets.ButtonHitProcType = {
X11Widgets.DestroyTopLevel[NARROW[key]];
};
SetLayer: X11Widgets.ButtonHitProcType = {
i: XSpec ← NARROW[clientData];
compoundKey: LayerSpec ← NARROW[key];
layerKey: ATOM ← compoundKey.layerKey;
statusKey: ATOM ← compoundKey.statusKey;
layer: CD.Layer ← CD.FetchLayer[i.design.technology, layerKey];
i.layers[layer] ← statusKey = $on;
};
ResetHit: X11Widgets.ButtonHitProcType = {
i: XSpec ← NARROW[clientData];
X11Widgets.SetText[i.magnification, Convert.RopeFromReal[initialSize], immediately];
i.moveVector ← [0.0, 0.0];
DoDraw[i];
};
MoveHit: X11Widgets.ButtonHitProcType = {
i: XSpec ← NARROW[clientData];
dX: REAL ← i.bitmap.s.size.width/2.0;
dY: REAL ← i.bitmap.s.size.height/2.0;
dXY: Imager.
VEC ←
SELECT key
FROM
$left => [-dX, 0.0],
$right => [dX, 0.0],
$up => [0.0, dY],
$down => [0.0, -dY],
ENDCASE => [0.0, 0.0];
i.moveVector ← Vector2.Add[i.moveVector, dXY];
DoDraw[i];
};
GrowShrinkHit: X11Widgets.ButtonHitProcType = {
i: XSpec ← NARROW[clientData];
oldScale: REAL ← Convert.RealFromRope[X11Widgets.GetText[i.magnification]];
newScale:
REAL ←
SELECT key
FROM
$grow => MIN[oldScale*2.0, 100.0],
$shrink => MAX[oldScale/2.0, 0.01],
ENDCASE => oldScale;
X11Widgets.SetText[i.magnification, Convert.RopeFromReal[newScale], immediately];
DoDraw[i];
};
MyDrawChild:
CD.DrawProc = {
PROC [pr: CD.DrawRef, ob: CD.Object, trans: CD.Transformation←[], readOnlyInstProps: CD.PropList←NIL];
CD.DrawOb[ob: ob, trans: trans, pr: pr, readOnlyInstProps: readOnlyInstProps];
};
MyDrawRect:
CD.DrawRectProc = {
PROC [pr: CD.DrawRef, r: CD.Rect, l: CD.Layer];
-- must have a better to pass context to DrawProc !!
IF globalSpec.layers[l]
THEN {
Imager.SetColor[pr.deviceContext, pr.contextColors[l]];
Imager.MaskBox[pr.deviceContext, [xmin: r.x1, ymin: r.y1, xmax: r.x2, ymax: r.y2]]};
};
DrawHit: X11Widgets.ButtonHitProcType = {
i: XSpec ← NARROW[clientData];
DoDraw[i];
};
DoDraw:
PROC [i: XSpec] ~ {
ct: Imager.Context ← X11BitmapWidgets.CreateContext[i.bitmap];
boundsRect: Imager.Rectangle ← ImagerBackdoor.GetBounds[ct];
boundsBox: Imager.Box ← ImagerBox.BoxFromRectangle[boundsRect];
scale: REAL ← Convert.RealFromRope[X11Widgets.GetText[i.magnification]];
instance: CD.Instance ← CDOps.SelectedInstance[design: i.design].first;
myDrawRef:
CD.DrawRef ←
CD.CreateDrawRef[[
interestClip: CDBasics.universe,
drawChild: MyDrawChild,
drawRect: MyDrawRect,
deviceContext: ct,
design: i.design,
contextColors: CDColors.globalColors[bw][normal].cols
]];
Imager.SetColor[ct, Imager.white]; Imager.MaskBox[ct, boundsBox];
Imager.TranslateT[ct, i.moveVector];
Imager.ScaleT[ct, scale];
globalSpec ← i;
IF instance # NIL THEN CD.DrawOb[myDrawRef, instance.ob, instance.trans, instance.properties];
myDrawRef ← NIL; globalSpec ← NIL;
};
BitmapChanged: X11BitmapWidgets.BitmapEventProc = {
i: XSpec ← NARROW[X11Tk.GetWidgetProp[widget, $CDDrawInX]];
IF i#
NIL
THEN {
IF reason#terminate
THEN {
sm: ImagerSample.SampleMap ← ImagerSample.NewSampleMap[box: [[0, 0], [widget.s.size.height, widget.s.size.width]]];
X11BitmapWidgets.SetBitmap[widget, sm, SF.maxBox, FALSE];
DoDraw[i];
};
};
};
CreateLayerWidget:
PROC [text: Rope.
ROPE, layerKey:
ATOM, i: XSpec]
RETURNS [widget: Widget] ~ {
header: Widget ← X11Widgets.CreateLabel[
widgetSpec: [borderWidth: 1],
textSpec: [text: text]
];
toggle: Widget ← X11Widgets.CreateToggle[
widgetSpec: [borderWidth: 1],
choices:
LIST [
["on", NEW[LayerRec ← [layerKey: layerKey, statusKey: $on]]],
["off", NEW[LayerRec ← [layerKey: layerKey, statusKey: $off]]]],
hitProc: SetLayer, clientData: i
];
widget ← X11Widgets.CreateYStack[[], LIST[header, toggle]];
};
CreateTopWidget:
PROC [connection:
X11.Connection, design:
CD.Design, name: Rope.
ROPE] = {
i: XSpec ← NEW[XSpecRec ← [connection: connection, name: name, design: design]];
top: Widget ← X11Widgets.CreateTopLevel[
parentWindow: X11.GetScreens[connection][screen].root,
connection: i.connection, windowHeader: Rope.Cat["ChipNDale: ", name]
];
bitmap: Widget ← X11BitmapWidgets.CreateBitmapWidget[
widgetSpec: [size: [1000, 1000], borderWidth: 1],
notify: BitmapChanged
];
levels: Widget ← X11Widgets.CreateXStack[[],
LIST[CreateLayerWidget["ndif", $ndif, i],
CreateLayerWidget["pdif", $pdif, i],
CreateLayerWidget["pwell", $pwell, i],
CreateLayerWidget["nwell", $nwell, i],
CreateLayerWidget["pwCont", $pwellCont, i],
CreateLayerWidget["nwCont", $nwellCont, i],
CreateLayerWidget["wndif", $wndif, i],
CreateLayerWidget["wpdif", $wpdif, i],
CreateLayerWidget["wpwellCont", $wpwellCont, i],
CreateLayerWidget["wnwellCont", $wnwellCont, i],
CreateLayerWidget["pol", $pol, i],
CreateLayerWidget["met", $met, i],
CreateLayerWidget["met2", $met2, i],
CreateLayerWidget["ovg", $ovg, i],
CreateLayerWidget["cut", $cut, i],
CreateLayerWidget["cut2", $cut2, i],
CreateLayerWidget["imp", $imp, i],
CreateLayerWidget["bur", $bur, i],
CreateLayerWidget["bond", $bond, i]]];
redraw: Widget ← X11Widgets.CreateButton[
widgetSpec: [borderWidth: 1],
textSpec: [text: "redraw"],
hitProc: DrawHit, clientData: i
];
destroy: Widget ← X11Widgets.CreateButton[
widgetSpec: [borderWidth: 1],
textSpec: [text: "destroy"],
hitProc: DestroyHit, key: top
];
action: Widget ← X11Widgets.CreateXStack[[], LIST[redraw, destroy]];
reset: Widget ← X11Widgets.CreateButton[
widgetSpec: [borderWidth: 1],
textSpec: [text: "reset"],
hitProc: ResetHit, clientData: i
];
left: Widget ← X11Widgets.CreateButton[
widgetSpec: [borderWidth: 1],
textSpec: [text: "left"],
hitProc: MoveHit, clientData: i, key: $left
];
right: Widget ← X11Widgets.CreateButton[
widgetSpec: [borderWidth: 1],
textSpec: [text: "right"],
hitProc: MoveHit, clientData: i, key: $right
];
up: Widget ← X11Widgets.CreateButton[
widgetSpec: [borderWidth: 1],
textSpec: [text: "up"],
hitProc: MoveHit, clientData: i, key: $up
];
down: Widget ← X11Widgets.CreateButton[
widgetSpec: [borderWidth: 1],
textSpec: [text: "down"],
hitProc: MoveHit, clientData: i, key: $down
];
grow: Widget ← X11Widgets.CreateButton[
widgetSpec: [borderWidth: 1],
textSpec: [text: "grow"],
hitProc: GrowShrinkHit, clientData: i, key: $grow
];
shrink: Widget ← X11Widgets.CreateButton[
widgetSpec: [borderWidth: 1],
textSpec: [text: "shrink"],
hitProc: GrowShrinkHit, clientData: i, key: $shrink
];
magnification: Widget ← X11Widgets.CreateField[
widgetSpec: [borderWidth: 1],
textSpec: [text: Convert.RopeFromReal[initialSize]]];
controls: Widget ← X11Widgets.CreateXStack[[], LIST[reset, left, right, up, down, grow, shrink, magnification]];
contents: Widget ← X11Widgets.CreateYStack[[], LIST[action, controls, levels, bitmap]];
i.bitmap ← bitmap;
i.magnification ← magnification;
X11Tk.PutWidgetProp[bitmap, $CDDrawInX, i];
X11Widgets.SetTopChild[top, contents];
X11Widgets.RealizeTopLevel[top];
};
Start: Commander.CommandProc ~ {
designName: Rope.ROPE ← TerminalIO.RequestRope[prompt: "Enter design name: "];
design: CD.Design ← CDViewer.FindDesign[name: designName];
IF design =
NIL
THEN {
design ← CDIO.ReadDesign[from: designName, wDir: CDIO.GetWorkingDirectory[]];
CDOps.SetMutability[design: design, mutability: editable];
[] ← CDViewer.CreateViewer[design: design, openPanel: FALSE]};
IF connection=
NIL
THEN {
s: Rope.ROPE ← IF Rope.IsEmpty[server] THEN X11Access.GetServerName[] ELSE server;
connection ← X11.CreateConnection[server: s, debugHelp: $demo, synchronized: synchronized];
};
IF screen<0 OR screen>=X11.ScreenCount[connection] THEN screen ← 0;
CreateTopWidget[connection, design, designName];
};
Stop: Commander.CommandProc ~ {
IF connection#
NIL
THEN {
TRUSTED {Process.Detach[FORK X11.CloseConnection[connection]]};
connection ← NIL;
};
};
Commander.Register["CDDemo", Start, "Create widget demo tool"];
Commander.Register["CDStop", Stop, "Stop widget demo tools"];
END.