Luce packages
LuceLuce BaseLuciaOS

dymokomi/luced-3d

Source of release 0.11.5

0.11.5 / src / sketch_tools.luc

## The Sketch editor's tools, as Fusion 360 groups them in its CREATE,
## MODIFY and CONSTRAINTS menus (docs/research/FUSION-SKETCH-STUDY.md):
## each with its shortcut, its icon and whether it works yet. Tools not
## built yet show greyed in their menu, so the menus read as Fusion's do.

pub class SketchTool:
    pub let name: str
    ## A single key that picks it, or "".
    pub let key: str
    pub let icon: str
    pub let ready: bool
    ## A separator above it in its menu.
    pub let group_start: bool
    ## Its kinds, in a submenu (Fusion's ▸): the row itself is no tool then.
    pub let variants: list[SketchTool]

    pub func init(self, name: str, key: str, icon: str, ready: bool, group_start: bool = false, variants: list[SketchTool] = []):
        self.name = name
        self.key = key
        self.icon = icon
        self.ready = ready
        self.group_start = group_start
        self.variants = variants

pub func menu_names() -> list[str]:
    return ["CREATE", "MODIFY", "CONSTRAINTS"]

## The tools of menu `menu` (menu_names' order).
pub func tools(menu: int) -> list[SketchTool]:
    if menu == 0:
        return [SketchTool("Line", "L", "line-tool", true), SketchTool("Midpoint Line", "", "line-tool", true),
                SketchTool("Rectangle", "", "rectangle-tool", true, variants = [SketchTool("2-Point Rectangle", "R", "rectangle-tool", true),
                    SketchTool("3-Point Rectangle", "", "rectangle-tool", true), SketchTool("Center Rectangle", "", "rectangle-tool", true)]),
                SketchTool("Circle", "", "ellipse-tool", true, variants = [SketchTool("Center Diameter Circle", "C", "ellipse-tool", true),
                    SketchTool("2-Point Circle", "", "ellipse-tool", true), SketchTool("3-Point Circle", "", "ellipse-tool", true),
                    SketchTool("2-Tangent Circle", "", "ellipse-tool", true), SketchTool("3-Tangent Circle", "", "ellipse-tool", true)]),
                SketchTool("Arc", "", "path-tool", true, variants = [SketchTool("3-Point Arc", "", "path-tool", true),
                    SketchTool("Center Point Arc", "", "path-tool", true), SketchTool("Tangent Arc", "", "path-tool", true)]),
                SketchTool("Polygon", "", "polygon-select-tool", true, variants = [SketchTool("Circumscribed Polygon", "", "polygon-select-tool", true),
                    SketchTool("Inscribed Polygon", "", "polygon-select-tool", true), SketchTool("Edge Polygon", "", "polygon-select-tool", true)]),
                SketchTool("Ellipse", "", "ellipse-tool", true),
                SketchTool("Slot", "", "rectangle-tool", true, variants = [SketchTool("Center to Center Slot", "", "rectangle-tool", true),
                    SketchTool("Overall Slot", "", "rectangle-tool", true), SketchTool("Center Point Slot", "", "rectangle-tool", true),
                    SketchTool("Three Point Arc Slot", "", "rectangle-tool", true), SketchTool("Center Point Arc Slot", "", "rectangle-tool", true)]),
                SketchTool("Spline", "", "pen-tool", true, variants = [SketchTool("Fit Point Spline", "", "pen-tool", true), SketchTool("Control Point Spline", "", "pen-tool", true)]),
                SketchTool("Conic Curve", "", "path-tool", true),
                SketchTool("Point", "P", "vertex-select", true), SketchTool("Text", "", "text-tool", true),
                SketchTool("Mirror", "", "mirror-modifier", true, true), SketchTool("Circular Pattern", "", "array-modifier", true),
                SketchTool("Rectangular Pattern", "", "array-modifier", true),
                SketchTool("Project / Include", "", "import", true, true, variants = [SketchTool("Project", "", "import", true), SketchTool("Intersect", "", "import", false),
                    SketchTool("Include 3D Geometry", "", "import", false), SketchTool("Project To Surface", "", "import", false)]),
                SketchTool("Sketch Dimension", "", "measure-tool", true, true)]
    if menu == 1:
        return [SketchTool("Fillet", "", "bevel", true), SketchTool("Chamfer", "", "bevel", true), SketchTool("Blend Curve", "", "path-tool", true, variants = [SketchTool("Blend Curve G1", "", "path-tool", true),
                    SketchTool("Blend Curve G2", "", "path-tool", true), SketchTool("Blend Curve G3", "", "path-tool", true)]),
                SketchTool("Offset", "O", "inset", true), SketchTool("Trim", "T", "crop-tool", true, true), SketchTool("Extend", "", "arrow-right", true),
                SketchTool("Break", "", "split-mesh", true), SketchTool("Sketch Scale", "", "scale-tool", true),
                SketchTool("Move/Copy", "M", "move-tool", true), SketchTool("Change Parameters", "", "settings", true, true)]
    return [SketchTool("Horizontal/Vertical", "", "align-horizontal-center", true), SketchTool("Coincident", "", "merge-vertices", true),
            SketchTool("Tangent", "", "path-tool", true), SketchTool("Equal", "", "distribute-horizontal", true),
            SketchTool("Parallel", "", "align-left", true), SketchTool("Perpendicular", "", "corner-pin", true),
            SketchTool("Fix/UnFix", "", "lock", true), SketchTool("MidPoint", "", "vertex-select", true),
            SketchTool("Concentric", "", "ellipse-select-tool", true), SketchTool("Collinear", "", "line-tool", true),
            SketchTool("Symmetry", "", "mirror-modifier", true), SketchTool("Curvature", "", "path-tool", true),
            SketchTool("Polygon", "", "polygon-select-tool", false)]

## The tool a key picks, or "".
pub func tool_for_key(key: str) -> str:
    for menu in 0..<3:
        for tool in tools(menu) + variants_of(menu):
            if tool.key != "" and tool.key == key and tool.ready:
                return tool.name
    return ""

## Every variant of menu `menu`'s tools.
func variants_of(menu: int) -> list[SketchTool]:
    let found: list[SketchTool] = []
    for tool in tools(menu):
        for variant in tool.variants:
            found.append(variant)
    return found

## Whether `name` draws (a CREATE tool placing geometry click by click).
pub func draws(name: str) -> bool:
    return name in ["Line", "Midpoint Line", "2-Point Rectangle", "3-Point Rectangle", "Center Rectangle", "Center Diameter Circle", "2-Point Circle",
                    "3-Point Circle", "2-Tangent Circle", "3-Tangent Circle", "3-Point Arc", "Center Point Arc", "Tangent Arc", "Circumscribed Polygon",
                    "Inscribed Polygon", "Edge Polygon", "Center to Center Slot", "Overall Slot", "Center Point Slot", "Three Point Arc Slot",
                    "Center Point Arc Slot", "Fit Point Spline", "Control Point Spline", "Ellipse", "Conic Curve", "Text", "Point"]

## Whether `name` places points as it is clicked (snapping where it
## does): the drawing tools, Move/Copy, Sketch Scale and the Patterns.
pub func places(name: str) -> bool:
    return draws(name) or name in ["Move/Copy", "Sketch Scale", "Circular Pattern", "Rectangular Pattern"]

## Whether `name` picks curves only (not the points on them).
pub func picks_curves(name: str) -> bool:
    return name in ["Trim", "Extend", "Break", "Offset"] or name.starts_with("Blend Curve")

## Whether `name` takes as many clicks as it is given (Enter, or the last
## point again, ends it).
pub func open_ended(name: str) -> bool:
    return name in ["Fit Point Spline", "Control Point Spline"]

## Whether `name` copies the selection (Mirror and the Patterns).
pub func copies(name: str) -> bool:
    return name in ["Mirror", "Circular Pattern", "Rectangular Pattern"]

## How many clicks drawing tool `name` takes.
pub func clicks_for(name: str) -> int:
    if name == "Point":
        return 1
    if name in ["Three Point Arc Slot", "Center Point Arc Slot"]:
        return 4
    if name in ["3-Point Rectangle", "3-Point Circle", "2-Tangent Circle", "3-Tangent Circle", "3-Point Arc", "Center Point Arc", "Center to Center Slot",
                "Overall Slot", "Center Point Slot", "Ellipse", "Conic Curve"]:
        return 3
    return 2

## Whether `name` is a MODIFY tool.
pub func modifies(name: str) -> bool:
    return in_menu(name, 1)

## Whether `name` is a constraint tool.
pub func constrains(name: str) -> bool:
    return in_menu(name, 2)

## Whether tool `name` is in menu `menu` (or a submenu of it).
pub func in_menu(name: str, menu: int) -> bool:
    for tool in tools(menu):
        if tool.name == name:
            return true
        for variant in tool.variants:
            if variant.name == name:
                return true
    return false

## Tool `name`'s icon, or "" when it is no sketch tool.
pub func icon_of(name: str) -> str:
    for menu in 0..<3:
        for tool in tools(menu) + variants_of(menu):
            if tool.name == name:
                return tool.icon
    return ""