CDSimpleCellsImpl.mesa
by Ch. Jacobi, June 10, 1985 12:06:12 pm PDT
last edited Ch. Jacobi, July 10, 1985 9:50:09 am PDT
DIRECTORY
CD,
CDBasics,
CDCells,
CDDirectory,
CDInstances,
CDOrient,
CDProperties,
Rope,
CDSimpleCells;
CDSimpleCellsImpl: CEDAR PROGRAM
IMPORTS CD, CDBasics, CDCells, CDDirectory, CDInstances, CDOrient, CDProperties, Rope
EXPORTS CDSimpleCells =
BEGIN
InstRec: TYPE = CDSimpleCells.InstRec;
Direction: TYPE = CDSimpleCells.Direction;
CreateSimpleCell: PUBLIC PROC [design: CD.Design, contents: LIST OF InstRec, cellName: Rope.ROPENIL, direction: Direction ← right, alignHigh: BOOLFALSE] RETURNS [CD.Object] =
BEGIN
r: CD.Rect ← [0, 0, 0, 0];
c: CD.Object = CDCells.CreateEmptyCell[];
inst: CD.Instance;
pos: CD.Position ← [0, 0];
IF Rope.IsEmpty[cellName] THEN cellName ← "-SimpleCell";
NARROW[c.specificRef, CD.CellPtr].name ← cellName;
FOR list: LIST OF InstRec ← contents, list.rest WHILE list#NIL DO
sz: CD.Position;
IF list.first.ob=NIL THEN LOOP;
sz ← CDOrient.OrientedSize[CDBasics.SizeOfRect[CD.InterestRect[list.first.ob]], list.first.orient];
SELECT direction FROM
right => {pos.x ← r.x2};
left => {pos.x ← r.x1-sz.x};
up  => {pos.y ← r.y2};
down => {pos.y ← r.y1-sz.y};
none => {pos ← [0, 0]};
ENDCASE => ERROR;
IF alignHigh THEN
SELECT direction FROM
right, left => {pos.y ← -sz.y};
up, down => {pos.x ← -sz.x};
none  => {pos ← [-sz.x, -sz.y]};
ENDCASE => ERROR;
inst ← CDCells.IncludeOb[cell: c, ob: list.first.ob,
position: [pos.x+list.first.dX, pos.y+list.first.dY],
orientation: list.first.orient,
cellCSystem: cdCoords,
obCSystem: interrestCoords,
mode: dontPropagate
].newInst;
r ← CDInstances.InstRectI[inst];
IF list.first.properties#NIL THEN
inst.properties ← CDProperties.AppendProps[inst.properties, list.first.properties];
IF ~Rope.IsEmpty[list.first.name] THEN
CDProperties.PutPropOnInstance[inst, $InstanceName, list.first.name];
ENDLOOP;
[] ← CDCells.RepositionCell[c, NIL];
IF design#NIL THEN [] ← CDDirectory.Include[design, c];
RETURN[c]
END;
END.