.help gterm Dec86 "Vector Graphics for the Sun Workstation"
.sp 2
.ce
\fBVector Graphics for IRAF on the Sun Workstation\fR
.ce
Doug Tody
.ce
December, 1986
.ce
(design document)
.sp 3
.NH
Graphics Terminal Model

    The window based, native vector graphics facility for Sun/IRAF will be
implemented as a purely data driven interface based on the concept of an
intelligent virtual graphics terminal.  The virtual graphics terminal will
be implemented in software as a process running under a window system such
as Sunview or X.

A virtual terminal interface will allow the Sun workstation to be used as an
ordinary graphics terminal to access IRAF or other software on either the
local or a foreign host via any data stream interface, e.g., rlogin, telnet,
or a modem connection.  For example, one will be able to use telnet running
in a GTERM window to login on a VMS machine, then run IRAF on the VMS machine
in the normal fashion.  Conversely, since the IRAF software on the Sun node
will always think that it is talking to a conventional data driven graphics
terminal, the Sun/IRAF software may in fact be run from a conventional
graphics terminal, via either a direct or remote login.  Finally, a pure data
stream TTY interface where all details of the windowing system are isolated
into a server process makes it possible for a single version of IRAF to support
multiple window systems on the same host.

The graphics terminal to be implemented by GTERM shall consist of independent
text and graphics frames.  These will be implemented as separate windows
(frames) under SunView, allowing them to be moved, resized, exposed, hidden,
open, closed, etc., independently of each other.  Note however that since both
frames are connected to the controlling process via a single terminal i/o
connection, the controlling process (e.g., the CL) can only read from or
write to one frame at a time.

In normal use, the user will work for a time in the text frame, issuing
commands to run tasks which do not require interactive graphics facilities.
When a graphics program is run the graphics frame will be opened or exposed
and the plot drawn.  If the graphics program is interactive, i.e., uses
cursor input, the cursor will be moved to the center of the window and the
crosshairs turned on to indicate that cursor input is required.  A sequence
of keystroke or mouse button triggered cursor reads will follow, and
eventually graphics mode will be exited by transmission of the close
workstation sequence to GTERM by GIO running in the applications program.

When graphics mode is exited GTERM terminal i/o is redirected to the text
frame and the cursor is restored to its former position in the text frame,
automatically restoring interactive control to the text frame.  The graphics
frame may or may not be closed or hidden, depending upon the GTERM defaults
set up by the user.  If the graphics frame is to be closed or hidden this
should probably require interactive confirmation by the user, else the plot
might disappear immediately after being drawn.  Since control naturally
toggles back and forth between the text and graphics frames and since screen
space is always limited and a large, high resolution graph is generally
desired, it is expected that the graphics frame will normally be displayed
only while in graphics mode.

.NH
GTERM Graphics Language

    The tektronix graphics language is a simple and efficient standard language
for graphics terminal i/o which will work about as well as anything in our
application.  In particular, the vector encoding scheme is simple, compact and 
efficient, and well suited to use with a variety of terminal drivers and
modems (since binary data is avoided).  The best approach to implementing the
GTERM graphics language would seem to be to take the tektronix language as a
starting point and add additional functionality by extending the language
with new control sequences.  Some of the extensions defined here a taken from
the Retrographics vt640 and the Pericom.  Others more specific to window based
applications will be added in the future in an upwards compatible fashion.


.ks
.nf
	GS 		open workstation if not already open
			    open/expose graphics frame (icon -> full window)
			    direct terminal i/o to graphics frame
			    save cursor (mouse) position
			    issue GS dark vector command (see below)
	CAN		close workstation
			    restore control to text frame (restore cursor)
			    close/hide graphics frame (full window -> icon)
			    keystroke required to trigger close-window?


	GS		(workstation already opened)
			    enter vector drawing mode, dark vector
	FS		enter point plot mode
	US,CR		enter alpha mode
			    text is drawn in graphics frame
			    defaults to transparent text, erase permitted
	ESC CR		enter text mode
			    lines of text are drawn on status line in
			    nontransparent (overwrite) mode

	ESC SUB		enter crosshair mode
	ESC FF		clear screen, initialize drawing modes
	ESC/f [x,y]	set crosshair position
	GS [x,y] US	sets alpha cursor position

	ESC[0123]	set character size (normal,2x,3x,4x)
	ESC[`abcd]	set line drawing style (normal,dotted,dotdash,sd,ld)
	ESC/[012]d	set drawing mode (set, clear, toggle)
	ESC/[0123]w	set polyline linewidth (normal,2x,3x,4x)

	Standard screen resolution is 1024 by 780.
	In graphics mode, chars are interpreted as [x,y] coordinate pairs.
	In alpha mode, chars are interpreted as characters to be drawn.
.fi
.ke


A number of extensions to this basic language are being considered for future
implementation.  Support for color, multiple text fonts, general polymarkers,
area fill, and possibly cell array are contemplated, as well as simple
extensions for window control and pop-down menus.  Support for the standard
textronix features which have been omitted (vector point elimination,
incremental point mode, status enquiry) is possible.  The interface is easily
extensible hence there is no need to attempt to define or support such features
in the initial interface.

.NH
Implementation Notes

    The GTERM virtual terminal consists of two independent frames, the text
frame and the graphics frame.  Selection of the frame to which output is to
be delivered is done at the lowest possible level, i.e., when the read system
call is issued by the terminal to accept terminal output from the pty
(pseudo-terminal driver) stream for the terminal.  This is done by linking in
a custom version of the notify_read() primitive, the low level read primitive
for notifer based programs.  Output is initially to the text frame.  Output
is redirected to the graphics frame when GS is seen in the output stream,
and later restored to the text frame when CAN is seen.  Input is controlled
independently by the two frames at a high level, hence does not have to be
switched.

All terminal operations are event driven.  Graphics data is deposited into a
circular input buffer by an event driven read routine, which can issue
<ctrl/s>/<ctrl/q> to the terminal driver to control the rate at which input
is accumulated.  A separate drawing routine running off an interval timer
is used to process data appearing in the input buffer.  The drawing code is
always in one of three modes: vector drawing mode, alpha mode (randomly
addressable character drawing), or text mode (textual output to the status
line).

.SH
Appendix: Tektronix Graphics Language (Retrographics vt640)

.ks
.nf
       *GS		enter graphics mode; dark vector
       *FS		enter point plot mode
	RS		enter incremental point mode
       *US,CR		enter alpha mode, graphics plane, tek font
	CAN		disable graphics mode, restore output to terminal plane

	ESC"0g		alias for enter transparent mode
	ESC"4g		alias for enter crosshair mode
	ESC"5g		enter light pen mode

       *ESC SUB		enter crosshair mode
       *ESC FF		clear screen, initialize drawing modes
       *ESC ENQ		return cursor position, other status

	ESC[0123]	set character size (normal,2x,3x,4x)
	ESC[`abcd]	set line drawing style (normal,dotted,dotdash,sd,ld)
	ESC/[012]d	set drawing mode (set, clear, toggle)

	ESC/f		set crosshair position
       *GS [x,y] US	sets alpha cursor position

	Vector coordinate encoding (max 10 bits = 1024 points res.):

			high y	P01XXXXX
			low  y	P11XXXXX
			high x	P01XXXXX
			low  x	P10XXXXX

	Cursor return structure:

			key	PXXXXXXX
			high x	P01XXXXX
			low  x	P01XXXXX
			high y	P01XXXXX
			low  y	P01XXXXX
			trailer	<cr>

	Standard 4010/4012 screen resolution is 1024 by 780.
	In graphics mode, chars are interpreted as [x,y] coordinate pairs.
	In alpha mode, chars are interpreted as characters to be drawn.
.fi
.ke
