Compare commits
3
Commits
dcf95d7e3a
...
ea3a9e157e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ea3a9e157e | ||
|
|
837ac1d994 | ||
|
|
142b5f8b93 |
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"executionMode": "DryRun",
|
||||||
|
"runtimeExecuted": false,
|
||||||
|
"plantProjectDetected": null,
|
||||||
|
"orthoDetection": "NotExecuted",
|
||||||
|
"viewportCount": null,
|
||||||
|
"dataLinksAvailable": null,
|
||||||
|
"objectsRead": null,
|
||||||
|
"plan": {
|
||||||
|
"create": null,
|
||||||
|
"update": null,
|
||||||
|
"skip": null,
|
||||||
|
"conflict": null,
|
||||||
|
"unsupported": null
|
||||||
|
},
|
||||||
|
"planDeterministic": true,
|
||||||
|
"dbmodBefore": null,
|
||||||
|
"dbmodAfter": null,
|
||||||
|
"dwgModified": null,
|
||||||
|
"dcfModified": null,
|
||||||
|
"projectXmlModified": null,
|
||||||
|
"unhandledExceptions": null,
|
||||||
|
"blocker": "No controlled test Ortho DWG/project path was supplied or discovered; runtime DryRun was not claimed."
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"product": "Autodesk AutoCAD Plant 3D 2026",
|
||||||
|
"manualNetload": true,
|
||||||
|
"bundleLoaded": true,
|
||||||
|
"automaticAppLoaderChecked": false,
|
||||||
|
"smokeModeConfirmedByOperator": true,
|
||||||
|
"observedCommandLogRuntimeMode": "Normal",
|
||||||
|
"assemblyInitializeCountObserved": 1,
|
||||||
|
"commands": {
|
||||||
|
"PHP_REC_ANNOT": { "registered": true, "executed": true, "usageEvents": 1, "result": "PreflightAccepted" },
|
||||||
|
"PXP-AAV": { "registered": true, "executed": true, "usageEvents": 1, "result": "PreflightAccepted" },
|
||||||
|
"PXP-OA": { "registered": true, "executed": true, "usageEvents": 1, "result": "PreflightAccepted" }
|
||||||
|
},
|
||||||
|
"ribbon": { "created": true, "duplicateCheckedExhaustively": false },
|
||||||
|
"plantContext": { "projectDetected": true, "projectDisplayName": "DefaultProject", "observedOrthoDetected": false, "dataLinksAvailable": true },
|
||||||
|
"writesBlocked": true,
|
||||||
|
"dbmodChecked": false,
|
||||||
|
"dwgModified": false,
|
||||||
|
"dcfModified": false,
|
||||||
|
"projectXmlModified": false,
|
||||||
|
"telemetryEventsExpected": 3,
|
||||||
|
"telemetryEventsActual": 3,
|
||||||
|
"unhandledExceptions": 0,
|
||||||
|
"temporaryInstallationRemoved": true,
|
||||||
|
"productionDeploy": false
|
||||||
|
}
|
||||||
@@ -10,7 +10,9 @@ The first real Plant 3D 2026 build is complete against the workstation assemblie
|
|||||||
| Ribbon | Implemented with `Autodesk.Windows`; idempotent tab/panel guard |
|
| Ribbon | Implemented with `Autodesk.Windows`; idempotent tab/panel guard |
|
||||||
| Adapter | Compiled against real 2026 assemblies |
|
| Adapter | Compiled against real 2026 assemblies |
|
||||||
| Bundle | Local smoke package built and checked for Autodesk DLL exclusion |
|
| Bundle | Local smoke package built and checked for Autodesk DLL exclusion |
|
||||||
| Runtime | Not executed in AutoCAD/Plant process |
|
| Runtime smoke | Manual NETLOAD confirmed on Plant 3D 2026; automatic AppLoader and Ortho DryRun remain unverified |
|
||||||
|
| Ortho read path | Compiled against `OrthoDocUtils`, `OrthoProject`, `DwgSheetDefinitions`, `DwgViewDefs`, and `DataLinksManager`; runtime fixture pending |
|
||||||
|
| Dry-run plan | Deterministic Core builder with DTO boundary and Apply guard; no annotation writes |
|
||||||
| Production deploy | NOT PERFORMED |
|
| Production deploy | NOT PERFORMED |
|
||||||
|
|
||||||
Fixed API assumptions: foundation-only lifecycle became `IExtensionApplication`; command descriptors became actual `CommandMethod` registrations; Plant project detection uses `PlantApplication.CurrentProject`; Ribbon uses `ComponentManager.Ribbon`, `RibbonTab`, `RibbonPanelSource`, and `RibbonButton`. Remaining blockers are runtime loading, Ortho API/data-link mapping, safe DWG transaction implementation, and golden fixture validation.
|
Fixed API assumptions: foundation-only lifecycle became `IExtensionApplication`; command descriptors became actual `CommandMethod` registrations; Ortho detection uses `OrthoDocUtils.IsValidOrthoDrawing` plus the Ortho project part; viewport metadata uses `DwgSheetDefinitions`/`DwgViewDefs`; object properties use read-only `DataLinksManager.SelectAcPpRowIds` and `GetAllProperties`; Core receives only immutable DTOs. Remaining blockers are a controlled Ortho fixture, geometry/object-to-viewport mapping, legacy source provenance, and future Apply implementation.
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# PXP-AAV read-path analysis
|
||||||
|
|
||||||
|
Status: traced to the existing command registration and the shared dry-run plan path; annotation writes are not implemented in this slice.
|
||||||
|
|
||||||
|
| RuleId | LegacyCommand | LegacyProject | LegacyFile | ObservedBehavior | TargetUseCase | TargetClass | Test | Status |
|
||||||
|
|---|---|---|---|---|---|---|---|---|
|
||||||
|
| PXP-AAV-001 | PXP-AAV | legacy audit | `docs/legacy-rule-provenance.csv` | legacy provenance is recorded, but the requested legacy checkout is absent on this workstation | read objects visible to an Ortho view and build a dry-run plan | adapter DTO -> `AnnotationPlan` | `AnnotationPlan_InputOrderDoesNotChangeResult` | partial |
|
||||||
|
|
||||||
|
The implementation deliberately does not claim behavioral equivalence. The next required input is a read-only copy of the legacy source or a golden test Ortho drawing with expected diagnostics.
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# PXP-OA read-path analysis
|
||||||
|
|
||||||
|
Status: command is a real `CommandMethod` and uses the same safe context/read-plan pipeline. No Ortho annotation is created, updated, or deleted.
|
||||||
|
|
||||||
|
| RuleId | LegacyCommand | LegacyProject | LegacyFile | ObservedBehavior | TargetUseCase | TargetClass | Test | Status |
|
||||||
|
|---|---|---|---|---|---|---|---|---|
|
||||||
|
| PXP-OA-001 | PXP-OA | legacy audit | `docs/legacy-rule-provenance.csv` | legacy provenance is available, but source checkout was not found locally | Ortho context and DataLinks read diagnostics | adapter DTO -> `AnnotationPlan` | `ApplyMode_IsBlocked` | partial |
|
||||||
|
|
||||||
|
Exact object filters, annotation text, placement rules, and existing-annotation detection remain unconfirmed until the legacy source or a controlled golden fixture is supplied.
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
# Plant 3D 2026 runtime smoke results
|
||||||
|
|
||||||
|
## Scope
|
||||||
|
|
||||||
|
The smoke test used a temporary per-user bundle installation only. Production deploy was not performed. The temporary installation was removed after AutoCAD closed.
|
||||||
|
|
||||||
|
## Confirmed
|
||||||
|
|
||||||
|
- Manual `NETLOAD` loaded the P_Rec_Annot entry assembly in AutoCAD Plant 3D 2026.
|
||||||
|
- `PHP_REC_ANNOT`, `PXP-AAV`, and `PXP-OA` were accepted by the command line.
|
||||||
|
- The active Plant project was detected as `DefaultProject`.
|
||||||
|
- The user confirmed Smoke mode behavior and no DWG mutation during the manual smoke interaction.
|
||||||
|
- The runtime log contains one assembly initialization and one normal termination for the observed process.
|
||||||
|
- The runtime log records Ribbon creation with status `Created`.
|
||||||
|
- The runtime log records exactly one `CommandUsageEvent` for each of the three commands.
|
||||||
|
- The observed Plant context reported `DataLinksAvailable=true` and `IsOrthoDrawing=false` for `Floor Plan Sample.dwg`.
|
||||||
|
- No unhandled exception was reported in the captured runtime log.
|
||||||
|
|
||||||
|
## Not confirmed
|
||||||
|
|
||||||
|
- Automatic AppLoader loading without `NETLOAD` was not tested.
|
||||||
|
- DBMOD and byte-level DWG/DCF/Project.xml comparisons were not captured by the smoke evidence.
|
||||||
|
- Ribbon duplicate behavior across workspace/document lifecycle was not exhaustively tested.
|
||||||
|
- A command invocation logged as `RuntimeMode=Smoke` is not present in the captured JSONL; the three detailed command records have `RuntimeMode=Normal`.
|
||||||
|
|
||||||
|
## Evidence handling
|
||||||
|
|
||||||
|
The detailed runtime JSONL remains local under `%LOCALAPPDATA%\Promhimproekt\PRecAnnot2026\Logs\` and is not committed. No DWG, DCF, Project.xml, Autodesk DLL, user identity, project path, or full local runtime path is included in the repository.
|
||||||
|
|
||||||
|
Temporary installation: PERFORMED AND REMOVED.
|
||||||
|
Production deploy: NOT PERFORMED.
|
||||||
@@ -12,3 +12,8 @@ Copy-Item -Recurse -Force .\Plant3D2026\P_Rec_Annot\artifacts\P_Rec_Annot.bundle
|
|||||||
In a controlled Plant 3D 2026 session, verify that the entry assembly loads, the `Промхимпроект` tab and `Аннотации` panel occur once, and the `Аннотировать` button invokes `PHP_REC_ANNOT`. Open a Plant project and active DWG, run all three commands, verify the project guard and diagnostic-only behavior, and confirm no unhandled exception. Repeat initialization and confirm no Ribbon duplicate. DWG mutation, Ortho viewport/data-link behavior, undo, repeat-run idempotence, and golden-DWG comparison remain runtime blockers for the implementation wave.
|
In a controlled Plant 3D 2026 session, verify that the entry assembly loads, the `Промхимпроект` tab and `Аннотации` panel occur once, and the `Аннотировать` button invokes `PHP_REC_ANNOT`. Open a Plant project and active DWG, run all three commands, verify the project guard and diagnostic-only behavior, and confirm no unhandled exception. Repeat initialization and confirm no Ribbon duplicate. DWG mutation, Ortho viewport/data-link behavior, undo, repeat-run idempotence, and golden-DWG comparison remain runtime blockers for the implementation wave.
|
||||||
|
|
||||||
Deploy status: NOT PERFORMED.
|
Deploy status: NOT PERFORMED.
|
||||||
|
# Current slice: Ortho read / dry-run
|
||||||
|
|
||||||
|
`P_REC_ANNOT_RUNTIME_MODE=Smoke` reads context only. `DryRun` reads Ortho view metadata and DataLinks properties, builds an immutable deterministic `AnnotationPlan`, and never applies it. `Apply` is blocked with `APPLY_MODE_NOT_IMPLEMENTED`; unknown values resolve to `DryRun`.
|
||||||
|
|
||||||
|
The read adapter uses `OrthoDocUtils.IsValidOrthoDrawing`, `OrthoProject.DwgSheetDefinitions`, `IDwgViewDef`, and read-only `DataLinksManager` methods. The adapter does not expose AutoCAD or Plant objects to Core and contains no write calls. A runtime DryRun result is not published until a controlled test Ortho DWG is available; see `docs/evidence/ortho-dry-run-summary.json`.
|
||||||
|
|||||||
@@ -1,5 +1,117 @@
|
|||||||
namespace PRecAnnot.Abstractions;
|
namespace PRecAnnot.Abstractions;
|
||||||
|
|
||||||
|
public sealed record RuntimeDiagnostic
|
||||||
|
{
|
||||||
|
public required string Code { get; init; }
|
||||||
|
public required string Message { get; init; }
|
||||||
|
public string Severity { get; init; } = "Warning";
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum OrthoDetectionStatus { Confirmed, NotOrtho, Ambiguous, Unsupported, Failed }
|
||||||
|
|
||||||
|
public sealed record OrthoDetectionResult
|
||||||
|
{
|
||||||
|
public required OrthoDetectionStatus Status { get; init; }
|
||||||
|
public required IReadOnlyList<string> Evidence { get; init; }
|
||||||
|
public required IReadOnlyList<RuntimeDiagnostic> Diagnostics { get; init; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly record struct Point2Dto(double X, double Y);
|
||||||
|
public readonly record struct Point3Dto(double X, double Y, double Z);
|
||||||
|
public readonly record struct Vector2Dto(double X, double Y);
|
||||||
|
public sealed record Bounds2Dto(Point2Dto Minimum, Point2Dto Maximum);
|
||||||
|
|
||||||
|
public sealed record GeometrySnapshot
|
||||||
|
{
|
||||||
|
public Point3Dto? WorldPosition { get; init; }
|
||||||
|
public Point2Dto? PaperPosition { get; init; }
|
||||||
|
public Bounds2Dto? ProjectedBounds { get; init; }
|
||||||
|
public double? Rotation { get; init; }
|
||||||
|
public double? Elevation { get; init; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed record OrthoViewportInfo
|
||||||
|
{
|
||||||
|
public required string Id { get; init; }
|
||||||
|
public required string DisplayName { get; init; }
|
||||||
|
public double CenterX { get; init; }
|
||||||
|
public double CenterY { get; init; }
|
||||||
|
public double Width { get; init; }
|
||||||
|
public double Height { get; init; }
|
||||||
|
public double Scale { get; init; }
|
||||||
|
public double TwistAngle { get; init; }
|
||||||
|
public bool IsOn { get; init; }
|
||||||
|
public bool IsLocked { get; init; }
|
||||||
|
public string? SourceDrawingName { get; init; }
|
||||||
|
public string? ViewName { get; init; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed record PlantObjectSnapshot
|
||||||
|
{
|
||||||
|
public required string SnapshotId { get; init; }
|
||||||
|
public required string ObjectClass { get; init; }
|
||||||
|
public string? Tag { get; init; }
|
||||||
|
public string? LineNumber { get; init; }
|
||||||
|
public string? SupportNumber { get; init; }
|
||||||
|
public string? EquipmentNumber { get; init; }
|
||||||
|
public required GeometrySnapshot Geometry { get; init; }
|
||||||
|
public IReadOnlyDictionary<string, string?> Properties { get; init; } = new Dictionary<string, string?>();
|
||||||
|
public IReadOnlyList<string> Diagnostics { get; init; } = Array.Empty<string>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed record PlantRuntimeContext
|
||||||
|
{
|
||||||
|
public bool HasActiveDocument { get; init; }
|
||||||
|
public bool HasPlantProject { get; init; }
|
||||||
|
public bool IsOrthoDrawing { get; init; }
|
||||||
|
public string? DrawingName { get; init; }
|
||||||
|
public string? ProjectDisplayName { get; init; }
|
||||||
|
public IReadOnlyList<OrthoViewportInfo> Viewports { get; init; } = Array.Empty<OrthoViewportInfo>();
|
||||||
|
public IReadOnlyList<RuntimeDiagnostic> Diagnostics { get; init; } = Array.Empty<RuntimeDiagnostic>();
|
||||||
|
public OrthoDetectionResult Detection { get; init; } = new() { Status = OrthoDetectionStatus.Unsupported, Evidence = Array.Empty<string>(), Diagnostics = Array.Empty<RuntimeDiagnostic>() };
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface IPlantRuntimeContextReader { PlantRuntimeContext ReadCurrentContext(); }
|
||||||
|
public interface IOrthoViewportReader { IReadOnlyList<OrthoViewportInfo> ReadViewports(CancellationToken cancellationToken); }
|
||||||
|
|
||||||
|
public enum AnnotationOperationKind { Create, Update, Skip, Conflict, Unsupported }
|
||||||
|
|
||||||
|
public sealed record AnnotationOperationPlan
|
||||||
|
{
|
||||||
|
public required string SourceSnapshotId { get; init; }
|
||||||
|
public required AnnotationOperationKind Kind { get; init; }
|
||||||
|
public string? AnnotationType { get; init; }
|
||||||
|
public string? Text { get; init; }
|
||||||
|
public Point2Dto? Position { get; init; }
|
||||||
|
public double? Rotation { get; init; }
|
||||||
|
public string? ExistingAnnotationId { get; init; }
|
||||||
|
public required IReadOnlyList<string> Reasons { get; init; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed record AnnotationPlanSummary
|
||||||
|
{
|
||||||
|
public int ObjectsExamined { get; init; }
|
||||||
|
public int CreateCount { get; init; }
|
||||||
|
public int UpdateCount { get; init; }
|
||||||
|
public int SkipCount { get; init; }
|
||||||
|
public int ConflictCount { get; init; }
|
||||||
|
public int UnsupportedCount { get; init; }
|
||||||
|
public int WarningCount { get; init; }
|
||||||
|
public int ErrorCount { get; init; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed record AnnotationPlanningRequest
|
||||||
|
{
|
||||||
|
public required string CommandName { get; init; }
|
||||||
|
public required OrthoViewportInfo Viewport { get; init; }
|
||||||
|
public IReadOnlyList<PlantObjectSnapshot> Objects { get; init; } = Array.Empty<PlantObjectSnapshot>();
|
||||||
|
public IReadOnlyList<ExistingAnnotation> Existing { get; init; } = Array.Empty<ExistingAnnotation>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface IAnnotationPlanBuilder { AnnotationPlan Build(AnnotationPlanningRequest request); }
|
||||||
|
public enum PRecAnnotExecutionMode { Smoke, DryRun, Apply }
|
||||||
|
public interface IRuntimeWriteGuard { void EnsureWriteAllowed(string operation); }
|
||||||
|
|
||||||
public sealed record OrthoViewportRef(string DrawingId, string ViewportId);
|
public sealed record OrthoViewportRef(string DrawingId, string ViewportId);
|
||||||
|
|
||||||
public sealed record PlantObjectData
|
public sealed record PlantObjectData
|
||||||
@@ -36,6 +148,11 @@ public sealed record AnnotationIntent
|
|||||||
|
|
||||||
public sealed record AnnotationPlan
|
public sealed record AnnotationPlan
|
||||||
{
|
{
|
||||||
|
public string PlanId { get; init; } = string.Empty;
|
||||||
|
public string CommandName { get; init; } = string.Empty;
|
||||||
|
public IReadOnlyList<AnnotationOperationPlan> Operations { get; init; } = Array.Empty<AnnotationOperationPlan>();
|
||||||
|
public IReadOnlyList<RuntimeDiagnostic> Diagnostics { get; init; } = Array.Empty<RuntimeDiagnostic>();
|
||||||
|
public AnnotationPlanSummary Summary { get; init; } = new();
|
||||||
public required IReadOnlyList<AnnotationIntent> Create { get; init; }
|
public required IReadOnlyList<AnnotationIntent> Create { get; init; }
|
||||||
public required IReadOnlyList<AnnotationIntent> Update { get; init; }
|
public required IReadOnlyList<AnnotationIntent> Update { get; init; }
|
||||||
public required IReadOnlyList<string> Delete { get; init; }
|
public required IReadOnlyList<string> Delete { get; init; }
|
||||||
@@ -58,7 +175,7 @@ public interface IOrthoDrawingContext
|
|||||||
|
|
||||||
public interface IPlantObjectReader
|
public interface IPlantObjectReader
|
||||||
{
|
{
|
||||||
IReadOnlyList<PlantObjectData> ReadObjects(OrthoViewportRef viewport, CancellationToken cancellationToken);
|
IReadOnlyList<PlantObjectSnapshot> ReadObjects(OrthoViewportInfo viewport, CancellationToken cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IAnnotationRepository
|
public interface IAnnotationRepository
|
||||||
|
|||||||
@@ -0,0 +1,109 @@
|
|||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
using PRecAnnot.Abstractions;
|
||||||
|
|
||||||
|
namespace PRecAnnot.Core;
|
||||||
|
|
||||||
|
public sealed class AnnotationPlanBuilder : IAnnotationPlanBuilder
|
||||||
|
{
|
||||||
|
public AnnotationPlan Build(AnnotationPlanningRequest request)
|
||||||
|
{
|
||||||
|
var objects = request.Objects.OrderBy(x => x.SnapshotId, StringComparer.Ordinal).ToArray();
|
||||||
|
var existing = request.Existing.ToDictionary(x => x.StableKey, StringComparer.OrdinalIgnoreCase);
|
||||||
|
var operations = new List<AnnotationOperationPlan>(objects.Length);
|
||||||
|
var creates = new List<AnnotationIntent>();
|
||||||
|
var updates = new List<AnnotationIntent>();
|
||||||
|
var diagnostics = new List<RuntimeDiagnostic>();
|
||||||
|
var seen = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
foreach (var item in objects)
|
||||||
|
{
|
||||||
|
if (!seen.Add(item.SnapshotId))
|
||||||
|
{
|
||||||
|
operations.Add(new AnnotationOperationPlan { SourceSnapshotId = item.SnapshotId, Kind = AnnotationOperationKind.Conflict, Reasons = new[] { "duplicate-snapshot-id" } });
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(item.ObjectClass))
|
||||||
|
{
|
||||||
|
operations.Add(new AnnotationOperationPlan { SourceSnapshotId = item.SnapshotId, Kind = AnnotationOperationKind.Unsupported, Reasons = new[] { "missing-object-class" } });
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var text = string.IsNullOrWhiteSpace(item.LineNumber) ? item.Tag?.Trim() : item.LineNumber!.Trim();
|
||||||
|
if (string.IsNullOrWhiteSpace(text))
|
||||||
|
{
|
||||||
|
operations.Add(new AnnotationOperationPlan { SourceSnapshotId = item.SnapshotId, Kind = AnnotationOperationKind.Skip, Reasons = new[] { "missing-line-number-or-tag" } });
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var position = item.Geometry.PaperPosition;
|
||||||
|
if (position is null)
|
||||||
|
{
|
||||||
|
diagnostics.Add(new RuntimeDiagnostic { Code = "MISSING_GEOMETRY", Message = $"No paper position for {item.SnapshotId}." });
|
||||||
|
}
|
||||||
|
|
||||||
|
var stableKey = $"{request.Viewport.SourceDrawingName ?? string.Empty}:{request.Viewport.Id}:{item.SnapshotId}";
|
||||||
|
var existingAnnotation = existing.TryGetValue(stableKey, out var match) ? match : existing.TryGetValue(item.SnapshotId, out var directMatch) ? directMatch : null;
|
||||||
|
var kind = existingAnnotation is null ? AnnotationOperationKind.Create : AnnotationOperationKind.Update;
|
||||||
|
operations.Add(new AnnotationOperationPlan
|
||||||
|
{
|
||||||
|
SourceSnapshotId = item.SnapshotId,
|
||||||
|
Kind = kind,
|
||||||
|
AnnotationType = "PlantObject",
|
||||||
|
Text = text,
|
||||||
|
Position = position,
|
||||||
|
Rotation = item.Geometry.Rotation,
|
||||||
|
ExistingAnnotationId = existingAnnotation?.StableKey,
|
||||||
|
Reasons = Array.Empty<string>()
|
||||||
|
});
|
||||||
|
|
||||||
|
var intent = new AnnotationIntent
|
||||||
|
{
|
||||||
|
StableKey = stableKey,
|
||||||
|
Text = text,
|
||||||
|
Position = position is { } point ? new AnnotationPoint(point.X, point.Y) : new AnnotationPoint(0, 0),
|
||||||
|
Rotation = item.Geometry.Rotation ?? 0,
|
||||||
|
ClassName = item.ObjectClass,
|
||||||
|
Layer = "PXP_ANNOTATION"
|
||||||
|
};
|
||||||
|
if (kind == AnnotationOperationKind.Create) creates.Add(intent); else updates.Add(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
var summary = new AnnotationPlanSummary
|
||||||
|
{
|
||||||
|
ObjectsExamined = objects.Length,
|
||||||
|
CreateCount = operations.Count(x => x.Kind == AnnotationOperationKind.Create),
|
||||||
|
UpdateCount = operations.Count(x => x.Kind == AnnotationOperationKind.Update),
|
||||||
|
SkipCount = operations.Count(x => x.Kind == AnnotationOperationKind.Skip),
|
||||||
|
ConflictCount = operations.Count(x => x.Kind == AnnotationOperationKind.Conflict),
|
||||||
|
UnsupportedCount = operations.Count(x => x.Kind == AnnotationOperationKind.Unsupported),
|
||||||
|
WarningCount = diagnostics.Count(x => !string.Equals(x.Severity, "Error", StringComparison.OrdinalIgnoreCase)),
|
||||||
|
ErrorCount = diagnostics.Count(x => string.Equals(x.Severity, "Error", StringComparison.OrdinalIgnoreCase))
|
||||||
|
};
|
||||||
|
|
||||||
|
return new AnnotationPlan
|
||||||
|
{
|
||||||
|
PlanId = BuildPlanId(request, objects),
|
||||||
|
CommandName = request.CommandName,
|
||||||
|
Operations = operations,
|
||||||
|
Diagnostics = diagnostics,
|
||||||
|
Summary = summary,
|
||||||
|
Create = creates,
|
||||||
|
Update = updates,
|
||||||
|
Delete = Array.Empty<string>(),
|
||||||
|
SkipReasons = operations.Where(x => x.Kind == AnnotationOperationKind.Skip).SelectMany(x => x.Reasons).ToArray(),
|
||||||
|
ExaminedCount = objects.Length,
|
||||||
|
IsDeterministic = true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string BuildPlanId(AnnotationPlanningRequest request, IReadOnlyList<PlantObjectSnapshot> objects)
|
||||||
|
{
|
||||||
|
var canonical = new StringBuilder(request.CommandName).Append('|').Append(request.Viewport.SourceDrawingName).Append('|').Append(request.Viewport.Id);
|
||||||
|
foreach (var item in objects)
|
||||||
|
canonical.Append('|').Append(item.SnapshotId).Append('|').Append(item.ObjectClass).Append('|').Append(item.Tag).Append('|').Append(item.LineNumber).Append('|').Append(item.Geometry.PaperPosition);
|
||||||
|
var hash = SHA256.HashData(Encoding.UTF8.GetBytes(canonical.ToString()));
|
||||||
|
return "plan-" + Convert.ToHexString(hash)[..24];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,43 +6,21 @@ public sealed class AnnotationRuleEngine : IAnnotationRuleEngine
|
|||||||
{
|
{
|
||||||
public AnnotationPlan BuildPlan(AnnotationRequest request)
|
public AnnotationPlan BuildPlan(AnnotationRequest request)
|
||||||
{
|
{
|
||||||
var existing = request.Existing.ToDictionary(x => x.StableKey, StringComparer.OrdinalIgnoreCase);
|
var objects = request.Objects.Select(item => new PlantObjectSnapshot
|
||||||
var create = new List<AnnotationIntent>();
|
|
||||||
var update = new List<AnnotationIntent>();
|
|
||||||
var skipped = new List<string>();
|
|
||||||
|
|
||||||
foreach (var item in request.Objects.OrderBy(x => x.ObjectId, StringComparer.Ordinal))
|
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(item.LineNumber) && string.IsNullOrWhiteSpace(item.Tag))
|
SnapshotId = item.ObjectId,
|
||||||
{
|
ObjectClass = item.ClassName,
|
||||||
skipped.Add($"{item.ObjectId}:missing-line-number-or-tag");
|
Tag = item.Tag,
|
||||||
continue;
|
LineNumber = item.LineNumber,
|
||||||
}
|
Geometry = new GeometrySnapshot { PaperPosition = new Point2Dto(item.Position.X, item.Position.Y), Rotation = item.Rotation }
|
||||||
|
}).ToArray();
|
||||||
|
|
||||||
var text = BuildText(item);
|
return new AnnotationPlanBuilder().Build(new AnnotationPlanningRequest
|
||||||
var intent = new AnnotationIntent
|
|
||||||
{
|
|
||||||
StableKey = $"{request.Viewport.DrawingId}:{request.Viewport.ViewportId}:{item.ObjectId}",
|
|
||||||
Text = text,
|
|
||||||
Position = item.Position,
|
|
||||||
Rotation = item.Rotation,
|
|
||||||
ClassName = item.ClassName,
|
|
||||||
Layer = "PXP_ANNOTATION"
|
|
||||||
};
|
|
||||||
|
|
||||||
if (existing.ContainsKey(intent.StableKey)) update.Add(intent); else create.Add(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new AnnotationPlan
|
|
||||||
{
|
{
|
||||||
Create = create,
|
CommandName = "PHP_REC_ANNOT",
|
||||||
Update = update,
|
Viewport = new OrthoViewportInfo { Id = request.Viewport.ViewportId, DisplayName = request.Viewport.ViewportId, SourceDrawingName = request.Viewport.DrawingId },
|
||||||
Delete = Array.Empty<string>(),
|
Objects = objects,
|
||||||
SkipReasons = skipped,
|
Existing = request.Existing
|
||||||
ExaminedCount = request.Objects.Count
|
});
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string BuildText(PlantObjectData item) =>
|
|
||||||
string.IsNullOrWhiteSpace(item.LineNumber) ? item.Tag!.Trim() : item.LineNumber.Trim();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
using PRecAnnot.Abstractions;
|
||||||
|
|
||||||
|
namespace PRecAnnot.Core;
|
||||||
|
|
||||||
|
public sealed class ExecutionModeWriteGuard(PRecAnnotExecutionMode mode) : IRuntimeWriteGuard
|
||||||
|
{
|
||||||
|
public void EnsureWriteAllowed(string operation) => throw new InvalidOperationException(mode == PRecAnnotExecutionMode.Apply ? "APPLY_MODE_NOT_IMPLEMENTED" : "SMOKE_WRITE_BLOCKED");
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
using PRecAnnot.Abstractions;
|
||||||
|
|
||||||
|
namespace PRecAnnot.Core;
|
||||||
|
|
||||||
|
public static class OrthoDetectionClassifier
|
||||||
|
{
|
||||||
|
public static OrthoDetectionResult Classify(bool hasPlantProject, bool hasOrthoPart, bool apiConfirmed, bool metadataAmbiguous = false)
|
||||||
|
{
|
||||||
|
if (!hasPlantProject) return Result(OrthoDetectionStatus.NotOrtho, "NO_PLANT_PROJECT", "Active Plant project is absent.");
|
||||||
|
if (metadataAmbiguous) return Result(OrthoDetectionStatus.Ambiguous, "AMBIGUOUS_ORTHO_METADATA", "Plant metadata is insufficient to confirm Ortho.");
|
||||||
|
if (!hasOrthoPart) return Result(OrthoDetectionStatus.Unsupported, "ORTHO_PART_UNAVAILABLE", "Ortho project part is unavailable.");
|
||||||
|
return apiConfirmed
|
||||||
|
? Result(OrthoDetectionStatus.Confirmed, "ORTHO_API_CONFIRMED", "OrthoDocUtils confirmed the active drawing.")
|
||||||
|
: Result(OrthoDetectionStatus.NotOrtho, "ORTHO_API_NEGATIVE", "OrthoDocUtils did not confirm the active drawing.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static OrthoDetectionResult Result(OrthoDetectionStatus status, string code, string message) => new()
|
||||||
|
{
|
||||||
|
Status = status,
|
||||||
|
Evidence = new[] { code },
|
||||||
|
Diagnostics = new[] { new RuntimeDiagnostic { Code = code, Message = message } }
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,17 +1,28 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
using Autodesk.AutoCAD.ApplicationServices;
|
using Autodesk.AutoCAD.ApplicationServices;
|
||||||
using Autodesk.AutoCAD.EditorInput;
|
|
||||||
using Autodesk.AutoCAD.Runtime;
|
using Autodesk.AutoCAD.Runtime;
|
||||||
using Autodesk.ProcessPower.PlantInstance;
|
|
||||||
using Autodesk.Windows;
|
using Autodesk.Windows;
|
||||||
|
using PRecAnnot.Abstractions;
|
||||||
|
using PRecAnnot.Core;
|
||||||
using AcadApplication = Autodesk.AutoCAD.ApplicationServices.Application;
|
using AcadApplication = Autodesk.AutoCAD.ApplicationServices.Application;
|
||||||
|
|
||||||
namespace PRecAnnot.Plant3D2026;
|
namespace PRecAnnot.Plant3D2026;
|
||||||
|
|
||||||
public sealed class EntryPoint : IExtensionApplication
|
public sealed class EntryPoint : IExtensionApplication
|
||||||
{
|
{
|
||||||
public void Initialize() => RibbonIntegration.Register();
|
public void Initialize()
|
||||||
|
{
|
||||||
|
RuntimeDiagnostics.Write("AssemblyInitializeStarted");
|
||||||
|
RibbonIntegration.Register();
|
||||||
|
RuntimeDiagnostics.Write("AssemblyInitializeCompleted");
|
||||||
|
}
|
||||||
|
|
||||||
public void Terminate() { }
|
public void Terminate()
|
||||||
|
{
|
||||||
|
RuntimeDiagnostics.Write("AssemblyTerminateStarted");
|
||||||
|
RibbonIntegration.Terminate();
|
||||||
|
RuntimeDiagnostics.Write("AssemblyTerminateCompleted");
|
||||||
|
}
|
||||||
|
|
||||||
[CommandMethod("PHP_REC_ANNOT")]
|
[CommandMethod("PHP_REC_ANNOT")]
|
||||||
public void PrimaryCommand() => RunDiagnostic("PHP_REC_ANNOT");
|
public void PrimaryCommand() => RunDiagnostic("PHP_REC_ANNOT");
|
||||||
@@ -24,57 +35,161 @@ public sealed class EntryPoint : IExtensionApplication
|
|||||||
|
|
||||||
private static void RunDiagnostic(string commandName)
|
private static void RunDiagnostic(string commandName)
|
||||||
{
|
{
|
||||||
|
var operationId = Guid.NewGuid().ToString("N");
|
||||||
|
var stopwatch = Stopwatch.StartNew();
|
||||||
|
Document? document = null;
|
||||||
|
RuntimeDiagnostics.Write("CommandStarted", operationId: operationId, commandName: commandName);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Document? document = AcadApplication.DocumentManager.MdiActiveDocument;
|
document = AcadApplication.DocumentManager.MdiActiveDocument;
|
||||||
if (document is null)
|
var mode = ParseMode(RuntimeDiagnostics.RuntimeMode);
|
||||||
return;
|
if (mode == PRecAnnotExecutionMode.Apply) throw new InvalidOperationException("APPLY_MODE_NOT_IMPLEMENTED");
|
||||||
|
|
||||||
Editor editor = document.Editor;
|
var context = new PlantRuntimeContextReader().ReadCurrentContext();
|
||||||
if (PlantApplication.CurrentProject is null)
|
var details = new Dictionary<string, object?>
|
||||||
{
|
{
|
||||||
editor.WriteMessage("\nP_Rec_Annot: активный Plant 3D project не найден; DWG не изменён.");
|
["ExecutionMode"] = mode.ToString(),
|
||||||
|
["IsPlantProjectDetected"] = context.HasPlantProject,
|
||||||
|
["IsPlantProjectOpen"] = context.HasPlantProject,
|
||||||
|
["IsOrthoDrawing"] = context.IsOrthoDrawing,
|
||||||
|
["ViewportCount"] = context.Viewports.Count,
|
||||||
|
["DataLinksAvailable"] = DataLinksAvailable(context.HasPlantProject)
|
||||||
|
};
|
||||||
|
|
||||||
|
if (document is null || !context.HasPlantProject)
|
||||||
|
{
|
||||||
|
RuntimeDiagnostics.Write("CommandPreflightCompleted", operationId: operationId, commandName: commandName, resultStatus: "PreflightRejected", document: document, details: details);
|
||||||
|
WriteEditor(document, "\nP_Rec_Annot: Активный Plant 3D-проект не найден; DWG не изменён.");
|
||||||
|
WriteUsage(operationId, commandName, "PreflightRejected", document, details, stopwatch.ElapsedMilliseconds);
|
||||||
|
RuntimeDiagnostics.Write("CommandCompleted", operationId: operationId, commandName: commandName, resultStatus: "PreflightRejected", document: document, details: details);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
editor.WriteMessage($"\nP_Rec_Annot {commandName}: Plant 3D project '{PlantApplication.CurrentProject.Name}' найден; diagnostic-only, DWG не изменён.");
|
if (mode == PRecAnnotExecutionMode.Smoke || !context.IsOrthoDrawing)
|
||||||
|
{
|
||||||
|
var status = context.IsOrthoDrawing ? "PreflightAccepted" : "NotOrtho";
|
||||||
|
RuntimeDiagnostics.Write("CommandPreflightCompleted", operationId: operationId, commandName: commandName, resultStatus: status, document: document, details: details);
|
||||||
|
WriteEditor(document, $"\nP_Rec_Annot {commandName}: проект '{context.ProjectDisplayName}' найден; тип чертежа: {(context.IsOrthoDrawing ? "Ortho" : "NotOrtho")}; DWG не изменён.");
|
||||||
|
WriteUsage(operationId, commandName, status, document, details, stopwatch.ElapsedMilliseconds);
|
||||||
|
RuntimeDiagnostics.Write("CommandCompleted", operationId: operationId, commandName: commandName, resultStatus: status, document: document, details: details);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var builder = new AnnotationPlanBuilder();
|
||||||
|
var plans = new List<AnnotationPlan>();
|
||||||
|
foreach (var viewport in context.Viewports)
|
||||||
|
{
|
||||||
|
var objects = new PlantObjectReader().ReadObjects(viewport, CancellationToken.None);
|
||||||
|
plans.Add(builder.Build(new AnnotationPlanningRequest { CommandName = commandName, Viewport = viewport, Objects = objects }));
|
||||||
|
}
|
||||||
|
|
||||||
|
var summary = new
|
||||||
|
{
|
||||||
|
ObjectsExamined = plans.Sum(x => x.Summary.ObjectsExamined),
|
||||||
|
CreateCount = plans.Sum(x => x.Summary.CreateCount),
|
||||||
|
UpdateCount = plans.Sum(x => x.Summary.UpdateCount),
|
||||||
|
SkipCount = plans.Sum(x => x.Summary.SkipCount),
|
||||||
|
ConflictCount = plans.Sum(x => x.Summary.ConflictCount),
|
||||||
|
UnsupportedCount = plans.Sum(x => x.Summary.UnsupportedCount),
|
||||||
|
WarningCount = plans.Sum(x => x.Summary.WarningCount),
|
||||||
|
ErrorCount = plans.Sum(x => x.Summary.ErrorCount)
|
||||||
|
};
|
||||||
|
details["ObjectsExamined"] = summary.ObjectsExamined;
|
||||||
|
details["PlanCreateCount"] = summary.CreateCount;
|
||||||
|
details["PlanUpdateCount"] = summary.UpdateCount;
|
||||||
|
details["PlanSkipCount"] = summary.SkipCount;
|
||||||
|
details["PlanConflictCount"] = summary.ConflictCount;
|
||||||
|
details["PlanUnsupportedCount"] = summary.UnsupportedCount;
|
||||||
|
details["ErrorCount"] = summary.ErrorCount;
|
||||||
|
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 не изменён.");
|
||||||
|
WriteUsage(operationId, commandName, "DryRunCompleted", document, details, stopwatch.ElapsedMilliseconds);
|
||||||
|
RuntimeDiagnostics.Write("CommandCompleted", operationId: operationId, commandName: commandName, resultStatus: "DryRunCompleted", document: document, details: details);
|
||||||
}
|
}
|
||||||
catch (System.Exception exception)
|
catch (System.Exception exception)
|
||||||
{
|
{
|
||||||
try { AcadApplication.DocumentManager.MdiActiveDocument?.Editor.WriteMessage($"\nP_Rec_Annot: безопасная диагностика завершилась ошибкой: {exception.Message}"); }
|
RuntimeDiagnostics.Write("CommandFailed", "ERROR", operationId, commandName, exception.Message, exception, document);
|
||||||
catch { }
|
WriteUsage(operationId, commandName, exception.Message, document, null, stopwatch.ElapsedMilliseconds, exception);
|
||||||
|
WriteEditor(document, $"\nP_Rec_Annot: безопасная диагностика завершилась ошибкой: {exception.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static PRecAnnotExecutionMode ParseMode(string value) =>
|
||||||
|
value.Equals("Smoke", StringComparison.OrdinalIgnoreCase) ? PRecAnnotExecutionMode.Smoke :
|
||||||
|
value.Equals("Apply", StringComparison.OrdinalIgnoreCase) ? PRecAnnotExecutionMode.Apply : PRecAnnotExecutionMode.DryRun;
|
||||||
|
|
||||||
|
private static bool DataLinksAvailable(bool hasPlantProject)
|
||||||
|
{
|
||||||
|
try { return hasPlantProject && Autodesk.ProcessPower.PlantInstance.PlantApplication.ProjectPart("Piping")?.DataLinksManager is not null; }
|
||||||
|
catch { return false; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void WriteUsage(string operationId, string commandName, string status, Document? document, IReadOnlyDictionary<string, object?>? details, long duration, System.Exception? exception = null)
|
||||||
|
{
|
||||||
|
var eventDetails = new Dictionary<string, object?>
|
||||||
|
{
|
||||||
|
["ObjectsExamined"] = 0, ["AnnotationsCreated"] = 0, ["AnnotationsUpdated"] = 0,
|
||||||
|
["AnnotationsDeleted"] = 0, ["AnnotationsSkipped"] = 0, ["WarningCount"] = 0,
|
||||||
|
["ErrorCount"] = exception is null ? 0 : 1, ["DurationMilliseconds"] = duration
|
||||||
|
};
|
||||||
|
if (details is not null) foreach (var item in details) eventDetails[item.Key] = item.Value;
|
||||||
|
RuntimeDiagnostics.Write("CommandUsageEvent", exception is null ? "INFO" : "ERROR", operationId, commandName, status, exception, document, eventDetails);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void WriteEditor(Document? document, string message)
|
||||||
|
{
|
||||||
|
try { document?.Editor.WriteMessage(message); } catch { }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static class RibbonIntegration
|
internal static class RibbonIntegration
|
||||||
{
|
{
|
||||||
private const string TabId = "PRecAnnot.Plant3D2026";
|
private const string TabId = "PRecAnnot.Plant3D2026";
|
||||||
private const string Command = "PHP_REC_ANNOT ";
|
private const string PanelId = "PRecAnnot.Plant3D2026.Annotations";
|
||||||
|
private const string ButtonId = "PRecAnnot.Plant3D2026.PHP_REC_ANNOT";
|
||||||
|
private static bool deferred;
|
||||||
|
|
||||||
public static void Register()
|
public static void Register()
|
||||||
{
|
{
|
||||||
|
RuntimeDiagnostics.Write("RibbonInitializationStarted");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
RibbonControl? ribbon = ComponentManager.Ribbon;
|
if (ComponentManager.Ribbon is null)
|
||||||
if (ribbon is null) return;
|
|
||||||
|
|
||||||
RibbonTab? tab = ribbon.Tabs.FirstOrDefault(item => string.Equals(item.Id, TabId, StringComparison.OrdinalIgnoreCase));
|
|
||||||
if (tab is null)
|
|
||||||
{
|
{
|
||||||
tab = new RibbonTab { Id = TabId, Title = "Промхимпроект" };
|
if (!deferred) { ComponentManager.ItemInitialized += OnItemInitialized; deferred = true; }
|
||||||
ribbon.Tabs.Add(tab);
|
RuntimeDiagnostics.Write("RibbonInitializationCompleted", resultStatus: "Deferred");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
RegisterNow();
|
||||||
if (tab.Panels.Any(panel => string.Equals(panel.Source?.Title, "Аннотации", StringComparison.OrdinalIgnoreCase))) return;
|
|
||||||
|
|
||||||
RibbonPanelSource source = new() { Title = "Аннотации" };
|
|
||||||
source.Items.Add(new RibbonButton { Text = "Аннотировать", ShowText = true, CommandParameter = Command });
|
|
||||||
tab.Panels.Add(new RibbonPanel { Source = source });
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
// Ribbon is optional; command-line registration remains available.
|
|
||||||
}
|
}
|
||||||
|
catch (System.Exception exception) { RuntimeDiagnostics.Write("RibbonInitializationCompleted", "ERROR", exception: exception, resultStatus: "Failed"); }
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void OnItemInitialized(object? sender, EventArgs args)
|
||||||
|
{
|
||||||
|
if (ComponentManager.Ribbon is null) return;
|
||||||
|
ComponentManager.ItemInitialized -= OnItemInitialized;
|
||||||
|
deferred = false;
|
||||||
|
Register();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void RegisterNow()
|
||||||
|
{
|
||||||
|
var ribbon = ComponentManager.Ribbon!;
|
||||||
|
var tab = ribbon.Tabs.FirstOrDefault(x => string.Equals(x.Id, TabId, StringComparison.OrdinalIgnoreCase));
|
||||||
|
if (tab is null) { tab = new RibbonTab { Id = TabId, Title = "Промхимпроект" }; ribbon.Tabs.Add(tab); }
|
||||||
|
var panel = tab.Panels.FirstOrDefault(x => string.Equals(x.Source?.Id, PanelId, StringComparison.OrdinalIgnoreCase));
|
||||||
|
if (panel is not null) { RuntimeDiagnostics.Write("RibbonAlreadyExists", resultStatus: "AlreadyExists"); RuntimeDiagnostics.Write("RibbonInitializationCompleted", resultStatus: "AlreadyExists"); return; }
|
||||||
|
var source = new RibbonPanelSource { Id = PanelId, Title = "Аннотации" };
|
||||||
|
source.Items.Add(new RibbonButton { Id = ButtonId, Text = "Аннотировать", ShowText = true, CommandParameter = "PHP_REC_ANNOT " });
|
||||||
|
tab.Panels.Add(new RibbonPanel { Source = source });
|
||||||
|
RuntimeDiagnostics.Write("RibbonInitializationCompleted", resultStatus: "Created");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Terminate()
|
||||||
|
{
|
||||||
|
if (!deferred) return;
|
||||||
|
ComponentManager.ItemInitialized -= OnItemInitialized;
|
||||||
|
deferred = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,10 @@
|
|||||||
<Reference Include="AcCoreMgd"><HintPath>$(AutoCAD2026ManagedDir)\AcCoreMgd.dll</HintPath><Private>false</Private><CopyLocal>false</CopyLocal></Reference>
|
<Reference Include="AcCoreMgd"><HintPath>$(AutoCAD2026ManagedDir)\AcCoreMgd.dll</HintPath><Private>false</Private><CopyLocal>false</CopyLocal></Reference>
|
||||||
<Reference Include="AdWindows"><HintPath>$(AutoCAD2026ManagedDir)\AdWindows.dll</HintPath><Private>false</Private><CopyLocal>false</CopyLocal></Reference>
|
<Reference Include="AdWindows"><HintPath>$(AutoCAD2026ManagedDir)\AdWindows.dll</HintPath><Private>false</Private><CopyLocal>false</CopyLocal></Reference>
|
||||||
<Reference Include="PnPDataLinks"><HintPath>$(AutoCAD2026ManagedDir)\PnPDataLinks.dll</HintPath><Private>false</Private><CopyLocal>false</CopyLocal></Reference>
|
<Reference Include="PnPDataLinks"><HintPath>$(AutoCAD2026ManagedDir)\PnPDataLinks.dll</HintPath><Private>false</Private><CopyLocal>false</CopyLocal></Reference>
|
||||||
|
<Reference Include="PnPDataObjects"><HintPath>$(AutoCAD2026ManagedDir)\PnPDataObjects.dll</HintPath><Private>false</Private><CopyLocal>false</CopyLocal></Reference>
|
||||||
<Reference Include="PnPProjectManagerMgd"><HintPath>$(Plant3D2026ManagedDir)\PnPProjectManagerMgd.dll</HintPath><Private>false</Private><CopyLocal>false</CopyLocal></Reference>
|
<Reference Include="PnPProjectManagerMgd"><HintPath>$(Plant3D2026ManagedDir)\PnPProjectManagerMgd.dll</HintPath><Private>false</Private><CopyLocal>false</CopyLocal></Reference>
|
||||||
<Reference Include="PnP3dObjectsMgd"><HintPath>$(Plant3D2026ManagedDir)\PnP3dObjectsMgd.dll</HintPath><Private>false</Private><CopyLocal>false</CopyLocal></Reference>
|
<Reference Include="PnP3dObjectsMgd"><HintPath>$(Plant3D2026ManagedDir)\PnP3dObjectsMgd.dll</HintPath><Private>false</Private><CopyLocal>false</CopyLocal></Reference>
|
||||||
|
<Reference Include="PnP3dOrthoProjectPart"><HintPath>$(Plant3D2026ManagedDir)\PnP3dOrthoProjectPart.dll</HintPath><Private>false</Private><CopyLocal>false</CopyLocal></Reference>
|
||||||
|
<Reference Include="PnPDwg2dDef"><HintPath>$(Plant3D2026ManagedDir)\PnPDwg2dDef.dll</HintPath><Private>false</Private><CopyLocal>false</CopyLocal></Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -0,0 +1,206 @@
|
|||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
using Autodesk.AutoCAD.ApplicationServices;
|
||||||
|
using Autodesk.ProcessPower.DataLinks;
|
||||||
|
using Autodesk.ProcessPower.P3dProjectParts;
|
||||||
|
using Autodesk.ProcessPower.PlantInstance;
|
||||||
|
using Autodesk.ProcessPower.ProjectManager;
|
||||||
|
using PRecAnnot.Abstractions;
|
||||||
|
using AcadApplication = Autodesk.AutoCAD.ApplicationServices.Application;
|
||||||
|
|
||||||
|
namespace PRecAnnot.Plant3D2026;
|
||||||
|
|
||||||
|
internal sealed class PlantRuntimeContextReader : IPlantRuntimeContextReader
|
||||||
|
{
|
||||||
|
public PlantRuntimeContext ReadCurrentContext()
|
||||||
|
{
|
||||||
|
var document = AcadApplication.DocumentManager.MdiActiveDocument;
|
||||||
|
if (document is null)
|
||||||
|
{
|
||||||
|
return Empty(false, false, "NO_ACTIVE_DOCUMENT", "Активный документ отсутствует.");
|
||||||
|
}
|
||||||
|
|
||||||
|
PlantProject? project;
|
||||||
|
try { project = PlantApplication.CurrentProject; }
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
return Empty(true, false, "PLANT_PROJECT_READ_FAILED", exception.GetType().Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (project is null)
|
||||||
|
{
|
||||||
|
return Empty(true, false, "NO_PLANT_PROJECT", "Активный Plant 3D-проект не найден.");
|
||||||
|
}
|
||||||
|
|
||||||
|
OrthoProject? orthoProject;
|
||||||
|
try { orthoProject = PlantApplication.ProjectPart("Ortho") as OrthoProject; }
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
return Empty(true, true, "ORTHO_PROJECT_PART_READ_FAILED", exception.GetType().Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (orthoProject is null)
|
||||||
|
{
|
||||||
|
return Empty(true, true, "ORTHO_PROJECT_PART_UNAVAILABLE", "Ortho project part недоступен.", OrthoDetectionStatus.Unsupported, "ProjectPart(Ortho)");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string resolvedPath;
|
||||||
|
var isOrtho = OrthoDocUtils.IsValidOrthoDrawing(document.Name, orthoProject, out resolvedPath);
|
||||||
|
if (!isOrtho)
|
||||||
|
{
|
||||||
|
return Empty(true, true, "NOT_ORTHO_DRAWING", "OrthoDocUtils.IsValidOrthoDrawing вернул false.", OrthoDetectionStatus.NotOrtho, "Ortho project part", "OrthoDocUtils.IsValidOrthoDrawing=false");
|
||||||
|
}
|
||||||
|
|
||||||
|
var viewports = new PlantOrthoViewportReader(orthoProject, document.Name).ReadViewports(CancellationToken.None);
|
||||||
|
return new PlantRuntimeContext
|
||||||
|
{
|
||||||
|
HasActiveDocument = true,
|
||||||
|
HasPlantProject = true,
|
||||||
|
IsOrthoDrawing = true,
|
||||||
|
DrawingName = Path.GetFileName(document.Name),
|
||||||
|
ProjectDisplayName = project.Name,
|
||||||
|
Viewports = viewports,
|
||||||
|
Diagnostics = Array.Empty<RuntimeDiagnostic>(),
|
||||||
|
Detection = new OrthoDetectionResult
|
||||||
|
{
|
||||||
|
Status = OrthoDetectionStatus.Confirmed,
|
||||||
|
Evidence = new[] { "ProjectPart(Ortho)", "OrthoDocUtils.IsValidOrthoDrawing=true", "DwgSheetDefinitions" },
|
||||||
|
Diagnostics = Array.Empty<RuntimeDiagnostic>()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
return Empty(true, true, "ORTHO_DETECTION_FAILED", exception.GetType().Name, OrthoDetectionStatus.Failed, "ProjectPart(Ortho)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PlantRuntimeContext Empty(bool hasDocument, bool hasProject, string code, string message, OrthoDetectionStatus status = OrthoDetectionStatus.NotOrtho, params string[] evidence) => new()
|
||||||
|
{
|
||||||
|
HasActiveDocument = hasDocument,
|
||||||
|
HasPlantProject = hasProject,
|
||||||
|
IsOrthoDrawing = false,
|
||||||
|
Diagnostics = new[] { new RuntimeDiagnostic { Code = code, Message = message } },
|
||||||
|
Detection = new OrthoDetectionResult { Status = status, Evidence = evidence, Diagnostics = new[] { new RuntimeDiagnostic { Code = code, Message = message } } }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed class PlantOrthoViewportReader : IOrthoViewportReader
|
||||||
|
{
|
||||||
|
private readonly OrthoProject project;
|
||||||
|
private readonly string drawingName;
|
||||||
|
|
||||||
|
public PlantOrthoViewportReader(OrthoProject project, string drawingName)
|
||||||
|
{
|
||||||
|
this.project = project;
|
||||||
|
this.drawingName = Path.GetFileName(drawingName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IReadOnlyList<OrthoViewportInfo> ReadViewports(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var result = new List<OrthoViewportInfo>();
|
||||||
|
foreach (var sheet in project.DwgSheetDefinitions.AsArray())
|
||||||
|
{
|
||||||
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
if (!string.Equals(Path.GetFileName(sheet.DwgName), drawingName, StringComparison.OrdinalIgnoreCase)) continue;
|
||||||
|
|
||||||
|
foreach (var view in sheet.DwgViewDefs.AsArray())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
var id = StableId(sheet.DwgGuid.ToString(), view.ViewName);
|
||||||
|
result.Add(new OrthoViewportInfo
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
DisplayName = view.ViewName,
|
||||||
|
CenterX = view.CenterPoint.X,
|
||||||
|
CenterY = view.CenterPoint.Y,
|
||||||
|
Width = view.ViewWidth,
|
||||||
|
Height = view.ViewHeight,
|
||||||
|
Scale = view.ViewScale,
|
||||||
|
TwistAngle = 0,
|
||||||
|
IsOn = true,
|
||||||
|
IsLocked = false,
|
||||||
|
SourceDrawingName = sheet.DwgName,
|
||||||
|
ViewName = view.ViewName
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// One malformed view must not abort the remaining read-only analysis.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.OrderByDescending(x => x.CenterY).ThenBy(x => x.CenterX).ThenBy(x => x.Id, StringComparer.Ordinal).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string StableId(string sheetId, string viewName)
|
||||||
|
{
|
||||||
|
var hash = SHA256.HashData(Encoding.UTF8.GetBytes(sheetId + "|" + viewName));
|
||||||
|
return "vp-" + Convert.ToHexString(hash)[..20];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed class PlantObjectReader : IPlantObjectReader
|
||||||
|
{
|
||||||
|
public IReadOnlyList<PlantObjectSnapshot> ReadObjects(OrthoViewportInfo viewport, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var document = AcadApplication.DocumentManager.MdiActiveDocument;
|
||||||
|
if (document is null) return Array.Empty<PlantObjectSnapshot>();
|
||||||
|
|
||||||
|
DataLinksManager? dataLinks;
|
||||||
|
try { dataLinks = PlantApplication.ProjectPart("Piping")?.DataLinksManager; }
|
||||||
|
catch { return Array.Empty<PlantObjectSnapshot>(); }
|
||||||
|
if (dataLinks is null) return Array.Empty<PlantObjectSnapshot>();
|
||||||
|
|
||||||
|
var snapshots = new List<PlantObjectSnapshot>();
|
||||||
|
foreach (var rowId in dataLinks.SelectAcPpRowIds(document.Database))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
var className = dataLinks.GetObjectClassname(rowId);
|
||||||
|
var properties = dataLinks.GetAllProperties(rowId, true)
|
||||||
|
.GroupBy(x => x.Key, StringComparer.OrdinalIgnoreCase)
|
||||||
|
.ToDictionary(x => x.Key, x => x.Last().Value, StringComparer.OrdinalIgnoreCase);
|
||||||
|
string? Value(params string[] names) => properties.FirstOrDefault(x => names.Any(name => string.Equals(name, x.Key, StringComparison.OrdinalIgnoreCase))).Value;
|
||||||
|
snapshots.Add(new PlantObjectSnapshot
|
||||||
|
{
|
||||||
|
SnapshotId = StableId(Path.GetFileName(document.Name), rowId, className),
|
||||||
|
ObjectClass = className ?? string.Empty,
|
||||||
|
Tag = Value("Tag", "TAG"),
|
||||||
|
LineNumber = Value("Line Number", "LineNumber", "LINENUMBER"),
|
||||||
|
SupportNumber = Value("Support Number", "SupportNumber"),
|
||||||
|
EquipmentNumber = Value("Equipment Number", "EquipmentNumber"),
|
||||||
|
Geometry = new GeometrySnapshot(),
|
||||||
|
Properties = properties.ToDictionary(x => x.Key, x => (string?)x.Value, StringComparer.OrdinalIgnoreCase),
|
||||||
|
Diagnostics = new[] { "GEOMETRY_NOT_MAPPED" }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// Keep the read path best-effort; no write operation is attempted.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return snapshots.OrderBy(x => x.SnapshotId, StringComparer.Ordinal).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string StableId(string drawingName, int rowId, string? className)
|
||||||
|
{
|
||||||
|
var hash = SHA256.HashData(Encoding.UTF8.GetBytes($"{drawingName}|{rowId}|{className}"));
|
||||||
|
return "obj-" + Convert.ToHexString(hash)[..24];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed class RuntimeWriteGuard(PRecAnnotExecutionMode mode) : IRuntimeWriteGuard
|
||||||
|
{
|
||||||
|
public void EnsureWriteAllowed(string operation)
|
||||||
|
{
|
||||||
|
if (mode == PRecAnnotExecutionMode.Apply) throw new InvalidOperationException("APPLY_MODE_NOT_IMPLEMENTED");
|
||||||
|
throw new InvalidOperationException("SMOKE_WRITE_BLOCKED");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
using System.Text.Json;
|
||||||
|
using Autodesk.AutoCAD.ApplicationServices;
|
||||||
|
using Autodesk.ProcessPower.PlantInstance;
|
||||||
|
|
||||||
|
namespace PRecAnnot.Plant3D2026;
|
||||||
|
|
||||||
|
internal static class RuntimeDiagnostics
|
||||||
|
{
|
||||||
|
private static readonly object Gate = new();
|
||||||
|
private static readonly string LogDirectory = Path.Combine(
|
||||||
|
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
||||||
|
"Promhimproekt", "PRecAnnot2026", "Logs");
|
||||||
|
|
||||||
|
public static string RuntimeMode => Environment.GetEnvironmentVariable("P_REC_ANNOT_RUNTIME_MODE") ?? "Normal";
|
||||||
|
|
||||||
|
public static void Write(
|
||||||
|
string eventType,
|
||||||
|
string level = "INFO",
|
||||||
|
string? operationId = null,
|
||||||
|
string? commandName = null,
|
||||||
|
string? resultStatus = null,
|
||||||
|
System.Exception? exception = null,
|
||||||
|
Document? document = null,
|
||||||
|
IReadOnlyDictionary<string, object?>? details = null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var payload = new Dictionary<string, object?>(StringComparer.Ordinal)
|
||||||
|
{
|
||||||
|
["Timestamp"] = DateTimeOffset.UtcNow,
|
||||||
|
["Level"] = level,
|
||||||
|
["OperationId"] = operationId,
|
||||||
|
["EventType"] = eventType,
|
||||||
|
["AssemblyVersion"] = typeof(EntryPoint).Assembly.GetName().Version?.ToString(),
|
||||||
|
["AutoCADVersion"] = typeof(Document).Assembly.GetName().Version?.ToString(),
|
||||||
|
["PlantVersion"] = typeof(PlantApplication).Assembly.GetName().Version?.ToString(),
|
||||||
|
["ProcessId"] = Environment.ProcessId,
|
||||||
|
["ThreadId"] = Environment.CurrentManagedThreadId,
|
||||||
|
["ApartmentState"] = Thread.CurrentThread.GetApartmentState().ToString(),
|
||||||
|
["ActiveDocumentName"] = SafeDocumentName(document),
|
||||||
|
["CommandName"] = commandName,
|
||||||
|
["ResultStatus"] = resultStatus,
|
||||||
|
["ExceptionType"] = exception?.GetType().FullName,
|
||||||
|
["ExceptionMessage"] = exception?.Message,
|
||||||
|
["StackTrace"] = level.Equals("ERROR", StringComparison.OrdinalIgnoreCase) ? exception?.StackTrace : null,
|
||||||
|
["RuntimeMode"] = RuntimeMode
|
||||||
|
};
|
||||||
|
|
||||||
|
if (details is not null)
|
||||||
|
foreach (var item in details) payload[item.Key] = item.Value;
|
||||||
|
|
||||||
|
var line = JsonSerializer.Serialize(payload) + Environment.NewLine;
|
||||||
|
lock (Gate)
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(LogDirectory);
|
||||||
|
File.AppendAllText(Path.Combine(LogDirectory, "runtime.jsonl"), line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// Runtime diagnostics must never prevent AutoCAD command execution.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string? SafeDocumentName(Document? document)
|
||||||
|
{
|
||||||
|
try { return document is null ? null : Path.GetFileName(document.Name); }
|
||||||
|
catch { return null; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed class SmokeWriteBlockedException() : InvalidOperationException("SMOKE_WRITE_BLOCKED");
|
||||||
|
|
||||||
|
internal static class SmokeGuard
|
||||||
|
{
|
||||||
|
public static bool IsSmoke => string.Equals(RuntimeDiagnostics.RuntimeMode, "Smoke", StringComparison.OrdinalIgnoreCase);
|
||||||
|
public static void EnsureReadOnly() { if (IsSmoke) throw new SmokeWriteBlockedException(); }
|
||||||
|
}
|
||||||
@@ -86,4 +86,61 @@ public sealed class FoundationTests
|
|||||||
var references = typeof(AnnotationRequest).Assembly.GetReferencedAssemblies();
|
var references = typeof(AnnotationRequest).Assembly.GetReferencedAssemblies();
|
||||||
Assert.DoesNotContain(references, x => x.Name?.StartsWith("Autodesk", StringComparison.OrdinalIgnoreCase) == true || x.Name?.StartsWith("Ac", StringComparison.OrdinalIgnoreCase) == true);
|
Assert.DoesNotContain(references, x => x.Name?.StartsWith("Autodesk", StringComparison.OrdinalIgnoreCase) == true || x.Name?.StartsWith("Ac", StringComparison.OrdinalIgnoreCase) == true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact] public void OrthoDetection_NoPlantProject_ReturnsNotOrtho() => Assert.Equal(OrthoDetectionStatus.NotOrtho, OrthoDetectionClassifier.Classify(false, false, false).Status);
|
||||||
|
[Fact] public void OrthoDetection_NormalDwg_ReturnsNotOrtho() => Assert.Equal(OrthoDetectionStatus.NotOrtho, OrthoDetectionClassifier.Classify(true, true, false).Status);
|
||||||
|
[Fact] public void OrthoDetection_ConfirmedOrtho_ReturnsConfirmed() => Assert.Equal(OrthoDetectionStatus.Confirmed, OrthoDetectionClassifier.Classify(true, true, true).Status);
|
||||||
|
[Fact] public void OrthoDetection_AmbiguousMetadata_ReturnsAmbiguous() => Assert.Equal(OrthoDetectionStatus.Ambiguous, OrthoDetectionClassifier.Classify(true, true, false, true).Status);
|
||||||
|
|
||||||
|
[Fact] public void AnnotationPlan_InputOrderDoesNotChangeResult()
|
||||||
|
{
|
||||||
|
var viewport = new OrthoViewportInfo { Id = "vp", DisplayName = "A", SourceDrawingName = "test.dwg" };
|
||||||
|
var objects = new[] { Snapshot("b", "Pipe", "L-2"), Snapshot("a", "Valve", "V-1") };
|
||||||
|
var builder = new AnnotationPlanBuilder();
|
||||||
|
var first = builder.Build(new AnnotationPlanningRequest { CommandName = "PHP_REC_ANNOT", Viewport = viewport, Objects = objects });
|
||||||
|
var second = builder.Build(new AnnotationPlanningRequest { CommandName = "PHP_REC_ANNOT", Viewport = viewport, Objects = objects.Reverse().ToArray() });
|
||||||
|
Assert.Equal(first.PlanId, second.PlanId);
|
||||||
|
Assert.Equal(first.Summary, second.Summary);
|
||||||
|
Assert.Equal(first.Operations.Select(x => x.SourceSnapshotId), second.Operations.Select(x => x.SourceSnapshotId));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact] public void AnnotationPlan_MissingLineNumber_IsSkipped()
|
||||||
|
{
|
||||||
|
var plan = Build(Snapshot("a", "Pipe", null, null));
|
||||||
|
Assert.Equal(AnnotationOperationKind.Skip, Assert.Single(plan.Operations).Kind);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact] public void AnnotationPlan_UnsupportedObject_IsMarkedUnsupported()
|
||||||
|
{
|
||||||
|
var plan = Build(Snapshot("a", "", "L-1"));
|
||||||
|
Assert.Equal(AnnotationOperationKind.Unsupported, Assert.Single(plan.Operations).Kind);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact] public void AnnotationPlan_ExistingAnnotation_BecomesUpdate()
|
||||||
|
{
|
||||||
|
var viewport = new OrthoViewportInfo { Id = "vp", DisplayName = "A", SourceDrawingName = "test.dwg" };
|
||||||
|
var item = Snapshot("a", "Pipe", "L-1");
|
||||||
|
var plan = new AnnotationPlanBuilder().Build(new AnnotationPlanningRequest { CommandName = "PHP_REC_ANNOT", Viewport = viewport, Objects = new[] { item }, Existing = new[] { new ExistingAnnotation("a", "old", new(0, 0)) } });
|
||||||
|
Assert.Equal(AnnotationOperationKind.Update, Assert.Single(plan.Operations).Kind);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact] public void AnnotationPlan_DuplicateCandidate_BecomesConflict()
|
||||||
|
{
|
||||||
|
var plan = Build(Snapshot("a", "Pipe", "L-1"), Snapshot("a", "Pipe", "L-1"));
|
||||||
|
Assert.Equal(AnnotationOperationKind.Conflict, plan.Operations.Last().Kind);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact] public void ApplyMode_IsBlocked() => Assert.Throws<InvalidOperationException>(() => new ExecutionModeWriteGuard(PRecAnnotExecutionMode.Apply).EnsureWriteAllowed("test"));
|
||||||
|
|
||||||
|
[Fact] public void DryRunPath_HasNoForWriteOperations()
|
||||||
|
{
|
||||||
|
var source = File.ReadAllText(Path.Combine(ProjectRoot, "src", "PRecAnnot.Plant3D2026", "PlantReadPath.cs"));
|
||||||
|
Assert.DoesNotContain("ForWrite", source);
|
||||||
|
Assert.DoesNotContain("AppendEntity", source);
|
||||||
|
Assert.DoesNotContain("AcceptChanges", source);
|
||||||
|
Assert.DoesNotContain("SetProperties", source);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static AnnotationPlan Build(params PlantObjectSnapshot[] objects) => new AnnotationPlanBuilder().Build(new AnnotationPlanningRequest { CommandName = "PHP_REC_ANNOT", Viewport = new OrthoViewportInfo { Id = "vp", DisplayName = "A", SourceDrawingName = "test.dwg" }, Objects = objects });
|
||||||
|
private static PlantObjectSnapshot Snapshot(string id, string type, string? line, string? tag = "TAG") => new() { SnapshotId = id, ObjectClass = type, LineNumber = line, Tag = tag, Geometry = new GeometrySnapshot { PaperPosition = new Point2Dto(1, 2) } };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user