Luce packages
LuceLuce BaseLuciaOS

dymokomi/luced-3d

Source of release 0.11.3

0.11.3 / tests / editor / select_tool_tests.luc

## Select → tool → node (Houdini's shelf tools): components selected on any
## displayed node, a tool creating the verb node after it with the selection
## as its Group and a topology guard, the output selection taking over, Tool →
## Select prompts, Reselect, Keep IDs and the Move gizmo on plain nodes.
from workspace import Workspace
from luce_3d.graphics import Vector3
import modeling_commands
import node_commands
import selection_commands
import tool_prompts
import component_moves

pub func select_tool_tests() -> unit!:
    let w = Workspace()
    let cube = w.network.selected
    # Any displayed node selects: here the Cube itself.
    assert(w.selecting() and not w.editing())
    selection_commands.set_mode(w, 3)
    selection_commands.choose_component(w, 2, false)
    assert(w.selected_ids() == [2])
    modeling_commands.model(w, "Extrude")
    let extrude = w.network.require(w.network.selected)
    assert(extrude.kind == "PolyExtrude" and extrude.inputs[0] == cube and w.network.display == extrude.id)
    assert(extrude.texts[0] == "2" and extrude.guard != 0)
    assert((w.geometry else trap("extruded")).face_count() == 10)
    # The extrusion's front face is the new selection; the step is one undo.
    assert(w.component_mode == 3 and w.selected_ids() == [2])
    w.undo()
    assert(w.network.find(extrude.id) == none and w.network.display == cube)
    w.redo()
    # A tool on a node with downstream nodes inserts itself between them.
    node_commands.add_node(w, "Transform", 0.0, 300.0)
    let transform = w.network.selected
    node_commands.select_node(w, extrude.id)
    node_commands.display_selected(w)
    selection_commands.set_mode(w, 3)
    selection_commands.choose_component(w, 0, false)
    modeling_commands.model(w, "Inset")
    let inset = w.network.require(w.network.selected)
    assert(inset.inputs[0] == extrude.id and w.network.require(transform).inputs[0] == inset.id)
    assert((w.geometry else trap("inset")).face_count() == 14)
    # Changing the input's topology trips the guard; Keep IDs clears it.
    node_commands.select_node(w, extrude.id)
    node_commands.set_text(w, 0, "3")
    node_commands.select_node(w, inset.id)
    node_commands.display_selected(w)
    assert(inset.failure.contains("Reselect"))
    node_commands.keep_ids(w, inset.id)
    assert(inset.failure == "" and inset.guard == 0)
    # Reselect picks on the input with the group selected while the node's
    # result shows; each change rewrites the group at once, Enter keeps it.
    tool_prompts.reselect(w, inset.id)
    assert(w.prompt != none and w.network.display == inset.id and w.selected_ids() == [0])
    assert((w.geometry else trap("input")).face_count() == 10)
    selection_commands.choose_component(w, 5, false)
    assert(inset.texts[0] == "5" and inset.guard != 0 and w.network.display == inset.id and w.prompt != none)
    assert((w.geometry else trap("input")).face_count() == 10)
    tool_prompts.accept_prompt(w)
    assert(inset.texts[0] == "5" and w.network.display == inset.id and w.prompt == none and w.network.selected == inset.id)
    # Tool → Select: nothing selected, the node waits for its components.
    w.selection = none
    modeling_commands.model(w, "Duplicate")
    let waiting = w.network.require((w.prompt else trap("prompt")).node)
    assert(waiting.kind == "Duplicate" and w.network.display == inset.id and w.network.selected == inset.id)
    selection_commands.set_mode(w, 3)
    selection_commands.choose_component(w, 1, false)
    assert(waiting.texts[0] == "1" and w.network.display == waiting.id and waiting.failure == "")
    # Shift adds, and the node follows; clearing shows the input again.
    selection_commands.choose_component(w, 2, true)
    assert(waiting.texts[0] != "1" and w.network.display == waiting.id)
    selection_commands.choose_component(w, -1, false)
    assert(w.network.display == inset.id)
    selection_commands.choose_component(w, 1, false)
    tool_prompts.accept_prompt(w)
    assert(waiting.texts[0] == "1" and w.network.display == waiting.id and w.network.selected == waiting.id and waiting.failure == "")
    # Esc drops a prompted node with its transaction, picks and all.
    w.selection = none
    modeling_commands.model(w, "Reverse")
    let dropped = w.prompt else trap("prompt")
    selection_commands.set_mode(w, 3)
    selection_commands.choose_component(w, 0, false)
    assert(w.network.display == dropped.node)
    w.cancel_prompt()
    assert(w.network.find(dropped.node) == none and w.prompt == none and w.network.display == waiting.id)
    # The Move gizmo on a plain node adds a Transform Components node.
    selection_commands.set_mode(w, 1)
    selection_commands.choose_component(w, 0, false)
    let points = (w.geometry else trap("points")).point_count()
    w.begin("Move components")
    component_moves.preview_move(w, Vector3(0.0, 1.0, 0.0))
    w.commit()
    let moved = w.network.require(w.network.selected)
    assert(moved.kind == "Transform Components" and moved.values[1] == 1.0 and (w.geometry else trap("moved")).point_count() == points)
    # Smart: a point picked selects points, a face then starts over on
    # faces; Smart stays the mode.
    selection_commands.set_mode(w, 4)
    selection_commands.choose_smart(w, 1, 4, false)
    assert(w.component_mode == 4 and w.domain() == 0 and w.group_type() == 1 and w.selected_ids() == [4])
    selection_commands.choose_smart(w, 3, 2, true)
    assert(w.component_mode == 4 and w.domain() == 2 and w.selected_ids() == [2])
    # Select edges, then Bevel: a PolyBevel node for just those edges, its
    # strips selected; Loop Cut from an edge selects the new loop.
    let fresh = Workspace()
    selection_commands.set_mode(fresh, 2)
    selection_commands.choose_component(fresh, 0, false)
    modeling_commands.model(fresh, "Bevel")
    let bevel = fresh.network.require(fresh.network.selected)
    assert(bevel.kind == "PolyBevel" and bevel.guard != 0 and bevel.texts[0] != "")
    assert((fresh.geometry else trap("beveled")).face_count() == 7 and fresh.component_mode == 3 and fresh.selected_count() == 1)
    selection_commands.set_mode(fresh, 2)
    selection_commands.choose_component(fresh, 0, false)
    modeling_commands.model(fresh, "Loop Cut")
    let cut = fresh.network.require(fresh.network.selected)
    assert(cut.kind == "Loop Cut" and fresh.component_mode == 2 and fresh.selected_count() > 0)
    print("PASS selection on any node, tool → node with guard and output selection, Tool → Select, Reselect, Keep IDs, gizmo nodes, Smart, bevel and loop cut on selected edges")