diff --git a/src/ada/ifc/read/read_beam_section.py b/src/ada/ifc/read/read_beam_section.py index 7c0a6f9a2..830463800 100644 --- a/src/ada/ifc/read/read_beam_section.py +++ b/src/ada/ifc/read/read_beam_section.py @@ -3,7 +3,7 @@ from ada.sections import Section -def import_section_from_ifc(ifc_elem): +def import_section_from_ifc(ifc_elem) -> Section: from ada.sections.utils import interpret_section_str try: diff --git a/src/ada/ifc/read/read_beams.py b/src/ada/ifc/read/read_beams.py index bf2518220..b187c0010 100644 --- a/src/ada/ifc/read/read_beams.py +++ b/src/ada/ifc/read/read_beams.py @@ -1,16 +1,34 @@ +import logging + import numpy as np -from ada import Beam, Material, Section +from ada import Assembly, Beam, Material from ada.core.vector_utils import unit_vector +from ada.ifc.utils import default_settings +from .read_beam_section import import_section_from_ifc from .read_shapes import get_ifc_shape -from .reader_utils import get_associated_material +from .reader_utils import get_associated_material, get_name, getIfcPropertySets + +def import_ifc_beam(ifc_elem, assembly: Assembly = None) -> Beam: + ifc_settings = default_settings() if assembly is None else assembly.ifc_settings -def import_ifc_beam(ifc_elem, name, props, ifc_settings) -> Beam: + props = getIfcPropertySets(ifc_elem) + name = get_name(ifc_elem) + logging.info(f"importing {name}") ass = get_associated_material(ifc_elem) - sec = Section(ass.Profile.ProfileName, ifc_elem=ass.Profile) - mat = Material(ass.Material.Name, ifc_mat=ass.Material) + sec = None + mat = None + + if assembly is not None: + sec = assembly.get_by_name(ass.Profile.ProfileName) + mat = assembly.get_by_name(ass.Material.Name) + + if sec is None: + sec = import_section_from_ifc(ass.Profile) + if mat is None: + mat = Material(ass.Material.Name, ifc_mat=ass.Material) axes = [rep for rep in ifc_elem.Representation.Representations if rep.RepresentationIdentifier == "Axis"] diff --git a/src/ada/ifc/read/read_ifc.py b/src/ada/ifc/read/read_ifc.py index 7e750b70b..7aaa715aa 100644 --- a/src/ada/ifc/read/read_ifc.py +++ b/src/ada/ifc/read/read_ifc.py @@ -8,19 +8,13 @@ from .read_parts import read_hierarchy from .read_plates import import_ifc_plate from .read_shapes import import_general_shape -from .reader_utils import ( - add_to_assembly, - get_name, - get_parent, - getIfcPropertySets, - open_ifc, -) +from .reader_utils import add_to_assembly, get_parent, open_ifc def read_ifc_file(ifc_file, ifc_settings, elements2part=False, data_only=False) -> Assembly: a = Assembly("TempAssembly") - + a.ifc_settings = ifc_settings f = open_ifc(ifc_file) scaled_ifc = scale_ifc_file(a.ifc_file, f) @@ -40,28 +34,25 @@ def read_ifc_file(ifc_file, ifc_settings, elements2part=False, data_only=False) logging.info(f'Passing product "{product}"') continue parent = get_parent(product) - obj = import_physical_ifc_elem(product, ifc_settings) + obj = import_physical_ifc_elem(product, a) + if obj is None: + continue obj.metadata["ifc_file"] = ifc_file - if obj is not None: - add_to_assembly(a, obj, parent, elements2part) + add_to_assembly(a, obj, parent, elements2part) print(f'Import of IFC file "{ifc_file}" is complete') return a -def import_physical_ifc_elem(product, ifc_settings): +def import_physical_ifc_elem(product, assembly: Assembly): pr_type = product.is_a() - - props = getIfcPropertySets(product) - name = get_name(product) - logging.info(f"importing {name}") if pr_type in ["IfcBeamStandardCase", "IfcBeam"]: - obj = import_ifc_beam(product, name, props, ifc_settings) + obj = import_ifc_beam(product, assembly) elif pr_type in ["IfcPlateStandardCase", "IfcPlate"]: - obj = import_ifc_plate(product, name, props, ifc_settings) + obj = import_ifc_plate(product, assembly) else: if product.is_a("IfcOpeningElement") is True: return None - obj = import_general_shape(product, name, props, ifc_settings) + obj = import_general_shape(product, assembly) return obj diff --git a/src/ada/ifc/read/read_plates.py b/src/ada/ifc/read/read_plates.py index 9c8fbe6b1..4d8633811 100644 --- a/src/ada/ifc/read/read_plates.py +++ b/src/ada/ifc/read/read_plates.py @@ -1,11 +1,27 @@ -from ada.concepts.structural import Plate -from ada.concepts.transforms import Placement +import logging + +from ada import Assembly, Material, Placement, Plate from ada.ifc.read.read_shapes import get_ifc_shape +from ..utils import default_settings from .read_curves import import_indexedpolycurve, import_polycurve +from .reader_utils import get_associated_material, get_name, getIfcPropertySets + + +def import_ifc_plate(ifc_elem, assembly: Assembly) -> Plate: + ifc_settings = default_settings() if assembly is None else assembly.ifc_settings + + props = getIfcPropertySets(ifc_elem) + name = get_name(ifc_elem) + logging.info(f"importing {name}") + ass = get_associated_material(ifc_elem) + mat = None + if assembly is not None: + mat = assembly.get_by_name(ass.Material.Name) + if mat is None: + mat = Material(ass.Material.Name, ifc_mat=ass.Material) -def import_ifc_plate(ifc_elem, name, props, ifc_settings) -> Plate: pdct_shape, color, alpha = get_ifc_shape(ifc_elem, ifc_settings) # TODO: Fix interpretation of IfcIndexedPolyCurve. Should pass origin to get actual 2d coordinates. @@ -44,6 +60,7 @@ def import_ifc_plate(ifc_elem, name, props, ifc_settings) -> Plate: name, nodes2d, t, + mat=mat, placement=placement, guid=ifc_elem.GlobalId, colour=color, diff --git a/src/ada/ifc/read/read_shapes.py b/src/ada/ifc/read/read_shapes.py index add9ffa42..b34fa9962 100644 --- a/src/ada/ifc/read/read_shapes.py +++ b/src/ada/ifc/read/read_shapes.py @@ -1,6 +1,10 @@ +import logging + import ifcopenshell.geom -from ada.concepts.primitives import Shape +from ada import Assembly, Shape + +from .reader_utils import get_name, getIfcPropertySets def get_ifc_shape(ifc_elem, settings): @@ -24,7 +28,10 @@ def get_ifc_shape(ifc_elem, settings): return geom, colour, alpha -def import_general_shape(product, name, props, ifc_settings): +def import_general_shape(product, assembly: Assembly): + props = getIfcPropertySets(product) + name = get_name(product) + logging.info(f"importing {name}") shp = Shape( name, None,