diff --git a/CHANGELOG.md b/CHANGELOG.md index f3c9b3a9..2aca5e3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,9 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added * Added `export` method to `IFCFile` and `Model` to export selected list of entities. +* Added `update_linear_deflection` to `Model`. ### Changed +* Automatically convert `Brep` to `Mesh` when assigned in `IFC2X3`. + ### Removed diff --git a/src/compas_ifc/file.py b/src/compas_ifc/file.py index 04a42877..17ba3076 100644 --- a/src/compas_ifc/file.py +++ b/src/compas_ifc/file.py @@ -34,6 +34,7 @@ def __init__(self, model, filepath=None, schema="IFC4", use_occ=False, load_geom else: self._file = ifcopenshell.open(filepath) print("IFC file loaded: {}".format(filepath)) + self.model.update_linear_deflection() self._schema = ifcopenshell.ifcopenshell_wrapper.schema_by_name(self._file.schema) diff --git a/src/compas_ifc/model.py b/src/compas_ifc/model.py index 731d17bc..e4ac4f42 100644 --- a/src/compas_ifc/model.py +++ b/src/compas_ifc/model.py @@ -3,6 +3,7 @@ from compas.data import Data from compas.geometry import Transformation +from compas.tolerance import TOL from compas_ifc.file import IFCFile @@ -149,6 +150,15 @@ def update_treeform(form, node): def create(self, cls="IfcBuildingElementProxy", parent=None, geometry=None, frame=None, properties=None, **kwargs): return self.file.create(cls=cls, parent=parent, geometry=geometry, frame=frame, properties=properties, **kwargs) + def update_linear_deflection(self): + length_unit = self.project.length_unit + if length_unit["name"] == "METRE" and length_unit["prefix"] == "MILLI": + TOL.lineardeflection = 1 + elif length_unit["name"] == "METRE" and length_unit["prefix"] == "CENTI": + TOL.lineardeflection = 1e-1 + elif length_unit["name"] == "METRE" and not length_unit["prefix"]: + TOL.lineardeflection = 1e-3 + @classmethod def template(cls, schema="IFC4", building_count=1, storey_count=1): model = cls(schema=schema) @@ -158,6 +168,8 @@ def template(cls, schema="IFC4", building_count=1, storey_count=1): building = model.create("IfcBuilding", parent=site, Name=f"Default Building {i+1}") for j in range(storey_count): model.create("IfcBuildingStorey", parent=building, Name=f"Default Storey {j+1}") + + model.update_linear_deflection() return model diff --git a/src/compas_ifc/resources/representation.py b/src/compas_ifc/resources/representation.py index 2a763f95..3aa46651 100644 --- a/src/compas_ifc/resources/representation.py +++ b/src/compas_ifc/resources/representation.py @@ -3,6 +3,7 @@ from compas.geometry import Cone from compas.geometry import Cylinder from compas.geometry import Sphere +from compas.tolerance import TOL from ifcopenshell.api import run from .brep import brep_to_ifc_advanced_brep @@ -35,7 +36,11 @@ def _body_to_shape(body): else: shape = mesh_to_IfcShellBasedSurfaceModel(file, body) elif OCCBrep and isinstance(body, OCCBrep): - shape = brep_to_ifc_advanced_brep(file, body) + if file.schema == "IFC2X3": + print("IFC2X3 does not support advanced brep, converting representation of {} to mesh.".format(ifc_entity)) + shape = mesh_to_IfcShellBasedSurfaceModel(file, body.to_viewmesh(linear_deflection=TOL.lineardeflection)[0]) + else: + shape = brep_to_ifc_advanced_brep(file, body) else: raise Exception("Unsupported body type.") return shape