Exemple #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}"
        ),
    )
Exemple #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."),
    )
Exemple #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,
    )
Exemple #4
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,
    )
Exemple #5
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,
    )
Exemple #6
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}"),
    )