-- objectdefs
-- Griffin object types and manipulating routines
-- Stone April 1, 1981 10:51 PM
-- Last Edited by: Stone, February 14, 1983 10:41 am

DIRECTORY
 PointDefs: FROM "PointDefs",
 EncodingDefs: FROM "EncodingDefs",
 StyleDefs: FROM "StyleDefs",
 XFormDefs: FROM "XFormDefs",
 SplineDefs: FROM "SplineDefs",
 Graphics USING [Context],
 Rope USING [ROPE],
 GriffinFontDefs: FROM "GriffinFontDefs";

ObjectDefs: DEFINITIONS =
BEGIN

ObjectType: TYPE = {shape,caption,token, menu};
ObjectHandle: TYPE = REF Object;
TokenType: TYPE = {CP,open, center, hgrid, vgrid, selected};

View: TYPE = {main,alternate};
MenuOrientation: TYPE = {horizontal, vertical};
ClusterID: TYPE = [0..1023];
selW: PUBLIC INTEGER;
OpenCluster: ClusterID = 1;
DisplayFnc: TYPE = {write,erase};


Object: TYPE = RECORD
 [
 link: ObjectHandle ← NIL,
 backLink: ObjectHandle ← NIL,
 style: StyleDefs.StyleHandle ← NIL,
 cluster: ClusterID ← 0,
 view: View ← main,
 deleted: BOOLEANFALSE,
 visible: BOOLEANTRUE,
 selected: BOOLEANFALSE,
 cull: {inside,outside,partial} ← partial,
-- part of encoding, but are here since true for all variants
 validEncoding: BOOLEANFALSE,
 tl,br: PointDefs.ScrPt ← [0,0],
 body: SELECT objectType: ObjectType FROM
  shape =>
   [
   closed: BOOLEANFALSE,
   trajectory: REF Trajectory ← NIL,
   chainEncoding: EncodingDefs.ChainHandle ← NIL, --for the traj
   areaEncoding: EncodingDefs.AreaHandle ← NIL
   ],
  caption =>
   [
   p0: PointDefs.ObjPt ← [-1,-1],
   text: Rope.ROPENIL
   ],
  token =>
   [
   tokenType: TokenType ← CP,
   p0: PointDefs.ObjPt ← [0,0],
   isSelected: ObjectHandle ← NIL
   ],
  menu =>
   [
   orientation: MenuOrientation ← vertical,
   head: REF ANYNIL --MenuDefs.MenuItemHandle. There is a loop
   ],
  ENDCASE
 ];


Trajectory: TYPE = RECORD
 [splineType: SplineDefs.SplineType,
 traj: SELECT type:* FROM
  linked => [links: REF Link ← NIL],
  cyclic => [knots: PointDefs.ObjPtSequence ← NIL],
  ENDCASE
 ];


Link: TYPE = RECORD
 [link: REF Link ← NIL,
 degree: {D0,D1,D2,D3},
 knots: PointDefs.ObjPtSequence ← NIL
 ];
ObjectProc: TYPE = PROCEDURE [obj: ObjectHandle];

--procedures implemented by objectfns

ObjectFns: PROGRAM;
GetCurrentView: PUBLIC PROCEDURE RETURNS [View];
SetCurrentView: PROCEDURE[view: View];
Visible: PROCEDURE[object: ObjectHandle] RETURNS[BOOLEAN];
GetNextClusterID: PROCEDURE RETURNS[id: ClusterID];
GetNextObject: PROCEDURE [obj: ObjectHandle] RETURNS [ObjectHandle];
ForAllObjects: PROCEDURE [proc: ObjectProc];
ForAllPictureObjects: PROCEDURE [proc: ObjectProc];
ForAllVisibleObjects: PROCEDURE [proc: ObjectProc] ;
ForAllVisiblePictureObjects: PROCEDURE [proc: ObjectProc] ;
ForAllObjectsThroughObject: PROCEDURE [proc: ObjectProc,
 lastObj: ObjectHandle];
GetTopPictureObj: PROCEDURE RETURNS [ObjectHandle];
ForAllInBoxDo: PROCEDURE[tl,br: PointDefs.ScrPt,proc: ObjectProc]
RETURNS [BOOLEAN];
ForAllPictureObjectsInBoxDo: PROCEDURE[tl,br: PointDefs.ScrPt,proc:
  ObjectProc] RETURNS [BOOLEAN];
ForAllInCluster: PROCEDURE [id: ClusterID,proc: ObjectProc] ;

GetObjectHandle: PROCEDURE [pt: PointDefs.ScrPt] RETURNS [ObjectHandle];
GetObjectHandleBetweenObjects: PROCEDURE
 [pt: PointDefs.ScrPt,topObject,bottomObject: ObjectHandle] RETURNS [ObjectHandle] ;

StartObject: PROCEDURE[type: ObjectType] RETURNS [ObjectHandle];
AddLink: PROCEDURE[obj: REF shape Object,link: REF Link];
DeleteLink: PROCEDURE[obj: REF shape Object,link: REF Link];
CopyObject: PROCEDURE [object: ObjectHandle] RETURNS [ObjectHandle];
DeleteObject: PROCEDURE[object: ObjectHandle]RETURNS [next: ObjectHandle];
ExpungeObjects: PROCEDURE;
FloatObject: PROCEDURE [object: ObjectHandle];
SinkObject: PROCEDURE [object: ObjectHandle];
FlipUpObject: PROCEDURE [object: ObjectHandle];
FlipDownObject: PROCEDURE [object: ObjectHandle];
AddToken: PROCEDURE[pt: PointDefs.ScrPt,type: TokenType] ;
SelectCP: PUBLIC PROCEDURE[pt: PointDefs.ScrPt];
DeSelectCP: PUBLIC PROCEDURE[pt: PointDefs.ScrPt];
MoveToken: PUBLIC PROCEDURE[from,to: PointDefs.ScrPt];
DeleteSelectedCPs: PROCEDURE;
DeleteAllCPs: PROCEDURE;
ReadCPs: PROCEDURE RETURNS[array: PointDefs.ObjPtSequence];
SelectObject: PUBLIC PROCEDURE[obj: ObjectHandle] RETURNS [ObjectHandle];
DeSelectObject: PROCEDURE [object: ObjectHandle];
SelectCluster: PROCEDURE[id: ClusterID] RETURNS [ObjectHandle];
DeSelectCluster: PUBLIC PROCEDURE[id: ClusterID];
ReturnSelected: PUBLIC PROCEDURE[object: ObjectHandle] RETURNS[ObjectHandle];
ForAllSelectedDo: PUBLIC PROCEDURE[proc: PROCEDURE[ObjectHandle]];

ReplotAllObjects: PROCEDURE[dc: Graphics.Context];

--procedures implemented by showobjects

ShowObjects: PROGRAM;
ReplotBox: PROCEDURE [tl,br: PointDefs.ScrPt, dc: Graphics.Context];
ReplotBoxFromObject: PROC [tl,br: PointDefs.ScrPt,object: ObjectHandle, dc: Graphics.Context];
ReplotFromObject: PROCEDURE[startObj: ObjectHandle, dc: Graphics.Context];
PlotOneObject: PROCEDURE [object: ObjectHandle, function:DisplayFnc];
WriteObject: PROCEDURE [object: ObjectHandle];
EraseObject: PROCEDURE [object: ObjectHandle];
WriteLink: PROCEDURE[obj: REF shape Object,link: REF Link];
EraseLink: PROCEDURE[obj: REF shape Object,link: REF Link];
GridOn: PROCEDURE;
GridOff: PROCEDURE;

--implemented by PressObjs
PressAllObjects: PROCEDURE[s: Rope.ROPE];
MigPressAllObjects: PROCEDURE[s: Rope.ROPE];

--implemented by Text
DisplayCaption: PROCEDURE[cobject: REF caption Object, dc: Graphics.Context];

--implemented by ObjectXForms
MoveObject: PROCEDURE[object: ObjectHandle, from,to: PointDefs.ScrPt];
XFormObject: PROCEDURE[object: ObjectHandle, matrix: XFormDefs.XFMDescriptor];
END.