Defining parameters - arklumpus/TreeViewer GitHub Wiki

Modules can define global settings and parameters that can be changed by the user and affect how the module behaves. Global settings can be defined by any kind of module, and usually determine the default behaviour of the module. Parameters can be defined by Transformer, Further transformation, Coordinates and Plot action modules, and affect how a single module instance behaves.

Global settings and parameters are defined in a similar way, by having a method (either GetGlobalSettings or GetParameters) return a List of (string, string) tuples that define the parameters. The first item of each tuple determines the name of the parameter (which is shown to the user and used as a key for the dictionary containing parameter values that is passed to the module), while the second item describes the type of control that should be used to change the value of the parameter and the default value. For global settings, these controls appear in the Preferences window that can be opened from the Edit menu; for module parameters, they can be shown by expanding the options for the module in the Settings panel.

For example, the following method states that the module requires a single parameter called "Thickness:", that can be changed using a numeric spin box, with a default value of 1, minimum value 0 and no upper bound (i.e. maximum value of ):

public static List<(string, string)> GetParameters(TreeNode tree)
{
    return new List<(string, string)>()
    {
        ("Thickness:", "NumericUpDown:1[\"0\",\"Infinity\"]")
    };
}

In general, the parameter type is specified in the second item of the tuple by a keyword (NumericUpDown in the example above), followed by a colon (:) and the default value (1 in the example above), followed by a JSON array describing additional parameters (in the example above, the JSON array is ["0","Infinity"], where "0" is the minimum value and "Infinity" is the maximum).

In the various methods in the module that have a Dictionary<string, object> argument containing parameter values, the value of the parameter can be obtained by retrieving the item from the dictionary and casting it to the appropriate type. In the case of the example above:

public static Point[] PlotAction(TreeNode tree, Dictionary<string, object> parameterValues, Dictionary<string, Point> coordinates, Graphics graphics)
{
    double thickness = (double)parameterValues["Thickness:"];
}

Note that the name of the parameter corresponds exactly to the name given in the GetParameters method, including any trailing spaces or punctuation.

All the possible parameter types, the options for the controls, and how to retrieve the value of the parameters can be found in the pages describing the Global settings and the Module parameters.