MathBoxTree.mesa
Arnon, September 7, 1989 10:20:18 am PDT
Definitions for Two-Dimensional Displays of Mathematical Expressions
DIRECTORY
MathExpr USING [EXPR, AtomEXPR, CompoundEXPR, AtomClass, CompoundClass, MatrixClass],
MathBox USING [BOX],
MathTypes USING [Style],
MathRules USING [Size],
Rope USING [ROPE],
Imager USING [Context, Color];
MathBoxTree: CEDAR DEFINITIONS ~
BEGIN
Type Abbreviations from Imported Interfaces
ROPE: TYPE ~ Rope.ROPE;
EXPR: TYPE ~ MathExpr.EXPR;
AtomEXPR: TYPE ~ MathExpr.AtomEXPR;
CompoundEXPR: TYPE ~ MathExpr.CompoundEXPR;
BOX: TYPE ~ MathBox.BOX;
Style: TYPE ~ MathTypes.Style;
Size: TYPE ~ MathRules.Size;
AtomClass: TYPE ~ MathExpr.AtomClass;
CompoundClass: TYPE ~ MathExpr.CompoundClass;
MatrixClass: TYPE ~ MathExpr.MatrixClass;
Display Expression Type Definitions
BoxTree: TYPE ~ REF BoxTreeRep; -- external abstract type
BoxTreeRep: TYPE; -- internal concrete rep
ObjectDisplay: TYPE ~ REF ObjectDisplayRep; -- external abstract type
ObjectDisplayRep: TYPE; -- internal concrete rep
ObjectDisplay Operations
Object: PROC[o: ObjectDisplay] RETURNS[Object];
Extracts the Object "imbedded" in an ObjectDisplay. Trivial for an AtomDisplayObject. For a CompoundDisplayObject, descends to its "leaves" (AtomDisplayObject's), then reascends and builds the Object by applying the (constructor) method of each internal node.
Selection Type Definitions
Selection: TYPE ~ RECORD[expr: BoxTree, color: Imager.Color, borderOnly: BOOLFALSE];
Display Expression Constructors
MakeAtomicBoxTree: PROC[tag: ATOM, class: AtomClass, value: ROPE, relBox, absBox: BOX, parent: BoxTree ← NIL] RETURNS[BoxTree];
effects: Constructs and returns a new atomic display expression.
MakeCompoundBoxTree: PROC[tag: ATOM, class: CompoundClass, subExprs: LIST OF BoxTree, relBox, absBox: BOX, parent: BoxTree ← NIL] RETURNS[BoxTree];
effects: Constructs and returns a new compound display expression.
MakeMatrixBoxTree: PROC[tag: ATOM, class: MatrixClass, nRows, nCols: INT, elements: LIST OF BoxTree, relBox, absBox: BOX, openSym, closeSym, space: BoxTree, parent: BoxTree ← NIL]
RETURNS[BoxTree];
effects: Constructs and returns a new matrix display expression.
Parse/UnParse Routines
ASRopeFromBoxTree: PROC[expr: BoxTree, flavor: ATOM ← $AS] RETURNS[ROPE];
effects: Returns a ROPE in selected format
BoxTreeFromExpr: PROC[expr: EXPR] RETURNS[BoxTree];
effects: Constructs and returns a new display expression from expr.
All Display formatting information is set to default values.
ExprFromBoxTree: PROC[expr: BoxTree] RETURNS[EXPR];
effects: Constructs and returns a new EXPR from expr.
Copy: PROC[expr: BoxTree] RETURNS[BoxTree];
effects: Returns a distinct copy of expr.
Selectors
Tag: PROC[expr: BoxTree] RETURNS[ATOM];
effects: Returns tag associated with expr.
Class: PROC[expr: BoxTree] RETURNS[ATOM];
effects: Returns class of expr.
GetSubExprs: PROC[expr: BoxTree] RETURNS[LIST OF BoxTree];
AbsBox: PROC[expr: BoxTree] RETURNS[BOX];
effects: Returns subexpressions for expr.
Returns NIL if no subexpressions exist.
List Operations
GetBoxTree: PROC[tag: ATOM, exprs: LIST OF BoxTree] RETURNS[BoxTree];
effects: Returns the BoxTree in exprs associated with tag.
SIGNALS exprNotFound if no association exists.
Format and Paint
Format: PROC[expr: BoxTree, size: Size] RETURNS[BOX];
modifies: expr
effects: expr is updated into a "paintable" form.
Returns a bounding box for expr.
SIGNALS unable[reason: ATOM] if Formatting can not be completed.
Paint: PROC[expr: BoxTree, context: Imager.Context, absBox: BOX,
selections: LIST OF Selection];
modifies: expr
effects: Displays expr in context, bounded by absBox.
Updates absolute bounding boxes (viewer coords).
SIGNALS unable[reason: ATOM] if Painting cannot be completed.
Selection Operations
BoxTreeFromCoords: PROC[expr: BoxTree, x, y: REAL] RETURNS[BoxTree];
effects: Returns the subexpression associated with coordinates [x, y] in expression expr.
SIGNALS noSelection if no association exists.
Selectable: PROC[expr: BoxTree] RETURNS[BOOL];
effects: Returns TRUE iff expr is selectable.
SelectableParent: PROC[expr: BoxTree] RETURNS[BoxTree];
effects: Returns the parent (enclosing expression) of expr.
SIGNALS noSelection if no selectable parent exists.
SelectableChild: PROC[expr: BoxTree] RETURNS[BoxTree];
effects: Returns a child expressions (subexpression) for expr.
SIGNALS noSelection if no selectable child exists.
SelectableSibling: PROC[expr: BoxTree] RETURNS[BoxTree];
effects: Returns the "next" sibling expression from expr.
SIGNALS noSelection if no selectable sibling exists.
Replace: PROC[expr, old, new: BoxTree] RETURNS[BoxTree];
effects: Returns a copy of display expression expr with new substituted for old.
caveats: Return value must be reformatted before Paint[]'ing.
Note that new is used (not a copy).
ReplacePair: TYPE ~ RECORD[old, new: BoxTree];
ReplaceN: PROC[expr: BoxTree, replacements: LIST OF ReplacePair] RETURNS[BoxTree];
effects: Returns a copy of display expression expr with
new substitured for old for each pair in replacements.
caveats: Return value must be reformatted before Paint[]'ing.
Note that the "new" components of replace pairs are used (not copies).
Signals & Errors
unable: ERROR[reason: ATOM];
noSelection: ERROR;
END.