Table of Contents

Class SimulationExtension

Namespace
NominalSystems.Universe
Assembly
NominalSystems.Universe.dll

[Nominal] The simulation extension provides additional functionality to the simulation for accessing objects, adding objects, and updating the simulation using more appropriate tick events.


public static class SimulationExtension
Inheritance
SimulationExtension

Methods

AddSchematic(Simulation?)

Adds a new schematic to the controller of a particular type.

public static Schematic? AddSchematic(this Simulation? simulation)

Parameters

simulation Simulation

A reference to the simulation

Returns

Schematic

The schematic that was created

Add<T>(Simulation)

Generic add method which is able to add a new object of a type to the simulation. This will add an object of a particular type to the root of the simulation.

public static T Add<T>(this Simulation simulation) where T : Object

Parameters

simulation Simulation

The simulation reference

Returns

T

The object that was added to the simulation

Type Parameters

T

The Nominal Systems object to add

CreateMessage<T>(Simulation)

Creates a new message and registers it to the simulation. This will keep track of the message over time.

public static T CreateMessage<T>(this Simulation simulation) where T : Message

Parameters

simulation Simulation

The simulation to add the message to

Returns

T

The message reference that was created

Type Parameters

T

The message type to create

FindObject<T>(Simulation)

Finds a universe object of a particular type. This will find the first object that exists in the controller of the type or subclass.

public static T? FindObject<T>(this Simulation simulation) where T : UniverseObject

Parameters

simulation Simulation

The simulation reference

Returns

T

The object reference, if it exists

Type Parameters

T

The universe object type to find

FindObjects<T>(Simulation)

Returns a list of universe objects that have been added to the simulation, in the order that they were created on the controller.

public static T[] FindObjects<T>(this Simulation simulation) where T : UniverseObject

Parameters

simulation Simulation

The simulation reference

Returns

T[]

The array of universe objects that were added

Type Parameters

T

The universe object type to find

GetControllerObjects(Simulation)

Returns a array of Nominal Systems universe objects that have been added to the simulation. This will not include messages and will include the order that the objects should be in, as per the controller.

public static Object[] GetControllerObjects(this Simulation simulation)

Parameters

simulation Simulation

The simulation reference

Returns

Object[]

An array of all objects in the simulation, in the order they were added

GetCurrentSeconds(Simulation)

Returns the current time of the simulation in seconds, which is converted from the raw nanoseconds stored in the simulation clock.

public static double GetCurrentSeconds(this Simulation simulation)

Parameters

simulation Simulation

The simulation reference

Returns

double

[s] The time of the simulation in seconds

GetDatabaseHistory(SQLiteConnection?, Object, string, double, double, double)

Returns the database history for a particular variable on a particular object. This assumes that the simulation database contains data for that object and that particular variable.

public static string[] GetDatabaseHistory(SQLiteConnection? connection, Object obj, string variable, double startTime, double endTime, double resolution)

Parameters

connection SQLiteConnection

The SQLite connection

obj Object

The object to grab the history of

variable string

The variable name to grab the history of

startTime double

The start time, in seconds, to fetch the data from

endTime double

The end time, in seconds, to fetch the data from. If less than 0, then there is no end

resolution double

The resolution in seconds to store the data in

Returns

string[]

The array of variable variants from the history

GetIsRunning(Simulation)

Returns whether the simulation is still running or whether it has reached the end of its life.

public static bool GetIsRunning(this Simulation simulation)

Parameters

simulation Simulation

The simulation reference

Returns

bool

The is running flag

GetObjects(Simulation)

Returns a list of Nominal Systems objects in the simulation. This will not be of a particular type, but will be of the base type and will return all objects and messages added.

public static Object[] GetObjects(this Simulation simulation)

Parameters

simulation Simulation

The simulation reference

Returns

Object[]

An array of all objects in the simulation, in the order they were added

GetSchematics(Simulation)

Returns a list of schematics that exist within the simulation. This will be an exhaustive list.

public static Schematic[] GetSchematics(this Simulation simulation)

Parameters

simulation Simulation

The simulation reference

Returns

Schematic[]

An array of all schematics in the simulation

GetState(Object)

Returns the state of the object as a JSON object.

public static JObject GetState(this Object src)

Parameters

src Object

Returns

JObject

GetSystem(Simulation, Type)

Returns a reference to a universe system added to the simulation. If it does not yet exist, it will create the object and attach it to the controller as a universe system should always exist. This works for a defined type.

public static UniverseSystem GetSystem(this Simulation simulation, Type type)

Parameters

simulation Simulation

The simulation reference

type Type

The universe system type to fetch

Returns

UniverseSystem

The universe system object from the controller

GetSystem<T>(Simulation)

Returns a reference to a universe system added to the simulation. If it does not yet exist, it will create the object and attach it to the controller as a universe system should always exist.

public static T GetSystem<T>(this Simulation simulation) where T : UniverseSystem

Parameters

simulation Simulation

The simulation reference

Returns

T

The universe system object from the controller

Type Parameters

T

The universe system type to fetch

InitializeSimulation(Simulation)

Initializes the simulation by updating the universe event controller. This should be called before the first tick and will ensure that the simulation is correctly initialized and an update step is called on all components for the purpose of the saving and loading system.

public static void InitializeSimulation(this Simulation simulation)

Parameters

simulation Simulation

The simulation reference

IsModelSupported(Type, Type)

Returns whether a universe model can be attached to a particular universe class. If the class is not supported, this will return false.

public static bool IsModelSupported(Type modelClass, Type objectClass)

Parameters

modelClass Type

The class type of the model

objectClass Type

The class type of the object

Returns

bool

A supported flag and enables adding of the class

IsParentSupported(Type, Type)

Returns whether a child class is supported by a parent class. If the class is not supported, this will return false. If there is no attribute, it will be assumed to be supported.

public static bool IsParentSupported(Type childClass, Type parentClass)

Parameters

childClass Type

The child class

parentClass Type

The parent class

Returns

bool

A supported flag and enables adding of the class

LoadAssemblies()

Loads all relevant assemblies required for the testing classes, to be able to recreate the objects and types that are being tested.

public static void LoadAssemblies()

LoadFromDatabase(Simulation, SQLiteConnection?, double)

Attempts to load the data from a database into the simulation object. This will require an SQLite database.

public static bool LoadFromDatabase(this Simulation simulation, SQLiteConnection? connection, double time)

Parameters

simulation Simulation

The simulation object to load

connection SQLiteConnection

The SQLite database connection

time double

[s] The time to fetch the data from

Returns

bool

A successful load operation

LoadFromFile(Simulation, string)

Loads the simulation state from a file. This will attempt to update every value in the simulation state to match the values in the file.

public static bool LoadFromFile(this Simulation simulation, string path)

Parameters

simulation Simulation

The simulation reference to load to

path string

The full file path of the file to load

Returns

bool

A successful load operation

LoadFromJson(Simulation, JObject)

Loads the simulation state from a JSON. This will attempt to update every value in the simulation state to match the values in the JSON.

public static bool LoadFromJson(this Simulation simulation, JObject json)

Parameters

simulation Simulation

The simulation reference to load to

json JObject

The JSON object

Returns

bool

A successful load operation

LoadFromString(Simulation, string)

Loads the simulation state from a string of JSON.

public static bool LoadFromString(this Simulation simulation, string json)

Parameters

simulation Simulation

The simulation reference to load to

json string

The full JSON string

Returns

bool

A successful load operation

RemoveSchematic(Simulation?, Schematic?)

Removes a schematic from the simulation

public static void RemoveSchematic(this Simulation? simulation, Schematic? schematic)

Parameters

simulation Simulation

A reference to the simulation

schematic Schematic

The schematic to remove

SaveToDatabase(Simulation, SQLiteConnection?)

Saves the state of the simulation to a database file that has already been opened. If the connection is not valid, then this will return false.

public static bool SaveToDatabase(this Simulation simulation, SQLiteConnection? connection)

Parameters

simulation Simulation

The simulation object to save

connection SQLiteConnection

The SQLite database connection

Returns

bool

A successful save operation

SaveToFile(Simulation, string)

Saves the state of the simulation to a file at the specified path. This will save the current state and turn it into a JSON object, which will be written to the file at the path location.

public static bool SaveToFile(this Simulation simulation, string path)

Parameters

simulation Simulation

The simulation object to save

path string

The full file path to the location of the save file

Returns

bool

A successful save operation

SaveToJson(Simulation)

Saves the state of the simulation to a JSON object.

public static JObject SaveToJson(this Simulation simulation)

Parameters

simulation Simulation

The simulation object to save

Returns

JObject

The simulation JSON

SaveToString(Simulation)

Saves the state of the simulation to a string and returns the string of the simulation.

public static string SaveToString(this Simulation simulation)

Parameters

simulation Simulation

The simulation object to save

Returns

string

The simulation JSON string

Stop(Simulation, double)

Stops the simulation at the current time and prevents the clock from ticking any further.

public static void Stop(this Simulation simulation, double seconds = 0)

Parameters

simulation Simulation

The simulation reference

seconds double

[s] The time to stop the clock at

Tick(Simulation, double)

Attempts to tick the simulation with a specific amount of time, which is in seconds.

public static double Tick(this Simulation simulation, double seconds = 1E-09)

Parameters

simulation Simulation

The simulation object reference

seconds double

[s] The time to tick the simulation

Returns

double

[s] The current time in seconds