dymokomi/luced-3d
Source of release 0.11.9
## The steps a modeling command adds: a verb step on the displayed Edit
## node (with its soft radius, falloff, symmetry and Keep), or a verb node
## inserted after the displayed node and shown.
from luce_geocore.geocore import Mesh, Verbs, VerbCatalog
from workspace import Workspace
from node import Node
from edit_operations import EditStep, insert_numbers
from edit_types import soft_radius_slot, falloff_slot, symmetry_slot, keep_slot
from tools import ToolRun
import node_catalog
import node_room
from luce_ui import ui
## Append one verb step to the displayed Edit node, with its settings.
pub func append_step(w: Workspace, label: str, verb: str, group: str, numbers: list[float], mesh: Mesh) -> unit!:
let node = w.selected() else return
w.perform(label + " components", func () -> unit!:
node.edits.append(edit_step(w, node, verb, group, numbers, mesh))
w.network.invalidate(node.id)
# A kind's own verb (not a mesh verb) keeps a selection that
# still fits.
let index = Verbs.index_of(verb)
w.adopt_output = index >= 0 and Verbs.changes_topology(index)
w.rebuild())
## A step of Edit node `node` on `group` of `mesh`: its soft radius and
## falloff reach the transform, its symmetry and Keep selection every step.
## The group is kept as the node's kind keeps it (EditKind.kept: Edit
## CAD's by B-rep entity, which records no topology).
pub func edit_step(w: Workspace, node: Node, verb: str, group: str, numbers: list[float], mesh: Mesh) -> EditStep!:
let kind = w.kind_of(node.kind)
var values = numbers.copy()
if verb == "Transform Components" and values.length >= 15:
values[13] = node.values[soft_radius_slot]
values[14] = node.values[falloff_slot]
# The kind's own numbers after the fifteen (Edit CAD's Create
# copy), as its Move/Copy tool starts them, so gizmo moves merge.
if let editing = kind:
for tool in editing.tools:
if let starting = tool.numbers:
if tool.verb == verb and starting.length > values.length:
values = values + starting[values.length..]
var kept = group
var topology = mesh.topology_hash()
if let editing = kind:
if let keeps = editing.kept:
kept = keeps(w.level_index(), w.group_type(), mesh, group)
if kept != group:
topology = 0
return EditStep(verb, kept, w.group_type(), values, topology, int(node.values[symmetry_slot]), node.values[keep_slot] != 0.0)
## A verb node after the displayed node, inserted before what it fed;
## display and selection move to it, and the tool's output selection when
## it changes the topology or is what it makes (a Select tool's); else the
## selection stays, as for a step.
pub func add_tool_node(w: Workspace, label: str, run: ToolRun, group: str, mesh: Mesh) -> unit!:
w.perform(label, func () -> unit!:
let node = insert_after_display(w, run)
node.texts[0] = group
node.guard = mesh.topology_hash() if group != "" else 0
let index = Verbs.index_of(run.verb)
w.adopt_output = index < 0 or Verbs.changes_topology(index) or Verbs.section(index) == "Select"
w.rebuild())
pub func insert_after_display(w: Workspace, run: ToolRun) -> Node!:
if not node_catalog.allowed(run.verb, w.network.context()):
error(ui.invalid, f"{run.verb} is not available in the {w.network.context()} context; enter its container first")
let source = w.network.display
let upstream = w.network.require(source)
let node = w.network.add(run.verb, upstream.x, upstream.y + 90.0)
for other in w.network.nodes:
if other.id == node.id: continue
for port in 0..<other.inputs.length:
if other.inputs[port] == source: other.inputs[port] = node.id
w.network.connect(source, node.id, 0)
# Below its input, the chain it was inserted into pushed down.
node_room.place_below(w.network, node.id, source)
w.sketch_return = -1
# Numbers after a verb's parameters pass over the Group Type's slot.
if VerbCatalog.index_of(run.verb) >= 0 and VerbCatalog.trailing(VerbCatalog.index_of(run.verb)):
insert_numbers(node.values, run.numbers)
else:
for slot in 0..<run.numbers.length:
node.values[slot] = run.numbers[slot]
if node_catalog.takes_group_type(node.kind):
node.values[node_catalog.group_type_slot] = float(w.group_type())
w.network.selected = node.id
show(w, node.id)
w.end_modal_tool()
return node
## Show node `id`'s result: it takes the display flag.
pub func show(w: Workspace, id: int) -> unit!:
w.network.set_display(id)