10.2. General Programming Model for Event Handling

Inventor includes a built-in event model for the scene database. This model is not based on any specific window system or toolkit. When writing an Inventor program, you can select the X window programming model and use the tools provided by the window system to open windows and pass events into Inventor. Inventor provides event translation from X events into the Inventor event classes. Figure 10.1, “ Event Processing in Inventor ” shows how X events are passed to the render area and then translated into Inventor events that are handled by the Inventor scene manager. Since Inventor is independent of any window system, you can also choose a different window system and then write your own event translator.

Event Processing in Inventor

Figure 10.1.  Event Processing in Inventor


Inventor provides a set of Xt utilities for use with the X Window System. This set of utilities contains the following:

In addition to these features, the Inventor Component Library also contains a set of Xt components. These components include viewers and editors with a user interface for modifying the scene database directly.

This chapter focuses on the aspects of Inventor that are independent of the window system:

Chapter 18, Open Inventor Component Library describes use of the Inventor Component Library in more detail. If you want to use Inventor viewers and editors, you must use an Xt render area (SoXtRenderArea( C++ )) and the X Window System model. If you are not using these viewers and editors, you can choose a different window system and then implement your own render area, event loop, and event translator.

The render-area widget provides a convenient object for creating a window and translating window-specific events into generic Inventor events. With the X Window System model, you create an SoXtRenderArea( C++ ) (see Figure 10.1, “ Event Processing in Inventor ”). Window-specific events are passed into this render area and then automatically translated into a generic Inventor SoEvent( C++ | Java | .NET ).

The render area provides the following:

The class tree for SoEvent( C++ | Java | .NET ) is shown in Figure 10.2, “ Event Classes ”.


Each SoEvent( C++ | Java | .NET ) instance contains the following information:

Subclasses of SoEvent( C++ | Java | .NET ) contain additional information. For example, SoButtonEvent( C++ | Java | .NET ) contains information about whether the button was up or down when the event occurred. SoMouseButtonEvent( C++ | Java | .NET ) contains information about which button was pressed (button 1, 2, or 3).

See the Open Inventor C++ Reference Manual entry on SoEvent( C++ | Java | .NET ) for a list of methods available for querying the event. In addition, you can use the following macros:

  • SO_MOUSE_PRESS_EVENT()—You pass in an SoEvent( C++ | Java | .NET ) and a button number, and the macro returns TRUE if that button was pressed.

  • SO_MOUSE_RELEASE_EVENT()—You pass in an SoEvent( C++ | Java | .NET ) and a button number, and the macro returns TRUE if that button was released.

SoKeyboardEvent( C++ | Java | .NET ) contains information on which key was pressed (but does not indicate uppercase or lowercase).

[Tip]

Tip: Using the SoKeyboardEvent::getKey() method is the same as using XLookupKeysym() on an X key event.

An SoLocation2Event( C++ | Java | .NET ) is generated whenever the cursor moves. This event contains the absolute location of the cursor in window coordinates. (Window coordinates begin with (0, 0) at the lower left corner of the window.) An SoMotion3Event( C++ | Java | .NET ) is generated whenever a 3D input device, such as the spaceball, moves. This event contains the rotation and translation relative to the device's previous position.

[Tip]

Tip: Inventor events are extensible. If you have a device that does not correspond to existing SoEvent( C++ | Java | .NET ) classes, you can create your own. (See The Inventor Toolmaker, Chapter 11.)

As shown in Figure 10.1, “ Event Processing in Inventor ”, SoSceneManager( C++ | Java | .NET ) is a common class used to tie window-system–dependent render areas (such as SoXtRenderArea( C++ )) to Inventor. The render area employs the scene manager to handle the scene graph. The scene manager handles both rendering and event processing and is independent of any particular window system.