CDMacroImpl.mesa (part of Chipndale)
by Christian Jacobi April 23, 1984 5:18:54 pm PST
last edited Christian Jacobi March 23, 1984 8:45:25 am PST
DIRECTORY
CD,
CDApplications,
CDCells,
CDDirectory,
CDInline,
CDOps,
CDOrient,
CDSequencer,
Process,
Rope,
TerminalIO;
CDMacroImpl:
CEDAR
PROGRAM
IMPORTS CD, CDApplications, CDCells, CDInline, CDOps, CDOrient, CDSequencer, Process, Rope, TerminalIO
SHARES CD, CDDirectory =
BEGIN
pForMacro: REF CD.ObjectProcs = CD.RegisterObjectType[$Macro];
pForCells: REF READONLY CD.ObjectProcs = CDCells.CreateEmptyCell[].p;
CellToMacro:
PROC[ob:
CD.ObPtr] =
BEGIN
TerminalIO.WriteRope["**CellToMacro called "];
IF ob=NIL OR ob.specificRef=NIL THEN TerminalIO.WriteRope["bad object\n"]
ELSE IF NOT ISTYPE[ob.specificRef, CD.CellPtr] THEN TerminalIO.WriteRope["object not cell\n"]
ELSE {
ob.p ← pForMacro;
TerminalIO.WriteRope[" done\n"]
}
END;
MacroAdjust:
PROC [ob:
CD.ObPtr, newBound:
CD.DesignRect] =
BEGIN
TerminalIO.WriteRope["**MacroAdjust called "];
IF ob=NIL OR ob.specificRef=NIL THEN TerminalIO.WriteRope["bad object\n"]
ELSE IF NOT ISTYPE[ob.specificRef, CD.CellPtr] THEN TerminalIO.WriteRope["object not cell\n"]
ELSE {
adjustItself: CDDirectory.AdjustItselfProc =
NARROW[pForCells.directoryProcs, REF CDDirectory.DirectoryProcs]^.adjustItself;
adjustItself[ob, newBound];
TerminalIO.WriteRope[" done\n"]
}
END;
Describe:
PROC[me:
CD.ObPtr]
RETURNS [Rope.
ROPE] =
BEGIN
cptr: CD.CellPtr = NARROW[me.specificRef];
RETURN [Rope.Concat["special cell ", cptr.name]]
END;
AdjustItself: CDDirectory.AdjustItselfProc
-- PROC [objToReposition: CD.ObPtr, newBound: CD.DesignRect] -- =
BEGIN
--don't do that accidently
END;
RepositionElements: CDDirectory.RepositionElementsProc
-- PROC [me: CD.ObPtr, objToReposition: CD.ObPtr, oldSize: CD.DesignPosition, newBound: CD.DesignRect, design: CD.Design] -- =
BEGIN
--don't do that
END;
ComputeBounds: CDDirectory.ComputeBoundsProc
-- PROC [ob: CD.ObPtr] RETURNS [CD.DesignRect] -- =
BEGIN
--here you cheat; therefore this tye is made !!!!!!!
RETURN [[x1: 0, y1: 0, x2: ob.size.x, y2: ob.size.y]];
END;
InternalRead:
CD.InternalReadProc
--PROC [] RETURNS [ObPtr]-- =
BEGIN
ob: CD.ObPtr ← pForCells.internalRead[];
ob.p ← pForMacro;
RETURN [ob]
END;
MakeSubClass:
PROC[me:
REF
CD.ObjectProcs, from:
REF
READONLY
CD.ObjectProcs] =
--me, from must have been registered!
--does NOT subClass the furtherprocs
BEGIN
dummy: REF CD.ObjectProcs ← NEW[CD.ObjectProcs𡤏rom^];
--handle the following fields specially
dummy.further ← me.further;
dummy.technology ← me.technology;
dummy.objectType ← me.objectType;
--handle directory
IF dummy.hasChildren
THEN {
dummy.directoryProcs ←
NEW[CDDirectory.DirectoryProcs←
NARROW[from.directoryProcs, REF CDDirectory.DirectoryProcs]^
];
};
--do overwrite all the other fields
me^ ← dummy^;
END;
DrawSelection:
PROC [aptr:
CD.ApplicationPtr, pos:
CD.DesignPosition, orient:
CD.Orientation,
pr: CD.DrawRef] =
BEGIN
pr.drawRect[CDOrient.RectAt[pos, aptr.ob.size, orient], CD.highLightShade, pr]
END;
Init:
PROC [] =
INLINE
BEGIN
dp: REF CDDirectory.DirectoryProcs;
MakeSubClass[me: pForMacro, from: pForCells];
dp ← NARROW[pForMacro.directoryProcs];
dp.adjustItself ← AdjustItself;
dp.repositionElements ← RepositionElements;
dp.computeBounds ← ComputeBounds;
pForMacro.describe ← Describe;
pForMacro.internalRead ← InternalRead;
pForMacro.showMeSelected ← DrawSelection;
CDSequencer.ImplementCommand[$ModifyMacroS, ModifyMacroS];
END;
--xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
--commands
ModifyMacroS:
PROC [comm: CDSequencer.Command] =
BEGIN
ap: CD.ApplicationPtr;
multiple: BOOL;
TerminalIO.WriteRope["Macro modifications\n"];
[ap, multiple] ← CDOps.SelectedApplication[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 {
rect: CD.DesignRect ← CDApplications.ARectO[ap];
TerminalIO.WriteRope[ap.ob.p.describe[ap.ob]];
IF
ISTYPE[ap.ob.specificRef,
CD.CellPtr]
THEN {
cptr: CD.CellPtr ~ NARROW[ap.ob.specificRef];
IF ap.ob.p=pForCells
THEN {
TerminalIO.WriteRope[" is ordinary cell\n"];
IF TerminalIO.UserSaysYes[label: "transform to macro", text: "transform cell to macro "]
THEN {
CellToMacro[ap.ob]
}
ELSE TerminalIO.WriteRope[" no\n"];
};
IF ap.ob.p#pForMacro
THEN {
TerminalIO.WriteRope[" not a macro; not done\n"];
RETURN
};
--now do it
pForMacro.showMeSelected ← pForCells.showMeSelected;
DO
m: INT;
n: CARDINAL;
rect ← CDInline.Surround[rect, CDApplications.ARectO[ap]];
CDOps.Redraw[comm.design, rect];
CDOps.DoTheDelayedRedraws[comm.design];
Process.Pause[Process.MsecToTicks[100]]; -- to allow drawing
n ← TerminalIO.RequestSelection[label: "macro commands",
choice: LIST["exit macro commands", "x-position", "y-position", "x-size", "y-size", "pause for redraw"]
];
SELECT n
FROM
1 => EXIT;
2 => {
m ← TerminalIO.RequestInt["change x position > "];
MacroAdjust[ob: ap.ob, newBound: [x1: m, y1: 0, x2: ap.ob.size.x, y2: ap.ob.size.y]];
TerminalIO.WriteLn[];
};
3 => {
m ← TerminalIO.RequestInt["change y position > "];
MacroAdjust[ob: ap.ob, newBound: [x1: 0, y1: m, x2: ap.ob.size.x, y2: ap.ob.size.y]];
TerminalIO.WriteLn[];
};
4 => {
m ← TerminalIO.RequestInt["change x size > "];
MacroAdjust[ob: ap.ob, newBound: [x1: 0, y1: 0, x2: ap.ob.size.x+m, y2: ap.ob.size.y]];
TerminalIO.WriteLn[];
};
5 => {
m ← TerminalIO.RequestInt["change y size > "];
MacroAdjust[ob: ap.ob, newBound: [x1: 0, y1: 0, x2: ap.ob.size.x, y2: ap.ob.size.y+m]];
TerminalIO.WriteLn[];
};
6 => Process.Pause[Process.MsecToTicks[200]];
ENDCASE => TerminalIO.WriteRope[" no selection\n"];
ENDLOOP;
pForMacro.showMeSelected ← DrawSelection;
TerminalIO.WriteRope[" end macro commands\n"];
}
ELSE TerminalIO.WriteRope[" not a cell; not done\n"];
}
END;
--xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Init[];
END.