Skip to main content

ifc_style/
fill_style.rs

1//! Fill-area presentation styles and hatch/tile definitions.
2
3use ifc_model::{EntityId, Value};
4
5use crate::error::StyleResult;
6use crate::view::Record;
7
8/// Borrowed projection of `IfcFillAreaStyle`.
9#[derive(Debug, Clone, Copy)]
10pub struct FillAreaStyle<'m, 's> {
11    record: Record<'m, 's>,
12}
13
14impl<'m, 's> FillAreaStyle<'m, 's> {
15    pub(crate) fn from_record(record: Record<'m, 's>) -> Self {
16        Self { record }
17    }
18
19    /// The `Name` attribute, when authored.
20    pub fn name(&self) -> StyleResult<Option<&'m str>> {
21        self.record.optional_text("Name")
22    }
23
24    /// The `FillStyles` select: one or more colour, external, hatching, or
25    /// tiling definitions making up this fill.
26    pub fn fill_styles(&self) -> StyleResult<Vec<EntityId>> {
27        self.record.required_refs_select(
28            "FillStyles",
29            "IfcFillStyleSelect",
30            &[
31                "IfcColour",
32                "IfcExternallyDefinedHatchStyle",
33                "IfcFillAreaStyleHatching",
34                "IfcFillAreaStyleTiles",
35            ],
36            1,
37            None,
38        )
39    }
40
41    /// The `ModelOrDraughting` flag: `true` for model-space geometry,
42    /// `false` for a draughting/annotation fill style, `None` if unauthored.
43    pub fn model_or_draughting(&self) -> StyleResult<Option<bool>> {
44        self.record.optional_bool("ModelOrDraughting")
45    }
46}
47
48/// Borrowed projection of `IfcFillAreaStyleHatching`: a parallel-line hatch pattern.
49#[derive(Debug, Clone, Copy)]
50pub struct FillAreaStyleHatching<'m, 's> {
51    record: Record<'m, 's>,
52}
53
54impl<'m, 's> FillAreaStyleHatching<'m, 's> {
55    pub(crate) fn from_record(record: Record<'m, 's>) -> Self {
56        Self { record }
57    }
58
59    /// The `HatchLineAppearance` attribute: the curve style drawing each hatch line. Mandatory.
60    pub fn hatch_line_appearance(&self) -> StyleResult<EntityId> {
61        self.record
62            .required_ref("HatchLineAppearance", "IfcCurveStyle")
63    }
64
65    /// The `StartOfNextHatchLine` attribute (an `IfcHatchLineDistanceSelect`),
66    /// returned raw because the select is not narrowed to one representation here.
67    pub fn start_of_next_hatch_line(&self) -> StyleResult<&'m Value> {
68        self.record.value("StartOfNextHatchLine")
69    }
70
71    /// The `PointOfReferenceHatchLine` attribute, when authored.
72    pub fn point_of_reference_hatch_line(&self) -> StyleResult<Option<EntityId>> {
73        self.record
74            .optional_ref("PointOfReferenceHatchLine", "IfcCartesianPoint")
75    }
76
77    /// The `PatternStart` attribute, when authored.
78    pub fn pattern_start(&self) -> StyleResult<Option<EntityId>> {
79        self.record
80            .optional_ref("PatternStart", "IfcCartesianPoint")
81    }
82
83    /// The `HatchLineAngle` attribute. Mandatory.
84    pub fn hatch_line_angle(&self) -> StyleResult<f64> {
85        self.record.required_number("HatchLineAngle")
86    }
87}
88
89/// Borrowed projection of `IfcFillAreaStyleTiles`: a repeating tile pattern.
90#[derive(Debug, Clone, Copy)]
91pub struct FillAreaStyleTiles<'m, 's> {
92    record: Record<'m, 's>,
93}
94
95impl<'m, 's> FillAreaStyleTiles<'m, 's> {
96    pub(crate) fn from_record(record: Record<'m, 's>) -> Self {
97        Self { record }
98    }
99
100    /// The `TilingPattern` attribute: exactly two vectors spanning the tile's repeat lattice.
101    pub fn tiling_pattern(&self) -> StyleResult<Vec<EntityId>> {
102        self.record
103            .required_refs("TilingPattern", "IfcVector", 2, Some(2))
104    }
105}