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"; 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, cellName]; 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] = { cell _ ob; IF ~CDCells.IsCell[cell] THEN { cell _ CDDirectory.ExpandRecursed[ob, from, from]; IF cell=NIL OR ~CDCells.IsCell[cell] 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: CD.DrawProc = { fRef: REF FlattenRec = NARROW[pr.devicePrivate]; newInst: CD.Instance _ NEW[CD.InstanceRep_[ob: ob, trans: trans, properties: CDProperties.DCopyProps[readOnlyInstProps]]]; IF fRef.flattenInst[newInst] THEN ob.class.drawMe[pr, ob, trans, newInst.properties] ELSE fRef.cellPtr.contents _ CONS[newInst, fRef.cellPtr.contents]; }; FlattenBareRect: PROC [pr: CD.DrawRef, r: CD.Rect, l: CD.Layer] = { 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.composed 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[ob: ob, pr: fPr]; IF ~CDCells.IsEmpty[fRef.cell] THEN { new _ fRef.cell; CDCells.SetInterestRect[NIL, new, CD.InterestRect[ob], doit]; IF design#NIL THEN { [] _ CDDirectory.FixChildren[new, design]; } }; }; END. 2CDUtilImpl.mesa Copyright c 1985, 1987 by Xerox Corporation. All rights reserved. Created by Christian Jacobi, June 10, 1985 12:06:12 pm PDT Last edited by: Christian Jacobi, February 23, 1987 7:24:31 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œ7™BKšœ:™:K™B—K˜šΟk ˜ Kšžœ˜Kšœ ˜ Kšœ˜Kšœ ˜ Kšœ ˜ Kšœ˜Kšœ ˜ Kšœ˜Kšœ˜Kšœ˜—K˜šΟn œžœž˜KšžœU˜\Kšžœ ˜—Kšžœ˜K˜Kšœ žœ˜Kšœ žœ˜#K˜šŸœžœžœ žœžœžœžœžœ+žœžœžœžœ ˜ΆKšœžœ˜Kšœžœ$˜)Kšœžœ ˜Kšœžœ˜Kšžœžœ˜8š žœžœžœžœžœž˜AKšžœžœžœžœ˜KšœF˜Fšžœ ž˜šœ ˜ Kšœ˜Kšžœ žœžœ˜4K˜—šœ ˜ Kšœ˜Kšžœ žœžœ˜4K˜—šœ˜Kšœ˜Kšžœ žœžœ˜4K˜—šœ ˜ Kšœ˜Kšžœ žœžœ˜4K˜—Kšœ˜Kšžœžœ˜—šœ5˜5KšœG˜GKšœ˜Kšœ ˜ —Kšœ ˜ šžœžœžœ˜"KšœG˜G—šžœ ž˜&KšœC˜C—Kšžœ˜—Kšœžœ˜ Kšžœžœžœ/˜AKšžœ˜ Kšœ˜—K˜š"Ÿ œžœžœžœžœžœžœžœžœ žœžœžœžœžœžœžœžœ˜ΓKšœ"™"šœ™KšœQ™Q—šœ™KšœQ™Q—K˜š Ÿ œžœžœžœ žœžœ ˜QKšœC™CKšœ ˜ šžœžœ˜Kšœ2˜2Kš žœžœžœžœžœžœ˜7K˜—Kšœ˜—K˜š Ÿ œžœžœ žœžœžœ˜>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šœ žœ žœžœ]˜zKšžœžœ3˜TKšžœžœ#˜DKšœ˜—K˜š Ÿœžœžœ žœ žœ ˜CKšœžœžœ˜0šœžœ žœžœ˜(Kšœ@˜@Kšœ)˜)Kšœ˜—Kšœžœ˜:Kšœ˜—K˜šœ žœžœ˜Kšœžœ˜Kšœ žœ˜Kšœ!˜!Kšœ˜—K˜šŸœ˜,Kšžœžœžœžœ˜/Jš žœ3žœžœžœžœ˜MKšžœžœ˜ K˜—K˜šŸœž œžœžœ+žœžœžœžœ˜šœžœžœ ˜'Kšœ ˜ Kšœ žœ˜ Kš œ žœ žœžœ žœ˜HKšœ˜—šœžœ žœ˜$Kšœ˜Kšœ˜Kšœ˜Kšœ žœ˜Kšœ˜Kš œžœžœžœžœ˜.Kšœ˜—Kšœžœ˜*Kšœ!˜!šžœžœ˜%Kšœ˜Kšœžœžœ˜=šžœžœžœ˜šœ+˜+Kšœ:™:Kšœ=™=Kšœ™—K˜—Kšœ˜—Kšœ˜—K˜Kšžœ˜K˜—…—6τ