PathEditor.mesa
Written by Darlene Plebon on August 23, 1983 5:08 pm
Routines providing a client interface to the Path Editor.
DIRECTORY
PETypes,
PEViewer USING [DrawProc, MenuLabelRec],
Rope USING [ROPE];
PathEditor: CEDAR DEFINITIONS =
BEGIN OPEN PETypes;
Point: TYPE = PETypes.Point;
PathData: TYPE = REF ANY;
MoveToProc: TYPE = PROCEDURE [p1: Point];
LineToProc: TYPE = PROCEDURE [p1: Point];
CurveToProc: TYPE = PROCEDURE [p1, p2, p3: Point];
DrawProc: TYPE = PEViewer.DrawProc;
ButtonHitProc: TYPE = PROCEDURE[event: ATOM, x, y: REAL];
MenuLabel: TYPE = PEViewer.MenuLabelRec;
BooleanSpecification: TYPE = {on, off, toggle};
VertexType: TYPE = {frontKnot, rearKnot, intermediateKnot, controlPoint};
CurveType: TYPE = {point, line, bezier};
Routines which operate on the entire image.
CreatePathViewer:
PROCEDURE [name: Rope.
ROPE, menuLabels:
LIST
OF MenuLabel, buttonProc: ButtonHitProc ←
NIL, redrawProc: DrawProc ←
NIL]
RETURNS [pathData: PathData];
This routine creates a viewer for the Path Editor. The viewer is created with the supplied name and menu labels. Client supplied routines are called to process button hits and when the entire viewer must be redrawn for some reason. This routine must be called before any others. It returns a pointer to Path Editor data which must be passed in all subsequent calls from the client.
DrawInPathViewer:
PROCEDURE [pathData: PathData, drawProc: DrawProc];
This routine calls the client supplied routine with the Path Editor viewer's context so it can draw in the Path Editor's viewer.
Redraw:
PUBLIC
PROCEDURE [pathData: PathData, erase:
BOOLEAN ← FALSE];
This routine redraws the entire image. The viewer may be erased first, if desired.
FlushImage:
PROCEDURE [pathData: PathData];
This routine flushes the contents of the image, so the client can start over.
Routines which operate on entire trajectories.
NewTrajectory:
PROCEDURE [pathData: PathData];
This routine creates a new trajectory and makes it the active trajectory. The trajectory is not actually created until an operation is performed which gives it some contents (e.g. AddKnotToFront).
SetActiveTrajectory:
PROCEDURE [pathData: PathData, where: Point]
RETURNS [activeTrajectorySet:
BOOLEAN, hitPoint: Point];
This routine makes the trajectory which is closest to the specified point the active trajectory. A trajectory must be made active before its contents can be edited. When a trajectory is first set active, the active vertex or active segment are unset (i.e. NIL). The specified position must be "close to" (i.e. whithin a certain minimum distance of) a trajectory in order for the operation to be carried out. This routine returns an indication of whether the active trajectory was in fact set and the position of the point on the active trajectory which is closest to the specified point.
TrajectoryIsEmpty:
PROCEDURE [pathData: PathData]
RETURNS [empty:
BOOLEAN];
This routine determines if the active trajectory currently has any contents.
DeleteActiveTrajectory:
PROCEDURE [pathData: PathData];
This routine deletes the active trajectory.
GetTrajectoryFile:
PROCEDURE [pathData: PathData, fileName: Rope.
ROPE];
This routine reads the specified trajectory file into the path editor. The trajectories read in are appended to those already in the image.
StoreTrajectoryFile:
PUBLIC
PROCEDURE [pathData: PathData, fileName: Rope.
ROPE];
This routine writes a text representation of the trajectories in the path editor to a file.
EnumerateTrajectories:
PROCEDURE [pathData: PathData, moveToProc: MoveToProc, lineToProc: LineToProc, curveToProc: CurveToProc];
This routine enumerates all the segments in the all the trajectories. Client specified routines are called for each line segment, and bezier curve in each trajectory. The moveToProc is called for the first point (FP) of each trajectory.
Routines which operate on (the contents of) the active trajectory.
AddKnotToFront:
PROCEDURE [pathData: PathData, position: Point];
This routine extends the active trajectory by adding a knot (and thus a segment) to its front end.
AddCubicToFront:
PROCEDURE [pathData: PathData, cp1, cp2, knot: Point];
This routine adds a cubic curve segment to the front of the active trajectory. The cubic is defined by the bezier vertices: knot, cp2, cp1, FP, where FP is the first knot in the original path.
AddKnotToRear:
PROCEDURE [pathData: PathData, position: Point];
This routine extends the active trajectory by adding a knot (and thus a segment) to its rear end.
AddCubicToRear:
PROCEDURE [pathData: PathData, cp1, cp2, knot: Point];
This routine adds a cubic curve segment to the rear (end) of the active trajectory. The cubic is defined by the bezier vertices: LP, cp1, cp2, knot, where LP is the last knot in the original path.
SplitSegment:
PROCEDURE [pathData: PathData, where: Point];
This routine splits the segment in the active trajectory which is nearest the specified position at the point which is closest to the specified position. The specified position must be "close to" (i.e. whithin a certain minimum distance of) a segment of the active trajectory in order for the operation to be carried out. This routine also updates the display to reflect the two new segments and saves appropriate information for reversing the action. A call to this routine may be followed by zero or more calls to AdjustSegmentSplit. Finally, ConfirmSegmentSplit must be called to clean up the display.
AdjustSegmentSplit:
PROCEDURE [pathData: PathData, where: Point];
This routine moves the knot at which a bezier segment is split into two segments.
ConfirmSegmentSplit:
PROCEDURE[pathData: PathData];
This routine confirms a segment split. That is, it makes it permanent. This routine basically cleans up the display a bit.
AddControlPoint:
PROCEDURE [pathData: PathData, where, position: Point];
This routine adds a control point to the specified segment (the segment in the active trajectory which is closest to "where"). Position specifies the position of the new control point. If the segment already contained one control point, the new control point is added before or after the current one depending on the the distance from "where" to the line segments defined by the existing control point and the two knots of the segment. If "where" is closer to the line segment defined by the existing control point and the first knot, the new control point is inserted before the existing one; otherwise it is inserted following the existing control point in the segment. If the segment already contains two control points, no action is performed.
CloseActiveTrajectory:
PROCEDURE [pathData: PathData];
This routine makes the active trajectory a closed trajectory.
OpenActiveTrajectory:
PROCEDURE [pathData: PathData];
This routine makes the active trajectory an open trajectory.
DeleteVertex:
PROCEDURE [pathData: PathData, vertex: Point];
This routine deletes the vertex (which may be a knot or a control point) in the active trajectory which is closest to the specified point. The specified point must be "close to" (i.e. whithin a certain minimum distance of) a vertex in the active trajectory in order for the operation to be carried out.
SetActiveVertex:
PROCEDURE [pathData: PathData, where: Point]
RETURNS [activeVertexSet:
BOOLEAN, vertex: Point];
This routine makes the vertex of the active trajectory which is closest to the specified point the active vertex. A vertex must be made active before it can be moved. The specified position must be "close to" (i.e. whithin a certain minimum distance of) a segment in the active trajectory in order for the operation to be carried out. This routine returns an indication of whether the active vertex was in fact set and the position of the active vertex. The routines for adding knots and control points also set the active vertex. The NewImage, DeleteVertex and AddCubic routines unset the active vertex.
GetActiveVertex:
PROCEDURE [pathData: PathData]
RETURNS [activeVertexSet:
BOOLEAN, vertex: Point];
This routine returns an indication of whether the active vertex is set and the position of the active vertex.
MoveActiveVertex:
PROCEDURE [pathData: PathData, newPosition: Point];
This routine moves the active vertex (which may be a knot or a control point) closest to the specified point to the specfied new position.
SetContinuity:
PROCEDURE [pathData: PathData, knot: Point, continuity: BooleanSpecification];
This routine sets the continuity requirements at the vertex in the active trajectory which is closest to the specified location. The specified point (knot) must be "close to" (i.e. within a certain minimum distance of) a vertex in the active trajectory in order for the operation to be carried out. This operation only applies to knots. The client can specify that continuity is required (on), that continuity is not required (off), or that the current continuity requirement setting is to be toggled. When continuity is requested, the positions of some vertices may be altered to satisfy the request.
FixControlPoint:
PROCEDURE [pathData: PathData, controlPoint: Point, fixed: BooleanSpecification];
This routine sets the indicator of whether the vertex in the active trajectory which is closest to the specified location is fixed (i.e. may not be moved unless explicitly requested by the client) or not fixed (i.e. may be moved without a client request in order to satisfy continuity requirements at some other vertex). The specified point (knot) must be "close to" (i.e. within a certain minimum distance of) a vertex in the active trajectory in order for the operation to be carried out. This operation only applies to control points. The client can specify that the vertex be fixed (on), that the vertex can be moved (off), of that the current setting is to be toggled.
EnumerateActiveTrajectory:
PROCEDURE [pathData: PathData, moveToProc: MoveToProc, lineToProc: LineToProc, curveToProc: CurveToProc];
This routine enumerates all the segments in the active trajectory. Client specified routines are called for each line segment, and bezier curve in the trajectory. The moveToProc is called for the first point (FP) of the active trajectory.
HitTestVertices:
PROCEDURE [pathData: PathData, where: Point]
RETURNS [closeToVertex:
BOOLEAN, vertexType: VertexType, vertex: Point];
This routine determines the vertex in the active trajectory which is closest to the specified point. Only those vertices which are in the active trajectory and within a threshold distance of the point are considered. This routine returns an indication of whether the point is close to a vertex, and if so, the position of the closest vertex and its type.
HitTestCurves:
PROCEDURE [pathData: PathData, where: Point]
RETURNS [closeToCurve:
BOOLEAN, curveType: CurveType, p0, p1, p2, p3: Point, hitPoint: Point];
This routine determines the curve segment in the active trajectory which is closest to the specified point. Only those segments which are in the active trajectory and within a threshold distance of the point are considered. This routine returns an indication of whether the point is close to a curve segment, and if so, the position of the vertices of the segment, its type, and the point on the curve closest to the specified point.