feat: add p-rec-annot line-number command preview service
This commit is contained in:
@@ -62,6 +62,7 @@ public sealed record LineNumberCommandPlan(IReadOnlyList<LineNumberCommandOperat
|
||||
public sealed record LineNumberApplyPreflight(string StableId, int MarkerNumber, string Text, AnnotationPoint Position, double Rotation, string Layer, string TextStyle);
|
||||
public sealed record LineNumberApplyResult(int Created, int Updated, int Unchanged);
|
||||
public sealed record LineNumberListApplyPreflight(string StableId, AnnotationPoint Position, double Rotation, IReadOnlyList<LineNumberApplyPreflight> Rows);
|
||||
public sealed record LineNumberPreviewResult(bool Success, LineNumberCommandPlan? Plan, IReadOnlyList<LineNumberApplyPreflight> Apply, string? FailureCode = null);
|
||||
public sealed record LineNumberTextAsset(string Layer, string TextStyle, double Size, string TextValue, Point2Dto Position);
|
||||
public sealed record LineNumberLineAsset(string Layer, Point2Dto Start, Point2Dto End);
|
||||
public sealed record LineNumberMarkerAsset(string Layer, double MaskScaleFactor, IReadOnlyList<LineNumberTextAsset> Texts, IReadOnlyList<LineNumberLineAsset> Lines);
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using PRecAnnot.Abstractions;
|
||||
|
||||
namespace PRecAnnot.Core;
|
||||
|
||||
public sealed class LineNumberCommandPreviewService(LineNumberCommandPlanner planner, LineNumberFieldResolver fieldResolver)
|
||||
{
|
||||
public LineNumberPreviewResult Preview(LineNumberAnnotationDefinition definition, IEnumerable<LineNumberCandidate> candidates, IEnumerable<ExistingLineNumberAnnotation> existing)
|
||||
{
|
||||
var resolved = new List<LineNumberCandidate>();
|
||||
foreach (var candidate in candidates.OrderBy(item => item.StableId, StringComparer.Ordinal))
|
||||
{
|
||||
var fields = definition.Tags.Select(tag => tag.Field).Where(field => !string.IsNullOrWhiteSpace(field));
|
||||
var properties = fieldResolver.Resolve(candidate.RowId, fields);
|
||||
if (!properties.Success) return new(false, null, Array.Empty<LineNumberApplyPreflight>(), properties.FailureCode);
|
||||
resolved.Add(candidate with { Properties = properties.Values });
|
||||
}
|
||||
var plan = planner.Build(definition, resolved, existing);
|
||||
return new(true, plan, LineNumberCommandPlanner.PrepareApply(plan));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user