Difference between revisions of "Extending OpenRocket"

From OpenRocket wiki
Jump to navigation Jump to search
Line 27: Line 27:
 
A simulation extensions typically consists of 2-4 Java classes:
 
A simulation extensions typically consists of 2-4 Java classes:
  
* The '''simulation extension''' implements the <code>SimulationExtension</code> interface.  A new instance is created for each simulation that has the extension defined. It contains the extension configuration and a method that is called whenever a simulation is started.
+
{| class="wikitable"
* The '''simulation extension provider''' is a plugin implementation that functions as a factory class for the simulation extension.  It implements the <code>SimulationExtensionProvider</code> interface.
+
|-
* A '''simulation extension configurator''' is an optional plugin implementation that provides a GUI for configuring a simulation extension. It implements the <code>SwingSimulationExtensionConfigurator</code> interface.
+
!
* A '''simulation listener''' is a listener that is attached to a simulation at runtime.  The listener is notified of all actions during the simulation and it can modify and affect the simulation while it is being run.  The simulation extension may add a simulation listener to the simulation run when it is started. A simulation listener implements one or more of the interfaces <code>SimulationListener</code>, <code>SimulationComputationListener</code> and <code>SimulationEventListener</code>.
+
! Interface / abstract class
 +
! Description
 +
|-
 +
! Simulation extension
 +
| ''<code>SimulationExtension</code>'' <br> <code>AbstractSimulationExtension</code>
 +
| Contains the extension configuration for a single simulation and a method that is called whenever the simulation is started.  A new instance is created for each simulation that has the extension defined.
 +
|-
 +
! Simulation extension ''provider''
 +
| ''<code>SimulationExtensionProvider</code>'' <br> <code>AbstractSimulationExtensionProvider</code>
 +
| An OpenRocket plugin that functions as a factory class for the simulation extension.  It provides the extension ID, location in the UI menu and instances of the extension.
 +
|-
 +
! Simulation extension ''configurator''
 +
| <code>SwingSimulationExtensionConfigurator</code> <br> <code>AbstractSwingSimulationExtensionConfigurator</code>
 +
| An (optional) OpenRocket plugin that provides a GUI for configuring the simulation extension.
 +
|-
 +
! Simulation ''listener''
 +
| ''<code>SimulationListener</code> <br> <code>SimulationComputationListener</code> <br> <code>SimulationEventListener</code>'' <br> <code>AbstractSimulationListener</code>
 +
| A listener that can be attached to a simulation at runtime.  The listener is notified of all actions during the simulation and it can modify and affect the simulation while it is being run.  The simulation extension may add a simulation listener to the simulation run when it is started.
 +
|-
 +
|}
  
'''The recommended way of implementing these interfaces''' is by extending the abstract classes <code>AbstractSimulationExtension</code>, <code>AbstractSimulationExtensionProvider</code>, <code>AbstractSwingSimulationExtensionConfigurator</code> and <code>AbstractSimulationListener</code>.  This allows maximum compatibility with future versions of OpenRocket when new methods are added to the interfaces.
+
'''The recommended way of implementing these interfaces is by extending the abstract classes'''.  This allows maximum compatibility with future versions of OpenRocket when new methods are added to the interfaces.

Revision as of 23:08, 25 December 2014

Extending OpenRocket

OpenRocket is built to be extensible using plugins. You can implement your own functionality or download plugins implemented by others.

This document describes how to implement your own extensions to OpenRocket.


Plugins

Extensions to OpenRocket are implemented as plugins. All interfaces that may have multiple implementations should be implemented using plugin interfaces internally. That way, external plugins may create new implementations.

A plugin is compiled into a JAR file and placed into the OpenRocket plugin directory. These JAR files are included in the OpenRocket classpath at startup and scanned for classes and interfaces annotated with @Plugin.

  • A plugin interface is a Java interface that is annotated with the @Plugin annotation. These interfaces are scanned from the classpath at startup and can be queried by the code.
  • A plugin implementation is a Java class that implements a plugin interface and is annotated with the @Plugin annotation.

In practise the plugin interfaces are defined by the internal OpenRocket code, and are extension points which internal and external plugins can implement.

Note: Many of the internal interfaces have not yet been changed to use the plugin interface. They will be migrated one by one. Help is appreciated.


Simulation extensions

Simulation extensions allow modifying simulations before or during a simulation. They allow controlling almost every aspect of a simulation.

A simulation extensions typically consists of 2-4 Java classes:

Interface / abstract class Description
Simulation extension SimulationExtension
AbstractSimulationExtension
Contains the extension configuration for a single simulation and a method that is called whenever the simulation is started. A new instance is created for each simulation that has the extension defined.
Simulation extension provider SimulationExtensionProvider
AbstractSimulationExtensionProvider
An OpenRocket plugin that functions as a factory class for the simulation extension. It provides the extension ID, location in the UI menu and instances of the extension.
Simulation extension configurator SwingSimulationExtensionConfigurator
AbstractSwingSimulationExtensionConfigurator
An (optional) OpenRocket plugin that provides a GUI for configuring the simulation extension.
Simulation listener SimulationListener
SimulationComputationListener
SimulationEventListener

AbstractSimulationListener
A listener that can be attached to a simulation at runtime. The listener is notified of all actions during the simulation and it can modify and affect the simulation while it is being run. The simulation extension may add a simulation listener to the simulation run when it is started.

The recommended way of implementing these interfaces is by extending the abstract classes. This allows maximum compatibility with future versions of OpenRocket when new methods are added to the interfaces.