Skip to main content

kernel_api/
chain.rs

1//! What a chain build answers: the solid and its mesh, the preview, and the
2//! error naming the failing op.
3
4use serde::{Deserialize, Serialize};
5use thiserror::Error;
6
7use crate::*;
8
9/// Error from executing a body's solid-op chain, attributed to the failing
10/// step so the caller can mark the matching feature.
11#[derive(Debug, Clone, Default, Error)]
12#[error("op {op_index}: {message}")]
13pub struct ChainError {
14    pub op_index: usize,
15    pub message: String,
16    /// The edges a refused fillet or chamfer took, and those it could not
17    /// round or bevel.
18    pub edges: EdgeRefusal,
19}
20
21/// The edges of a fillet or chamfer the kernel refused.
22#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
23pub struct EdgeRefusal {
24    /// Every edge the op took, in its order, tangent chains followed: what
25    /// it rounds without the failing ones is these less those.
26    pub request: Vec<EdgeProbe>,
27    /// The edges that fail.
28    pub failing: Vec<FailingEdge>,
29    /// The largest share of the asked size at which every edge of the
30    /// request builds, when it does at some: the size times it fits.
31    #[serde(default)]
32    pub fits: Option<f64>,
33}
34
35/// An edge a fillet or chamfer could not round or bevel: refused alone, or
36/// in a group of the op's edges meeting at a vertex.
37#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
38pub struct FailingEdge {
39    /// Its place among the edges the op rounds, from zero.
40    pub index: usize,
41    /// How many edges the op rounds.
42    pub of: usize,
43    /// A pick that names it in the body's own frame: a point halfway
44    /// along, the way it runs there and its faces' names.
45    pub probe: EdgeProbe,
46    /// Points along it in the body's own frame, to draw it by.
47    pub points: Vec<[f64; 3]>,
48    /// Why the kernel refused it.
49    pub reason: String,
50    /// The largest share of the asked size at which it builds on its own,
51    /// when it does at some.
52    #[serde(default)]
53    pub fits: Option<f64>,
54}
55
56/// Result of executing a body's solid-op chain.
57#[derive(Debug, Clone, Default, Serialize, Deserialize)]
58pub struct SolidBuildResult {
59    /// Native-format shape snapshot of the final solid (for later
60    /// re-tessellation, persistence, and downstream booleans).
61    pub brep_blob: Vec<u8>,
62    /// Render mesh of the final solid.
63    pub mesh: TriMesh,
64    /// Axis-aligned bounds in millimetres.
65    pub bounds_mm: Option<([f32; 3], [f32; 3])>,
66    /// What the feature being edited does, when the build was asked for it.
67    pub preview: Option<Box<FeaturePreview>>,
68    /// The answers to the chain's probes, in the order they were asked.
69    pub probes: Vec<Result<ProbeAnswer, String>>,
70    /// The curves the chain's projections came to, in the order they were
71    /// asked.
72    #[serde(default)]
73    pub projections: Vec<Result<Vec<ProjectedEdge>, String>>,
74}
75
76/// What a feature being edited does to its body, beside the body without
77/// it: the view while it is edited.
78#[derive(Debug, Clone, Default, Serialize, Deserialize)]
79pub struct FeaturePreview {
80    /// The body to show meanwhile: as it stood before a feature that adds,
81    /// after one that cuts. None when an adding feature is the body's
82    /// first.
83    pub shown: Option<Box<SolidBuildResult>>,
84    /// The feature's own tool solid, meshed: the material it adds or takes.
85    pub tool: TriMesh,
86    /// The feature cuts.
87    pub cuts: bool,
88}