Skip to content

Demo App Phase 2: Workplanes & Selectors #27

@gsdali

Description

@gsdali

Overview

Add CadQuery-style workplane operations and face/edge selectors.

Parent issue: #25
Depends on: #26

Goals

  • Implement selector parser
  • Add workplane stack
  • Implement 2D sketch operations
  • Add context-sensitive operations (hole at selected face)

Selector System

Face Selectors

Selector Meaning Implementation
">Z" Top face (normal +Z) Filter by normal.z > 0.9
"<Z" Bottom face (normal -Z) Filter by normal.z < -0.9
">X" Right face Filter by normal.x > 0.9
"<X" Left face Filter by normal.x < -0.9
">Y" Front face Filter by normal.y > 0.9
"<Y" Back face Filter by normal.y < -0.9

Edge Selectors

Selector Meaning Implementation
"|Z" Edges parallel to Z Filter by direction
"|X" Edges parallel to X Filter by direction
"#Z" Edges perpendicular to Z Filter by direction

API Additions

// Select faces and work on them
shape.faces(">Z")           // Select top face
     .workplane()           // Create workplane on face
     .hole(diameter)        // Drill hole

// Select edges for filleting
shape.edges("|Z")           // Select vertical edges
     .fillet(radius)

// 2D sketching
Workplane("XY")
    .rect(width, height)    // Draw rectangle
    .circle(radius)         // Draw circle
    .polygon(points)        // Draw polygon
    .extrude(height)        // Extrude to solid

Implementation

CadQuerySelectors.swift

struct Selector {
    enum Direction { case x, y, z }
    enum Comparison { case greater, less, parallel, perpendicular }
    
    static func parse(_ str: String) -> Selector? {
        // Parse ">Z", "<X", "|Z", "#Y" etc.
    }
    
    func filterFaces(_ faces: [Face]) -> [Face] {
        // Apply selector logic
    }
}

CadQueryWorkplane.swift

class CadQueryWorkplane: NSObject, CadQueryExports {
    var origin: SIMD3<Double>
    var normal: SIMD3<Double>
    var xDirection: SIMD3<Double>
    
    func rect(_ w: Double, _ h: Double) -> CadQueryWorkplane
    func circle(_ r: Double) -> CadQueryWorkplane
    func extrude(_ h: Double) -> CadQueryShape
}

Acceptance Criteria

  • Face selectors work (">Z", "<Z", ">X", etc.)
  • Edge selectors work ("|Z", "#Z", etc.)
  • Workplane operations work
  • 2D sketches can be extruded
  • Holes can be placed on selected faces

Effort Estimate

~5 days

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions