-- September 14, 1982 4:38 pm
-- JunoStorage.mesa, coded June 81 by Greg Nelson.
-- Definitions of record types and types of allocation and deallocation procedures. 

DIRECTORY Rope, Graphics;


JunoStorage: DEFINITIONS = BEGIN

PointPtr: TYPE = REF Point;

Point: TYPE = RECORD[
  x:		REAL ← 0,			-- x and y are screen coordinates of point
  y:		REAL ← 0,
  xheader:      INTEGER ← 0,
  yheader:	INTEGER ← 0,	
  oldx:	REAL ← 0,		 -- delx and dely are components of the
  oldy:	REAL ← 0,		 -- gradient; used only by Newton's alg.
  moveHasBeenPlotted: BOOL ← FALSE,  -- used at end of junosolverimplB 
  fixed:	BOOLEAN ← FALSE,		-- p.fixed => p cannot be moved.
  tempfixed: BOOLEAN ← FALSE,
  visible: BOOLEAN ← TRUE,     -- false for control points of strings
  -- command:	PROCEDURE ← NIL,		 Non-NIL => point is command button. 
  -- pen:	REF TEXT,		 string to be plotted at this point
  wn:		INTEGER ← 0,		-- winding number; used only in TrackLoop
  copy:		PointPtr ← NIL, -- used by CopyCmd.
  slink:	PointPtr ← NIL, -- link for list of selectees.
  name: REF ← NIL,
  link:		PointPtr];		-- link for list of all points
  

SaveStateRec: TYPE = RECORD[
  savePointLpad: PointPtr ← NIL,
  saveEdgeLpad: EdgePtr ← NIL,
  saveArcLpad: ArcPtr ← NIL,
  saveLineLpad: LinPtr ← NIL,
  saveCongLpad: CongPtr ← NIL,
  saveHorLpad: HorPtr ← NIL,
  saveVerLpad: VerPtr ← NIL,
  saveStringLpad: StringPtr ← NIL,
  saveCCLpad: CCPtr ← NIL];


EdgePtr: TYPE = REF Edge;

Edge: TYPE = RECORD[
  b1:	PointPtr ← NIL,		-- b1 and b2 are the endpoints of the edge.
  b2:	PointPtr ← NIL,
  -- pen:	REF TEXT,		string to be plotted at each point of the edge.
  -- slink:EdgePtr ← NIL,	link for list of selected edges.
  link:	EdgePtr];		-- link for list of all edges

ArcPtr: TYPE = REF Arc;

Arc: TYPE = RECORD[		-- there is one Arc record for each spline
  b1:	PointPtr ← NIL,		-- It is a Bezier spline defined by the
  b2:	PointPtr ← NIL,		-- points b1, b2, b3, and b4.
  b3:	PointPtr ← NIL,
  b4:	PointPtr ← NIL,
  -- pen:	REF TEXT,		string to be plotted at each point of the arc.
  -- slink:ArcPtr ← NIL,	link for list of selected arcs.
  link:	ArcPtr];		-- link for list of all arcs.

LinPtr: TYPE = REF LineConstraint;

LineConstraint: TYPE = RECORD[	-- There is one LineConstraint record
  i:	PointPtr ← NIL,		-- for each collinearity constraint; the
  j:	PointPtr ← NIL,		-- record constrains points i, j, and k
  k:	PointPtr ← NIL,		-- to be collinear.
  l:	PointPtr ← NIL,
  link:	LinPtr];	-- link for list of all line constraints.

CongPtr: TYPE = REF CongruenceConstraint;

CongruenceConstraint: TYPE = RECORD[	-- A CongruenceConstraint record constrains
  i:	PointPtr ← NIL,		-- points i, j, k, and l to satisfy
  j:	PointPtr ← NIL,		-- Distance(i,j) = Distance(k,l).
  k:	PointPtr ← NIL,
  l:	PointPtr ← NIL,		-- link for list of all CongruenceConstraints:
  link:	CongPtr];

HorPtr: TYPE = REF HorizontalConstraint;

HorizontalConstraint: TYPE = RECORD[
  i: PointPtr ← NIL,
  j: PointPtr ← NIL,
  link: HorPtr];

VerPtr: TYPE = REF VerticalConstraint;

VerticalConstraint: TYPE = RECORD[
  i: PointPtr ← NIL,
  j: PointPtr ← NIL,
  link: VerPtr];

StringPtr: TYPE = REF String;

String:  TYPE = RECORD[
  b3 : PointPtr ← NIL,
  b4 : PointPtr ← NIL,
  stringText : Rope.ROPE ← NIL,
  stringFont : Graphics.FontRef ← NIL,
  fontName: Rope.ROPE ← NIL,
  fontSize: INT ← 0,
  bold: BOOL ← FALSE,
  italic: BOOL ← FALSE,
  height, width, depth : REAL ← 0.0,
  link : StringPtr];

CCPtr: TYPE = REF CCConstraint;

CCConstraint: TYPE = RECORD[i: PointPtr ← NIL, j:PointPtr ← NIL, k: PointPtr ← NIL, link: CCPtr];
  
HasDef: PUBLIC PROC [name: REF ANY, defList: LIST OF REF ANY] RETURNS [BOOL];

GetBody: PUBLIC PROC [name: REF ANY] RETURNS [REF ANY];

GetLocals: PUBLIC PROC [name: REF ANY] RETURNS [REF ANY];

AddDef: PUBLIC PROC [name, locals, body: REF ANY];  --  adds to lambdaAlist the definition of name

lambdaAlist: PUBLIC LIST OF REF ANY;

constructionList: PUBLIC LIST OF ApplyRecord;

AddX: PUBLIC PROC [f: REF ANY, args:LIST OF PointPtr];  
 --  adds (f, args) to constructionList, which is a list of ApplyRecords

ApplyRecord: TYPE = RECORD [f: REF ANY, args: LIST OF PointPtr];

Basis: TYPE = REF BasisRec;

BasisRec: TYPE = RECORD[head:TangentVector ← NIL, tail:Basis];

TangentVector: TYPE = REF TvRec;

TvRec: TYPE = RECORD[head:PointPtr ← NIL, x, y: REAL ← 0, tail:TangentVector];

PushState: PUBLIC PROCEDURE;

PopState: PUBLIC PROCEDURE;

NewPoint: PROCEDURE RETURNS [r: PointPtr];
	
GcPoint: PROCEDURE[p:PointPtr];

NewEdge: PROCEDURE RETURNS [r: EdgePtr];
	
GcEdge: PROCEDURE[p:EdgePtr];

NewArc: PROCEDURE RETURNS [r: ArcPtr];
  
GcArc: PROCEDURE[p:ArcPtr];

NewLine: PROCEDURE RETURNS [r: LinPtr];
	
GcLine: PROCEDURE[p:LinPtr];

NewString: PROCEDURE RETURNS [r: StringPtr];

GcString: PROCEDURE[p: StringPtr];

NewCong: PROCEDURE RETURNS [r: CongPtr];
	
GcCong: PROCEDURE[p:CongPtr];

NewHor: PROCEDURE RETURNS [r: HorPtr];
	
GcHor: PROCEDURE[p:HorPtr];

NewVer: PROCEDURE RETURNS [r: VerPtr];
	
GcVer: PROCEDURE[p:VerPtr];

NewCC: PROC RETURNS [r: CCPtr];

GcCC: PROC[p: CCPtr];

NewBasis: PROC RETURNS [Basis];

GcBasis: PROC[Basis];

NewTv: PROC RETURNS [TangentVector];

GcTv: PROC[TangentVector];

AddHor: PROC[a,b:PointPtr];
AddVer: PROC[a,b:PointPtr];
AddCong: PROC[a,b,c,d:PointPtr];
AddLin: PROC[a,b,c,d:PointPtr];
AddPoint: PROC [x,y:REAL] RETURNS [PointPtr];
FindPoint: PROC [x,y:REAL] RETURNS [PointPtr];
AddEdge: PROC[a,b:PointPtr];
AddArc: PROC[a,b,c,d:PointPtr];
AddString: PROC [c,d: PointPtr, h, w, dep : REAL, 
                      stringText: Rope.ROPE, stringFont: Graphics.FontRef, 
                      fontName: Rope.ROPE, fontSize: INT, bold, italic: BOOL];
AddCC: PROC [a, b, c: PointPtr];
InitJunoStorage: PROC;
ResetJunoStorage: PROC; -- reclaims all records.

pointLpad, pointRpad: PointPtr;	-- The lists of points, edges, arcs
edgeLpad, edgeRpad: EdgePtr;	-- line constraints, and cong. constraints
arcLpad, arcRpad: ArcPtr;	-- are padded on both sides. 
lineLpad, lineRpad: LinPtr;
congLpad, congRpad: CongPtr;
stringLpad, stringRpad: StringPtr;
horLpad, horRpad: HorPtr;
verLpad, verRpad: VerPtr;
ccLpad, ccRpad: CCPtr;

END.