Luce packages
LuceLuce BaseLuciaOS

dymokomi/luced-3d

Source of release 0.11.9

0.11.9 / src / panels.luc

## The editor's window: the viewport, network, inspector, spreadsheet,
## outliner, render view and takes docked together, with the status line,
## the node search, the shading menu, the sketch's value and text boxes,
## the tool bar and the viewport's tool shelf (its panel's footer); it
## routes refreshes to them. Nothing polls: a change to the workspace
## refreshes them once a turn (catch_up), the compute worker's and Script
## checks' notifiers bring their results, a timed wait (a press held, a pause
## in typing) asks for one turn when due, and frames are drawn one after
## another only while something moves on by itself (playing, rendering).
from luce_ui.ui import Application, VStack, HStack, Text, TextField, Font, Button, ButtonStyle, Spacer, DStack, Panel, DockPosition, Size, ScrollView, Menu, TextPrompt, ContextMenu, Point
from dock_layout import DockLayout
from project_session import ProjectSession
from node_menu import NodeMenu
from interop import Connection
from workspace import Workspace
from view import SceneViewport
from network_view import NetworkView
from inspector import Inspector
from actions import Actions
from network import kinds
from geometry_sheet import GeometrySheet
from outliner import Outliner
from shading_menu import ShadingMenu
from sketch_value import SketchValue
from tool_bar import ToolBar
from tool_shelf import ToolShelf
from timeline_pane import TimelinePane
from project_settings import ProjectSettings
from luce_gpu.gpu import Rect
import sketch_commands
import sketch_source
import modeling_commands
from render_view import RenderView
from takes_pane import TakesList
import node_commands
import node_room
from icon_shelf import IconShelf
from cad_timeline import CadTimeline
from node_path_picker import NodePathPicker
import take_commands
import time
from top_menus import TopMenus
from node_context_menu import NodeContextMenu
from viewport_menu import ViewportMenu
import selection_commands

## The shortest time between the frames drawn while something moves on.
let frame_seconds: float = 1.0 / 120.0

pub class Panels:
    ## The application, for a turn asked at a time (`wake`) and the frames
    ## drawn while something moves on (`animate`): none headless.
    pub var app: Application? = none
    ## When the turn asked last is due (0: none asked).
    var wake_at: int = 0
    ## The frame callback while something moves on by itself (`animate`).
    var frames: Connection? = none
    ## Told when something the editor's settings keep may have changed (the
    ## workspace, a view, the panels' layout).
    pub var on_settings: func() -> unit!? = none
    pub let body: VStack
    pub let view: SceneViewport
    pub let graph: NetworkView
    pub let inspector: Inspector
    pub let spreadsheet: GeometrySheet
    pub let outliner: Outliner
    pub let render_view: RenderView
    pub let takes: TakesList
    let take_name: TextField
    let path: Text
    ## The Network panel's Up button and bottom toolbar.
    let up: Button
    pub let network_tools: IconShelf
    ## The CAD timeline strip (cad_timeline.luc).
    pub let cad_timeline: CadTimeline
    ## The Outliner's search field.
    pub let outliner_search: TextField
    ## The Import node's object menu.
    pub let node_path_picker: NodePathPicker
    pub let search: NodeMenu
    pub let shading: ShadingMenu
    let context_anchor: Text
    pub let context_menu: ContextMenu
    ## A new sketch dimension's value box.
    pub let sketch_value: SketchValue
    ## The Edit node's last tool step's parameters, along the viewport's bottom.
    pub let tool_bar: ToolBar
    ## The viewport's tool shelf, along its bottom (tool_shelf.luc).
    pub let shelf: ToolShelf
    ## The timeline along the bottom.
    pub let timeline: TimelinePane
    pub let project_settings: ProjectSettings
    ## What the sketch's Text tool says.
    pub let sketch_text: TextPrompt
    ## The network's and Outliner's right-click menu.
    pub let node_menu: NodeContextMenu
    ## The viewport's right-click menu.
    pub let viewport_menu: ViewportMenu
    ## Modify › Rename… (F2): the selected node's new name.
    pub let rename_prompt: TextPrompt
    pub let actions: Actions
    ## The menu bar's Create and Modify menus.
    pub let menus: TopMenus
    pub let dock: DStack
    pub let dock_layout: DockLayout
    pub let projects: ProjectSession
    pub let status: Text
    pub let workspace: Workspace
    let connections: list[Connection]
    var shown_revision: int = -1
    ## Refreshes so far (tests, and the idle probe: none while idle).
    pub var refreshes: int = 0
    var shown_scope: int = -2
    var add_x: float = 70.0
    var add_y: float = 70.0
    ## The node menu was opened over the viewport: its Group groups the
    ## objects picked there, even one.
    var from_viewport: bool = false
    ## The menu adding a node (Tab, a marking menu) placed it at add_x/add_y;
    ## otherwise (the Create menu) it goes where place_added says.
    var placed: bool = false
    ## Where the node menu was opened on the network (graph coordinates):
    ## its Paste puts the nodes there.
    var paste_at: Point? = none

    pub func init(self, workspace: Workspace, font: Font) -> unit!:
        self.workspace = workspace
        self.connections = []
        self.actions = Actions(workspace)
        self.view = SceneViewport(workspace, self.actions)
        self.graph = NetworkView(workspace, self.actions, font)
        self.projects = ProjectSession(workspace, self.graph, self.actions, font)
        self.projects.refreshed = self.refresh
        self.graph.on_search = self.open_search
        self.graph.on_inspect = self.inspect_node
        self.graph.on_menu = self.open_network_menu
        self.inspector = Inspector(workspace, self.actions, font)
        self.spreadsheet = GeometrySheet(workspace)
        self.outliner = Outliner(workspace, font)
        self.outliner.on_menu = self.open_outliner_menu
        self.render_view = RenderView(self.workspace.display)
        self.takes = TakesList(workspace, font)
        self.take_name = TextField("", font = font, placeholder = "Take name", cells = 12.0)
        self.search = NodeMenu(self.actions.add)
        self.shading = ShadingMenu(workspace)
        self.view.on_shading = self.open_shading
        self.view.on_context_menu = self.open_context_menu
        self.sketch_value = SketchValue(workspace, font)
        self.tool_bar = ToolBar(workspace, font)
        self.shelf = ToolShelf(workspace, self.actions, self.view.sketch.editor, self.view.tools.chrome.shelf, self.view.layout())
        self.view.tools.chrome.on_shelf = self.shelf.refresh
        self.timeline = TimelinePane(workspace, self.actions, font)
        self.timeline.on_play = self.animate
        self.project_settings = ProjectSettings(workspace, font)
        self.project_settings.applied = self.refresh
        self.connections.append(self.actions.project_settings.on_trigger(self.project_settings.open))
        self.sketch_text = TextPrompt(font)
        self.connections.append(self.sketch_text.on_submit(self.view.sketch.editor.place_text))
        self.view.sketch.editor.on_text = func () -> unit!: self.sketch_text.open("Sketch text", accept = "Place")
        self.rename_prompt = TextPrompt(font)
        self.connections.append(self.rename_prompt.on_submit(func (name: str) -> unit!:
            node_commands.rename(workspace, name)
            self.refresh()))
        self.connections.append(self.actions.rename.on_trigger(func () -> unit!:
            if let node = workspace.selected():
                self.rename_prompt.open("Rename " + node.name, node.name, accept = "Rename")))
        self.view.sketch.editor.on_ask = self.ask_sketch_value
        self.view.sketch.editor.on_value = self.open_sketch_value
        self.view.sketch.editor.on_click = self.sketch_value.dismiss
        self.view.on_search = self.open_viewport_search
        self.view.on_add = self.add_from_viewport
        self.view.on_wait = self.wake
        self.view.on_input = self.settings_changed
        self.view.on_resized = self.resized
        self.inspector.wait_with(self.wake)
        self.search.on_close = func () -> unit!: self.placed = false
        let types = kinds()
        for index in 0..<types.length:
            let kind = types[index]
            self.connections.append(self.actions.add[index].on_trigger(func () -> unit!:
                # Group with nodes picked (two, or any over the viewport)
                # groups them; otherwise it adds an empty Group.
                if not self.placed:
                    self.place_added()
                self.placed = false
                let picked = workspace.network.selection().length
                if kind == "Group" and (picked >= 2 or (self.from_viewport and picked >= 1)):
                    node_commands.group_selected(workspace)
                else:
                    node_commands.add_node(workspace, kind, self.add_x, self.add_y)
                self.refresh()))
        self.connections.append(self.actions.add_node.on_trigger(self.open_search))
        self.connections.append(self.actions.paste.on_trigger(self.paste_nodes))
        self.connections.append(self.actions.frame_nodes.on_trigger(self.graph.frame_all))
        self.menus = TopMenus(workspace, self.actions, font)
        let header = HStack([
            Menu("File", [self.actions.new_project, self.actions.open_project, self.actions.save, self.actions.save_as], font = font),
            self.menus.create, self.menus.modify,
            Menu("Window", [self.actions.project_settings, self.actions.reset_layout, self.actions.four_views, self.actions.full_screen], font = font),
            Button(action = self.actions.undo, font = font), Button(action = self.actions.redo, font = font), Spacer(), self.projects.caption
        ], spacing = 4.0, padding = 4.0)
        let viewport = Panel("Viewport", self.view, minimum = Size(440.0, 270.0), closable = false, footer = self.shelf, id = "viewport")
        let parameters = Panel("Parameters", ScrollView(self.inspector.body), minimum = Size(330.0, 180.0), closable = false, id = "parameters")
        # The Network panel: where it is along the top (Up, the path), its
        # tools along the bottom, as luced-2d's panels have them.
        self.path = Text("/ scene", font = font, muted = true)
        self.up = Button(icon = "arrow-up", font = font)
        self.up.set_style(ButtonStyle.plain)
        self.connections.append(self.up.on_click(func () -> unit!: self.actions.parent.trigger()))
        let network_header = HStack([self.up, self.path, Spacer()], spacing = 4.0, padding = 4.0)
        self.network_tools = IconShelf([("add-node", self.actions.add_node), ("group-nodes", self.actions.group), ("output-node", self.actions.set_output)],
                                       [("frame-selection", self.actions.frame_nodes)], font)
        # Inside a CAD network, the timeline strip over the tools.
        self.cad_timeline = CadTimeline(workspace)
        let network_body = VStack([network_header, self.graph, self.cad_timeline], spacing = 0.0)
        network_body.layout().set_flex()
        let network = Panel("Network", network_body, minimum = Size(460.0, 250.0), closable = false, footer = self.network_tools.body, id = "network")
        self.dock = DStack([viewport], font = font)
        self.dock.add(parameters, viewport, DockPosition.right)
        self.dock.set_fraction(viewport, 0.75)
        let rendered = Panel("Render", self.render_view, minimum = Size(440.0, 270.0), closable = false, id = "render")
        self.dock.add(rendered, viewport, DockPosition.tab)
        self.dock.select(viewport)
        self.dock.add(network, viewport, DockPosition.bottom)
        self.dock.set_fraction(viewport, 0.63)
        # The Outliner, its search field at the top: matching rows and their
        # parents list as you type.
        self.outliner_search = TextField("", font = font, placeholder = "Search objects", cells = 12.0)
        self.outliner_search.layout().set_flex()
        self.connections.append(self.outliner_search.on_change(func (text: str) -> unit!: self.outliner.search(text)))
        let search_icon = Button(icon = "search", font = font)
        search_icon.set_style(ButtonStyle.plain)
        self.connections.append(search_icon.on_click(func () -> unit!: self.outliner_search.layout().request_focus()))
        let outliner_body = VStack([HStack([search_icon, self.outliner_search], spacing = 2.0, padding = 4.0), self.outliner], spacing = 0.0)
        outliner_body.layout().set_flex()
        let outliner = Panel("Outliner", outliner_body, minimum = Size(260.0, 150.0), closable = false, id = "outliner")
        self.dock.add(outliner, parameters, DockPosition.top)
        self.dock.set_fraction(outliner, 0.32)
        let new_take = Button("New", font = font)
        let delete_take = Button("Delete", font = font)
        self.connections.append(self.take_name.on_commit(func (name: str) -> unit!: take_commands.rename_take(workspace, name)))
        self.connections.append(new_take.on_click(func () -> unit!: take_commands.add_take(workspace)))
        self.connections.append(delete_take.on_click(func () -> unit!: take_commands.remove_take(workspace)))
        let takes_body = VStack([HStack([self.take_name, Spacer(), new_take, delete_take], spacing = 4.0, padding = 4.0), self.takes], spacing = 0.0)
        takes_body.layout().set_flex()
        let takes = Panel("Takes", takes_body, minimum = Size(260.0, 150.0), closable = false, id = "takes")
        self.dock.add(takes, outliner, DockPosition.tab)
        self.dock.select(outliner)
        let attributes = TextField("", font = font, placeholder = "Filter attributes", cells = 12.0)
        let rows = TextField("", font = font, placeholder = "Rows: * / 0-8 / @group", cells = 16.0)
        self.connections.append(attributes.on_commit(self.spreadsheet.filter_attributes))
        self.connections.append(rows.on_commit(self.spreadsheet.filter_rows))
        let sheet_body = VStack([HStack([attributes, rows], spacing = 4.0, padding = 4.0), self.spreadsheet], spacing = 0.0)
        sheet_body.layout().set_flex()
        let spreadsheet = Panel("Geometry Spreadsheet", sheet_body, minimum = Size(460.0, 200.0), closable = false, id = "geometry_spreadsheet")
        self.dock.add(spreadsheet, network, DockPosition.tab)
        self.dock.select(network)
        self.dock_layout = DockLayout(self.dock, [viewport, rendered, parameters, outliner, takes, network, spreadsheet])
        self.connections.append(self.actions.reset_layout.on_trigger(self.dock_layout.reset))
        self.connections.append(self.dock.on_select(func (panel: Panel) -> unit!: self.settings_changed()))
        self.connections.append(self.dock.on_close(func (panel: Panel) -> unit!: self.settings_changed()))
        self.dock.layout().set_flex()
        self.status = Text("", font = font, muted = true)
        # The context display menu, anchored on an empty label in the footer
        # and opened over the viewport's button (open_context_menu).
        self.context_anchor = Text("", font = font)
        self.context_menu = ContextMenu(self.context_anchor, self.actions.context_modes, font = font)
        self.node_path_picker = NodePathPicker(workspace, font)
        self.node_path_picker.chosen = self.refresh
        self.node_menu = NodeContextMenu(workspace, self.actions, font)
        self.viewport_menu = ViewportMenu(workspace, self.actions, self.view.sketch.editor, font)
        self.view.on_menu = self.open_viewport_menu
        self.connections.append(self.node_menu.menu.on_close(self.node_menu_closed))
        # The viewport's menu hid the step's tool bar: it shows again.
        self.connections.append(self.viewport_menu.menu.on_close(func () -> unit!: self.tool_bar.refresh(false)))
        let footer = HStack([self.status, self.context_menu, self.node_path_picker.menu, self.node_menu.menu, self.viewport_menu.menu], padding = 6.0)
        self.body = VStack([header, self.dock, self.timeline.body, footer, self.search, self.shading, self.sketch_value.body, self.tool_bar.body, self.sketch_text, self.rename_prompt, self.project_settings.dialog, self.projects.confirm], spacing = 0.0)
        self.body.layout().set_flex()
        self.refresh()

    ## The node menu over the viewport, at its pointer; nodes it adds go
    ## below the network's selected node.
    pub func open_viewport_search(self) -> unit!:
        self.from_viewport = true
        self.placed = true
        if let node = self.workspace.selected():
            self.add_x = node.x
            self.add_y = node.y + node_room.row
        let view_bounds = self.view.pane_bounds()
        let body_bounds = self.body.layout().bounds()
        self.search.open(view_bounds.x - body_bounds.x + self.view.pointer_x, view_bounds.y - body_bounds.y + self.view.pointer_y, self.workspace.network.context(), self.workspace.network.has_inputs(self.workspace.network.scope))

    ## A marking menu's node `kind`: added below the selected node (wired
    ## to it), as the viewport's Tab menu adds.
    pub func add_from_viewport(self, kind: str) -> unit!:
        self.from_viewport = true
        self.placed = true
        if let node = self.workspace.selected():
            self.add_x = node.x
            self.add_y = node.y + node_room.row
        let index = kinds().index_of(kind) else return
        self.actions.add[index].trigger()

    pub func open_search(self) -> unit!:
        self.from_viewport = false
        self.placed = true
        self.add_at(self.graph.pointer_x, self.graph.pointer_y)
        let graph_bounds = self.graph.layout().bounds()
        let body_bounds = self.body.layout().bounds()
        self.search.open(graph_bounds.x - body_bounds.x + self.graph.pointer_x, graph_bounds.y - body_bounds.y + self.graph.pointer_y, self.workspace.network.context(), self.workspace.network.has_inputs(self.workspace.network.scope))

    ## A right click on the network view, on node `id` (-1: the canvas): the
    ## node menu at the pointer; its Paste and Create put nodes there.
    pub func open_network_menu(self, id: int) -> unit!:
        let x = self.graph.pointer_x
        let y = self.graph.pointer_y
        self.paste_at = self.graph.to_graph(x, y)
        if id < 0:
            self.from_viewport = false
            self.placed = true
            self.add_at(x, y)
        let bounds = self.graph.layout().bounds()
        self.refresh()
        self.node_menu.open(bounds.x + x, bounds.y + y, id >= 0)

    ## A right click on the viewport at (`x`, `y`) of it: its menu there.
    ## What is under the pointer, when nothing is selected, is selected first:
    ## the menu is for it.
    func open_viewport_menu(self, x: float, y: float) -> unit!:
        let w = self.workspace
        let hovered = self.view.tools.hovered
        if not w.sketching() and w.hovered_sketch == "" and w.selecting() and not w.picking_objects() and w.selected_count() == 0 and hovered >= 0:
            selection_commands.choose_component(w, hovered, false)
        self.refresh()
        let bounds = self.view.pane_bounds()
        self.viewport_menu.open(bounds.x + x, bounds.y + y)
        self.tool_bar.refresh(true)

    ## A right click on node `id`'s row in the Outliner, at (`x`, `y`) in
    ## window points: the node menu there.
    func open_outliner_menu(self, id: int, x: float, y: float) -> unit!:
        self.paste_at = none
        self.refresh()
        self.node_menu.open(x, y, true)

    ## Paste: where the node menu opened on the network, else at the pointer
    ## over the network view, else in its middle.
    func paste_nodes(self) -> unit!:
        let bounds = self.graph.layout().bounds()
        var at = self.graph.to_graph(bounds.width * 0.5, bounds.height * 0.5)
        if self.graph.pointer_inside:
            at = self.graph.to_graph(self.graph.pointer_x, self.graph.pointer_y)
        if let point = self.paste_at:
            at = point
        self.paste_at = none
        self.actions.clipboard.paste(self.workspace, at.x, at.y)
        self.refresh()

    ## A node added at (`x`, `y`) of the network view; repeated additions at
    ## an unchanged point do not bury a node.
    func add_at(self, x: float, y: float):
        let at = self.graph.to_graph(x, y)
        self.add_x = at.x
        self.add_y = at.y
        for node in self.workspace.network.local_nodes():
            if self.add_x >= node.x - 96.0 and self.add_x <= node.x + 260.0 and self.add_y >= node.y - 40.0 and self.add_y <= node.y + 60.0:
                self.add_x = node.x
                self.add_y = node.y + node_room.row

    ## Where a node added from the menu bar goes: below the selected node
    ## (which it is wired to), as the viewport's Tab menu adds; with nothing
    ## selected, in the middle of the network view.
    func place_added(self):
        self.from_viewport = false
        if let node = self.workspace.selected():
            self.add_x = node.x
            self.add_y = node.y + node_room.row
            return
        let bounds = self.graph.layout().bounds()
        self.add_at(bounds.width * 0.5, bounds.height * 0.5)

    ## A sketch tool asks for a length: the value box opens at the pointer.
    func ask_sketch_value(self, label: str, value: float, answer: func(float) -> unit!) -> unit!:
        let bounds = self.view.pane_bounds()
        let root = self.body.layout().bounds()
        let e = self.view.sketch.editor
        self.sketch_value.ask(label, value, bounds.x - root.x + e.pointer_x + 16.0, bounds.y - root.y + e.pointer_y + 16.0, answer)

    ## Sketch Dimension placed dimension `constraint` at (`x`, `y`) of the
    ## viewport: its value box opens there.
    ## On a label (`inline`), the field alone covers it.
    func open_sketch_value(self, constraint: int, x: float, y: float, inline: bool) -> unit!:
        let node = self.workspace.selected() else return
        let bounds = self.view.pane_bounds()
        let root = self.body.layout().bounds()
        let name = self.workspace.edit_sketch if node.id == self.workspace.edit_sketch_node else ""
        for d in sketch_commands.dimensions(sketch_source.edited_text(node, name)):
            if d.constraint == constraint:
                let inset = 6.0 if inline else 0.0
                self.sketch_value.open(node.id, constraint, d.name, d.value, d.angle, bounds.x - root.x + x - inset, bounds.y - root.y + y - inset, named = not inline)

    ## A feature's value box by its handle: wanted when the feature was just
    ## made from the viewport (its first handle's, once its cook placed
    ## the handles; never when it failed) or a handle was clicked. Its
    ## typed value is the handle's row.
    func ask_value(self) -> unit!:
        let w = self.workspace
        let handles = self.view.arrow
        var slot = handles.take_click()
        if w.ask_value:
            let node = w.selected() else return
            if node.failure != "":
                w.ask_value = false
                return
            if not handles.active():
                return
            w.ask_value = false
            slot = handles.first_slot()
        if slot < 0:
            return
        let target = handles.feature() else return
        let id = target.node.id
        let wanted = slot
        let bounds = self.view.pane_bounds()
        let root = self.body.layout().bounds()
        let tip = handles.tip(bounds.width, bounds.height, slot) else [bounds.width * 0.5, bounds.height * 0.5]
        let label = handles.row_name(target.kind, slot)
        let (least, most) = handles.range(target.kind, slot)
        let step = target.step
        # A node's row, or an Edit CAD step's number (its tool bar's row).
        let answer = func (value: float) -> unit!:
            if w.network.selected == id:
                if step:
                    modeling_commands.set_last_step(w, wanted, value, least, most)
                else:
                    node_commands.set_parameter(w, wanted, value)
        self.sketch_value.ask(label, target.values[slot], bounds.x - root.x + tip[0] + 22.0, bounds.y - root.y + tip[1] - 34.0, answer, angle = handles.is_angle(slot))

    ## The context display modes' menu under its viewport button; `held` when
    ## a long press opens it (letting go over a mode chooses it).
    func open_context_menu(self, held: bool) -> unit!:
        self.actions.refresh()
        let anchor = self.context_anchor.layout().bounds()
        let button = self.view.context_button()
        self.context_menu.open_at(button.x - anchor.x, button.y + button.height + 4.0 - anchor.y, held = held)

    func open_shading(self, held: bool) -> unit!:
        let bounds = self.view.pane_bounds()
        let root = self.body.layout().bounds()
        self.shading.open(bounds.x - root.x + bounds.width - 282.0, bounds.y - root.y + 42.0, held)

    pub func inspect_node(self, id: int) -> unit!:
        node_commands.select_node(self.workspace, id)
        self.spreadsheet.pinned = -1
        if let panel = self.dock.find("geometry_spreadsheet"):
            self.dock.select(panel)
        self.refresh()

    ## Render the selected Render node's input in the Render panel.
    pub func render(self) -> unit!:
        let node = self.workspace.selected() else return
        if node.kind != "Render":
            return
        let data = self.workspace.network.evaluate_data(node.id) catch failure:
            self.report_error(failure.message)
            return
        let camera = self.workspace.network.render_camera(node) catch failure:
            self.report_error(f"Render: {failure.message}")
            return
        self.render_view.start(data, node.values, camera) catch failure:
            self.report_error(f"Render: {failure.message}")
            return
        if let panel = self.dock.find("render"):
            self.dock.select(panel)
        self.refresh()

    pub func refresh(self) -> unit!:
        self.refreshes += 1
        self.apply_full_screen()
        self.projects.refresh()
        self.path.set_text(self.workspace.network.path())
        self.outliner.refresh()
        self.takes.refresh()
        if not self.take_name.layout().is_focused():
            self.take_name.set_text(self.workspace.network.takes[self.workspace.network.take].name)
        if self.shown_scope != self.workspace.network.scope:
            self.graph.reset_scope()
            self.shown_scope = self.workspace.network.scope
        self.actions.refresh()
        self.menus.refresh()
        self.spreadsheet.refresh()
        self.inspector.refresh()
        # The right-click menu over the viewport hides the step's tool bar,
        # which would draw over it.
        self.tool_bar.refresh(self.viewport_menu.is_open())
        self.place_tool_bar()
        self.shelf.refresh()
        self.network_tools.sync_enabled()
        self.up.layout().set_enabled(self.actions.parent.is_enabled())
        self.cad_timeline.sync()
        self.timeline.sync()
        self.view.follow_cameras()
        self.view.layout().invalidate()
        self.graph.layout().invalidate()
        self.ask_if_wanted()
        self.status.set_text(self.status_text())
        self.shown_revision = self.workspace.revision
        self.animate()

    ## The status line: the workspace's notice (a failure), else the
    ## displayed node's warning (an Edit step that could not be built), else
    ## the keys.
    func status_text(self) -> str:
        if self.workspace.notice != "":
            return self.workspace.notice
        if let node = self.workspace.network.find(self.workspace.network.display):
            if node.warning != "":
                return f"{node.name}: {node.warning}"
        return "A / S / D: create, modify, select   D in the network: display flag   B: bypass   Alt + mouse: camera   Cmd/Ctrl-Z: undo"

    ## The workspace changed (`Workspace.on_change`, heard once a turn):
    ## the panels show its new revision.
    pub func catch_up(self) -> unit!:
        if self.shown_revision != self.workspace.revision:
            self.refresh()
        self.settings_changed()

    ## The compute worker has a result or progress (its notifier): the
    ## workspace takes it, and the panels show it.
    pub func computed(self) -> unit!:
        if self.workspace.poll_compute():
            self.graph.layout().invalidate()
        self.catch_up()

    ## A Script check's sync or job ended (its notifier).
    pub func checked(self) -> unit!:
        self.inspector.poll_checks()

    ## Something the editor's settings keep may have changed.
    func settings_changed(self) -> unit!:
        if let changed = self.on_settings:
            changed()

    ## A feature's value box, when one is wanted and the viewport is laid
    ## out (so the box lands by its arrow).
    func ask_if_wanted(self) -> unit!:
        if (self.workspace.ask_value or self.view.arrow.clicked >= 0) and self.view.pane_bounds().width > 0.0:
            self.ask_value()

    ## The viewport drew at a new size: the tool bar follows it, a value
    ## box waiting for it opens, and the settings keep the window's size.
    func resized(self) -> unit!:
        self.place_tool_bar()
        self.ask_if_wanted()
        self.settings_changed()

    ## The network's or Outliner's menu closed: where it opened is spent.
    func node_menu_closed(self) -> unit!:
        self.paste_at = none
        self.placed = false

    ## Whether something moves on by itself: playing, or a render taking
    ## samples (the viewport's Render mode, the Render panel).
    func animating(self) -> bool:
        return self.timeline.bar.playing or self.view.rendering() or self.render_view.running()

    ## Draw frame after frame while something moves on by itself, and stop
    ## once nothing does: called when playing starts, a render's scene has
    ## compiled, and after each refresh.
    pub func animate(self) -> unit!:
        if self.frames != none or not self.animating():
            return
        let app = self.app else return
        self.frames = app.on_frame(self.frame)

    ## One of those frames: playing moves on, a render takes its next
    ## samples (its view draws again), and the next turn is asked for.
    func frame(self, elapsed: float) -> unit!:
        _ = elapsed
        if self.timeline.bar.playing:
            self.timeline.play_frame()
            self.view.layout().invalidate()
        if self.view.rendering():
            self.view.layout().invalidate()
        if self.render_view.running():
            self.render_view.layout().invalidate()
        if not self.animating():
            # One last draw: a render whose viewport settled after a resize
            # starts again at the new size there (its compile then wakes
            # the frames, `animate`).
            self.view.layout().invalidate()
            self.stop_frames()
            return
        # The next frame soon: at most 120 a second, enough for playing and
        # a render's samples (a present need not wait for the display, and
        # frames asked at once would spin).
        if let app = self.app:
            app.wake_after(frame_seconds)

    ## Whether frames are drawn one after another now (tests).
    pub func drawing_frames(self) -> bool:
        return self.frames != none

    func stop_frames(self):
        if let frames = self.frames:
            frames.disconnect()
        self.frames = none

    ## Ask the loop for one turn when the earliest timed wait is due (a
    ## press held, a pause in typing); their owners call this when one
    ## begins, and a quiet editor sleeps.
    func wake(self) -> unit!:
        let app = self.app else return
        let now = time.now()
        var soon = -1
        for left in [self.view.waits(now), self.inspector.waits(now)]:
            if left >= 0 and (soon < 0 or left < soon): soon = left
        if soon < 0:
            return
        let due = now + soon
        if self.wake_at != 0 and self.wake_at <= due and self.wake_at > now:
            return
        self.wake_at = due
        _ = app.after(float(soon) / 1000000000.0, func () -> unit!:
            self.wake_at = 0
            self.due())

    ## The waits that are due run, and the next one is asked for.
    func due(self) -> unit!:
        self.view.due()
        self.inspector.due()
        self.wake()

    ## The viewport filling the window (Space with F, Window › Full screen
    ## viewport): every other panel and the timeline hidden, their layout
    ## kept; or them back as they were.
    func apply_full_screen(self) -> unit!:
        let wanted = self.workspace.panes.full_screen
        if wanted == self.dock_layout.is_solo():
            return
        if wanted:
            self.dock_layout.solo("viewport")
        else:
            self.dock_layout.unsolo()
        self.timeline.body.layout().set_visible(not wanted)

    ## The tool bar follows the viewport (resized, docked elsewhere).
    func place_tool_bar(self) -> unit!:
        let view_bounds = self.view.pane_bounds()
        let body_bounds = self.body.layout().bounds()
        self.tool_bar.place(Rect(view_bounds.x - body_bounds.x, view_bounds.y - body_bounds.y, view_bounds.width, view_bounds.height))

    pub func report_error(self, message: str) -> unit!:
        self.workspace.notice = message
        self.refresh()

    pub func close(self):
        self.stop_frames()
        self.on_settings = none
        self.view.on_wait = none
        self.view.on_input = none
        self.view.on_resized = none
        self.search.on_close = none
        self.view.tools.objects.silhouette.close()
        self.projects.close()
        self.timeline.close()
        self.network_tools.close()
        self.project_settings.close()
        self.node_path_picker.close()
        self.view.on_shading = none
        self.view.on_context_menu = none
        self.view.sketch.editor.on_value = none
        self.view.sketch.editor.on_click = none
        self.view.sketch.editor.on_modify = none
        self.view.sketch.editor.on_finish = none
        self.view.sketch.editor.on_pick = none
        self.view.sketch.editor.on_constrain = none
        self.view.sketch.editor.on_text = none
        self.view.sketch.editor.on_ask = none
        self.sketch_value.disconnect()
        self.tool_bar.close()
        self.view.on_search = none
        self.view.on_add = none
        self.view.on_menu = none
        self.viewport_menu.close()
        self.view.tools.chrome.on_reuse = none
        self.view.tools.chrome.on_shelf = none
        self.view.tools.chrome.sketch_selected = none
        self.graph.on_search = none
        self.graph.on_inspect = none
        self.graph.on_menu = none
        self.outliner.on_menu = none
        for connection in self.connections:
            connection.disconnect()
        self.connections.clear()
        self.inspector.close()
        self.render_view.stop()
        self.view.stop_rendering()
        self.actions.close()