dstv/
numeration.rs

1pub use crate::prelude::DstvElement;
2use crate::{dstv_element::ParseDstvError, get_f64_from_str, prelude::PartFace};
3use std::str::FromStr;
4
5/// Represents a numeration element
6/// A numeration element is a text element that is used to label a part
7#[derive(Debug)]
8pub struct Numeration {
9    /// Angle of the text
10    pub angle: f64,
11    /// Height of the text
12    pub letterheight: f64,
13    /// Text to be displayed
14    pub text: String,
15    /// X coordinate of the text
16    pub x_coord: f64,
17    /// Y coordinate of the text
18    pub y_coord: f64,
19    /// Flange code of the text
20    pub fl_code: PartFace,
21}
22
23impl DstvElement for Numeration {
24    /// Parses a numeration element from a line of text
25    /// # Arguments
26    /// * `line` - A line of text from a DSTV file
27    /// # Returns
28    /// A `Result` containing either a `Numeration` or an error message
29    fn from_str(line: &str) -> Result<Self, ParseDstvError> {
30        let mut iter = line.split_whitespace();
31        let fl_code = PartFace::from_str(iter.next().ok_or(ParseDstvError::new("No Numeration Found"))?)?;
32        let x_coord = get_f64_from_str(iter.next(), "x_coord")?;
33        let y_coord = get_f64_from_str(iter.next(), "y_coord")?;
34        let angle = get_f64_from_str(iter.next(), "angle")?;
35        let letterheight = get_f64_from_str(iter.next(), "letterheight")?;
36        let text = iter
37            .next()
38            .ok_or(ParseDstvError::new("Text element not found"))?
39            .to_string();
40
41        Ok(Self {
42            angle,
43            letterheight,
44            text,
45            x_coord,
46            y_coord,
47            fl_code,
48        })
49    }
50
51    /// Converts a numeration element to an SVG text element
52    fn to_svg(&self) -> String {
53        // todo: implement
54        "".to_string()
55    }
56
57    fn get_index(&self) -> usize {
58        2
59    }
60
61    fn get_facing(&self) -> &PartFace {
62        &self.fl_code
63    }
64}