DIRECTORY
CD, CDCells, CDCreateLabels, CDPinObjects, CDProperties, CDRects, CDUtils, HashTable, Imager, ImagerFont, IO, PW, PWPins, Real, Rope, VFonts;
CDUtilsImpl:
CEDAR
PROGRAM
IMPORTS CD, CDCells, CDCreateLabels, CDPinObjects, CDProperties, CDRects, HashTable, ImagerFont, IO, PWPins, Real, Rope, VFonts
EXPORTS CDUtils =
BEGIN
Signal: SIGNAL = CODE;
ROPE: TYPE = CDUtils.ROPE;
cache: HashTable.Table ←
HashTable.Create[equal: HashTable.RopeEqual, hash: HashTable.HashRope];
Store: PROC[name: ROPE, obj: CD.Object] = {[]←HashTable.Store[cache, name, obj]};
Fetch:
PROC[name:
ROPE]
RETURNS[obj:
CD.Object] =
{RETURN[NARROW[HashTable.Fetch[cache, name].value, CD.Object]]};
BlankCell:
PUBLIC
PROC[size:
CD.Position]
RETURNS[cell:
CD.Object] ~ {
cellPtr: CD.CellPtr;
found: BOOL ← FALSE;
name: ROPE ← IO.PutFR["Dummy-%g-%g", IO.int[size.x], IO.int[size.y]];
IF size.x=0 OR size.y=0 THEN RETURN[NIL];
cell ← Fetch[name];
IF cell#NIL THEN RETURN[cell];
cell ← CDCells.CreateEmptyCell[];
cellPtr ← NARROW[cell.specificRef];
cellPtr.contents ←
CONS[
NEW[
CD.InstanceRep ←
[ob: CDRects.CreateRect[size, CD.backGround]] ], cellPtr.contents];
Store[name, cell]};
ObjName:
PUBLIC
PROC[obj:
CD.Object]
RETURNS[name:
ROPE] = {
IF obj=NIL THEN RETURN[NIL];
IF obj.specificRef=NIL THEN RETURN[NIL];
IF NOT ISTYPE[obj.specificRef, CD.CellPtr] THEN RETURN[NIL];
RETURN[NARROW[obj.specificRef, CD.CellPtr].name]};
ObjSize:
PUBLIC
PROC[obj:
CD.Object]
RETURNS[size:
CD.Position] =
{RETURN[CD.InterestSize[obj]]};
font1: Imager.Font ← VFonts.EstablishFont
[family:"Helvetica", size: 7, bold: TRUE, italic: FALSE, defaultOnFailure: FALSE];
font2: Imager.Font ← VFonts.EstablishFont
[family:"Helvetica", size: 14, bold: TRUE, italic: FALSE, defaultOnFailure: FALSE];
ScaledText:
PUBLIC
PROC[text:
ROPE, box:
CD.Position, layer:
CD.Layer]
RETURNS[cell: CD.Object] = {
Scale:
PROC[font: Imager.Font]
RETURNS[scale:
INT] = {
extents: ImagerFont.Extents ← ImagerFont.RopeBoundingBox[font, text];
strSize: CD.Position;
IF box.x<4 OR box.y<4 THEN RETURN[0];
strSize.x ← Real.RoundI[extents.rightExtent+extents.leftExtent];
strSize.y ← Real.RoundI[extents.ascent+extents.descent];
scale ← MIN[box.x/strSize.x, box.y/strSize.y]};
scaleFactor: INT ← Scale[font2];
IF scaleFactor>0
THEN RETURN[CDCreateLabels.CreateTextCell[NIL, text, font2, scaleFactor, layer]];
scaleFactor ← Scale[font1];
IF scaleFactor>0
THEN RETURN[CDCreateLabels.CreateTextCell[NIL, text, font1, scaleFactor, layer]];
RETURN[NIL] };
RenamePins:
PUBLIC
PROC[
object: CD.Object,
pinNameProc: CDUtils.PinNameProc]
RETURNS[newObject: CD.Object] = {
KeepPinOnEdge: CDPinObjects.InstanceEnumerator = {
newRope: ROPE;
newInst: CD.Instance;
side: PWPins.Side;
side ← PWPins.GetSide[object, inst];
IF side=none THEN RETURN;
newRope ← pinNameProc[inst, side];
IF Rope.IsEmpty[newRope] THEN RETURN;
newInst ←
NEW[
CD.InstanceRep ← [
ob: CDPinObjects.CreatePinOb[inst.ob.size],
location: inst.location,
orientation: inst.orientation ]];
CDProperties.CopyProps[inst.properties, newInst];
CDPinObjects.SetName[newInst, newRope];
newCellPtr.contents ← CONS[newInst, newCellPtr.contents] };
newCellPtr: CD.CellPtr;
inst: CD.Instance ← NEW[CD.InstanceRep ← [ob: object]];
CDProperties.PutPropOnInstance[inst, $StopEnumerateDeepPins, $StopEnumerateDeepPins];
newObject ← CDCells.CreateEmptyCell[];
newCellPtr ← NARROW[newObject.specificRef];
[] ← PWPins.EnumerateDeepPins[object, KeepPinOnEdge];
newCellPtr.contents ← CONS[inst, newCellPtr.contents];
CDCells.SetInterestRect[newObject, CD.InterestRect[object]];
RETURN[newObject] };
END.