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.Properties_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.CopyProps[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.CopyProps[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.CopyProps[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, June 11, 1985 10:10:25 am 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 Ê ™˜šœ.™.Jšœ Ïmœ7™BJšœ,™,Jšœ?™?—J˜Jšœ0™0J˜šÏk ˜ Jšžœ˜J˜ J˜ J˜ J˜ J˜—šÏbœžœžœ˜Jšžœ2˜9Jšžœ˜—Jšž˜J˜JšœI™IJšœK™KJšœO™OJšœY™YJ˜Jšœ+™+J˜šÏnœžœžœžœžœ žœžœ˜LJšœM™MJšž˜Jšœžœ%˜*Jšžœžœžœžœ˜3Jšžœ˜Jšžœ˜J˜—š  œžœžœžœžœžœžœ˜OJšœM™MJšž˜šžœ˜ Jšœ ˜ šœ˜Jšœ˜Jšœ˜Jšœ!˜!Jšœ˜Jšœ˜—Jšœ˜—Jšžœ˜J˜—š   œž œžœ žœžœ˜>Jšž˜šžœ˜šœ˜Jšœ%˜%Jšœ˜Jšœ!˜!Jšœ˜J˜—J˜—Jšžœ˜J˜—š  œžœžœžœžœ žœžœ˜hJš œ žœžœžœ žœžœžœ ˜OJšž˜šœžœ ˜'šœ˜Jšœ ˜ J˜J˜J˜J˜——š œžœ žœžœžœ ˜5J˜J˜,J˜J˜J˜J˜—Jšžœ˜ Jšžœ˜J˜—š  œžœžœžœžœžœžœžœ˜_Jšž˜Jšœžœ˜ š žœžœžœžœžœžœž˜>Jš žœžœžœžœžœ˜5JšœB˜BJšžœ˜—Jšžœ˜Jšžœ˜J˜—š  œžœžœžœžœžœžœžœ˜_Jšž˜Jšœžœ˜ š žœžœžœžœžœžœž˜>Jš žœžœžœžœžœ˜5Jšœ6˜6Jšžœ˜—Jšžœ˜Jšžœ˜—J˜š   œžœžœžœžœ ˜@Jš œžœžœžœžœ ˜1JšœQ™QJšž˜š žœžœžœžœž˜2šžœžœ˜'Jšžœ$˜'Jšžœžœ˜ Jšžœ ˜—Jšžœ˜—Jšžœžœ˜ Jšžœ˜J˜J˜—Jšœ<™