dymokomi/luced-3d
Source of release 0.11.9
0.11.9 / src / handle_lines.luc
## Where a CAD feature's viewport handles stand, as its cook finds them
## (GeometryData.handles, Node.handles): one handle a line of text, so the
## compute worker's report carries them and the viewport never cooks to
## draw them (feature_handles.luc draws and drags them). A handle's place
## is fixed by the cook; how far along it its tip is comes from the node's
## value in `slot`, live while it is dragged.
## arrow: the tip at `foot + way × value × scale` (Extrude's distances,
## Press Pull's offset, a blend's radius).
## pair: an arrow whose value is the mean of slots `slot` and
## `reference`, a drag moving both alike (Align's middle Tangent Scale
## arrow, sliding the whole row).
## taper: a ring leaning from `foot + way × length` by the angle in
## `slot` (degrees, positive outward as Fusion's), `length` the value
## in slot `reference` times `scale`.
## angle: a ring turned `value × scale` degrees (scale ±1, the way the
## side turns) about the axis through `foot` along `way`, from `side`
## (the radius out to the profiles).
from luce_3d.graphics import Vector3
pub class HandleLine:
pub let kind: str
pub let slot: int
pub let scale: float
pub let reference: int
pub let foot: Vector3
pub let way: Vector3
pub let side: Vector3
pub func init(self, kind: str, slot: int, scale: float, foot: Vector3, way: Vector3, reference: int, side: Vector3):
self.kind = kind
self.slot = slot
self.scale = scale
self.reference = reference
self.foot = foot
self.way = way
self.side = side
pub func encode(self) -> str:
let f = self.foot
let d = self.way
let s = self.side
return f"{self.kind} {self.slot} {self.scale} {self.reference} {f.x} {f.y} {f.z} {d.x} {d.y} {d.z} {s.x} {s.y} {s.z}"
## Handles as a cook reports them.
pub func encode(handles: list[HandleLine]) -> str:
let lines: list[str] = []
for handle in handles:
lines.append(handle.encode())
return lines.join("\n")
## The handles `text` holds (lines that do not read are left out).
pub func parse(text: str) -> list[HandleLine]!:
let result: list[HandleLine] = []
for line in text.split("\n"):
let words = line.split(" ")
if words.length != 13:
continue
let n: list[float] = []
for at in 4..<13:
n.append(float(words[at]))
result.append(HandleLine(words[0], int(words[1]), float(words[2]), Vector3(n[0], n[1], n[2]), Vector3(n[3], n[4], n[5]), int(words[3]), Vector3(n[6], n[7], n[8])))
return result