DIRECTORY PrincOpsUtils, CD, Graphics; CDOrient: CEDAR DEFINITIONS IMPORTS Graphics, PrincOpsUtils = BEGIN Orientation: TYPE = CD.Orientation; original: Orientation = 0; rotate90: Orientation = 4; rotate180: Orientation = 8; rotate270: Orientation = 12; mirrorX: Orientation = 1; MapRect: PROC [itemInCell: CD.Rect, cellSize: CD.Position, cellInstOrient: Orientation, cellInstPos: CD.Position _ [0,0]] RETURNS [itemInWorld: CD.Rect]; DeMapRect: PROC [itemInWorld: CD.Rect, cellSize: CD.Position, cellInstOrient: Orientation, cellInstPos: CD.Position _ [0,0]] RETURNS [itemInCell: CD.Rect]; MapPosition: PROC [itemInCell: CD.Rect, cellSize: CD.Position, cellInstOrient: Orientation, cellInstPos: CD.Position _ [0,0]] RETURNS [posInWorld: CD.Position]; ComposeOrient: PROC [ itemOrientInCell, cellOrientInWorld: Orientation] RETURNS [itemOrientInWorld: Orientation]; InverseOrient: PROC [orient: Orientation] RETURNS [inverse: Orientation]; DecomposeOrient: PROCEDURE[ itemOrientInWorld, cellOrientInWorld: Orientation] RETURNS [itemOrientInCell: Orientation]; OrientedSize: PROC [size: CD.Position, orient: Orientation] RETURNS [CD.Position] = INLINE {RETURN [IF IncludesOddRot90[orient] THEN [x: size.y, y: size.x] ELSE size]}; OrientedRect: PROC [rect: CD.Rect, orient: Orientation] RETURNS [CD.Rect] = INLINE {RETURN [IF IncludesOddRot90[orient] THEN [x1: rect.x1, y1: rect.y1, x2: rect.x1+rect.y2-rect.y1, y2: rect.y1+rect.x2-rect.x1] ELSE rect]}; RectAt: PROC [pos, size: CD.Position, orient: Orientation_original] RETURNS [CD.Rect] = INLINE {RETURN [ IF IncludesOddRot90[orient] THEN CD.Rect[x1: pos.x, y1: pos.y, x2: pos.x+size.y, y2: pos.y+size.x] ELSE CD.Rect[x1: pos.x, y1: pos.y, x2: pos.x+size.x, y2: pos.y+size.y]]}; IncludesOddRot90: PROC [orient: Orientation] RETURNS [BOOLEAN] = TRUSTED INLINE {RETURN [PrincOpsUtils.BITAND[orient, rotate90]#0]}; IncludesOddRot45: PROC [orient: Orientation] RETURNS [BOOLEAN] = TRUSTED INLINE {RETURN [PrincOpsUtils.BITAND[orient, 2]#0]}; IncludesMirrorX: PROC [orient: Orientation] RETURNS [BOOLEAN] = TRUSTED INLINE {RETURN [PrincOpsUtils.BITAND[orient, mirrorX]#0]}; MirrorX: PROC [orient: Orientation] RETURNS [Orientation] = TRUSTED INLINE {RETURN [PrincOpsUtils.BITXOR[orient, mirrorX]]}; Rotate90: PROC [orient: Orientation] RETURNS [Orientation] = TRUSTED INLINE {RETURN [PrincOpsUtils.BITAND[orient+rotate90, 15]]}; ConcentrateOnRotate90: PROC [orient: Orientation] RETURNS [Orientation] = TRUSTED INLINE {RETURN [PrincOpsUtils.BITAND[orient, 12]]}; OrientateContext: PROC [cont: Graphics.Context, size: CD.DesignPosition, orient: Orientation] = INLINE BEGIN SELECT ConcentrateOnRotate90[orient] FROM -- chipndale rotates clockwise but graphics anticlockwise original => IF IncludesMirrorX[orient] THEN {Graphics.Scale[cont, -1, 1]; Graphics.Translate[cont, -size.x, 0]}; rotate90 => BEGIN Graphics.Rotate[cont, 90]; Graphics.Translate[cont, 0, -size.y]; IF IncludesMirrorX[orient] THEN {Graphics.Scale[cont, 1, -1]; Graphics.Translate[cont, 0, -size.y]}; END; rotate180 => BEGIN Graphics.Rotate[cont, 180]; Graphics.Translate[cont, -size.x, -size.y]; IF IncludesMirrorX[orient] THEN {Graphics.Scale[cont, -1, 1]; Graphics.Translate[cont, -size.x, 0]}; END; rotate270 => BEGIN Graphics.Rotate[cont, 270]; Graphics.Translate[cont, -size.x, 0]; IF IncludesMirrorX[orient] THEN {Graphics.Scale[cont, 1, -1]; Graphics.Translate[cont, 0, -size.y]}; END; ENDCASE =>ERROR; END; END. VCDOrient.mesa (part of Chipndale) last edited by Ch. Jacobi, November 21, 1983 8:55 pm some code from "ChipOrient" E. McCreight, February 22, 1982 10:00 AM --If your program depends on the representation of Orientation, it --is probably wrong. --An orientation idx is composed of two parts: --a clockwise rotation of (idx/2)*45 degrees, --followed by a reflection in x if (idx MOD 2)#0 --odd multiples of 45 degrees are not supported for all kind of objects --clockwise and anticlockwise might be reversed depending on coordinate system: --if the origin is on top we mean really clockwise for clockwise, --if the origin is on the bottom we have to exchange clockwise with anticlockwise --Given an item in a prototype cell, and the --size of the prototype cell, both in "cell" co-ordinates, and --the position and orientation index of an instance of that cell in "world" --co-ordinates, this procedure returns the world --co-ordinates of the instance of the item. --Given an item in world co-ordinates, and the --size of a prototype cell, in "cell" co-ordinates, and --the position and orientation index of an instance of that cell in "world" --co-ordinates, this procedure returns the cell prototype --co-ordinates of that item. --Given an position in a prototype cell, and the --size of the prototype cell, both in "cell" co-ordinates, and --the position and orientation index of an instance of that cell in "world" --co-ordinates, this procedure returns the world --co-ordinates of the instance of the item. --This procedure produces the composite orientation --obtained by first doing itemInCell and then --doing cellInWorld. --For all orientationIndexes o1, ComposeOrient[o1, InverseOrient[o1]] = 0. For all orientationIndexes o1 and o2, --DecomposeOrient[cellOrientInWorld: o1, itemOrientInWorld: --ComposeOrient[cellOrientInWorld: o1, itemOrientInCell: o2]] = o2. --returns the size transformed by transformation "orient" --returns the rect "rect" transformed by transformation "orient" --returns a rect of size "size" at position "pos" and orientation "orient" --returns orient includes an odd multiple of 90 degree --returns orient includes an odd multiple of 45 degree --returns orient includes some mirroring --returns the orientation composed with mirror in x --returns the orientation composed with a clockwise rotation of 90 degree --discard mirroring and rotations of 45 degree -- if cont is an context drawing in object coordinates of an un-transformed object, -- transforms cont such that it draws into an oriented object. (size=size of object) -- but we do still not reverse rotation, because viewerpackage does ÊŽ˜Jšœ"™"J˜Jšœ4™4JšœE™EJ˜šÏk ˜ Jšœ˜Jš˜Jšœ ˜ J˜—šÏnœœ œ˜Jšœ˜!Jšœ˜J˜šœ œœ ˜#JšœB™BJšœ™Jšœ.™.Jšœ-™-Jšœ0™0JšœH™H—JšœO™OJšœA™AJšœQ™QJ˜J˜J˜J˜J˜J˜J˜J˜šžœœœœ ˜:Jšœ*œ˜>Jšœœ˜Jšœ,™,Jšœ>™>JšœK™KJšœ0™0Jšœ+™+J˜J˜—šž œœœœ ˜=Jšœ*œ˜>Jšœœ˜Jšœ.™.Jšœ7™7JšœK™KJšœ9™9Jšœ™J˜J˜—šž œœœœ ˜>Jšœ*œ˜>Jšœœ ˜"Jšœ0™0Jšœ>™>JšœK™KJšœ0™0Jšœ+™+J˜J˜—šž œœ˜J˜1Jšœ"˜)Jšœ3™3Jšœ-™-Jšœ™J˜J˜—šž œœ˜)Jšœ˜JšœJ™JJ˜J˜—šžœ œ˜J˜2Jšœ!˜(Jšœ%™%Jšœ;™;JšœC™CJ˜J˜J˜—š ž œœœ œœ ˜TJšœ:™:šœœ˜Jšœœœœ˜EJ˜——š ž œœœœœ ˜LJšœA™Ašœœ˜šœœœ˜"J˜U—Jšœ˜ J˜——š žœœ œ)œœ ˜XJšœK™Kšœœ˜Jšœœœ@˜cJšœœB˜IJ˜J˜J˜——šžœœœœ˜AJšœ7™7Jšœœœ˜CJ˜—šžœœœœ˜AJšœ7™7Jšœœœ˜