diff --git a/src/Kompas.Mcp.Core/Drawings/DrawingService.cs b/src/Kompas.Mcp.Core/Drawings/DrawingService.cs index faa94ec..bbacfa3 100644 --- a/src/Kompas.Mcp.Core/Drawings/DrawingService.cs +++ b/src/Kompas.Mcp.Core/Drawings/DrawingService.cs @@ -118,7 +118,9 @@ public sealed class DrawingService fmt.Format = PaperFormats.ToKompas(format); if (format == PaperFormat.User) { - // Для пользовательского ориентация задаётся соотношением width/height — VerticalOrientation не трогаем. + // Для пользовательского КОМПАС САМ выводит VerticalOrientation из соотношения width/height + // (W>H → альбомная, H>W → книжная) и игнорирует заданный флаг, W/H не свопает — проверено + // спайком. Поэтому VerticalOrientation не трогаем; read-back ниже даёт верную ориентацию. fmt.FormatWidth = width; fmt.FormatHeight = height; } diff --git a/src/Kompas.Mcp.Core/Drawings/DrawingValidation.cs b/src/Kompas.Mcp.Core/Drawings/DrawingValidation.cs index ab4108c..d7b176e 100644 --- a/src/Kompas.Mcp.Core/Drawings/DrawingValidation.cs +++ b/src/Kompas.Mcp.Core/Drawings/DrawingValidation.cs @@ -63,15 +63,20 @@ public static class DrawingValidation { if (format == PaperFormat.User) { - if (!double.IsFinite(width) || width <= 0 || !double.IsFinite(height) || height <= 0) + if (!double.IsFinite(width) || width <= 0) throw new ArgumentOutOfRangeException(nameof(width), - "Для format=user ширина и высота должны быть конечными и > 0."); + "Для format=user ширина должна быть конечной и > 0."); + if (!double.IsFinite(height) || height <= 0) + throw new ArgumentOutOfRangeException(nameof(height), + "Для format=user высота должна быть конечной и > 0."); } else if (width != 0 || height != 0) { + // Точное имя нарушившего параметра (а не всегда width). + var offender = width != 0 ? nameof(width) : nameof(height); throw new ArgumentException( "Ширина/высота задаются только для format=user; для стандартного формата размеры авто (передайте 0).", - nameof(width)); + offender); } } diff --git a/tests/Kompas.Mcp.Tests/Integration/DrawingSheetFormatTests.cs b/tests/Kompas.Mcp.Tests/Integration/DrawingSheetFormatTests.cs index f5a3b66..4edf39a 100644 --- a/tests/Kompas.Mcp.Tests/Integration/DrawingSheetFormatTests.cs +++ b/tests/Kompas.Mcp.Tests/Integration/DrawingSheetFormatTests.cs @@ -48,15 +48,48 @@ public sealed class DrawingSheetFormatTests : IntegrationTestBase } [Fact] - public async Task User_format_with_dimensions() + public async Task A4_landscape_swaps_dimensions() { await _docs.CreateAsync(KompasDocumentType.Drawing); try { + var r = await _drawing.SetSheetFormatAsync(PaperFormat.A4, landscape: true, width: 0, height: 0); + Assert.Equal("A4", r.Format); + Assert.InRange(r.Width, 296.5, 297.5); // своп: альбомная A4 = 297×210 + Assert.InRange(r.Height, 209.5, 210.5); + Assert.True(r.Landscape); + } + finally { await _docs.CloseAsync(save: false); } + } + + [Fact] + public async Task User_landscape_dimensions_derive_orientation() + { + await _docs.CreateAsync(KompasDocumentType.Drawing); + try + { + // 500×300 (W>H) → КОМПАС выводит альбомную ориентацию (Landscape=true), W/H литеральны. var r = await _drawing.SetSheetFormatAsync(PaperFormat.User, landscape: false, width: 500, height: 300); Assert.Equal("User", r.Format); Assert.InRange(r.Width, 499.5, 500.5); Assert.InRange(r.Height, 299.5, 300.5); + Assert.True(r.Landscape); // ориентация выведена из соотношения сторон (не из флага landscape=false) + } + finally { await _docs.CloseAsync(save: false); } + } + + [Fact] + public async Task User_portrait_dimensions_derive_orientation() + { + await _docs.CreateAsync(KompasDocumentType.Drawing); + try + { + // 300×500 (H>W) → книжная (Landscape=false). + var r = await _drawing.SetSheetFormatAsync(PaperFormat.User, landscape: true, width: 300, height: 500); + Assert.Equal("User", r.Format); + Assert.InRange(r.Width, 299.5, 300.5); + Assert.InRange(r.Height, 499.5, 500.5); + Assert.False(r.Landscape); // landscape=true проигнорирован — ориентация из сторон } finally { await _docs.CloseAsync(save: false); } } @@ -97,6 +130,18 @@ public sealed class DrawingSheetFormatTests : IntegrationTestBase finally { await _docs.CloseAsync(save: false); } } + [Fact] + public async Task Nonpositive_sheet_number_throws() + { + await _docs.CreateAsync(KompasDocumentType.Drawing); + try + { + await Assert.ThrowsAsync(() => + _drawing.SetSheetFormatAsync(PaperFormat.A4, landscape: false, width: 0, height: 0, sheetNumber: 0)); + } + finally { await _docs.CloseAsync(save: false); } + } + [Fact] public async Task Active_document_not_drawing_throws() { diff --git a/tests/Kompas.Mcp.Tests/PaperFormatsTests.cs b/tests/Kompas.Mcp.Tests/PaperFormatsTests.cs index db232fc..8195575 100644 --- a/tests/Kompas.Mcp.Tests/PaperFormatsTests.cs +++ b/tests/Kompas.Mcp.Tests/PaperFormatsTests.cs @@ -10,6 +10,7 @@ public sealed class PaperFormatsTests [InlineData("a3", PaperFormat.A3)] [InlineData(" A2 ", PaperFormat.A2)] [InlineData("a0", PaperFormat.A0)] + [InlineData("A1", PaperFormat.A1)] [InlineData("A5", PaperFormat.A5)] [InlineData("user", PaperFormat.User)] [InlineData("USER", PaperFormat.User)]