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; NewInstance: PUBLIC PROC [ob: CD.Object_NIL, location: CD.Position_[0,0], orientation: CD.Orientation_0, selected: BOOL _ FALSE, properties: CD.PropList_NIL] RETURNS [CD.Instance] = BEGIN off: CD.Position = CDBasics.BaseOfRect[ CDOrient.MapRect[ itemInCell: CD.InterestRect[ob], cellSize: ob.size, cellInstOrient: orientation, cellInstPos: [0, 0] ]]; a: CD.Instance = NEW[CD.InstanceRep _ CD.InstanceRep[ ob: ob, location: CDBasics.SubPoints[location, off], orientation: orientation, selected: selected, properties: properties ]]; RETURN [a] END; BoundingRectO: PUBLIC PROC[list: CD.InstanceList, selectedOnly: BOOL_FALSE] RETURNS [CD.Rect] = BEGIN bound: CD.Rect _ CDBasics.empty; FOR tem: LIST OF CD.Instance _ list, tem.rest WHILE tem#NIL DO IF selectedOnly AND NOT tem.first.selected THEN LOOP; bound _ CDBasics.Surround[bound, CDInstances.InstRectO[tem.first]] ENDLOOP; RETURN [bound] END; BoundingRectI: PUBLIC PROC[list: CD.InstanceList, selectedOnly: BOOL_FALSE] RETURNS [CD.Rect] = BEGIN bound: CD.Rect _ CDBasics.empty; FOR tem: LIST OF CD.Instance _ list, tem.rest WHILE tem#NIL DO IF selectedOnly AND NOT tem.first.selected THEN LOOP; bound _ CDBasics.Surround[bound, InstRectI[tem.first]] ENDLOOP; RETURN [bound] END; InstanceAt: PUBLIC PROC [il: CD.InstanceList, pos: CD.Position, selectedOnly: BOOL_FALSE] RETURNS [CD.Instance] = BEGIN FOR w: CD.InstanceList _ il, w.rest WHILE w#NIL DO IF (~selectedOnly OR w.first.selected) AND CDInstances.PointToO[pos, w.first] AND PointToI[pos, w.first] THEN RETURN [w.first] ENDLOOP; RETURN [NIL] END; TransformList: PUBLIC PROC[il: CD.InstanceList, cellRect: CD.Rect, transformation: CD.Orientation] = BEGIN FOR t: CD.InstanceList _ il, t.rest WHILE t#NIL DO Transform[t.first, cellRect, transformation]; ENDLOOP 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; SplitPointed: PUBLIC PROC [from: CD.InstanceList, pos: CD.Position] RETURNS [pointed, others: CD.InstanceList] = BEGIN pApp: CD.Instance = InstanceAt[from, pos]; pointed _ NIL; others _ NIL; FOR w: CD.InstanceList _ from, w.rest WHILE w#NIL DO IF w.first=pApp THEN pointed _ LIST[w.first] ELSE others _ CONS[w.first, others] ENDLOOP END; SplitSelected: PUBLIC PROC [from: CD.InstanceList] RETURNS [selected, others: CD.InstanceList] = BEGIN selected_NIL; others_NIL; FOR w: CD.InstanceList _ from, 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; Transform: PUBLIC PROC [inst: CD.Instance, cellRect: CD.Rect, transformation: CD.Orientation] = BEGIN r: CD.Rect _ CDOrient.MapRect[ itemInCell: CDOrient.RectAt[ CDBasics.SubPoints[inst.location, CDBasics.BaseOfRect[cellRect]], inst.ob.size, inst.orientation], cellSize: CDBasics.SizeOfRect[cellRect], cellInstOrient: transformation, cellInstPos: CDBasics.BaseOfRect[cellRect]]; inst.location _ CDBasics.BaseOfRect[r]; inst.orientation _ CDOrient.ComposeOrient[ itemOrientInCell: inst.orientation, cellOrientInWorld: transformation]; END; CopyList: PUBLIC PROC[il: CD.InstanceList] RETURNS [CD.InstanceList] = BEGIN newList: CD.InstanceList _ NIL; FOR t: CD.InstanceList _ il, t.rest WHILE t#NIL DO a: CD.Instance = NEW[CD.InstanceRep _ t.first^]; a.properties _ CDProperties.DangerousCopyProps[a.properties]; newList _ CONS[a, newList] ENDLOOP; RETURN [newList] END; ComposedCopy: PUBLIC PROC[il: CD.InstanceList, cellPos, cellSize: CD.Position, cellOrient: CD.Orientation] RETURNS [CD.InstanceList] = BEGIN r: CD.Rect; newList: CD.InstanceList _ NIL; FOR t: CD.InstanceList _ il, t.rest WHILE t#NIL DO a: CD.Instance _ NEW[CD.InstanceRep _ t.first^]; r _ CDOrient.MapRect[ itemInCell: CDOrient.RectAt[a.location, a.ob.size, a.orientation], cellSize: cellSize, cellInstOrient: cellOrient, cellInstPos: cellPos]; a.location _ CDBasics.BaseOfRect[r]; a.orientation _ CDOrient.ComposeOrient[ itemOrientInCell: a.orientation, cellOrientInWorld: cellOrient]; a.properties _ CDProperties.DangerousCopyProps[t.first.properties]; newList _ CONS[a, newList] ENDLOOP; RETURN [newList] END; DeComposedCopy: PUBLIC PROC[il: CD.InstanceList, cellPos, cellSize: CD.Position, cellOrient: CD.Orientation] RETURNS [CD.InstanceList] = BEGIN r: CD.Rect; newList: CD.InstanceList _ NIL; FOR t: CD.InstanceList _ il, t.rest WHILE t#NIL DO a: CD.Instance _ NEW[CD.InstanceRep_ t.first^]; r _ CDOrient.DeMapRect[ itemInWorld: CDOrient.RectAt[a.location, a.ob.size, a.orientation], cellSize: cellSize, cellInstOrient: cellOrient, cellInstPos: cellPos]; a.location _ CDBasics.BaseOfRect[r]; a.orientation _ CDOrient.DecomposeOrient[ itemOrientInWorld: a.orientation, cellOrientInWorld: cellOrient]; a.properties _ CDProperties.DangerousCopyProps[t.first.properties]; newList _ CONS[a, newList] ENDLOOP; RETURN [newList] END; END. CDInstancesImpl.mesa (part of ChipNDale) Copyright c 1983, 1985 by Xerox Corporation. All rights reserved. by Christian Jacobi, May 12, 1983 12:22 pm last edited by Christian Jacobi, September 20, 1985 3:37:35 pm PDT --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 --copyes the pointed application references from "from" to "pointed" --copyes the non-pointed application references from "from" to "others" --does not make copies of the real instances --finds maximal 1 pointed application --copyes the selected application references from "from" to "selected" --copyes the non-selected application references from "from" to "others" --does not make copies of the real instances -- returns new list but same instances --procedures which create a new application list, with new instances --performs "transformation" to "inst"; the transformation occurs to the rect "cellRect". --"cellRect" and "inst" in the same coordinate system --WARNING transformation group NOT abelsch --creates a new list with new instances --makes a copy of "il" with world coordinates assumed that "il" has cell coordinates --cellSize in cell coordinates, cellPos in world cordinates --the new list points to new instances --makes a copy of "il" with cell coordinates assumed il has world coordinates --cellSize in cell coordinates --cellPos, cellOrient in world coordinates --the new list points to new instances Κ £˜codešœ.™.Kšœ Οmœ7™BKšœ,™,KšœC™C—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˜—š  œžœžœžœžœ žœžœ˜hKš œ žœžœžœ žœžœžœ ˜MKšž˜šœžœ ˜'šœ˜Kšœ žœ˜ K˜K˜K˜K˜——š œžœ žœžœžœ ˜5K˜K˜,K˜K˜K˜K˜—Kšžœ˜ Kšžœ˜K˜—š  œžœžœžœžœžœžœžœ˜_Kšž˜Kšœžœ˜ š žœžœžœžœžœžœž˜>Kš žœžœžœžœžœ˜5KšœB˜BKšžœ˜—Kšžœ˜Kšžœ˜K˜—š  œžœžœžœžœžœžœžœ˜_Kšž˜Kšœžœ˜ š žœžœžœžœžœžœž˜>Kš žœžœžœžœžœ˜5Kšœ6˜6Kšžœ˜—Kšžœ˜Kšžœ˜—K˜š   œžœžœžœžœ ˜@Kš œžœžœžœžœ ˜1KšœQ™QKšž˜š žœžœžœžœž˜2šžœžœ˜'Kšžœ$˜'Kšžœžœ˜ Kšžœ ˜—Kšžœ˜—Kšžœžœ˜ Kšžœ˜K˜K˜—Kšœ<™