Skip to main content

geop_core_editor/tools/
mod.rs

1//! [`Tool`]: a mode in hand while no step is edited, which the events of
2//! the viewport go to — the drag tool of an assembly, the pick tool of an
3//! inspector ([`pick`]).
4//!
5//! A tool is no operation: what it does is no step. It may move the
6//! program's state, or ask about the part, and says what it changed as a
7//! command does ([`Changed`]).
8
9pub mod pick;
10
11use std::any::Any;
12
13use geop_core_math::geop_error::GeopResult;
14use serde::Serialize;
15
16use crate::{
17    editing::{Presentation, StepEditEvent},
18    editor::{Changed, EditorContext},
19    output::Inspection,
20};
21
22/// What a tool is to an editor: the key it is taken in hand by
23/// ([`crate::editor::Command::Tool`]), and how it is offered. A tool is no
24/// operation, so it is offered where the inspectors are — beside what asks
25/// about the part — not among the operations a step can be.
26#[derive(Clone, Debug, PartialEq, Serialize)]
27pub struct ToolInfo {
28    pub key: &'static str,
29    pub label: &'static str,
30    pub doc: &'static str,
31    /// What it is shown as: SVG on a 20 × 20 grid, as an operation's icon.
32    pub icon: Option<&'static str>,
33}
34
35/// A mode in hand while no step is edited: see the module docs. Taken in
36/// hand by its key, a fresh one each time (see
37/// [`crate::registry::Registry::tool`]).
38pub trait Tool: Any {
39    /// Something the user did in the viewport.
40    fn handle(&mut self, ctx: &mut EditorContext, event: &StepEditEvent) -> GeopResult<Changed>;
41
42    /// What it shows: what it would take lit, and whether a press grabs.
43    fn presentation(&self) -> Presentation;
44
45    /// What it answers about the part, with every update while it is in
46    /// hand: nothing, unless it says otherwise.
47    fn inspection(&mut self, _ctx: &mut EditorContext) -> GeopResult<Option<Inspection>> {
48        Ok(None)
49    }
50}