CDRepetitionCommands.mesa (part of ChipNDale)
Copyright © 1983, 1984, 1986 by Xerox Corporation. All rights reserved.
Created by Christian Jacobi, July 11, 1983 3:42 pm
Last edited by: Christian Jacobi, October 23, 1986 10:40:18 am PDT
DIRECTORY
CD,
CDBasics,
CDCellsInteractions,
CDDirectory,
CDOps,
CDRepetitions,
CDSequencer,
Rope,
TerminalIO;
CDRepetitionCommands: CEDAR PROGRAM
IMPORTS CDCellsInteractions, CDOps, CDBasics, CDRepetitions, CDSequencer, TerminalIO =
BEGIN
MakeRepetition: PROC [comm: CDSequencer.Command] = {
ob: CD.Object; offset: CD.Position; count: INT;
inst: CD.Instance; multiple: BOOL;
TerminalIO.PutRope["make a repetition "];
[inst, multiple] ← CDOps.SelectedInstance[comm.design];
IF inst=NIL THEN {TerminalIO.PutRope["no selected object\n"]; RETURN};
count ← TerminalIO.RequestInt["number: "];
IF count<1 OR count>=LAST[NAT] THEN {
TerminalIO.PutRope["bad number\n"]; RETURN
};
IF count>=257 THEN {
TerminalIO.PutRope["don't exagerate\n"]; RETURN
};
IF multiple THEN {
[done: multiple, cellInst: inst] ← CDCellsInteractions.CreateCellSelected[comm.design, "-dummy"];
IF NOT multiple OR inst=NIL THEN {TerminalIO.PutRope["not done\n"]; RETURN};
};
offset ← [comm.pos.x-comm.sPos.x, comm.pos.y-comm.sPos.y];
ob ← CDRepetitions.CreateRepetition[comm.design, inst.ob, count, offset, inst.trans.orient];
inst.ob ← ob;
inst.trans.orient ← original;
CDOps.RedrawInstance[comm.design, inst];
};
ChangeRepetition: PROC [comm: CDSequencer.Command] = {
inst: CD.Instance = CDOps.TheInstance[comm.design, "change a repetition\n"];
IF inst#NIL THEN
IF ~ISTYPE[inst.ob.specific, CDRepetitions.RepSpecific] THEN
TerminalIO.PutRope[" selected ob not a repetition"]
ELSE {
offset: CD.Position = [comm.pos.x-comm.sPos.x, comm.pos.y-comm.sPos.y];
rp: CDRepetitions.RepSpecific = NARROW[inst.ob.specific];
CDOps.RedrawInstance[comm.design, inst];
inst.ob ← CDRepetitions.CreateRepetition[comm.design, rp.ob, rp.count, offset, CDBasics.ComposeOrient[rp.orientation, inst.trans.orient]];
inst.trans.orient ← original;
CDOps.RedrawInstance[comm.design, inst, FALSE];
TerminalIO.PutRope[" done\n"]
};
};
IncCount: PROC [comm: CDSequencer.Command] = {
inst: CD.Instance = CDOps.TheInstance[comm.design, "inc count of a repetition\n"];
IF inst#NIL THEN
IF ~ISTYPE[inst.ob.specific, CDRepetitions.RepSpecific] THEN TerminalIO.PutRope[" selected ob not a repetition"]
ELSE {
rptr: CDRepetitions.RepSpecific ← NARROW[inst.ob.specific];
newOb: CD.Object = CDRepetitions.CreateRepetition[comm.design, rptr.ob, rptr.count+1, rptr.offset, rptr.orientation];
IF newOb#NIL THEN inst.ob ← newOb;
CDOps.RedrawInstance[comm.design, inst, FALSE];
};
};
DecCount: PROC [comm: CDSequencer.Command] = {
inst: CD.Instance = CDOps.TheInstance[comm.design, "inc count of a repetition\n"];
IF inst#NIL THEN
IF ~ISTYPE[inst.ob.specific, CDRepetitions.RepSpecific] THEN TerminalIO.PutRope[" selected ob not a repetition"]
ELSE {
newOb: CD.Object ← NIL;
rptr: CDRepetitions.RepSpecific ← NARROW[inst.ob.specific];
IF rptr.count>1 THEN
newOb ← CDRepetitions.CreateRepetition[comm.design, rptr.ob, rptr.count-1, rptr.offset, rptr.orientation];
CDOps.RedrawInstance[comm.design, inst];
IF newOb#NIL THEN inst.ob ← newOb
};
};
AllRepetitionsToCells: PROC [comm: CDSequencer.Command] = {
n: NAT ← 0;
repList: LIST OF CD.Object ← NIL;
--we make a list first, otherwise: directory changes while the enumeration
FindRepetitions: CDDirectory.EachEntryAction = {
IF CDRepetitions.IsRepetition[ob] THEN repList ← CONS[ob, repList]
};
TerminalIO.PutRope["transform all repetitions to cells\n"];
[] ← CDDirectory.Enumerate[design: comm.design, action: FindRepetitions];
FOR list: LIST OF CD.Object ← repList, list.rest WHILE list#NIL DO
name: Rope.ROPE ← CDDirectory.Name[list.first];
rCell: CD.Object ← CDDirectory.Expand[list.first, comm.design, comm.design];
IF rCell=NIL THEN
TerminalIO.PutRope[Rope.Cat["** ", name, " not transformed\n"]]
ELSE {
[] ← CDDirectory.Remove[design: comm.design, name: name, expectObject: list.first];
[] ← CDDirectory.Rename[design: comm.design, object: rCell, newName: name];
n ← n+1;
CDDirectory.ReplaceObject[design: comm.design, old: list.first, new: rCell];
TerminalIO.PutRope[Rope.Cat[" cell ", CDDirectory.Name[rCell], " generated\n"]]
};
ENDLOOP;
TerminalIO.WriteInt[n]; TerminalIO.PutRope[" repetitions transformed\n"];
};
CDSequencer.ImplementCommand[$DrawRepetition, MakeRepetition];
CDSequencer.ImplementCommand[$ChangeRepetition, ChangeRepetition];
CDSequencer.ImplementCommand[$IncRepetition, IncCount];
CDSequencer.ImplementCommand[$DecRepetition, DecCount];
END.