Luce packages
LuceLuce BaseLuciaOS

dymokomi/luced-3d

Source of release 0.11.7

0.11.7 / src / edit_cad_build.luc

## What the surface builders (surfacing Stage 5: Square, Skin, Rail,
## Profile, Set Planar, Sheet Extrude, Sheet Revolve, Extend; build_ops.luc
## does the work) and the blends between surfaces (Stages 6 to 8: Blend
## Surface, Surface Fillet, Tube, Fill Surface, Bridge Fillet, Corner;
## blend_ops.luc) share, each declared in its tool_<name>.luc: their cook,
## a node's and an Edit step's alike, and their picks as words. A builder
## starts on what is picked, in the order picked; when it needs more it
## waits, and each click adds a curve, an edge or a face (again: takes it
## out; a double-click on a surface a temporary isoparm, Alias's), Enter
## finishing (tool_picks.luc).
from luce_geocore.geocore import Mesh, Selection
from luce_3d.graphics import Vector3
from geometry_data import GeometryData
from tool_record import Invocation
import build_ops
import blend_ops
import edit_cad_align

## A new step's values (a builder's or a blend's).
pub func starting(verb: str) -> list[float]:
    return blend_ops.starting(verb) if verb in blend_ops.verbs() else build_ops.starting(verb)

## A builder's or a blend's cook, a node's and a step's alike: its words
## (curves, edges, faces) in its texts; `tag` names the sheet it makes. A
## step's numbers made before rows were added take those rows' starts.
pub func cook(call: Invocation, data: GeometryData, tag: str) -> GeometryData!:
    let numbers = call.numbers.copy()
    if not call.node:
        let start = starting(call.verb)
        while numbers.length < start.length:
            numbers.append(start[numbers.length])
    if call.verb in blend_ops.verbs():
        return blend_ops.build(call.verb, data, numbers, call.texts if call.node else [call.text(0), call.text(1), call.text(2)], tag, call.tolerances)
    return build_ops.build(call.verb, data, numbers, call.texts if call.node else [call.text(0), call.text(1)], tag, call.tolerances)

## The words for the picks of `chosen` on `mesh` at `level`, in order: a
## curve ("curve <name>") or an edge ("edge <face> x y z"); for Extend
## (`input`) a curve's end or an edge's face side ("curve <name> x y z",
## "face <face> x y z").
pub func picked_words(mesh: Mesh, chosen: Selection, level: int, input: bool) -> list[str]!:
    let found: list[str] = []
    var at = chosen.next(-1)
    while at >= 0:
        let words = edit_cad_align.pick_words(mesh, at, level, not input)
        if words != "" and not (words in found):
            found.append(words)
        at = chosen.next(at)
    return found

## The list `text` with `words` added, or taken out when in it (a second
## click on a curve lets it go).
pub func toggled(text: str, words: str) -> str:
    let list_now = build_ops.items(text)
    if words in list_now:
        let kept: list[str] = []
        for w in list_now:
            if w != words:
                kept.append(w)
        return kept.join(";")
    list_now.append(words)
    return list_now.join(";")

## Whether `words` name a point for a temporary isoparm ("isoparm_at").
pub func isoparm_words(p: Vector3) -> str:
    return f"isoparm_at {p.x} {p.y} {p.z}"