Skip to main content

ifc_template_catalog/overlay/
built_in.rs

1//! Evidence-backed Nehirde correction ledger.
2
3use crate::definition::{
4    Applicability, CatalogEdition, PropertyDataType, PropertyKind, PropertyTemplate, QuantityKind,
5};
6
7use super::{AdvisorySeverity, Patch, PatchOperation};
8
9/// Ordered built-in patches for an exact source edition.
10pub fn corrected_patches(edition: CatalogEdition) -> Vec<Patch> {
11    match edition {
12        CatalogEdition::Ifc4Add2Tc1 => {
13            vec![
14            Patch {
15                id: "NEH-IFC4-QTO-0001".into(),
16                edition,
17                target_template: "Qto_WallBaseQuantities".into(),
18                rationale: "Backport the type applicability published by later catalogs".into(),
19                evidence: "IfcOpenShell test/util/test_pset.py: backported IFC4 fix".into(),
20                operation: PatchOperation::AddApplicability(Applicability::entity("IfcWallType")),
21            },
22            environmental_advisory(
23                edition,
24                "NEH-IFC4-EPD-0001",
25                "Pset_EnvironmentalImpactIndicators",
26            ),
27            environmental_advisory(
28                edition,
29                "NEH-IFC4-EPD-0002",
30                "Pset_EnvironmentalImpactValues",
31            ),
32            applicability_from_evidence(
33                edition,
34                "NEH-IFC4-PSD-0001",
35                "Pset_CivilElementCommon",
36                Applicability::entity("IfcCivilElement"),
37                "IFC4 ADD2 TC1 publishes this set with no applicable entity; backport the entity \
38                 later evidence names",
39                "IFC4 ADD2 TC1 psd/Pset_CivilElementCommon.xml and \
40                 annex-a/general-usage/IFC4_ADD2.ifc #541 declare no applicable entity; \
41                 IFC4X3 ADD2 associates the same template GUID with IfcCivilElement \
42                 (IFC4.x-development 524daac53ca682e0649d240ace87f4cd7baff6e7 \
43                 schemas/IFC.xml, association EAID_106DE783_E427_4cae_91F7_626CDCE4D04B); \
44                 IfcOpenShell 1a6336bd Pset_IFC4_ADD2.ifc #541: 'IfcCivilElement'".into(),
45            ),
46            applicability_from_evidence(
47                edition,
48                "NEH-IFC4-PSD-0002",
49                "Pset_ElementAssemblyCommon",
50                Applicability::entity("IfcElementAssembly"),
51                "IFC4 ADD2 TC1 publishes this set with no applicable entity; backport the entity \
52                 later evidence names",
53                "IFC4 ADD2 TC1 psd/Pset_ElementAssemblyCommon.xml and \
54                 annex-a/general-usage/IFC4_ADD2.ifc #559 declare no applicable entity; \
55                 IFC4X3 ADD2 associates the same template GUID with IfcElementAssembly \
56                 (IFC4.x-development 524daac53ca682e0649d240ace87f4cd7baff6e7 \
57                 schemas/IFC.xml, association EAID_097D723E_5187_42d7_AAC0_0F29E0733215); \
58                 IfcOpenShell 1a6336bd Pset_IFC4_ADD2.ifc #559: 'IfcElementAssembly'".into(),
59            ),
60            applicability_from_evidence(
61                edition,
62                "NEH-IFC4-PSD-0003",
63                "Pset_SpatialZoneCommon",
64                Applicability::entity("IfcSpatialZone"),
65                "IFC4 ADD2 TC1 publishes this set with no applicable entity; backport the entity \
66                 later evidence names",
67                "IFC4 ADD2 TC1 psd/Pset_SpatialZoneCommon.xml and \
68                 annex-a/general-usage/IFC4_ADD2.ifc #1750 declare no applicable entity; \
69                 IFC4X3 ADD2 associates the same template GUID with IfcSpatialZone \
70                 (IFC4.x-development 524daac53ca682e0649d240ace87f4cd7baff6e7 \
71                 schemas/IFC.xml, association EAID_239365BE_FADD_46bf_A54E_3FA8D892187C); \
72                 IfcOpenShell 1a6336bd Pset_IFC4_ADD2.ifc #1750: 'IfcSpatialZone'".into(),
73            ),
74            proxy_quantity_kind(
75                edition,
76                "NEH-IFC4-QTO-0002",
77                "NetSurfaceArea",
78                QuantityKind::Area,
79            ),
80            proxy_quantity_kind(
81                edition,
82                "NEH-IFC4-QTO-0003",
83                "NetVolume",
84                QuantityKind::Volume,
85            ),
86        ]
87        }
88        CatalogEdition::Ifc4x3Add2 => vec![
89        Patch {
90            id: "NEH-IFC4X3-PSD-0001".into(),
91            edition,
92            target_template: "Pset_Stationing".into(),
93            rationale: "The published ADD2 documentation lists HasIncreasingStation; the \
94                        embedded reference_schemas PSD XML omits it"
95                .into(),
96            evidence: "IFC 4.3.2.0 (IFC4X3 ADD2) documentation, 6.6.4.10 Pset_Stationing, \
97                       Table 6.6.4.10.A: HasIncreasingStation, IfcPropertySingleValue, IfcBoolean"
98                .into(),
99            // Name, form and type only: the documentation publishes no
100            // GlobalId for the member, and its prose is not restated here.
101            operation: PatchOperation::AddProperty(PropertyTemplate {
102                name: "HasIncreasingStation".into(),
103                guid: None,
104                definition: None,
105                name_aliases: Vec::new(),
106                definition_aliases: Vec::new(),
107                kind: PropertyKind::SingleValue {
108                    data_type: PropertyDataType::new("IfcBoolean"),
109                },
110            }),
111        },
112        applicability_from_evidence(
113            edition,
114            "NEH-IFC4X3-PSD-0002",
115            "Pset_CivilElementCommon",
116            Applicability::entity("IfcCivilElement"),
117            "The pinned reference_schemas PSD XML lists no applicable entity; schemas/IFC.xml at \
118             the same commit associates the set with one",
119            "buildingSMART IFC4.x-development 524daac53ca682e0649d240ace87f4cd7baff6e7 \
120             schemas/IFC.xml: association EAID_106DE783_E427_4cae_91F7_626CDCE4D04B between \
121             Pset_CivilElementCommon and IfcCivilElement".into(),
122        ),
123        applicability_from_evidence(
124            edition,
125            "NEH-IFC4X3-PSD-0003",
126            "Pset_ElementAssemblyCommon",
127            Applicability::entity("IfcElementAssembly"),
128            "The pinned reference_schemas PSD XML lists no applicable entity; schemas/IFC.xml at \
129             the same commit associates the set with one",
130            "buildingSMART IFC4.x-development 524daac53ca682e0649d240ace87f4cd7baff6e7 \
131             schemas/IFC.xml: association EAID_097D723E_5187_42d7_AAC0_0F29E0733215 between \
132             Pset_ElementAssemblyCommon and IfcElementAssembly".into(),
133        ),
134        applicability_from_evidence(
135            edition,
136            "NEH-IFC4X3-PSD-0004",
137            "Pset_MarineFacilityTransportation",
138            Applicability::entity("IfcMarineFacility"),
139            "The pinned reference_schemas PSD XML lists no applicable entity; schemas/IFC.xml at \
140             the same commit associates the set with one",
141            "buildingSMART IFC4.x-development 524daac53ca682e0649d240ace87f4cd7baff6e7 \
142             schemas/IFC.xml: association EAID_61F9C3A1_FD78_4512_8432_BC3B5BAEEF8C between \
143             Pset_MarineFacilityTransportation and IfcMarineFacility".into(),
144        ),
145        applicability_from_evidence(
146            edition,
147            "NEH-IFC4X3-PSD-0005",
148            "Pset_SpatialZoneCommon",
149            Applicability::entity("IfcSpatialZone"),
150            "The pinned reference_schemas PSD XML lists no applicable entity; schemas/IFC.xml at \
151             the same commit associates the set with one",
152            "buildingSMART IFC4.x-development 524daac53ca682e0649d240ace87f4cd7baff6e7 \
153             schemas/IFC.xml: association EAID_239365BE_FADD_46bf_A54E_3FA8D892187C between \
154             Pset_SpatialZoneCommon and IfcSpatialZone".into(),
155        ),
156        applicability_from_evidence(
157            edition,
158            "NEH-IFC4X3-QTO-0001",
159            "Qto_CourseBaseQuantities",
160            Applicability::entity("IfcCourse"),
161            "The pinned reference_schemas PSD XML lists no applicable entity; schemas/IFC.xml at \
162             the same commit associates the set with one",
163            "buildingSMART IFC4.x-development 524daac53ca682e0649d240ace87f4cd7baff6e7 \
164             schemas/IFC.xml: association EAID_C65F7735_7FB2_4847_B5C4_076476EF53D4 between \
165             Qto_CourseBaseQuantities and IfcCourse".into(),
166        ),
167        applicability_from_evidence(
168            edition,
169            "NEH-IFC4X3-QTO-0002",
170            "Qto_EarthworksCutBaseQuantities",
171            Applicability::entity("IfcEarthworksCut"),
172            "The pinned reference_schemas PSD XML lists no applicable entity; schemas/IFC.xml at \
173             the same commit associates the set with one",
174            "buildingSMART IFC4.x-development 524daac53ca682e0649d240ace87f4cd7baff6e7 \
175             schemas/IFC.xml: association EAID_00D7D326_5DEC_438d_AD40_E95B9285BD91 between \
176             Qto_EarthworksCutBaseQuantities and IfcEarthworksCut".into(),
177        ),
178        applicability_from_evidence(
179            edition,
180            "NEH-IFC4X3-QTO-0003",
181            "Qto_EarthworksFillBaseQuantities",
182            Applicability::entity("IfcEarthworksFill"),
183            "The pinned reference_schemas PSD XML lists no applicable entity; schemas/IFC.xml at \
184             the same commit associates the set with one",
185            "buildingSMART IFC4.x-development 524daac53ca682e0649d240ace87f4cd7baff6e7 \
186             schemas/IFC.xml: association EAID_2517FAD3_A946_42cb_8047_D8C2A0A1300A between \
187             Qto_EarthworksFillBaseQuantities and IfcEarthworksFill".into(),
188        ),
189        applicability_from_evidence(
190            edition,
191            "NEH-IFC4X3-QTO-0004",
192            "Qto_ImpactProtectionDeviceBaseQuantities",
193            Applicability::entity("IfcImpactProtectionDevice"),
194            "The pinned reference_schemas PSD XML lists no applicable entity; schemas/IFC.xml at \
195             the same commit associates the set with one",
196            "buildingSMART IFC4.x-development 524daac53ca682e0649d240ace87f4cd7baff6e7 \
197             schemas/IFC.xml: association EAID_DDD6466D_A2DD_4afa_A5A4_A50AB1401342 between \
198             Qto_ImpactProtectionDeviceBaseQuantities and IfcImpactProtectionDevice".into(),
199        ),
200        applicability_from_evidence(
201            edition,
202            "NEH-IFC4X3-QTO-0005",
203            "Qto_KerbBaseQuantities",
204            Applicability::entity("IfcKerb"),
205            "The pinned reference_schemas PSD XML lists no applicable entity; schemas/IFC.xml at \
206             the same commit associates the set with one",
207            "buildingSMART IFC4.x-development 524daac53ca682e0649d240ace87f4cd7baff6e7 \
208             schemas/IFC.xml: association EAID_9CB6B0D7_518E_41ac_BA77_33C47D5094BA between \
209             Qto_KerbBaseQuantities and IfcKerb".into(),
210        ),
211        applicability_from_evidence(
212            edition,
213            "NEH-IFC4X3-QTO-0006",
214            "Qto_PavementBaseQuantities",
215            Applicability::entity("IfcPavement"),
216            "The pinned reference_schemas PSD XML lists no applicable entity; schemas/IFC.xml at \
217             the same commit associates the set with one",
218            "buildingSMART IFC4.x-development 524daac53ca682e0649d240ace87f4cd7baff6e7 \
219             schemas/IFC.xml: association EAID_42C83610_A2B1_4530_9D13_CBB07161FAB0 between \
220             Qto_PavementBaseQuantities and IfcPavement".into(),
221        ),
222        applicability_from_evidence(
223            edition,
224            "NEH-IFC4X3-QTO-0007",
225            "Qto_PictorialSignQuantities",
226            Applicability {
227                    raw: "IfcSign/PICTORAL".into(),
228                    entity: "IfcSign".into(),
229                    predefined_type: Some("PICTORAL".into()),
230                },
231            "The pinned reference_schemas PSD XML lists no applicable entity; schemas/IFC.xml at \
232             the same commit associates the set with one",
233            "buildingSMART IFC4.x-development 524daac53ca682e0649d240ace87f4cd7baff6e7 \
234             schemas/IFC.xml: association EAID_708CD5AD_A390_486f_B4D7_E5B57307D48C between \
235             Qto_PictorialSignQuantities and IfcSignTypeEnum.PICTORAL".into(),
236        ),
237        applicability_from_evidence(
238            edition,
239            "NEH-IFC4X3-QTO-0008",
240            "Qto_ReinforcedSoilBaseQuantities",
241            Applicability::entity("IfcReinforcedSoil"),
242            "The pinned reference_schemas PSD XML lists no applicable entity; schemas/IFC.xml at \
243             the same commit associates the set with one",
244            "buildingSMART IFC4.x-development 524daac53ca682e0649d240ace87f4cd7baff6e7 \
245             schemas/IFC.xml: association EAID_64009BF7_8698_4797_920C_6DCD7C4D0820 between \
246             Qto_ReinforcedSoilBaseQuantities and IfcReinforcedSoil".into(),
247        ),
248        applicability_from_evidence(
249            edition,
250            "NEH-IFC4X3-QTO-0009",
251            "Qto_SignBaseQuantities",
252            Applicability::entity("IfcSign"),
253            "The pinned reference_schemas PSD XML lists no applicable entity; schemas/IFC.xml at \
254             the same commit associates the set with one",
255            "buildingSMART IFC4.x-development 524daac53ca682e0649d240ace87f4cd7baff6e7 \
256             schemas/IFC.xml: association EAID_9A2DD3BB_4D54_4875_BBEB_BB9B413B4D71 between \
257             Qto_SignBaseQuantities and IfcSign".into(),
258        ),
259        applicability_from_evidence(
260            edition,
261            "NEH-IFC4X3-QTO-0010",
262            "Qto_SignalBaseQuantities",
263            Applicability::entity("IfcSignal"),
264            "The pinned reference_schemas PSD XML lists no applicable entity; schemas/IFC.xml at \
265             the same commit associates the set with one",
266            "buildingSMART IFC4.x-development 524daac53ca682e0649d240ace87f4cd7baff6e7 \
267             schemas/IFC.xml: association EAID_4C85C5F9_B489_4139_BA94_188A5ABAB22E between \
268             Qto_SignalBaseQuantities and IfcSignal".into(),
269        ),
270        applicability_from_evidence(
271            edition,
272            "NEH-IFC4X3-QTO-0011",
273            "Qto_SurfaceFeatureBaseQuantities",
274            Applicability::entity("IfcSurfaceFeature"),
275            "The pinned reference_schemas PSD XML lists no applicable entity; schemas/IFC.xml at \
276             the same commit associates the set with one",
277            "buildingSMART IFC4.x-development 524daac53ca682e0649d240ace87f4cd7baff6e7 \
278             schemas/IFC.xml: association EAID_B40B9136_EB56_4717_8EDB_9CD7FDE69A22 between \
279             Qto_SurfaceFeatureBaseQuantities and IfcSurfaceFeature".into(),
280        ),
281        proxy_quantity_kind(
282            edition,
283            "NEH-IFC4X3-QTO-0012",
284            "NetSurfaceArea",
285            QuantityKind::Area,
286        ),
287        proxy_quantity_kind(
288            edition,
289            "NEH-IFC4X3-QTO-0013",
290            "NetVolume",
291            QuantityKind::Volume,
292        ),
293        process_item_enumeration(edition, "NEH-IFC4X3-PSD-0006", "Pset_CargoCommon"),
294        process_item_enumeration(edition, "NEH-IFC4X3-PSD-0007", "Pset_ProcessCapacity"),
295        ],
296        _ => Vec::new(),
297    }
298}
299
300fn environmental_advisory(edition: CatalogEdition, id: &str, target: &str) -> Patch {
301    Patch {
302        id: id.into(),
303        edition,
304        target_template: target.into(),
305        rationale: "Flag legacy scalar environmental data without changing official semantics".into(),
306        evidence: "docs/adr/0017-versioned-psd-qto-catalog.md".into(),
307        operation: PatchOperation::AddAdvisory {
308            severity: AdvisorySeverity::Warning,
309            message: "Legacy and underspecified for module-based EPD data; use an explicit EPD domain model"
310                .into(),
311        },
312    }
313}
314
315/// Fill a set the source publishes with no applicable entity.
316///
317/// `expected` is the empty list on purpose: if a regenerated snapshot ever
318/// gains a selector, the patch fails as stale instead of stacking a second
319/// one on top of the published value.
320fn applicability_from_evidence(
321    edition: CatalogEdition,
322    id: &str,
323    target: &str,
324    selector: Applicability,
325    rationale: &str,
326    evidence: String,
327) -> Patch {
328    Patch {
329        id: id.into(),
330        edition,
331        target_template: target.into(),
332        rationale: rationale.into(),
333        evidence,
334        operation: PatchOperation::ReplaceApplicability {
335            expected: Vec::new(),
336            replacement: vec![selector],
337        },
338    }
339}
340
341/// Correct a `Qto_BuildingElementProxyQuantities` member the source declares
342/// `Q_COUNT`.
343///
344/// The IFC4 ADD2 TC1 and IFC4X3 ADD2 PSD XML both declare `NetSurfaceArea`
345/// and `NetVolume` with no definition and `Q_COUNT`, so `expected` is
346/// `Count`: a regenerated snapshot that already differs fails as stale.
347fn proxy_quantity_kind(
348    edition: CatalogEdition,
349    id: &str,
350    member: &str,
351    replacement: QuantityKind,
352) -> Patch {
353    let (psd, detail) = match edition {
354        CatalogEdition::Ifc4Add2Tc1 => (
355            "reference_schemas/psd_IFC4_ADD2_TC1/Qto_BuildingElementProxyQuantities.xml",
356            "the same-named members of every other IFC4 ADD2 TC1 base quantity set are \
357             Q_AREA and Q_VOLUME (IfcOpenShell 1a6336bd Pset_IFC4_ADD2.ifc, e.g. \
358             Qto_BeamBaseQuantities #4919 and #4931)",
359        ),
360        _ => (
361            "reference_schemas/psd/Qto_BuildingElementProxyQuantities.xml",
362            "the IfcOpenShell 1a6336bd Pset_IFC4X3.ifc template generated from the IFC4X3 \
363             documentation declares the set's NetSurfaceArea (#4856) Q_AREA and NetVolume \
364             (#4857) Q_VOLUME",
365        ),
366    };
367    Patch {
368        id: id.into(),
369        edition,
370        target_template: "Qto_BuildingElementProxyQuantities".into(),
371        rationale: format!(
372            "The source declares {member} as a count; it is a measured quantity, and real \
373             files carry it as an IfcQuantity{replacement:?}"
374        ),
375        evidence: format!(
376            "buildingSMART IFC4.x-development 524daac53ca682e0649d240ace87f4cd7baff6e7 \
377             {psd}: {member} QtoType Q_COUNT; {detail}"
378        ),
379        operation: PatchOperation::ReplaceQuantityKind {
380            member: member.into(),
381            expected: QuantityKind::Count,
382            replacement,
383        },
384    }
385}
386
387/// Correct the IFC4X3 `ProcessItem` member the source declares as a single
388/// value of the enumeration `PEnum_ProcessItem`.
389fn process_item_enumeration(edition: CatalogEdition, id: &str, target: &str) -> Patch {
390    Patch {
391        id: id.into(),
392        edition,
393        target_template: target.into(),
394        rationale: "ProcessItem selects from the enumeration PEnum_ProcessItem; a single value \
395                    cannot hold an enumerated selection"
396            .into(),
397        evidence: format!(
398            "buildingSMART IFC4.x-development 524daac53ca682e0649d240ace87f4cd7baff6e7 \
399             reference_schemas/psd/{target}.xml: ProcessItem is a TypePropertySingleValue of \
400             DataType PEnum_ProcessItem; \
401             docs/schemas/core/IfcProductExtension/PropertyEnumerations/PEnum_ProcessItem.md: \
402             enumeration of TEU, CGT, BARREL, TONNE, PASSENGER, VEHICLE"
403        ),
404        operation: PatchOperation::ReplacePropertyKind {
405            member: "ProcessItem".into(),
406            expected: PropertyKind::SingleValue {
407                data_type: PropertyDataType::new("PEnum_ProcessItem"),
408            },
409            replacement: PropertyKind::EnumeratedValue {
410                enumeration_name: Some("PEnum_ProcessItem".into()),
411                data_type: None,
412                values: ["TEU", "CGT", "BARREL", "TONNE", "PASSENGER", "VEHICLE"]
413                    .into_iter()
414                    .map(String::from)
415                    .collect(),
416                constants: Vec::new(),
417            },
418        },
419    }
420}