Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Sketch dimensions accept explicit expressions
Claude6cda4d95dae3
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentIntelliDraftTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentIntelliDraftTests.csindex 73d840c4..b53c7dba 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentIntelliDraftTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentIntelliDraftTests.cs@@ -165,6 +165,27 @@ public class FirmamentIntelliDraftTestsAssert.Equal(Math.PI, arcs.Sum(a => Math.Abs(a.Sweep)), 10);}+ [Fact]+ public void ADimensionCanBeWrittenAsAnExplicitExpression()+ {+ var draft = new Draft(); draft.Add(new("layout", Name: "layout"));+ draft.Add(new("rectangle", draft.Id("layout"), "outer", Width: 60, Height: 40));+ draft.Add(new("rectangle", draft.Id("layout"), "inner", Width: 20, Height: 10));+ string Width(string shape) => draft.View.Shapes.Single(s => s.Name == shape).Controls.Single(c => c.Label == "Width").Id;+ void Edit(string control, string expression) => draft.Source = FirmamentSketchService.Edit(draft.Source, "draft.firmament", "0",+ new("constructionDimensions", Changes: [new(control, 0, expression)])).Text;+ Edit(Width("inner"), "outerWidth / 2");+ Assert.Contains("Static innerWidth: Length = outerWidth / 2", draft.Source);+ var inner = draft.View.Shapes.Single(s => s.Name == "inner").Controls.Single(c => c.Label == "Width");+ Assert.Equal(30, inner.Value, 9); Assert.False(inner.Editable);+ Edit(Width("outer"), "80");+ Assert.Equal(40, draft.View.Shapes.Single(s => s.Name == "inner").Controls.Single(c => c.Label == "Width").Value, 9);+ var before = draft.Source;+ Assert.Throws<FirmamentLanguageEditException>(() => Edit(Width("outer"), "outerHeight + }"));+ Assert.ThrowsAny<Exception>(() => Edit(Width("outer"), "nowhere * 2"));+ Assert.Equal(before, draft.Source);+ }+private static string Flat(string source) => System.Text.RegularExpressions.Regex.Replace(source, @"\s+", " ");private sealed class Draft{diff --git a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentSketch.cs b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentSketch.csindex 4717a3e5..e96fb3b7 100644--- a/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentSketch.cs+++ b/Aetheris.Kernel.Firmament/FirmamentV2/FirmamentSketch.cs@@ -22,7 +22,9 @@ public sealed record FirmamentSketch(string Version, string Document, string Rev{public FirmamentDraftConstruction? Construction { get; init; }}-public sealed record FirmamentSketchChange(string Control, double Value);+/// <summary>A dimension edit: a number in the control's unit, or an explicit source expression+/// (`rect2Width * 2`) that makes the relationship part of the source.</summary>+public sealed record FirmamentSketchChange(string Control, double Value, string? Expression = null);public sealed record FirmamentSketchEditRequest(string Kind, string? Node = null, string? Shape = null,IReadOnlyList<FirmamentSketchChange>? Changes = null, double X = 0, double Y = 0,string? Reference = null, string? Anchor = null, double Diameter = 4, double Width = 80, double Height = 50,@@ -267,11 +269,24 @@ public static class FirmamentSketchServiceforeach (var change in changes){if (!targets.TryGetValue(change.Control, out var target)) throw Refuse("sketch-dimension-readonly", "The dimension is driven by an expression or is no longer available. Edit its inputs instead.");- if (!double.IsFinite(change.Value)) throw Refuse("sketch-number-invalid", "A dimension must be finite.");var control = view.Shapes.SelectMany(s => s.Controls).Single(c => c.Id == change.Control);var key = (target.Node, target.Field);if (!replacements.TryGetValue(key, out var list)) replacements[key] = list = [];- var value = change.Value.ToString("R", CultureInfo.InvariantCulture) + control.Unit;+ string value;+ if (change.Expression is { } authored && authored.Trim().Length > 0)+ {+ var expression = authored.Trim();+ if (double.TryParse(expression, NumberStyles.Float, CultureInfo.InvariantCulture, out var plain)) expression = plain.ToString("R", CultureInfo.InvariantCulture) + control.Unit;+ var probe = FirmamentSyntaxParser.Parse($"Static probe: Length = {expression}");+ if (probe.Diagnostics.Any(d => d.Severity is "error" or "fatal") || expression.IndexOfAny(['{', '}', ';', '\n']) >= 0)+ throw Refuse("sketch-expression-invalid", $"'{authored.Trim()}' is not one expression.");+ value = expression;+ }+ else+ {+ if (!double.IsFinite(change.Value)) throw Refuse("sketch-number-invalid", "A dimension must be finite.");+ value = change.Value.ToString("R", CultureInfo.InvariantCulture) + control.Unit;+ }if (list.Any(p => p.Expression.Span == target.Expression.Span && p.Value != value))throw Refuse("sketch-shared-parameter-conflict", "These dimensions share a parameter and requested different values. Edit the parameter once.");list.Add((target.Expression, value));diff --git a/Aetheris.Web.Runtime/sdk/src/index.d.ts b/Aetheris.Web.Runtime/sdk/src/index.d.tsindex 75ee5bb2..eb0e42aa 100644--- a/Aetheris.Web.Runtime/sdk/src/index.d.ts+++ b/Aetheris.Web.Runtime/sdk/src/index.d.ts@@ -103,7 +103,7 @@ export interface SketchProjection {shapes: readonly SketchShape[]; diagnostics: readonly { severity: string; code: string; message: string; span: { start: number; length: number } | null }[];validationLevel: 'ProfileResolvedNotBuilt' | 'Unresolved';}-export interface SketchEditRequest { kind: 'dimensions' | 'create' | 'opening' | 'construction' | 'constructionDimensions'; construction?: DraftOperation; node?: string | null; shape?: string; changes?: readonly { control: string; value: number }[]; x?: number; y?: number; reference?: string; anchor?: string; diameter?: number; width?: number; height?: number }+export interface SketchEditRequest { kind: 'dimensions' | 'create' | 'opening' | 'construction' | 'constructionDimensions'; construction?: DraftOperation; node?: string | null; shape?: string; changes?: readonly { control: string; value: number; /** An explicit source expression instead of a number, e.g. `rect1Width / 2`. */ expression?: string }[]; x?: number; y?: number; reference?: string; anchor?: string; diameter?: number; width?: number; height?: number }export interface LanguageHover { readonly document: string; readonly revision: string; readonly start: number; readonly length: number; readonly title: string; readonly description: string }export interface LanguageFormat { readonly document: string; readonly revision: string; readonly text: string; readonly changed: boolean }diff --git a/docs/public/firmament/sketcher.md b/docs/public/firmament/sketcher.mdindex 9a9c5e39..e86f36b7 100644--- a/docs/public/firmament/sketcher.md+++ b/docs/public/firmament/sketcher.md@@ -31,7 +31,16 @@ zoom; Alt snaps to 0.1 mm.- The rounded menu also draws `SmoothRoundedRect2` (continuous-curvaturecorners) with its `cornerExtent`.+While drawing, a click snaps to a named point, a line's midpoint, a point on a+curve, or the level of (or the line under) a named point, and a marker says which.+Snaps only place points; nothing remembers them. Alt draws freely.+Selected shapes show their dimensions on the canvas; click one to type a value.+A value can also be an expression over parameters, such as `outerWidth / 2`+(parameter names complete as you type); it is written to source, so the dimension+becomes driven and shows in parentheses. **Align … to** moves the selected shape so+its edges or centre line up with another shape, which stays put; this too is+written as plain coordinates.Values driven by an expression are dashed and read-only. Resizing a shape whoseedge is lined up with another shape's edge asks once whether to move that shapetoo; nothing is stored, and drags never ask. Rename and Delete act on the selected@@ -44,10 +53,13 @@ picking and alignment, but their source and any traced Profile remain intact.Temporary alignment guides help placement while dragging; they do not linkshapes. Hold Alt to bypass alignment.-Choose **Trace** and click the edges of the outline on the canvas: rectangle+Choose **Trace** and click inside an enclosed area to trace it in one step, or click+the edges of the outline on the canvas: rectanglesides, lines and arcs between named points, across shapes. Click order anddirection do not matter; the outline is written counter-clockwise. The sidebar-shows whether the outline is closed. **Use this outline** writes the Profile;+shows whether the outline is closed. The canvas marks open ends (nothing continues+from them) and ends that meet only by position (two named points that happen to+coincide, which an edit could pull apart). **Use this outline** writes the Profile;**Use whole shape outline** traces one closed shape. Picks are also availableas a list under **Edges as a list**.