Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ MCP, tests) · `verified` (done + golden/e2e coverage + reviewed on macOS).

| ID | Feature | Status | Module | Test | MCP tool | Notes |
|---|---|---|---|---|---|---|
| `7.12/measure` | Measure | in progress | ForgeKernel | Tests/ForgeCommandsTests/MeasurementTests.swift, Tests/ForgeUITests/MeasureWorkflowTests.swift | measure | bodies/faces/edges/vertices: size, radius, coordinates, minimum distance, closest points and XYZ deltas; angles/max/normal-distance modes pending |
| `7.12/measure` | Measure | in progress | ForgeCommands / ForgeUI | Tests/ForgeCommandsTests/MeasurementTests.swift, Tests/ForgeUITests/MeasureWorkflowTests.swift | measure | bodies/faces/edges/vertices: size, radius, coordinates, minimum distance, closest points and XYZ deltas; explicit angle mode for planar faces/straight edges (mixed pairs, unoriented 0–90°); curved angles/max/normal-distance modes pending |
| `7.12/measure/all-modes` | ↳ all modes | not started | ForgeModel | — | — | |
| `7.12/measure/point-to-point` | ↳ point-to-point | not started | ForgeModel | — | — | |
| `7.12/measure/min-max-normal` | ↳ min/max/normal | not started | ForgeModel | — | — | |
Expand Down
30 changes: 30 additions & 0 deletions PROGRESS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
# Progress

## Session 13 — 2026-10-02 — Planar face and straight edge measurement angles

- `query.measure` and MCP `measure` accept `mode: "angle"` for two planar faces or
straight edges, including mixed pairs, and return `angle_degrees`. Default single
entity properties and minimum distance behavior remain unchanged.
- Angles use unoriented supporting planes/lines in 0–90°: parallel or antiparallel
geometry gives 0°, perpendicular planes/lines give 90°, and a line normal to a plane
gives 90°. Stable atan2 formulas cover near-parallel/perpendicular cases. Curved
faces/edges, degenerate edges, bodies and vertices fail with structured errors.
- macOS and shared Windows/Linux PropertyManagers offer a mode picker with scope and
degree labels. Mode changes clear old results; async results check both selection and
requested mode before display. Persistent names keep the existing single-entity rules.
- Added analytic cardinal/oblique/near-boundary angles, reversed directions, mixed-pair
symmetry, persistent face/edge references after rebuild, explicit unsupported-geometry
errors (including spherical degenerate edges), read-only/default-distance checks,
desktop mode switching and a real MCP angle/error subprocess workflow.

Validation: isolated Apple Silicon checkout with Xcode/Swift **6.4** and locally built
pinned **OCCT 8.0.1**, limited to three build jobs. Native app + test build and all
**384 Swift tests** pass; all **33 golden models** and **six MCP subprocess workflows**
pass. CI validates Linux headless (including **three packaging regressions** and shared
Windows frontend type checking), CachyOS, native macOS and Windows builds/runtime
checks. Matrix synchronization and whitespace checks pass. No app windows were opened
on the live desktop. Local macOS packaging checks pass 2/3: the existing Windows fetch
script's GNU `find -printf` requirement prevents its DLL-path fixture from passing with
BSD find; those unrelated files are unchanged and all three pass in Linux CI.

Remaining scope: curved/tangent/directed/reflex angle measurements, maximum/normal
and projected distances, sketch-entity measurements and broader SolidWorks parity.

## Session 12 — 2026-09-30 — Selected contours, planar limits and selection filters

- Added `sketch.regions` with stable complete-curve selectors, holes, nested islands,
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@ accounts for all 1,000 matrix entries and documents remaining work.

**Measure** accepts one face, edge, vertex or body for its size/coordinates, or two
for minimum distance and closest points. The MCP `measure` tool uses `from` and an
optional `to`; results use millimeters. Angle and maximum-distance modes remain pending.
optional `to`; sizes and distances use millimeters. Choose **Angle (0–90°)** for two
planar faces or straight edges, including mixed pairs. MCP `measure` and `query.measure`
accept `mode: "angle"` and return `angle_degrees`. Angles use unoriented supporting
planes/lines: parallel or antiparallel geometry gives 0°, perpendicular geometry gives
90°; a line normal to a plane gives 90°. Curved faces/edges, degenerate edges, bodies
and vertices produce explicit unsupported-geometry errors in angle mode. Omit `mode`
or use `"distance"` for the existing behavior. Maximum/normal-distance modes remain pending.

Use the body tree or **Features → Visibility** to hide/show bodies, isolate a selection,
exit isolation or show all bodies. Hidden bodies are excluded from drawing and picking;
Expand Down
15 changes: 14 additions & 1 deletion Sources/ForgeApp/PMPages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -506,11 +506,24 @@ struct OperationPage: View {
}
}
case .massProperties, .measure, .check:
if op == .measure {
PMSection("Mode") {
PMPicker(label: "Mode", selection: $model.form.measureMode) {
Text("Size / Minimum Distance").tag("distance")
Text("Angle (0–90°)").tag("angle")
}
PMNote(text: "Angles require two planar faces or straight edges; supporting planes/lines are unoriented.")
}
.onChange(of: model.form.measureMode) { _, _ in
model.form.result = nil
Task { await model.computeMeasure() }
}
}
PMSection(op == .measure ? "Measure" : "Results") {
if let r = model.form.result {
KeyValueList(value: r)
} else {
Text(op == .measure ? "Select one entity for its size, or two for their minimum distance." : "Select a body.")
Text(op == .measure ? (model.form.measureMode == "angle" ? "Select two planar faces or straight edges for their angle." : "Select one entity for its size, or two for their minimum distance.") : "Select a body.")
.font(.system(size: 12)).foregroundStyle(Theme.text2)
}
}
Expand Down
66 changes: 62 additions & 4 deletions Sources/ForgeCommands/Commands/QueryCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,17 @@ public enum QueryMassProperties: Command {
}

public enum QueryMeasure: Command {
public enum Mode: String, Codable, Sendable, CaseIterable, SchemaEnum {
case distance, angle
}
public struct Params: Codable, Sendable, SchemaDocumented {
public var from: String
public var to: String?
public var mode: Mode?
public static let fieldDocs: [String: FieldDoc] = [
"from": "Body, face, edge or vertex reference (including persistent face/edge names)",
"to": "Optional second reference; return minimum distance and closest points when supplied",
"to": "Optional second reference for distance; required for angle",
"mode": FieldDoc("distance or angle; angle requires two planar faces/straight edges (mixed pairs allowed), returning angle_degrees in [0, 90] between unoriented supporting planes/lines", default: "distance"),
]
}
public struct EntityMeasurement: Codable, Sendable {
Expand All @@ -222,27 +227,30 @@ public enum QueryMeasure: Command {
}
}
public struct Output: Codable, Sendable {
public var angleDegrees: Double?
public var distanceMM: Double?
public var pointFrom: [Double]?
public var pointTo: [Double]?
public var deltaMM: [Double]?
public var fromEntity: EntityMeasurement
public var toEntity: EntityMeasurement?
enum CodingKeys: String, CodingKey {
case angleDegrees = "angle_degrees"
case distanceMM = "distance_mm", pointFrom = "point_from", pointTo = "point_to", deltaMM = "delta_mm"
case fromEntity = "from_entity", toEntity = "to_entity"
}
}

public static let name = "query.measure"
public static let summary = "Measure bodies, faces, edges or vertices, with minimum distance between two selections"
public static let discussion = "One selection returns its length, area, volume, circular radius or vertex position as applicable. Two selections also return exact B-rep minimum distance, closest points and their signed XYZ displacement, all in millimeters. Named references must identify a single face or edge. Angles, maximum distances and normal-distance modes are not implemented."
public static let summary = "Measure entity sizes, minimum distances, or angles between planar faces and straight edges"
public static let discussion = "One selection returns its length, area, volume, circular radius or vertex position as applicable. In distance mode, two selections also return exact B-rep minimum distance, closest points and their signed XYZ displacement, all in millimeters. Named references must identify a single face or edge. mode=angle requires two planar faces or straight edges (including mixed pairs), returning angle_degrees in [0, 90] between their unoriented supporting planes/lines. Parallel or antiparallel planes/lines measure 0; a line normal to a plane measures 90. Curved, degenerate and body/vertex angle selections are rejected. Maximum distances and normal-distance modes are not implemented."
public static let category = CommandCategory.query
public static let undo = UndoBehavior.none
public static let errors: [ErrorCode] = [.unknownEntity, .invalidParams, .referenceLost, .kernelFailure]
public static let errors: [ErrorCode] = [.unknownEntity, .invalidParams, .referenceLost, .kernelFailure, .notImplemented]
public static let examples: [JSONValue] = [
["from": "body-1", "to": "body-2"], ["from": "body-1/edge-0"],
["from": "body-1/face-0", "to": "body-1/vertex-2"],
["from": "body-1/face-0", "to": "body-1/edge-0", "mode": "angle"],
]

static func resolve(_ reference: String, in doc: Document) throws -> (Shape, EntityMeasurement) {
Expand Down Expand Up @@ -280,11 +288,61 @@ public enum QueryMeasure: Command {
}
}

/// Resolve through the same single-entity/persistent-name rules used by distance.
static func angleDirection(_ reference: String, in doc: Document) throws -> (Vec3, Bool) {
let ref = try EntityRef.parse(reference)
let body = try doc.body(ref.body)
let direction: Vec3
let isPlane: Bool
switch ref.kind {
case .face:
let face = try body.shape.face(doc.faceIndices([reference], of: body, sets: false)[0])
guard face.surfaceType == .plane else {
throw ForgeError(.notImplemented, "angle measurement requires a planar face", entities: [reference])
}
direction = face.normal
isPlane = true
case .edge:
let indices = try doc.edgeIndices([reference], of: body)
guard indices.count == 1 else {
throw ForgeError(.invalidParams, "angle measurement requires one edge", entities: [reference])
}
let edge = try body.shape.edge(indices[0])
guard edge.curveType == .line, !edge.isDegenerate else {
throw ForgeError(.notImplemented, "angle measurement requires a nondegenerate straight edge", entities: [reference])
}
direction = edge.end - edge.start
isPlane = false
case .body, .vertex:
throw ForgeError(.notImplemented, "angle measurement supports planar faces and straight edges", entities: [reference])
}
guard direction.length.isFinite, direction.length > 0 else {
throw ForgeError(.invalidParams, "angle measurement has no defined direction", entities: [reference])
}
return (direction.normalized, isPlane)
}

static func angleDegrees(_ a: Vec3, _ b: Vec3, mixed: Bool) -> Double {
// atan2 avoids acos/asin domain errors and cancellation near 0 and 90 degrees.
let dot = abs(a.dot(b))
let cross = a.cross(b).length
return (mixed ? atan2(dot, cross) : atan2(cross, dot)) * 180 / .pi
}

public static func run(_ p: Params, _ ctx: inout CommandContext) throws -> Output {
if p.mode == .angle && p.to == nil {
throw ForgeError(.invalidParams, "angle measurement requires two selections")
}
let doc = try ctx.requireDocument()
let (a, first) = try resolve(p.from, in: doc)
guard let to = p.to else { return Output(fromEntity: first) }
let (b, second) = try resolve(to, in: doc)
if p.mode == .angle {
let (u, firstPlane) = try angleDirection(p.from, in: doc)
let (v, secondPlane) = try angleDirection(to, in: doc)
return Output(angleDegrees: angleDegrees(u, v, mixed: firstPlane != secondPlane),
fromEntity: first, toEntity: second)
}
let distance = try Kernel.distance(a, b)
return Output(distanceMM: distance.distance, pointFrom: distance.pointA.array, pointTo: distance.pointB.array,
deltaMM: (distance.pointB - distance.pointA).array, fromEntity: first, toEntity: second)
Expand Down
12 changes: 11 additions & 1 deletion Sources/ForgeUI/PanelSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,19 @@ extension AppModel {
}
s.append(PanelSection("Results", controls: controls))
case .massProperties, .measure, .check:
if op == .measure {
s.append(PanelSection("Mode", controls: [
PanelControl(id: "measureMode", kind: .choice(label: "Mode", options: [("distance", "Size / Minimum Distance"), ("angle", "Angle (0–90°)")], get: { [unowned self] in form.measureMode }, set: { [unowned self] in
form.measureMode = $0
form.result = nil
Task { await computeMeasure() }
})),
note("angleScope", "Angles require two planar faces or straight edges; supporting planes/lines are unoriented."),
]))
}
let rows = form.result.map(Self.keyValues) ?? []
s.append(PanelSection(op == .measure ? "Measure" : "Results", controls: rows.isEmpty
? [note("empty", op == .measure ? "Select one entity for its size, or two for their minimum distance." : "Select a body.")]
? [note("empty", op == .measure ? (f.measureMode == "angle" ? "Select two planar faces or straight edges for their angle." : "Select one entity for its size, or two for their minimum distance.") : "Select a body.")]
: rows.enumerated().map { i, kv in PanelControl(id: "r\(i)", kind: .value(label: kv.0, value: kv.1)) }))
case .addRelation:
s += [selectedEntitiesSection, relationsSection(all: false), relationButtonsSection].compactMap { $0 }
Expand Down
10 changes: 6 additions & 4 deletions Sources/ForgeUI/PropertyManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ package enum EndConditionUI: String, CaseIterable {

/// Values being edited in the PropertyManager. Lengths are text so units work ("0.5 in").
package struct OperationForm {
package var measureMode = "distance"
package var bodyDX = "0", bodyDY = "0", bodyDZ = "0", bodyCopy = false
package var bodyCustomAxis: [JSONValue] = [0, 0, 1]
package var bodyRotation = false, bodyAngle = "90", bodyAxis = "z"
Expand Down Expand Up @@ -821,19 +822,20 @@ extension AppModel {
return
}
let requestedSelection = selection
var params: [String: JSONValue] = ["from": .string(refs[0])]
let requestedMode = form.measureMode
var params: [String: JSONValue] = ["from": .string(refs[0]), "mode": .string(requestedMode)]
if refs.count == 2 { params["to"] = .string(refs[1]) }
do {
let result = try await engine.execute("query.measure", .object(params)).result
guard selection == requestedSelection, operation == .measure else { return }
guard selection == requestedSelection, form.measureMode == requestedMode, operation == .measure else { return }
form.result = result
lastError = nil
} catch let error as ForgeError {
guard selection == requestedSelection, operation == .measure else { return }
guard selection == requestedSelection, form.measureMode == requestedMode, operation == .measure else { return }
form.result = nil
lastError = error
} catch {
guard selection == requestedSelection, operation == .measure else { return }
guard selection == requestedSelection, form.measureMode == requestedMode, operation == .measure else { return }
form.result = nil
lastError = ForgeError(.internalError, error.localizedDescription)
}
Expand Down
Loading
Loading