Beispiel #1
0
def import_ifc_hierarchy(assembly: Assembly, product, ifc_ref: IfcRef):
    pr_type = product.is_a()
    pp = get_parent(product)
    if pp is None:
        return None, None

    # "IfcSpace",
    if pr_type not in ["IfcBuilding", "IfcBuildingStorey", "IfcSpatialZone"]:
        return None, None

    props = get_psets(product)
    name = product.Name
    if name is None:
        logging.debug(
            f'Name was not found for the IFC element "{product}". Will look for ref to name in props'
        )
        name = resolve_name(props, product)

    new_part = Part(
        name,
        metadata=dict(original_name=name, props=props),
        guid=product.GlobalId,
        ifc_ref=ifc_ref,
        units=assembly.units,
    )

    pp_name = pp.Name
    if pp_name is None:
        pp_name = resolve_name(get_psets(pp), pp)
    if pp_name is None:
        return None, None
    parent = assembly.get_by_name(pp_name)
    return parent, new_part
Beispiel #2
0
 def test_only_getting_qtos_and_not_psets(self):
     element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
     pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="pset")
     ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"a": "b"})
     qto = ifcopenshell.api.run("pset.add_qto", self.file, product=element, name="qto")
     ifcopenshell.api.run("pset.edit_qto", self.file, qto=qto, properties={"x": 42})
     assert subject.get_psets(element, qtos_only=True) == {"qto": {"x": 42, "id": qto.id()}}
Beispiel #3
0
def eleclass_has_property_in_pset(context, ifc_class, aproperty, pset):
    context.falseelems = []
    context.falseguids = []
    context.falseprops = {}
    from ifcopenshell.util.element import get_psets

    elements = IfcStore.file.by_type(ifc_class)
    for elem in elements:
        psets = get_psets(elem)
        if not (pset in psets and aproperty in psets[pset]):
            context.falseelems.append(str(elem))
            context.falseguids.append(elem.GlobalId)
        context.falseprops[elem.id()] = str(psets)

    context.elemcount = len(elements)
    context.falsecount = len(context.falseelems)
    util.assert_elements(
        ifc_class,
        context.elemcount,
        context.falsecount,
        context.falseelems,
        # TODO: Translate these messages into other languages
        message_all_falseelems=
        _("All {elemcount} {ifc_class} elements are missing the property {parameter} in the pset."
          ),
        message_some_falseelems=
        _("The following {falsecount} of {elemcount} {ifc_class} elements are missing the property {parameter} in the pset: {falseelems}"
          ),
        message_no_elems=_(
            "There are no {ifc_class} elements in the IFC file."),
        parameter=aproperty,
    )
Beispiel #4
0
def read_ifc_file(ifc_file: Union[str, pathlib.Path, StringIO],
                  ifc_settings,
                  elements2part=False,
                  data_only=False) -> Assembly:
    if type(ifc_file) is not StringIO:
        ifc_file = pathlib.Path(ifc_file).resolve().absolute()

        if ifc_file.exists() is False:
            raise FileNotFoundError(f'Unable to find "{ifc_file}"')

    ifc_ref = IfcRef(ifc_file)

    f = open_ifc(ifc_file)
    unit = get_unit_type(f)
    a = Assembly("TempAssembly", units=unit)
    a.ifc_settings = ifc_settings

    # Get hierarchy
    if elements2part is None:
        read_hierarchy(f, a, ifc_ref)

    # Get Materials
    read_ifc_materials(f, a, ifc_ref)

    # Get physical elements
    for product in f.by_type("IfcProduct"):
        if product.Representation is None or data_only is True:
            logging.info(f'Passing product "{product}"')
            continue
        parent = get_parent(product)
        name = product.Name

        if parent is None:
            logging.debug(f'Skipping "{name}". Parent is None')
            continue

        props = get_psets(product)

        if name is None:
            name = resolve_name(props, product)

        logging.info(f"importing {name}")

        obj = import_physical_ifc_elem(product, name, a, ifc_ref)
        if obj is None:
            continue

        obj.metadata.update(dict(props=props))
        obj.metadata["ifc_file"] = ifc_file

        add_to_assembly(a, obj, parent, elements2part)
    ifc_file_name = "object" if type(ifc_file) is StringIO else ifc_file
    print(f'Import of IFC file "{ifc_file_name}" is complete')
    return a
Beispiel #5
0
def step_impl(context, ifc_class, property_path, pattern):
    import re
    from ifcopenshell.util.element import get_psets

    pset_name, property_name = property_path.split(".")
    elements = IfcStore.file.by_type(ifc_class)
    for element in elements:

        psets = get_psets(element)

        if not pset_name in psets:
            assert False

        pset = psets[pset_name]
        if not property_name in pset:
            assert False

        prop = pset[property_name]
        # get_psets returns just strings

        if not re.search(pattern, prop):
            assert False
Beispiel #6
0
def add_to_assembly(assembly, obj, ifc_parent, elements2part):
    pp_name = ifc_parent.Name
    if pp_name is None:
        pp_name = resolve_name(get_psets(ifc_parent), ifc_parent)
        if pp_name is None:
            raise ValueError(f'Name of ifc element "{ifc_parent}" is None')

    imported = False
    if elements2part is not None:
        add_to_parent(assembly, obj)
        imported = True
    else:
        all_parts = assembly.get_all_parts_in_assembly()
        for p in all_parts:
            if p.name == pp_name or p.metadata.get("original_name") == pp_name:
                add_to_parent(p, obj)
                imported = True
                break

    if imported is False:
        logging.info(
            f'Unable to find parent "{pp_name}" for {type(obj)} "{obj.name}". Adding to Assembly'
        )
        assembly.add_shape(obj)
Beispiel #7
0
 def test_getting_psets_from_an_element_which_cannot_have_psets(self):
     assert subject.get_psets(self.file.create_entity("IfcPerson")) == {}
Beispiel #8
0
 def test_getting_the_psets_of_a_profile_as_a_dictionary(self):
     profile = self.file.createIfcCircleProfileDef()
     assert subject.get_psets(profile) == {}
     pset = ifcopenshell.api.run("pset.add_pset", self.file, product=profile, name="name")
     ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"x": "y"})
     assert subject.get_psets(profile) == {"name": {"x": "y", "id": pset.id()}}
Beispiel #9
0
 def test_getting_the_psets_of_a_material_as_a_dictionary(self):
     material = self.file.createIfcMaterial()
     assert subject.get_psets(material) == {}
     pset = ifcopenshell.api.run("pset.add_pset", self.file, product=material, name="name")
     ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"x": "y"})
     assert subject.get_psets(material) == {"name": {"x": "y", "id": pset.id()}}
Beispiel #10
0
 def test_getting_the_psets_of_a_product_type_as_a_dictionary(self):
     type_element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
     assert subject.get_psets(type_element) == {}
     pset = ifcopenshell.api.run("pset.add_pset", self.file, product=type_element, name="name")
     ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"x": "y"})
     assert subject.get_psets(type_element) == {"name": {"x": "y", "id": pset.id()}}