| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (11 out of 19)

Creating Connection Classes

Connections are graphical items that embody logical relationships. You can use connections to represent almost anything that provides a pathway or route between two or more objects. For information about using connections, see Chapter 17, Connections.

The G2 class hierarchy provides the system-defined class CONNECTION for use in defining connections. This section refers to CONNECTION and any system-defined or user-defined subclass of CONNECTION as a connection class. You can create a connection class that has the properties you need. For example, you may wish to create a connection class that displays as a green stripe with a black border.

Connections use stubs on objects (described under Specifying Connection Stubs), junction blocks, and connection posts, both described in this section.

To create a connection class:

  1. Create a CLASS-DEFINITION whose primary direct superior is CONNECTION or any subclass of CONNECTION, following the directions under:

  2. Provide additional information as described in this section.

Instantiability does not apply to connections. G2 ignores the values of a CLASS-DEFINITION's instantiability attributes when the primary direct superior is a connection class.

System-Defined Connection Attributes

Three initializable system-defined attributes exist in every connection class:

When you create a class definition that inherits any connection class, these three attributes appear as initializable system attributes in the definition. The grammar for providing their default values is described under Specifying Default Values for Inherited Attributes. The rest of this section shows you how to specify values for the attributes.

Defining Connection Regions

The Cross-section-pattern attribute lets you define connection regions to which you can assign a width and a color. When connection regions exist, you can refer to them in expressions. For example, during the execution of a KB, you could change the color of one or more connection regions to signal changes in events and status.

Also, completing the Cross-section-pattern attribute automatically creates a corresponding DEFAULT-JUNCTION class.


Hint: While it is not a requirement, we recommend that you define connection cross-section patterns with a symmetrical design.

Here is how to specify the cross-section-pattern attribute:

To specify... Enter a statement such as this...
connection regions
Where you specify one or more regions (region1 and region2) as any unreserved symbol in G2 and assign each a color. Enter as many regions as necessary. An example is:
the size of the regions
Enter the size of each region as a positive integer (in workspace units). This example creates a connection with a black border and a green stripe.

Here is an example of a Cross-section-pattern attribute value:


Once region names exist for a connection class, you can refer to them in expressions by using this syntax:

An example is:

Specifying a Stub Length

The Stub-length attribute specifies the length of stubs as an integer in workspace units.

While an object class definition defines the class, location, and direction of the connection flow, the Stub-length attribute specifies the default length of the stub on a class instance. The default length is 20 (workspace units).

Defining the Junction Block to Use

The Junction-block attribute defines which junction block a connection will use.

A connection is drawn from point-to point, directly from the stub of one object to the stub (or any available location) of another object. To terminate a connection at another connection (rather than at an object), you can use a junction block. In that way, two incoming connections can be joined to an input stub or two inputs fed from an output stub. The Junction-block attribute indicates the class of junction block to use at the intersection of two connections. Here is a junction block:


Whenever you complete the Cross-section-pattern attribute, G2 automatically creates a corresponding Junction-block class with the name of the connection class preceded by junction-block-for-. For example, if the connection name is water-line, and you change the Cross-section-pattern attribute, G2 creates a junction block for that connection with the name:

A junction-block is a DEFAULT-JUNCTION subclass, which is an abstract object class. When G2 creates a new junction-block class automatically, the new class does not appear on the hierarchy of menus, but you can create an instance of it programmatically, or whenever you terminate connections.

If a connection class inherits a cross-section-pattern, G2 does not create a new junction block class for the subclass automatically. However, if you edit the Cross-section-pattern attribute and choose copy inherited path, G2 does two things:

  1. Displays the Cross-section-pattern attribute exactly as it was specified in the superior class

  2. Creates a new junction-block class dynamically with the naming convention noted above


Hint: While you can create a new junction block class interactively (by creating a new object class definition using DEFAULT-JUNCTION as the Direct-superior-class), we recommend that you do not. G2 creates a a junction-box class dynamically any time you specify a Cross-section-pattern in a connection definition.

Creating a Junction-Block Subclass

If it is necessary to create a junction block subclass, create a new object class definition and specify DEFAULT-JUNCTION as the direct superior class.

By default, the icon for a DEFAULT-JUNCTION subclass is a small grey square.

| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (11 out of 19)

Copyright © 1997 Gensym Corporation, Inc.