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)
Exemple #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)
Exemple #4
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 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]
Exemple #7
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 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
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
Exemple #11
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))
Exemple #12
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)
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)
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
Exemple #15
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
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
Exemple #17
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):
    for building in IfcFile.get().by_type("IfcBuilding"):
        if not building.BuildingAddress:
            assert False, f'The building "{building.Name}" has no address.'
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)
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)
Exemple #21
0
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", "MapProjection", coordinate_reference_name)
        return
    check_ifc4_geolocation("IfcProjectedCRS", "MapProjection", coordinate_reference_name)
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, schema):
    assert IfcFile.get(
    ).schema == schema, "We expected a schema of {} but instead got {}".format(
        schema,
        IfcFile.get().schema)
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
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
def step_impl(context, ifc_class, reason):
    assert len(IfcFile.get().by_type(ifc_class)) == 0
def step_impl(context, guid):
    assert_attribute(IfcFile.get().by_type("IfcProject")[0], "GlobalId", guid)
def step_impl(context, value):
    assert_attribute(IfcFile.get().by_type("IfcProject")[0], "Phase", value)
def step_impl(context, attribute_name, attribute_value):
    project = IfcFile.get().by_type("IfcProject")[0]
    assert getattr(project, attribute_name) == attribute_value
Exemple #30
0
def step_impl(context, guid, reason):
    try:
        element = IfcFile.get().by_id(guid)
    except:
        return
    assert False, 'This element {} should be reevaluated.'.format(element)