ifc_lite_wasm/api/
symbolic.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5//! 2D symbol extraction for the browser. Thin wrapper over the canonical
6//! extractor in `ifc-lite-processing` so the browser and the HTTP server
7//! produce bit-identical symbol streams (issue #843 follow-up: full
8//! parity, no separate code paths).
9//!
10//! The heavy lifting — Transform2D composition, IfcGrid bubbles,
11//! IfcTrimmedCurve arc handling, IfcAnnotationFillArea with holes,
12//! IfcStyledItem colour resolution, etc. — lives in
13//! `rust/processing/src/symbolic.rs`. This file just converts the
14//! resulting pure-Rust `SymbolicData` into the `wasm_bindgen` types the
15//! JS layer consumes.
16
17use super::IfcAPI;
18use wasm_bindgen::prelude::*;
19
20#[wasm_bindgen]
21impl IfcAPI {
22    /// Parse IFC file and extract symbolic representations (Plan,
23    /// Annotation, FootPrint, Axis). These are 2D curves used for
24    /// architectural drawings instead of sectioning 3D geometry.
25    ///
26    /// This standalone entry point detects an RTC frame from the whole source.
27    /// Use `parseSymbolicRepresentationsInFrame` when the symbols accompany
28    /// meshes produced by a streaming pre-pass or federation override.
29    ///
30    /// Example:
31    /// ```javascript
32    /// const api = new IfcAPI();
33    /// const symbols = api.parseSymbolicRepresentations(ifcData);
34    /// console.log('Found', symbols.totalCount, 'symbolic items');
35    /// for (let i = 0; i < symbols.polylineCount; i++) {
36    ///   const polyline = symbols.getPolyline(i);
37    ///   console.log('Polyline for', polyline.ifcType, ':', polyline.points);
38    /// }
39    /// ```
40    #[wasm_bindgen(js_name = parseSymbolicRepresentations)]
41    pub fn parse_symbolic_representations(
42        &self,
43        content: String,
44    ) -> crate::zero_copy::SymbolicRepresentationCollection {
45        let data = ifc_lite_processing::extract_symbolic_data_with_provenance(&content);
46        crate::zero_copy::SymbolicRepresentationCollection::from_data_with_provenance(data)
47    }
48
49    /// Parse symbolic representations in the exact RTC frame selected by the
50    /// browser mesh pre-pass rather than detecting a second frame from the
51    /// whole source.
52    #[wasm_bindgen(js_name = parseSymbolicRepresentationsInFrame)]
53    pub fn parse_symbolic_representations_in_frame(
54        &self,
55        content: String,
56        #[wasm_bindgen(unchecked_param_type = "RtcFrame")] frame: JsValue,
57    ) -> Result<crate::zero_copy::SymbolicRepresentationCollection, JsValue> {
58        let frame = super::overlay_frame::parse_overlay_frame(&frame)?;
59        let data = ifc_lite_processing::extract_symbolic_data_with_provenance_in_frame(
60            &content,
61            frame,
62        );
63        Ok(crate::zero_copy::SymbolicRepresentationCollection::from_data_with_provenance(data))
64    }
65}