Skip to content

Instantly share code, notes, and snippets.

@s-ol
Last active October 15, 2019 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s-ol/8b747a43f047d20997c7dfe26edd9712 to your computer and use it in GitHub Desktop.
Save s-ol/8b747a43f047d20997c7dfe26edd9712 to your computer and use it in GitHub Desktop.
End-user programmable UX concept for CAD

(this was inspired by libfive, antimony and Ronin)

EDIT: see a Proof-of-Concept demonstration and explanation video here.

an electronics CAD software could have a livecoding typing area somewhere, here illustrated with some Clojure pseudocode: (I chose a lisp-y thing because originally I thought that was going to be relevant, but now I see it is not at all necessary. Which is good news because it means this could be built more easily on top of the KiCAD API as it is, potentially.)

(let [rect (select-rect)
      footprints (sort by-name (select-footprints))
      min-stride (max (map footprints (fn [fp] (width fp))))
      cols (floor (/ (width rect) min-stride))]
      rows (ceil (/ (count footprints) cols))]
  (each [[column x] (enumerate (group-into-bins cols footprints))]
    (each [[footprint y] (enumerate column)]
      (let [pos (+ (origin rect) (* (size rect) (vec2 (/ x cols) (/ y rows))))]
        (move-to footprint pos)))))

...but you don't have to hit enter or a button to make it execute, and you don't have to undo if it didn't do what you wanted it to. The code is continuously parsed and interpeted as it is edited (as long as it is valid). The API used isolates all application state behind a non-mutable API, that runs like an immediate mode UI library:

  • select-rect draws a rectangle that can be selected, moved, resized and returns its current origin and size vecctors
  • select-footprints highlights selected footprints, lets you shift-click to add/remove footprints from the set, and returns the current set
  • move-to previews the destination positions

The function-invocations register themselves with the editor UI, which draws these visualisations and keeps state for them as long as the editing session exists and the function invocation is not removed.

This lets the user tweak the code and make sure it works, as well as tweak the selections etc. Once the user is happy with the result, they can commit the changes. To commit the changes, the API is switched into a different mode, where the select-* functions simply return the last known state, while the move-to function applies the change instead of previewing it. With this mode-changed API the block is executed one final time, and the changes are recorded into an undo-redo step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment