DEFINITION MODULE GKSSeg;

(*
    Title: 	GKS Segment Functions
    LastEdit:	"Tue Feb 26 14:54:48 1985"
    Author: 	jd
		Cambridge University Computer Laboratory
*)

(*  This module implements the GKS segment abstraction, a list of stored
    primitives. The idea is that segments can be used to construct a stored
    model of the picture being displayed and can be selectively modified.

    Each workstation is potentially displaying only a subset of the segments
    created by the client. This module maintains the mapping between segments
    and the workstations on which they are known, using the segment list
    entry of the WS.

    A rather tricky point is that some GKS back ends may be clever enough to
    operate on segments by themselves, e.g to transform a stored segment. To
    allow for this variation in device intelligence, this module must call
    the device directly whenever one of its segments must be redisplayed. The
    device may refuse if it is not capable, and in this case GKSSeg clears
    and redisplays the primitives in the stored segments by talking to the
    workstation interface GKSWork.
*)

FROM Vector IMPORT RVEC, RBOX;

FROM GKSTypes IMPORT 
    WS, PRIMITIVE, SEGMENT, ATTRIBUTE, GDPCODE;

FROM SYSTEM IMPORT WORD;


EXPORT QUALIFIED
    OpenSegment, RedrawWS, CreateSegment, CloseSegment, DeleteSegment,
    DeleteFromWS, AssociateWithWS, CopyToWS, InsertSegment,
    SetTransformation, SetVisibility, SetHighlighting, SetPriority,
    StoreLine, StoreMarker, StoreText, StoreFillArea, StorePixelArray, StoreGdp;


    (********** External Definitions Accessible to GKS Clients **********)


TYPE TRANSFORMATION = ARRAY [1..2], [1..3] OF REAL;


PROCEDURE RedrawWS (ws: WS);
PROCEDURE CreateSegment (): SEGMENT;
          (* Closes any already open segment *)
PROCEDURE CloseSegment ();
          (* Null if no open segment *)
PROCEDURE DeleteSegment (s: SEGMENT);
          (* Null if no open segment *)
PROCEDURE DeleteFromWS (ws: WS; s: SEGMENT);
          (* Null if no open segment *)
PROCEDURE AssociateWithWS (ws: WS; s: SEGMENT);
PROCEDURE CopyToWS (ws: WS; s: SEGMENT);
PROCEDURE InsertSegment (s: SEGMENT; t: TRANSFORMATION);
PROCEDURE SetTransformation (s: SEGMENT; t: TRANSFORMATION);
PROCEDURE SetVisibility (s: SEGMENT; visible: BOOLEAN);
PROCEDURE SetHighlighting (s: SEGMENT; highlit: BOOLEAN);
PROCEDURE SetPriority (s: SEGMENT; priority: REAL);

    (********** Internal Definitions for GKS only **********)

VAR OpenSegment: SEGMENT;


PROCEDURE StoreLine (index, high: INTEGER;
        VAR points: ARRAY OF RVEC): PRIMITIVE;
PROCEDURE StoreMarker (index, high: INTEGER;
        VAR points: ARRAY OF RVEC): PRIMITIVE;
PROCEDURE StoreText (index: INTEGER; at: RVEC;
        char: ATTRIBUTE; VAR text: ARRAY OF CHAR): PRIMITIVE;
PROCEDURE StoreFillArea (ref: ATTRIBUTE;
        index, high: INTEGER; VAR points: ARRAY OF RVEC): PRIMITIVE;
PROCEDURE StorePixelArray (in: RBOX;
        rowhigh, columnhigh: INTEGER; pixels: ARRAY OF CARDINAL): PRIMITIVE;
PROCEDURE StoreGdp (function: GDPCODE; arg: WORD;
        high: INTEGER; VAR points: ARRAY OF RVEC): PRIMITIVE;


END GKSSeg.
