Skip to main content

ifc_style/surface_style/
rendering.rs

1//! `IfcSurfaceStyleRendering` projection.
2
3use ifc_model::{EntityId, Value};
4
5use crate::colour::{optional_colour_or_factor, ColourOrFactor};
6use crate::error::StyleResult;
7use crate::view::Record;
8
9/// Borrowed projection of `IfcSurfaceStyleRendering` (a subtype of
10/// `IfcSurfaceStyleShading` adding rendering-oriented colour selects and the
11/// reflectance method).
12#[derive(Debug, Clone, Copy)]
13pub struct SurfaceStyleRendering<'m, 's> {
14    record: Record<'m, 's>,
15}
16
17impl<'m, 's> SurfaceStyleRendering<'m, 's> {
18    pub(crate) fn from_record(record: Record<'m, 's>) -> Self {
19        Self { record }
20    }
21
22    /// The entity id of this `IfcSurfaceStyleRendering`.
23    pub fn id(&self) -> EntityId {
24        self.record.id
25    }
26
27    /// The `SurfaceColour` attribute, inherited from `IfcSurfaceStyleShading`. Mandatory.
28    pub fn surface_colour(&self) -> StyleResult<EntityId> {
29        self.record.required_ref("SurfaceColour", "IfcColourRgb")
30    }
31
32    /// The `Transparency` attribute, when authored.
33    pub fn transparency(&self) -> StyleResult<Option<f64>> {
34        self.record.optional_normalized("Transparency")
35    }
36
37    /// The `DiffuseColour` attribute (`IfcColourOrFactor`), when authored.
38    pub fn diffuse_colour(&self) -> StyleResult<Option<ColourOrFactor>> {
39        optional_colour_or_factor(&self.record, "DiffuseColour")
40    }
41
42    /// The `TransmissionColour` attribute (`IfcColourOrFactor`), when authored.
43    pub fn transmission_colour(&self) -> StyleResult<Option<ColourOrFactor>> {
44        optional_colour_or_factor(&self.record, "TransmissionColour")
45    }
46
47    /// The `DiffuseTransmissionColour` attribute (`IfcColourOrFactor`), when authored.
48    pub fn diffuse_transmission_colour(&self) -> StyleResult<Option<ColourOrFactor>> {
49        optional_colour_or_factor(&self.record, "DiffuseTransmissionColour")
50    }
51
52    /// The `ReflectionColour` attribute (`IfcColourOrFactor`), when authored.
53    pub fn reflection_colour(&self) -> StyleResult<Option<ColourOrFactor>> {
54        optional_colour_or_factor(&self.record, "ReflectionColour")
55    }
56
57    /// The `SpecularColour` attribute (`IfcColourOrFactor`), when authored.
58    pub fn specular_colour(&self) -> StyleResult<Option<ColourOrFactor>> {
59        optional_colour_or_factor(&self.record, "SpecularColour")
60    }
61
62    /// The `SpecularHighlight` attribute (`IfcSpecularHighlightSelect`:
63    /// specular exponent or roughness), when authored. Returned raw because
64    /// the select is not narrowed to one representation here.
65    pub fn specular_highlight(&self) -> StyleResult<Option<&'m Value>> {
66        self.record.optional_raw("SpecularHighlight")
67    }
68
69    /// The `ReflectanceMethod` attribute: the `IfcReflectanceMethodEnum`
70    /// token (e.g. `"PHYSICAL"`, `"BLINN"`, `"FLAT"`) selecting the shading
71    /// model this rendering data feeds. Mandatory.
72    pub fn reflectance_method(&self) -> StyleResult<&'m str> {
73        self.record.required_enum("ReflectanceMethod")
74    }
75}