Compiler ObjectXForms
Stone May 2, 1981 1:09 PM
Last Edited by: Stone, January 28, 1983 6:43 pm
DIRECTORY
ObjectDefs: FROM "ObjectDefs",
PointDefs: FROM "PointDefs",
GriffinEncoding USING [TranslateEdge, TranslateArea],
GriffinGrid USING [MoveGrid],
GriffinText USING [GetBoundingBox],
MenuDefs: FROM "MenuDefs",
XFormDefs: FROM "XFormDefs",
GriffinMemoryDefs USING [CZone];
ObjectXForms: CEDAR PROGRAM
IMPORTS ObjectDefs,XFormDefs,PointDefs,MenuDefs, GriffinMemoryDefs, GriffinEncoding, GriffinGrid, GriffinText
EXPORTS ObjectDefs =
BEGIN OPEN ObjectDefs,XFormDefs,GriffinMemoryDefs,PointDefs;
does a translation on all control points and on the encoding
MoveObject: PUBLIC PROCEDURE[object: ObjectHandle, from,to: ScrPt]=
BEGIN
token: REF selectToken Object ← ObjectDefs.ReturnSelectToken[object];
Move[object,from,to];
IF token # NIL THEN Move[token,from,to];
END;
Move: PROCEDURE[object: ObjectHandle, from,to: ScrPt]=
BEGIN
transmatrix: XFMDescriptor ← CZone.NEW[XFormMatrix];
hgrid,vgrid: BOOLEANFALSE;
objfrom,objto,dist: ObjPt;
dx,dy: INTEGER;
moveBB: PROC = {
move bounding boxes
object.tl [X] ← object.tl [X] + dx;
object.tl [Y] ← object.tl [Y] + dy;
object.br [X] ← object.br [X] + dx;
object.br [Y] ← object.br [Y] + dy;
};
dx ← to[X]-from[X];
dy ← to[Y]-from[Y];
move the object in object space
objfrom ← ScrToObj[from];
objto ← ScrToObj[to];
dist[X] ← objto[X]-objfrom[X];
dist[Y] ← objto[Y]-objfrom[Y];
InitXForms[transmatrix];
Translate[dist,transmatrix];
XForm[object,transmatrix];
WITH object SELECT FROM
shape: REF shape Object => BEGIN
moveBB[];
GriffinEncoding.TranslateEdge[shape.edgeEncoding, [dx,dy]];
IF shape.areaEncoding#NIL THEN
GriffinEncoding.TranslateArea[shape.areaEncoding, [dx,dy]];
END;
menu: REF menu Object => BEGIN OPEN MenuDefs;
MoveMenuItem: MenuProc =
BEGIN
item.tl [X] ← item.tl [X] + dx;
item.tl [Y] ← item.tl [Y] + dy;
item.br [X] ← item.br [X] + dx;
item.br [Y] ← item.br [Y] + dy;
END;
ForAllMenuItems [menu, MoveMenuItem];
moveBB[];
END;
token: REF token Object =>
IF token.tokenType=hgrid OR token.tokenType=vgrid
THEN GriffinGrid.MoveGrid[token,dx,dy]
ELSE moveBB[];
caption: REF caption Object=> moveBB[];
selectToken: REF selectToken Object=> moveBB[];
ENDCASE;
END;
XFormObject: PUBLIC PROCEDURE [object: ObjectHandle,matrix: XFMDescriptor] =
BEGIN
token: REF selectToken Object ← ReturnSelectToken[object];
Transform the object
XForm[object,matrix];
Transform the select token
IF token # NIL THEN BEGIN
XForm[token,matrix];
[token.tl, token.br] ← GetSelectTokenBoundingBox[token];
END;
Recompute the bounding boxes
WITH object SELECT FROM
shape: REF shape Object => {
ObjectDefs.EncodeObject[shape];
ObjectDefs.AdjustBoxForStyle[shape];
};
caption: REF caption Object =>
[caption.tl, caption.br] ← GriffinText.GetBoundingBox[caption.text, caption.style, caption.p0];
ENDCASE;
END;
XForm: PROCEDURE [object: ObjectHandle,matrix: XFMDescriptor] =
TRUSTED BEGIN
WITH objtype: object SELECT FROM
shape => WITH traj: objtype.trajectory SELECT FROM
linked => BEGIN
link: REF Link ← traj.links;
UNTIL link=NIL
DO
XFormArray[link.knots,matrix];
link ← link.link;
ENDLOOP;
END;
cyclic => XFormArray[traj.knots,matrix];
ENDCASE;
captions and tokens don't do much except on translate
caption => objtype.p0 ← XFormPt[objtype.p0,matrix]; 
selectToken => objtype.p0 ← XFormPt[objtype.p0,matrix]; 
token => IF NOT (objtype.tokenType=hgrid OR objtype.tokenType=vgrid)
THEN objtype.p0 ← XFormPt[objtype.p0,matrix];  --grid is moved in GriffinGridImpl
ENDCASE;
END;
XFormArray: PROCEDURE [array: PointDefs.ObjPtSequence,xform: XFMDescriptor] =
BEGIN
i: INTEGER;
FOR i IN [0..array.length) DO
array[i] ← XFormPt[array[i],xform];
ENDLOOP;
END;
END.