<> <> <> 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.ROPE_NIL, remove: BOOL_TRUE, prop: ATOM _ $InstanceName, name: Rope.ROPE_NIL] 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: BOOL_TRUE] = { <<--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.