CDViewerImpl.mesa (part of Chipndale)
by Christian Jacobi October 13, 1983 3:07 pm
last edited by Christian Jacobi November 21, 1983 8:38 pm
DIRECTORY
CD,
CDViewer,
CDVPrivate,
CDInline,
Rope USING [ROPE, Equal],
ViewerClasses USING [Viewer],
ViewerOps;
CDViewerImpl: CEDAR PROGRAM
IMPORTS CDVPrivate, CDInline, Rope, ViewerOps
EXPORTS CDViewer
SHARES CDVPrivate =
BEGIN
ViewerList: TYPE = LIST OF ViewerClasses.Viewer;
ViewersOf: PUBLIC PROC[design: REF] RETURNS [vl: ViewerList←NIL] =
BEGIN
FOR l: CDVPrivate.MyGraphicRef ← CDVPrivate.linkBase, l.link WHILE l#NIL DO
IF design=l.actualDesign OR design=l.actualDesign.technology THEN vl ← CONS[l.viewer, vl];
ENDLOOP
END;
DesignOf: PUBLIC PROC[viewer: ViewerClasses.Viewer] RETURNS
[isDesign: BOOLFALSE, design: CD.Design←NIL, rect: CD.DesignRect�Inline.empty] =
BEGIN
IF viewer#NIL AND viewer.data#NIL
AND ISTYPE[viewer.data, CDVPrivate.MyGraphicRef] THEN {
me: CDVPrivate.MyGraphicRef = NARROW[viewer.data];
design ← me.actualDesign;
IF me.deviceDrawRef#NIL THEN rect ← me.deviceDrawRef.worldClip;
isDesign←TRUE;
};
END;
ShowPosition: PUBLIC PROC[viewer: ViewerClasses.Viewer, pos: CD.DesignPosition] =
--moves viewer such that pos is in visible area (does not open closed viewer)
--approximative only
BEGIN
viewerCenterOffset: CD.Position ← [viewer.cw/2, viewer.ch/2];
designCenterOffset: CD.Position;
IF viewer#NIL AND viewer.data#NIL
AND ISTYPE[viewer.data, CDVPrivate.MyGraphicRef] THEN {
me: CDVPrivate.MyGraphicRef = NARROW[viewer.data];
IF CDInline.InsidePos[pos, me.deviceDrawRef.worldClip] THEN RETURN;
me.noff ← [0, 0];
designCenterOffset ← CDVPrivate.ViewerToDesignPosition[me, viewerCenterOffset];
CDVPrivate.SetScale[me, me.nscale, me.ngrid, CDInline.SubPoints[pos, designCenterOffset]];
ViewerOps.PaintViewer[viewer, client, FALSE, NIL];
};
END;
ShowAndScale: PUBLIC PROC[viewer: ViewerClasses.Viewer, rect: CD.DesignRect] =
--moves and scales viewer such that rect is in visible area (does not open closed viewer)
--approximative only
BEGIN
viewerCenterOffset: CD.Position ← [viewer.cw/2, viewer.ch/2];
nw, nh: CD.DesignNumber;
IF viewer#NIL AND viewer.data#NIL
AND ISTYPE[viewer.data, CDVPrivate.MyGraphicRef] THEN {
me: CDVPrivate.MyGraphicRef = NARROW[viewer.data];
noff: CD.DesignPosition = me.noff;
FOR j: CARDINAL ← 0, j+1 WHILE j<CDVPrivate.scaleNum DO
CDVPrivate.SetScale[me, j, me.ngrid, noff];
IF CDVPrivate.ScaleViewerToDesign[me, viewer.cw]>(rect.x2-rect.x1)
AND CDVPrivate.ScaleViewerToDesign[me, viewer.ch]>(rect.y2-rect.y1) THEN EXIT
ENDLOOP;
nw ← CDVPrivate.ScaleViewerToDesign[me, viewer.cw];
nh ← CDVPrivate.ScaleViewerToDesign[me, viewer.ch];
CDVPrivate.SetScale[me, me.nscale, me.ngrid, [rect.x1-(nw-(rect.x2-rect.x1))/2, rect.y1-(nh-(rect.y2-rect.y1))/2]];
ViewerOps.PaintViewer[viewer, client, FALSE, NIL];
};
END;
CreateViewer: PUBLIC PROC [design: CD.Design] RETURNS [ViewerClasses.Viewer] =
{RETURN [CDVPrivate.CreateViewer[design]]};
ShowArrow: PUBLIC PROC [design: CD.Design, pos: CD.DesignPosition] =
{CDVPrivate.ShowArrow[design, pos]};
RemoveArrow: PUBLIC PROC[design: CD.Design] =
{CDVPrivate.RemoveArrow[design]};
FindDesign: PUBLIC PROC[name: Rope.ROPE, case: BOOLTRUE] RETURNS [CD.Design] =
--only designs with viewers can be found;
--if multiple designs have the same name, find arbitrary one
BEGIN
FOR l: CDVPrivate.MyGraphicRef ← CDVPrivate.linkBase, l.link WHILE l#NIL DO
IF Rope.Equal[l.actualDesign.name, name, case] THEN RETURN[l.actualDesign];
ENDLOOP;
RETURN [NIL]
END;
END.