feat: drawing_add_diametral_dimension — диаметральный размер на виде (API7)
Веха 2D-ЧЕРТЁЖ, инкремент 4. DrawingService.AddDiametralDimensionAsync: (ISymbols2DContainer)view.DiametralDimensions.Add → Xc/Yc/Radius/Angle(рад) + AutoNominalValue → Update → Valid → NominalValue (= диаметр 2R). angle в градусах (DimensionAngles.ToRadians). Новый инструмент drawing_add_diametral_dimension. Рефактор по ревью Codex: извлечён RequireSymbols2DContainer(viewNumber) (общий для линейных/диаметральных размеров); AutoNominalValue выставляется явно (как у линейного); DimensionType — COM-дефолт; ToRadians — чистый helper с unit-тестом. Валидаторы: RequirePositiveRadius (новый). Тесты: +10 unit (ToRadians, RequirePositiveRadius), +4 integration (DrawingDiametralTests: диаметр=2R, адресация вида, radius<=0, нет видов). Итого 141 unit + 76 integration = 217. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -21,4 +21,16 @@ public sealed class DimensionOrientationsTests
|
||||
// ToKompas (→ ksLineDimensionOrientationEnum) намеренно НЕ покрыт unit-тестом: тестовый проект
|
||||
// не ссылается на Kompas6Constants (граница проекта). Маппинг тривиален и проверяется интеграцией
|
||||
// (horizontal → |X2-X1|, vertical → |Y2-Y1|).
|
||||
|
||||
[Theory]
|
||||
[InlineData(0, 0)]
|
||||
[InlineData(90, Math.PI / 2)]
|
||||
[InlineData(180, Math.PI)]
|
||||
[InlineData(-45, -Math.PI / 4)]
|
||||
public void ToRadians_converts_degrees(double degrees, double expected)
|
||||
=> Assert.Equal(expected, DimensionAngles.ToRadians(degrees), 9);
|
||||
|
||||
[Fact]
|
||||
public void ToRadians_throws_on_non_finite()
|
||||
=> Assert.Throws<ArgumentException>(() => DimensionAngles.ToRadians(double.NaN));
|
||||
}
|
||||
|
||||
@@ -68,4 +68,16 @@ public sealed class DrawingValidationTests
|
||||
Assert.Throws<ArgumentException>(() => DrawingValidation.RequireDistinctPoints(10, 20, 10, 20));
|
||||
Assert.Null(Record.Exception(() => DrawingValidation.RequireDistinctPoints(0, 0, 40, 0)));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(-5)]
|
||||
[InlineData(double.NaN)]
|
||||
[InlineData(double.PositiveInfinity)]
|
||||
public void RequirePositiveRadius_throws_on_non_positive_or_non_finite(double radius)
|
||||
=> Assert.Throws<ArgumentOutOfRangeException>(() => DrawingValidation.RequirePositiveRadius(radius));
|
||||
|
||||
[Fact]
|
||||
public void RequirePositiveRadius_accepts_positive()
|
||||
=> Assert.Null(Record.Exception(() => DrawingValidation.RequirePositiveRadius(15)));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
using Kompas.Mcp.Core.Documents;
|
||||
using Kompas.Mcp.Core.Drawings;
|
||||
using Kompas.Mcp.Core.Modeling;
|
||||
|
||||
namespace Kompas.Mcp.Tests.Integration;
|
||||
|
||||
/// <summary>Интеграция: диаметральный размер на виде (API7 ISymbols2DContainer.DiametralDimensions).</summary>
|
||||
[Trait("Category", "Integration")]
|
||||
[Collection(KompasCollection.Name)]
|
||||
public sealed class DrawingDiametralTests : IntegrationTestBase
|
||||
{
|
||||
private readonly DocumentService _docs;
|
||||
private readonly PartModeler _modeler;
|
||||
private readonly DrawingService _drawing;
|
||||
|
||||
public DrawingDiametralTests(KompasFixture fx) : base(fx)
|
||||
{
|
||||
_docs = new DocumentService(fx.Session, fx.Dispatcher);
|
||||
_modeler = new PartModeler(fx.Session, fx.Dispatcher);
|
||||
_drawing = new DrawingService(fx.Session, fx.Dispatcher);
|
||||
}
|
||||
|
||||
private async Task<string> BuildAndSaveBoxAsync()
|
||||
{
|
||||
var path = TestPaths.NewFile(".m3d");
|
||||
await _docs.CreateAsync(KompasDocumentType.Part);
|
||||
try
|
||||
{
|
||||
var s = await _modeler.OpenSketchAsync(BasePlane.XOY);
|
||||
await _modeler.AddRectangleAsync(s, 0, 0, 40, 30);
|
||||
await _modeler.CloseSketchAsync(s);
|
||||
await _modeler.ExtrudeAsync(s, depth: 20);
|
||||
await _modeler.RebuildAsync();
|
||||
await _docs.SaveAsAsync(path);
|
||||
}
|
||||
finally { await _docs.CloseAsync(save: false); }
|
||||
return path;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Diametral_dimension_value_is_diameter()
|
||||
{
|
||||
var partFile = await BuildAndSaveBoxAsync();
|
||||
await _docs.CreateAsync(KompasDocumentType.Drawing);
|
||||
try
|
||||
{
|
||||
await _drawing.CreateStandardViewsAsync(partFile, 1.0, 100, 150);
|
||||
// Радиус 15 → диаметр 30.
|
||||
var r = await _drawing.AddDiametralDimensionAsync(viewNumber: 0, xc: 10, yc: 10, radius: 15, angleDeg: 45);
|
||||
Assert.InRange(r.Value, 29.9, 30.1);
|
||||
}
|
||||
finally { await _docs.CloseAsync(save: false); }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Targets_specific_view_and_increments_diametral_count()
|
||||
{
|
||||
var partFile = await BuildAndSaveBoxAsync();
|
||||
await _docs.CreateAsync(KompasDocumentType.Drawing);
|
||||
try
|
||||
{
|
||||
var views = await _drawing.CreateStandardViewsAsync(partFile, 1.0, 100, 150);
|
||||
var targetNumber = views.ViewNumbers[1];
|
||||
|
||||
var before = await _drawing.GetViewDiametralDimensionCountAsync(targetNumber);
|
||||
var r = await _drawing.AddDiametralDimensionAsync(targetNumber, xc: 5, yc: 5, radius: 8, angleDeg: 30);
|
||||
var after = await _drawing.GetViewDiametralDimensionCountAsync(targetNumber);
|
||||
|
||||
Assert.Equal(targetNumber, r.ViewNumber);
|
||||
Assert.Equal(before + 1, after);
|
||||
Assert.InRange(r.Value, 15.9, 16.1); // Ø = 2·8
|
||||
}
|
||||
finally { await _docs.CloseAsync(save: false); }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Non_positive_radius_throws()
|
||||
{
|
||||
var partFile = await BuildAndSaveBoxAsync();
|
||||
await _docs.CreateAsync(KompasDocumentType.Drawing);
|
||||
try
|
||||
{
|
||||
await _drawing.CreateStandardViewsAsync(partFile, 1.0, 100, 150);
|
||||
await Assert.ThrowsAsync<ArgumentOutOfRangeException>(() =>
|
||||
_drawing.AddDiametralDimensionAsync(viewNumber: 0, xc: 0, yc: 0, radius: 0, angleDeg: 0));
|
||||
}
|
||||
finally { await _docs.CloseAsync(save: false); }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task No_views_throws()
|
||||
{
|
||||
await _docs.CreateAsync(KompasDocumentType.Drawing);
|
||||
try
|
||||
{
|
||||
await Assert.ThrowsAsync<InvalidOperationException>(() =>
|
||||
_drawing.AddDiametralDimensionAsync(viewNumber: 0, xc: 0, yc: 0, radius: 10, angleDeg: 0));
|
||||
}
|
||||
finally { await _docs.CloseAsync(save: false); }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user