-- mig objectdefs
-- Griffin object types and manipulating routines
-- Stone April 1, 1981  10:51 PM

DIRECTORY
	PointDefs: FROM "PointDefs",
	EncodingDefs: FROM "EncodingDefs",
	StyleDefs: FROM "StyleDefs",
	XFormDefs: FROM "XFormDefs",
	SplineDefs: FROM "SplineDefs",
	GriffinFontDefs: FROM "GriffinFontDefs";

ObjectDefs: DEFINITIONS =
BEGIN

ObjectType: TYPE = {shape,caption,token, menu};
ObjectHandle: TYPE  = POINTER TO 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,
	backLink: ObjectHandle,
	style: StyleDefs.StyleHandle,
	cluster: ClusterID,
	view: View,
	deleted,visible: BOOLEAN,
	selected: BOOLEAN,
	cull: {inside,outside,partial},
-- part of encoding, but are here since true for all variants
	validEncoding: BOOLEAN,
	tl,br: PointDefs.ScrPt,
	body: SELECT objectType: ObjectType FROM
		shape =>
			[
			closed: BOOLEAN,
			trajectory: Trajectory,
			chainEncoding: POINTER TO EncodingDefs.ChainEncoding, --for the traj
			areaEncoding: POINTER TO EncodingDefs.AreaEncoding
			],
		caption =>
			[
			p0: PointDefs.ObjPt,
			text: STRING
			],
		token =>
			[
			tokenType: TokenType,
			p0: PointDefs.ObjPt,
			selected: ObjectHandle
			],
		menu =>
			[
			orientation: MenuOrientation,
			head: POINTER
			],
		ENDCASE
	];


Trajectory: TYPE = RECORD
	[splineType: SplineDefs.SplineType,
	traj: SELECT type:* FROM
		linked => [links: POINTER TO Link],
		cyclic => [knots: DESCRIPTOR FOR ARRAY OF PointDefs.ObjPt],
		ENDCASE
	];


Link: TYPE = RECORD
	[link: POINTER TO Link,
	degree: {D0,D1,D2,D3},
	knots: DESCRIPTOR FOR ARRAY OF PointDefs.ObjPt
	];
ObjectProc: TYPE = PROCEDURE [obj: ObjectHandle];

--procedures implemented by objectfns

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] ;
ReplotAllObjects: PROCEDURE;
ReplotBox: PROCEDURE [tl,br: PointDefs.ScrPt];
ReplotBoxFromObject: PROCEDURE [tl,br: PointDefs.ScrPt,object: ObjectHandle];

StartObject: PROCEDURE[type: ObjectType] RETURNS [ObjectHandle];
AddLink: PROCEDURE[obj: POINTER TO shape Object,link: POINTER TO Link];
DeleteLink: PROCEDURE[obj: POINTER TO shape Object,link: POINTER TO 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: DESCRIPTOR FOR ARRAY OF PointDefs.ObjPt];
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]];

EmergencyDeleteEncodings: PROCEDURE;	--when out of space


--procedures implemented by showobjects
ReplotFromObject:  PROCEDURE[startObj: ObjectHandle];
PlotOneObject: PROCEDURE [object: ObjectHandle, function:DisplayFnc];
WriteObject: PROCEDURE [object: ObjectHandle];
EraseObject: PROCEDURE [object: ObjectHandle];
WriteLink: PROCEDURE[obj: POINTER TO shape Object,link: POINTER TO Link];
EraseLink: PROCEDURE[obj: POINTER TO shape Object,link: POINTER TO Link];
GridOn: PROCEDURE;
GridOff: PROCEDURE;

--implemented by PressObjs
PressAllObjects: PROCEDURE[s: STRING];
MigPressAllObjects: PROCEDURE[s: STRING];

--implemented by Text
DisplayCaption: PROCEDURE[POINTER TO caption Object];
DisplayString: PROCEDURE [string: STRING, screenpt: PointDefs.ScrPt,
	anchor: StyleDefs.Anchor, torient: StyleDefs.Orientation,
	fd: GriffinFontDefs.FontDescriptor];

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