feat(heidenhain): AdminUI driver/device forms, typed tag editor, CSV + browse-commit (#803)

- HeidenhainDriverForm over HeidenhainDriverFormModel (JsonObject bag preserves Devices and
  unknown keys; no enum fields; Validate asks HeidenhainOptionsParser) + DriverConfigFormMap.
- HeidenhainDeviceForm/Model (Host, Port 19000, optional per-device password references)
  + DeviceFormMap. Literal passwords are refused in both forms.
- RawDriverTypeDialog entry; HeidenhainTagConfigEditor over HeidenhainTagConfigModel, whose
  Validate is the driver's own TryFromTagConfig; catalog leaves derive dataType + isArray;
  registered in TagConfigEditorMap + TagConfigValidator.
- CsvColumnMap (HhAddress/HhDataType/HhIsArray) and RawBrowseCommitMapper branch.
- Guards: DriverPageJsonConverterTests external-serializer entry, TagConfigNonEnumParityTests
  runtime map + corpus + freshly-authored rows, TagConfigRoundTrip, HeidenhainAuthoringTests.
This commit is contained in:
Joseph Doherty
2026-11-10 23:17:26 -05:00
parent 2b45694f91
commit 3641d56154
17 changed files with 721 additions and 0 deletions
@@ -280,6 +280,10 @@ public static class RawBrowseCommitMapper
}.ToJson();
if (Is(driverType, DriverTypeNames.Galaxy))
return WriteSingleKey("attributeRef", address);
// Heidenhain: a browsed leaf is a fixed catalog address; the typed model derives its data type and array
// flag from the catalog, so the committed tag opens in the editor and passes the driver's gate unchanged.
if (Is(driverType, DriverTypeNames.Heidenhain))
return new HeidenhainTagConfigModel { Address = address }.ToJson();
// Sql: a browsed leaf is a COLUMN, and a column name alone cannot address a tag — SqlTagConfigModel
// needs the table too. SqlBrowseSession therefore travels schema/table/columnName in AddressFields.
// Without this branch a Sql commit fell through to the generic "address" key below, which the typed
@@ -635,6 +635,15 @@ public static class CsvColumnMap
new CsvRawKeyColumn(new CsvTypedColumn("MtDevice", "mtDevice", null), CsvRawKeyKind.String),
new CsvRawKeyColumn(new CsvTypedColumn("MtComponent", "mtComponent", null), CsvRawKeyKind.String),
}),
// Heidenhain (#803): address + the binding data type NAME + the array flag the catalog's array leaves
// require. The driver's HeidenhainTagDefinitionFactory is the gate a CSV row is validated against.
new RawKeyCsvDriverTagMap(DriverTypeNames.Heidenhain, new[]
{
new CsvRawKeyColumn(new CsvTypedColumn("HhAddress", "address", null), CsvRawKeyKind.String),
new CsvRawKeyColumn(new CsvTypedColumn("HhDataType", "dataType", null), CsvRawKeyKind.String),
new CsvRawKeyColumn(new CsvTypedColumn("HhIsArray", "isArray", null), CsvRawKeyKind.Bool),
}),
};
return maps.ToDictionary(m => m.DriverType, m => m, StringComparer.OrdinalIgnoreCase);
@@ -0,0 +1,82 @@
using System.Text.Json.Nodes;
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
using ZB.MOM.WW.OtOpcUa.Driver.Heidenhain;
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Uns.TagEditors;
/// <summary>
/// Typed model of a Heidenhain raw tag's <c>TagConfig</c> (lmxopcua#803). Keys: <c>address</c>, <c>dataType</c>
/// (a NAME), <c>isArray</c>. Unknown keys (historian intent, …) are preserved.
/// </summary>
/// <remarks>
/// <para><b>The driver is the only authority.</b> <see cref="Validate"/> asks
/// <see cref="HeidenhainTagDefinitionFactory.TryFromTagConfig"/> about the blob this model would save (or, on
/// first load, the blob it was loaded from — CSV import and the API save verbatim), so the editor, the deploy
/// gate and the runtime accept exactly the same tags.</para>
/// <para><b>Shape is derived, not authored, for fixed leaves.</b> For a catalog address <see cref="ToJson"/>
/// writes the catalog's data type and its array flag, so the node's rank always matches what the driver
/// publishes. A PLC/DATA binding carries the operator-chosen type. A stray <c>writable</c> key is dropped —
/// the driver is read-only.</para>
/// </remarks>
public sealed class HeidenhainTagConfigModel
{
/// <summary>The address: a catalog leaf, <c>PLC:AREA:INDEX</c> or <c>DATA:/path</c>.</summary>
public string Address { get; set; } = "";
/// <summary>The binding data type (ignored for fixed leaves, whose type is the catalog's).</summary>
public DriverDataType DataType { get; set; } = DriverDataType.Int32;
private JsonObject _bag = new();
private string? _source;
/// <summary>True when <see cref="Address"/> is a fixed catalog leaf.</summary>
public bool IsCatalogAddress => HeidenhainCatalog.TryGet(Address.Trim(), out _);
public static HeidenhainTagConfigModel FromJson(string? json)
{
var o = TagConfigJson.ParseOrNew(json);
var address = TagConfigJson.GetString(o, "address") ?? "";
var typeText = TagConfigJson.GetString(o, "dataType");
DriverDataType type;
if (HeidenhainCatalog.TryGet(address.Trim(), out var entry)) type = entry.DataType;
else if (typeText is not null && HeidenhainTagDefinitionFactory.TryParseDataTypeName(typeText, out var parsed)) type = parsed;
else type = DriverDataType.Int32;
return new HeidenhainTagConfigModel { Address = address, DataType = type, _bag = o, _source = json ?? "" };
}
public string ToJson()
{
var address = Address.Trim();
TagConfigJson.Set(_bag, "address", address);
TagConfigJson.Set(_bag, "writable", null);
if (HeidenhainCatalog.TryGet(address, out var entry))
{
TagConfigJson.Set(_bag, "dataType", entry.DataType);
TagConfigJson.Set(_bag, "isArray", entry.IsArray ? true : null);
}
else
{
TagConfigJson.Set(_bag, "dataType", DataType);
TagConfigJson.Set(_bag, "isArray", null);
}
return _source = TagConfigJson.Serialize(_bag);
}
public string? Validate()
{
if (string.IsNullOrWhiteSpace(Address)) return "An address is required (e.g. Status/ExecutionState, PLC:WORD:4, DATA:/PLC/memory/W/8).";
var blob = _source is null ? ToJsonPreview() : _source;
return HeidenhainTagDefinitionFactory.TryFromTagConfig(TagConfigParseGate.AuthoringRawPath, "", blob, out _, out var error)
? null
: error;
}
private string ToJsonPreview()
{
var saved = _source;
var json = ToJson();
_source = saved;
return json;
}
}
@@ -25,6 +25,7 @@ public static class TagConfigEditorMap
[DriverTypeNames.Sql] = typeof(Components.Shared.Uns.TagEditors.SqlTagConfigEditor),
[DriverTypeNames.Mqtt] = typeof(Components.Shared.Uns.TagEditors.MqttTagConfigEditor),
[DriverTypeNames.MTConnect] = typeof(Components.Shared.Uns.TagEditors.MTConnectTagConfigEditor),
[DriverTypeNames.Heidenhain] = typeof(Components.Shared.Uns.TagEditors.HeidenhainTagConfigEditor),
};
/// <summary>Returns the editor component type for a driver type, or null if none is registered.</summary>
@@ -27,6 +27,7 @@ public static class TagConfigValidator
[DriverTypeNames.Sql] = j => SqlTagConfigModel.FromJson(j).Validate(),
[DriverTypeNames.Mqtt] = j => MqttTagConfigModel.FromJson(j).Validate(),
[DriverTypeNames.MTConnect] = j => MTConnectTagConfigModel.FromJson(j).Validate(),
[DriverTypeNames.Heidenhain] = j => HeidenhainTagConfigModel.FromJson(j).Validate(),
};
/// <summary>