feat: add controlled p-rec-annot line-number apply
This commit is contained in:
@@ -98,6 +98,19 @@ public sealed class EntryPoint : IExtensionApplication
|
||||
var operations = string.Join(", ", preview.Plan!.Operations.Select(value => $"{value.Kind}:{value.Text}"));
|
||||
editor.WriteMessage($"\nPXP-LN preview: {operations}. DWG не изменён.");
|
||||
RuntimeDiagnostics.Write("LineNumberPreviewCompleted", commandName: "PXP-LN", resultStatus: "PreviewCompleted", document: document, details: new Dictionary<string, object?> { ["OperationCount"] = preview.Apply.Count });
|
||||
if (ParseMode(RuntimeDiagnostics.RuntimeMode) != PRecAnnotExecutionMode.Apply) return;
|
||||
|
||||
var operation = preview.Apply.SingleOrDefault() ?? throw new InvalidOperationException("LINE_NUMBER_APPLY_REQUIRES_EXACTLY_ONE_OPERATION");
|
||||
var placement = editor.GetPoint("\nУкажите положение маркера номера линии: ");
|
||||
if (placement.Status != PromptStatus.OK) return;
|
||||
operation = operation with { Position = new AnnotationPoint(placement.Value.X, placement.Value.Y, placement.Value.Z) };
|
||||
var permit = LineNumberApplyPermitReader.Read();
|
||||
LineNumberApplyPermitReader.Validate(document, permit, operation);
|
||||
// AutoCAD wraps a command's committed transaction in its native
|
||||
// UNDO record. No compensating-delete path is used here.
|
||||
var result = new LineNumberAnnotationWriter().Apply(document, [operation], configuration.Assets);
|
||||
RuntimeDiagnostics.Write("LineNumberApplyCompleted", commandName: "PXP-LN", resultStatus: result.Created > 0 ? "Created" : result.Updated > 0 ? "Updated" : "AlreadyCurrent", document: document, details: new Dictionary<string, object?> { ["Created"] = result.Created, ["Updated"] = result.Updated, ["AlreadyCurrent"] = result.Unchanged });
|
||||
editor.WriteMessage($"\nPXP-LN Apply: created={result.Created}; updated={result.Updated}; already-current={result.Unchanged}.");
|
||||
}
|
||||
catch (System.Exception exception)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Text.Json;
|
||||
using Autodesk.AutoCAD.ApplicationServices;
|
||||
using PRecAnnot.Abstractions;
|
||||
|
||||
namespace PRecAnnot.Plant3D2026;
|
||||
|
||||
internal sealed record LineNumberApplyPermit
|
||||
{
|
||||
public required bool AllowApply { get; init; }
|
||||
public required string FixtureMarkerPath { get; init; }
|
||||
public required string ExpectedStableId { get; init; }
|
||||
public required string ExpectedText { get; init; }
|
||||
}
|
||||
|
||||
internal static class LineNumberApplyPermitReader
|
||||
{
|
||||
private const string MarkerContent = "P_REC_ANNOT_TEST_FIXTURE=LINE_NUMBER_APPLY";
|
||||
|
||||
public static void Validate(Document document, LineNumberApplyPermit permit, LineNumberApplyPreflight operation)
|
||||
{
|
||||
if (!permit.AllowApply || !string.Equals(permit.ExpectedStableId, operation.StableId, StringComparison.Ordinal) || !string.Equals(permit.ExpectedText, operation.Text, StringComparison.Ordinal))
|
||||
throw new InvalidOperationException("LINE_NUMBER_APPLY_PERMIT_PLAN_MISMATCH");
|
||||
if (!Path.IsPathFullyQualified(permit.FixtureMarkerPath) || permit.FixtureMarkerPath.StartsWith("\\\\", StringComparison.Ordinal) || !File.Exists(permit.FixtureMarkerPath) || !string.Equals(File.ReadAllText(permit.FixtureMarkerPath).Trim(), MarkerContent, StringComparison.Ordinal))
|
||||
throw new InvalidOperationException("LINE_NUMBER_APPLY_TEST_FIXTURE_REQUIRED");
|
||||
var fixtureRoot = Path.GetDirectoryName(Path.GetFullPath(permit.FixtureMarkerPath))! + Path.DirectorySeparatorChar;
|
||||
if (!Path.GetFullPath(document.Name).StartsWith(fixtureRoot, StringComparison.OrdinalIgnoreCase)) throw new InvalidOperationException("LINE_NUMBER_APPLY_TEST_FIXTURE_REQUIRED");
|
||||
}
|
||||
|
||||
public static LineNumberApplyPermit Read()
|
||||
{
|
||||
var path = Environment.GetEnvironmentVariable("P_REC_ANNOT_LINE_NUMBER_APPLY_PERMIT_PATH");
|
||||
if (string.IsNullOrWhiteSpace(path) || !Path.IsPathFullyQualified(path) || path.StartsWith("\\\\", StringComparison.Ordinal) || !File.Exists(path))
|
||||
throw new InvalidOperationException("LINE_NUMBER_APPLY_PERMIT_REQUIRED");
|
||||
return JsonSerializer.Deserialize<LineNumberApplyPermit>(File.ReadAllText(path), new JsonSerializerOptions { PropertyNameCaseInsensitive = true })
|
||||
?? throw new InvalidOperationException("LINE_NUMBER_APPLY_PERMIT_INVALID");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user