CDXImpl.mesa (part of ChipNDale)
Copyright © 1984, 1985 by Xerox Corporation. All rights reserved.
by Ch. Jacobi, September 10, 1984 9:20:09 am PDT
last edited by Ch. Jacobi, December 20, 1985 3:40:02 pm PST
DIRECTORY
CD,
CDBasics,
CDOrient,
CDX;
CDXImpl: CEDAR PROGRAM
IMPORTS CD, CDBasics, CDOrient, CDX
EXPORTS CDX =
BEGIN
--Public interface between ChipNDale and outside clients.
--Maps chipndales complex and mutable (but fast clippable) positioning
--mechanism to an immutable client cordinate system.
--The Origin is a hypothtical point of an object; the client's cordinate
--system origin.
--types
ClientPosition: TYPE = CD.Position;
ClientRect: TYPE = CD.Rect;
--Transfer between ChipNDale and client coordinates, both relative to the object
--  have all been inlines
ClientIRect: PUBLIC PROC [ob: CD.Object] RETURNS [ClientRect] =
BEGIN
RETURN [ CDBasics.MoveRect[ob.class.interestRect[ob], CDBasics.NegOffset[ob.class.origin[ob]]]]
END;
ClientORect: PUBLIC PROC [ob: CD.Object] RETURNS [ClientRect] =
BEGIN
RETURN [CDBasics.RectAt[CDBasics.NegOffset[ob.class.origin[ob]], ob.size]]
END;
--Transfer between client object relative coordinates and ChipNDale global coordinates
MapClientPos: PUBLIC PROC [cPos: ClientPosition←[0, 0], inst: CD.Instance] RETURNS [globPos: CD.Position] =
BEGIN
cPos ← CDX.ClientToCDPos[inst.ob, cPos];
RETURN [CDOrient.MapPoint[
pointInCell: cPos,
cellSize: inst.ob.size,
cellInstOrient: inst.orientation,
cellInstPos: inst.location
]]
END;
DeMapClientPos: PUBLIC PROC [globPos: CD.Position, inst: CD.Instance] RETURNS [cPos: ClientPosition] =
BEGIN
pointInCell: CD.Position = CDOrient.DeMapPoint[
pointInWorld: globPos,
cellSize: inst.ob.size,
cellInstOrient: inst.orientation,
cellInstPos: inst.location
];
RETURN [CDX.CDToClientPos[inst.ob, pointInCell]]
END;
MapClientRect: PUBLIC PROC [cRect: ClientRect, inst: CD.Instance] RETURNS [globRect: CD.Rect] =
BEGIN
RETURN [CDOrient.MapRect[
itemInCell: CDX.ClientToCDRect[inst.ob, cRect],
cellSize: inst.ob.size,
cellInstOrient: inst.orientation,
cellInstPos: inst.location
]]
END;
DeMapClientRect: PUBLIC PROC [globRect: CD.Rect, inst: CD.Instance] RETURNS [cRect: ClientRect] =
BEGIN
RETURN [CDX.CDToClientRect[inst.ob,
CDOrient.DeMapRect[
itemInWorld: globRect,
cellSize: inst.ob.size,
cellInstOrient: inst.orientation,
cellInstPos: inst.location
]
]]
END;
PositionFromPairO: PUBLIC PROC [ob: CD.Object,
cPos: ClientPosition←[0,0],
correspondingGlobPos: CD.Position←[0,0],
orientation: CD.Orientation𡤀
] RETURNS [appPos: CD.Position] =
--Computes a position useable for an application, such that the
--client-origin relative point oPos is at the global position correspondingGlobPos
BEGIN
obCDPos: CD.Position = CDX.ClientToCDPos[ob, cPos];
fakeAppPos: CD.Position = CDOrient.MapPoint[
pointInCell: obCDPos,
cellSize: ob.size,
cellInstOrient: orientation,
cellInstPos: [0, 0]
];
RETURN [CDBasics.SubPoints[correspondingGlobPos, fakeAppPos]]
END;
PositionFromPairI: PUBLIC PROC [ob: CD.Object,
cPos: ClientPosition←[0,0],
correspondingGlobPos: CD.Position←[0,0],
orientation: CD.Orientation𡤀
] RETURNS [iPos: CD.Position] =
--Computes the position of the innerrect, such that the client-origin
--relative point oPos is at the global position correspondingGlobPos
BEGIN
appOPos: CD.Position = PositionFromPairO[ob, cPos, correspondingGlobPos, orientation];
RETURN [CDBasics.BaseOfRect[CDOrient.MapRect[
itemInCell: CD.InterestRect[ob],
cellSize: ob.size,
cellInstOrient: orientation,
cellInstPos: appOPos
]]]
END;
END.