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

Working With Items Interactively

When G2 is running, part of its memory contains all the items in the current KB. By default, when you start G2, the current KB is empty. You use the developer's environment to add items to the current KB. After you add some number of items, you save the current KB into a KB file. Working with the current KB and with KB files is described in Chapter 3, Knowledge Bases.

To place items on a workspace interactively:

  1. Create a new workspace by selecting:

    G2 creates a new empty workspace.

  2. To add an item to this workspace, click on the workspace background and select one of the menu choices on the KB Workspace menu that begins with the word New.

    For example, to create a variable:

    1. Select the New Object menu choice.

    2. Select g2-variable from the choose a class submenu.

    3. Choose logical-variable from the choose a class submenu.

    G2 automatically creates a new logical variable item and attaches its icon to the mouse pointer.

  3. Position the mouse and click to place the icon on the workspace.

    The new item now resides upon that workspace.

When you create an item interactively, you see it appear on the screen. Items have different kinds of appearances, such as icons or text boxes. Each kind of item appearance is called its representation. For a description of the kinds of item representations in G2, see Item Representation.

To learn more about working with workspaces, see Chapter 4, Workspaces.

Using Item Menus

You perform an operation on an item interactively by selecting a choice from its menu.

To open an item's menu:

As shown in the next figure, clicking the mouse on an item causes G2 to display the item's menu over or near the item. The title bar of an item's menu shows the item's class.


To dismiss an item's menu:

G2 automatically positions and scales a menu so that it is entirely visible within the G2 process's window.

Common Item Menu Choices

This table lists several interactive operations that are common to most classes of items:

Menu Choice Description
change size
Open a workspace that lets you resize the item.
clone
Create a new copy of the item.
color
Change a color setting.
create subworkspace
Create a new workspace that is subordinate to this item.
delete
Remove this item from the current KB.
describe
Display the Describe workspace for this item.
describe configuration
Display the inheritance of configurations for this item.
enable
disable

Allow or disallow this item to participate in the KB's processing.
lift to top
drop to bottom

Display the item so that it is on top of all other items upon this workspace; display the item so that it is beneath all other items upon this workspace.
name
Edit the name of this item.
rotate/reflect
Rotate the item's representation in increments of 90 degrees; display the item's representation with mirrored appearance.
table
Display the item's attribute table.
transfer
Allow you to drag the item to another workspace.

Changing the Size of an Item

Selecting the change size menu choice opens a dialog that you use to change the size of this item's representation. G2 encloses the item in a rectangle with a thick border. To change the size of an item, move any edge or corner of the rectangle, then press the Update Now button.

For example, this figure shows how you can enlarge the icon of a logical variable:


When you finish changing the size:


Note: Every G2 item has a maximum size limit, beyond which the change size option has no effect.

Cloning an Item

Cloning an item means to make a copy of it and all its knowledge. You can clone items interactively or programmatically.

To clone an item interactively:

  1. Select the clone choice on its menu.

    This causes G2 to create a copy of the selected item and to attach the new item to the mouse pointer.

  2. Move the mouse to a location upon this workspace or (upon any other visible kb-workspace), then click the mouse.

    This causes G2 to place the new item at that location upon the workspace.

Interactively, you can clone either permanent or transient items. Cloning a permanent item interactively results in a permanent cloned item; cloning a transient item interactively results in a transient cloned item.

To clone an item programmatically:

Unlike when cloning an item interactively, executing the create by cloning action always causes G2 to create a transient cloned item that does not reside upon any workspace. For the new item to become visible, your KB must also execute the transfer action, to place the new item upon a kb-workspace. You can also optionally execute actions that make the cloned item permanent.

For more information about the create by cloning action, see Creating an Item by Cloning Another.

Cloning Specific Knowledge

In most cases, a cloned item's knowledge includes all the knowledge of its source item, if it is valid for a new copy of that knowledge to exist in the current KB. For instance, a cloned item has the same attribute displays that are defined for its source item. However, an object that is cloned from another object that is the value of an attribute cannot also be the value of the same attribute.

You can clone a KB-workspace. This results in a new workspace item, cloned items upon the new workspace that are copies of source items upon the source workspace, cloned subworkspaces, if any, of the cloned items, and so on. However, if you clone a workspace that is the subworkspace of another item, the clone workspace is not also the subworkspace of that item.

A cloned item does not automatically participate in the relations already established between its source item and other items. A cloned item does not have a value in its Names attribute. This reflects the philosophy that, in general, it is less desirable to have more than one item with the same name, especially among items of the same class.

After cloning an executable item (that is, a rule, procedure, method, and so on), G2 initializes the item so that its OK/incomplete/bad status is incomplete. This means that the item must be edited or explicitly recompiled before G2 allows it to be invoked. For a cloned rule, G2 also appends ellipses (...) to the rule's text, to indicate visually that the rule's status does not allow it to be invoked.

The next figure shows a rule that has been cloned from a named rule that has an attribute display. The rule's text shows that it is not ready to be invoked, and the attribute display for the item's Names attribute displays that this item has no name.


Changing the Color of an Item

The color menu choice allows you to assign color settings interactively to the color attributes of items.

The color attributes that are settable using the color menu choice depend on the item's representation style, as follows:

For information about how a set of color attributes corresponds to each item representation style, see Item Representation.

The next figure shows how G2 displays the color palette after you select the color menu choice:


For example, the color choice in the menu for a rule allows you to set the three color attributes for items with a text box representation style:


Deleting an Item

The delete menu choice for an item causes G2 to remove that item from the current KB. Use this menu choice to delete an item, regardless of whether the KB is running, paused, or reset, and regardless of the settings of the item status.

Use the Delete Workspace choice on a workspace's menu to delete the workspace. Remember that deleting a workspace also deletes all items upon the workspace, as well as all items below those items in the KB's workspace hierarchy.

Deleting an item, either interactively or programmatically, can also affect other items:

Whether done interactively or programmatically, deleting a permanent item (and any additional changes that this causes for other permanent items) cannot be undone by resetting the current KB. Deleting a permanent item changes the current KB's permanent knowledge. For a description of the KB's permanent knowledge, see Distinguishing Permanent and Current Knowledge.

Describing an Item

The describe menu choice for an item directs G2 to display a Describe workspace, which presents information about an item's knowledge. The exact information that the workspace displays depends on the class of the selected item.

For many items, the Describe workspace simply displays the first name listed in the item's Names attribute. If the selected item has no user-specified name, the Describe workspace displays the G2-assigned name for the item, as with this Describe workspace for an unnamed workspace:


For items of certain classes, the Describe workspace offers much more information, as for this unnamed logical variable:


The Describe workspace has its own menu. The text items that appear in a Describe workspace are also selectable and have their own menus.


Tip: See the various chapters in this document to obtain more information about what appears in the Describe workspace for items of a particular system-defined class.

Describing the Configuration of an Item

Selecting the describe configuration choice on an item's menu displays a table that shows the hierarchy of configurations that apply to the item. Configurations and the configurations hierarchy are described in Chapter 7, Configurations.

Lifting to the Top and Dropping to the Bottom

Use the Lift to Top and Drop to Bottom menu choices to change an item's layer position, adjusting its relative position, top to bottom, among the items in this workspace.

Selecting Lift to Top causes the selected item to appear on top of any other item on its workspace. Selecting Drop to Bottom causes the selected item to appear beneath any other item on its workspace.

Lift to Top and Drop to Bottom work by revising the layering of items on a workspace. Lift to Top makes the selected item's item layer position less than the item layer positions of all other items on that workspace. Conversely, Drop to Bottom makes the selected item's item layer position greater than the item layer positions of all other items on that workspace.

For two items whose representations overlap, the following diagram shows the result of selecting Lift to Top and Drop to Bottom:


Naming an Item

Select the name menu choice to edit the Names attribute of an item. Selecting name causes G2 to open a Text Editor workspace. When you finish editing the name, press Return, or click the mouse on the End button.

If you name an item, try to make the name unique. Though G2 allows duplicate item names, their use is not recommended as a development practice. When duplicate names exist, and more than one of the items satisfies a reference, G2 chooses one of the items at random. The choice may not be the same from one reference to the next, which can cause unpredictable results.

For some items, and for most objects, after you edit the item's name, G2 displays the item's name in a name box below the item.


After a name box appears, you can drag it to a new position near the item or anywhere else upon the workspace. You can quickly open the Text Editor and edit the item's name by clicking on the text of the name box.

To open the menu for a item's name box:

To edit the name of an item shown in a name box:

To hide the display of a name box:


Tip: An item's name box is not the same as an attribute display. See
Adding Attribute Displays.

Showing and Hiding an Item Name Box Programmatically

You can access and manipulate an item's name box programmatically using the attribute access facility. The name-box of an item is represented in a structure.


The next procedure shows one way to hide and show the name box of any variable or parameter. This procedure:

Rotating and Reflecting an Item


The Rotate/Reflect menu choice presents the submenu shown at left. Selecting a degree of rotation directs G2 to turn the item's representation on its center, by either 90 degrees or 180 degrees. Selecting either left-right or up-down reflection directs G2 to display a mirrored version of the item's representation.

This figure shows the effect of rotating an item with an icon representation:


This figure shows the effect of reflecting an item with an icon representation:


Displaying the Table for an Item

Selecting the table menu choice directs G2 to display the attribute table for this item.

Interacting with attribute tables is explained in Using Attribute Tables.

Transferring Items to Another Workspace

Selecting the transfer menu choice allows you to use the mouse pointer to drag the selected item to any KB workspace that is displayed in the G2 window.


The figure shows that after dragging the item to the destination workspace, G2 enlarges the workspace so that it encloses the item's representation within the workspace's current margins.

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

Copyright © 1997 Gensym Corporation, Inc.