dymokomi/luced-3d
Source of release 0.11.2
0.11.2 / src / marking_items.luc
## What the marking menus offer (marking_menu.luc), by context:
## a sketch being edited: its CREATE, MODIFY and CONSTRAINTS tools;
## an Edit node: its primitives (A) and its tools (S), steps inside it;
## inside a CAD node: sketches, extrusions and solids (A), features (S);
## elsewhere: primitives, lights, containers and Edit nodes (A), and the
## modeling tools on the displayed mesh's selection, each a new node (S).
## Node entries add the node after the selected one (`add`).
from marking_menu import MarkItem
from workspace import Workspace
from actions import Actions
from sketch_editor import SketchEditor
from tool_icons import asset_name
from luce_ui.ui import Command
import sketch_tools
from sketch_tools import SketchTool
import cad_nodes
import sketch_node
## Create (A).
pub func create_items(w: Workspace, actions: Actions, add: func(str) -> unit!, sketch: SketchEditor) -> list[MarkItem]:
if w.sketching():
return sketch_items(sketch, 0)
if w.editing():
return command_items(actions.create_commands())
let context = w.network.context()
if context == "cad":
return node_items([sketch_node.kind_name, "Extrude", "Revolve"] + cad_nodes.solid_kinds(), add)
if context == "shading":
return no_items()
return node_items(["Cube", "Sphere", "Cylinder", "Cone", "Torus", "Grid", "Light", "Camera", "Group", "Null", "Code", "CAD", "Edit Mesh", "Edit SDF", "File"], add)
## Modify (S).
pub func modify_items(w: Workspace, actions: Actions, add: func(str) -> unit!, sketch: SketchEditor) -> list[MarkItem]:
if w.sketching():
return sketch_items(sketch, 1)
if w.editing():
return command_items(actions.modify_commands())
let context = w.network.context()
if context == "cad":
return node_items(["Fillet", "Chamfer", "Boolean", "Mirror Body", "Pattern", "Transform", "Edit CAD"], add)
if context == "shading":
return no_items()
return command_items(actions.modify_commands()) + node_items(["Transform", "Mirror", "CopyTransform"], add)
## Constraints (D, in a sketch).
pub func constraint_items(sketch: SketchEditor) -> list[MarkItem]:
return sketch_items(sketch, 2)
## A sketch menu's tools: a tool with variants is one family item.
func sketch_items(sketch: SketchEditor, menu: int) -> list[MarkItem]:
let result = no_items()
for tool in sketch_tools.tools(menu):
if tool.variants.length == 0:
result.append(sketch_item(sketch, tool))
continue
let variants = no_items()
for variant in tool.variants:
variants.append(sketch_item(sketch, variant))
let first = variants[0]
result.append(MarkItem(tool.name, first.icon, tool.ready, first.run, variants = variants))
return result
func sketch_item(sketch: SketchEditor, tool: SketchTool) -> MarkItem:
let name = tool.name
return MarkItem(name, tool.icon, tool.ready, func () -> unit!: sketch.choose(name))
func command_items(commands: list[Command]) -> list[MarkItem]:
let result = no_items()
for command in commands:
let chosen = command
result.append(MarkItem(command.text(), asset_name(command.text()), command.is_enabled(), func () -> unit!: chosen.trigger()))
return result
func node_items(kinds: list[str], add: func(str) -> unit!) -> list[MarkItem]:
let result = no_items()
for kind in kinds:
let chosen = kind
result.append(MarkItem(kind, asset_name(kind), true, func () -> unit!: add(chosen)))
return result
func no_items() -> list[MarkItem]:
let result: list[MarkItem] = []
return result