dymokomi/luced-3d
Source of release 0.11.6
0.11.6 / tools / preview_cad.luc
## The CAD captures of preview.py (docs/research/FUSION-CAD-UX.md's stages),
## each a scene set up before the first frame and driven as a user would
## over the next ones:
## cad_glyphs: a sketch's Parallel glyph clicked (selected, what it holds
## lit) and right-clicked, the viewport menu open on Delete constraint.
## cad_window: a box dragged right to left over a plate's corner and its
## hole at the Lines level: only the hole, wholly inside, is taken.
## cad_profiles: a plate with a hole seen at an angle, its profiles
## shaded, the plate's ring picked at Shapes, the pointer over the hole.
## cad_extrude: the ring extruded from the sketch: the Extrude shown and
## selected, its arrow and distance box.
## cad_face_menu: a box's top face right-clicked at the Faces level:
## Sketch on face (Press Pull to come).
## cad_rollback: Box → Sketch on its top (a circle) → Extrude cut down →
## the sketch selected again: the box as it was there, the Extrude
## downstream, the right-click menu with Extrude and Finish Sketch.
## cad_marking: in that sketch, A held: CREATE with Extrude and Finish
## Sketch.
## cad_edge_menu: the cut box's rim edge right-clicked at the Edges
## level: Fillet and Chamfer.
## cad_dims: a plate with a hole and a slanted cut, fully dimensioned
## (lengths, the hole's place and diameter, an angle), one label moved
## off; the pointer over the width.
## cad_typing: a Line begun at the origin, 25 typed in its Length box
## (locked, the line held at it) and Tab pressed: its Angle box focused.
## cad_dim_edit: the plate's width clicked twice: its value box open on
## its label.
## cad_face_sketch: a Sketch on a box's top face from the right-click
## menu: the face's loop projected (purple), offset inward 3 as one
## relation with its one dimension.
## cad_lost: that sketch with one projected line pointed at an edge that
## is gone: drawn yellow, the node's badge yellow.
## cad_face_open: a Sketch on a box's top face just made (with
## --background, the projection and plane come from the compute
## worker's cook).
## cad_slice: a Sketch on the XY plane through a box, Slice on: only the
## body behind the plane shows, its cut capped and hatched.
## cad_auto: the cut Extrude selected: its Operation row says Auto (Cut).
## cad_origin: a line typed 30 long at 40° from a point off the origin
## (its angle dimensioned from the x axis), and a point's distance from
## the x axis; Sketch Dimension's pointer over the y axis (lit).
## cad_typed: a center point arc typed radius 12, sweep 120 (an angle
## dimension on the arc) and a circumscribed hexagon beside it.
## cad_conflict: the dimensioned plate's width dimensioned again: added
## driven, the width it repeats lit in the warning color.
## cad_project_face: Project in a Sketch above a box with a hole, the
## pointer inside the top face (its loops lit), one edge projected.
## cad_project_body: the box's outline brought by Project body.
## cad_project_silhouette: a cylinder seen from its side (a Sketch on XY
## in front of it), its outline brought by Project body: its two
## silhouettes and its rims seen edge-on.
## Stages 4 and 5's scenes are preview_features.luc's, stage 6's
## preview_direct.luc's, stages 7 and 8's preview_history.luc's.
import preview_support
from luce_ui.ui import Event
from luce_window.input import EventKind, Key
from luce_3d.graphics import Vector3
from luce_cad.modeling import CadModeling
from app import Luce3D
from luce_cad.sketch import CadSketch
from view_projection import project
import node_commands
import sketch_commands
import selection_commands
import cad_commands
import sketch_kinds as names
import text as characters
import preview_features
import preview_direct
import preview_history
import preview_tutorial
import preview_kernel
pub func scenes() -> list[str]:
return ["cad_glyphs", "cad_window", "cad_profiles", "cad_extrude", "cad_face_menu", "cad_rollback", "cad_marking", "cad_edge_menu", "cad_dims", "cad_typing", "cad_dim_edit", "cad_face_sketch", "cad_lost", "cad_slice", "cad_auto", "cad_face_open", "cad_origin", "cad_typed", "cad_conflict", "cad_project_face", "cad_project_body", "cad_project_silhouette"] + preview_features.scenes() + preview_direct.scenes() + preview_history.scenes() + preview_tutorial.scenes() + preview_kernel.scenes()
## A CAD node holding a Solid Box with a Sketch on its top face, made from
## the face selected as a user does (the right-click menu's command).
func box_face_sketch(editor: Luce3D) -> unit!:
let w = editor.workspace
node_commands.delete_selected(w)
node_commands.add_node(w, "CAD", 40.0, 40.0)
node_commands.enter_group(w, w.network.selected)
node_commands.add_node(w, "Solid Box", 40.0, 40.0)
look(editor, 0.5, 0.6, 75.0, Vector3())
selection_commands.set_mode(w, w.level_of(2))
let mesh = preview_support.shown(w) else trap("no pick mesh")
for face in 0..<mesh.face_count():
if mesh.face_center(face).y > 9.99:
selection_commands.choose_component(w, face, false)
break
editor.panels.refresh()
editor.panels.actions.sketch_on_face.trigger()
editor.panels.view.sketch.editor.sync()
editor.panels.refresh()
## A plate 60 by 30 with its bottom-left corner fixed at the origin, a
## hole of 12 placed 15 and 15 from it, and its top-right corner cut at 30°
## from the top: every length, the hole's place and diameter, and the
## cut's angle dimensioned, so all of it is fully constrained. The width
## dimension's index is the text's first dimension.
func dimensioned_plate() -> str!:
let s = CadSketch.parse("")
let p0 = s.add_point(0.0, 0.0)
let p1 = s.add_point(60.0, 0.0)
let p2 = s.add_point(60.0, 18.0)
let p3 = s.add_point(39.2, 30.0)
let p4 = s.add_point(0.0, 30.0)
let bottom = s.add_line(p0, p1)
let right = s.add_line(p1, p2)
let cut = s.add_line(p2, p3)
let top = s.add_line(p3, p4)
let left = s.add_line(p4, p0)
_ = s.constrain(names.fix, p0)
_ = s.constrain(names.horizontal, bottom)
_ = s.constrain(names.vertical, right)
_ = s.constrain(names.horizontal, top)
_ = s.constrain(names.vertical, left)
_ = s.constrain(names.distance, p0, p1, value = 60.0)
_ = s.constrain(names.distance, p4, p0, value = 30.0)
_ = s.constrain(names.distance, p1, p2, value = 18.0)
_ = s.constrain(names.angle, top, cut, value = -0.5235987755982988)
let c = s.add_point(15.0, 15.0)
let hole = s.add_circle(c, 6.0)
_ = s.constrain(names.diameter, hole, value = 12.0)
_ = s.constrain(names.horizontal_distance, p0, c, value = 15.0)
_ = s.constrain(names.vertical_distance, p0, c, value = 15.0)
_ = s.solve()
return s.text()
## Type `text` into what has the keyboard.
func type_text(editor: Luce3D, text: str) -> unit!:
for character in text:
editor.app.dispatch(Event(kind = EventKind.text_input, codepoint = characters.code_of(character)))
## The view from (yaw, pitch) at `distance` round `target`.
func look(editor: Luce3D, yaw: float, pitch: float, distance: float, target: Vector3) -> unit!:
let w = editor.workspace
w.view.yaw = yaw
w.view.pitch = pitch
w.view.distance = distance
w.view.target = target
w.view.update_camera()
## A right click on the viewport at world point `p`.
func right_click(editor: Luce3D, p: Vector3) -> unit!:
let area = editor.panels.view.layout().bounds()
let s = project(editor.workspace, p, area.width, area.height)
editor.app.dispatch(Event(kind = EventKind.pointer_moved, x = area.x + s[0], y = area.y + s[1]))
editor.app.dispatch(Event(kind = EventKind.pointer_down, x = area.x + s[0], y = area.y + s[1], button = 1))
editor.app.dispatch(Event(kind = EventKind.pointer_up, x = area.x + s[0], y = area.y + s[1], button = 1))
## A plate with a hole on the ground, its ring picked at Shapes.
func holed_plate(editor: Luce3D) -> unit!:
let w = editor.workspace
let s = CadSketch.parse(sketch_commands.rectangle_text(20.0, -10.0, 40.0, 20.0))
_ = s.add_circle(s.add_point(10.0, -10.0), 5.0)
open_sketch(editor, s.text(), 20.0, -10.0, 80.0)
look(editor, 0.35, 0.75, 85.0, Vector3(20.0, 0.0, 10.0))
let e = editor.panels.view.sketch.editor
selection_commands.set_mode(w, 3)
e.sync()
w.sketch_profiles = [CadModeling.profile_at(s.curves(e.frame.origin, e.frame.u, e.frame.v), e.frame.at(30.0, -10.0))]
editor.panels.refresh()
## Box → Sketch on its top face holding a circle of radius 4 → Extrude 6
## down (Auto: a cut); the Extrude shown and selected.
func cut_box(editor: Luce3D) -> unit!:
let w = editor.workspace
node_commands.delete_selected(w)
node_commands.add_node(w, "CAD", 40.0, 40.0)
node_commands.enter_group(w, w.network.selected)
node_commands.add_node(w, "Solid Box", 40.0, 40.0)
look(editor, 0.5, 0.6, 75.0, Vector3())
selection_commands.set_mode(w, w.level_of(2))
let mesh = preview_support.shown(w) else trap("no pick mesh")
for face in 0..<mesh.face_count():
if mesh.face_center(face).y > 9.99:
selection_commands.choose_component(w, face, false)
break
editor.panels.refresh()
editor.panels.actions.sketch_on_face.trigger()
let e = editor.panels.view.sketch.editor
e.sync()
let middle = e.frame.coordinates(Vector3(0.0, 10.0, 0.0))
let s = CadSketch.parse("")
_ = s.add_circle(s.add_point(middle[0], middle[1]), 4.0)
node_commands.set_text(w, 0, s.text())
editor.panels.refresh()
# The circle's profile (the face's projected loop is one too).
e.sync()
let drawn = e.sketch else trap("no sketch")
w.sketch_profiles = [CadModeling.profile_at(drawn.curves(e.frame.origin, e.frame.u, e.frame.v), Vector3(0.0, 10.0, 0.0))]
editor.panels.actions.extrude_profiles.trigger()
w.ask_value = false
node_commands.set_parameter(w, 0, -6.0)
look(editor, 0.5, 0.6, 75.0, Vector3())
editor.panels.refresh()
## A Sketch on the ground in a new CAD node holding `text`, edited and
## looked at from above round sketch point (x, y), `distance` away.
func open_sketch(editor: Luce3D, text: str, x: float, y: float, distance: float) -> unit!:
let w = editor.workspace
node_commands.delete_selected(w)
node_commands.add_node(w, "CAD", 40.0, 40.0)
node_commands.enter_group(w, w.network.selected)
node_commands.add_node(w, "Sketch", 40.0, 40.0)
node_commands.set_text(w, 0, text)
w.view.yaw = 0.0
w.view.pitch = 1.5
w.view.distance = distance
w.view.target = editor.panels.view.sketch.editor.frame.at(x, y)
w.view.update_camera()
editor.panels.view.sketch.editor.sync()
editor.panels.refresh()
## Scene `scene` before its first frame.
pub func setup(editor: Luce3D, scene: str) -> unit!:
if scene in preview_features.scenes():
preview_features.setup(editor, scene)
return
if scene in preview_direct.scenes():
preview_direct.setup(editor, scene)
return
if scene in preview_history.scenes():
preview_history.setup(editor, scene)
return
if scene in preview_tutorial.scenes():
preview_tutorial.setup(editor, scene)
return
if scene in preview_kernel.scenes():
preview_kernel.setup(editor, scene)
return
if scene == "cad_glyphs":
let s = CadSketch.parse(sketch_commands.rectangle_text(20.0, -10.0, 40.0, 20.0))
var bottom = -1
for at in 0..<s.entity_count():
if bottom < 0 and s.kind(at) == names.line_kind:
bottom = at
let slant = s.add_line(s.add_point(5.0, -14.0), s.add_point(35.0, -6.0))
_ = s.constrain(names.parallel, slant, bottom)
_ = s.solve()
open_sketch(editor, s.text(), 20.0, -2.0, 80.0)
elif scene == "cad_window":
let plate = CadSketch.parse(sketch_commands.rectangle_text(20.0, -10.0, 40.0, 20.0))
_ = plate.add_circle(plate.add_point(12.0, -10.0), 5.0)
open_sketch(editor, plate.text(), 20.0, -10.0, 80.0)
selection_commands.set_mode(editor.workspace, 2)
editor.panels.refresh()
elif scene == "cad_profiles":
holed_plate(editor)
elif scene == "cad_extrude":
holed_plate(editor)
editor.panels.actions.extrude_profiles.trigger()
look(editor, 0.35, 0.6, 110.0, Vector3(20.0, 5.0, 10.0))
editor.panels.refresh()
elif scene == "cad_face_menu":
let w = editor.workspace
node_commands.delete_selected(w)
node_commands.add_node(w, "CAD", 40.0, 40.0)
node_commands.enter_group(w, w.network.selected)
node_commands.add_node(w, "Solid Box", 40.0, 40.0)
look(editor, 0.5, 0.6, 75.0, Vector3())
selection_commands.set_mode(w, w.level_of(2))
editor.panels.refresh()
elif scene in ["cad_dims", "cad_dim_edit"]:
open_sketch(editor, dimensioned_plate(), 30.0, 13.0, 95.0)
elif scene == "cad_typing":
open_sketch(editor, "", 12.0, 8.0, 70.0)
editor.panels.view.sketch.editor.choose("Line")
elif scene in ["cad_face_sketch", "cad_lost"]:
box_face_sketch(editor)
let w = editor.workspace
let e = editor.panels.view.sketch.editor
let s = e.sketch else trap("no sketch")
let loop: list[int] = []
for at in 0..<s.entity_count():
if s.kind(at) == names.line_kind and s.linked(at):
loop.append(at)
_ = s.offset(loop, 3.0, 0.0, 0.0, relation = true)
_ = s.solve()
if scene == "cad_lost":
s.link_to(loop[0], "gone")
node_commands.set_text(w, 0, s.text())
e.sync()
look(editor, 0.4, 0.9, 60.0, Vector3(0.0, 10.0, 0.0))
editor.panels.refresh()
elif scene == "cad_face_open":
let w = editor.workspace
node_commands.delete_selected(w)
node_commands.add_node(w, "CAD", 40.0, 40.0)
node_commands.enter_group(w, w.network.selected)
node_commands.add_node(w, "Solid Box", 40.0, 40.0)
look(editor, 0.5, 0.6, 75.0, Vector3())
selection_commands.set_mode(w, w.level_of(2))
editor.panels.refresh()
elif scene == "cad_slice":
let w = editor.workspace
node_commands.delete_selected(w)
node_commands.add_node(w, "CAD", 40.0, 40.0)
node_commands.enter_group(w, w.network.selected)
node_commands.add_node(w, "Solid Box", 40.0, 40.0)
node_commands.add_node(w, "Sketch", 40.0, 140.0)
node_commands.set_parameter(w, 0, 0.0)
node_commands.set_text(w, 0, sketch_commands.rectangle_text(0.0, 0.0, 12.0, 8.0))
node_commands.display_selected(w)
cad_commands.toggle_slice(w)
editor.panels.refresh()
# Looked at from the side once the sketch is entered (which looks
# straight at it).
editor.panels.view.sketch.editor.sync()
look(editor, 0.7, 0.45, 75.0, Vector3())
editor.panels.refresh()
elif scene in ["cad_origin", "cad_typed"]:
open_sketch(editor, "", 15.0, 10.0, 90.0)
elif scene == "cad_conflict":
open_sketch(editor, dimensioned_plate(), 30.0, 13.0, 95.0)
elif scene in ["cad_project_face", "cad_project_body", "cad_project_silhouette"]:
let w = editor.workspace
node_commands.delete_selected(w)
node_commands.add_node(w, "CAD", 40.0, 40.0)
node_commands.enter_group(w, w.network.selected)
node_commands.add_node(w, "Solid Cylinder" if scene == "cad_project_silhouette" else "Solid Box", 40.0, 40.0)
node_commands.add_node(w, "Sketch", 40.0, 140.0)
if scene == "cad_project_silhouette":
node_commands.set_parameter(w, 0, 0.0)
node_commands.set_parameter(w, 1, 20.0)
node_commands.display_selected(w)
editor.panels.refresh()
let e = editor.panels.view.sketch.editor
e.sync()
if scene == "cad_project_silhouette":
look(editor, 0.25, 0.3, 90.0, Vector3(0.0, 0.0, 10.0))
else:
look(editor, 0.5, 0.9, 80.0, Vector3(0.0, 10.0, 0.0))
e.choose("Project")
editor.panels.refresh()
elif scene == "cad_auto":
cut_box(editor)
look(editor, 0.5, 0.6, 75.0, Vector3())
editor.panels.refresh()
elif scene in ["cad_rollback", "cad_marking", "cad_edge_menu"]:
cut_box(editor)
let w = editor.workspace
if scene == "cad_edge_menu":
selection_commands.set_mode(w, w.level_of(4))
else:
let extrude = w.network.selected
node_commands.select_node(w, w.network.require(extrude).inputs[0])
look(editor, 0.5, 0.6, 75.0, Vector3())
editor.panels.refresh()
## Frame `frame` of scene `scene` (from 2; `last` is the frame captured).
pub func act(editor: Luce3D, scene: str, frame: int, last: int) -> unit!:
if scene in preview_features.scenes():
preview_features.act(editor, scene, frame, last)
return
if scene in preview_direct.scenes():
preview_direct.act(editor, scene, frame, last)
return
if scene in preview_history.scenes():
preview_history.act(editor, scene, frame, last)
return
if scene in preview_tutorial.scenes():
preview_tutorial.act(editor, scene, frame, last)
return
if scene in preview_kernel.scenes():
preview_kernel.act(editor, scene, frame, last)
return
let w = editor.workspace
let view = editor.panels.view
let area = view.layout().bounds()
let e = view.sketch.editor
if scene == "cad_glyphs" and frame == last - 1:
let sketch = e.sketch else trap("no sketch")
for g in e.placed_glyphs(area.width, area.height):
if sketch.constraint_kind(g.constraint) == names.parallel:
let x = area.x + g.box.x + g.box.width * 0.5
let y = area.y + g.box.y + g.box.height * 0.5
editor.app.dispatch(Event(kind = EventKind.pointer_moved, x = x, y = y))
editor.app.dispatch(Event(kind = EventKind.pointer_down, x = x, y = y, button = 1))
editor.app.dispatch(Event(kind = EventKind.pointer_up, x = x, y = y, button = 1))
if scene == "cad_profiles" and frame == last - 1:
let at = project(w, e.frame.at(10.0, -10.0), area.width, area.height)
editor.app.dispatch(Event(kind = EventKind.pointer_moved, x = area.x + at[0], y = area.y + at[1]))
if scene == "cad_face_menu" and frame == last - 1:
right_click(editor, Vector3(3.0, 10.0, 2.0))
if scene == "cad_rollback" and frame == last - 1:
right_click(editor, Vector3(6.0, 10.0, -6.0))
if scene == "cad_marking" and frame == last - 1:
let at = project(w, Vector3(0.0, 10.0, 0.0), area.width, area.height)
editor.app.dispatch(Event(kind = EventKind.pointer_moved, x = area.x + at[0], y = area.y + at[1]))
editor.app.dispatch(Event(kind = EventKind.key_down, key = Key.a))
if scene == "cad_edge_menu" and frame == last - 1:
right_click(editor, Vector3(10.0, 10.0, 3.0))
if scene == "cad_window" and frame == last - 1:
# Right to left over the top-left corner and the whole hole.
let a = project(w, e.frame.at(19.0, -17.0), area.width, area.height)
let b = project(w, e.frame.at(-3.0, 3.0), area.width, area.height)
editor.app.dispatch(Event(kind = EventKind.pointer_moved, x = area.x + a[0], y = area.y + a[1]))
editor.app.dispatch(Event(kind = EventKind.pointer_down, x = area.x + a[0], y = area.y + a[1], button = 0))
editor.app.dispatch(Event(kind = EventKind.pointer_moved, x = area.x + b[0], y = area.y + b[1]))
editor.app.dispatch(Event(kind = EventKind.pointer_up, x = area.x + b[0], y = area.y + b[1], button = 0))
# And again, held, to show the box over what it took.
editor.app.dispatch(Event(kind = EventKind.pointer_down, x = area.x + a[0], y = area.y + a[1], button = 0, shift = true))
editor.app.dispatch(Event(kind = EventKind.pointer_moved, x = area.x + b[0], y = area.y + b[1], shift = true))
if scene in ["cad_dims", "cad_dim_edit"] and frame == last - 1:
let sketch = e.sketch else trap("no sketch")
_ = e.dimensions.placed(w, sketch, e.frame, e.revision, area.width, area.height)
let width = e.dimensions.find(5) else trap("no width dimension")
let x = area.x + width.box.x + width.box.width * 0.5
let y = area.y + width.box.y + width.box.height * 0.5
let clicks = 2 if scene == "cad_dim_edit" else 0
for _ in 0..<clicks:
for kind in [EventKind.pointer_moved, EventKind.pointer_down, EventKind.pointer_up]:
editor.app.dispatch(Event(kind = kind, x = x, y = y, button = 0))
editor.app.dispatch(Event(kind = EventKind.pointer_moved, x = x, y = y))
if scene == "cad_typing" and frame == last - 1:
let start = project(w, e.frame.at(0.0, 0.0), area.width, area.height)
let toward = project(w, e.frame.at(16.0, 9.0), area.width, area.height)
for kind in [EventKind.pointer_moved, EventKind.pointer_down, EventKind.pointer_up]:
editor.app.dispatch(Event(kind = kind, x = area.x + start[0], y = area.y + start[1], button = 0))
editor.app.dispatch(Event(kind = EventKind.pointer_moved, x = area.x + toward[0], y = area.y + toward[1]))
type_text(editor, "25")
editor.app.dispatch(Event(kind = EventKind.key_down, key = Key.tab))
# The tool's hint is no failure.
w.notice = ""
if scene == "cad_origin" and frame == last - 1:
let at = func (x: float, y: float) -> list[float]!:
let s = project(w, e.frame.at(x, y), area.width, area.height)
return [area.x + s[0], area.y + s[1]]
let clicked = func (x: float, y: float) -> unit!:
let p = at(x, y)
for kind in [EventKind.pointer_moved, EventKind.pointer_down, EventKind.pointer_up]:
editor.app.dispatch(Event(kind = kind, x = p[0], y = p[1], button = 0))
e.choose("Line")
clicked(10.0, 5.0)
let toward = at(20.0, 16.0)
editor.app.dispatch(Event(kind = EventKind.pointer_moved, x = toward[0], y = toward[1]))
type_text(editor, "30")
editor.app.dispatch(Event(kind = EventKind.key_down, key = Key.tab))
type_text(editor, "40")
editor.app.dispatch(Event(kind = EventKind.key_down, key = Key.enter))
editor.app.dispatch(Event(kind = EventKind.key_down, key = Key.escape))
e.choose("Sketch Dimension")
clicked(10.0, 5.0)
clicked(25.0, 0.0)
clicked(4.0, -4.0)
if editor.panels.sketch_value.is_open():
editor.app.dispatch(Event(kind = EventKind.key_down, key = Key.escape))
e.choose("Sketch Dimension")
let over = at(0.0, 18.0)
editor.app.dispatch(Event(kind = EventKind.pointer_moved, x = over[0], y = over[1]))
w.notice = ""
if scene == "cad_typed" and frame == last - 1:
let at = func (x: float, y: float) -> list[float]!:
let s = project(w, e.frame.at(x, y), area.width, area.height)
return [area.x + s[0], area.y + s[1]]
let clicked = func (x: float, y: float) -> unit!:
let p = at(x, y)
for kind in [EventKind.pointer_moved, EventKind.pointer_down, EventKind.pointer_up]:
editor.app.dispatch(Event(kind = kind, x = p[0], y = p[1], button = 0))
e.choose("Center Point Arc")
clicked(6.0, 8.0)
let start = at(16.0, 10.0)
editor.app.dispatch(Event(kind = EventKind.pointer_moved, x = start[0], y = start[1]))
type_text(editor, "12")
editor.app.dispatch(Event(kind = EventKind.key_down, key = Key.enter))
let sweep = at(0.0, 20.0)
editor.app.dispatch(Event(kind = EventKind.pointer_moved, x = sweep[0], y = sweep[1]))
type_text(editor, "120")
editor.app.dispatch(Event(kind = EventKind.key_down, key = Key.enter))
e.choose("Circumscribed Polygon")
clicked(34.0, 10.0)
let side = at(42.0, 10.0)
editor.app.dispatch(Event(kind = EventKind.pointer_moved, x = side[0], y = side[1]))
type_text(editor, "8")
editor.app.dispatch(Event(kind = EventKind.key_down, key = Key.enter))
w.notice = ""
if scene == "cad_conflict" and frame == last - 1:
let at = func (x: float, y: float) -> list[float]!:
let s = project(w, e.frame.at(x, y), area.width, area.height)
return [area.x + s[0], area.y + s[1]]
e.choose("Sketch Dimension")
for place in [[30.0, 0.0], [30.0, -14.0]]:
let p = at(place[0], place[1])
for kind in [EventKind.pointer_moved, EventKind.pointer_down, EventKind.pointer_up]:
editor.app.dispatch(Event(kind = kind, x = p[0], y = p[1], button = 0))
# The over-constraint's notice is what the scene shows, no failure.
assert(w.notice.contains("over-constrain"))
w.notice = ""
if scene in ["cad_project_face", "cad_project_body", "cad_project_silhouette"] and frame == last - 1:
if scene in ["cad_project_body", "cad_project_silhouette"]:
e.project_body()
else:
let p = project(w, Vector3(10.0, 20.0, 3.0), area.width, area.height)
for kind in [EventKind.pointer_moved, EventKind.pointer_down, EventKind.pointer_up]:
editor.app.dispatch(Event(kind = kind, x = area.x + p[0], y = area.y + p[1], button = 0))
# Project again (a tool is used once), the pointer in the face.
e.choose("Project")
let inside = project(w, Vector3(3.0, 20.0, -2.0), area.width, area.height)
editor.app.dispatch(Event(kind = EventKind.pointer_moved, x = area.x + inside[0], y = area.y + inside[1]))
if w.notice != "":
print(f"project scene: {w.notice}")
w.notice = ""
# Once the cook (the worker's, with --background) gave the pick mesh:
# the top face selected and a Sketch made on it.
if scene == "cad_face_open" and not w.sketching() and frame < last - 1:
if let mesh = preview_support.shown(w):
for face in 0..<mesh.face_count():
if mesh.face_center(face).y > 9.99:
selection_commands.choose_component(w, face, false)
break
editor.panels.refresh()
editor.panels.actions.sketch_on_face.trigger()