Luce packages
LuceLuce BaseLuciaOS

dymokomi/luced-3d

Source of release 0.11.7

0.11.7 / src / tool_registry.luc

## The tool registry (docs/research/POLY-MODELING.md §3): every tool, from
## each home of declarations, and the views the surfaces read. Luce has no
## reflection, so each home is listed here: the luce-geocore verbs
## (verb_tools.luc) and the CAD tools' declarations (cad_tools.luc).
## Nothing else keeps a list of tool names: the node menu, the Edit kinds'
## tools, the tool bar, the Create/Modify menus, the A/S/D marking menus,
## the right-click menu, Repeat, the prompts, the icons and docs/TOOLS.md
## all come from here.
from tool_record import Tool, ToolEntry
import verb_tools
import cad_tools

## Every tool, in declaration order: the mesh tools, then CAD's.
pub func all() -> list[Tool]:
    return verb_tools.tools() + cad_tools.tools()

## The tools that are steps of Edit kind `kind`.
pub func of_kind(kind: str) -> list[Tool]:
    let result: list[Tool] = []
    for tool in all():
        if kind in tool.kinds:
            result.append(tool)
    return result

## The Geo tool (a mesh tool) labeled `name`, or whose node kind it is.
pub func find(name: str) -> Tool?:
    for tool in verb_tools.tools():
        if tool.label == name or tool.name == name:
            return tool
    return none

## The CAD tool whose node kind, label or step verb is `name`.
pub func cad(name: str) -> Tool?:
    let entry = cad_tools.entry_of(name) else return none
    return entry.make()

## The CAD tools that are nodes in a CAD network, without
## building them: their entries.
pub func cad_nodes() -> list[ToolEntry]:
    let result: list[ToolEntry] = []
    for entry in cad_tools.entries():
        if entry.contexts.length > 0:
            result.append(entry)
    return result

## The CAD tool that is node `kind`, or none.
pub func cad_node(kind: str) -> Tool?:
    for entry in cad_tools.entries():
        if entry.name == kind and entry.contexts.length > 0:
            return entry.make()
    return none

## The CAD tool whose Edit step runs `verb`, or none.
pub func cad_step(verb: str) -> Tool?:
    for entry in cad_tools.entries():
        if entry.verb == verb and entry.kinds.length > 0:
            return entry.make()
    return none

## The order menus list families in (Extrude before Bevel before Cut…);
## a family not named here follows them, in declaration order.
pub func family_order() -> list[str]:
    return ["Primitives", "Extrude", "Bevel", "Cut", "Fill", "Merge", "Delete", "Split", "Sweep", "Subdivide", "Shape", "Deform", "Sculpt", "Normals", "UV", "Draw",
            "Loops", "Region", "Similar", "Find", "Pattern", "Symmetry", "Convert",
            "Sketch", "Features", "Solids", "Blends", "Faces", "Bodies", "Curves", "Surface Edit", "Align", "Surface Build", "Surface Blends", "Surface Structure", "Inspect"]

## Where family `name` sorts (family_order's place, else after them).
pub func family_rank(name: str) -> int:
    let order = family_order()
    for at in 0..<order.length:
        if order[at] == name:
            return at
    return order.length

## Tool `name`'s icon ("" for no tool), without building the tools: the
## icon chain and the strip ask often.
pub func icon_of(name: str) -> str:
    let meshed = verb_tools.icon_of(name)
    if meshed != "":
        return meshed
    let entry = cad_tools.entry_of(name) else return ""
    return entry.icon

## Tool `name`'s viewport gesture ("" for none), without building them.
pub func gesture_of(name: str) -> str:
    return verb_tools.gesture_of(name)