Ejemplo n.º 1
0
def only_eleclasses(context, ifc_classes):

    context.falseelems = []
    context.falseguids = []

    # get the list of ifc_classes
    target_ifc_classes = ifc_classes.replace(" ", "").split(",")
    # ToDo test if they exist in ifc standard, should be possible with ifcos

    all_elements = IfcStore.file.by_type("IfcBuildingElement")
    context.elemcount = len(all_elements)

    false_elements = []
    for elem in all_elements:
        if elem.is_a() not in target_ifc_classes:
            context.falseelems.append(str(elem))
            context.falseguids.append(elem.GlobalId)
    context.falsecount = len(context.falseelems)

    # use ifc_classes in method parameter but ifc_class in string parameter
    # be careful somehow the opposite of most other tests is tested
    util.assert_elements(
        ifc_classes,
        context.elemcount,
        context.falsecount,
        context.falseelems,
        message_all_falseelems=_("All {elemcount} elements in the file are not {ifc_class} elements."),
        message_some_falseelems=_(
            "{falsecount} of {elemcount} false_elements are not {ifc_class} elements: {falseelems}"
        ),
    )
Ejemplo n.º 2
0
def eleclass_has_description_with_a_value(context, ifc_class):

    context.falseelems = []
    context.falseguids = []

    elements = IfcStore.file.by_type(ifc_class)
    for elem in elements:
        # print(elem.Description)
        if not elem.Description:
            context.falseelems.append(str(elem))
            context.falseguids.append(elem.GlobalId)

    context.elemcount = len(elements)
    context.falsecount = len(context.falseelems)
    util.assert_elements(
        ifc_class,
        context.elemcount,
        context.falsecount,
        context.falseelems,
        message_all_falseelems=_("The description of all {elemcount} elements is not set."),
        message_some_falseelems=_(
            "The description of {falsecount} out of {elemcount} {ifc_class} elements is not set: {falseelems}"
        ),
        message_no_elems=_("There are no {ifc_class} elements in the IFC file."),
    )
Ejemplo n.º 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,
    )
Ejemplo n.º 4
0
def assert_type(element, ifc_class, is_exact=False):
    if is_exact:
        assert element.is_a() == ifc_class, _(
            "The element {} is an {} instead of {}.").format(
                element, element.is_a(), ifc_class)
    else:
        assert element.is_a(ifc_class), _(
            "The element {} is an {} instead of {}.").format(
                element, element.is_a(), ifc_class)
Ejemplo n.º 5
0
def eleclass_has_geometric_representation_of_specific_class(
        context, ifc_class, representation_class):
    def is_item_a_representation(item, representation):
        if "/" in representation:
            for cls in representation.split("/"):
                if item.is_a(cls):
                    return True
        elif item.is_a(representation):
            return True

    context.falseelems = []
    context.falseguids = []
    context.falseprops = {}
    rep = None

    elements = IfcStore.file.by_type(ifc_class)
    for elem in elements:
        if not elem.Representation:
            continue
        has_representation = False
        for representation in elem.Representation.Representations:
            for item in representation.Items:
                if item.is_a("IfcMappedItem"):
                    # We only check one more level deep.
                    for item2 in item.MappingSource.MappedRepresentation.Items:
                        if is_item_a_representation(item2,
                                                    representation_class):
                            has_representation = True
                        rep = item2
                else:
                    if is_item_a_representation(item, representation_class):
                        has_representation = True
                    rep = item
        if not has_representation:
            context.falseelems.append(str(elem))
            context.falseguids.append(elem.GlobalId)
            context.falseprops[elem.id()] = str(rep)

    context.elemcount = len(elements)
    context.falsecount = len(context.falseelems)
    util.assert_elements(
        ifc_class,
        context.elemcount,
        context.falsecount,
        context.falseelems,
        message_all_falseelems=
        _("All {elemcount} {ifc_class} elements are not a {parameter} representation."
          ),
        message_some_falseelems=
        _("The following {falsecount} of {elemcount} {ifc_class} elements are not a {parameter} representation: {falseelems}"
          ),
        message_no_elems=_(
            "There are no {ifc_class} elements in the IFC file."),
        parameter=representation_class,
    )
Ejemplo n.º 6
0
def step_impl(context, guid):
    site = util.assert_guid(IfcStore.file, guid)
    util.assert_type(site, "IfcSite")
    if not site.ObjectPlacement:
        assert False, _("The site has no object placement")
    site_placement = ifcopenshell.util.placement.get_local_placement(
        site.ObjectPlacement)[:, 3][0:3]
    origin = np.array([0, 0, 0])
    assert np.allclose(
        origin,
        site_placement), _('The site location is at "{}" instead of "{}"')
Ejemplo n.º 7
0
def step_impl(context, guid, easting, northing, elevation):
    if IfcStore.file.schema == "IFC2X3":
        if element.is_a("IfcSite"):
            site = element
        else:
            potential_sites = [
                s for s in get_containing_spatial_elements(element)
                if s.is_a("IfcSite")
            ]
            if potential_sites:
                site = potential_sites[0]
            else:
                assert False, _(
                    "The datum element does not belong to a geolocated site")
        map_conversion = util.assert_pset(site, "EPset_MapConversion")
    else:
        map_conversion = IfcStore.file.by_type("IfcMapConversion")
        if map_conversion:
            map_conversion = map_conversion[0].get_info()
        else:
            assert False, _("No map conversion was found in the file")

    element = util.assert_guid(IfcStore.file, guid)
    if not element.ObjectPlacement:
        assert False, _("The element does not have an object placement: {}"
                        ).format(element)
    m = ifcopenshell.util.placement.get_local_placement(
        element.ObjectPlacement)
    e, n, h = ifcopenshell.util.geolocation.xyz2enh(
        m[0][3],
        m[1][3],
        m[2][3],
        float(map_conversion["Eastings"]),
        float(map_conversion["Northings"]),
        float(map_conversion["OrthogonalHeight"]),
        float(map_conversion["XAxisAbscissa"]),
        float(map_conversion["XAxisOrdinate"]),
        float(map_conversion["Scale"]),
    )
    element_x = round(e, get_decimal_points(easting))
    element_y = round(n, get_decimal_points(northing))
    element_z = round(h, get_decimal_points(elevation))
    expected_placement = (util.assert_number(easting),
                          util.assert_number(northing),
                          util.assert_number(elevation))
    if (element_x, element_y, element_z) != expected_placement:
        assert False, _(
            "The element {} is meant to have a location of {} but instead we found {}"
        ).format(element, expected_placement,
                 (element_x, element_y, element_z))
Ejemplo n.º 8
0
def eleclass_have_class_attributes_with_a_value(context, ifc_class):

    from ifcopenshell.ifcopenshell_wrapper import schema_by_name

    # schema = schema_by_name("IFC2X3")
    schema = schema_by_name(IfcStore.file.schema)
    class_attributes = []
    for cl_attrib in schema.declaration_by_name(ifc_class).all_attributes():
        class_attributes.append(cl_attrib.name())
    # print(class_attributes)

    context.falseelems = []
    context.falseguids = []
    context.falseprops = {}

    elements = IfcStore.file.by_type(ifc_class)
    failed_attribs = []
    for elem in elements:
        elem_failed = False
        for cl_attrib in class_attributes:
            attrib_value = getattr(elem, cl_attrib)
            if not attrib_value:
                elem_failed = True
                failed_attribs.append(cl_attrib)
                # print(attrib_value)
        if elem_failed is True:
            context.falseelems.append(str(elem))
            context.falseguids.append(elem.GlobalId)
            context.falseprops[elem.id()] = failed_attribs

    context.elemcount = len(elements)
    context.falsecount = len(context.falseelems)
    util.assert_elements(
        ifc_class,
        context.elemcount,
        context.falsecount,
        context.falseelems,
        message_all_falseelems=_(
            "For all {elemcount} {ifc_class} elements at least one of these class attributes {parameter} has no value."
        ),
        message_some_falseelems=_(
            "For the following {falsecount} out of {elemcount} {ifc_class} elements at least one of these class attributes {parameter} has no value: {falseelems}"
        ),
        message_no_elems=_("There are no {ifc_class} elements in the IFC file."),
        parameter=failed_attribs,
    )
Ejemplo n.º 9
0
def step_impl(context, number):
    number = util.assert_number(number)
    project = IfcStore.file.by_type("IfcProject")[0]
    for c in project.RepresentationContexts:
        if c.TrueNorth:
            actual_value = round(
                ifcopenshell.util.geolocation.yaxis2angle(
                    c.TrueNorth.DirectionRatios[0],
                    c.TrueNorth.DirectionRatios[1]),
                3,
            )
            value = round(number, 3)
            assert actual_value == value, _(
                'We expected a value of "{}" but instead got "{}"').format(
                    value, actual_value)
            return
    assert False, _("True north is not defined in the file")
Ejemplo n.º 10
0
def step_impl(context, guid, x, y, z):
    element = util.assert_guid(IfcStore.file, guid)
    if not element.ObjectPlacement:
        assert False, _("The element does not have an object placement: {}"
                        ).format(element)
    m = ifcopenshell.util.placement.get_local_placement(
        element.ObjectPlacement)
    element_x = round(m[0][3], get_decimal_points(x))
    element_y = round(m[1][3], get_decimal_points(y))
    element_z = round(m[2][3], get_decimal_points(z))
    expected_placement = (util.assert_number(x), util.assert_number(y),
                          util.assert_number(z))
    if (element_x, element_y, element_z) != expected_placement:
        assert False, _(
            "The element {} is meant to have a location of {} but instead we found {}"
        ).format(element, expected_placement,
                 (element_x, element_y, element_z))
Ejemplo n.º 11
0
def step_impl(context, unit):
    if IfcStore.file.schema == "IFC2X3":
        for site in IfcStore.file.by_type("IfcSite"):
            util.assert_pset(site, "EPset_ProjectedCRS", "MapUnit", unit)
        return
    actual_value = check_ifc4_geolocation("IfcProjectedCRS",
                                          "MapUnit",
                                          should_assert=False)
    if not actual_value:
        assert False, _("A unit was not provided in the projected CRS")
    if actual_value.is_a("IfcSIUnit"):
        prefix = actual_value.Prefix if actual_value.Prefix else ""
        actual_value = prefix + actual_value.Name
    elif actual_value.is_a("IfcConversionBasedUnit"):
        actual_value = actual_value.Name
    assert actual_value == unit, _(
        'We expected a value of "{}" but instead got "{}"').format(
            unit, actual_value)
Ejemplo n.º 12
0
def step_impl(context, guid, identification, reference_name):
    element = util.assert_guid(IfcStore.file, guid)
    if not hasattr(element, "HasAssociations") or not element.HasAssociations:
        assert False, _("The element {} has no associations.").format(element)
    references = [a.RelatingClassification for a in element.HasAssociations if a.is_a("IfcRelAssociatesClassification")]
    if not references:
        assert False, _("The element {element} has no associated classification references.").format(element)
    is_success = False
    for reference in references:
        try:
            util.assert_attribute(reference, "Identification", identification)
            util.assert_attribute(reference, "Name", reference_name)
            is_success = True
        except:
            pass
    if not is_success:
        assert False, _(
            "No classification references met the requirement for an identification {} and name {} for the element {}.  The references we found were: {}"
        ).format(identification, reference_name, element, references)
Ejemplo n.º 13
0
def assert_attribute(element, name, value=None):
    if not hasattr(element, name):
        assert False, _(
            "The element {} does not have the attribute {}").format(
                element, name)
    if not value:
        if getattr(element, name) is None:
            assert False, _(
                "The element {} does not have a value for the attribute {}"
            ).format(element, name)
        return getattr(element, name)
    if value == "NULL":
        value = None
    actual_value = getattr(element, name)
    if isinstance(value, list) and actual_value:
        actual_value = list(actual_value)
    assert actual_value == value, _(
        'We expected a value of "{}" but instead got "{}" for the element {}'
    ).format(value, actual_value, element)
Ejemplo n.º 14
0
def assert_pset(element, pset_name, prop_name=None, value=None):
    if value == "NULL":
        value = None
    psets = ifcopenshell.util.element.get_psets(site)
    if pset_name not in psets:
        assert False, _(
            "The element {} does not have a property set named {}").format(
                element, pset_name)
    if prop_name is None:
        return psets[pset_name]
    if prop_name not in psets[pset_name]:
        assert False, _(
            'The element {} does not have a property named "{}" in the pset "{}"'
        ).format(element, prop_name, pset_name)
    if value is None:
        return psets[pset_name][prop_name]
    actual_value = psets[pset_name][prop_name]
    assert actual_value == value, _(
        'We expected a value of "{}" but instead got "{}" for the element {}'
    ).format(value, actual_value, element)
Ejemplo n.º 15
0
def step_impl(context, guid, predefined_type):
    element = util.assert_guid(IfcStore.file, guid)
    if (
        hasattr(element, "PredefinedType")
        and element.PredefinedType == "USERDEFINED"
        and hasattr(element, "ObjectType")
    ):
        util.assert_attribute(element, "ObjectType", predefined_type)
    elif hasattr(element, "PredefinedType"):
        util.assert_attribute(element, "PredefinedType", predefined_type)
    else:
        assert False, _("The element {} does not have a PredefinedType or ObjectType attribute").format(element)
Ejemplo n.º 16
0
def no_eleclass(context, ifc_class):

    context.falseelems = []
    context.falseguids = []

    elements = IfcStore.file.by_type(ifc_class)
    context.elemcount = len(IfcStore.file.by_type("IfcBuildingElement"))
    for elem in elements:
        context.falseelems.append(str(elem))
        context.falseguids.append(elem.GlobalId)
    context.falsecount = len(context.falseelems)

    # be careful somehow the opposite of most other tests is tested
    util.assert_elements(
        ifc_class,
        context.elemcount,
        context.falsecount,
        context.falseelems,
        message_all_falseelems=_("All {elemcount} elements in the file are {ifc_class} elements."),
        message_some_falseelems=_("{falsecount} of {elemcount} false_elements are {ifc_class} elements: {falseelems}"),
    )
Ejemplo n.º 17
0
def assert_elements(
    ifc_class,
    elemcount,
    falsecount,
    falseelems,
    message_all_falseelems,
    message_some_falseelems,
    message_no_elems="",
    parameter=None,
):
    out_falseelems = "\n"
    for e in falseelems:
        out_falseelems += e + "\n"
    # old, elemcount == 0 creates a failed test, but should not
    # no elements of a ifc_class should not be a fail
    # if a ifc_class has to be exist, it should be in a own test
    # if elemcount > 0 and falsecount == 0:
    #     return # Test OK
    # elif elemcount == 0:
    #     assert False, (
    #         message_no_elems.format(
    #             ifc_class=ifc_class
    #         )
    #     )
    if falsecount == 0:
        return  # test ok for elemcount == 0 and elemcount > 0
    elif falsecount == elemcount:
        if parameter is None:
            assert False, message_all_falseelems.format(elemcount=elemcount,
                                                        ifc_class=ifc_class)
        else:
            assert False, message_all_falseelems.format(elemcount=elemcount,
                                                        ifc_class=ifc_class,
                                                        parameter=parameter)
    elif falsecount > 0 and falsecount < elemcount:
        if parameter is None:
            assert False, message_some_falseelems.format(
                falsecount=falsecount,
                elemcount=elemcount,
                ifc_class=ifc_class,
                falseelems=out_falseelems,
            )
        else:
            assert False, message_some_falseelems.format(
                falsecount=falsecount,
                elemcount=elemcount,
                ifc_class=ifc_class,
                falseelems=out_falseelems,
                parameter=parameter,
            )
    else:
        assert False, _(
            "Error in falsecount calculation, something went wrong.")
Ejemplo n.º 18
0
def check_ifc4_geolocation(entity_name,
                           prop_name=None,
                           value=None,
                           should_assert=True):
    if entity_name not in IfcStore.bookmarks:
        has_entity = False
        project = IfcStore.file.by_type("IfcProject")[0]
        for context in project.RepresentationContexts:
            if entity_name == "IfcMapConversion":
                if (context.is_a("IfcGeometricRepresentationContext")
                        and context.ContextType == "Model"
                        and context.HasCoordinateOperation):
                    IfcStore.bookmarks[
                        entity_name] = context.HasCoordinateOperation[0]
                    has_entity = True
            elif entity_name == "IfcProjectedCRS":
                if (context.is_a("IfcGeometricRepresentationContext")
                        and context.ContextType == "Model"
                        and context.HasCoordinateOperation
                        and context.HasCoordinateOperation[0].TargetCRS):
                    IfcStore.bookmarks[
                        entity_name] = context.HasCoordinateOperation[
                            0].TargetCRS
                    has_entity = True
        if not has_entity:
            assert False, _(
                "No model geometric representation contexts refer to an {}"
            ).format(entity_name)
    if not prop_name:
        return
    actual_value = getattr(IfcStore.bookmarks[entity_name], prop_name)
    if should_assert:
        assert actual_value == value, _(
            'We expected a value of "{}" but instead got "{}"').format(
                value, actual_value)
    else:
        return actual_value
Ejemplo n.º 19
0
 def get_template_strings(self):
     return {
         # "_lang": _("en"),
         "_success": _("Success"),
         "_failure": _("Failure"),
         "_tests_passed": _("Tests passed"),
         "_duration": _("Duration"),
         "_auditing": _("OpenBIM auditing is a feature of"),
         "_and": _("and"),
     }
Ejemplo n.º 20
0
def step_impl(context, number):
    number = util.assert_number(number)
    if IfcStore.file.schema == "IFC2X3":
        return check_ifc2x3_geolocation("EPset_MapConversion", "Height",
                                        number)
    abscissa = check_ifc4_geolocation("IfcMapConversion",
                                      "XAxisAbscissa",
                                      should_assert=False)
    ordinate = check_ifc4_geolocation("IfcMapConversion",
                                      "XAxisOrdinate",
                                      should_assert=False)
    actual_value = round(
        ifcopenshell.util.geolocation.xaxis2angle(abscissa, ordinate), 3)
    value = round(number, 3)
    assert actual_value == value, _(
        'We expected a value of "{}" but instead got "{}"').format(
            value, actual_value)
Ejemplo n.º 21
0
def step_impl(context, ifc_class):
    assert len(IfcStore.file.by_type(ifc_class)) >= 1, _(
        "An element of {} could not be found").format(ifc_class)
Ejemplo n.º 22
0
def step_impl(context, guid, reason):
    try:
        element = IfcStore.file.by_id(guid)
    except:
        return
    assert False, _("This element {} should be reevaluated.").format(element)
Ejemplo n.º 23
0
def assert_number(number):
    try:
        return float(number)
    except ValueError:
        assert False, _("A number should be specified, not {}").format(number)
Ejemplo n.º 24
0
def assert_guid(ifc, guid):
    try:
        return ifc.by_guid(guid)
    except:
        assert False, _(
            "An element with the ID {} could not be found.").format(guid)
Ejemplo n.º 25
0
def step_impl(context, schema):
    real_schema = IfcStore.file.schema
    assert real_schema == schema, _(
        "We expected a schema of {} but instead got {}").format(
            schema, real_schema)
Ejemplo n.º 26
0
def step_impl(context, name, tokens):
    try:
        tokens = json.loads(tokens)
    except:
        assert False, _("Tokens {} are not specified as a JSON list").format(tokens)
    util.assert_attribute(get_classification(name), "ReferenceTokens", tokens)