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
8mod resolve;
9mod resolved;
10
11pub(crate) use resolve::resolve_fill;
12pub use resolved::{ContextFill, ContextFillResult, HatchLine, MaterialFill};
13
14/// Borrowed projection of `IfcFillAreaStyle`.
15#[derive(Debug, Clone, Copy)]
16pub struct FillAreaStyle<'m, 's> {
17    record: Record<'m, 's>,
18}
19
20impl<'m, 's> FillAreaStyle<'m, 's> {
21    pub(crate) fn from_record(record: Record<'m, 's>) -> Self {
22        Self { record }
23    }
24
25    /// The `Name` attribute, when authored.
26    pub fn name(&self) -> StyleResult<Option<&'m str>> {
27        self.record.optional_text("Name")
28    }
29
30    /// The `FillStyles` select: one or more colour, external, hatching, or
31    /// tiling definitions making up this fill.
32    ///
33    /// `IfcFillStyleSelect` nests the `IfcColour` select, so a solid fill
34    /// is accepted through that select's own members
35    /// (`IfcColourSpecification`, e.g. `IfcColourRgb`, and
36    /// `IfcPreDefinedColour`) in every supported release; read it with
37    /// [`crate::StyleView::colour_rgb`].
38    pub fn fill_styles(&self) -> StyleResult<Vec<EntityId>> {
39        self.record.required_refs_select(
40            "FillStyles",
41            "IfcFillStyleSelect",
42            &[
43                // `IfcColour` is itself a select: list its members, since a
44                // select name never matches an instance's entity type.
45                "IfcColourSpecification",
46                "IfcPreDefinedColour",
47                "IfcExternallyDefinedHatchStyle",
48                "IfcFillAreaStyleHatching",
49                "IfcFillAreaStyleTiles",
50            ],
51            1,
52            None,
53        )
54    }
55
56    /// The `ModelOrDraughting` flag: `true` for model-space geometry,
57    /// `false` for a draughting/annotation fill style, `None` if unauthored.
58    pub fn model_or_draughting(&self) -> StyleResult<Option<bool>> {
59        self.record.optional_bool("ModelOrDraughting")
60    }
61}
62
63/// Borrowed projection of `IfcFillAreaStyleHatching`: a parallel-line hatch pattern.
64#[derive(Debug, Clone, Copy)]
65pub struct FillAreaStyleHatching<'m, 's> {
66    record: Record<'m, 's>,
67}
68
69impl<'m, 's> FillAreaStyleHatching<'m, 's> {
70    pub(crate) fn from_record(record: Record<'m, 's>) -> Self {
71        Self { record }
72    }
73
74    /// The `HatchLineAppearance` attribute: the curve style drawing each hatch line. Mandatory.
75    pub fn hatch_line_appearance(&self) -> StyleResult<EntityId> {
76        self.record
77            .required_ref("HatchLineAppearance", "IfcCurveStyle")
78    }
79
80    /// The `StartOfNextHatchLine` attribute (an `IfcHatchLineDistanceSelect`),
81    /// returned raw because the select is not narrowed to one representation here.
82    pub fn start_of_next_hatch_line(&self) -> StyleResult<&'m Value> {
83        self.record.value("StartOfNextHatchLine")
84    }
85
86    /// The `PointOfReferenceHatchLine` attribute, when authored.
87    pub fn point_of_reference_hatch_line(&self) -> StyleResult<Option<EntityId>> {
88        self.record
89            .optional_ref("PointOfReferenceHatchLine", "IfcCartesianPoint")
90    }
91
92    /// The `PatternStart` attribute, when authored.
93    pub fn pattern_start(&self) -> StyleResult<Option<EntityId>> {
94        self.record
95            .optional_ref("PatternStart", "IfcCartesianPoint")
96    }
97
98    /// The `HatchLineAngle` attribute. Mandatory.
99    pub fn hatch_line_angle(&self) -> StyleResult<f64> {
100        self.record.required_number("HatchLineAngle")
101    }
102}
103
104/// Borrowed projection of `IfcFillAreaStyleTiles`: a repeating tile pattern.
105#[derive(Debug, Clone, Copy)]
106pub struct FillAreaStyleTiles<'m, 's> {
107    record: Record<'m, 's>,
108}
109
110impl<'m, 's> FillAreaStyleTiles<'m, 's> {
111    pub(crate) fn from_record(record: Record<'m, 's>) -> Self {
112        Self { record }
113    }
114
115    /// The `TilingPattern` attribute: exactly two vectors spanning the tile's repeat lattice.
116    pub fn tiling_pattern(&self) -> StyleResult<Vec<EntityId>> {
117        self.record
118            .required_refs("TilingPattern", "IfcVector", 2, Some(2))
119    }
120}