Open Inventor Release 2024.2.0
 
Loading...
Searching...
No Matches
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. 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

Using the X Window System

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

  • A render-area “widget”
  • Main loop and initialization functions
  • An event translator utility 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:

  • Events (derived from SoEvent)
  • Scene manager
  • Handle event action
  • Event callback functions
  • Selection node 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) 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.

Render Area

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 (see Event Processing in Inventor ). Window-specific events are passed into this render area and then automatically translated into a generic Inventor SoEvent.

The render area provides the following:

  • Built-in sensors that redraw the window when the scene changes or when the window resizes or is exposed
  • Built-in event processing
  • Certain controls, such as the type of transparency and the amount of antialiasing

Inventor Events (SoEvent)

The class tree for SoEvent is shown in Event Classes .

Event Classes

Each SoEvent instance contains the following information:

  • Type identification (SoType)
  • Time the event occurred
  • Cursor position when the event occurred
  • State of the modifier keys (Shift, Control, Alt) when the event occurred Subclasses of SoEvent contain additional information. For example, SoButtonEvent contains information about whether the button was up or down when the event occurred. SoMouseButtonEvent contains information about which button was pressed (button 1, 2, or 3).

See the Open Inventor C++ Reference Manual entry on SoEvent 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 and a button number, and the macro returns TRUE if that button was pressed.
  • SO_MOUSE_RELEASE_EVENT()—You pass in an SoEvent and a button number, and the macro returns TRUE if that button was released. SoKeyboardEvent contains information on which key was pressed (but does not indicate uppercase or lowercase).

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

An SoLocation2Event 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 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.

Inventor events are extensible. If you have a device that does not correspond to existing SoEvent classes, you can create your own. (See Touch and Gesture Events)

Scene Manager

As shown in Event Processing in Inventor , SoSceneManager is a common class used to tie window-system–dependent render areas (such as SoXtRenderArea) 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.