dymokomi/luce-geocore
Source of release 0.7.8
0.7.8 / src / core / verb_specs.lucb
## What a modeling operation declares about its inputs: its parameters (the
## rows a node's pane shows, in the order a run receives their numbers) and
## its picks (the selections it works on, and the levels they are picked
## at). The mesh verbs (verbs/) and the select rules (selecting/) share them,
## so a Select tool is a verb and a group function from one declaration.
import errors
from core.growing import Growing
pub enum ParmKind as u8:
number = 0
integer = 1
toggle = 2
vector = 3
menu = 4
## A luce-std ramp (`ramp.lucb`'s flat list) in `components` numbers,
## its points after the header; the numbers past its size are unused.
ramp = 5
## No per-component initial values: each component starts at `initial`.
let no_initials: f64[1] = [0.0]
## One parameter of a verb: what the node's parameter pane shows, and where
## its values sit among the numbers a run receives.
pub struct ParmSpec:
pub let label: str
pub let kind: ParmKind
pub let initial: f64
pub let minimum: f64
pub let maximum: f64
## Vectors: components (each defaults to `initial`).
pub let components: usize = 1
## Menus: `Label|Label` (values 0, 1, …).
pub let choices: str = ""
pub let doc: str = ""
## A soft maximum for sliders (0: the maximum).
pub let soft: f64 = 0.0
## Whether a tool's bar shows it after the tool runs (off for numbers a
## gesture records: the knife's plane, PolyDraw's corners).
pub let bar: bool = true
## Whether it sits behind More options (a folder closed at first) on the
## bar and in the node's pane: the rows a modeler sets less often.
pub let more: bool = false
## Initial values per component, where they differ (a ramp's default
## points); components past them start at `initial`.
pub let initials: const f64[] = no_initials[..<0]
## Component `component`'s initial value.
pub func initial_at(component: usize) -> f64:
return self.initials[component] if component < self.initials.length else self.initial
## One selection a tool works on (its first is the group the verb runs on):
## what it is called, the selection levels it is picked at and what the
## editor says while it waits for it.
pub struct PickSpec:
pub let label: str
## The levels it is picked at, space apart, from "objects" (whole
## pieces), "points", "edges" and "faces"; "" takes every level.
pub let levels: str = ""
pub let prompt: str = ""
## How the viewport's interactive creation sets a primitive's rows
## (Verb.place), after Modo's and Maya's interactive primitives: a drag on
## the ground or a surface draws the base, then (with a rise) the pointer
## raises it; where the base lands and the way that surface faces set the
## Position and Up rows.
pub struct PlaceSpec:
## "rect": the drag's two corners set the base's width and depth (a
## vector parameter's X and Z, or two numbers: width, then depth);
## "radius": the drag out from the center sets a radius.
pub let base: str
pub let size: i64
## The parameter the second stage sets (-1: none), its component (a
## vector's), and how: "height" along Up from the base, "radius" the
## distance off the base's circle (a torus's tube).
pub let rise: i64 = -1
pub let rise_component: i64 = 0
pub let rise_mode: str = "height"
## The Position and Up parameters (vectors); Turn and Name piece follow
## Up (verbs/create.lucb's rows).
pub let position: i64 = -1
pub let up: i64 = -1
## A key that changes a tool while its drag lasts, as Blender's modal keys
## do: `action` "drag" makes the drag set parameter `parm` instead (moved
## by `mode`, one of Verb.drag_mode's words), "cycle" steps a menu
## parameter to its next choice, "toggle" flips a toggle.
pub struct KeySpec:
pub let key: str
pub let parm: i64
pub let action: str
pub let mode: str = ""
## The values of one run: numbers in parameter order (a vector takes its
## components), one per component of the verb's parameters (`filled_parms`).
pub struct Parms:
pub let numbers: const f64[]
pub func at(index: usize) -> f64:
if index >= self.numbers.length: trap("a verb read past its parameters")
return self.numbers[index]
## `numbers` completed with the initial values of the parameters they leave
## out, one per component. More numbers than `specs` take is an error unless
## the verb takes `trailing` numbers, which are kept after the parameters.
pub func filled_parms(specs: const ParmSpec[], numbers: const f64[], trailing: bool = false) -> Growing[f64]!:
var total: usize = 0
for spec in specs: total += spec.components
if numbers.length > total and not trailing: error(errors.invalid, "more parameter values than the operation takes")
let length = numbers.length if numbers.length > total else total
var values = Growing[f64]()
try values.reserve(length)
var at: usize = 0
for spec in specs:
for component in 0..<spec.components:
values.items[at] = numbers[at] if at < numbers.length else spec.initial_at(component)
at += 1
for extra in total..<length: values.items[extra] = numbers[extra]
values.count = length
return values