rvt 0.4.0

Apache-2.0 clean-room reader for Autodesk Revit files (.rvt, .rfa, .rte, .rft) without Revit: metadata, previews and the embedded schema of 2016-2026 files, and typed elements with measured geometry from Revit 2024 and 2025 projects, exported as IFC4, glTF and plan SVG.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
//! Revit class / category → IFC4 entity type mapping table.
//!
//! Every concrete [`crate::walker::ElementDecoder`] implementation
//! ultimately needs to know "when I emit this as IFC, what entity
//! type should it be?" This module is the single source of truth for
//! that mapping. Keeping it data-driven (a static table) instead of
//! scattered through per-class code means:
//!
//! - Adding a new Revit class gets one line here.
//! - IFC2X3 / IFC4 / IFC4.3 migration is a table swap.
//! - Tests can sweep every entry for spec conformance.
//!
//! See buildingSMART's MVD / IDM documentation for the canonical
//! entity choices per class category.

/// Mapping entry: Revit class → IFC entity type + optional
/// `PredefinedType` enum value.
///
/// `ifc_type` is the uppercase STEP entity name (e.g. `"IFCWALL"`,
/// `"IFCSLAB"`). `predefined_type` is the value that goes into the
/// entity's `PredefinedType` attribute when present (e.g.
/// `"FLOOR"` / `"ROOF"` for IfcSlab, `"BEAM"` for IfcBeam).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Mapping {
    pub revit_class: &'static str,
    pub ifc_type: &'static str,
    pub predefined_type: Option<&'static str>,
}

/// Lookup table, checked at test time for uniqueness + completeness.
///
/// Ordered by a rough "primary Revit category" sort so reviewers
/// scanning the list see related entries together.
pub const MAPPINGS: &[Mapping] = &[
    // Spatial containers (project scaffolding — already handled by
    // the RvtDocExporter but listed here for the lookup to cover
    // the full Revit vocabulary).
    Mapping {
        revit_class: "Level",
        ifc_type: "IFCBUILDINGSTOREY",
        predefined_type: None,
    },
    Mapping {
        revit_class: "Grid",
        ifc_type: "IFCGRID",
        predefined_type: None,
    },
    // Architectural — walls and hosted elements.
    //
    // `.NOTDEFINED.` rather than `.STANDARD.` is the authoring
    // witness's own choice, not a shrug (#220): on
    // `2024_Core_Interior_slim.ifc` Revit's exporter writes
    // `.NOTDEFINED.` on all 360 `IFCWALL` rows, including the ones
    // whose body is a plain `SweptSolid` that `.STANDARD.` would
    // describe. Agreement with the recorded export is what the
    // verdicts score, so where an edge shows the witness's answer we
    // take it.
    Mapping {
        revit_class: "Wall",
        ifc_type: "IFCWALL",
        predefined_type: Some("NOTDEFINED"),
    },
    Mapping {
        revit_class: "ArcWall",
        ifc_type: "IFCWALL",
        predefined_type: Some("NOTDEFINED"),
    },
    // Also a wall a mullion names (RE-46). Revit's IFC4 export of Snowdon
    // Towers writes `.NOTDEFINED.` on all 60 of its `IFCCURTAINWALL` rows;
    // 42 are bodiless aggregates of their panels and mullions, and the
    // other 18 are panels that hold a basic wall (`CurtainPanelWall`).
    Mapping {
        revit_class: "CurtainWall",
        ifc_type: "IFCCURTAINWALL",
        predefined_type: Some("NOTDEFINED"),
    },
    // A curtain panel that holds a basic wall (RE-64). Revit's export of
    // Snowdon Towers writes all 18 as `IFCCURTAINWALL` with their own body,
    // nested under the curtain wall they are panels of (RE-72); these are
    // the only curtain walls there that carry a body.
    Mapping {
        revit_class: "CurtainPanelWall",
        ifc_type: "IFCCURTAINWALL",
        predefined_type: Some("NOTDEFINED"),
    },
    // Revit writes `.DOOR.` on all 132 `IFCDOOR` rows and `.WINDOW.`
    // on all 6 `IFCWINDOW` rows of the same export (#220); emitting
    // `$` there dropped a value the witness had already shown.
    Mapping {
        revit_class: "Door",
        ifc_type: "IFCDOOR",
        predefined_type: Some("DOOR"),
    },
    Mapping {
        revit_class: "Window",
        ifc_type: "IFCWINDOW",
        predefined_type: Some("WINDOW"),
    },
    // 2024 ArcWallRectOpening index rows — not typed Door/Window.
    Mapping {
        revit_class: "ArcWallRectOpening",
        ifc_type: "IFCOPENINGELEMENT",
        predefined_type: None,
    },
    // Architectural — horizontal elements.
    Mapping {
        revit_class: "Floor",
        ifc_type: "IFCSLAB",
        predefined_type: Some("FLOOR"),
    },
    // A Revit building pad is not a floor, but Revit's own exporter
    // emits it as `IfcSlab` with `PredefinedType = .FLOOR.` — see the
    // `Pad:Site Pad:21975` row in the Core Interior reference export
    // (#212, RE-22). The class stays `BuildingPad` so the mapping is
    // visible here rather than hidden behind a relabelled decode.
    Mapping {
        revit_class: "BuildingPad",
        ifc_type: "IFCSLAB",
        predefined_type: Some("FLOOR"),
    },
    Mapping {
        revit_class: "Roof",
        ifc_type: "IFCROOF",
        predefined_type: None,
    },
    Mapping {
        revit_class: "Ceiling",
        ifc_type: "IFCCOVERING",
        predefined_type: Some("CEILING"),
    },
    // Architectural — circulation.
    Mapping {
        revit_class: "Stair",
        ifc_type: "IFCSTAIR",
        predefined_type: None,
    },
    Mapping {
        revit_class: "Railing",
        ifc_type: "IFCRAILING",
        predefined_type: None,
    },
    // Curtain-wall parts (RE-33): Revit's IFC4 export writes a mullion as
    // `IfcMember` `.MULLION.` and a panel as `IfcPlate` `.CURTAIN_PANEL.`.
    Mapping {
        revit_class: "CurtainWallMullion",
        ifc_type: "IFCMEMBER",
        predefined_type: Some("MULLION"),
    },
    Mapping {
        revit_class: "CurtainWallPanel",
        ifc_type: "IFCPLATE",
        predefined_type: Some("CURTAIN_PANEL"),
    },
    // `OST_Cornices`: Revit's IFC4 export writes a wall sweep as
    // `IfcBuildingElementProxy` `.NOTDEFINED.` (RE-33).
    Mapping {
        revit_class: "WallSweep",
        ifc_type: "IFCBUILDINGELEMENTPROXY",
        predefined_type: Some("NOTDEFINED"),
    },
    Mapping {
        revit_class: "Ramp",
        ifc_type: "IFCRAMP",
        predefined_type: None,
    },
    // Structural — load-bearing elements.
    Mapping {
        revit_class: "Column",
        ifc_type: "IFCCOLUMN",
        predefined_type: Some("COLUMN"),
    },
    Mapping {
        revit_class: "StructuralColumn",
        ifc_type: "IFCCOLUMN",
        predefined_type: Some("COLUMN"),
    },
    Mapping {
        revit_class: "StructuralFraming",
        ifc_type: "IFCBEAM",
        predefined_type: Some("BEAM"),
    },
    Mapping {
        revit_class: "StructuralFoundation",
        ifc_type: "IFCFOOTING",
        predefined_type: None,
    },
    Mapping {
        revit_class: "Rebar",
        ifc_type: "IFCREINFORCINGBAR",
        predefined_type: None,
    },
    // Structural — secondary members (IFC-10).
    // IfcMember is IFC4's entity for structural elements that aren't
    // the primary load path: bracing, trusses, studs, girts, purlins,
    // mullions, posts. Revit distinguishes these via the Family
    // Symbol / PredefinedType on the StructuralFraming class. When
    // the walker can identify the subtype, route through one of these
    // entries; otherwise StructuralFraming stays on the IfcBeam row
    // above.
    Mapping {
        revit_class: "Brace",
        ifc_type: "IFCMEMBER",
        predefined_type: Some("BRACE"),
    },
    Mapping {
        revit_class: "StructuralTruss",
        ifc_type: "IFCMEMBER",
        predefined_type: Some("CHORD"),
    },
    Mapping {
        revit_class: "Purlin",
        ifc_type: "IFCMEMBER",
        predefined_type: Some("PURLIN"),
    },
    Mapping {
        revit_class: "Post",
        ifc_type: "IFCMEMBER",
        predefined_type: Some("POST"),
    },
    Mapping {
        revit_class: "Stud",
        ifc_type: "IFCMEMBER",
        predefined_type: Some("STUD"),
    },
    Mapping {
        revit_class: "Strut",
        ifc_type: "IFCMEMBER",
        predefined_type: Some("STRUT"),
    },
    Mapping {
        revit_class: "Girt",
        ifc_type: "IFCMEMBER",
        predefined_type: Some("MEMBER"),
    },
    Mapping {
        revit_class: "Rafter",
        ifc_type: "IFCMEMBER",
        predefined_type: Some("RAFTER"),
    },
    // Spatial zoning.
    //
    // `.SPACE.` rather than `.INTERNAL.` (#220): Revit writes
    // `.SPACE.` on all 116 `IFCSPACE` rows of
    // `2024_Core_Interior_slim.ifc`. `Area` and `Space` keep `None` —
    // no recorded edge shows what the witness does with those two
    // Revit classes, and inventing a value is the thing this table
    // exists to avoid.
    Mapping {
        revit_class: "Room",
        ifc_type: "IFCSPACE",
        predefined_type: Some("SPACE"),
    },
    Mapping {
        revit_class: "Area",
        ifc_type: "IFCSPACE",
        predefined_type: None,
    },
    Mapping {
        revit_class: "Space",
        ifc_type: "IFCSPACE",
        predefined_type: None,
    },
    // Furnishings / equipment.
    Mapping {
        revit_class: "Furniture",
        ifc_type: "IFCFURNITURE",
        predefined_type: None,
    },
    Mapping {
        revit_class: "FurnitureSystem",
        ifc_type: "IFCFURNITURE",
        predefined_type: None,
    },
    Mapping {
        revit_class: "Casework",
        ifc_type: "IFCFURNITURE",
        predefined_type: None,
    },
    Mapping {
        revit_class: "LightingFixture",
        ifc_type: "IFCLIGHTFIXTURE",
        predefined_type: None,
    },
    Mapping {
        revit_class: "ElectricalEquipment",
        ifc_type: "IFCBUILDINGELEMENTPROXY",
        predefined_type: None,
    },
    Mapping {
        revit_class: "ElectricalFixture",
        ifc_type: "IFCBUILDINGELEMENTPROXY",
        predefined_type: None,
    },
    Mapping {
        revit_class: "MechanicalEquipment",
        ifc_type: "IFCBUILDINGELEMENTPROXY",
        predefined_type: None,
    },
    // #96: the IFC4 subtype of what Revit's export of RE1 Electrical (IFC2x3)
    // writes: fire alarm devices are IfcDistributionControlElement typed
    // IfcAlarmType, so IfcAlarm; data devices (its thermostats) are
    // IfcFlowTerminal typed IfcElectricApplianceType, so IfcElectricAppliance.
    // Lighting devices, electrical fixtures and electrical and mechanical
    // equipment are proxies there, and stay proxies.
    Mapping {
        revit_class: "LightingDevice",
        ifc_type: "IFCBUILDINGELEMENTPROXY",
        predefined_type: None,
    },
    Mapping {
        revit_class: "FireAlarmDevice",
        ifc_type: "IFCALARM",
        predefined_type: None,
    },
    Mapping {
        revit_class: "DataDevice",
        ifc_type: "IFCELECTRICAPPLIANCE",
        predefined_type: None,
    },
    Mapping {
        revit_class: "PlumbingFixture",
        ifc_type: "IFCSANITARYTERMINAL",
        predefined_type: None,
    },
    Mapping {
        revit_class: "SpecialtyEquipment",
        ifc_type: "IFCBUILDINGELEMENTPROXY",
        predefined_type: None,
    },
    // Ducts and pipes (RE-33), as their IFC4 distribution-element types.
    Mapping {
        revit_class: "Duct",
        ifc_type: "IFCDUCTSEGMENT",
        predefined_type: None,
    },
    Mapping {
        revit_class: "DuctFitting",
        ifc_type: "IFCDUCTFITTING",
        predefined_type: None,
    },
    Mapping {
        revit_class: "Pipe",
        ifc_type: "IFCPIPESEGMENT",
        predefined_type: None,
    },
    Mapping {
        revit_class: "PipeFitting",
        ifc_type: "IFCPIPEFITTING",
        predefined_type: None,
    },
    // Massing / abstract.
    Mapping {
        revit_class: "Mass",
        ifc_type: "IFCBUILDINGELEMENTPROXY",
        predefined_type: None,
    },
    Mapping {
        revit_class: "GenericModel",
        ifc_type: "IFCBUILDINGELEMENTPROXY",
        predefined_type: None,
    },
    // RE-37: the entities Revit's own IFC4 export writes for these
    // categories on Snowdon Towers (air terminals from the IFC4 subtype of
    // the IFC2x3 `IfcFlowTerminal` Revit writes on RE1 Mechanical).
    Mapping {
        revit_class: "DuctTerminal",
        ifc_type: "IFCAIRTERMINAL",
        predefined_type: None,
    },
    Mapping {
        revit_class: "FoodServiceEquipment",
        ifc_type: "IFCELECTRICAPPLIANCE",
        predefined_type: None,
    },
    Mapping {
        revit_class: "Planting",
        ifc_type: "IFCBUILDINGELEMENTPROXY",
        predefined_type: None,
    },
    Mapping {
        revit_class: "Parking",
        ifc_type: "IFCBUILDINGELEMENTPROXY",
        predefined_type: None,
    },
    Mapping {
        revit_class: "Entourage",
        ifc_type: "IFCBUILDINGELEMENTPROXY",
        predefined_type: None,
    },
    Mapping {
        revit_class: "Hardscape",
        ifc_type: "IFCBUILDINGELEMENTPROXY",
        predefined_type: None,
    },
    Mapping {
        revit_class: "VerticalCirculation",
        ifc_type: "IFCTRANSPORTELEMENT",
        predefined_type: None,
    },
    // RE-40: Revit's own IFC4 export writes every Snowdon slab edge outside
    // a non-primary design option as a proxy.
    Mapping {
        revit_class: "SlabEdge",
        ifc_type: "IFCBUILDINGELEMENTPROXY",
        predefined_type: None,
    },
    // #323: a stair's parts, aggregated under its `IfcStair` as in Revit's
    // IFC4 export of Snowdon Towers (flights, `.LANDING.` slabs,
    // `.STRINGER.` members).
    Mapping {
        revit_class: "StairsRun",
        ifc_type: "IFCSTAIRFLIGHT",
        predefined_type: None,
    },
    Mapping {
        revit_class: "StairsLanding",
        ifc_type: "IFCSLAB",
        predefined_type: Some("LANDING"),
    },
    Mapping {
        revit_class: "StairsStringer",
        ifc_type: "IFCMEMBER",
        predefined_type: Some("STRINGER"),
    },
];

/// Look up the IFC entity type for a Revit class name.
///
/// Returns `None` when the class has no registered mapping — callers
/// should emit `IfcBuildingElementProxy` as the fallback.
pub fn lookup(revit_class: &str) -> Option<&'static Mapping> {
    MAPPINGS.iter().find(|m| m.revit_class == revit_class)
}

/// IFC entity types a per-element Revit "IFC Export As" override may
/// redirect a decoded element to (#212, RE-22).
///
/// The override carrier is general —
/// [`crate::partition_ifc_export_overrides`] returns whatever value
/// string the parameter block holds — but acting on a value is a
/// claim, so only values proven against a reference export are
/// listed. An unlisted value leaves the element on its class mapping
/// and is reported as an unhonoured override rather than guessed at.
///
/// `IfcShadingDevice` is the one proven value: on
/// `2024_Core_Interior.rvt` the twenty `OST_Floors` instances that
/// carry it are exactly the twenty `IFCSHADINGDEVICE` rows in
/// Revit's own export, and the remaining seventy-nine plus the one
/// `OST_BuildingPad` instance are exactly its eighty `IFCSLAB` rows.
/// `PredefinedType` follows the authoring witness (#220 rule, #235):
/// Revit writes `.NOTDEFINED.` on all twenty `IFCSHADINGDEVICE` rows of
/// `IFC Exports/2024_Core_Interior_slim.ifc`, the same recorded choice
/// that moved `IFCWALL` off `.STANDARD.`. Before #235 this slot was `$`
/// on the grounds that rvt-rs decodes no value for it; the witness is
/// the value.
///
/// RE-45 adds two targets, each proven against a reference export:
/// `IfcSlab`, which the two Core Interior floors carrying `ifcSlab` (with
/// predefined type `ROOF`) are in Revit's export, and `IfcCovering`, which
/// the three `teste_export_2025` walls whose type carries `IfcCoveringType`
/// (with `CLADDING`) are. The override's own predefined type replaces the
/// target's default when it is an enumerator of that entity
/// ([`predefined_type_for`]).
pub const EXPORT_OVERRIDE_TARGETS: &[Mapping] = &[
    Mapping {
        revit_class: "IfcShadingDevice",
        ifc_type: "IFCSHADINGDEVICE",
        predefined_type: Some("NOTDEFINED"),
    },
    Mapping {
        revit_class: "IfcSlab",
        ifc_type: "IFCSLAB",
        predefined_type: Some("FLOOR"),
    },
    Mapping {
        revit_class: "IfcCovering",
        ifc_type: "IFCCOVERING",
        predefined_type: Some("NOTDEFINED"),
    },
];

/// IFC4 `PredefinedType` enumerators of the entities an export override
/// can name, as the IFC4 schema lists them (`IfcSlabTypeEnum`,
/// `IfcCoveringTypeEnum`, `IfcShadingDeviceTypeEnum`, `IfcRoofTypeEnum`).
const PREDEFINED_TYPE_ENUMERATORS: &[(&str, &[&str])] = &[
    (
        "IFCSLAB",
        &[
            "FLOOR",
            "ROOF",
            "LANDING",
            "BASESLAB",
            "USERDEFINED",
            "NOTDEFINED",
        ],
    ),
    (
        "IFCCOVERING",
        &[
            "CEILING",
            "FLOORING",
            "CLADDING",
            "ROOFING",
            "MOLDING",
            "SKIRTINGBOARD",
            "INSULATION",
            "MEMBRANE",
            "SLEEVING",
            "WRAPPING",
            "USERDEFINED",
            "NOTDEFINED",
        ],
    ),
    (
        "IFCSHADINGDEVICE",
        &["JALOUSIE", "SHUTTER", "AWNING", "USERDEFINED", "NOTDEFINED"],
    ),
    (
        "IFCROOF",
        &[
            "FLAT_ROOF",
            "SHED_ROOF",
            "GABLE_ROOF",
            "HIP_ROOF",
            "HIPPED_GABLE_ROOF",
            "GAMBREL_ROOF",
            "MANSARD_ROOF",
            "BARREL_ROOF",
            "RAINBOW_ROOF",
            "BUTTERFLY_ROOF",
            "PAVILION_ROOF",
            "DOME_ROOF",
            "FREEFORM",
            "USERDEFINED",
            "NOTDEFINED",
        ],
    ),
];

/// The IFC4 enumerator `value` names for `ifc_type`'s `PredefinedType`
/// (RE-45), compared case-insensitively because the Revit parameter is
/// user-entered text. `None` when the entity is not listed or the value is
/// not one of its enumerators, so the caller keeps its own default.
pub fn predefined_type_for(ifc_type: &str, value: &str) -> Option<&'static str> {
    let value = value.trim();
    PREDEFINED_TYPE_ENUMERATORS
        .iter()
        .find(|(entity, _)| *entity == ifc_type)?
        .1
        .iter()
        .copied()
        .find(|enumerator| enumerator.eq_ignore_ascii_case(value))
}

/// Look up the IFC entity type a "IFC Export As" override value names.
///
/// The comparison is case-insensitive because the parameter value is
/// user-entered text; everything else about it is exact.
pub fn lookup_export_override(value: &str) -> Option<&'static Mapping> {
    EXPORT_OVERRIDE_TARGETS
        .iter()
        .find(|m| m.revit_class.eq_ignore_ascii_case(value.trim()))
}

/// True when the mapping routes a Revit class through `IfcMember`
/// (as opposed to `IfcBeam` / `IfcColumn` / `IfcFooting`). Useful
/// for downstream code that wants to emit IfcMember-specific
/// property-sets (`Pset_MemberCommon`) or group members into an
/// `IfcRelAggregates` under a truss / frame assembly.
///
/// IFC-10: IfcMember is IFC4's dedicated entity for secondary
/// structural elements. Routing through it (rather than the
/// fallback `IfcBeam`) lets validators and downstream tools
/// distinguish primary beams from bracing / purlins / studs /
/// trusses, which matters for load-path visualization and
/// structural schedules.
pub fn is_ifc_member(revit_class: &str) -> bool {
    lookup(revit_class)
        .map(|m| m.ifc_type == "IFCMEMBER")
        .unwrap_or(false)
}

#[cfg(test)]
mod tests {
    use super::*;
    use std::collections::BTreeSet;

    #[test]
    fn export_override_maps_the_one_proven_value() {
        let m = lookup_export_override("IfcShadingDevice").unwrap();
        assert_eq!(m.ifc_type, "IFCSHADINGDEVICE");
        // The witness's own value on all 20 rows (#235).
        assert_eq!(m.predefined_type, Some("NOTDEFINED"));
        // The parameter value is user-entered text.
        assert!(lookup_export_override("  ifcshadingdevice  ").is_some());
    }

    #[test]
    fn export_override_maps_the_re45_values() {
        assert_eq!(
            lookup_export_override("ifcSlab").unwrap().ifc_type,
            "IFCSLAB"
        );
        assert_eq!(
            lookup_export_override("IfcCovering").unwrap().ifc_type,
            "IFCCOVERING"
        );
        assert!(lookup_export_override("IfcFooting").is_none());
    }

    #[test]
    fn predefined_type_override_must_be_an_enumerator_of_the_entity() {
        assert_eq!(predefined_type_for("IFCSLAB", "ROOF"), Some("ROOF"));
        assert_eq!(
            predefined_type_for("IFCCOVERING", "cladding"),
            Some("CLADDING")
        );
        assert_eq!(predefined_type_for("IFCSLAB", "CLADDING"), None);
        assert_eq!(predefined_type_for("IFCFOOTING", "PAD_FOOTING"), None);
        assert_eq!(predefined_type_for("IFCSLAB", "Sample"), None);
    }

    #[test]
    fn unproven_export_override_values_are_not_honoured() {
        // A value the reference export never demonstrated must leave
        // the element on its class mapping rather than invent a type.
        // Core Interior carries `IfcSpace` and `ifcFooting` overrides, but
        // only on elements Revit does not export, so neither is proven.
        assert!(lookup_export_override("IfcSpace").is_none());
        assert!(lookup_export_override("ifcFooting").is_none());
        assert!(lookup_export_override("").is_none());
    }

    #[test]
    fn building_pad_maps_to_ifcslab_floor() {
        let m = lookup("BuildingPad").unwrap();
        assert_eq!(m.ifc_type, "IFCSLAB");
        assert_eq!(m.predefined_type, Some("FLOOR"));
    }

    #[test]
    fn lookup_known_class() {
        let m = lookup("Wall").unwrap();
        assert_eq!(m.ifc_type, "IFCWALL");
        assert_eq!(m.predefined_type, Some("NOTDEFINED"));
    }

    /// #220: the four mappings that now follow the authoring witness
    /// instead of the closest-reading IFC4 enum. Each value is what
    /// Revit's own exporter writes on `2024_Core_Interior_slim.ifc`
    /// (360 walls `.NOTDEFINED.`, 116 spaces `.SPACE.`, 132 doors
    /// `.DOOR.`, 6 windows `.WINDOW.`).
    #[test]
    fn witness_following_predefined_types() {
        for (class, ifc_type, expected) in [
            ("Wall", "IFCWALL", "NOTDEFINED"),
            ("ArcWall", "IFCWALL", "NOTDEFINED"),
            ("Room", "IFCSPACE", "SPACE"),
            ("Door", "IFCDOOR", "DOOR"),
            ("Window", "IFCWINDOW", "WINDOW"),
        ] {
            let m = lookup(class).unwrap();
            assert_eq!(m.ifc_type, ifc_type, "{class} entity type");
            assert_eq!(m.predefined_type, Some(expected), "{class} PredefinedType");
        }
    }

    #[test]
    fn lookup_unknown_class_returns_none() {
        assert!(lookup("DefinitelyNotARevitClass").is_none());
    }

    #[test]
    fn revit_classes_unique() {
        let mut seen = BTreeSet::new();
        for m in MAPPINGS {
            assert!(
                seen.insert(m.revit_class),
                "duplicate mapping for {}",
                m.revit_class
            );
        }
    }

    #[test]
    fn ifc_type_names_uppercase_step_format() {
        for m in MAPPINGS {
            assert!(
                m.ifc_type.starts_with("IFC"),
                "{} should start with IFC",
                m.ifc_type
            );
            assert_eq!(
                m.ifc_type.to_uppercase(),
                m.ifc_type,
                "{} should be uppercase",
                m.ifc_type
            );
        }
    }

    #[test]
    fn door_and_window_follow_the_witness_predefined_type() {
        // This used to assert `None`, on the reading that IfcDoor /
        // IfcWindow carry their type variance on IfcDoorType /
        // IfcWindowType rather than PredefinedType. That reading is
        // defensible and still wrong for this table (#220): Revit's own
        // exporter populates both — the type object *and* `.DOOR.` /
        // `.WINDOW.` on the occurrence, on all 132 doors and all 6
        // windows of the recorded artifact. Writing `$` where the
        // witness wrote a value is a dropped observation, not restraint.
        assert_eq!(lookup("Door").unwrap().predefined_type, Some("DOOR"));
        assert_eq!(lookup("Window").unwrap().predefined_type, Some("WINDOW"));
    }

    #[test]
    fn structural_framing_maps_to_ifcbeam() {
        let m = lookup("StructuralFraming").unwrap();
        assert_eq!(m.ifc_type, "IFCBEAM");
    }

    #[test]
    fn room_area_space_all_map_to_ifcspace() {
        assert_eq!(lookup("Room").unwrap().ifc_type, "IFCSPACE");
        assert_eq!(lookup("Area").unwrap().ifc_type, "IFCSPACE");
        assert_eq!(lookup("Space").unwrap().ifc_type, "IFCSPACE");
    }

    // IFC-10: IfcMember secondary-structural routing.
    #[test]
    fn brace_maps_to_ifcmember_brace() {
        let m = lookup("Brace").unwrap();
        assert_eq!(m.ifc_type, "IFCMEMBER");
        assert_eq!(m.predefined_type, Some("BRACE"));
    }

    #[test]
    fn structural_truss_maps_to_ifcmember_chord() {
        let m = lookup("StructuralTruss").unwrap();
        assert_eq!(m.ifc_type, "IFCMEMBER");
        assert_eq!(m.predefined_type, Some("CHORD"));
    }

    #[test]
    fn secondary_members_route_to_ifcmember() {
        // All 8 IfcMember subtypes should route through IFCMEMBER
        // with the correct IFC4 PredefinedType. If any of these
        // flip back to IfcBeam, validators will complain about
        // bracing-in-load-path misclassification.
        let cases = [
            ("Brace", "BRACE"),
            ("StructuralTruss", "CHORD"),
            ("Purlin", "PURLIN"),
            ("Post", "POST"),
            ("Stud", "STUD"),
            ("Strut", "STRUT"),
            ("Girt", "MEMBER"),
            ("Rafter", "RAFTER"),
        ];
        for (revit, expected_pt) in cases {
            let m = lookup(revit).unwrap_or_else(|| panic!("{revit} missing from MAPPINGS"));
            assert_eq!(m.ifc_type, "IFCMEMBER", "{revit} should be IFCMEMBER");
            assert_eq!(
                m.predefined_type,
                Some(expected_pt),
                "{revit} predefined_type mismatch"
            );
        }
    }

    #[test]
    fn is_ifc_member_true_for_member_classes() {
        assert!(is_ifc_member("Brace"));
        assert!(is_ifc_member("StructuralTruss"));
        assert!(is_ifc_member("Stud"));
    }

    #[test]
    fn is_ifc_member_false_for_primary_beams() {
        // StructuralFraming stays on IfcBeam — callers that want to
        // route framing-as-bracing need a separate decision point
        // (e.g. Symbol family-name pattern match) and should NOT
        // rely on is_ifc_member() returning true for the base class.
        assert!(!is_ifc_member("StructuralFraming"));
        assert!(!is_ifc_member("Column"));
        assert!(!is_ifc_member("Beam"));
    }

    #[test]
    fn is_ifc_member_false_for_unknown_classes() {
        assert!(!is_ifc_member("DefinitelyNotARevitClass"));
    }

    #[test]
    fn ifc_member_predefined_types_are_spec_legal() {
        // IFC4 IfcMemberTypeEnum values — any future additions must
        // stay within this set. Updating IFC schema bumps (IFC4.3,
        // IFC5) would edit this list.
        let legal = [
            "BRACE",
            "CHORD",
            "COLLAR",
            "MEMBER",
            "MULLION",
            "PLATE",
            "POST",
            "PURLIN",
            "RAFTER",
            "STRINGER",
            "STRUT",
            "STUD",
            "USERDEFINED",
            "NOTDEFINED",
        ];
        for m in MAPPINGS.iter().filter(|m| m.ifc_type == "IFCMEMBER") {
            let pt = m
                .predefined_type
                .expect("IfcMember entries must have an explicit PredefinedType");
            assert!(
                legal.contains(&pt),
                "{} has illegal IfcMember PredefinedType: {}",
                m.revit_class,
                pt
            );
        }
    }
}