Skip to content

Commit

Permalink
further work on Ifc reading refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
krande committed Nov 12, 2021
1 parent 5a767e2 commit eacc284
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/ada/ifc/read/read_beam_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
28 changes: 23 additions & 5 deletions src/ada/ifc/read/read_beams.py
Original file line number Diff line number Diff line change
@@ -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"]

Expand Down
29 changes: 10 additions & 19 deletions src/ada/ifc/read/read_ifc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
23 changes: 20 additions & 3 deletions src/ada/ifc/read/read_plates.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 9 additions & 2 deletions src/ada/ifc/read/read_shapes.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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,
Expand Down

0 comments on commit eacc284

Please sign in to comment.