Skip to main content

ifc_geometry/authoring/
swept_in.rs

1//! The sweeps whose record depends on the model's declared release.
2//!
3//! `StartParam`/`EndParam` of the directrix-driven sweeps are
4//! `IfcParameterValue` in IFC2X3 and IFC4 (written bare) and the SELECT
5//! `IfcCurveMeasureSelect` in IFC4X3 (written `IFCPARAMETERVALUE(..)`), so a
6//! writer without a model cannot be right in every release (#200). The swept
7//! disk's trim keeps its form but not its optionality: IFC2X3 requires it,
8//! later releases do not (#210). These writers take the model and write what
9//! its release declares; see `release.rs` for the evidence and the binding
10//! rule. They are the only writers of these three entities.
11
12use ifc_model::{Entity, EntityId, Model, Transaction, Value};
13
14use crate::error::GeometryError;
15use crate::solid::swept::directrix_slot;
16
17use super::release::bind;
18use super::swept::{directrix_attrs, disk_attrs, ParamForm, SweepTrim};
19
20/// Stage an `IfcSurfaceCurveSweptAreaSolid` in `model`'s declared release.
21///
22/// The profile is swept along `directrix` while staying on
23/// `reference_surface`, which is what fixes its orientation. The trim
24/// parameters take the form the release declares:
25///
26/// ```text
27/// IFC2X3  StartParam : IfcParameterValue           0.5   (required)
28/// IFC4    StartParam : OPTIONAL IfcParameterValue  0.5
29/// IFC4X3  StartParam : OPTIONAL IfcCurveMeasureSelect
30///                                    IFCPARAMETERVALUE(0.5)
31/// ```
32///
33/// A model without `FILE_SCHEMA` binds IFC4.
34///
35/// # Errors
36///
37/// [`GeometryError::InvalidAuthoredValue`] for a non-finite trim parameter,
38/// or an attribute the release requires left unset (in IFC2X3, `Position`,
39/// `StartParam` and `EndParam`).
40/// [`GeometryError::AuthoringSchemaUnbound`] if `FILE_SCHEMA` names an
41/// unknown release or several. Nothing is staged on error.
42pub fn surface_curve_swept_area_solid_in(
43    tx: &mut Transaction,
44    model: &Model,
45    swept_area: EntityId,
46    position: Option<EntityId>,
47    directrix: EntityId,
48    trim: SweepTrim,
49    reference_surface: EntityId,
50) -> Result<EntityId, GeometryError> {
51    const T: &str = "IFCSURFACECURVESWEPTAREASOLID";
52    let release = bind(model, T)?;
53    let form = ParamForm::Release(release);
54    let mut attrs = directrix_attrs(T, swept_area, position, directrix, trim, form)?;
55    attrs[directrix_slot::REFERENCE_SURFACE] = Value::Ref(reference_surface);
56    release.require(T, &attrs)?;
57    Ok(tx.create(Entity::new(T, attrs)))
58}
59
60/// Stage an `IfcFixedReferenceSweptAreaSolid` in `model`'s declared release.
61///
62/// Like the surface-curve sweep, but the profile's orientation is fixed by a
63/// direction rather than by a surface. The trim parameters are bare in IFC4
64/// and `IFCPARAMETERVALUE(..)` in IFC4X3. IFC2X3 does not declare the
65/// entity. A model without `FILE_SCHEMA` binds IFC4.
66///
67/// # Errors
68///
69/// [`GeometryError::InvalidAuthoredValue`] for a non-finite trim parameter.
70/// [`GeometryError::AuthoringEntityNotInSchema`] in IFC2X3.
71/// [`GeometryError::AuthoringSchemaUnbound`] if `FILE_SCHEMA` names an
72/// unknown release or several. Nothing is staged on error.
73pub fn fixed_reference_swept_area_solid_in(
74    tx: &mut Transaction,
75    model: &Model,
76    swept_area: EntityId,
77    position: Option<EntityId>,
78    directrix: EntityId,
79    trim: SweepTrim,
80    fixed_reference: EntityId,
81) -> Result<EntityId, GeometryError> {
82    const T: &str = "IFCFIXEDREFERENCESWEPTAREASOLID";
83    let release = bind(model, T)?;
84    let form = ParamForm::Release(release);
85    let mut attrs = directrix_attrs(T, swept_area, position, directrix, trim, form)?;
86    attrs[directrix_slot::FIXED_REFERENCE] = Value::Ref(fixed_reference);
87    release.require(T, &attrs)?;
88    Ok(tx.create(Entity::new(T, attrs)))
89}
90
91/// Stage an `IfcSweptDiskSolid` in `model`'s declared release: a disk swept
92/// along a curve.
93///
94/// Note the slot layout: this subtypes `IfcSolidModel` directly, so
95/// `Directrix` is slot 0 and there is no `SweptArea` or `Position`.
96///
97/// The trim parameters are `IfcParameterValue`, written bare, in every
98/// release; what changes is whether they may be left out:
99///
100/// ```text
101/// IFC2X3  StartParam : IfcParameterValue           (required)
102/// IFC4    StartParam : OPTIONAL IfcParameterValue
103/// IFC4X3  StartParam : OPTIONAL IfcParameterValue
104/// ```
105///
106/// An IFC2X3 swept disk therefore needs both trim values; the writer does
107/// not invent the directrix's full range, which only an evaluator knows. A
108/// model without `FILE_SCHEMA` binds IFC4.
109///
110/// # Errors
111///
112/// [`GeometryError::InvalidAuthoredValue`] for a non-positive radius or
113/// inner radius, an inner radius that is not smaller than the outer one (a
114/// bore wider than its tube leaves no solid), a non-finite trim parameter,
115/// or, in IFC2X3, an unset `StartParam` or `EndParam`.
116/// [`GeometryError::AuthoringSchemaUnbound`] if `FILE_SCHEMA` names an
117/// unknown release or several. Nothing is staged on error.
118pub fn swept_disk_solid_in(
119    tx: &mut Transaction,
120    model: &Model,
121    directrix: EntityId,
122    radius: f64,
123    inner_radius: Option<f64>,
124    trim: SweepTrim,
125) -> Result<EntityId, GeometryError> {
126    const T: &str = "IFCSWEPTDISKSOLID";
127    let release = bind(model, T)?;
128    let form = ParamForm::Release(release);
129    let attrs = disk_attrs(T, directrix, radius, inner_radius, trim, form)?;
130    release.require(T, &attrs)?;
131    Ok(tx.create(Entity::new(T, attrs)))
132}