feat: implement first limited Pipe annotation Apply
This commit is contained in:
@@ -43,7 +43,6 @@ public sealed class EntryPoint : IExtensionApplication
|
||||
{
|
||||
document = AcadApplication.DocumentManager.MdiActiveDocument;
|
||||
var mode = ParseMode(RuntimeDiagnostics.RuntimeMode);
|
||||
if (mode == PRecAnnotExecutionMode.Apply) throw new InvalidOperationException("APPLY_MODE_NOT_IMPLEMENTED");
|
||||
|
||||
var context = new PlantRuntimeContextReader().ReadCurrentContext();
|
||||
var details = new Dictionary<string, object?>
|
||||
@@ -75,6 +74,15 @@ public sealed class EntryPoint : IExtensionApplication
|
||||
return;
|
||||
}
|
||||
|
||||
if (mode == PRecAnnotExecutionMode.Apply && !string.Equals(commandName, "PXP-OA", StringComparison.Ordinal))
|
||||
throw new InvalidOperationException("APPLY_RULE_NOT_SUPPORTED");
|
||||
var hasLimitedApplyPermit = !string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("P_REC_ANNOT_APPLY_PERMIT_PATH"));
|
||||
var applyPermit = (mode == PRecAnnotExecutionMode.Apply || hasLimitedApplyPermit) && document is not null
|
||||
? FirstLimitedApplyPermitReader.ReadFor(document)
|
||||
: null;
|
||||
if (mode == PRecAnnotExecutionMode.Apply && context.Viewports.Count != 1)
|
||||
throw new InvalidOperationException("APPLY_REQUIRES_EXACTLY_ONE_VIEWPORT");
|
||||
|
||||
var builder = new AnnotationPlanBuilder();
|
||||
var plans = new List<AnnotationPlan>();
|
||||
var objectsByViewport = new List<IReadOnlyList<PlantObjectSnapshot>>();
|
||||
@@ -82,7 +90,14 @@ public sealed class EntryPoint : IExtensionApplication
|
||||
{
|
||||
var objects = new PlantObjectReader().ReadObjects(viewport, CancellationToken.None);
|
||||
objectsByViewport.Add(objects);
|
||||
plans.Add(builder.Build(new AnnotationPlanningRequest { CommandName = commandName, Viewport = viewport, Objects = objects }));
|
||||
plans.Add(builder.Build(new AnnotationPlanningRequest
|
||||
{
|
||||
CommandName = commandName,
|
||||
Viewport = viewport,
|
||||
Objects = objects,
|
||||
LimitedApplyTargetSnapshotId = applyPermit?.TargetSnapshotId,
|
||||
LimitedApplyRuleId = applyPermit is null ? null : FirstLimitedApplyPlanner.RuleId
|
||||
}));
|
||||
}
|
||||
|
||||
var summary = new
|
||||
@@ -114,11 +129,32 @@ public sealed class EntryPoint : IExtensionApplication
|
||||
details["PlanConflictCount"] = summary.ConflictCount;
|
||||
details["PlanUnsupportedCount"] = summary.UnsupportedCount;
|
||||
details["ErrorCount"] = summary.ErrorCount;
|
||||
if (mode == PRecAnnotExecutionMode.Apply)
|
||||
{
|
||||
var corePermit = new FirstLimitedApplyPermit
|
||||
{
|
||||
FixtureMarker = FirstLimitedApplyPlanner.FixtureMarker,
|
||||
AllowApply = applyPermit!.AllowApply,
|
||||
TargetSnapshotId = applyPermit.TargetSnapshotId,
|
||||
ExpectedPlanId = applyPermit.ExpectedPlanId
|
||||
};
|
||||
var preflight = new FirstLimitedApplyPlanner().Prepare(mode, plans.Single(), context.Viewports.Single(), objectsByViewport.Single(), corePermit);
|
||||
new RuntimeWriteGuard(mode).EnsureWriteAllowed(preflight.Operation.OperationId);
|
||||
RuntimeDiagnostics.Write("ApplyPreflightCompleted", operationId: operationId, commandName: commandName, resultStatus: "Accepted", document: document);
|
||||
RuntimeDiagnostics.Write("AnnotationTransactionStarted", operationId: operationId, commandName: commandName, document: document);
|
||||
var outcome = new FirstLimitedPipeAnnotationWriter().Write(document!, preflight.Operation, applyPermit.VisibilityState);
|
||||
details["ApplyOutcome"] = outcome.ToString();
|
||||
details["AnnotationsCreated"] = outcome == PipeAnnotationWriteOutcome.Created ? 1 : 0;
|
||||
details["AnnotationsSkipped"] = outcome == PipeAnnotationWriteOutcome.AlreadyExists ? 1 : 0;
|
||||
RuntimeDiagnostics.Write(outcome == PipeAnnotationWriteOutcome.Created ? "AnnotationCreated" : "AnnotationDuplicateDetected", operationId: operationId, commandName: commandName, resultStatus: outcome.ToString(), document: document);
|
||||
RuntimeDiagnostics.Write("AnnotationTransactionCommitted", operationId: operationId, commandName: commandName, resultStatus: outcome.ToString(), document: document);
|
||||
}
|
||||
RuntimeDiagnostics.Write("CommandPreflightCompleted", operationId: operationId, commandName: commandName, resultStatus: "DryRunCompleted", document: document, details: details);
|
||||
WriteEditor(document, $"\nP_Rec_Annot — диагностический план\nПроект: {context.ProjectDisplayName}\nТип чертежа: Ortho\nViewport: {context.Viewports.Count}\nОбъектов найдено: {summary.ObjectsExamined}\nБудет создано: {summary.CreateCount}\nБудет обновлено: {summary.UpdateCount}\nБудет пропущено: {summary.SkipCount}\nКонфликтов: {summary.ConflictCount}\nОшибок: {summary.ErrorCount}\nDWG не изменён.");
|
||||
WriteEditor(document, $"\nPlan schema: {AnnotationPlanBuilder.CurrentPlanSchemaVersion}; PlanId: {planId ?? "multiple"}; membership resolved/partial/outside/unresolved: {membershipResolved}/{membershipPartial}/{membershipOutside}/{membershipUnresolved}.");
|
||||
WriteUsage(operationId, commandName, "DryRunCompleted", document, details, stopwatch.ElapsedMilliseconds);
|
||||
RuntimeDiagnostics.Write("CommandCompleted", operationId: operationId, commandName: commandName, resultStatus: "DryRunCompleted", document: document, details: details);
|
||||
var completedStatus = mode == PRecAnnotExecutionMode.Apply ? "ApplyCompleted" : "DryRunCompleted";
|
||||
WriteUsage(operationId, commandName, completedStatus, document, details, stopwatch.ElapsedMilliseconds);
|
||||
RuntimeDiagnostics.Write("CommandCompleted", operationId: operationId, commandName: commandName, resultStatus: completedStatus, document: document, details: details);
|
||||
}
|
||||
catch (System.Exception exception)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user