CDCellCommands.mesa (part of ChipNDale)
Copyright © 1983, 1985 by Xerox Corporation. All rights reserved.
by Christian Jacobi, July 11, 1983 3:42 pm
last edited by Christian Jacobi, July 1, 1985 12:08:09 pm PDT
DIRECTORY
Ascii,
CD,
CDCells,
CDCommandOps,
CDDirectory,
CDDirectoryOps,
CDOps,
CDSequencer,
TerminalIO,
Rope;
CDCellCommands: CEDAR PROGRAM
IMPORTS Ascii, CDOps, CDCells, CDCommandOps, CDDirectory, CDDirectoryOps, CDSequencer, Rope, TerminalIO =
BEGIN
orientForTest: CD.Orientation ← 0;
obCSystemForTest: CDCells.CoordSystem ← interrestCoords;
DrawCellComm: PROC [comm: CDSequencer.Command] =
BEGIN
name: Rope.ROPE;
cellOb: CD.Object;
found: BOOLEAN;
TerminalIO.WriteRope["Include cell; "];
DO
name ← TerminalIO.RequestRope["type name\n"! TerminalIO.UserAbort => {GOTO aborted}];
[found, cellOb] ← CDDirectory.Fetch[comm.design, name];
IF found THEN {
inst: CD.Instance = CDCells.IncludeOb[design: comm.design,
ob: cellOb,
position: comm.pos,
obCSystem: obCSystemForTest,
orientation: orientForTest
].newInst;
CDCommandOps.RedrawInstance[comm.design, inst, FALSE];
TerminalIO.WriteRope[name];
TerminalIO.WriteRope[" inserted\n"];
RETURN
};
TerminalIO.WriteRope[name]; TerminalIO.WriteRope[" not found\n"];
IF NOT TerminalIO.UserSaysYes[label: "another try ?"
! TerminalIO.UserAbort => {GOTO aborted}] THEN RETURN;
ENDLOOP
EXITS
aborted => NULL;
END;
DeleteCellComm: PROC [comm: CDSequencer.Command] =
BEGIN
name, msg: Rope.ROPENIL;
done: BOOL;
ob: CD.Object;
TerminalIO.WriteRope["remove object from directory; "];
name ← TerminalIO.RequestRope["type name\n"];
[done, ob] ← CDDirectory.Fetch[comm.design, name];
IF ~done OR ob=NIL THEN {
TerminalIO.WriteRope[name]; TerminalIO.WriteRope[" not found\n"];
RETURN
};
[done, msg] ← CDDirectoryOps.RemoveObjectFromDirectory[comm.design, ob];
TerminalIO.WriteRope[msg];
IF ~done THEN TerminalIO.WriteRope[" not "];
TerminalIO.WriteRope["done\n"];
END;
DisplayCellNames: PROC [comm: CDSequencer.Command] =
BEGIN
EachEntryDisplay: CDDirectory.EachEntryAction
--[name: Rope.ROPE, ob: CD.Object] RETURNS [quit: BOOL] -- =
BEGIN
quit ← FALSE;
count ← count+1;
IF comm.a=$RestricedDisplayCellNames THEN {
IF Rope.Length[name]<=0 THEN RETURN
ELSE {
ch: CHAR = Rope.Fetch[name];
IF ~Ascii.Letter[ch] AND ~Ascii.Digit[ch] THEN RETURN
}
};
displayed ← displayed+1;
WITH ob.specificRef SELECT FROM
cp: CD.CellPtr => {
TerminalIO.WriteRope[" "];
TerminalIO.WriteRope[cp.name];
};
ENDCASE => {
TerminalIO.WriteRope[" ("]; TerminalIO.WriteRope[name];
TerminalIO.WriteRope[") "];
TerminalIO.WriteRope[CDOps.Info[ob]];
};
TerminalIO.WriteLn[];
END;
count: INT ← 0;
displayed: INT ← 0;
TerminalIO.WriteRope["Display object names\n"];
IF CDDirectory.Enumerate[comm.design, EachEntryDisplay] THEN TerminalIO.WriteRope["stopped\n"];
TerminalIO.WriteInt[count];
TerminalIO.WriteRope[" objects counted "];
IF count#displayed THEN {
TerminalIO.WriteInt[displayed];
TerminalIO.WriteRope[" displayed"];
};
TerminalIO.WriteLn[]
END;
CreateCellAndName: PROC [comm: CDSequencer.Command] =
BEGIN
done: BOOL;
TerminalIO.WriteRope["Create cell "];
[done: done] ← CDCells.CreateCellSelected[comm.design];
IF ~done THEN TerminalIO.WriteRope[" not done\n"];
END;
CreateCellDefaultName: PROC [comm: CDSequencer.Command] =
BEGIN
done: BOOL;
TerminalIO.WriteRope["Create cell without name\n"];
[done: done] ← CDCells.CreateCellSelected[comm.design, "-no name-"];
IF ~done THEN TerminalIO.WriteRope[" not done\n"];
END;
PushIntoCellS: PROC [comm: CDSequencer.Command] =
BEGIN
Expand: PROC [inst: CD.Instance] RETURNS [ob: CD.Object] =
BEGIN
ob ← CDDirectory.Expand[inst.ob, comm.design, comm.design];
IF ob=NIL THEN TerminalIO.WriteRope["expand failed\n"]
ELSE TerminalIO.WriteRope["object expanded\n"];
END;
inst: CD.Instance ← CDCommandOps.TheInstance[comm: comm, text: "Push into cell "];
IF inst#NIL THEN {
WHILE ~CDCells.IsCell[inst.ob] DO
TerminalIO.WriteRope[CDOps.Info[inst.ob]];
TerminalIO.WriteRope[" is not cell;"];
IF ~ inst.ob.class.inDirectory THEN CDSequencer.QuitCommand[" not done"];
SELECT TerminalIO.RequestSelection[label: "convert to cell?",
choice: LIST["all instances", "this instance"],
text: " convert to cell?\n",
default: 1] FROM
1 => {--all instances
ob: CD.Object ← Expand[inst];
IF ob=NIL THEN RETURN;
CDSequencer.MarkChanged[comm.design];
CDDirectory.ReplaceObject[design: comm.design, old: inst.ob, new: ob]
};
2 => {--this instance
ob: CD.Object ← Expand[inst];
IF ob=NIL THEN RETURN;
CDSequencer.MarkChanged[comm.design];
inst.ob ← ob;
};
ENDCASE => CDSequencer.QuitCommand["no expansion; not done"];
ENDLOOP;
IF CDCells.PushInCellInstance[comm.design, inst] THEN TerminalIO.WriteRope["done\n"]
ELSE TerminalIO.WriteRope["not done\n"];
};
END;
PopFromCellMenu: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["pop\n"];
IF ~CDCells.PopFromCell[comm.design, interactive] THEN
TerminalIO.WriteRope[" not done\n"];
END;
PopFromCellFlush: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["pop and flush\n"];
IF ~CDCells.PopFromCell[comm.design, flush] THEN
TerminalIO.WriteRope[" not done\n"];
END;
PopFromCellReplace: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["pop and replace\n"];
IF ~CDCells.PopFromCell[comm.design, replace] THEN
TerminalIO.WriteRope[" not done\n"];
END;
PopFromCellNew: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["pop and new\n"];
IF ~CDCells.PopFromCell[comm.design, newcell] THEN
TerminalIO.WriteRope[" not done\n"];
END;
CleanUpDirectoryComm: PROC [comm: CDSequencer.Command] =
BEGIN
autoOnly: BOOL;
TerminalIO.WriteRope["Clean up directory\n"];
autoOnly ← comm.a#$DeleteUnUsedObjects;
CDDirectoryOps.CleanUpDirectory[design: comm.design, autoOnly: autoOnly, askFirst: TRUE];
END;
SetSimplification: PROC [comm: CDSequencer.Command] =
BEGIN
ap: CD.Instance;
multiple: BOOL;
TerminalIO.WriteRope["Set cell simplification\n"];
[ap, multiple] ← CDOps.SelectedInstance[comm.design];
IF multiple THEN TerminalIO.WriteRope[" multiple selection; not done\n"]
ELSE IF ap=NIL THEN TerminalIO.WriteRope[" no selection; not done\n"]
ELSE {
TerminalIO.WriteRope[ap.ob.class.describe[ap.ob]];
IF ISTYPE[ap.ob.specificRef, CD.CellPtr] THEN {
cptr: CD.CellPtr ~ NARROW[ap.ob.specificRef];
TerminalIO.WriteRope[" [currently: simplification if height < "];
TerminalIO.WriteInt[cptr.simplifyOn];
cptr.simplifyOn ← MIN[
MAX[
TerminalIO.RequestInt[" pixels] type > "],
0],
LAST[NAT]
];
TerminalIO.WriteRope[" done\n"]
}
ELSE TerminalIO.WriteRope[" not a cell; not done\n"];
}
END;
RenameComm: PROC [comm: CDSequencer.Command] =
BEGIN
RenameAppOb: PROC[design: CD.Design, ap: CD.Instance] =
BEGIN
done: BOOLFALSE;
IF ap=NIL THEN TerminalIO.WriteRope[" no object;\n"]
ELSE {
TerminalIO.WriteRope[ap.ob.class.describe[ap.ob]];
IF NOT ap.ob.class.inDirectory THEN TerminalIO.WriteRope[" object can not have name;\n"]
ELSE {
newName: Rope.ROPE ← TerminalIO.RequestRope[" new name > "];
IF Rope.IsEmpty[newName] THEN newName ← "-";
done ← CDDirectory.Rename[design, ap.ob, newName];
};
};
IF done THEN TerminalIO.WriteRope["done\n"] ELSE TerminalIO.WriteRope[" not done\n"]
END;
ap: CD.Instance = CDCommandOps.TheInstance[comm];
IF ap#NIL THEN RenameAppOb[comm.design, ap]
END;
ReplaceComm: PROC [comm: CDSequencer.Command] =
BEGIN
name: Rope.ROPE;
old, new: CD.Object;
found: BOOLEAN;
TerminalIO.WriteRope["replace an entry allover in the design\n"];
name ← TerminalIO.RequestRope[" replace (name) > "];
[found, old] ← CDDirectory.Fetch[comm.design, name];
IF found THEN {
name ← TerminalIO.RequestRope[" by (name) > "];
[found, new] ← CDDirectory.Fetch[comm.design, name];
};
IF ~found THEN {
TerminalIO.WriteRope[" "];
TerminalIO.WriteRope[name];
TerminalIO.WriteRope[" not found\n"];
}
ELSE {
offset: CD.Position← [0, 0];
TerminalIO.WriteRope[" do you want to specify an offset?\n"];
IF TerminalIO.UserSaysYes[label: "offset", default: FALSE] THEN {
offset.x ← TerminalIO.RequestInt[" x in lambda >"]*CD.lambda;
offset.y ← TerminalIO.RequestInt[" y in lambda >"]*CD.lambda;
};
CDDirectory.ReplaceObject[design: comm.design, old: old, new: new, off: offset];
TerminalIO.WriteRope[" end replace\n"];
}
END;
CDSequencer.ImplementCommand[$PopMenu, PopFromCellMenu,, doQueue];
CDSequencer.ImplementCommand[$PopNew, PopFromCellNew,, doQueue];
CDSequencer.ImplementCommand[$PopFlush, PopFromCellFlush,, doQueue];
CDSequencer.ImplementCommand[$PopReplace, PopFromCellReplace,, doQueue];
CDSequencer.ImplementCommand[$PushS, PushIntoCellS,, doQueue];
CDSequencer.ImplementCommand[$CreateCellSAndName, CreateCellAndName];
CDSequencer.ImplementCommand[$CreateCellSUnNamed, CreateCellDefaultName];
CDSequencer.ImplementCommand[$DisplayCellNames, DisplayCellNames,, doQueue];
CDSequencer.ImplementCommand[$RestricedDisplayCellNames, DisplayCellNames,, doQueue];
CDSequencer.ImplementCommand[$DrawCell, DrawCellComm];
CDSequencer.ImplementCommand[$RemoveCell, DeleteCellComm,, doQueue];
CDSequencer.ImplementCommand[$DeleteUnUsedObjects, CleanUpDirectoryComm,, doQueue];
CDSequencer.ImplementCommand[$DeleteUnUsedAutoObs, CleanUpDirectoryComm,, doQueue];
CDSequencer.ImplementCommand[$CellSimplification, SetSimplification,, doQueue];
CDSequencer.ImplementCommand[$RenameS, RenameComm,, doQueue];
CDSequencer.ImplementCommand[$Replace, ReplaceComm];
END.