Skip to main content

printobserver_supervisor_api/
image.rs

1//! Which image a check or a look was shown, and why it was the plain frame.
2//!
3//! The server shows a print's check its three-panel image when it can trust
4//! the drawing and the whole camera frame otherwise. These shapes say which it
5//! was in structured fields, beside the one line of prose the image's note
6//! carries, so a client and the agent learn each downgrade and its reason
7//! rather than reading it out of a sentence.
8
9use printobserver_types::contract::Sample;
10use printobserver_types::schemars::JsonSchema;
11use printobserver_types::serde::{Deserialize, Serialize};
12
13/// Which image a check or a look was shown.
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
15#[serde(crate = "printobserver_types::serde", rename_all = "snake_case")]
16#[schemars(crate = "printobserver_types::schemars")]
17pub enum ImageKind {
18    /// The three panels: the frame with this layer's plan drawn on it, a
19    /// close-up of the part, and the previous check's frame.
20    ThreePanel,
21    /// The camera's frame, scaled whole and uncropped, nothing drawn.
22    WholeFrame,
23}
24
25/// Why a check or a look was shown the whole frame: one code per reason the
26/// server gives one.
27#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
28#[serde(crate = "printobserver_types::serde", rename_all = "snake_case")]
29#[schemars(crate = "printobserver_types::schemars")]
30pub enum WholeFrameReasonCode {
31    /// No print is named: a look at the printer.
32    NoPrint,
33    /// No camera calibration is configured.
34    NoCalibration,
35    /// No camera snapshot address is configured.
36    NoStream,
37    /// The print's G-code index gives no file position for the check.
38    NoPosition,
39    /// The G-code names no extruded object laid at that point.
40    NoObject,
41    /// It names no layer there.
42    NoLayer,
43    /// The layer's planned toolpath could not be read back.
44    ToolpathUnread,
45    /// The print's first layer is not down, or no frame of it has been judged
46    /// yet.
47    AlignmentPending,
48    /// The last frame judged could not tell where the first layer lies: the
49    /// toolhead covered the part, or the layer was not clearly found. A later
50    /// check's frame is judged again. No evidence of a defect.
51    AlignmentInconclusive,
52    /// The print's G-code lays no object to align.
53    AlignmentUnavailable,
54    /// The camera's frames cannot be judged against the calibration.
55    AlignmentFailed,
56    /// Fewer than two landmarks are found, so whether the camera shifted is
57    /// unknown.
58    LandmarksNotFound,
59    /// The camera moved since the drawing's correction was taken.
60    ViewRefitRejected,
61    /// The landmarks show the camera has moved since its calibration, so the
62    /// plan cannot be drawn reliably on its frames: the camera wants
63    /// recalibrating.
64    CalibrationStale,
65    /// The frame is not the calibration's size or stream.
66    FrameMismatch,
67    /// The printer reports the print paused, its bed moved off the plan's
68    /// height.
69    Paused,
70    /// The composer refused the frame for another reason.
71    Refused,
72}
73
74/// Why a check or a look was shown the whole frame.
75#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
76#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
77#[schemars(crate = "printobserver_types::schemars")]
78pub struct ImageFallback {
79    /// The reason, as a code.
80    pub code: WholeFrameReasonCode,
81    /// The reason, in the sentence the image's note gives it in.
82    pub message: String,
83}
84
85impl Sample for ImageFallback {
86    fn sample_full() -> Self {
87        Self {
88            code: WholeFrameReasonCode::AlignmentInconclusive,
89            message: "the print's first-layer alignment is inconclusive on the frame judged last: the toolhead covers the part, so a later check's frame is judged again".to_owned(),
90        }
91    }
92
93    fn sample_minimal() -> Self {
94        Self {
95            code: WholeFrameReasonCode::Paused,
96            message: "the printer reports the print paused".to_owned(),
97        }
98    }
99}
100
101impl Sample for ImageKind {
102    fn sample_full() -> Self {
103        Self::ThreePanel
104    }
105
106    fn sample_alternates() -> Vec<Self> {
107        vec![Self::WholeFrame]
108    }
109}
110
111impl Sample for WholeFrameReasonCode {
112    fn sample_full() -> Self {
113        Self::AlignmentInconclusive
114    }
115
116    fn sample_alternates() -> Vec<Self> {
117        vec![
118            Self::NoPrint,
119            Self::NoCalibration,
120            Self::NoStream,
121            Self::NoPosition,
122            Self::NoObject,
123            Self::NoLayer,
124            Self::ToolpathUnread,
125            Self::AlignmentPending,
126            Self::AlignmentUnavailable,
127            Self::AlignmentFailed,
128            Self::LandmarksNotFound,
129            Self::ViewRefitRejected,
130            Self::CalibrationStale,
131            Self::FrameMismatch,
132            Self::Paused,
133            Self::Refused,
134        ]
135    }
136}