3.1. Overview

The file SoSubField.h contains the macros for defining new field classes. If you do create a field class, you will probably need to use only a few of these macros. The more commonly used ones are documented in this chapter.

Creating a new field requires these steps:

  1. Select a name for the new field class, determine whether it is derived from SoSField( C++ | Java | .NET ) or SoMField( C++ | Java | .NET ) (or a subclass), and determine the type of the field value (for example, float, SbVec3f( C++ | Java )).

  2. Define an initClass() method to initialize type information. This step is required for both single-value and multiple-value fields (see Section 3.2, “Initializing the Field Class”).

  3. Define an exitClass() method to clean up the type information. In the exitClass() routine of your class, use the macro SO_SFIELD_EXIT_CLASS for single-value fields, and SO_MFIELD_EXIT_CLASS for multiple-value fields.

  4. Implement the reading and writing methods for the field.

    a. For single-value fields, implement readValue() and writeValue() methods (see Section 3.3, “Creating a Single-Value Field”).

    b. For multiple-value fields, implement read1Value() and write1Value() methods. You may also want to implement a getNumValuesPerLine() method for a multiple-value field. This method is used by the ASCII file format and tells how many values fit on one line when the field is written out (see Section 3.4, “Creating a Multiple-Value Field”).

  5. If it is useful, you can optionally define other methods for setting and accessing values in the field. For example, SoSFVec3f( C++ | Java | .NET ) allows you to set the value from three floats or from an array of three floats, and so on.