DIRECTORY CD, CDBasics, CDOrient, CDInstances, CDProperties; CDInstancesImpl: CEDAR PROGRAM IMPORTS CD, CDInstances, CDOrient, CDBasics, CDProperties EXPORTS CDInstances = BEGIN PointToI: PUBLIC PROC [pos: CD.Position, inst: CD.Instance] RETURNS [BOOL] = BEGIN r: CD.Rect = CDBasics.RectAt[pos, [0, 0]]; IF ~CDBasics.InsidePos[pos, r] THEN RETURN [FALSE]; RETURN [HitInstance[inst, r]] END; HitInstance: PUBLIC PROC [inst: CD.Instance, hitRect: CD.Rect] RETURNS [BOOL] = BEGIN RETURN [inst.ob.class.hitInside[ inst.ob, CDOrient.DeMapRect[ itemInWorld: hitRect, cellSize: inst.ob.size, cellInstOrient: inst.orientation, cellInstPos: inst.location ] ]] END; InstRectI: PUBLIC PROC [inst: CD.Instance] RETURNS [CD.Rect] = BEGIN RETURN [ CDOrient.MapRect[ itemInCell: CD.InterestRect[inst.ob], cellSize: inst.ob.size, cellInstOrient: inst.orientation, cellInstPos: inst.location ] ] END; NewInst: PUBLIC PROC [ob: CD.Object, location: CD.Position, orientation: CD.Orientation, selected: BOOL, properties: CD.PropList] RETURNS [inst: CD.Instance] = BEGIN inst _ NEW[CD.InstanceRep _ CD.InstanceRep[ob: ob, location: location, orientation: orientation, selected: selected, properties: properties]]; END; Copy: PUBLIC PROC [inst: CD.Instance] RETURNS [CD.Instance] = BEGIN RETURN [ NEW[CD.InstanceRep _ CD.InstanceRep[ob: inst.ob, location: inst.location, orientation: inst.orientation, selected: inst.selected, properties: CDProperties.DCopyProps[inst.properties]]] ]; END; NewInstI: PUBLIC PROC [ob: CD.Object, location: CD.Position, orientation: CD.Orientation, selected: BOOL, properties: CD.PropList] RETURNS [inst: CD.Instance] = BEGIN off: CD.Position = CDBasics.BaseOfRect[ CDOrient.MapRect[ itemInCell: CD.InterestRect[ob], cellSize: ob.size, cellInstOrient: orientation, cellInstPos: [0, 0] ]]; inst _ NewInst[ob, CDBasics.SubPoints[location, off], orientation, selected, properties]; END; BoundingRectO: PUBLIC PROC[list: CD.InstanceList, selectedOnly: BOOL] RETURNS [bound: CD.Rect _ CDBasics.empty] = BEGIN FOR l: LIST OF CD.Instance _ list, l.rest WHILE l#NIL DO IF selectedOnly AND NOT l.first.selected THEN LOOP; bound _ CDBasics.Surround[bound, CDInstances.InstRectO[l.first]] ENDLOOP; END; BoundingRectI: PUBLIC PROC[list: CD.InstanceList, selectedOnly: BOOL] RETURNS [bound: CD.Rect _ CDBasics.empty] = BEGIN FOR l: LIST OF CD.Instance _ list, l.rest WHILE l#NIL DO IF selectedOnly AND NOT l.first.selected THEN LOOP; bound _ CDBasics.Surround[bound, InstRectI[l.first]] ENDLOOP; END; InstanceAt: PUBLIC PROC [il: CD.InstanceList, pos: CD.Position, selectedOnly: BOOL] RETURNS [CD.Instance] = BEGIN FOR l: CD.InstanceList _ il, l.rest WHILE l#NIL DO IF (~selectedOnly OR l.first.selected) AND CDInstances.PointToO[pos, l.first] AND PointToI[pos, l.first] THEN RETURN [l.first] ENDLOOP; RETURN [NIL] END; TranslateList: PUBLIC PROC[il: CD.InstanceList, offset: CD.Position] = BEGIN FOR t: CD.InstanceList _ il, t.rest WHILE t#NIL DO CDInstances.Translate[t.first, offset]; ENDLOOP; END; DeSelectList: PUBLIC PROC [list: CD.InstanceList] = BEGIN FOR w: CD.InstanceList _ list, w.rest WHILE w#NIL DO w.first.selected _ FALSE ENDLOOP; END; AppendToList: PUBLIC PROC [inst, to: CD.InstanceList] RETURNS [CD.InstanceList] = BEGIN FOR w: CD.InstanceList _ inst, w.rest WHILE w#NIL DO to _ CONS[w.first, to]; ENDLOOP; RETURN [to] END; SplitSelected: PUBLIC PROC [il: CD.InstanceList] RETURNS [selected, others: CD.InstanceList _ NIL] = BEGIN FOR w: CD.InstanceList _ il, w.rest WHILE w#NIL DO IF w.first.selected THEN selected _ CONS[w.first, selected] ELSE others _ CONS[w.first, others] ENDLOOP END; OnlySelected: PUBLIC PROC[il: CD.InstanceList] RETURNS [selected: CD.InstanceList_NIL] = BEGIN FOR l: CD.InstanceList _ il, l.rest WHILE l#NIL DO IF l.first.selected THEN selected _ CONS[l.first, selected]; ENDLOOP; END; CopyList: PUBLIC PROC[il: CD.InstanceList] RETURNS [nl: CD.InstanceList_NIL] = BEGIN FOR l: CD.InstanceList _ il, l.rest WHILE l#NIL DO nl _ CONS[Copy[l.first], nl]; ENDLOOP; END; Composed: PUBLIC PROC[inst: CD.Instance, cellPos, cellSize: CD.Position, cellOrient: CD.Orientation] RETURNS [c: CD.Instance] = BEGIN c _ Copy[inst]; c.location _ CDBasics.BaseOfRect[CDOrient.MapRect[ itemInCell: CDOrient.RectAt[inst.location, inst.ob.size, inst.orientation], cellSize: cellSize, cellInstOrient: cellOrient, cellInstPos: cellPos ]]; c.orientation _ CDOrient.ComposeOrient[itemOrientInCell: inst.orientation, cellOrientInWorld: cellOrient]; END; DeComposed: PUBLIC PROC[inst: CD.Instance, cellPos, cellSize: CD.Position, cellOrient: CD.Orientation] RETURNS [dc: CD.Instance] = BEGIN dc _ Copy[inst]; dc.location _ CDBasics.BaseOfRect[CDOrient.DeMapRect[ itemInWorld: CDOrient.RectAt[inst.location, inst.ob.size, inst.orientation], cellSize: cellSize, cellInstOrient: cellOrient, cellInstPos: cellPos ]]; dc.orientation _ CDOrient.DecomposeOrient[itemOrientInWorld: inst.orientation, cellOrientInWorld: cellOrient]; END; ComposedList: PUBLIC PROC[il: CD.InstanceList, cellPos, cellSize: CD.Position, cellOrient: CD.Orientation] RETURNS [cl: CD.InstanceList _ NIL] = BEGIN FOR l: CD.InstanceList _ il, l.rest WHILE l#NIL DO cl _ CONS[Composed[l.first, cellPos, cellSize, cellOrient], cl]; ENDLOOP; END; DeComposedList: PUBLIC PROC[il: CD.InstanceList, cellPos, cellSize: CD.Position, cellOrient: CD.Orientation] RETURNS [dcl: CD.InstanceList _ NIL] = BEGIN FOR l: CD.InstanceList _ il, l.rest WHILE l#NIL DO dcl _ CONS[DeComposed[l.first, cellPos, cellSize, cellOrient], dcl]; ENDLOOP; END; END. .CDInstancesImpl.mesa (part of ChipNDale) Copyright c 1983, 1986 by Xerox Corporation. All rights reserved. by Christian Jacobi, May 12, 1983 12:22 pm last edited by Christian Jacobi, March 14, 1986 2:08:42 pm PST --Procedures with vanilla stuff around instances --be carefull, InstanceList's are lists of pointers, distinguish between: --procedures which modify the application list, from procedures which don't --procedures which modify the instances pointed to, from procedures which don't --procedures which modify an application list, from procedures which modify the instances --procedures inspecting an application list --returns "pos points to the application inst", using its virtual coordinates --returns "pos points to the application inst", using its virtual coordinates --returns a reference to an application at location pos (or NIL if there is none) --procedures which modify the instances referenced by a list --composes the lists "inst" and "to" --the original list "to" is destroied and must be replaced by the retuned list --the original list "inst" is not touched --procedures which handle the application list but don't modify the instances -- returns new list but same instances --procedures which create a new application list, with new instances --creates a new list with new instances Κπ˜codešœ.™.Kšœ Οmœ7™BKšœ,™,Kšœ?™?—K˜Kšœ0™0K˜šΟk ˜ Kšžœ˜K˜ K˜ K˜ K˜ —K˜šΠblœžœžœ˜Kšžœ2˜9Kšžœ˜—Kšž˜K˜KšœI™IKšœK™KKšœO™OKšœY™YK˜Kšœ+™+K˜šΟnœžœžœžœžœ žœžœ˜LKšœM™MKšž˜Kšœžœ%˜*Kšžœžœžœžœ˜3Kšžœ˜Kšžœ˜K˜—š  œžœžœžœžœžœžœ˜OKšœM™MKšž˜šžœ˜ Kšœ ˜ šœ˜Kšœ˜Kšœ˜Kšœ!˜!Kšœ˜Kšœ˜—Kšœ˜—Kšžœ˜K˜—š   œž œžœ žœžœ˜>Kšž˜šžœ˜šœ˜Kšœ%˜%Kšœ˜Kšœ!˜!Kšœ˜K˜—K˜—Kšžœ˜K˜—š œžœžœžœžœžœžœžœ žœžœ ˜ Kšž˜Kšœžœžœžœp˜ŽKšžœ˜K˜—š  œžœžœžœ žœžœ ˜=Kšž˜Kšžœžœžœžœ€˜ΔKšžœ˜K˜K˜—š œžœžœžœžœžœžœžœ žœžœ ˜‘Kšž˜šœžœ ˜'šœ˜Kšœ žœ˜ K˜K˜K˜K˜——KšœY˜YKšžœ˜K˜—š  œžœžœžœžœžœ žœ˜qKšž˜š žœžœžœžœžœžœž˜8Kš žœžœžœžœžœ˜3Kšœ@˜@Kšžœ˜—Kšžœ˜K˜—š  œžœžœžœžœžœ žœ˜qKšž˜š žœžœžœžœžœžœž˜8Kš žœžœžœžœžœ˜3Kšœ4˜4Kšžœ˜—Kšžœ˜—K˜š  œžœžœžœžœžœžœžœ ˜kKšœQ™QKšž˜š žœžœžœžœž˜2šžœžœ˜'Kšžœ$˜'Kšžœžœ˜ Kšžœ ˜—Kšžœ˜—Kšžœžœ˜ Kšžœ˜K˜K˜—Kšœ<™