Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Implement M6c topology-backed selector counting for expect_selectable

Yuechen Liee1bed1ee08c
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs
index 1fd6cce9..dd959e5d 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs
@@ -118,7 +118,7 @@ public sealed class FirmamentPrimitiveExecutionTests
Assert.True(result.Compilation.IsSuccess);
var artifact = result.Compilation.Value;
- Assert.Equal("firmament-topology-exists-validation-executed", artifact.ArtifactKind);
+ Assert.Equal("firmament-topology-selectable-validation-executed", artifact.ArtifactKind);
Assert.Equal(2, artifact.PrimitiveLoweringPlan!.Primitives.Count);
Assert.Equal(2, artifact.PrimitiveLoweringPlan.Booleans.Count);
Assert.Single(artifact.PrimitiveLoweringPlan.SkippedOps);
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentScaffoldTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentScaffoldTests.cs
index a22fd063..71435551 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentScaffoldTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentScaffoldTests.cs
@@ -37,7 +37,7 @@ public sealed class FirmamentScaffoldTests
Assert.True(result.Compilation.IsSuccess);
var artifact = result.Compilation.Value;
- Assert.Equal("firmament-topology-exists-validation-executed", artifact.ArtifactKind);
+ Assert.Equal("firmament-topology-selectable-validation-executed", artifact.ArtifactKind);
Assert.NotNull(artifact.ParsedDocument);
Assert.Equal("1", artifact.ParsedDocument!.Firmament.Version);
Assert.Equal("demo", artifact.ParsedDocument.Model.Name);
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentValidationExecutionTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentValidationExecutionTests.cs
index 04275bc0..0a66a212 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentValidationExecutionTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentValidationExecutionTests.cs
@@ -45,41 +45,48 @@ public sealed class FirmamentValidationExecutionTests
Assert.True(validation.IsExecuted);
Assert.False(validation.IsSuccess);
Assert.Equal("Selector 'sphere.edges' resolved to no topology elements.", validation.Reason);
-
}
[Fact]
- public void Compile_Executes_ExpectSelectable_One_With_Count_One()
+ public void Compile_Executes_ExpectSelectable_With_TopologyBacked_Counts_As_Successes()
{
- var result = CompileFixture("testdata/firmament/fixtures/m6a-valid-expect-selectable-one-count1.firmament");
+ var result = CompileFixture("testdata/firmament/fixtures/m6c-valid-selectable-count.firmament");
Assert.True(result.Compilation.IsSuccess);
- var validation = Assert.Single(result.Compilation.Value.ValidationExecutionResult!.Validations);
- Assert.True(validation.IsExecuted);
- Assert.True(validation.IsSuccess);
+ var validations = result.Compilation.Value.ValidationExecutionResult!.Validations;
+ Assert.Equal(4, validations.Count);
+ Assert.All(validations, validation =>
+ {
+ Assert.True(validation.IsExecuted);
+ Assert.True(validation.IsSuccess);
+ Assert.Null(validation.Reason);
+ });
}
[Fact]
- public void Compile_Executes_ExpectSelectable_One_With_Count_Greater_Than_One_As_Failure()
+ public void Compile_Executes_ExpectSelectable_With_Count_Mismatch_As_Deterministic_Failure()
{
- var result = CompileFixture("testdata/firmament/fixtures/m6a-invalid-expect-selectable-one-count2.firmament");
+ var result = CompileFixture("testdata/firmament/fixtures/m6c-invalid-selectable-count-mismatch.firmament");
Assert.True(result.Compilation.IsSuccess);
- var validation = Assert.Single(result.Compilation.Value.ValidationExecutionResult!.Validations);
- Assert.True(validation.IsExecuted);
- Assert.False(validation.IsSuccess);
- Assert.Contains("incompatible", validation.Reason, StringComparison.Ordinal);
- }
+ var validations = result.Compilation.Value.ValidationExecutionResult!.Validations;
+ Assert.Equal(2, validations.Count);
- [Fact]
- public void Compile_Executes_ExpectSelectable_Many_With_Plural_Count()
- {
- var result = CompileFixture("testdata/firmament/fixtures/m6a-valid-expect-selectable-many-count2.firmament");
+ Assert.Collection(
+ validations,
+ first =>
+ {
+ Assert.True(first.IsExecuted);
+ Assert.False(first.IsSuccess);
+ Assert.Equal("Selector 'base.side_faces' resolved to 6 elements but 3 were expected.", first.Reason);
+ },
+ second =>
+ {
+ Assert.True(second.IsExecuted);
+ Assert.False(second.IsSuccess);
+ Assert.Equal("Selector 'sphere.surface' resolved to 1 elements but 2 were expected.", second.Reason);
+ });
- Assert.True(result.Compilation.IsSuccess);
- var validation = Assert.Single(result.Compilation.Value.ValidationExecutionResult!.Validations);
- Assert.True(validation.IsExecuted);
- Assert.True(validation.IsSuccess);
}
[Fact]
diff --git a/Aetheris.Kernel.Firmament/Diagnostics/FirmamentDiagnosticCodes.cs b/Aetheris.Kernel.Firmament/Diagnostics/FirmamentDiagnosticCodes.cs
index 80d2aa05..e1517ac3 100644
--- a/Aetheris.Kernel.Firmament/Diagnostics/FirmamentDiagnosticCodes.cs
+++ b/Aetheris.Kernel.Firmament/Diagnostics/FirmamentDiagnosticCodes.cs
@@ -31,6 +31,7 @@ public static class FirmamentDiagnosticCodes
public static readonly FirmamentDiagnosticCode ValidationTargetInvalidSelectorPortToken = new($"{FirmamentDiagnosticConventions.ReferencePrefix}-0005");
public static readonly FirmamentDiagnosticCode ValidationTargetSelectorPortNotAllowedForFeatureKind = new($"{FirmamentDiagnosticConventions.ReferencePrefix}-0006");
public static readonly FirmamentDiagnosticCode ValidationTargetSelectorResolvedEmpty = new($"{FirmamentDiagnosticConventions.ReferencePrefix}-0007");
+ public static readonly FirmamentDiagnosticCode ValidationTargetSelectableCountMismatch = new($"{FirmamentDiagnosticConventions.ReferencePrefix}-0008");
public static readonly FirmamentDiagnosticCode SelectorPlaceholder = new($"{FirmamentDiagnosticConventions.SelectorPrefix}-0001");
public static readonly FirmamentDiagnosticCode SchemaPlaceholder = new($"{FirmamentDiagnosticConventions.SchemaPrefix}-0001");
public static readonly FirmamentDiagnosticCode LoweringPlaceholder = new($"{FirmamentDiagnosticConventions.LoweringPrefix}-0001");
diff --git a/Aetheris.Kernel.Firmament/Execution/FirmamentValidationExecutor.cs b/Aetheris.Kernel.Firmament/Execution/FirmamentValidationExecutor.cs
index 8d48534e..5c7400a6 100644
--- a/Aetheris.Kernel.Firmament/Execution/FirmamentValidationExecutor.cs
+++ b/Aetheris.Kernel.Firmament/Execution/FirmamentValidationExecutor.cs
@@ -32,7 +32,7 @@ internal static class FirmamentValidationExecutor
var result = entry.KnownKind switch
{
FirmamentKnownOpKind.ExpectExists => ExecuteExpectExists(index, entry, target, featureBodies, diagnostics),
- FirmamentKnownOpKind.ExpectSelectable => ExecuteExpectSelectable(index, entry, target),
+ FirmamentKnownOpKind.ExpectSelectable => ExecuteExpectSelectable(index, entry, target, featureBodies, diagnostics),
FirmamentKnownOpKind.ExpectManifold => new FirmamentExecutedValidation(
OpIndex: index,
Kind: entry.KnownKind,
@@ -124,7 +124,12 @@ internal static class FirmamentValidationExecutor
: $"Selector '{target}' resolved to no topology elements.");
}
- private static FirmamentExecutedValidation ExecuteExpectSelectable(int opIndex, FirmamentParsedOpEntry entry, string? target)
+ private static FirmamentExecutedValidation ExecuteExpectSelectable(
+ int opIndex,
+ FirmamentParsedOpEntry entry,
+ string? target,
+ IReadOnlyDictionary<string, Aetheris.Kernel.Core.Brep.BrepBody> featureBodies,
+ ICollection<KernelDiagnostic> diagnostics)
{
if (IsFeatureIdTarget(entry))
{
@@ -138,9 +143,12 @@ internal static class FirmamentValidationExecutor
}
if (entry.ClassifiedFields is null
- || !entry.ClassifiedFields.TryGetValue("selectorCardinality", out var selectorCardinality)
+ || !entry.ClassifiedFields.TryGetValue("selectorResultKind", out var selectorResultKind)
+ || !Enum.TryParse<FirmamentSelectorResultKind>(selectorResultKind, out var resultKind)
|| !entry.RawFields.TryGetValue("count", out var countRaw)
- || !int.TryParse(countRaw, NumberStyles.Integer, CultureInfo.InvariantCulture, out var requestedCount))
+ || !int.TryParse(countRaw, NumberStyles.Integer, CultureInfo.InvariantCulture, out var requestedCount)
+ || string.IsNullOrWhiteSpace(target)
+ || !FirmamentSelectorResolver.TryResolve(target, featureBodies, resultKind, out var resolution))
{
return new FirmamentExecutedValidation(
OpIndex: opIndex,
@@ -148,13 +156,16 @@ internal static class FirmamentValidationExecutor
Target: target,
IsExecuted: true,
IsSuccess: false,
- Reason: "expect_selectable missing executable contract-cardinality inputs.");
+ Reason: "expect_selectable selector target could not be resolved to executable topology at M6c.");
}
- var isSuccess = string.Equals(selectorCardinality, FirmamentSelectorCardinality.One.ToString(), StringComparison.Ordinal)
- ? requestedCount == 1
- : string.Equals(selectorCardinality, FirmamentSelectorCardinality.Many.ToString(), StringComparison.Ordinal)
- && requestedCount > 1;
+ var isSuccess = resolution.Count == requestedCount;
+ if (!isSuccess)
+ {
+ diagnostics.Add(CreateDiagnostic(
+ FirmamentDiagnosticCodes.ValidationTargetSelectableCountMismatch,
+ $"Selector '{target}' resolved to {resolution.Count.ToString(CultureInfo.InvariantCulture)} elements but {requestedCount.ToString(CultureInfo.InvariantCulture)} were expected."));
+ }
return new FirmamentExecutedValidation(
OpIndex: opIndex,
@@ -164,7 +175,7 @@ internal static class FirmamentValidationExecutor
IsSuccess: isSuccess,
Reason: isSuccess
? null
- : $"expect_selectable count '{requestedCount}' is incompatible with selector cardinality '{selectorCardinality}' at M6a contract level.");
+ : $"Selector '{target}' resolved to {resolution.Count.ToString(CultureInfo.InvariantCulture)} elements but {requestedCount.ToString(CultureInfo.InvariantCulture)} were expected.");
}
private static IReadOnlyDictionary<string, Aetheris.Kernel.Core.Brep.BrepBody> BuildFeatureBodyMap(FirmamentPrimitiveExecutionResult primitiveExecutionResult)
diff --git a/Aetheris.Kernel.Firmament/FirmamentCompilationArtifact.cs b/Aetheris.Kernel.Firmament/FirmamentCompilationArtifact.cs
index 3117cb6a..4100c038 100644
--- a/Aetheris.Kernel.Firmament/FirmamentCompilationArtifact.cs
+++ b/Aetheris.Kernel.Firmament/FirmamentCompilationArtifact.cs
@@ -5,7 +5,7 @@ using Aetheris.Kernel.Firmament.ParsedModel;
namespace Aetheris.Kernel.Firmament;
public sealed record FirmamentCompilationArtifact(
- string ArtifactKind = "firmament-topology-exists-validation-executed",
+ string ArtifactKind = "firmament-topology-selectable-validation-executed",
FirmamentParsedDocument? ParsedDocument = null,
FirmamentPrimitiveLoweringPlan? PrimitiveLoweringPlan = null,
FirmamentPrimitiveExecutionResult? PrimitiveExecutionResult = null,
diff --git a/Aetheris.Kernel.Firmament/FirmamentCompiler.cs b/Aetheris.Kernel.Firmament/FirmamentCompiler.cs
index 4cc669d8..18e7e3c2 100644
--- a/Aetheris.Kernel.Firmament/FirmamentCompiler.cs
+++ b/Aetheris.Kernel.Firmament/FirmamentCompiler.cs
@@ -80,7 +80,7 @@ public sealed class FirmamentCompiler
return new FirmamentCompileResult(
KernelResult<FirmamentCompilationArtifact>.Success(
new FirmamentCompilationArtifact(
- ArtifactKind: "firmament-topology-exists-validation-executed",
+ ArtifactKind: "firmament-topology-selectable-validation-executed",
ParsedDocument: validatedDocument,
PrimitiveLoweringPlan: primitiveLoweringResult.Value,
PrimitiveExecutionResult: primitiveExecutionResult.Value,
diff --git a/testdata/firmament/fixtures/m6c-invalid-selectable-count-mismatch.firmament b/testdata/firmament/fixtures/m6c-invalid-selectable-count-mismatch.firmament
new file mode 100644
index 00000000..b0f6e054
--- /dev/null
+++ b/testdata/firmament/fixtures/m6c-invalid-selectable-count-mismatch.firmament
@@ -0,0 +1,27 @@
+firmament:
+ version: 1
+
+model:
+ name: m6c_invalid_selectable_count_mismatch
+ units: mm
+
+ops[4]:
+ -
+ op: box
+ id: base
+ size[3]:
+ 10
+ 8
+ 6
+ -
+ op: sphere
+ id: sphere
+ radius: 4
+ -
+ op: expect_selectable
+ target: base.side_faces
+ count: 3
+ -
+ op: expect_selectable
+ target: sphere.surface
+ count: 2
diff --git a/testdata/firmament/fixtures/m6c-valid-selectable-count.firmament b/testdata/firmament/fixtures/m6c-valid-selectable-count.firmament
new file mode 100644
index 00000000..d4c9a5b8
--- /dev/null
+++ b/testdata/firmament/fixtures/m6c-valid-selectable-count.firmament
@@ -0,0 +1,50 @@
+firmament:
+ version: 1
+
+model:
+ name: m6c_valid_selectable_count
+ units: mm
+
+ops[8]:
+ -
+ op: box
+ id: base
+ size[3]:
+ 10
+ 8
+ 6
+ -
+ op: sphere
+ id: sphere
+ radius: 4
+ -
+ op: cylinder
+ id: cyl
+ radius: 2
+ height: 5
+ -
+ op: add
+ id: join
+ to: base
+ with:
+ op: box
+ size[3]:
+ 1
+ 1
+ 1
+ -
+ op: expect_selectable
+ target: base.side_faces
+ count: 6
+ -
+ op: expect_selectable
+ target: sphere.surface
+ count: 1
+ -
+ op: expect_selectable
+ target: cyl.circular_edges
+ count: 3
+ -
+ op: expect_selectable
+ target: join.edges
+ count: 12