CDConvertTechnologies.mesa (a package to convert technologies of ChipNDale designs)
Copyright © 1983, 1985, 1986 by Xerox Corporation. All rights reserved.
Created by Christian Jacobi, June 24, 1983 5:03 pm
Last edited by: Christian Jacobi, December 12, 1986 9:44:46 am PST
DIRECTORY
CD,
CDAtomicObjects,
CDBasics,
CDCells,
CDCommandOps,
CDCommandOpsExtras2,
CDCleanUp,
CDDirectory,
CDExtras,
CDImports,
CDOps,
CDOrient,
CDCurves,
CDProperties,
CDRects,
CDSequencer,
CDSymbolicObjects,
CDTexts,
CDViewer,
RefTab,
Rope,
TerminalIO;
CDConvertTechnologies:
CEDAR
PROGRAM
IMPORTS CD, CDBasics, CDAtomicObjects, CDCleanUp, CDCells, CDCommandOps, CDCommandOpsExtras2, CDDirectory, CDExtras, CDImports, CDOps, CDOrient, CDCurves, CDProperties, CDRects, CDSymbolicObjects, CDTexts, CDViewer, RefTab, TerminalIO =
BEGIN
--MUST BE SETUP USING INTERPRETER
fromTechnologyKey: ATOM←NIL;
toTechnologyKey: ATOM←NIL;
layerConversion: RefTab.Ref; -- layerkey => layerkey
classConversion: RefTab.Ref; -- object class key => key for atomic objects
classPosOffsets: RefTab.Ref; -- old object class key => CD.Position [offset in old coord system]
classSizeOffsets: RefTab.Ref; -- old object class key => CD.Position [offset in old coord system]
--must be protected
correspondKey: REF INT;
abortFlag: REF BOOL ← NEW[BOOL←FALSE];
design: CD.Design;
newDesign: CD.Design;
lambda: CD.Number;
newLambda: CD.Number;
oldTech: CD.Technology;
newTech: CD.Technology;
TRect:
PROC [rect:
CD.Rect]
RETURNS [r:
CD.Rect] =
BEGIN
r ← [x1: rect.x1*newLambda/lambda, x2: rect.x2*newLambda/lambda, y1: rect.y1*newLambda/lambda, y2: rect.y2*newLambda/lambda]
END;
TPos:
PROC [pos:
CD.Position]
RETURNS [p:
CD.Position] =
BEGIN
p ← [pos.x*newLambda/lambda, pos.y*newLambda/lambda]
END;
TNum:
PROC [n:
CD.Number]
RETURNS [
CD.Number] =
BEGIN
RETURN [n*newLambda/lambda]
END;
SizeOffset:
PROC [oldOb:
CD.Object]
RETURNS [s:
CD.Position←[0, 0]] =
BEGIN
IF classSizeOffsets#
NIL
THEN
WITH RefTab.Fetch[classSizeOffsets, oldOb.class.objectType].val
SELECT
FROM
p: REF CD.Position => s ← p^;
ENDCASE => NULL;
END;
MustOffsetOrigin:
PROC [oldOb:
CD.Object]
RETURNS [off:
CD.Position ← [0, 0]] =
--off in old coord system
BEGIN
IF classPosOffsets#
NIL
THEN
WITH RefTab.Fetch[classPosOffsets, oldOb.class.objectType].val
SELECT
FROM
p: REF CD.Position => off ← p^;
ENDCASE => NULL;
END;
OriginPos:
PROC [i:
CD.Instance, point:
CD.Position ← [0, 0]]
RETURNS [p:
CD.Position] =
--point in origin coordinates of object i.ob is returned in world coordinates
BEGIN
RETURN [CDOrient.MapPoint[
pointInCell: CDBasics.AddPoints[point, CD.ClientOrigin[i.ob]],
cellSize: i.ob.size,
cellInstOrient: i.orientation,
cellInstPos: i.location
]]
END;
CorrespondingLayer:
PROC [layer:
CD.Layer]
RETURNS [l:
CD.Layer] =
BEGIN
key: ATOM ← CD.LayerKey[layer];
WITH RefTab.Fetch[layerConversion, key].val
SELECT
FROM
a: ATOM => l ← CD.FetchLayer[newTech, a];
ENDCASE => {
IF CD.LayerTechnology[layer]=NIL THEN RETURN [layer];
l ← CD.FetchLayer[newTech, CD.LayerKey[layer]]
}
END;
TransferAny:
PROC [ob:
CD.Object]
RETURNS [new:
CD.Object←
NIL] =
BEGIN
WITH CDProperties.GetProp[ob, correspondKey]
SELECT
FROM
ob1: CD.Object => RETURN [ob1];
ENDCASE => NULL;
IF CDAtomicObjects.IsAtomicOb[ob] THEN new ← TransferAtomicObject[ob]
ELSE IF CDCells.IsCell[ob] THEN new ← TransferCell[ob]
ELSE IF ob.class.wireTyped THEN new ← TransferWire[ob]
ELSE IF CDSymbolicObjects.IsMark[ob] THEN new ← CDSymbolicObjects.CreateMark[]
ELSE IF CDTexts.IsText[ob] THEN new ← TransferText[ob]
ELSE IF CDImports.IsImport[ob] THEN new ← TransferImport[ob]
ELSE IF CDCurves.IsPolygon[ob] THEN new ← TransferPolygon[ob]
ELSE IF CDCurves.IsLine[ob] THEN new ← TransferLine[ob]
ELSE IF CDCurves.IsSpline[ob] THEN new ← TransferSpline[ob]
ELSE IF CDCurves.IsFilledCurve[ob] THEN new ← TransferFilledCurve[ob];
IF new=NIL THEN new ← TransferHard[ob];
IF new=NIL THEN TerminalIO.WriteRope["unknown object type\n"]
END;
GetAtomKey:
PROC [a:
ATOM]
RETURNS [
ATOM] =
BEGIN
WITH RefTab.Fetch[classConversion, a].val
SELECT
FROM
aa: ATOM => RETURN [aa];
ENDCASE => RETURN [NIL];
END;
TransferAtomicObject:
PROC [ob:
CD.Object]
RETURNS [new:
CD.Object←
NIL] =
BEGIN
newKey: ATOM ← GetAtomKey[ob.class.objectType];
sz: CD.Position ← CD.InterestSize[ob];
sz ← TPos[CDBasics.AddSize[sz, SizeOffset[ob]]];
IF newKey#
NIL
THEN {
new ← CDAtomicObjects.CreateAtomicOb[newKey, sz, newTech, CorrespondingLayer[ob.layer]];
}
END;
TransferHard:
PROC [ob:
CD.Object]
RETURNS [new:
CD.Object←
NIL] =
BEGIN
ob1: CD.Object ← CDDirectory.Expand[ob, design, NIL].new;
IF ob1=NIL OR ob1=ob THEN ob1 ← CDDirectory.ExpandByDraw[ob];
IF ob1#
NIL
THEN {
new ← TransferWithChildrenCheck[ob1];
CDProperties.PutProp[ob, correspondKey, CDProperties.GetProp[ob1, correspondKey]];
}
END;
TransferWire:
PROC [ob:
CD.Object]
RETURNS [new:
CD.Object] =
BEGIN
new ← CDRects.CreateRect[TPos[CD.InterestSize[ob]], CorrespondingLayer[ob.layer]]
END;
TransferText:
PROC [ob:
CD.Object]
RETURNS [new:
CD.Object] =
BEGIN
tp: CDTexts.TextPtr ← NARROW[ob.specificRef];
font: CDTexts.CDFont;
font ← CDTexts.MakeFont[name: tp.cdFont.supposedName, scale: TNum[tp.cdFont.scaleI]];
new ← CDTexts.CreateText[text: tp.text, font: font, layer: CorrespondingLayer[ob.layer]];
END;
TransferImport:
PROC [ob:
CD.Object]
RETURNS [new:
CD.Object] =
BEGIN
--dirty
ip: CDImports.ImportPtr ← NARROW[ob.specificRef];
newIp: CDImports.ImportPtr ← NEW[CDImports.ImportRep←[ir: TRect[ip.ir], objectName: ip.objectName, designName: ip.designName]];
new ← NEW[CD.ObjectRep←ob^];
new.properties ← NIL;
new.specificRef ← newIp;
new.size ← TPos[new.size];
[] ← CDDirectory.Include[newDesign, new, CDDirectory.Name[ob]]
END;
TransferPosList:
PROC [ob:
CD.Object]
RETURNS [newPl:
LIST
OF
CD.Position←
NIL, w:
CD.Number] =
BEGIN
pp: CDCurves.CurvePtr ← NARROW[ob.specificRef];
FOR pl:
LIST
OF
CD.Position ← pp.points, pl.rest
WHILE pl#
NIL
DO
newPl ← CONS[TPos[pl.first], newPl];
ENDLOOP;
w ← pp.w
END;
TransferPolygon:
PROC [ob:
CD.Object]
RETURNS [new:
CD.Object] =
BEGIN
newPl: LIST OF CD.Position; w: CD.Number;
[newPl, w] ← TransferPosList[ob];
new ← CDCurves.CreatePolygon[newPl, CorrespondingLayer[ob.layer]].ob;
END;
TransferLine:
PROC [ob:
CD.Object]
RETURNS [new:
CD.Object] =
BEGIN
newPl: LIST OF CD.Position; w: CD.Number;
[newPl, w] ← TransferPosList[ob];
new ← CDCurves.CreateLine[newPl, w, CorrespondingLayer[ob.layer]].ob;
END;
TransferSpline:
PROC [ob:
CD.Object]
RETURNS [new:
CD.Object] =
BEGIN
newPl: LIST OF CD.Position; w: CD.Number;
[newPl, w] ← TransferPosList[ob];
new ← CDCurves.CreateSpline[newPl, w, CorrespondingLayer[ob.layer]].ob;
END;
TransferFilledCurve:
PROC [ob:
CD.Object]
RETURNS [new:
CD.Object] =
BEGIN
newPl: LIST OF CD.Position; w: CD.Number;
[newPl, w] ← TransferPosList[ob];
new ← CDCurves.CreateFilledCurve[newPl, CorrespondingLayer[ob.layer]].ob;
END;
TransferCell:
PROC [ob:
CD.Object]
RETURNS [new:
CD.Object] =
BEGIN
newChild: CD.Object;
cp: CD.CellPtr ← NARROW[ob.specificRef];
new ← CDCells.CreateEmptyCell[];
FOR il:
CD.InstanceList ← cp.contents, il.rest
WHILE il#
NIL
DO
inst: CD.Instance;
position: CD.Position ← TPos[CDBasics.SubPoints[OriginPos[il.first, MustOffsetOrigin[il.first.ob]], cp.origin]];
newChild ← TransferAny[il.first.ob];
IF newChild=NIL THEN LOOP;
inst ← CDCells.IncludeOb[design: NIL, cell: new, position: position, ob: newChild, orientation: il.first.orientation, cellCSystem: originCoords, obCSystem: originCoords, mode: dontPropagate].newInst;
CDProperties.AppendProps[winner: inst.properties, looser: il.first.properties, putOnto: inst];
ENDLOOP;
IF ~cp.useDIr
THEN
CDCells.SetInterestRect[new,
TRect[CDBasics.MoveRect[cp.ir, CDBasics.NegOffset[CD.ClientOrigin[ob]]]]
];
[] ← CDCells.RepositionCell[new, NIL];
[] ← CDCells.SetSimplificationTreshhold[new, -1];
CDProperties.AppendProps[winner: new.properties, looser: ob.properties, putOnto: new];
[] ← CDDirectory.Include[newDesign, new, CDDirectory.Name[ob]]
END;
ReallyTransfer:
PROC [ob:
CD.Object]
RETURNS [ob1:
CD.Object] =
--all children of ob are already transfereed
BEGIN
ob1 ← TransferAny[ob]
END;
TransferWithChildrenCheck:
PROC [ob:
CD.Object]
RETURNS [ob1
: CD.Object] =
BEGIN
EachChild:
PROC [me:
CD.Object, x:
REF] = {
[] ← TransferWithChildrenCheck[me];
};
WITH CDProperties.GetProp[ob, correspondKey]
SELECT
FROM
obx: CD.Object => ob1 ← obx;
ENDCASE => {
CDDirectory.EnumerateChildObjects[ob, EachChild, NIL];
ob1 ← ReallyTransfer[ob];
CDProperties.PutProp[ob, correspondKey, ob1]
};
END;
Transfer:
PROC [from:
CD.Design, tech:
CD.Technology]
RETURNS [nD:
CD.Design] =
BEGIN
EachDirEl:
PROC [name: Rope.
ROPE, ob:
CD.Object]
RETURNS [quit:
BOOL←
FALSE] = {
[] ← TransferWithChildrenCheck[ob];
};
dummyOb, newDummyOb: CD.Object;
design ← from;
correspondKey ← NEW[INT];
oldTech ← from.technology;
newTech ← tech;
newDesign ← nD ← CDOps.CreateDesign[tech];
CDExtras.PopToTopLevel[from];
dummyOb ← CDExtras.CreateDummyObject[from];
lambda ← oldTech.lambda;
newLambda ← newTech.lambda;
[] ← CDDirectory.Enumerate[design: from, action: EachDirEl];
newDummyOb ← TransferWithChildrenCheck[dummyOb];
[] ← CDCells.IncludeOb[design: newDesign, ob: newDummyOb];
CDCleanUp.RemoveProperties[from, correspondKey];
END;
ProtectedTransferComm:
PROC [comm: CDSequencer.Command] =
BEGIN
t: CD.Technology;
d: CD.Design;
TerminalIO.WriteRope["transfer technology\n"];
IF comm.design.technology.key#fromTechnologyKey
THEN {
TerminalIO.WriteRope["not right ""from"" technology set up\n"];
ERROR ABORTED
};
t ← CD.FetchTechnology[toTechnologyKey];
IF t=
NIL
THEN {
TerminalIO.WriteRope["the ""to"" technology is not loaded\n"];
ERROR ABORTED
};
[] ← CDCleanUp.CleanUp[comm.design];
d ← Transfer[comm.design, t];
[] ← CDViewer.CreateViewer[d];
END;
TransferComm:
PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["transfer technology\n"];
abortFlag^ ← FALSE;
[] ← CDCommandOps.CallWithResource[
proc: ProtectedTransferComm,
comm: comm,
resource: $CDTransferTecnology,
abortFlag: abortFlag
];
END;
CDCommandOpsExtras2.RegisterWithMenu[menu: $ProgramMenu, entry: "convert technology", proc: TransferComm, key: $CDConvertTechnologiesX, doc: "MUST set up technologies with command file first"];
END.