From beadf751b0d47d967f27de061aa5bb8c20fb75db Mon Sep 17 00:00:00 2001 From: codex Date: Mon, 10 Aug 2026 15:44:38 +0300 Subject: [PATCH] feat: model legacy line number marker settings --- .../ProductionSettingsContract.cs | 30 +++++++++++++++++-- .../ProductionSettingsContractTests.cs | 11 +++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Plant3D2026/P_Rec_Annot/src/PRecAnnot.Core/ProductionSettingsContract.cs b/Plant3D2026/P_Rec_Annot/src/PRecAnnot.Core/ProductionSettingsContract.cs index c97fa36..4ff2c39 100644 --- a/Plant3D2026/P_Rec_Annot/src/PRecAnnot.Core/ProductionSettingsContract.cs +++ b/Plant3D2026/P_Rec_Annot/src/PRecAnnot.Core/ProductionSettingsContract.cs @@ -17,7 +17,8 @@ public sealed record ProductionSettingsContract( string ElevationTextStyle, string SetLayer, double? FixedSupportPlusLength, - string? ScriptFolder) + string? ScriptFolder, + LineNumberMarkerSettings? LineNumberMarker) { public static ProductionSettingsContract Parse(string xml) { @@ -38,6 +39,12 @@ public sealed record ProductionSettingsContract( if (string.IsNullOrWhiteSpace(setLayer)) throw Invalid("SetLayer.name"); var plusLength = root.Element("PlusLengthNO")?.Attribute("value")?.Value; double? parsedPlusLength = TryParseLegacyNumber(plusLength, out var plus) ? plus : null; + var marker = root.Element("LineNumbers")?.Element("Marker"); + LineNumberMarkerSettings? parsedMarker = marker is null ? null : new( + Required(marker, "layer"), + TryParseLegacyNumber(marker.Attribute("maskscalefactor")?.Value, out var mask) ? mask : null, + ParseLine(marker.Element("Line")), + ParseText(marker.Element("Text"))); return new( copy, layers, @@ -51,9 +58,25 @@ public sealed record ProductionSettingsContract( Required(elevations, "textstyle"), setLayer, parsedPlusLength, - root.Element("ScriptFolder")?.Attribute("path")?.Value); + root.Element("ScriptFolder")?.Attribute("path")?.Value, + parsedMarker); } + private static LineGeometrySettings? ParseLine(XElement? value) => value is null ? null : new( + TryParseLegacyNumber(value.Attribute("startx")?.Value, out var startX) ? startX : null, + TryParseLegacyNumber(value.Attribute("starty")?.Value, out var startY) ? startY : null, + TryParseLegacyNumber(value.Attribute("endx")?.Value, out var endX) ? endX : null, + TryParseLegacyNumber(value.Attribute("endy")?.Value, out var endY) ? endY : null, + value.Attribute("layer")?.Value); + + private static TextAnnotationSettings? ParseText(XElement? value) => value is null ? null : new( + value.Attribute("layer")?.Value, + value.Attribute("textstyle")?.Value, + TryParseLegacyNumber(value.Attribute("size")?.Value, out var size) ? size : null, + value.Attribute("textvalue")?.Value, + TryParseLegacyNumber(value.Attribute("positionx")?.Value, out var positionX) ? positionX : null, + TryParseLegacyNumber(value.Attribute("positiony")?.Value, out var positionY) ? positionY : null); + private static int? ParseInt(XElement value, string name) => int.TryParse(value.Attribute(name)?.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var parsed) ? parsed : null; private static bool TryParseLegacyNumber(string? value, out double parsed) { @@ -66,3 +89,6 @@ public sealed record ProductionSettingsContract( public sealed record NamedDrawingObject(string Type, string Name); public sealed record LayerSetupRule(string FilterType, string FilterValue, int? LineWeight, string LineType, string Color); +public sealed record LineNumberMarkerSettings(string Layer, double? MaskScaleFactor, LineGeometrySettings? Line, TextAnnotationSettings? Text); +public sealed record LineGeometrySettings(double? StartX, double? StartY, double? EndX, double? EndY, string? Layer); +public sealed record TextAnnotationSettings(string? Layer, string? TextStyle, double? Size, string? TextValue, double? PositionX, double? PositionY); diff --git a/Plant3D2026/P_Rec_Annot/tests/PRecAnnot.Core.Tests/ProductionSettingsContractTests.cs b/Plant3D2026/P_Rec_Annot/tests/PRecAnnot.Core.Tests/ProductionSettingsContractTests.cs index 766b809..b376682 100644 --- a/Plant3D2026/P_Rec_Annot/tests/PRecAnnot.Core.Tests/ProductionSettingsContractTests.cs +++ b/Plant3D2026/P_Rec_Annot/tests/PRecAnnot.Core.Tests/ProductionSettingsContractTests.cs @@ -43,4 +43,15 @@ public sealed class ProductionSettingsContractTests var result = ProductionSettingsContract.Parse(xml); Assert.Equal(1.5, result.FixedSupportPlusLength); } + + [Fact] + public void ParsesLegacyLineNumberMarkerContract() + { + const string xml = "
"; + var result = ProductionSettingsContract.Parse(xml); + Assert.NotNull(result.LineNumberMarker); + Assert.Equal(1.10, result.LineNumberMarker!.MaskScaleFactor); + Assert.Equal(-1.0607, result.LineNumberMarker.Line!.StartX); + Assert.Equal(2.5, result.LineNumberMarker.Text!.Size); + } }