mod decoder;
pub mod ifcx;
pub mod lighting;
mod model;
mod properties;
mod resolver;
mod scanner;
mod spatial;
mod tokenizer;
mod units;
pub use decoder::EntityDecoder;
pub use ifcx::{is_ifcx_format, IfcxGeometry, IfcxModel};
pub use lighting::{
export_to_json, extract_lighting_data, goniometric_to_eulumdat, goniometric_to_ldt,
light_source_to_eulumdat, light_source_to_ldt, DistributionPlane, LightDistributionData,
LightFixtureData, LightSourceData, LightingExport,
};
pub use model::ParsedModel;
pub use scanner::EntityScanner;
pub use tokenizer::{parse_entity, Token};
use bimifc_model::{IfcModel, IfcParser, ProgressCallback, Result};
use std::sync::Arc;
#[derive(Default)]
pub struct StepParser {
pub build_spatial_tree: bool,
pub extract_properties: bool,
}
impl StepParser {
pub fn new() -> Self {
Self {
build_spatial_tree: true,
extract_properties: true,
}
}
pub fn geometry_only() -> Self {
Self {
build_spatial_tree: false,
extract_properties: false,
}
}
pub fn with_spatial_tree(mut self, enabled: bool) -> Self {
self.build_spatial_tree = enabled;
self
}
pub fn with_properties(mut self, enabled: bool) -> Self {
self.extract_properties = enabled;
self
}
}
impl IfcParser for StepParser {
fn parse(&self, content: &str) -> Result<Arc<dyn IfcModel>> {
ParsedModel::parse(content, self.build_spatial_tree, self.extract_properties)
.map(|m| Arc::new(m) as Arc<dyn IfcModel>)
}
fn parse_with_progress(
&self,
content: &str,
on_progress: ProgressCallback,
) -> Result<Arc<dyn IfcModel>> {
ParsedModel::parse_with_progress(
content,
self.build_spatial_tree,
self.extract_properties,
on_progress,
)
.map(|m| Arc::new(m) as Arc<dyn IfcModel>)
}
}
pub fn parse(content: &str) -> Result<Arc<dyn IfcModel>> {
StepParser::new().parse(content)
}
pub fn parse_with_progress(
content: &str,
on_progress: impl Fn(&str, f32) + Send + 'static,
) -> Result<Arc<dyn IfcModel>> {
StepParser::new().parse_with_progress(content, Box::new(on_progress))
}
pub fn parse_auto(content: &str) -> Result<Arc<dyn IfcModel>> {
if is_ifcx_format(content) {
IfcxModel::parse(content).map(|m| Arc::new(m) as Arc<dyn IfcModel>)
} else {
parse(content)
}
}
#[derive(Default)]
pub struct UnifiedParser {
pub step_settings: StepParser,
}
impl UnifiedParser {
pub fn new() -> Self {
Self::default()
}
}
impl IfcParser for UnifiedParser {
fn parse(&self, content: &str) -> Result<Arc<dyn IfcModel>> {
if is_ifcx_format(content) {
IfcxModel::parse(content).map(|m| Arc::new(m) as Arc<dyn IfcModel>)
} else {
self.step_settings.parse(content)
}
}
fn parse_with_progress(
&self,
content: &str,
on_progress: ProgressCallback,
) -> Result<Arc<dyn IfcModel>> {
if is_ifcx_format(content) {
on_progress("Parsing IFCX JSON", 0.0);
let result = IfcxModel::parse(content).map(|m| Arc::new(m) as Arc<dyn IfcModel>);
on_progress("Done", 1.0);
result
} else {
self.step_settings.parse_with_progress(content, on_progress)
}
}
}