OOF2: The Manual
Internal extensions are easier to build and use than external extensions because they use the OOF2 installation machinery. However they have two disadvantages:
-
They require the developer to have permission to write files in the OOF2 source code directories.
-
The directory containing internal extensions will be rewritten when a new version OOF2 is installed, so any changes there will be lost.
All of the source code for an internal extension should be put
in a subdirectory of SRC/EXTENSIONS in the
main OOF2 source directory. If an
add_subdirectory(extensionname) line is added to
SRC/EXTENSIONS/CMakeLists.txt, then the
code in the subdirectory extensionname will
be compiled and installed when OOF2 is built. If a
subdirectory of this directory contains an
__init__.py file, the directory will be
imported automatically if OOF2 is started with the --autoload
option.
The files required for an internal extension depend on whether the extension contains C++ code or is purely Python.
If the extension contains only Python files, all of the
files in its entire
subdirectory, including any nested subdirectories, will be
installed when OOF2 is installed. No
CMakeLists.txt file is required in the
extension's directory, and
the extension does not have to be listed in any other OOF2
CMakeLists.txt file.
The extension's directory must contain an
__init__.py, which should import the
extension's other Python files, if those files need to be
imported when the extension is loaded. Files defining new
Fields or Properties generally should be loaded at start
up time.
To build an extension called “oofextension”, do the following:
-
Create a subdirectory called
oofextensioninSRC/EXTENSIONS/ -
Edit
SRC/EXTENSIONS/CMakeLists.txtand add the line
add_subdirectory(oofextension) -
Inside
SRC/EXTENSIONS/oofextension, write the C++ code for the extension, following the guidance in Chapter 8. The C++ files do not have to be namedoofextension.C, but they can be. Write swig files to create the Python interface to those parts of the extension that have to be accessible from Python. -
Create a
CMakeLists.txtin the extension's directory. It should look like Example 7.5. If there are subdirectories containing C++ code withinoofextension, createCMakeLists.txtfiles there too.
Example 7.5. CMakeLists.txt for an internal extension
oof_swig_sources( #SWIGFILES oofextension #
SOURCES oofextension.C #
LIBRARIES oof2common oof2engine #
) add_subdirectory(subdirectoryname) #
![]()
|
|
|
|
This is the name of the swig file, without its
suffix. CMake will look for
|
|
|
Additional C++ source files that need to be compiled
are listed here. There can be more than one. The
C++ file generated by swig should
not be listed. Don't use this
if more than one swig file is included in
|
|
|
The OOF2 libraries that this extension uses are
listed here.
Note that when building external extensions,
|
|
|
If there are subdirectories, add a line like this
for each, and put a
|
Internal extensions are loaded automatically if the --autoload
option is used when starting OOF2.
An individual extension can be loaded manually by typing
import ooflib.EXTENSIONS.extensionname in the OOF2 Console Window, or by putting that line a script and loading the script.


SWIGFILES oofextension #
SOURCES oofextension.C #
LIBRARIES oof2common oof2engine #
)
add_subdirectory(subdirectoryname) #

