Skip to main content

ifc_structural/model/
result_group.rs

1//! `IfcStructuralResultGroup` projection.
2
3use ifc_model::EntityId;
4use ifc_schema::SchemaVersion;
5
6use crate::error::StructuralResult;
7use crate::view::Record;
8
9/// Borrowed projection of an `IfcStructuralResultGroup`.
10#[derive(Debug, Clone, Copy)]
11pub struct ResultGroup<'m, 's> {
12    record: Record<'m, 's>,
13}
14
15impl<'m, 's> ResultGroup<'m, 's> {
16    pub(crate) fn from_record(record: Record<'m, 's>) -> Self {
17        Self { record }
18    }
19
20    #[must_use]
21    /// The `IfcStructuralResultGroup` entity id.
22    pub fn id(&self) -> EntityId {
23        self.record.id
24    }
25
26    /// `Name`, inherited from `IfcRoot`. Legally absent.
27    pub fn name(&self) -> StructuralResult<Option<&'m str>> {
28        self.validate_semantics()?;
29        self.record.optional_text("Name")
30    }
31
32    /// `TheoryType`, always mandatory.
33    pub fn theory_type(&self) -> StructuralResult<&'m str> {
34        self.validate_semantics()?;
35        self.record.required_enum("TheoryType")
36    }
37
38    /// `ResultForLoadGroup`, the `IfcStructuralLoadGroup` these results were computed for. Legally absent.
39    pub fn result_for_load_group(&self) -> StructuralResult<Option<EntityId>> {
40        self.validate_semantics()?;
41        self.record
42            .optional_ref("ResultForLoadGroup", "IfcStructuralLoadGroup")
43    }
44
45    /// `IsLinear`, always mandatory: whether the results came from a linear analysis.
46    pub fn is_linear(&self) -> StructuralResult<bool> {
47        self.validate_semantics()?;
48        self.record.required_bool("IsLinear")
49    }
50
51    /// Validates the `USERDEFINED`-requires-`ObjectType` rule for IFC4/IFC4X3.
52    ///
53    /// Fails with [`crate::StructuralError::SemanticViolation`] if
54    /// `TheoryType` is `USERDEFINED` but `ObjectType` is unset. IFC2X3
55    /// declares no such constraint here.
56    fn validate_semantics(&self) -> StructuralResult<()> {
57        if self.record.schema.version() == Some(SchemaVersion::Ifc2x3) {
58            return Ok(());
59        }
60        let user_defined = self
61            .record
62            .required_enum("TheoryType")?
63            .eq_ignore_ascii_case("USERDEFINED");
64        self.record.require_object_type_if(
65            user_defined,
66            "USERDEFINED result theory requires ObjectType",
67        )
68    }
69}