dymokomi/luced-3d
Source of release 0.11.6
0.11.6 / src / tool_split_face.luc
## Split Face (Fusion 360's): faces split where a picked face's surface
## (extended, or with Extend splitting tool off only the face itself,
## right across each face it meets) or an origin plane crosses them; the
## pieces can be picked apart afterwards (edit_cad_faces.luc). The node
## keeps its faces by name; an Edit CAD step takes the faces picked, then
## waits for the splitting face.
from tool_record import Tool, ToolEntry, Pick, Invocation
from geometry_data import GeometryData
from parameter_rows import Parameter, number, toggle, menu
from edit_types import face_level, patch_level
import pick_kinds
import edit_cad_faces
import cad_cook
pub func entry() -> ToolEntry:
return ToolEntry("Split Face", "Split Face", "split-face", "Modify", [cad_cook.context], [cad_cook.edit_kind], made)
func made() -> Tool:
return entry().tool("Modify", "Faces", "Split faces where a face's surface or an origin plane crosses them", picks(), rows(), cook, waits = waits)
func picks() -> list[Pick]:
return [Pick("Faces", [face_level, patch_level], kind = pick_kinds.faces, slot = 0, doc = "The faces to split."),
Pick("Splitting face", [face_level], kind = pick_kinds.face, slot = 1, step = edit_cad_faces.target_text, hide_when = "{ splitting_tool != 0 }",
needed = by_face, doc = "The face whose surface, extended, splits them.")]
## Whether a split's tool is the face picked (not an origin plane).
pub func by_face(values: list[float], texts: list[str], wired: bool) -> bool:
return int(values[edit_cad_faces.split_tool_slot]) == 0
## A splitting face picked: the tool is it.
pub func picked_face(values: list[float], picked: str):
values[edit_cad_faces.split_tool_slot] = 0.0
func waits(values: list[float], texts: list[str], wired: bool) -> str:
if texts[0].trim() == "":
return "Pick the faces to split"
if texts[1].trim() == "" and by_face(values, texts, wired):
return "Pick the splitting face, or choose an origin plane"
return ""
func cook(call: Invocation, data: GeometryData, tag: str) -> GeometryData!:
if not call.node:
return cad_cook.face_step(call, data, tag)
let waiting = waits(call.numbers, call.texts, false)
if waiting != "":
return data.passed(waiting)
let mesh = cad_cook.node_mesh(data, call.verb)
return cad_cook.node_face_step(call, "Split Face", data, mesh, cad_cook.picked(call, mesh, 0, false), [call.text(1), ""], 8, tag)
func rows() -> list[Parameter]:
return split_rows("the faces", "must cut right across each face it meets")
## A split's rows: its tool (the picked face or an origin plane), the
## face's extension and a plane's offset; `what` it splits and how far the
## face must `reach` unextended.
pub func split_rows(what: str, reach: str) -> list[Parameter]:
let offset = number("Offset", edit_cad_faces.split_offset_slot, 0.0, -100000.0, 100000.0, 0.5, "An origin plane moved along its normal.", soft = 100.0)
offset.hide_when = "{ splitting_tool == 0 }"
let tool = menu("Splitting tool", edit_cad_faces.split_tool_slot, "Picked face|XY plane|XZ plane|YZ plane", 0.0, "The face picked (its surface extended), or an origin plane.")
let extend = toggle("Extend splitting tool", edit_cad_faces.split_extend_slot, 1.0, f"On: the picked face's surface, extended past the face, splits {what}. Off: the face cuts only where it reaches, and {reach}.")
extend.hide_when = "{ splitting_tool != 0 }"
return [tool, extend, offset]