def step_impl(context, number):
    number = assert_number(number)
    if IfcFile.get().schema == 'IFC2X3':
        for site in IfcFile.get().by_type('IfcSite'):
            assert_pset(site, 'EPset_MapConversion', 'Scale', number)
        return
    check_ifc4_geolocation('IfcMapConversion', 'Scale', number)
Example #2
0
def step_impl(context, number):
    number = assert_number(number)
    if IfcFile.get().schema == "IFC2X3":
        for site in IfcFile.get().by_type("IfcSite"):
            assert_pset(site, "EPset_MapConversion", "Scale", number)
        return
    check_ifc4_geolocation("IfcMapConversion", "Scale", number)
def step_impl(context, coordinate_reference_name):
    if IfcFile.get().schema == 'IFC2X3':
        for site in IfcFile.get().by_type('IfcSite'):
            assert_pset(site, 'EPset_ProjectedCRS', 'VerticalDatum',
                        coordinate_reference_name)
        return
    check_ifc4_geolocation('IfcProjectedCRS', 'VerticalDatum',
                           coordinate_reference_name)
Example #4
0
def step_impl(context, ifc_class, property_path, pattern):
    import re
    pset_name, property_name = property_path.split('.')
    elements = IfcFile.get().by_type(ifc_class)
    for element in elements:
        prop = IfcFile.get_property(element, pset_name, property_name)
        if not prop:
            assert False
        # For now, we only check single values
        if prop.is_a('IfcPropertySingleValue'):
            if not (prop.NominalValue \
                    and re.search(pattern, prop.NominalValue.wrappedValue)):
                assert False
Example #5
0
def step_impl(context, unit):
    if IfcFile.get().schema == "IFC2X3":
        for site in IfcFile.get().by_type("IfcSite"):
            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)
def step_impl(context, ifc_class, attribute_name, attribute_value):
    elements = IfcFile.get().by_type(ifc_class)
    for element in elements:
        if hasattr(element, attribute_name) and getattr(
                element, attribute_name) == attribute_value:
            return
    assert False
def step_impl(context, ifc_class, pattern):
    import re

    elements = IfcFile.get().by_type(ifc_class)
    for element in elements:
        if not re.search(pattern, element.Name):
            assert False
Example #8
0
def step_impl(context, ifc_class, attribute, pattern):
    import re
    elements = IfcFile.get().by_type(ifc_class)
    for element in elements:
        value = getattr(element, attribute)
        print(f'Checking value "{value}" for {element}')
        assert re.search(pattern, value)
def step_impl(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

    elements = IfcFile.get().by_type(ifc_class)
    for element in elements:
        if not element.Representation:
            continue
        has_representation = False
        for representation in element.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
                else:
                    if is_item_a_representation(item, representation_class):
                        has_representation = True
        if not has_representation:
            assert False
def get_classification(name):
    classifications = [
        c for c in IfcFile.get().by_type('IfcClassification') if c.Name == name
    ]
    if len(classifications) != 1:
        assert False, f'The classification "{name}" was not found'
    return classifications[0]
Example #11
0
def check_ifc4_geolocation(entity_name,
                           prop_name=None,
                           value=None,
                           should_assert=True):
    if entity_name not in IfcFile.bookmarks:
        has_entity = False
        project = IfcFile.get().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:
                    IfcFile.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:
                    IfcFile.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(IfcFile.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
Example #12
0
def step_impl(context, guid, number):
    number = assert_number(number)
    site = IfcFile.by_guid(guid)
    if not site.is_a("IfcSite"):
        assert False, "The element {} is not an IfcSite".format(site)
    ref = assert_attribute(site, "RefLatitude")
    number = ifcopenshell.util.geolocation.dd2dms(number, use_ms=(len(ref) == 4))
    assert_attribute(site, "RefLatitude", number)
Example #13
0
def step_impl(context, guid, easting, northing, elevation):
    if IfcFile.get().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 = assert_pset(site, 'EPset_MapConversion')
    else:
        map_conversion = IfcFile.get().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 = IfcFile.by_guid(guid)
    if not element.ObjectPlacement:
        assert False, 'The element does not have an object placement: {}'.format(
            element)
    m = 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 = (assert_number(easting), assert_number(northing),
                          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))
Example #14
0
def step_impl(context, number):
    number = assert_number(number)
    if IfcFile.get().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.xy2angle(abscissa, ordinate), 3)
    value = round(number, 3)
    assert actual_value == value, 'We expected a value of "{}" but instead got "{}"'.format(value, actual_value)
Example #15
0
def check_geocode_address(guid, spatial_type, name, value):
    element = IfcFile.by_guid(guid)
    ifc_class = get_ifc_class_from_spatial_type(spatial_type)
    assert_type(element, ifc_class)
    if ifc_class == "IfcSite":
        address_name = "SiteAddress"
    elif ifc_class == "IfcBuilding":
        address_name = "BuildingAddress"
    assert_attribute(element, address_name)
    assert_attribute(getattr(element, address_name), name, value)
def get_subcontext(identifier, type, target_view):
    project = IfcFile.get().by_type("IfcProject")[0]
    for rep_context in project.RepresentationContexts:
        for subcontext in rep_context.HasSubContexts:
            if (subcontext.ContextIdentifier == identifier
                    and subcontext.ContextType == type
                    and subcontext.TargetView == target_view):
                return True
    assert False, "The subcontext with identifier {}, type {}, and target view {} could not be found".format(
        identifier, type, target_view)
Example #17
0
def step_impl(context, guid, predefined_type):
    element = IfcFile.by_guid(guid)
    if (hasattr(element, "PredefinedType")
            and element.PredefinedType == "USERDEFINED"
            and hasattr(element, "ObjectType")):
        assert_attribute(element, "ObjectType", predefined_type)
    elif hasattr(element, "PredefinedType"):
        assert_attribute(element, "PredefinedType", predefined_type)
    else:
        assert False, "The element {} does not have a PredefinedType or ObjectType attribute".format(
            element)
Example #18
0
def step_impl(context, guid, predefined_type):
    element = IfcFile.by_guid(guid)
    if hasattr(element, 'PredefinedType') \
            and element.PredefinedType == 'USERDEFINED' \
            and hasattr(element,'ObjectType'):
        assert_attribute(element, 'ObjectType', predefined_type)
    elif hasattr(element, 'PredefinedType'):
        assert_attribute(element, 'PredefinedType', predefined_type)
    else:
        assert False, 'The element {} does not have a PredefinedType or ObjectType attribute'.format(
            element)
def step_impl(context, ifc_class, qto_name, quantity_name):
    elements = IfcFile.get().by_type(ifc_class)
    for element in elements:
        is_successful = False
        if not element.IsDefinedBy:
            assert False
        for relationship in element.IsDefinedBy:
            if relationship.RelatingPropertyDefinition.Name == qto_name:
                for quantity in relationship.RelatingPropertyDefinition.Quantities:
                    if quantity.Name == quantity_name:
                        is_successful = True
        if not is_successful:
            assert False
Example #20
0
def step_impl(context, guid, x, y, z):
    element = IfcFile.by_guid(guid)
    if not element.ObjectPlacement:
        assert False, 'The element does not have an object placement: {}'.format(
            element)
    m = 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 = (assert_number(x), assert_number(y), 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))
def step_impl(context, number):
    number = int(number)
    errors = []
    for element in IfcFile.get().by_type('IfcElement'):
        if not element.Representation:
            continue
        total_polygons = 0
        tree = IfcFile.get().traverse(element.Representation)
        for e in tree:
            if e.is_a('IfcFace'):
                total_polygons += 1
            elif e.is_a('IfcPolygonalFaceSet'):
                total_polygons += len(e.Faces)
            elif e.is_a('IfcTriangulatedFaceSet'):
                total_polygons += len(e.CoordIndex)
        if total_polygons > number:
            errors.append((total_polygons, element))
    if errors:
        message = 'The following {} elements are over 500 polygons:\n'.format(len(errors))
        for error in errors:
            message += 'Polygons: {} - {}\n'.format(error[0], error[1])
        assert False,  message
Example #22
0
def step_impl(context, ifc_class, attributes, list_file):
    import csv
    values = []
    with open(list_file) as csvfile:
        reader = csv.reader(csvfile)
        for row in reader:
            values.append(row)
    elements = IfcFile.get().by_type(ifc_class)
    for element in elements:
        attribute_values = []
        for attribute in attributes.split(','):
            if not hasattr(element, attribute):
                assert False, f'Failed at element {element.GlobalId}'
            attribute_values.append(getattr(element, attribute))
        if attribute_values not in values:
            assert False, f'Failed at element {element.GlobalId}'
def step_impl(context, guid, identification, reference_name):
    element = IfcFile.by_guid(guid)
    if not hasattr(element, 'HasAssociations') or not element.HasAssociations:
        assert False, f'The element {element} has no associations.'
    references = [
        a.RelatingClassification for a in element.HasAssociations
        if a.is_a('IfcRelAssociatesClassification')
    ]
    if not references:
        assert False, f'The element {element} has no associated classification references.'
    is_success = False
    for reference in references:
        try:
            assert_attribute(reference, 'Identification', identification)
            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)
def step_impl(context, ifc_class, attribute):
    elements = IfcFile.get().by_type(ifc_class)
    for element in elements:
        if not getattr(element, attribute):
            assert False
Example #25
0
def step_impl(context, ifc_class):
    assert len(IfcFile.get().by_type(ifc_class)
               ) >= 1, 'An element of {} could not be found'.format(ifc_class)
Example #26
0
def step_impl(context, value):
    if IfcFile.get().schema == 'IFC2X3':
        for site in IfcFile.get().by_type('IfcSite'):
            assert_pset(site, 'EPset_ProjectedCRS', 'Description', value)
        return
    check_ifc4_geolocation('IfcProjectedCRS', 'Description', value)
Example #27
0
def step_impl(context, guid, number):
    number = assert_number(number)
    site = IfcFile.by_guid(guid)
    if not site.is_a('IfcSite'):
        assert False, 'The element {} is not an IfcSite'.format(site)
    assert_attribute(site, 'RefElevation', number)
Example #28
0
def step_impl(context):
    if IfcFile.get().schema == 'IFC2X3':
        for site in IfcFile.get().by_type('IfcSite'):
            assert_pset(site, 'EPset_MapConversion')
    check_ifc4_geolocation('IfcMapConversion')
def step_impl(context, ifc_class, reason):
    assert len(IfcFile.get().by_type(ifc_class)) == 0
def step_impl(context, ifc_class, property_path):
    pset_name, property_name = property_path.split(".")
    elements = IfcFile.get().by_type(ifc_class)
    for element in elements:
        if not IfcFile.get_property(element, pset_name, property_name):
            assert False