6.1. Overview

As described in The Inventor Mentor, all engines have at least one input and one output. The inputs are derived from SoField SoField SoField (either SoSF or SoMF fields). Outputs are of type SoEngineOutput SoEngineOutput SoEngineOutput . In addition, each engine has an evaluate() method, which uses the current input values and produces new output values. The file SoSubEngine.h contains the macros for defining new engine classes. The SO_ENGINE_HEADER() macro declares type identifier and naming variables and methods that all engine classes must support. The macro defines the static variables and methods declared in the SO_ENGINE_HEADER() macro. Other macros useful in creating new engine classes are mentioned in the following sections.

Creating a new engine requires these steps:

  1. Select a name for the new engine class and determine what class it is derived from.

  2. Define and name each input and output of the engine (see Section 6.2, “Defining Inputs and Outputs”).

  3. Define an initClass() method to initialize the type information (see Section 6.3, “Initializing the Engine Class”).

  4. Define an exitClass() method to clean up the type information. In the exitClass() routine of your class, use the macro SO_ENGINE_EXIT_CLASS.

  5. Define a constructor (see Section 6.4, “Defining the Constructor”).

  6. Define a destructor.

  7. Implement an evaluate() method for the engine class (see Section 6.8, “Notification and Evaluation”).

  8. If necessary, implement an inputChanged() method (see the section called “Creating a Fan-in Engine” and the section called “Creating a Second-Ticker Engine”).

  9. Implement a copy() method if the engine contains any nonfield instance data (see Chapter 2, “Creating a Node,” for more information on implementing a copy() method).