CDSimpleCells2Impl.mesa
by Ch. Jacobi, June 10, 1985 12:06:12 pm PDT
last edited Ch. Jacobi, August 29, 1985 6:06:10 pm PDT
DIRECTORY
CD,
CDCells,
CDDirectory,
CDExtras,
CDInstances,
CDProperties,
Rope,
CDSimpleCells2;
CDSimpleCells2Impl: CEDAR PROGRAM
IMPORTS CDCells, CDExtras, CDDirectory, CDProperties, Rope
EXPORTS CDSimpleCells2 =
BEGIN
PartialCopy: PUBLIC PROC [ob: CD.Object, design: CD.Design, instances: LIST OF Rope.ROPENIL, remove: BOOLTRUE, prop: ATOM ← $InstanceName, name: Rope.ROPENIL] RETURNS [copy: CD.Object←NIL] =
--copy the object; creates a cell
--remove TRUE:
--all the instances with property prop are and a value in instances are removed
--remove FALSE:
--only the instances with property prop are and a value in instances are copied
BEGIN
ExpandToCell: PROC [ob: CD.Object, from: CD.Design] RETURNS [cell: CD.Object] = {
--returns cell; however we dont care if cell is in design or not...
cell ← ob;
IF ~CDCells.IsCell[cell] THEN {
cell ← CDDirectory.ExpandHard[ob, from, NIL];
IF ~CDCells.IsCell[cell] THEN cell ← NIL;
}
};
ShouldCopy: PROC[i: CD.Instance] RETURNS [copy: BOOLTRUE] = {
--accesses parameters of CopyInst
ref: REF = CDProperties.GetPropFromInstance[i, prop];
IF ref#NIL THEN {
val: Rope.ROPE = CDExtras.ToRope[ref];
FOR rl: LIST OF Rope.ROPE ← instances, rl.rest WHILE rl#NIL DO
IF Rope.Equal[val, rl.first] THEN RETURN [copy ← ~remove];
ENDLOOP
};
copy ← remove
};
cell: CD.Object ← ExpandToCell[ob, design]; --don't care if top level in design; we copy anyway
IF cell#NIL THEN {
newList: CD.InstanceList ← NIL;
cp, newCp: CD.CellPtr;
copy ← CDCells.CreateEmptyCell[];
cp ← NARROW[cell.specificRef];
newCp ← NARROW[copy.specificRef];
copy.size ← cell.size;
copy.properties ← CDProperties.CopyProps[cell.properties];
newCp^ ← cp^;
FOR il: CD.InstanceList ← cp.contents, il.rest WHILE il#NIL DO
IF ShouldCopy[il.first] THEN {
i: CD.Instance ← NEW[CD.InstanceRep ← il.first^];
i.properties ← CDProperties.CopyProps[i.properties];
newList ← CONS[i, newList];
};
ENDLOOP;
newCp.contents ← newList;
--interest rect: by luck, the right thing happens even without coding
[] ← CDCells.RepositionCell[copy, NIL];
IF design#NIL THEN [] ← CDDirectory.Include[design, copy, name];
};
END;
END.