DIRECTORY CD, CDBasics, CDCells, CDDirectory, CDInstances, CDOps, CDProperties, CDRects, Rope, CDUtil; CDUtilImpl: CEDAR PROGRAM IMPORTS CD, CDBasics, CDCells, CDDirectory, CDInstances, CDOps, CDProperties, CDRects, Rope EXPORTS CDUtil = BEGIN InstRec: TYPE = CDUtil.InstRec; Direction: TYPE = CDUtil.Direction; CreateSimpleCell: PUBLIC PROC [design: CD.Design, contents: LIST OF InstRec, cellName: Rope.ROPE _ NIL, direction: Direction _ right, alignHigh: BOOL _ FALSE] RETURNS [CD.Object] = { r, ir: 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.specific, CD.CellSpecific].name _ cellName; FOR list: LIST OF InstRec _ contents, list.rest WHILE list#NIL DO IF list.first.ob=NIL THEN LOOP; ir _ CDBasics.MapRect[list.first.ob.bbox, [[0,0], list.first.orient]]; SELECT direction FROM right => { pos.x _ r.x2-ir.x1; IF alignHigh THEN pos.y _ -ir.y2 ELSE pos.y _ -ir.y1 }; left => { pos.x _ r.x1-ir.x2; IF alignHigh THEN pos.y _ -ir.y2 ELSE pos.y _ -ir.y1 }; up => { pos.y _ r.y2-ir.y1; IF alignHigh THEN pos.x _ -ir.x2 ELSE pos.x _ -ir.x1 }; down => { pos.y _ r.y1-ir.y2; IF alignHigh THEN pos.x _ -ir.x2 ELSE pos.x _ -ir.x1 }; none => pos _ [0, 0]; ENDCASE => ERROR; inst _ CDCells.IncludeOb[cell: c, ob: list.first.ob, trans: [[pos.x+list.first.dX, pos.y+list.first.dY], list.first.orient], mode: dontResize ].newInst; r _ CDInstances.InstRectI[inst]; IF list.first.properties#NIL THEN CDProperties.AppendProps[inst.properties, list.first.properties, inst]; IF ~Rope.IsEmpty[list.first.name] THEN CDProperties.PutInstanceProp[inst, $InstanceName, list.first.name]; ENDLOOP; [] _ CDCells.ResizeCell[NIL, c]; IF design#NIL THEN [] _ CDDirectory.Include[design, c]; RETURN[c] }; 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] = { ExpandToCell: PROC [ob: CD.Object, from: CD.Design] RETURNS [cell: CD.Object] = { tm, cm: CDDirectory.DMode; cell _ ob; IF ~CDCells.IsCell[cell] THEN { [cell, tm, cm] _ CDDirectory.Expand[ob, from, from]; IF cell=NIL OR ~CDCells.IsCell[cell] THEN RETURN [NIL]; IF cm#included THEN IF ~CDDirectory.FixChildren[cell, from] THEN RETURN [NIL] } }; ShouldCopy: PROC[i: CD.Instance] RETURNS [copy: BOOL_TRUE] = { ref: REF = CDProperties.GetInstanceProp[i, prop]; IF ref#NIL THEN { val: Rope.ROPE = CDOps.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]; IF cell#NIL THEN { newList: CD.InstanceList _ NIL; cp, newCp: CD.CellSpecific; EachInst: CDCells.InstEnumerator = { IF ShouldCopy[inst] THEN newList _ CONS[CDInstances.Copy[inst], newList]; }; copy _ CDCells.CreateEmptyCell[]; cp _ NARROW[cell.specific]; newCp _ NARROW[copy.specific]; copy.bbox _ cell.bbox; CDProperties.CopyProps[cell.properties, copy]; newCp^ _ cp^; newCp.sequence _ NIL; [] _ CDCells.EnumerateInstances[cell, EachInst]; newCp.contents _ newList; [] _ CDCells.ResizeCell[NIL, copy]; IF design#NIL THEN [] _ CDDirectory.Include[design, copy, name]; } ELSE ERROR; }; FlattenChild: PROC [inst: CD.Instance, trans: CD.Transformation, pr: REF CD.DrawInformation] = { fRef: REF FlattenRec = NARROW[pr.devicePrivate]; newInst: CD.Instance _ NEW[CD.InstanceRep_[ob: inst.ob, trans: trans, properties: CDProperties.DCopyProps[inst.properties]]]; IF fRef.flattenInst[newInst] THEN inst.ob.class.drawMe[newInst, trans, pr] ELSE fRef.cellPtr.contents _ CONS[newInst, fRef.cellPtr.contents]; }; FlattenBareRect: PROC [r: CD.Rect, l: CD.Layer, pr: CD.DrawRef] = { fRef: REF FlattenRec = NARROW[pr.devicePrivate]; inst: CD.Instance _ NEW[CD.InstanceRep_[ ob: CDRects.CreateBareRect[size: CDBasics.SizeOfRect[r], l: l], trans: [CDBasics.BaseOfRect[r], original] ]]; fRef.cellPtr.contents _ CONS[inst, fRef.cellPtr.contents]; }; FlattenRec: TYPE = RECORD [ cell: CD.Object, cellPtr: CD.CellSpecific, flattenInst: CDUtil.InstPredicate ]; DefaultFlattenInst: CDUtil.InstPredicate = { IF ~inst.ob.class.inDirectory THEN RETURN [FALSE]; IF CDProperties.GetObjectProp[inst.ob, $DontFlatten]#NIL THEN RETURN [FALSE]; RETURN [TRUE] }; Flatten: PUBLIC PROC [ob: CD.Object, design: CD.Design, flattenInst: CDUtil.InstPredicate_NIL] RETURNS [new: CD.Object_NIL] = { fRef: REF FlattenRec = NEW[FlattenRec_[ cell: CDCells.CreateEmptyCell[], cellPtr: NIL, flattenInst: IF flattenInst#NIL THEN flattenInst ELSE DefaultFlattenInst ]]; fPr: CD.DrawRef = CD.CreateDrawRef[[ design: design, drawRect: FlattenBareRect, drawChild: FlattenChild, selections: FALSE, devicePrivate: fRef, contextFilter: NEW[CD.ContextFilter_ALL[TRUE]] ]]; fRef.cellPtr _ NARROW[fRef.cell.specific]; ob.class.drawMe[inst: NEW[CD.InstanceRep_[ob: ob]], trans: [], pr: fPr]; IF ~CDCells.IsEmpty[fRef.cell] THEN { name: Rope.ROPE _ CDDirectory.Name[ob]; IF Rope.IsEmpty[name] THEN name _ CDOps.ObjectRope[ob]; fRef.cellPtr.name _ Rope.Concat["!", name]; new _ fRef.cell; CDCells.SetInterestRect[NIL, new, CD.InterestRect[ob], doit]; IF design#NIL THEN { [] _ CDDirectory.Include[design, new]; [] _ CDDirectory.FixChildren[new, design]; } }; }; END. .CDUtilImpl.mesa Copyright c 1985 by Xerox Corporation. All rights reserved. Created by Christian Jacobi, June 10, 1985 12:06:12 pm PDT Last edited by: Christian Jacobi, November 17, 1986 12:55:38 pm PST --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 --returns cell; however we dont care if cell is in design or not... --accesses parameters of CopyInst don't care if top level in design; we copy anyway --interest rect: by luck, the right thing happens even without coding --actually, fixing children would also work for NIL design --but PW sometimes use NIL design and we don't want to remove --all children in this case Κ˜codešœ™Kšœ Οmœ1™Kšœ!™!Kšœžœ)˜1šžœžœžœ˜Kšœ žœ˜#š žœžœžœžœžœžœž˜>Kšžœžœžœ˜:Kšž˜—K˜—Kšœ ˜ K˜—K˜šœžœ$˜,Kšœ1™1—šžœžœžœ˜Kšœ žœžœ˜Kšœ žœ˜šŸœ˜$šžœžœ˜Kšœ žœ"˜0—K˜—Kšœ!˜!Kšœžœ˜Kšœžœ˜Kšœ˜Kšœ.˜.Kšœžœ˜$Kšœ0˜0Kšœ˜K™EKšœžœ˜#Kšžœžœžœ.˜@Kšœ˜—Kšžœžœ˜ Kšœ˜K˜—K˜š Ÿ œžœžœžœžœžœ˜`Kšœžœžœ˜0Kšœ žœ žœžœ`˜}Kšžœžœ)˜JKšžœžœ#˜DKšœ˜—K˜š Ÿœžœžœ žœ žœ ˜CKšœžœžœ˜0šœžœ žœžœ˜(Kšœ@˜@Kšœ)˜)Kšœ˜—Kšœžœ˜:Kšœ˜—K˜šœ žœžœ˜Kšœžœ˜Kšœ žœ˜Kšœ!˜!Kšœ˜—K˜šŸœ˜,Kšžœžœžœžœ˜2Jš žœ3žœžœžœžœ˜MKšžœžœ˜ K˜—K˜šŸœž œžœžœ+žœžœžœžœ˜šœžœžœ ˜'Kšœ ˜ Kšœ žœ˜ Kš œ žœ žœžœ žœ˜HKšœ˜—šœžœ žœ˜$Kšœ˜Kšœ˜Kšœ˜Kšœ žœ˜Kšœ˜Kš œžœžœžœžœ˜.Kšœ˜—Kšœžœ˜*Kšœžœžœ,˜Hšžœžœ˜%Kšœ žœ˜'Kšžœžœ˜7Kšœ+˜+Kšœ˜Kšœžœžœ˜=šžœžœžœ˜Kšœ&˜&šœ+˜+Kšœ:™:Kšœ=™=Kšœ™—K˜—Kšœ˜—Kšœ˜—K˜Kšžœ˜K˜—…—ζ