Interactive Methods (and GKS).

Copyright (c) Susan Laflin. August 1999.

Most of the programs written today are interactive to some extent. The days when programs were punched on cards and left in a tray to be collected and run by the computer operators, who then returned cards and printout to the users' pigeonholes several hours later, are now past. `Batch-processing', as this rather slow and tedious process was called, may be a very efficient use of machine time but it is very wasteful of programmers' time, and as the cost of hardware falls and that of personnel rises so installations move from batch to interactive use. Interactive use generally results in a less efficient use of the mainframe computer, but gives the programmer a much faster response time, and so speeds up the development of software.

If you are not sharing a mainframe, but using your own microcomputer, then for most of the time the speed is limited by the human response time, not that of the computer. When you come to graphics programs, there are some additional modes of graphics input in addition to the normal interactive input you have used before. For example, GKS has three modes of interactive input and six classes of logical input. These are described here, since they are typical of the type of reasoning required to write such programs.

Modes of Input

1. Request Mode

This is the mode you will find most familiar. The program issues a request for data from a device and then waits until it has been transferred. It might do this by using a `Read' statement to transfer characters from the keyboard, in which case the program will pause in its execution and wait until the data has been typed on the keyboard and the return key pressed to indicate the end of the input. The graphical input devices such as mouse, cursor or digitising tablet can also be programmed in this way.

2. Sample Mode

In this case the input device sends a constant stream of data to the computer and the program samples these values as and when it is ready. The excess data is overwritten and lost. A digitising tablet may be used in this way - it will continually send the latest coordinates of its puck position to the buffer of the serial port and the program may copy values from this port as often as needed.

3. Event Mode

This is similar to sample mode, but no data is lost. Each time the device transmits a value, the program must respond. It may do so by placing the value in an event queue for later processing, so that the logic of the program is very similar to sample mode, but there may also be some data values which cause a different response. This type of interrupt can be used to provide a very powerful facility.

Classes of Logical Input

1. Locator

This inputs the (x,y) coordinates of a position. It usually comes from a cursor, controlled either by keys or by a mouse, and has to be transferred from Device Coordinates to Normalised Device Coordinates to World Coordinates. If you have several overlapping viewports, they must be ordered so that the one with the highest priority can be used to calculate these transformations. Each pixel position on the screen must correspond to a unique value in world coordinates. It need not remain the same throughout the running of the program, since the priorities of the viewports may be changed. At every moment there must be a single unambiguous path from cursor position to world coordinates.

2. Pick

This allows the user to identify a particular object or segment from all those displayed on the screen. It is usually indicated by moving the cursor until it coincides with the required object, and then performing some other action such as pressing a mouse button or a key on the keyboard to indicate that the required object is now identified. The value transferred to this program is usually a segment identifier.

3. Choice

This works in a very similar manner to the pick input. You now have a limited set of choices, as might be displayed in a menu, and some means of indicating your choice. Only one of the limited list of choices is acceptable as input, any attempt to choose some other segment displayed on the screen will be ignored.

4. Valuator

This inputs a single real number by some means, the simplest method being typing it in from the keyboard.

5. String

This inputs a string of characters, again the simplest method is to type them in from the keyboard.

6. Stroke

This inputs a series of pairs of (x,y) coordinates. The combination of Stroke, Input and Sample Mode from a digitising tablet is a very fast method of input.

Most of the terminals or microcomputers you will meet will have some form of cursor control for graphic input. You can write your programs using which ever combination of logical input class and mode is most convenient. Alternatively, you could ignore all forms of graphic input and merely rely on `Read' statements and data typed from the keyboard. The choice is yours.

Software Techniques

1. Locating

Probably you have all used software in which the cursor is moved around the screen by means of keys or a mouse. The program may well give the impression that the cursor and mouse are linked together so that any movement of the mouse is automatically indicated by movement of the cursor on the screen. In fact, this effect is achieved by means of a graphics program which has to read in the new coordinates indicated by the mouse, delete the previous drawing of the cursor and then redraw it at the new position. This small program runs very quickly and gives the impression of a continuous process.

Usually this software also contains a test for input from the keyboard and when a suitable key is pressed, the current position of the cursor is recorded. This allows fast input of a number of points to form a picture or diagram on the screen. Some means of storing the data and terminating the program is also required.

Such points are recorded to the full accuracy of the screen, which has both advantages and disadvantages. If you are using a digitising tablet instead of a mouse, then the accuracy is even greater and the resulting problems even more extreme. You very seldom want to record information to the nearest 0.1mm, usually to the nearest millimetre is quite sufficient. Problems arise when you want to select the same point a second time. Whatever accuracy you have chosen, you must be able to indicate the point to this accuracy in order to reselect it, as you might need to do if you had several lines meeting at a point. To achieve this more easily, software involving the use of various types of constraint may be used to speed up the input process.

2. Modular Constraints

In this case, you should imagine a grid, which may be visible or invisible, placed across the screen. Now, whenever you indicate a position with the cursor, the actual coordinates are replaced by the coordinates of the nearest point on the grid. So to indicate the same point a second time, you merely have to get sufficiently close to the same grid point. Provided the grid allows enough flexibility to choose the shapes required in the diagram, this gives much faster input.

3. Directional Constraints

These can be useful when you want some lines to be in a particular direction, such as horizontal or vertical. You can write software to recalculate the coordinates so that a line close to vertical becomes exactly vertical. You can choose whether this is done automatically for every line within a few degrees of vertical or only applied when requested by the user. If the constraint is applied automatically, then you can choose how close the line must be to the required direction before it is moved and how the recalculation is computed. You may wish to move both vertices by a small amount, or one vertex by a larger amount, and if you are only moving one, you must specify some rule or rules to decide which one.

4. Gravity Field Effect

The name implies that the line should be visualised as lying at the bottom of a gravity well and points close to the line slide down on to it. As each line is added to the diagram, a small area is defined which surrounds it. When a new point is defined which lies inside the area, its actual coordinates are replaced by the coordinates of the nearest point on the line.

There are two commonly used shapes for this area. In each case, along most of the line, two parallel lines are drawn, one each side of the line and a small distance t from it. In the one shape, each vertex at the end of the line is surrounded by a semi-circle of radius t. In the other shape, each vertex is surrounded by a circle of radius greater than t, giving a dumb-bell shape to the entire area. This second case expresses the philosophy that users are much more likely to want to connect other lines to the vertices than to points along the line.

5. Scales and Guidelines

Just as you may use a ruler when measuring distances on a piece of paper, so you may wish to include software to calculate and display a ruler on the screen. The choice of scales and the way in which the ruler is positioned on the screen must be decided when the software is written.

6. Rubber-banding

This is name given to the technique where a line connects the previous point to the present cursor position. This line expands or contracts like a rubber band as the cursor is moved. To produce this effect, the lines must be deleted and re-drawn whenever the cursor is moved.

7. Menus

Many programs display a menu of choices somewhere on the screen and allow the user to indicate a choice of option by placing the cursor over the desired symbol. Alternatively, the options could be numbered and the choice could be indicated by typing a number on the keyboard. In either case, the resulting action will depend on the program.

8. Dragging

Many software packages provide a selection of commonly used shapes, and allow the user to select a shape and use the cursor to drag a copy of the shape to any required position in the drawing. Some packages continually delete and redraw the shape as it is dragged, others only redraw it when the cursor halts or pauses.

9. Inking-in

Another type of software imitates the use of pen or paintbrush in leaving a track as it is drawn across the paper. These routines allow the user to set the width and colour of the pen and some also allow patterned `inks' in two or more colours. Then as the cursor is moved across the screen, a large number of coordinates are recorded and the lines joining these points are drawn as required.

All these techniques may be coded, using a combination of graphical input and output. The success of such software depends very much on the user-interface. If it is difficult or inconvenient to use, then as soon as something better comes along, the previous software will be ignored. When designing your own graphical packages, you need to have a clear idea of the purpose for which your package is designed and also the habits and experience of the users for whom it is intended.