Search Results for

    Show / Hide Table of Contents

    Class ModelConfigController

    High-level controller for ModelConfig persistence and keyed access. Paths may be file or directory; if a directory is given, the file name modelConfig.json is used. Dotted keys address JSON nodes, e.g. "calib.mode", "calib.targets.index.threshold".

    Inheritance
    object
    ModelConfigController
    Namespace: Wss.ModelModule
    Assembly: WSS_Core_Interface.dll
    Syntax
    public sealed class ModelConfigController

    Constructors

    ModelConfigController(string)

    Create or open a model config at path. If path is a directory, appends modelConfig.json. Ensures the file exists by saving defaults when first created.

    Declaration
    public ModelConfigController(string path)
    Parameters
    Type Name Description
    string path

    File path like "C:\data\modelConfig.json" or directory like "C:\data".

    Examples
    var mc = new ModelConfigController(@"Configs\");      // uses Configs\modelConfig.json
    var mc2 = new ModelConfigController(@"Configs\m.json"); // uses given file directly
    Exceptions
    Type Condition
    ArgumentException

    When path is null or whitespace.

    Methods

    GetAllCalibParams()

    Return a flat snapshot of scalar values under "calib". Keys are dotted, e.g., "calib.mode", "calib.targets.index.threshold".

    Declaration
    public Dictionary<string, string> GetAllCalibParams()
    Returns
    Type Description
    Dictionary<string, string>

    A copy of key/value pairs as strings.

    Examples
    var all = mc.GetAllCalibParams();
    foreach (var kv in all) Debug.Log($"{kv.Key} = {kv.Value}");

    GetCalibMode()

    Get the model’s calibration mode from "calib.mode". Throws if missing.

    Declaration
    public string GetCalibMode()
    Returns
    Type Description
    string

    Calibration mode string, e.g., "midpoint", "sweep".

    Examples
    string mode = mc.GetCalibMode();

    GetModelParam<T>(string)

    Get a required typed value from a dotted key. Throws if the key is missing or the value cannot be converted to T.

    Declaration
    public T GetModelParam<T>(string key)
    Parameters
    Type Name Description
    string key

    Dotted key, e.g., "calib.mode".

    Returns
    Type Description
    T

    Value at the key as T.

    Type Parameters
    Name Description
    T

    Expected return type.

    Examples
    string mode = mc.GetModelParam<string>("calib.mode");
    float thr   = mc.GetModelParam<float>("calib.targets.index.threshold");
    Exceptions
    Type Condition
    ArgumentException

    If key is null or whitespace.

    KeyNotFoundException

    If the key does not exist.

    GetOrDefault<T>(string, T)

    Get a typed value or a default when missing. Does not throw on absent keys.

    Declaration
    public T GetOrDefault<T>(string key, T dflt = default)
    Parameters
    Type Name Description
    string key

    Dotted key, e.g., "calib.sampling.rateHz".

    T dflt

    Fallback value to return when the key is missing.

    Returns
    Type Description
    T

    Value at the key, or dflt if absent.

    Type Parameters
    Name Description
    T

    Expected return type.

    Examples
    int rate = mc.GetOrDefault("calib.sampling.rateHz", 1000);

    LoadModelJson()

    Reload the current model configuration from its existing path. Reinstantiates the underlying ModelConfig so disk edits are reflected in memory.

    Declaration
    public void LoadModelJson()
    Examples
    // external tool edited the JSON on disk:
    mc.LoadModelJson(); // refresh memory view

    LoadModelJson(string)

    Load a model configuration from a new path. If path is a directory, appends modelConfig.json. Replaces the active config instance.

    Declaration
    public void LoadModelJson(string path)
    Parameters
    Type Name Description
    string path

    File path like "..\profiles\a.json" or directory like "..\profiles".

    Examples
    mc.LoadModelJson(@"Profiles\UserA\");       // Profiles\UserA\modelConfig.json
    mc.LoadModelJson(@"Profiles\AltModel.json"); // specific file
    Exceptions
    Type Condition
    ArgumentException

    When path is null or whitespace.

    SaveModelJson()

    Save the current in-memory model configuration to disk. Uses Save(). Call after any Set/Update to persist changes.

    Declaration
    public void SaveModelJson()
    Examples
    mc.SetModelParam("calib.mode", "midpoint");
    mc.SaveModelJson();

    SetCalibMode(string)

    Set "calib.mode" and save.

    Declaration
    public void SetCalibMode(string mode)
    Parameters
    Type Name Description
    string mode

    Non-empty mode string, e.g., "midpoint".

    Examples
    mc.SetCalibMode("midpoint");
    Exceptions
    Type Condition
    ArgumentException

    If mode is null or whitespace.

    SetModelParam<T>(string, T)

    Set a value at the dotted key and immediately save. Use for scalars or small objects that serialize to a JSON value.

    Declaration
    public void SetModelParam<T>(string key, T value)
    Parameters
    Type Name Description
    string key

    Dotted key, e.g., "calib.mode", "calib.targets.index.threshold".

    T value

    Value to write.

    Type Parameters
    Name Description
    T

    Serializable type (e.g., string, int, float, small POCO).

    Examples
    mc.SetModelParam("calib.mode", "midpoint");
    mc.SetModelParam("calib.targets.index.threshold", 0.42f);
    Exceptions
    Type Condition
    ArgumentException

    If key is null or whitespace.

    TryGetModelParam<T>(string, out T)

    Try to get a typed value without throwing.

    Declaration
    public bool TryGetModelParam<T>(string key, out T value) where T : notnull
    Parameters
    Type Name Description
    string key

    Dotted key, e.g., "calib.targets.middle.gain".

    T value

    Output value when found and convertible.

    Returns
    Type Description
    bool

    true if the key exists and was converted; otherwise false.

    Type Parameters
    Name Description
    T

    Expected return type.

    Examples
    if (mc.TryGetModelParam("calib.targets.thumb.offset", out float off)) { /* use off */ }
    Exceptions
    Type Condition
    ArgumentException

    If key is null or whitespace.

    In this article
    Back to top Generated by DocFX