File: StretchImpl.mesa   
Copyright © 1984 by Xerox Corporation. All rights reserved.
Created by: Mayo, June 26, 1984 12:12:25 pm PDT
Last Edited by: Mayo, November 5, 1984 4:46:45 pm PST
DIRECTORY
Stretch,
Atom USING [GetPName],
CDSequencer USING [Command, ImplementCommand],
Rope USING [Cat, ROPE],
CDDirectory USING [Include],
CDBasics USING [SubPoints],
CDOps USING [DelayedRedraw],
CDObjectProcs USING [RegisterFurther, FetchFurther],
TerminalIO USING [WriteRope],
CD USING [Design, Position, ObPtr, ObjectProcs];
StretchImpl: CEDAR PROGRAM    
IMPORTS Atom, Rope, CDDirectory, CDObjectProcs, CDBasics, TerminalIO, CDSequencer, CDOps EXPORTS Stretch =  
BEGIN OPEN Stretch;
DoStretch: PUBLIC PROC [obj: CD.ObPtr, design: CD.Design, place: INT, dir: Direction, amount: INT] RETURNS [CD.ObPtr, Rope.ROPE] = {
proc: REF StretchProc ← NARROW[CDObjectProcs.FetchFurther[obj.p, $StretchProc]];
ob: CD.ObPtr;
msg: Rope.ROPE;
IF amount = 0 THEN
RETURN[obj, NIL];
IF proc = NIL THEN
RETURN[NIL, Rope.Cat["Don't know how to stretch objects of type '", Atom.GetPName[obj.p.objectType], "'."]];
[ob, msg] ← proc[obj, design, place, dir, amount];
RETURN[ob, msg];
};
-- Top-level command routines
StretchArea: PROC [comm: CDSequencer.Command] = BEGIN
oldObj: CD.ObPtr ← comm.design.actual.first.dummyCell.ob;
obj: CD.ObPtr;
dist: CD.Position;
xPlace, yPlace: INT;
msg: Rope.ROPE;
obj ← oldObj;
dist ← CDBasics.SubPoints[comm.pos, comm.sPos];
IF dist.x < 0 THEN
xPlace ← comm.pos.x
ELSE
xPlace ← comm.sPos.x;
IF dist.y < 0 THEN
yPlace ← comm.pos.y
ELSE
yPlace ← comm.sPos.y;
[obj, msg] ← DoStretch[obj, comm.design, xPlace, $right, dist.x];
IF obj = NIL THEN {
TerminalIO.WriteRope[msg];
TerminalIO.WriteRope[" Stretch not done."];
TerminalIO.WriteRope["\n"];
RETURN;
};
[obj, msg] ← DoStretch[obj, comm.design, yPlace, $up, dist.y];
IF obj = NIL THEN {
TerminalIO.WriteRope[msg];
TerminalIO.WriteRope[" Stretch not done."];
TerminalIO.WriteRope["\n"];
RETURN;
};
IF obj = oldObj THEN RETURN;
IF ~CDDirectory.Include[comm.design, obj] THEN {
TerminalIO.WriteRope["Error: Could not include new object into the design.\n"];
RETURN;
};
comm.design.actual.first.dummyCell.ob ← obj;
comm.design.actual.first.specific ← NARROW[obj.specificRef];
CDOps.DelayedRedraw[design: comm.design, eraseFirst: TRUE];
TerminalIO.WriteRope["Stretch Done.\n"];
END;
Init: PROC[] = BEGIN
CDObjectProcs.RegisterFurther[$StretchProc, NIL];
CDSequencer.ImplementCommand[$StretchArea, StretchArea];
END;
-- Main body
Init[];
END.