Luce packages
LuceLuce BaseLuciaOS

dymokomi/luced-3d

Source of release 0.11.9

0.11.9 / src / drag_session.luc

## What a tool's viewport drag works on (POLY-MODELING.md ยง6.1, owner answer
## 7): the step or node the tool just made, the row a drag sets and the
## rows the wheel and an axis lock set, the numbers the tool ran with (Escape
## goes back to them) and the frame its group gives the pointer (its center,
## its average normal, its rails), measured on the input the tool ran on.
## tool_drag.luc turns pointer, wheel and key events into values; this
## record only holds them. It lives on the workspace from the tool's run
## until a click keeps the value, Escape restores it, or anything else
## changes the node.
from luce_geocore.geocore import DragFrame, Mesh
from tool_record import Tool
from parameter_rows import Parameter

pub class DragSession:
    ## The node (an Edit node with the tool as its last step, or the tool's
    ## node), whether it is a step, and the recipe's length then.
    pub let node: int
    pub let step: bool
    pub let steps: int
    pub let tool: Tool
    ## The drag's row (a tool key may switch it: Bevel's P drags the shape)
    ## and how the pointer moves it, and the wheel's row (none: no wheel).
    pub var row: Parameter
    pub var mode: str
    pub let wheel_row: Parameter?
    ## Value slots: the drag's row, the wheel's (-1), the axis lock's vector
    ## and menu (-1), and the menu's choice that takes the vector.
    pub var slot: int
    pub let wheel_slot: int
    pub let axis_slot: int
    pub let choice_slot: int
    pub let choice_value: float
    ## The numbers the tool ran with.
    pub let start: list[float]
    pub var frame: DragFrame
    ## What the frame was measured on: the tool's input, its group and how
    ## it was picked (a wheel step measures again: Loop Cut's rails move
    ## with its cuts).
    pub let input: Mesh
    pub let group: str
    pub let group_type: int
    pub let symmetry: int
    ## The undo position right after the tool's step: each drag after it
    ## folds into that one undo step.
    pub let mark: int
    ## Whether the pointer moves the value with no button held (until a
    ## click), whether a button drag is on, and whether it moved.
    pub var following: bool
    pub var dragging: bool = false
    pub var moved: bool = false
    ## Whether the drag opened the workspace's transaction it is showing in.
    pub var open: bool = false
    ## Where the measuring starts: the pointer and the value then; -1 x
    ## before the first move.
    pub var anchor_x: float = -1.0
    pub var anchor_y: float = 0.0
    pub var anchor_value: float = 0.0
    ## The pointer, for the value box.
    pub var pointer_x: float = 0.0
    pub var pointer_y: float = 0.0
    ## The world axis locked (0 X, 1 Y, 2 Z; -1 none).
    pub var locked: int = -1
    ## A slide's rails: the first rail of the element it slides, and the
    ## rail picked by the first move (-1: by the pointer's side each move).
    pub var rail: int = -1
    pub var chosen_rail: int = -1
    ## An angle drag's turn so far (degrees) and its last angle on screen.
    pub var turned: float = 0.0
    pub var last_angle: float = 0.0
    ## Points the trackpad scrolled toward the next wheel step.
    pub var scrolled: float = 0.0
    ## The value box beside the pointer.
    pub let box: TypedValue

    pub func init(self, node: int, step: bool, steps: int, tool: Tool, row: Parameter, start: list[float], frame: DragFrame, input: Mesh, group: str, group_type: int, symmetry: int, mark: int, following: bool):
        self.node = node
        self.step = step
        self.steps = steps
        self.tool = tool
        self.row = row
        self.mode = tool.drag_mode
        self.wheel_row = tool.row_at(tool.wheel)
        self.slot = tool.slot_of(tool.drag)
        self.wheel_slot = tool.slot_of(tool.wheel)
        self.axis_slot = tool.slot_of(tool.axis)
        self.choice_slot = tool.slot_of(tool.axis_choice)
        self.choice_value = last_choice(tool)
        self.start = start.copy()
        self.frame = frame
        self.input = input
        self.group = group
        self.group_type = group_type
        self.symmetry = symmetry
        self.mark = mark
        self.following = following
        self.box = TypedValue()

    ## The drag's row.
    pub func row_name(self) -> str:
        return self.row.name

    ## Whether typing and the axis keys go to it: while the value follows the
    ## pointer (once it has moved since the tool ran) or a button drags it.
    pub func live(self) -> bool:
        return (self.following and self.anchor_x >= 0.0) or self.dragging

## What was typed into a drag's value box: its text, locked once typed (the
## pointer no longer moves the value), whether it reads as a number, and
## the number.
pub class TypedValue:
    pub var text: str = ""
    pub var locked: bool = false
    pub var valid: bool = true
    pub var value: float = 0.0

## The last choice of tool `tool`'s axis-lock menu (its "Vector"), or 0.
func last_choice(tool: Tool) -> float:
    let row = tool.row_at(tool.axis_choice) else return 0.0
    return float(row.items.split("|").length - 1)