Esempio n. 1
0
 def delete_ifc_object(self, obj):
     if obj.BIMObjectProperties.ifc_definition_id:
         element = IfcStore.get_file().by_id(obj.BIMObjectProperties.ifc_definition_id)
         IfcStore.delete_element(element)
         if getattr(element, "FillsVoids", None):
             self.remove_filling(element)
         if element.is_a("IfcOpeningElement"):
             for rel in element.HasFillings:
                 self.remove_filling(rel.RelatedBuildingElement)
             if element.VoidsElements:
                 self.delete_opening_element(element)
         elif getattr(element, "HasOpenings", None):
             for rel in element.HasOpenings:
                 self.delete_opening_element(rel.RelatedOpeningElement)
Esempio n. 2
0
    def set_viewpoint_components(self, viewpoint, context):
        if not viewpoint.components:
            return

        # Operators with context overrides are used because they are
        # significantly faster than looping through all objects

        exception_global_ids = [
            v.ifc_guid for v in viewpoint.components.visibility.exceptions
        ]

        if viewpoint.components.visibility.default_visibility:
            old = context.area.type
            context.area.type = "VIEW_3D"
            bpy.ops.object.hide_view_clear()
            context.area.type = old
            for global_id in exception_global_ids:
                obj = IfcStore.get_element(global_id)
                if obj:
                    obj.hide_set(True)
        else:
            objs = []
            for global_id in exception_global_ids:
                obj = IfcStore.get_element(global_id)
                if obj:
                    objs.append(obj)
            if objs:
                old = context.area.type
                context.area.type = "VIEW_3D"
                context_override = {}
                context_override["object"] = context_override[
                    "active_object"] = objs[0]
                context_override["selected_objects"] = context_override[
                    "selected_editable_objects"] = objs
                bpy.ops.object.hide_view_set(context_override, unselected=True)
                context.area.type = old

        if viewpoint.components.view_setup_hints:
            if not viewpoint.components.view_setup_hints.spaces_visible:
                self.hide_spaces(context)
            if viewpoint.components.view_setup_hints.openings_visible is not None:
                self.set_openings_visibility(
                    viewpoint.components.view_setup_hints.openings_visible,
                    context)
        else:
            self.hide_spaces(context)
            self.set_openings_visibility(False, context)

        self.set_selection(viewpoint)
        self.set_colours(viewpoint)
Esempio n. 3
0
def update_cost_item_name(self, context):
    props = context.scene.BIMCostProperties
    if not props.is_cost_update_enabled or self.name == "Unnamed":
        return
    self.file = IfcStore.get_file()
    ifcopenshell.api.run(
        "cost.edit_cost_item",
        self.file,
        **{"cost_item": self.file.by_id(self.ifc_definition_id), "attributes": {"Name": self.name}},
    )
    Data.load(IfcStore.get_file())
    if props.active_cost_item_id == self.ifc_definition_id:
        attribute = props.cost_item_attributes.get("Name")
        attribute.string_value = self.name
Esempio n. 4
0
 def _execute(self, context):
     props = context.scene.BIMResourceProperties
     self.file = IfcStore.get_file()
     ifcopenshell.api.run(
         "cost.edit_cost_value_formula",
         self.file,
         **{
             "cost_value": self.file.by_id(self.cost_value),
             "formula": props.cost_value_formula
         },
     )
     Data.load(IfcStore.get_file())
     bpy.ops.bim.disable_editing_resource_cost_value()
     return {"FINISHED"}
Esempio n. 5
0
 def _execute(self, context):
     self.file = IfcStore.get_file()
     props = get_pset_props(context, self.obj, self.obj_type)
     ifc_definition_id = get_pset_obj_ifc_definition_id(
         context, self.obj, self.obj_type)
     ifcopenshell.api.run(
         "pset.add_qto",
         self.file,
         **{
             "product": self.file.by_id(ifc_definition_id),
             "name": props.qto_name,
         },
     )
     Data.load(IfcStore.get_file(), ifc_definition_id)
Esempio n. 6
0
 def execute(self, context):
     self.file = IfcStore.get_file()
     if self.obj_type == "Object":
         obj = bpy.data.objects.get(self.obj)
     elif self.obj_type == "Material":
         obj = bpy.data.materials.get(self.obj)
     oprops = obj.BIMObjectProperties
     props = obj.BIMAttributeProperties
     props.attributes.clear()
     if oprops.ifc_definition_id not in Data.products:
         Data.load(IfcStore.get_file(), oprops.ifc_definition_id)
     blenderbim.bim.helper.import_attributes2(
         tool.Ifc.get().by_id(oprops.ifc_definition_id), props.attributes)
     props.is_editing_attributes = True
     return {"FINISHED"}
Esempio n. 7
0
 def _execute(self, context):
     props = context.scene.BIMStructuralProperties
     attributes = blenderbim.bim.helper.export_attributes(props.structural_load_attributes)
     self.file = IfcStore.get_file()
     ifcopenshell.api.run(
         "structural.edit_structural_load",
         self.file,
         **{
             "structural_load": self.file.by_id(props.active_structural_load_id),
             "attributes": attributes,
         },
     )
     Data.load(IfcStore.get_file())
     bpy.ops.bim.load_structural_loads()
     return {"FINISHED"}
Esempio n. 8
0
    def _execute(self, context):
        from ifc5d.csv2ifc import Csv2Ifc

        self.file = IfcStore.get_file()
        start = time.time()
        csv2ifc = Csv2Ifc()
        csv2ifc.csv = self.filepath
        csv2ifc.file = self.file
        csv2ifc.is_schedule_of_rates = self.is_schedule_of_rates
        csv2ifc.execute()
        Data.load(IfcStore.get_file())
        UnitData.load(IfcStore.get_file())
        purge()
        print("Import finished in {:.2f} seconds".format(time.time() - start))
        return {"FINISHED"}
Esempio n. 9
0
 def _execute(self, context):
     obj = bpy.data.materials.get(
         self.obj) if self.obj else context.active_object.active_material
     self.file = IfcStore.get_file()
     result = ifcopenshell.api.run(
         "material.remove_material",
         self.file,
         **{
             "material":
             self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
         },
     )
     obj.BIMObjectProperties.ifc_definition_id = 0
     Data.load(IfcStore.get_file())
     return {"FINISHED"}
Esempio n. 10
0
 def _execute(self, context):
     props = context.scene.BIMLayerProperties
     attributes = {}
     for attribute in props.layer_attributes:
         if attribute.is_null:
             attributes[attribute.name] = None
         else:
             attributes[attribute.name] = attribute.string_value
     self.file = IfcStore.get_file()
     ifcopenshell.api.run(
         "layer.edit_layer", self.file, **{"layer": self.file.by_id(props.active_layer_id), "attributes": attributes}
     )
     Data.load(IfcStore.get_file())
     bpy.ops.bim.load_layers()
     return {"FINISHED"}
Esempio n. 11
0
def the_object_name_is_not_voided_by_void(name, void):
    ifc = IfcStore.get_file()
    element = ifc.by_id(
        the_object_name_exists(name).BIMObjectProperties.ifc_definition_id)
    for rel in element.HasOpenings:
        if rel.RelatedOpeningElement.Name == void:
            assert False, "A void was found"
Esempio n. 12
0
    def execute(self, context):
        import ifcopenshell.validate

        logger = logging.getLogger("validate")
        logger.setLevel(logging.DEBUG)
        ifcopenshell.validate.validate(IfcStore.get_file(), logger)
        return {"FINISHED"}
Esempio n. 13
0
 def _execute(self, context):
     props = context.scene.BIMQtoProperties
     self.file = IfcStore.get_file()
     for obj in (o for o in context.selected_objects if o.type == "MESH"):
         if not obj.BIMObjectProperties.ifc_definition_id:
             continue
         result = 0
         if props.qto_methods == "HEIGHT":
             result = helper.calculate_height(obj)
         elif props.qto_methods == "VOLUME":
             result = helper.calculate_volumes([obj], context)
         elif props.qto_methods == "FORMWORK":
             result = helper.calculate_formwork_area([obj], context)
         elif props.qto_methods == "SIDE_FORMWORK":
             result = helper.calculate_side_formwork_area([obj], context)
         if not result:
             continue
         result = round(result, 3)
         qto = ifcopenshell.api.run(
             "pset.add_qto",
             self.file,
             product=self.file.by_id(
                 obj.BIMObjectProperties.ifc_definition_id),
             name=props.qto_name,
         )
         ifcopenshell.api.run("pset.edit_qto",
                              self.file,
                              qto=qto,
                              properties={props.prop_name: result})
         PsetData.load(self.file, obj.BIMObjectProperties.ifc_definition_id)
     return {"FINISHED"}
Esempio n. 14
0
def getMaterials(self, context):
    global materials_enum
    if len(materials_enum) == 0 and IfcStore.get_file():
        materials_enum.clear()
        materials_enum = [(str(m_id), m["Name"], "")
                          for m_id, m in Data.materials.items()]
    return materials_enum
Esempio n. 15
0
 def execute(self, context):
     self.file = IfcStore.get_file()
     elements = self.file.by_type("IfcElement") + self.file.by_type(
         "IfcSpace")
     total = len(elements)
     settings = ifcopenshell.geom.settings()
     failures = []
     excludes = ()  # For the developer to debug with
     for i, element in enumerate(elements):
         if element.GlobalId in excludes:
             continue
         print(f"{i}/{total}:", element)
         start = time.time()
         try:
             shape = ifcopenshell.geom.create_shape(settings, element)
             print(
                 "Success",
                 time.time() - start,
                 len(shape.geometry.verts),
                 len(shape.geometry.edges),
                 len(shape.geometry.faces),
             )
         except:
             failures.append(element)
             print("***** FAILURE *****")
     print(f"Failures: {len(failures)}")
     for failure in failures:
         print(failure)
     return {"FINISHED"}
Esempio n. 16
0
 def _execute(self, context):
     props = context.scene.BIMResourceProperties
     attributes = blenderbim.bim.helper.export_attributes(
         props.quantity_attributes)
     self.file = IfcStore.get_file()
     ifcopenshell.api.run(
         "resource.edit_resource_quantity",
         self.file,
         **{
             "physical_quantity": self.file.by_id(self.physical_quantity),
             "attributes": attributes
         },
     )
     Data.load(IfcStore.get_file())
     bpy.ops.bim.disable_editing_resource_quantity()
     return {"FINISHED"}
Esempio n. 17
0
    def draw(self, context):
        if not Data.is_loaded:
            Data.load(IfcStore.get_file())
        self.props = context.scene.BIMGroupProperties

        row = self.layout.row(align=True)
        row.label(text="{} Groups Found".format(len(Data.groups)), icon="OUTLINER")
        if self.props.is_editing:
            row.operator("bim.add_group", text="", icon="ADD")
            row.operator("bim.disable_group_editing_ui", text="", icon="CANCEL")
        else:
            row.operator("bim.load_groups", text="", icon="GREASEPENCIL")

        if self.props.is_editing:
            self.layout.template_list(
                "BIM_UL_groups",
                "",
                self.props,
                "groups",
                self.props,
                "active_group_index",
            )

        if self.props.active_group_id:
            self.draw_editable_ui(context)
Esempio n. 18
0
    def load_set_item_attributes(self, material_set_item,
                                 material_set_item_data):
        self.props.material_set_item_attributes.clear()

        for attribute in IfcStore.get_schema().declaration_by_name(
                material_set_item.is_a()).all_attributes():
            data_type = ifcopenshell.util.attribute.get_primitive_type(
                attribute)
            if data_type == "entity":
                continue
            if attribute.name() in material_set_item_data:
                new = self.props.material_set_item_attributes.add()
                new.name = attribute.name()
                new.is_null = material_set_item_data[attribute.name()] is None
                new.data_type = data_type
                if data_type == "string":
                    new.string_value = "" if new.is_null else material_set_item_data[
                        attribute.name()]
                elif data_type == "float":
                    new.float_value = 0.0 if new.is_null else material_set_item_data[
                        attribute.name()]
                elif data_type == "integer":
                    new.int_value = 0 if new.is_null else material_set_item_data[
                        attribute.name()]
                elif data_type == "boolean":
                    new.bool_value = False if new.is_null else material_set_item_data[
                        attribute.name()]
Esempio n. 19
0
    def _execute(self, context):
        if not ContextData.is_loaded:
            ContextData.load(IfcStore.get_file())

        objs = [bpy.data.objects.get(self.obj)] if self.obj else context.selected_objects
        self.file = IfcStore.get_file()

        for obj in objs:
            # TODO: write unit tests to see how this bulk operation handles
            # contradictory ifc_representation_class values and when
            # ifc_representation_class is IfcTextLiteral
            if not obj.data:
                continue
            self.update_obj_mesh_representation(context, obj)
            IfcStore.edited_objs.discard(obj)
        return {"FINISHED"}
Esempio n. 20
0
 def execute(self, context):
     obj = bpy.data.objects.get(self.obj)
     if obj is None:
         return {"FINISHED"}
     product = IfcStore.get_file().by_id(
         obj.BIMObjectProperties.ifc_definition_id)
     if not product.HasOpenings:
         return {"FINISHED"}
     if [m for m in obj.modifiers if m.type == "BOOLEAN"]:
         return {"FINISHED"}
     representation = ifcopenshell.util.representation.get_representation(
         product, "Model", "Body", "MODEL_VIEW")
     if not representation:
         return {"FINISHED"}
     was_edit_mode = obj.mode == "EDIT"
     if was_edit_mode:
         bpy.ops.object.mode_set(mode="OBJECT")
     blenderbim.core.geometry.switch_representation(
         tool.Geometry,
         obj=obj,
         representation=representation,
         should_reload=True,
         enable_dynamic_voids=True,
         is_global=True,
         should_sync_changes_first=False,
     )
     if was_edit_mode:
         bpy.ops.object.mode_set(mode="EDIT")
     return {"FINISHED"}
Esempio n. 21
0
    def execute(self, context):
        self.file = IfcStore.get_file()
        obj = bpy.data.objects.get(
            self.obj) if self.obj else context.active_object
        self.props = obj.BIMObjectMaterialProperties
        self.props.active_material_set_item_id = self.material_set_item
        product_data = Data.products[obj.BIMObjectProperties.ifc_definition_id]
        material_set_item = self.file.by_id(self.material_set_item)

        if product_data["type"] == "IfcMaterialConstituentSet":
            material_set_item_data = Data.constituents[self.material_set_item]
        elif product_data["type"] == "IfcMaterialLayerSet" or product_data[
                "type"] == "IfcMaterialLayerSetUsage":
            material_set_item_data = Data.layers[self.material_set_item]
        elif product_data["type"] == "IfcMaterialProfileSet" or product_data[
                "type"] == "IfcMaterialProfileSetUsage":
            material_set_item_data = Data.profiles[self.material_set_item]
        else:
            material_set_item_data = {}

        self.props.material_set_item_material = str(
            material_set_item_data["Material"])

        self.load_set_item_attributes(material_set_item,
                                      material_set_item_data)
        if material_set_item.is_a("IfcMaterialProfile"):
            self.load_profile_attributes(material_set_item,
                                         material_set_item_data)

        return {"FINISHED"}
Esempio n. 22
0
    def draw(self, context):
        self.file = IfcStore.get_file()
        if not Data.is_loaded:
            Data.load(self.file)
        self.props = context.scene.BIMProfileProperties

        row = self.layout.row(align=True)
        row.label(text="{} Profiles Found".format(len(Data.profiles)), icon="SNAP_GRID")
        if self.props.is_editing:
            row.operator("bim.disable_profile_editing_ui", text="", icon="CANCEL")
        else:
            row.operator("bim.load_profiles", text="", icon="GREASEPENCIL")

        if not self.props.is_editing:
            return

        self.layout.template_list(
            "BIM_UL_profiles",
            "",
            self.props,
            "profiles",
            self.props,
            "active_profile_index",
        )

        if self.props.active_profile_id:
            self.draw_editable_ui(context)
Esempio n. 23
0
    def execute(self, context):
        props = context.scene.BIMDocumentProperties
        props.document_attributes.clear()

        if props.is_editing == "information":
            data = Data.information[self.document]
            ifc_class = "IfcDocumentInformation"
        elif props.is_editing == "reference":
            data = Data.references[self.document]
            ifc_class = "IfcDocumentReference"

        for attribute in IfcStore.get_schema().declaration_by_name(
                ifc_class).all_attributes():
            data_type = ifcopenshell.util.attribute.get_primitive_type(
                attribute)
            if data_type == "entity":
                continue
            new = props.document_attributes.add()
            new.name = attribute.name()
            new.is_null = data[attribute.name()] is None
            new.is_optional = attribute.optional()
            new.data_type = data_type
            if data_type == "string":
                new.string_value = "" if new.is_null else data[
                    attribute.name()]
            elif data_type == "enum":
                new.enum_items = json.dumps(
                    ifcopenshell.util.attribute.get_enum_items(attribute))
                if data[attribute.name()]:
                    new.enum_value = data[attribute.name()]
        props.active_document_id = self.document
        return {"FINISHED"}
Esempio n. 24
0
    def draw(self, context):
        if not Data.is_loaded:
            Data.load(IfcStore.get_file())
        self.props = context.scene.BIMGroupProperties
        row = self.layout.row(align=True)
        if self.props.is_adding:
            row.label(text="Adding Groups", icon="OUTLINER")
            row.operator("bim.toggle_assigning_group", text="", icon="CANCEL")
            self.layout.template_list(
                "BIM_UL_object_groups",
                "",
                self.props,
                "groups",
                self.props,
                "active_group_index",
            )
        else:
            row.label(text=f"{len(Data.groups)} Groups in IFC Project", icon="OUTLINER")
            row.operator("bim.toggle_assigning_group", text="", icon="ADD")

        groups_object = Data.products.get(context.active_object.BIMObjectProperties.ifc_definition_id, [])
        for group_id in groups_object:
            row = self.layout.row(align=True)
            row.label(text=Data.groups[group_id].get("Name", "Unnamed"))
            op = row.operator("bim.unassign_group", text="", icon="X")
            op.group = group_id

        if not groups_object:
            self.layout.label(text="No Group associated with Active Object")
Esempio n. 25
0
def the_void_name_is_not_filled_by_filling(name, filling):
    ifc = IfcStore.get_file()
    element = ifc.by_id(
        the_object_name_exists(name).BIMObjectProperties.ifc_definition_id)
    if any(rel.RelatedBuildingElement.Name == filling
           for rel in element.HasFillings):
        assert False, "A filling was found"
Esempio n. 26
0
def update_filter_mode(self, context):
    self.filter_categories.clear()
    if self.filter_mode == "NONE":
        return
    file = IfcStore.get_file()
    if self.filter_mode == "DECOMPOSITION":
        if file.schema == "IFC2X3":
            elements = file.by_type("IfcSpatialStructureElement")
        else:
            elements = file.by_type("IfcSpatialElement")
        elements = [(e, ifcopenshell.util.placement.get_storey_elevation(e))
                    for e in elements]
        elements = sorted(elements, key=lambda e: e[1])
        for element in elements:
            element = element[0]
            new = self.filter_categories.add()
            new.name = "{}/{}".format(element.is_a(), element.Name
                                      or "Unnamed")
            new.ifc_definition_id = element.id()
            new.total_elements = sum(
                [len(r.RelatedElements) for r in element.ContainsElements])
    elif self.filter_mode == "IFC_CLASS":
        for ifc_class in sorted(
                list(set([e.is_a() for e in file.by_type("IfcElement")]))):
            new = self.filter_categories.add()
            new.name = ifc_class
            new.total_elements = len(
                file.by_type(ifc_class, include_subtypes=False))
Esempio n. 27
0
 def _execute(self, context):
     self.file = IfcStore.get_file()
     if self.obj:
         objects = [bpy.data.objects.get(self.obj)]
     else:
         objects = context.selected_objects
     for obj in objects:
         if obj.BIMObjectProperties.ifc_definition_id:
             IfcStore.unlink_element(obj=obj)
         for material_slot in obj.material_slots:
             if material_slot.material:
                 blenderbim.core.style.unlink_style(tool.Ifc, tool.Style, obj=material_slot.material)
                 blenderbim.core.material.unlink_material(tool.Ifc, obj=material_slot.material)
         if "Ifc" in obj.name and "/" in obj.name:
             obj.name = "/".join(obj.name.split("/")[1:])
     return {"FINISHED"}
Esempio n. 28
0
def getParameterizedProfileClasses(self, context):
    global parameterizedprofileclasses_enum
    if len(parameterizedprofileclasses_enum) == 0 and IfcStore.get_schema():
        parameterizedprofileclasses_enum.clear()
        parameterizedprofileclasses_enum = [
            (t.name(), t.name(), "")
            for t in IfcStore.get_schema().declaration_by_name(
                "IfcParameterizedProfileDef").subtypes()
        ]
        for ifc_class in parameterizedprofileclasses_enum:
            parameterizedprofileclasses_enum.extend([
                (t.name(), t.name(), "")
                for t in IfcStore.get_schema().declaration_by_name(
                    ifc_class[0]).subtypes() or []
            ])
    return parameterizedprofileclasses_enum
Esempio n. 29
0
    def draw(self, context):
        if not Data.is_loaded:
            Data.load(IfcStore.get_file())

        self.props = context.scene.BIMConstraintProperties

        if not self.props.is_editing or self.props.is_editing == "IfcObjective":
            row = self.layout.row(align=True)
            row.label(text="{} Objectives Found".format(len(Data.objectives)),
                      icon="LIGHT")
            if self.props.is_editing == "IfcObjective":
                row.operator("bim.disable_constraint_editing_ui",
                             text="",
                             icon="CHECKMARK")
                row.operator("bim.add_objective", text="", icon="ADD")
            else:
                row.operator("bim.load_objectives",
                             text="",
                             icon="GREASEPENCIL")

        if self.props.is_editing:
            self.layout.template_list(
                "BIM_UL_constraints",
                "",
                self.props,
                "constraints",
                self.props,
                "active_constraint_index",
            )

        if self.props.active_constraint_id:
            self.draw_editable_ui(context)
Esempio n. 30
0
def regenerate_profile_usage(usecase_path, ifc_file, settings):
    elements = []
    if ifc_file.schema == "IFC2X3":
        for rel in ifc_file.get_inverse(settings["usage"]):
            if not rel.is_a("IfcRelAssociatesMaterial"):
                continue
            for element in rel.RelatedObjects:
                elements.append(element)
    else:
        for rel in settings["usage"].AssociatedTo:
            for element in rel.RelatedObjects:
                elements.append(element)

    for element in elements:
        obj = IfcStore.get_element(element.id())
        if not obj:
            continue
        representation = ifcopenshell.util.representation.get_representation(
            element, "Model", "Body", "MODEL_VIEW")
        if representation:
            blenderbim.core.geometry.switch_representation(
                tool.Geometry,
                obj=obj,
                representation=representation,
                should_reload=True,
                enable_dynamic_voids=True,
                is_global=True,
                should_sync_changes_first=False,
            )