Skip to main content

ifc_style/curve_style/
style.rs

1//! `IfcCurveStyle` projection.
2
3use ifc_model::{EntityId, Value};
4
5use crate::error::StyleResult;
6use crate::view::Record;
7
8/// Borrowed projection of `IfcCurveStyle`.
9#[derive(Debug, Clone, Copy)]
10pub struct CurveStyle<'m, 's> {
11    record: Record<'m, 's>,
12}
13
14impl<'m, 's> CurveStyle<'m, 's> {
15    pub(crate) fn from_record(record: Record<'m, 's>) -> Self {
16        Self { record }
17    }
18
19    /// The entity id of this `IfcCurveStyle`.
20    pub fn id(&self) -> EntityId {
21        self.record.id
22    }
23
24    /// The `Name` attribute, when authored.
25    pub fn name(&self) -> StyleResult<Option<&'m str>> {
26        self.record.optional_text("Name")
27    }
28
29    /// The `CurveFont` attribute: a reference to an `IfcCurveStyleFont`, a
30    /// predefined curve font name, or `None` if unauthored. Returned raw
31    /// because the select is not narrowed to a single entity type here.
32    pub fn curve_font(&self) -> StyleResult<Option<&'m Value>> {
33        self.record.optional_raw("CurveFont")
34    }
35
36    /// The `CurveWidth` attribute (an `IfcSizeSelect`: a fixed measure or a
37    /// positive-length select member), when authored.
38    pub fn curve_width(&self) -> StyleResult<Option<&'m Value>> {
39        self.record.optional_raw("CurveWidth")
40    }
41
42    /// The `CurveColour` attribute, resolved through the `IfcColour` select,
43    /// when authored.
44    pub fn curve_colour(&self) -> StyleResult<Option<EntityId>> {
45        self.record.optional_ref_select(
46            "CurveColour",
47            "IfcColour",
48            &["IfcColourSpecification", "IfcPreDefinedColour"],
49        )
50    }
51
52    /// The `ModelOrDraughting` flag: `true` for model-space geometry,
53    /// `false` for a draughting/annotation curve style, `None` if unauthored.
54    pub fn model_or_draughting(&self) -> StyleResult<Option<bool>> {
55        self.record.optional_bool("ModelOrDraughting")
56    }
57}
58
59/// Borrowed projection of `IfcCurveStyleFont`: a named list of dash/gap
60/// patterns applied along a styled curve.
61#[derive(Debug, Clone, Copy)]
62pub struct CurveStyleFont<'m, 's> {
63    record: Record<'m, 's>,
64}
65
66impl<'m, 's> CurveStyleFont<'m, 's> {
67    pub(crate) fn from_record(record: Record<'m, 's>) -> Self {
68        Self { record }
69    }
70
71    /// The `Name` attribute, when authored.
72    pub fn name(&self) -> StyleResult<Option<&'m str>> {
73        self.record.optional_text("Name")
74    }
75
76    /// The `PatternList`: one or more `IfcCurveStyleFontPattern` references
77    /// making up this font's repeating dash/gap sequence. At least one
78    /// pattern is required by the schema.
79    pub fn patterns(&self) -> StyleResult<Vec<EntityId>> {
80        self.record
81            .required_refs("PatternList", "IfcCurveStyleFontPattern", 1, None)
82    }
83}
84
85/// Borrowed projection of `IfcCurveStyleFontPattern`: one visible/invisible
86/// segment pair in a dashed curve font.
87#[derive(Debug, Clone, Copy)]
88pub struct CurveStyleFontPattern<'m, 's> {
89    record: Record<'m, 's>,
90}
91
92impl<'m, 's> CurveStyleFontPattern<'m, 's> {
93    pub(crate) fn from_record(record: Record<'m, 's>) -> Self {
94        Self { record }
95    }
96
97    /// The `VisibleSegmentLength` attribute. Mandatory.
98    pub fn visible_segment_length(&self) -> StyleResult<f64> {
99        self.record.required_number("VisibleSegmentLength")
100    }
101
102    /// The `InvisibleSegmentLength` attribute. Mandatory.
103    pub fn invisible_segment_length(&self) -> StyleResult<f64> {
104        self.record.required_number("InvisibleSegmentLength")
105    }
106}