feat: activate p-rec-annot line-number edit commands
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
using Autodesk.AutoCAD.ApplicationServices;
|
||||
using Autodesk.AutoCAD.DatabaseServices;
|
||||
using Autodesk.AutoCAD.EditorInput;
|
||||
using PRecAnnot.Abstractions;
|
||||
using PRecAnnot.Core;
|
||||
using AcadApplication = Autodesk.AutoCAD.ApplicationServices.Application;
|
||||
|
||||
namespace PRecAnnot.Plant3D2026;
|
||||
|
||||
internal static class LineNumberEditCommands
|
||||
{
|
||||
public static void Renumber()
|
||||
{
|
||||
Run("PXP-ESN", (document, editor, selected) =>
|
||||
{
|
||||
var start = editor.GetInteger(new PromptIntegerOptions("\nВведите новое начальное значение маркера: ") { LowerLimit = 1 });
|
||||
if (start.Status != PromptStatus.OK) return null;
|
||||
var rows = new LineNumberOwnedAnnotationReader().ReadList(document, selected);
|
||||
return new LineNumberAnnotationWriter().ApplyEdits(document, LineNumberEditPlanner.Renumber(rows, start.Value));
|
||||
}, "Выберите блок списка номеров линий: ");
|
||||
}
|
||||
|
||||
public static void EditText()
|
||||
{
|
||||
Run("PXP-ELN", (document, editor, selected) =>
|
||||
{
|
||||
var rows = new LineNumberOwnedAnnotationReader().ReadList(document, selected);
|
||||
var marker = editor.GetInteger(new PromptIntegerOptions("\nВведите номер редактируемого маркера: ") { LowerLimit = 1 });
|
||||
if (marker.Status != PromptStatus.OK) return null;
|
||||
var row = rows.SingleOrDefault(value => value.MarkerNumber == marker.Value) ?? throw new InvalidOperationException("LINE_NUMBER_ROW_NOT_FOUND");
|
||||
var text = editor.GetString(new PromptStringOptions("\nВведите новый текст номера линии: ") { AllowSpaces = true });
|
||||
if (text.Status != PromptStatus.OK) return null;
|
||||
return new LineNumberAnnotationWriter().ApplyEdits(document, [LineNumberEditPlanner.EditText(row, text.StringResult)]);
|
||||
}, "Выберите блок списка номеров линий: ");
|
||||
}
|
||||
|
||||
public static void ResetMarkerPosition()
|
||||
{
|
||||
Run("PXP-RMP", (document, _, selected) =>
|
||||
{
|
||||
var row = new LineNumberOwnedAnnotationReader().ReadMarker(document, selected);
|
||||
var configured = LineNumberRuntimeConfigurationReader.Read().Assets.Marker.Texts[0].Position;
|
||||
return new LineNumberAnnotationWriter().ApplyEdits(document, [LineNumberEditPlanner.ResetMarkerAttributePosition(row, configured)]);
|
||||
}, "Выберите маркер номера линии: ");
|
||||
}
|
||||
|
||||
private static void Run(string command, Func<Document, Editor, ObjectId, LineNumberApplyResult?> operation, string prompt)
|
||||
{
|
||||
var document = AcadApplication.DocumentManager.MdiActiveDocument;
|
||||
if (document is null) return;
|
||||
try
|
||||
{
|
||||
var options = new PromptEntityOptions($"\n{prompt}");
|
||||
options.SetRejectMessage("\nТребуется вхождение блока PXP-LN.");
|
||||
options.AddAllowedClass(typeof(BlockReference), true);
|
||||
var selected = document.Editor.GetEntity(options);
|
||||
if (selected.Status != PromptStatus.OK) return;
|
||||
var result = operation(document, document.Editor, selected.ObjectId);
|
||||
if (result is null) return;
|
||||
document.Editor.WriteMessage($"\n{command}: updated={result.Updated}; unchanged={result.Unchanged}.");
|
||||
RuntimeDiagnostics.Write("LineNumberEditCompleted", commandName: command, resultStatus: result.Updated > 0 ? "Updated" : "AlreadyCurrent", document: document,
|
||||
details: new Dictionary<string, object?> { ["Updated"] = result.Updated, ["AlreadyCurrent"] = result.Unchanged });
|
||||
}
|
||||
catch (System.Exception exception)
|
||||
{
|
||||
RuntimeDiagnostics.Write("LineNumberEditFailed", "ERROR", commandName: command, resultStatus: exception.Message, exception: exception, document: document);
|
||||
document.Editor.WriteMessage($"\n{command}: {exception.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user