Jump over left menu
Chapter 13: Individual Attributes
As we saw in Chapter 2, the actual appearance (or aspects) of primitives are controlled by attributes. In GKS, the aspects of primitives belong to two classes:
- Global aspects are applicable on all workstations. These are controlled directly by attributes.
- Workstation dependent aspects may vary from workstation to workstation so that the same primitive may be displayed quite differently on different workstations. These are controlled by a single attribute per primitive, the primitive index.
For example, the polyline primitive has no global aspects but has three workstation dependent aspects that are controlled by the polyline index. Polylines may be differentiated by using different values of the polyline index that access different combinations of these workstation dependent aspects or different representations, as we called them earlier. Thus:
SET POLYLINE INDEX(1) POLYLINE(N, XA, YA) SET POLYLINE INDEX(2) POLYLINE(M, XB, VB)
will output two poly lines which should appear different on any workstation. The workstation dependent aspects that are controlled by the polyline index are linetype, linewidth scale factor and polyline colour index.
Other primitives, however, have several global aspects. For example, the text primitive has character height, character up vector, text path and text alignment as its global aspects. Each global aspect is controlled directly by an attribute of the same name. Of course, the text primitive also has a text index which controls the workstation dependent aspects: text font and precision, character expansion factor, character spacing and text colour index.
In general, GKS defines aspects as global if they affect the geometry of the picture being described. Thus, linetype, which does not have any effect on the shape of the line or where it starts and finishes, is defined as workstation dependent. Conversely, character height which affects the size of the text primitive, and text alignment, which affects the start and finish points of the text primitive, are both defined as global. As character spacing and width are specified relative to character height in GKS, they are defined as workstation dependent. For both text and polyline primitives, the colour indices do not affect the geometry of the picture and so are defined as workstation dependent.
In Chapter 2, output primitives and their attributes were described. In Chapter 7, we saw the means of differentiating the two polylines in the example above, on a workstation and, more importantly, how specific styles of line could be chosen to achieve the differentiation on different workstations. We can choose specific values of the three workstation aspects to associate with a polyline index value on a particular workstation. For example:
SET POLYLINE REPRESENTATION(WS, 1, LT, LW, PLCI)
would specify that polyline index 1 on workstation WS would be represented by a line of linetype LT with a linewidth scale factor of LW and a colour specified by the entry PLCI in the colour table of the workstation (see Section 7.5 and Section 7.6).
The main reason for this method of specifying aspects is to achieve portability of application packages from one environment to another. Only the workstation dependent parts of the program need be changed when it is moved from one installation to another or from one workstation to another. The workstation independent parts of the program do not need to be changed at all. In a similar manner, libraries of high level graphics routines may be written independently of the workstations on which they will run, and the workstation dependent settings incorporated in the application program which invokes the library routines.
This is clearly useful and important for large application packages designed to run on a range of different workstations and systems, especially when the workstation dependent aspects are being used as a means of differentiating particular primitives from others. However, there are disadvantages to this mode of working for certain applications and so, to ensure GKS also caters for their needs, GKS provides another way of controlling the workstation dependent aspects, that is like that used for controlling the global aspects. The former is referred to as bundled specification and the latter as individual specification.
13.2 DYNAMIC BINDING OF ASPECTS
Another difference between global aspects and workstation dependent aspects is how they are bound to the primitive. A global aspect is controlled directly by an attribute of the same name. For example, the character height aspect is controlled by the character height attribute and so:
SET CHARACTER HEIGHT(2) TEXT(X, Y, STRING)
will output the text with a character height of 2. A subsequent call of SET CHARACTER HEIGHT cannot change the height of this text. The character height attribute is bound to the primitive when it is output and cannot be changed. The character height aspect is said to be statically bound.
Conversely, workstation dependent aspects are controlled in groups (or bundles) by a single attribute called a primitive index. For example, the linetype, linewidth scale factor and polyline colour index aspects are controlled in a bundle by the polyline index attribute and so:
SET POLYLINE REPRESENTATION(WS, 1, LT1, LW1, PLCIl) SET POLYLINE INDEX(1) POLYLlNE(N, XA, VA)
will output the polyline with a polyline index of 1, statically bound to the polyline. As with the character height for text above, this polyline index is always associated with the polyline and cannot be changed. On workstation WS, the workstation dependent aspects are specified by LT1, LW1 and PLCI1. If this is followed later in the program by:
SET POLYLINE REPRESENTATION(WS, 1, LT2, LW2, PLCI2) SET POLYLINE INDEX(1) POLYLINE(M, XB, YB)
it is clear that this latter polyline is also output with a polyline index of 1 and on workstation WS, the workstation dependent aspects are specified by LT2, LW2 and PLCI2. However, in GKS there are further consequences. On workstation WS, all polylines with a polyline index of 1 will now have their workstation dependent aspects speci!ied by LT2, LW2 and PLCI2. At the point where the representation is changed, the workstation is expected to change the aspects of all polylines which have a polyline index of I, but this is only guaranteed for polylines inside segments. The polyline index of a polyline may not be changed after a polyline has been output but the workstation dependent aspects of a polyline may be changed at any time after it has been output. The linetype, linewidth scale factor and polyline colour index workstation dependent aspects are said to be dynamically bound. The workstation may not be able to execute the changes in the picture immediately; Section 7.11 describes when the picture changes wil1 take place and how this may be control1ed. Thus an important distinction between global aspects and workstation dependent aspects is that the former are statically bound while the latter are dynamically bound.
13.3 INDIVIDUAL ATTRIBUTES
So far, this book has concentrated on the bundled specification of workstation dependent aspects. The primitive index for a primitive points into a bundle table which contains the values of the workstation dependent aspects for that primitive. In the case of polyline described above, the polyline index points into the polyline bundle table which contains the values of linetype, linewidth scale factor and polyline colour index. Entries in the table may be altered by the SET POLYLINE REPRESENTATION function (and similar functions for other primitives) to provide dynamic binding of the workstation dependent aspects.
However, some applications require features of global aspects for these workstation dependent aspects; they require static binding and applicability on all workstations. GKS provides an alternative mode of working, cal1ed individual specification, which allows the workstation dependent aspects to be treated as global aspects.
For individual specification, the workstation dependent aspects are each control1ed directly by attributes of the same name (called individual attributes). Thus, polyline has the individual attributes linetype, linewidth scale factor and polyline colour index. These attributes are bound to the primitive when it is output and cannot be changed. For example,
SET LlNETYPE(LT1) SET LlNEWIDTH SCALE FACTOR(LW) SET POLYLINE COLOUR INDEX(PLCI) POLYLlNE(N, XA, YA) SET LINETYPE(LT2) POLYLlNE(M, XB, YB)
will output the first polyline with aspects LT1, LW and PLCI and the second polyline with aspects LT2, LW and PLCI on all workstations on which they appear. These aspects are statically bound.
An advantage of this mode of working is that lines may be specified as dashed, for example, and will appear dashed on all workstations. In addition, changing aspect values (by setting the corresponding attributes) will not affect primitives that have already been output.
The individual mode of working can also be very useful when the number of different forms of a primitive to be output is potentially very large. For example, if polylines need to be output in possibly five different linetypes, ten linewidths and 256 colours, this would require 12,800 bundle table entries on the workstation. In the individual mode of working, no bundle table entries are needed at all.
Conversely, since the aspects are set globally, it may only be possible to output a primitive with an approximation to its aspects on a particular workstation. In contrast to bundled specification, where a representation may be checked for availability by the specific workstation, it is not possible with individual specification for GKS to check that the specified value of an aspect is available on the required workstation when it is set, as the set of workstations may change while the value is in use. This means that the user has to be more aware of his environment when writing the program. Consider:
SET LlNEWIDTH SCALE FACTOR(3.0) POLYLlNE(N, XA, YA) SET LINEWIDTH SCALE FACTOR(1.0) POLYLINE(M, XB, YB)
The user is attempting to differentiate the two polylines by drawing the first one thicker than the second. If the workstation he is using can only draw lines at one thickness, the differentiation will not be visible. A similar problem arises if colour is being used for differentiation when the workstation is a monochrome display!
GKS provides the following functions for individual specification of workstation dependent aspects:
SET LINETYPE(LT) SET LINEWIDTH SCALE FACTOR(LW) SET POLYLINE COLOUR INDEX(PLCI) SET MARKER TYPE(MT) SET MARKER SIZE SCALE FACTOR(MS) SET POLYMARKER COLOUR INDEX(PMCI) SET TEXT FONT AND PRECISION(TF, TP) SET CHARACTER EXPANSION FACTOR(CEF) SET CHARACTER SPACING(CS) SET TEXT COLOUR INDEX(TCI) SET FILL AREA INTERIOR STYLE(FAI) SET FILL AREA STYLE INDEX(SI) SET FILL AREA COLOUR INDEX(FACI)
The use of individual attributes is illustrated by rewriting the example in Section 2.8 using individual specification:
REAL XNEWDK(44), YNEWDK(44), XNEWW(10), YNEWW(10) PI=4*ATAN(1) XC=45 YC=45 R=30 MOVE DUCK(XC, YC, R, 5*PI/6, XNEWDK, YNEWDK, XNEWW, YNEWW) SET LINETYPE(1) SET LINEWIDTH SCALE FACTOR(1) SET POLYLINE COLOUR INDEX(1) POLYLINE(44, XNEWDK, YNEWDK) POLYLINE(10, XNEWW, YNEWW) MOVE DUCK(XC, YC, R, PI/2, XNEWDK, YNEWDK, XNEWW, YNEWW) SET LINETYPE(2) POLYLINE(44, XNEWDK, YNEWDK) POLYLINE(10, XNEWW, YNEWW) MOVE DUCK(XC, YC, R, PI/6, XNEWDK, YNEWDK, XNEWW, YNEWW) SET MARKER TYPE(3) SET MARKER SIZE SCALE FACTOR(1) SET POLYMARKER COLOUR INDEX(1) POLYMARKER(44, XNEWDK, YNEWDK) SET MARKER TYPE(2) POLYMARKER(10, XNEWW, YNEWW) MOVE DUCK(XC, YC, R, -PI/6, XNEWDK, YNEWDK, XNEWW, YNEWW) SET FILL AREA INTERIOR STYLE(SOLID) SET FILL AREA COLOUR INDEX(1) FILL AREA(44, XNEWDK, YNEWDK) MOVE DUCK(XC, YC, R, -PI/2, XNEWDK, YNEWDK, XNEWW, YNEWW) SET FILL AREA INTERIOR STYLE(HATCH) SET FILL AREA STYLE INDEX(-4) FILL AREA(44, XNEWDK, YNEWDK) SET LINETYPE(1) POLYLINE(44, XNEWDK, YNEWDK) MOVE DUCK(XC, YC, R, -5*PI/6, XNEWDK, YNEWDK, XNEWW, YNEWW) FILL AREA(44, XNEWDK, YNEWDK) SET LINETYPE(2) POLYLINE(44, XNEWDK, YNEWDK) SET TEXT FONT AND PRECISION(-104, STROKE) SET CHARACTER EXPANSION FACTOR(1) SET CHARACTER SPACING(0) SET TEXT COLOUR INDEX(1) SET CHARACTER HEIGHT(7.5) SET TEXT ALIGNMENT(RIGHT, HALF) TEXT(23.5, 45, 'G') SET CHARACTER HEIGHT(3) SET TEXT ALIGNMENT(LEFT, HALF) TEXT(23.5, 45, 'RAPHICAL') SET TEXT ALIGNMENT(RIGHT, HALF) TEXT(59, 45, 'DUC') SET CHARACTER HEIGHT(7.5) SET TEXT ALIGNMENT(LEFT, HALF) TEXT(59, 45, 'KS')
The output produced is the same as that shown in Figure 2-30. The same colour index is used for all primitives and so the output will be in one colour.
It should be noted that although the colour aspects are statically bound, the colour aspects are themselves indices into the colour table of the workstation, The entries in the colour table may be changed and the changes may affect the primitives that have already been output. Thus, to ensure that a primitive appears with the same colour on two workstations, it is necessary to make the colour table entry, pointed to by the colour index, the same on the two workstations.
13.4 SWITCHING MODES
It is clear that both modes of working cannot be in use at the same time, GKS provides a function which allows the user to switch between the two modes of working, This function is:
SET ASPECT SOURCE FLAGS(LST)
The array LST specifies for each aspect whether it is to be specified globally (INDIVIDUAL) or through a bundle (BUNDLED). Each element is termed an aspect source flag (ASF). The order of elements in this array is the same as the order in which the corresponding functions appear above. Most installations are likely to define higher level routines on top of this function to specify the mode of working for each primitive's aspects. Although it is possible for the mode setting to be changed during the program's execution, it is more normal for one mode to be set at the start of the program for the complete program run.
A particular installation will specify one mode of working as the default. Bundled specification will normally be set as the default although it is possible in some installations where a small number of similar devices exist that the default will be individual specification. Implementations in the USA are likely to have individual specification as the default.
The examples in this book (in Chapter 2 in particular) assume that the default mode of working is bundled. For these examples to work correctly on an implementation of GKS for which the default is individual attributes, the following function call needs to be made after GKS has been opened:
INTEGER LST(13) DATA LST/13*BUNDLED/ SET ASPECT SOURCE FLAGS(LST)
Similarly, for the example in Section 13.3 to work correctly on an implementation for which the default is bundled, the following is required:
INTEGER LST(13) DATA LST/13*INDIVIDUAL/ SET ASPECT SOURCE FLAGS(LST)
13.5 USER DEFINED BUNDLES
As each of the aspect source flags can be set independently, it is possible to use mixed mode working and specify that some aspects are global and statically bound while others are workstation dependent and dynamically bound. It is useful to think of this as giving the user the ability to define the contents of the bundles for each primitive. For example, if we consider that the text bundle should consist of only the text font and precision and text colour index aspects and that the character expansion factor and character spacing should be global and should not vary between workstations, we can achieve this by:
INTEGER LST(13) DATA LST/13*BUNDLED/ LST(8) = INDIVIDUAL LST(9) = INDIVIDUAL SET ASPECT SOURCE FLAGS(LST)
Let us use these settings in an example:
SET TEXT REPRESENTATION(WS1, 4, 3, STROKE, 0, 1, 1) SET TEXT REPRESENTATION(WS2, 4, 1, CHAR, 0, 1, 3) SET TEXT INDEX(4) SET CHARACTER HEIGHT(CH) SET CHARACTER EXPANSION FACTOR(1.5) SET CHARACTER SPACING(0.2) TEXT(X, Y, LABEL)
The text will be output in font 3 at STROKE precision and colour 1 on workstation WSI (maybe a monochrome high quality hardcopy device) and in font 1 at CHAR precision and colour 3 on workstation WS2 (maybe a colour raster display for preview). On both workstations a character expansion factor of 1.5 and a character spacing of 0.2 will be used (so that the characters are placed in the same positions on the preview device and the hardcopy device, for instance). The corresponding parameters in the SET TEXT REPRESENTATION functions have been specified as standard values, reflecting that these parameters are not used. They could equally well have been set to any other valid values as they are not used when the corresponding aspect source flags are set to INDIVIDUAL However, the workstation will still check that a valid representation has been defined.
As has been shown, GKS provides a very versatile method of specifying how aspects should be associated with primitives. Novices are recommended to use either the bundled mode or the individual mode of working initially and only venture into mixed mode working, defining their own bundles, when they fully understand all the consequences.