From 43cc7a0304e4b813f7465b958502f183e5a9b0f1 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 19 Feb 2025 12:15:39 +0500 Subject: [PATCH] Replace direct access to IfcStore with tool.Ifc --- src/bonsai/bonsai/bim/handler.py | 8 +-- src/bonsai/bonsai/bim/helper.py | 4 +- src/bonsai/bonsai/bim/import_ifc.py | 2 +- .../bonsai/bim/module/aggregate/operator.py | 1 - src/bonsai/bonsai/bim/module/aggregate/ui.py | 6 +- .../bonsai/bim/module/attribute/operator.py | 3 +- .../bonsai/bim/module/attribute/prop.py | 1 - src/bonsai/bonsai/bim/module/attribute/ui.py | 1 - src/bonsai/bonsai/bim/module/bcf/operator.py | 9 ++- src/bonsai/bonsai/bim/module/boundary/ui.py | 9 ++- src/bonsai/bonsai/bim/module/bsdd/ui.py | 1 - .../bonsai/bim/module/clash/operator.py | 4 +- .../bim/module/classification/operator.py | 2 +- .../bonsai/bim/module/classification/ui.py | 3 +- .../bonsai/bim/module/constraint/operator.py | 5 +- src/bonsai/bonsai/bim/module/constraint/ui.py | 8 +-- src/bonsai/bonsai/bim/module/cost/prop.py | 5 +- src/bonsai/bonsai/bim/module/cost/ui.py | 3 +- .../bonsai/bim/module/covetool/operator.py | 4 +- src/bonsai/bonsai/bim/module/csv/operator.py | 5 +- src/bonsai/bonsai/bim/module/csv/ui.py | 6 +- .../bonsai/bim/module/debug/operator.py | 14 ++--- src/bonsai/bonsai/bim/module/diff/ui.py | 1 - .../bonsai/bim/module/document/operator.py | 1 - src/bonsai/bonsai/bim/module/document/ui.py | 8 +-- .../bonsai/bim/module/drawing/operator.py | 2 +- src/bonsai/bonsai/bim/module/fm/ui.py | 5 +- .../bonsai/bim/module/geometry/operator.py | 8 +-- src/bonsai/bonsai/bim/module/geometry/ui.py | 5 +- .../bonsai/bim/module/group/operator.py | 4 +- src/bonsai/bonsai/bim/module/group/ui.py | 6 +- .../bonsai/bim/module/layer/operator.py | 7 +-- src/bonsai/bonsai/bim/module/layer/ui.py | 4 +- .../bonsai/bim/module/material/operator.py | 19 +++--- src/bonsai/bonsai/bim/module/material/prop.py | 1 - src/bonsai/bonsai/bim/module/material/ui.py | 9 ++- src/bonsai/bonsai/bim/module/model/handler.py | 1 - src/bonsai/bonsai/bim/module/model/opening.py | 1 - .../bonsai/bim/module/model/polyline.py | 1 - src/bonsai/bonsai/bim/module/model/product.py | 2 +- src/bonsai/bonsai/bim/module/model/slab.py | 2 +- src/bonsai/bonsai/bim/module/model/wall.py | 4 +- src/bonsai/bonsai/bim/module/nest/operator.py | 5 +- src/bonsai/bonsai/bim/module/nest/ui.py | 6 +- src/bonsai/bonsai/bim/module/profile/prop.py | 1 - .../bonsai/bim/module/project/operator.py | 34 +++++----- src/bonsai/bonsai/bim/module/project/prop.py | 2 +- src/bonsai/bonsai/bim/module/project/ui.py | 10 +-- src/bonsai/bonsai/bim/module/pset/operator.py | 10 +-- src/bonsai/bonsai/bim/module/pset/prop.py | 10 +-- src/bonsai/bonsai/bim/module/pset/ui.py | 5 +- .../bonsai/bim/module/pset_template/prop.py | 3 +- src/bonsai/bonsai/bim/module/qto/operator.py | 1 - src/bonsai/bonsai/bim/module/resource/prop.py | 1 - src/bonsai/bonsai/bim/module/resource/ui.py | 4 +- src/bonsai/bonsai/bim/module/root/operator.py | 3 +- src/bonsai/bonsai/bim/module/root/ui.py | 4 +- .../bonsai/bim/module/sequence/operator.py | 13 ++-- src/bonsai/bonsai/bim/module/sequence/prop.py | 1 - src/bonsai/bonsai/bim/module/sequence/ui.py | 11 ++-- .../module/structural/load_decoration_data.py | 9 ++- .../bonsai/bim/module/structural/operator.py | 63 ++++++++++--------- .../bonsai/bim/module/structural/prop.py | 1 - src/bonsai/bonsai/bim/module/structural/ui.py | 28 ++++----- src/bonsai/bonsai/bim/module/style/ui.py | 4 +- .../bonsai/bim/module/system/operator.py | 2 - src/bonsai/bonsai/bim/module/type/operator.py | 7 +-- src/bonsai/bonsai/bim/module/type/prop.py | 2 - src/bonsai/bonsai/bim/module/type/ui.py | 1 - src/bonsai/bonsai/bim/module/unit/prop.py | 1 - src/bonsai/bonsai/bim/module/unit/ui.py | 4 +- src/bonsai/bonsai/bim/module/void/operator.py | 5 +- src/bonsai/bonsai/tool/ifc.py | 6 +- src/bonsai/bonsai/tool/structural.py | 5 +- .../docs/guides/development/undo_system.rst | 2 +- src/bonsai/scripts/headless_import.py | 1 - src/bonsai/test/bim/bootstrap.py | 18 +++--- src/bonsai/test/bim/test_feature.py | 14 ++--- src/bonsai/test/tool/test_drawing.py | 1 - src/bonsai/test/tool/test_misc.py | 1 - .../recipes/FixArchiCADToRevitSpaces.py | 5 +- 81 files changed, 228 insertions(+), 271 deletions(-) diff --git a/src/bonsai/bonsai/bim/handler.py b/src/bonsai/bonsai/bim/handler.py index 572cfaf117..287e0bb09d 100644 --- a/src/bonsai/bonsai/bim/handler.py +++ b/src/bonsai/bonsai/bim/handler.py @@ -60,7 +60,7 @@ def name_callback(obj: Union[bpy.types.Object, bpy.types.Material], data: str) - if props.is_renaming: props.is_renmaing = False return - IfcStore.get_file().by_id(ifc_definition_id).Name = obj.name + tool.Ifc.get().by_id(ifc_definition_id).Name = obj.name refresh_ui_data() return @@ -71,7 +71,7 @@ def name_callback(obj: Union[bpy.types.Object, bpy.types.Material], data: str) - obj.BIMObjectProperties.is_renaming = False return - element = IfcStore.get_file().by_id(obj.BIMObjectProperties.ifc_definition_id) + element = tool.Ifc.get().by_id(obj.BIMObjectProperties.ifc_definition_id) if "/" in obj.name: object_name = obj.name element_name = obj.name.split("/", 1)[1] @@ -231,9 +231,9 @@ def refresh_ui_data(): def loadIfcStore(scene): IfcStore.purge() refresh_ui_data() - if not IfcStore.get_file(): + if not tool.Ifc.get(): return - IfcStore.get_schema() + tool.Ifc.schema() IfcStore.relink_all_objects() diff --git a/src/bonsai/bonsai/bim/helper.py b/src/bonsai/bonsai/bim/helper.py index a8b25bca1a..2d19fa6e1f 100644 --- a/src/bonsai/bonsai/bim/helper.py +++ b/src/bonsai/bonsai/bim/helper.py @@ -27,7 +27,6 @@ import ifcopenshell.util.element import ifcopenshell.util.unit from ifcopenshell.util.doc import get_attribute_doc, get_predefined_type_doc, get_property_doc import bonsai.tool as tool -from bonsai.bim.ifc import IfcStore from typing import Optional, Callable, Any, Union, Iterable, TYPE_CHECKING if TYPE_CHECKING: @@ -119,7 +118,8 @@ def import_attributes( data: dict[str, Any], callback: Optional[ImportCallback] = None, ) -> None: - for attribute in IfcStore.get_schema().declaration_by_name(ifc_class).all_attributes(): + schema = tool.Ifc.schema() + for attribute in schema.declaration_by_name(ifc_class).all_attributes(): import_attribute(attribute, props, data, callback=callback) diff --git a/src/bonsai/bonsai/bim/import_ifc.py b/src/bonsai/bonsai/bim/import_ifc.py index 13fce33a93..5dd519de28 100644 --- a/src/bonsai/bonsai/bim/import_ifc.py +++ b/src/bonsai/bonsai/bim/import_ifc.py @@ -881,7 +881,7 @@ class IfcImporter: self.ifc_import_settings.logger.info("loading file %s", self.ifc_import_settings.input_file) if not bpy.context.scene.BIMProperties.ifc_file: bpy.context.scene.BIMProperties.ifc_file = self.ifc_import_settings.input_file - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() def calculate_unit_scale(self): self.unit_scale = ifcopenshell.util.unit.calculate_unit_scale(self.file) diff --git a/src/bonsai/bonsai/bim/module/aggregate/operator.py b/src/bonsai/bonsai/bim/module/aggregate/operator.py index c2e0cb16c2..c324037b89 100644 --- a/src/bonsai/bonsai/bim/module/aggregate/operator.py +++ b/src/bonsai/bonsai/bim/module/aggregate/operator.py @@ -23,7 +23,6 @@ import ifcopenshell.util.element import bonsai.tool as tool import bonsai.core.aggregate as core import bonsai.core.spatial -from bonsai.bim.ifc import IfcStore class BIM_OT_aggregate_assign_object(bpy.types.Operator, tool.Ifc.Operator): diff --git a/src/bonsai/bonsai/bim/module/aggregate/ui.py b/src/bonsai/bonsai/bim/module/aggregate/ui.py index 7b9503f530..74389c723d 100644 --- a/src/bonsai/bonsai/bim/module/aggregate/ui.py +++ b/src/bonsai/bonsai/bim/module/aggregate/ui.py @@ -39,7 +39,7 @@ class BIM_PT_aggregate(Panel): props = context.active_object.BIMObjectProperties if not props.ifc_definition_id: return False - if not IfcStore.get_element(props.ifc_definition_id): + if not tool.Ifc.get_object_by_identifier(props.ifc_definition_id): return False if not IfcStore.get_file().by_id(props.ifc_definition_id).is_a("IfcObjectDefinition"): return False @@ -120,9 +120,9 @@ class BIM_PT_linked_aggregate(Panel): props = context.active_object.BIMObjectProperties if not props.ifc_definition_id: return False - if not IfcStore.get_element(props.ifc_definition_id): + if not tool.Ifc.get_object_by_identifier(props.ifc_definition_id): return False - if not IfcStore.get_file().by_id(props.ifc_definition_id).is_a("IfcObjectDefinition"): + if not tool.Ifc.get().by_id(props.ifc_definition_id).is_a("IfcObjectDefinition"): return False return True diff --git a/src/bonsai/bonsai/bim/module/attribute/operator.py b/src/bonsai/bonsai/bim/module/attribute/operator.py index 3282c66ec5..2b279895e3 100644 --- a/src/bonsai/bonsai/bim/module/attribute/operator.py +++ b/src/bonsai/bonsai/bim/module/attribute/operator.py @@ -26,7 +26,6 @@ import bonsai.bim.helper import bonsai.tool as tool import bonsai.core.attribute as core import bonsai.core.spatial -from bonsai.bim.ifc import IfcStore def get_objs_for_operation(operator_properties, context): @@ -117,7 +116,7 @@ class EditAttributes(bpy.types.Operator, tool.Ifc.Operator): bl_options = {"REGISTER", "UNDO"} def _execute(self, context): - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() obj = tool.Blender.get_active_object(is_selected=False) if not (element := tool.Ifc.get_entity(obj)): return diff --git a/src/bonsai/bonsai/bim/module/attribute/prop.py b/src/bonsai/bonsai/bim/module/attribute/prop.py index 207fd927fd..fd2dab7cd2 100644 --- a/src/bonsai/bonsai/bim/module/attribute/prop.py +++ b/src/bonsai/bonsai/bim/module/attribute/prop.py @@ -17,7 +17,6 @@ # along with Bonsai. If not, see . import bpy -from bonsai.bim.ifc import IfcStore from bonsai.bim.prop import StrProperty, Attribute from bpy.types import PropertyGroup from bpy.props import ( diff --git a/src/bonsai/bonsai/bim/module/attribute/ui.py b/src/bonsai/bonsai/bim/module/attribute/ui.py index 6f0f5a5599..0fce2b07d4 100644 --- a/src/bonsai/bonsai/bim/module/attribute/ui.py +++ b/src/bonsai/bonsai/bim/module/attribute/ui.py @@ -18,7 +18,6 @@ import bonsai.bim.helper from bpy.types import Panel -from bonsai.bim.ifc import IfcStore from bonsai.bim.module.attribute.data import AttributesData import bonsai.tool as tool diff --git a/src/bonsai/bonsai/bim/module/bcf/operator.py b/src/bonsai/bonsai/bim/module/bcf/operator.py index aed65de52c..0c145d98f8 100644 --- a/src/bonsai/bonsai/bim/module/bcf/operator.py +++ b/src/bonsai/bonsai/bim/module/bcf/operator.py @@ -43,7 +43,6 @@ import bonsai.tool as tool import bonsai.bim.module.bcf.prop as bcf_prop import bonsai.bim.module.bcf.bcfstore as bcfstore from pathlib import Path -from bonsai.bim.ifc import IfcStore from math import radians, degrees, atan, tan, cos, sin from mathutils import Vector, Matrix, Euler, geometry from xsdata.models.datatype import XmlDateTime @@ -1206,7 +1205,7 @@ class ActivateBcfViewpoint(bpy.types.Operator): return True def execute(self, context): - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() bcfxml = bcfstore.BcfStore.get_bcfxml() assert bcfxml @@ -1355,7 +1354,7 @@ class ActivateBcfViewpoint(bpy.types.Operator): objs: list[bpy.types.Object] = [] for global_id in exception_global_ids: - obj = IfcStore.get_element(global_id) + obj = tool.Ifc.get_object_by_identifier(global_id) if obj and context.view_layer.objects.get(obj.name): assert isinstance(obj, bpy.types.Object) objs.append(obj) @@ -1414,7 +1413,7 @@ class ActivateBcfViewpoint(bpy.types.Operator): return bpy.ops.object.select_all(action="DESELECT") for global_id in selected_global_ids: - obj = IfcStore.get_element(global_id) + obj = tool.Ifc.get_object_by_identifier(global_id) if obj: obj.select_set(True) obj.hide_set(False) @@ -1427,7 +1426,7 @@ class ActivateBcfViewpoint(bpy.types.Operator): for acomponent in acoloring.component: global_id_colours.setdefault(acomponent.ifc_guid, acoloring.color) for global_id, color in global_id_colours.items(): - obj = IfcStore.get_element(global_id) + obj = tool.Ifc.get_object_by_identifier(global_id) if obj: obj.color = self.hex_to_rgb(color) diff --git a/src/bonsai/bonsai/bim/module/boundary/ui.py b/src/bonsai/bonsai/bim/module/boundary/ui.py index e3c7d8936f..e7332d50c6 100644 --- a/src/bonsai/bonsai/bim/module/boundary/ui.py +++ b/src/bonsai/bonsai/bim/module/boundary/ui.py @@ -18,7 +18,6 @@ import bpy from bpy.types import Panel, UIList -from bonsai.bim.ifc import IfcStore import bonsai.tool as tool from bonsai.bim.module.boundary.data import SpaceBoundariesData @@ -34,7 +33,7 @@ class BIM_PT_SceneBoundaries(Panel): @classmethod def poll(cls, context): - return IfcStore.get_file() + return tool.Ifc.get() def draw(self, context): row = self.layout.row(align=True) @@ -58,9 +57,9 @@ class BIM_PT_Boundary(Panel): props = context.active_object.BIMObjectProperties if not props.ifc_definition_id: return False - if not IfcStore.get_element(props.ifc_definition_id): + if not tool.Ifc.get_object_by_identifier(props.ifc_definition_id): return False - entity = IfcStore.get_file().by_id(props.ifc_definition_id) + entity = tool.Ifc.get().by_id(props.ifc_definition_id) return entity.is_a("IfcRelSpaceBoundary") def draw(self, context): @@ -134,7 +133,7 @@ class BIM_PT_SpaceBoundaries(Panel): props = context.active_object.BIMObjectProperties if not props.ifc_definition_id: return False - if not IfcStore.get_element(props.ifc_definition_id): + if not tool.Ifc.get_object_by_identifier(props.ifc_definition_id): return False element = tool.Ifc.get_entity(context.active_object) for ifc_class in ("IfcSpace", "IfcExternalSpatialElement"): diff --git a/src/bonsai/bonsai/bim/module/bsdd/ui.py b/src/bonsai/bonsai/bim/module/bsdd/ui.py index ac3e633d8a..046bc46fec 100644 --- a/src/bonsai/bonsai/bim/module/bsdd/ui.py +++ b/src/bonsai/bonsai/bim/module/bsdd/ui.py @@ -18,7 +18,6 @@ import bonsai.tool as tool from bpy.types import Panel, UIList -from bonsai.bim.ifc import IfcStore class BIM_PT_bsdd(Panel): diff --git a/src/bonsai/bonsai/bim/module/clash/operator.py b/src/bonsai/bonsai/bim/module/clash/operator.py index 020aeba55e..d8eb640551 100644 --- a/src/bonsai/bonsai/bim/module/clash/operator.py +++ b/src/bonsai/bonsai/bim/module/clash/operator.py @@ -300,7 +300,7 @@ class SelectIfcClashResults(bpy.types.Operator): def execute(self, context): # TODO refactor into new clash results system - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() self.filepath = bpy.path.ensure_ext(self.filepath, ".json") with open(self.filepath) as f: clash_sets = json.load(f) @@ -478,7 +478,7 @@ class SelectSmartGroup(bpy.types.Operator): @classmethod def poll(cls, context): - return IfcStore.get_file() and context.visible_objects and context.scene.BIMClashProperties.active_smart_group + return tool.Ifc.get() and context.visible_objects and context.scene.BIMClashProperties.active_smart_group def execute(self, context): selected_smart_group = context.scene.BIMClashProperties.active_smart_group diff --git a/src/bonsai/bonsai/bim/module/classification/operator.py b/src/bonsai/bonsai/bim/module/classification/operator.py index acdffae946..fa5e914880 100644 --- a/src/bonsai/bonsai/bim/module/classification/operator.py +++ b/src/bonsai/bonsai/bim/module/classification/operator.py @@ -240,7 +240,7 @@ class RemoveClassification(bpy.types.Operator, tool.Ifc.Operator): classification: bpy.props.IntProperty() def _execute(self, context): - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() ifcopenshell.api.run( "classification.remove_classification", tool.Ifc.get(), diff --git a/src/bonsai/bonsai/bim/module/classification/ui.py b/src/bonsai/bonsai/bim/module/classification/ui.py index 87257fbaaa..c171ff3cd6 100644 --- a/src/bonsai/bonsai/bim/module/classification/ui.py +++ b/src/bonsai/bonsai/bim/module/classification/ui.py @@ -21,7 +21,6 @@ import bonsai.bim.helper import bonsai.tool as tool import bonsai.bim.module.classification.prop as classification_prop from bpy.types import Panel, UIList -from bonsai.bim.ifc import IfcStore from bonsai.bim.module.classification.data import ( ClassificationsData, ClassificationReferencesData, @@ -124,7 +123,7 @@ class ReferenceUI: self.sprops = context.scene.BIMClassificationProperties self.bprops = context.scene.BIMBSDDProperties self.props = context.scene.BIMClassificationReferenceProperties - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() self.draw_add_ui(context) diff --git a/src/bonsai/bonsai/bim/module/constraint/operator.py b/src/bonsai/bonsai/bim/module/constraint/operator.py index deed4d6335..3a66b074c7 100644 --- a/src/bonsai/bonsai/bim/module/constraint/operator.py +++ b/src/bonsai/bonsai/bim/module/constraint/operator.py @@ -23,7 +23,6 @@ import ifcopenshell.api.constraint import ifcopenshell.util.attribute import bonsai.bim.helper import bonsai.tool as tool -from bonsai.bim.ifc import IfcStore class LoadObjectives(bpy.types.Operator): @@ -84,7 +83,7 @@ class AddObjective(bpy.types.Operator, tool.Ifc.Operator): bl_options = {"REGISTER", "UNDO"} def _execute(self, context): - result = ifcopenshell.api.run("constraint.add_objective", IfcStore.get_file()) + result = ifcopenshell.api.run("constraint.add_objective", tool.Ifc.get()) bpy.ops.bim.load_objectives() bpy.ops.bim.enable_editing_constraint(constraint=result.id()) return {"FINISHED"} @@ -116,7 +115,7 @@ class RemoveConstraint(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): props = context.scene.BIMConstraintProperties - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() ifcopenshell.api.run( "constraint.remove_constraint", self.file, **{"constraint": self.file.by_id(self.constraint)} ) diff --git a/src/bonsai/bonsai/bim/module/constraint/ui.py b/src/bonsai/bonsai/bim/module/constraint/ui.py index f7d530a757..76f4c4a1bb 100644 --- a/src/bonsai/bonsai/bim/module/constraint/ui.py +++ b/src/bonsai/bonsai/bim/module/constraint/ui.py @@ -16,8 +16,8 @@ # You should have received a copy of the GNU General Public License # along with Bonsai. If not, see . +import bonsai.tool as tool from bpy.types import Panel, UIList -from bonsai.bim.ifc import IfcStore from bonsai.bim.helper import draw_attributes from bonsai.bim.module.constraint.data import ConstraintsData, ObjectConstraintsData @@ -33,7 +33,7 @@ class BIM_PT_constraints(Panel): @classmethod def poll(cls, context): - return IfcStore.get_file() + return tool.Ifc.get() def draw(self, context): if not ConstraintsData.is_loaded: @@ -81,7 +81,7 @@ class BIM_PT_object_constraints(Panel): def poll(cls, context): if not context.active_object: return False - if not IfcStore.get_element(context.active_object.BIMObjectProperties.ifc_definition_id): + if not tool.Ifc.get_object_by_identifier(context.active_object.BIMObjectProperties.ifc_definition_id): return False return bool(context.active_object.BIMObjectProperties.ifc_definition_id) @@ -93,7 +93,7 @@ class BIM_PT_object_constraints(Panel): self.oprops = obj.BIMObjectProperties self.sprops = context.scene.BIMConstraintProperties self.props = obj.BIMObjectConstraintProperties - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() self.draw_add_ui() diff --git a/src/bonsai/bonsai/bim/module/cost/prop.py b/src/bonsai/bonsai/bim/module/cost/prop.py index 092f429121..abe035fdb6 100644 --- a/src/bonsai/bonsai/bim/module/cost/prop.py +++ b/src/bonsai/bonsai/bim/module/cost/prop.py @@ -19,7 +19,6 @@ import bpy import ifcopenshell.api import bonsai.tool as tool -from bonsai.bim.ifc import IfcStore from bonsai.bim.module.classification.data import CostClassificationsData from bonsai.bim.module.cost.data import CostSchedulesData, CostItemRatesData, CostItemQuantitiesData from bonsai.bim.prop import StrProperty, Attribute @@ -83,7 +82,7 @@ def update_cost_item_identification(self, context): props = context.scene.BIMCostProperties if not props.is_cost_update_enabled or self.identification == "XXX": return - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() ifcopenshell.api.run( "cost.edit_cost_item", self.file, @@ -98,7 +97,7 @@ 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() + self.file = tool.Ifc.get() ifcopenshell.api.run( "cost.edit_cost_item", self.file, diff --git a/src/bonsai/bonsai/bim/module/cost/ui.py b/src/bonsai/bonsai/bim/module/cost/ui.py index 67d14437ed..387998e9ac 100644 --- a/src/bonsai/bonsai/bim/module/cost/ui.py +++ b/src/bonsai/bonsai/bim/module/cost/ui.py @@ -21,7 +21,6 @@ import bonsai.bim.helper import bonsai.bim.module.cost.prop as CostProp import bonsai.tool as tool from bpy.types import Panel, UIList -from bonsai.bim.ifc import IfcStore from bonsai.bim.module.cost.data import CostSchedulesData from typing import Any @@ -37,7 +36,7 @@ class BIM_PT_cost_schedules(Panel): @classmethod def poll(cls, context): - file = IfcStore.get_file() + file = tool.Ifc.get() return file and hasattr(file, "schema") and file.schema != "IFC2X3" def draw(self, context): diff --git a/src/bonsai/bonsai/bim/module/covetool/operator.py b/src/bonsai/bonsai/bim/module/covetool/operator.py index 0bafcafa4f..1d64dd958e 100644 --- a/src/bonsai/bonsai/bim/module/covetool/operator.py +++ b/src/bonsai/bonsai/bim/module/covetool/operator.py @@ -20,8 +20,8 @@ import bpy import json import ifcopenshell import ifcopenshell.util.element +import bonsai.tool as tool from math import degrees, atan2 -from bonsai.bim.ifc import IfcStore from .api import Api @@ -92,7 +92,7 @@ class RunAnalysis(bpy.types.Operator): bl_label = "Run Analysis" def execute(self, context): - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() self.inputs = { "floors": [], "walls": [], diff --git a/src/bonsai/bonsai/bim/module/csv/operator.py b/src/bonsai/bonsai/bim/module/csv/operator.py index 7d59bc5a92..cd9e784bf2 100644 --- a/src/bonsai/bonsai/bim/module/csv/operator.py +++ b/src/bonsai/bonsai/bim/module/csv/operator.py @@ -27,7 +27,6 @@ import ifcopenshell import ifcopenshell.util.selector import bonsai.tool as tool import bonsai.bim.module.drawing.scheduler as scheduler -from bonsai.bim.ifc import IfcStore from bonsai.bim.handler import refresh_ui_data from typing import TYPE_CHECKING from collections import Counter @@ -212,7 +211,7 @@ class ExportIfcCsv(bpy.types.Operator): props = context.scene.CsvProperties self.filepath = bpy.path.ensure_ext(self.filepath, f".{props.format}") if props.should_load_from_memory: - ifc_file = IfcStore.get_file() + ifc_file = tool.Ifc.get() else: ifc_file = ifcopenshell.open(props.csv_ifc_file) results = ifcopenshell.util.selector.filter_elements( @@ -314,7 +313,7 @@ class ImportIfcCsv(bpy.types.Operator, tool.Ifc.Operator): props = context.scene.CsvProperties if props.should_load_from_memory: - ifc_file = IfcStore.get_file() + ifc_file = tool.Ifc.get() else: ifc_file = ifcopenshell.open(props.csv_ifc_file) ifc_csv = ifccsv.IfcCsv() diff --git a/src/bonsai/bonsai/bim/module/csv/ui.py b/src/bonsai/bonsai/bim/module/csv/ui.py index 0d4d6ef11e..6aa41177b0 100644 --- a/src/bonsai/bonsai/bim/module/csv/ui.py +++ b/src/bonsai/bonsai/bim/module/csv/ui.py @@ -17,8 +17,8 @@ # along with Bonsai. If not, see . import bonsai.bim.helper +import bonsai.tool as tool from bpy.types import Panel -from bonsai.bim.ifc import IfcStore from bonsai.bim.module.search.data import SearchData @@ -37,7 +37,7 @@ class BIM_PT_ifccsv(Panel): scene = context.scene props = scene.CsvProperties - if IfcStore.get_file(): + if tool.Ifc.get(): row = layout.row(align=True) row.prop(props, "should_load_from_memory") row.operator("bim.import_csv_attributes", icon="IMPORT", text="") @@ -49,7 +49,7 @@ class BIM_PT_ifccsv(Panel): row.operator("bim.export_csv_attributes", icon="EXPORT", text="") row.prop(props, "should_show_settings", icon="PREFERENCES", text="") - if not IfcStore.get_file() or not props.should_load_from_memory: + if not tool.Ifc.get() or not props.should_load_from_memory: row = layout.row(align=True) row.prop(props, "csv_ifc_file") row.operator("bim.select_csv_ifc_file", icon="FILE_FOLDER", text="") diff --git a/src/bonsai/bonsai/bim/module/debug/operator.py b/src/bonsai/bonsai/bim/module/debug/operator.py index bb949b8fd0..68e3525a87 100644 --- a/src/bonsai/bonsai/bim/module/debug/operator.py +++ b/src/bonsai/bonsai/bim/module/debug/operator.py @@ -78,10 +78,10 @@ class PrintIfcFile(bpy.types.Operator): @classmethod def poll(cls, context): - return IfcStore.get_file() + return tool.Ifc.get() def execute(self, context): - print(IfcStore.get_file().wrapped_data.to_string()) + print(tool.Ifc.get().wrapped_data.to_string()) return {"FINISHED"} @@ -184,10 +184,10 @@ class CreateAllShapes(bpy.types.Operator): @classmethod def poll(cls, context): - return IfcStore.get_file() + return tool.Ifc.get() def execute(self, context): - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() elements = self.file.by_type("IfcElement") + self.file.by_type("IfcSpace") total = len(elements) @@ -328,10 +328,10 @@ class InspectFromStepId(bpy.types.Operator): @classmethod def poll(cls, context): - return IfcStore.get_file() + return tool.Ifc.get() def execute(self, context): - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() debug_props = tool.Debug.get_debug_props() debug_props.active_step_id = self.step_id crumb = debug_props.step_id_breadcrumb.add() @@ -422,7 +422,7 @@ class PrintObjectPlacement(bpy.types.Operator): return self.execute(context) def execute(self, context): - placement = ifcopenshell.util.placement.get_local_placement(IfcStore.get_file().by_id(self.step_id)) + placement = ifcopenshell.util.placement.get_local_placement(tool.Ifc.get().by_id(self.step_id)) if self.create_empty_object: bpy.ops.object.empty_add(type="ARROWS") si_conversion = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get()) diff --git a/src/bonsai/bonsai/bim/module/diff/ui.py b/src/bonsai/bonsai/bim/module/diff/ui.py index b147f884d1..34e66df0f5 100644 --- a/src/bonsai/bonsai/bim/module/diff/ui.py +++ b/src/bonsai/bonsai/bim/module/diff/ui.py @@ -17,7 +17,6 @@ # along with Bonsai. If not, see . from bpy.types import Panel -from bonsai.bim.ifc import IfcStore from bonsai.bim.module.diff.data import DiffData import bonsai.bim.helper import bonsai.tool as tool diff --git a/src/bonsai/bonsai/bim/module/document/operator.py b/src/bonsai/bonsai/bim/module/document/operator.py index 70c3401fb0..13c494d092 100644 --- a/src/bonsai/bonsai/bim/module/document/operator.py +++ b/src/bonsai/bonsai/bim/module/document/operator.py @@ -24,7 +24,6 @@ import ifcopenshell.util.element import bonsai.bim.handler import bonsai.tool as tool import bonsai.core.document as core -from bonsai.bim.ifc import IfcStore class LoadProjectDocuments(bpy.types.Operator): diff --git a/src/bonsai/bonsai/bim/module/document/ui.py b/src/bonsai/bonsai/bim/module/document/ui.py index d2cf2e7ab6..c2aff57ed4 100644 --- a/src/bonsai/bonsai/bim/module/document/ui.py +++ b/src/bonsai/bonsai/bim/module/document/ui.py @@ -16,8 +16,8 @@ # You should have received a copy of the GNU General Public License # along with Bonsai. If not, see . +import bonsai.tool as tool from bpy.types import Panel, UIList -from bonsai.bim.ifc import IfcStore from bonsai.bim.helper import draw_attributes from bonsai.bim.module.document.data import DocumentData, ObjectDocumentData @@ -33,7 +33,7 @@ class BIM_PT_documents(Panel): @classmethod def poll(cls, context): - return IfcStore.get_file() + return tool.Ifc.get() def draw(self, context): if not DocumentData.is_loaded: @@ -92,7 +92,7 @@ class BIM_PT_object_documents(Panel): def poll(cls, context): if not context.active_object: return False - if not IfcStore.get_element(context.active_object.BIMObjectProperties.ifc_definition_id): + if not tool.Ifc.get_object_by_identifier(context.active_object.BIMObjectProperties.ifc_definition_id): return False return bool(context.active_object.BIMObjectProperties.ifc_definition_id) @@ -103,7 +103,7 @@ class BIM_PT_object_documents(Panel): obj = context.active_object self.oprops = obj.BIMObjectProperties self.props = context.scene.BIMDocumentProperties - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() self.draw_add_ui() diff --git a/src/bonsai/bonsai/bim/module/drawing/operator.py b/src/bonsai/bonsai/bim/module/drawing/operator.py index 6bac483f21..3d1c3f46ec 100644 --- a/src/bonsai/bonsai/bim/module/drawing/operator.py +++ b/src/bonsai/bonsai/bim/module/drawing/operator.py @@ -261,7 +261,7 @@ class CreateDrawing(bpy.types.Operator): self.camera = context.scene.camera self.camera_element = tool.Ifc.get_entity(self.camera) self.camera_document = tool.Drawing.get_drawing_document(self.camera_element) - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() with profile("Drawing generation process"): with profile("Initialize drawing generation process"): diff --git a/src/bonsai/bonsai/bim/module/fm/ui.py b/src/bonsai/bonsai/bim/module/fm/ui.py index 1e76ec61c3..89cd764adf 100644 --- a/src/bonsai/bonsai/bim/module/fm/ui.py +++ b/src/bonsai/bonsai/bim/module/fm/ui.py @@ -18,7 +18,6 @@ import bonsai.tool as tool from bpy.types import Panel -from bonsai.bim.ifc import IfcStore from bonsai.bim.module.fm.data import FMData @@ -40,11 +39,11 @@ class BIM_PT_fm(Panel): scene = context.scene props = scene.BIMFMProperties - if IfcStore.get_file(): + if tool.Ifc.get(): row = layout.row() row.prop(props, "should_load_from_memory") - if not IfcStore.get_file() or not props.should_load_from_memory: + if not tool.Ifc.get() or not props.should_load_from_memory: row = layout.row() props.ifc_files.layout_file_select(row, "*.ifc;*.ifczip;*.ifcxml", "IFC File(s)") diff --git a/src/bonsai/bonsai/bim/module/geometry/operator.py b/src/bonsai/bonsai/bim/module/geometry/operator.py index 1d43e584d7..3dd372d6cd 100644 --- a/src/bonsai/bonsai/bim/module/geometry/operator.py +++ b/src/bonsai/bonsai/bim/module/geometry/operator.py @@ -609,7 +609,7 @@ class UpdateParametricRepresentation(bpy.types.Operator): return (obj := context.active_object) and obj.mode == "OBJECT" and tool.Geometry.has_mesh_properties(obj.data) def execute(self, context): - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() obj = context.active_object assert obj and tool.Geometry.has_mesh_properties(obj.data) props = tool.Geometry.get_mesh_props(obj.data) @@ -834,7 +834,7 @@ class OverrideOutlinerDelete(bpy.types.Operator): # unintended IFC spatial modifications. To make life less confusing for # the user, Delete means Delete. End of story. # Deep magick from the dawn of time - if IfcStore.get_file(): + if tool.Ifc.get(): return IfcStore.execute_ifc_operator(self, context) # https://blender.stackexchange.com/questions/203729/python-get-selected-objects-in-outliner objects_to_delete = set() @@ -958,7 +958,7 @@ class OverrideDuplicateMove(bpy.types.Operator): @staticmethod def execute_duplicate_operator(self, context, linked=False): # Deep magick from the dawn of time - if IfcStore.get_file(): + if tool.Ifc.get(): IfcStore.execute_ifc_operator(self, context) if self.new_active_obj: context.view_layer.objects.active = self.new_active_obj @@ -3218,7 +3218,7 @@ class OverrideMove(bpy.types.Operator): def execute(self, context): # Deep magick from the dawn of time - if IfcStore.get_file(): + if tool.Ifc.get(): IfcStore.execute_ifc_operator(self, context) if self.new_active_obj: context.view_layer.objects.active = self.new_active_obj diff --git a/src/bonsai/bonsai/bim/module/geometry/ui.py b/src/bonsai/bonsai/bim/module/geometry/ui.py index b0ad2ea47d..8ba3958222 100644 --- a/src/bonsai/bonsai/bim/module/geometry/ui.py +++ b/src/bonsai/bonsai/bim/module/geometry/ui.py @@ -20,7 +20,6 @@ import bpy import bonsai.bim import bonsai.tool as tool from bpy.types import Panel, Menu, UIList -from bonsai.bim.ifc import IfcStore from bonsai.bim.helper import prop_with_search from bonsai.bim.module.geometry.data import ( RepresentationsData, @@ -337,9 +336,9 @@ class BIM_PT_connections(Panel): def poll(cls, context): if not context.active_object: return False - if not IfcStore.get_element(context.active_object.BIMObjectProperties.ifc_definition_id): + if not tool.Ifc.get_object_by_identifier(context.active_object.BIMObjectProperties.ifc_definition_id): return False - return IfcStore.get_file() + return tool.Ifc.get() def draw(self, context): if not ConnectionsData.is_loaded: diff --git a/src/bonsai/bonsai/bim/module/group/operator.py b/src/bonsai/bonsai/bim/module/group/operator.py index e991dcf4f1..9a9124ebfa 100644 --- a/src/bonsai/bonsai/bim/module/group/operator.py +++ b/src/bonsai/bonsai/bim/module/group/operator.py @@ -22,7 +22,6 @@ import ifcopenshell.api.group import ifcopenshell.util.attribute import bonsai.bim.helper import bonsai.tool as tool -from bonsai.bim.ifc import IfcStore import json @@ -129,8 +128,7 @@ class RemoveGroup(bpy.types.Operator, tool.Ifc.Operator): group: bpy.props.IntProperty() def _execute(self, context): - props = context.scene.BIMGroupProperties - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() ifcopenshell.api.run("group.remove_group", self.file, **{"group": self.file.by_id(self.group)}) bpy.ops.bim.load_groups() return {"FINISHED"} diff --git a/src/bonsai/bonsai/bim/module/group/ui.py b/src/bonsai/bonsai/bim/module/group/ui.py index 88077f99eb..8cd7d1fe2a 100644 --- a/src/bonsai/bonsai/bim/module/group/ui.py +++ b/src/bonsai/bonsai/bim/module/group/ui.py @@ -17,8 +17,8 @@ # along with Bonsai. If not, see . import bpy +import bonsai.tool as tool from bpy.types import Panel, UIList -from bonsai.bim.ifc import IfcStore from bonsai.bim.helper import draw_attributes from bonsai.bim.module.group.data import GroupsData, ObjectGroupsData @@ -34,7 +34,7 @@ class BIM_PT_groups(Panel): @classmethod def poll(cls, context): - return IfcStore.get_file() + return tool.Ifc.get() def draw(self, context): if not GroupsData.is_loaded: @@ -93,7 +93,7 @@ class BIM_PT_object_groups(Panel): def poll(cls, context): if not context.active_object: return False - return IfcStore.get_file() and context.active_object.BIMObjectProperties.ifc_definition_id + return tool.Ifc.get() and context.active_object.BIMObjectProperties.ifc_definition_id def draw(self, context): if not ObjectGroupsData.is_loaded: diff --git a/src/bonsai/bonsai/bim/module/layer/operator.py b/src/bonsai/bonsai/bim/module/layer/operator.py index 13b5d79a56..5480c86034 100644 --- a/src/bonsai/bonsai/bim/module/layer/operator.py +++ b/src/bonsai/bonsai/bim/module/layer/operator.py @@ -24,7 +24,6 @@ import ifcopenshell.util.element import ifcopenshell.util.attribute import bonsai.bim.helper import bonsai.tool as tool -from bonsai.bim.ifc import IfcStore class LoadLayers(bpy.types.Operator): @@ -33,7 +32,7 @@ class LoadLayers(bpy.types.Operator): bl_options = {"REGISTER", "UNDO"} def execute(self, context): - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() props = context.scene.BIMLayerProperties props.layers.clear() for layer in tool.Ifc.get().by_type("IfcPresentationLayerAssignment"): @@ -126,7 +125,7 @@ class RemovePresentationLayer(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): props = context.scene.BIMLayerProperties - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() ifcopenshell.api.run("layer.remove_layer", self.file, **{"layer": self.file.by_id(self.layer)}) bpy.ops.bim.load_layers() return {"FINISHED"} @@ -142,7 +141,7 @@ class AssignPresentationLayer(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): item = bpy.data.meshes.get(self.item) if self.item else context.active_object.data - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() ifcopenshell.api.run( "layer.assign_layer", self.file, diff --git a/src/bonsai/bonsai/bim/module/layer/ui.py b/src/bonsai/bonsai/bim/module/layer/ui.py index 5fb8db827d..609cb62815 100644 --- a/src/bonsai/bonsai/bim/module/layer/ui.py +++ b/src/bonsai/bonsai/bim/module/layer/ui.py @@ -17,8 +17,8 @@ # along with Bonsai. If not, see . import bpy +import bonsai.tool as tool from bpy.types import Panel, UIList, Mesh -from bonsai.bim.ifc import IfcStore from bonsai.bim.helper import draw_attributes from bonsai.bim.module.layer.data import LayersData @@ -34,7 +34,7 @@ class BIM_PT_layers(Panel): @classmethod def poll(cls, context): - return IfcStore.get_file() + return tool.Ifc.get() def draw(self, context): if not LayersData.is_loaded: diff --git a/src/bonsai/bonsai/bim/module/material/operator.py b/src/bonsai/bonsai/bim/module/material/operator.py index 820ac5359e..3e9ff20924 100644 --- a/src/bonsai/bonsai/bim/module/material/operator.py +++ b/src/bonsai/bonsai/bim/module/material/operator.py @@ -29,7 +29,6 @@ import bonsai.tool as tool import bonsai.core.style import bonsai.core.material as core import bonsai.bim.module.model.profile as model_profile -from bonsai.bim.ifc import IfcStore from typing import Any, Union, TYPE_CHECKING from bonsai.bim.module.model import wall, slab @@ -118,7 +117,7 @@ class AssignParameterizedProfile(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() profile = ifcopenshell.api.run( "profile.add_parameterized_profile", self.file, @@ -292,7 +291,7 @@ class AddConstituent(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() ifcopenshell.api.run( "material.add_constituent", self.file, @@ -328,7 +327,7 @@ class AddProfile(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() props = tool.Material.get_material_props() ifcopenshell.api.run( "material.add_profile", @@ -387,7 +386,7 @@ class ReorderMaterialSetItem(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() material_set = self.file.by_id(self.material_set) ifcopenshell.api.run( "material.reorder_set_item", @@ -443,7 +442,7 @@ class AddListItem(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() ifcopenshell.api.run( "material.add_list_item", self.file, @@ -463,7 +462,7 @@ class RemoveListItem(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() ifcopenshell.api.run( "material.remove_list_item", self.file, @@ -557,7 +556,7 @@ class EditAssignedMaterial(bpy.types.Operator, tool.Ifc.Operator): material_set_usage: bpy.props.IntProperty() def _execute(self, context): - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() active_obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object props = active_obj.BIMObjectMaterialProperties element = tool.Ifc.get_entity(active_obj) @@ -663,7 +662,7 @@ class EnableEditingMaterialSetItem(bpy.types.Operator): material_set_item: bpy.props.IntProperty() def execute(self, context): - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object self.mprops = tool.Material.get_material_props() self.props = obj.BIMObjectMaterialProperties @@ -707,7 +706,7 @@ class EditMaterialSetItem(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() props = obj.BIMObjectMaterialProperties mprops = tool.Material.get_material_props() element = tool.Ifc.get_entity(obj) diff --git a/src/bonsai/bonsai/bim/module/material/prop.py b/src/bonsai/bonsai/bim/module/material/prop.py index f21a34a702..04a596e73f 100644 --- a/src/bonsai/bonsai/bim/module/material/prop.py +++ b/src/bonsai/bonsai/bim/module/material/prop.py @@ -22,7 +22,6 @@ from ifcopenshell.util.doc import get_entity_doc import bonsai.tool as tool from bonsai.bim.module.material.data import MaterialsData, ObjectMaterialData from bonsai.bim.module.profile.data import ProfileData -from bonsai.bim.ifc import IfcStore from bonsai.bim.prop import StrProperty, Attribute from bpy.types import PropertyGroup from bpy.props import ( diff --git a/src/bonsai/bonsai/bim/module/material/ui.py b/src/bonsai/bonsai/bim/module/material/ui.py index 9ddd5ccd9d..fe0fce2413 100644 --- a/src/bonsai/bonsai/bim/module/material/ui.py +++ b/src/bonsai/bonsai/bim/module/material/ui.py @@ -21,7 +21,6 @@ import bonsai.bim.helper import bonsai.tool as tool import bpy from bpy.types import Panel, UIList -from bonsai.bim.ifc import IfcStore from bonsai.bim.helper import draw_attributes from bonsai.bim.helper import prop_with_search from bonsai.bim.module.material.data import MaterialsData, ObjectMaterialData @@ -43,7 +42,7 @@ class BIM_PT_materials(Panel): @classmethod def poll(cls, context): - return IfcStore.get_file() + return tool.Ifc.get() def draw(self, context): if not MaterialsData.is_loaded: @@ -143,9 +142,9 @@ class BIM_PT_object_material(Panel): props = context.active_object.BIMObjectProperties if not props.ifc_definition_id: return False - if not IfcStore.get_element(props.ifc_definition_id): + if not tool.Ifc.get_object_by_identifier(props.ifc_definition_id): return False - if not hasattr(IfcStore.get_file().by_id(props.ifc_definition_id), "HasAssociations"): + if not hasattr(tool.Ifc.get().by_id(props.ifc_definition_id), "HasAssociations"): return False return True @@ -153,7 +152,7 @@ class BIM_PT_object_material(Panel): if not ObjectMaterialData.is_loaded: ObjectMaterialData.load() - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() self.oprops = context.active_object.BIMObjectProperties self.props = context.active_object.BIMObjectMaterialProperties self.mprops = tool.Material.get_material_props() diff --git a/src/bonsai/bonsai/bim/module/model/handler.py b/src/bonsai/bonsai/bim/module/model/handler.py index 2b30a1238c..b69b595c34 100644 --- a/src/bonsai/bonsai/bim/module/model/handler.py +++ b/src/bonsai/bonsai/bim/module/model/handler.py @@ -20,7 +20,6 @@ import bpy import ifcopenshell import ifcopenshell.api from bonsai.bim.module.model import product, wall, slab, profile, opening, task -from bonsai.bim.ifc import IfcStore from bpy.app.handlers import persistent diff --git a/src/bonsai/bonsai/bim/module/model/opening.py b/src/bonsai/bonsai/bim/module/model/opening.py index d9da756705..319ffdd345 100644 --- a/src/bonsai/bonsai/bim/module/model/opening.py +++ b/src/bonsai/bonsai/bim/module/model/opening.py @@ -38,7 +38,6 @@ import bonsai.tool as tool import bonsai.core.geometry import bonsai.bim.import_ifc as import_ifc from collections import defaultdict -from bonsai.bim.ifc import IfcStore from math import pi, radians from mathutils import Vector, Matrix from bpy.types import Operator diff --git a/src/bonsai/bonsai/bim/module/model/polyline.py b/src/bonsai/bonsai/bim/module/model/polyline.py index 2f780015a1..d3c014586a 100644 --- a/src/bonsai/bonsai/bim/module/model/polyline.py +++ b/src/bonsai/bonsai/bim/module/model/polyline.py @@ -35,7 +35,6 @@ import bonsai.core.root import bonsai.core.geometry import bonsai.core.model as core import bonsai.tool as tool -from bonsai.bim.ifc import IfcStore from math import pi, sin, cos, degrees, tan, radians from mathutils import Vector, Matrix, Quaternion from bonsai.bim.module.model.opening import FilledOpeningGenerator diff --git a/src/bonsai/bonsai/bim/module/model/product.py b/src/bonsai/bonsai/bim/module/model/product.py index ddc9eb5fea..ef00ea7b21 100644 --- a/src/bonsai/bonsai/bim/module/model/product.py +++ b/src/bonsai/bonsai/bim/module/model/product.py @@ -757,7 +757,7 @@ def regenerate_profile_usage(usecase_path, ifc_file, settings): elements.append(element) for element in elements: - obj = IfcStore.get_element(element.id()) + obj = tool.Ifc.get_object_by_identifier(element.id()) if not obj: continue representation = ifcopenshell.util.representation.get_representation(element, "Model", "Body", "MODEL_VIEW") diff --git a/src/bonsai/bonsai/bim/module/model/slab.py b/src/bonsai/bonsai/bim/module/model/slab.py index 328eb34090..2ccd20a3e5 100644 --- a/src/bonsai/bonsai/bim/module/model/slab.py +++ b/src/bonsai/bonsai/bim/module/model/slab.py @@ -889,7 +889,7 @@ class DrawPolylineSlab(bpy.types.Operator, PolylineOperator, tool.Ifc.Operator): model_props = tool.Model.get_model_props() direction_sense = model_props.direction_sense offset = model_props.offset - model = IfcStore.get_file() + model = tool.Ifc.get() element = tool.Ifc.get_entity(slab) material = ifcopenshell.util.element.get_material(element) material_set_usage = model.by_id(material.id()) diff --git a/src/bonsai/bonsai/bim/module/model/wall.py b/src/bonsai/bonsai/bim/module/model/wall.py index d6e6ec7a31..daf9d9a43b 100644 --- a/src/bonsai/bonsai/bim/module/model/wall.py +++ b/src/bonsai/bonsai/bim/module/model/wall.py @@ -377,7 +377,7 @@ class DrawPolylineWall(bpy.types.Operator, PolylineOperator, tool.Ifc.Operator): walls, is_polyline_closed = DumbWallGenerator(self.relating_type).generate("POLYLINE") for wall in walls: - model = IfcStore.get_file() + model = tool.Ifc.get() element = tool.Ifc.get_entity(wall["obj"]) material = ifcopenshell.util.element.get_material(element) material_set_usage = model.by_id(material.id()) @@ -598,7 +598,7 @@ class DumbWallGenerator: self.unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get()) def generate(self, insertion_type="CURSOR"): - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() self.layers = tool.Model.get_material_layer_parameters(self.relating_type) if not self.layers["thickness"]: return diff --git a/src/bonsai/bonsai/bim/module/nest/operator.py b/src/bonsai/bonsai/bim/module/nest/operator.py index 00b1f15f33..f3247817ec 100644 --- a/src/bonsai/bonsai/bim/module/nest/operator.py +++ b/src/bonsai/bonsai/bim/module/nest/operator.py @@ -21,7 +21,6 @@ import ifcopenshell import ifcopenshell.util.element import bonsai.tool as tool import bonsai.core.nest as core -from bonsai.bim.ifc import IfcStore class BIM_OT_nest_assign_object(bpy.types.Operator, tool.Ifc.Operator): @@ -113,7 +112,7 @@ class BIM_OT_select_components(bpy.types.Operator): obj: bpy.props.StringProperty() def execute(self, context): - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() obj = bpy.data.objects.get(self.obj) or context.active_object components = ifcopenshell.util.element.get_components(tool.Ifc.get_entity(obj)) component_objs = set(tool.Ifc.get_object(c) for c in components) @@ -132,7 +131,7 @@ class BIM_OT_select_nest(bpy.types.Operator): obj: bpy.props.StringProperty() def execute(self, context): - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() obj = bpy.data.objects.get(self.obj) or context.active_object nest = ifcopenshell.util.element.get_nest(tool.Ifc.get_entity(obj)) nest_obj = tool.Ifc.get_object(nest) diff --git a/src/bonsai/bonsai/bim/module/nest/ui.py b/src/bonsai/bonsai/bim/module/nest/ui.py index b1983a2411..1fd8f5ca4a 100644 --- a/src/bonsai/bonsai/bim/module/nest/ui.py +++ b/src/bonsai/bonsai/bim/module/nest/ui.py @@ -16,9 +16,9 @@ # You should have received a copy of the GNU General Public License # along with Bonsai. If not, see . +import bonsai.tool as tool from bpy.types import Panel from bonsai.bim.module.nest.data import NestData -from bonsai.bim.ifc import IfcStore class BIM_PT_nest(Panel): @@ -37,9 +37,9 @@ class BIM_PT_nest(Panel): props = context.active_object.BIMObjectProperties if not props.ifc_definition_id: return False - if not IfcStore.get_element(props.ifc_definition_id): + if not tool.Ifc.get_object_by_identifier(props.ifc_definition_id): return False - if not IfcStore.get_file().by_id(props.ifc_definition_id).is_a("IfcObjectDefinition"): + if not tool.Ifc.get().by_id(props.ifc_definition_id).is_a("IfcObjectDefinition"): return False return True diff --git a/src/bonsai/bonsai/bim/module/profile/prop.py b/src/bonsai/bonsai/bim/module/profile/prop.py index 9a2da938e6..3f25c5f4e4 100644 --- a/src/bonsai/bonsai/bim/module/profile/prop.py +++ b/src/bonsai/bonsai/bim/module/profile/prop.py @@ -21,7 +21,6 @@ import ifcopenshell import ifcopenshell.util.schema import ifcopenshell.util.attribute import bonsai.tool as tool -from bonsai.bim.ifc import IfcStore from bonsai.bim.prop import StrProperty, Attribute from bonsai.bim.module.profile.data import ProfileData from bpy.types import PropertyGroup diff --git a/src/bonsai/bonsai/bim/module/project/operator.py b/src/bonsai/bonsai/bim/module/project/operator.py index 0aea8d00a3..02ee383a6a 100644 --- a/src/bonsai/bonsai/bim/module/project/operator.py +++ b/src/bonsai/bonsai/bim/module/project/operator.py @@ -503,10 +503,10 @@ class AppendEntireLibrary(bpy.types.Operator, tool.Ifc.Operator): @classmethod def poll(cls, context): - return IfcStore.get_file() + return tool.Ifc.get() def _execute(self, context): - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() self.library = IfcStore.library_file query = ", ".join(tool.Project.get_appendable_asset_types()) @@ -523,10 +523,10 @@ class AppendLibraryElementByQuery(bpy.types.Operator, tool.Ifc.Operator): @classmethod def poll(cls, context): - return IfcStore.get_file() + return tool.Ifc.get() def _execute(self, context): - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() self.library = IfcStore.library_file for element in ifcopenshell.util.selector.filter_elements(self.library, self.query): @@ -556,7 +556,7 @@ class AppendLibraryElement(bpy.types.Operator, tool.Ifc.Operator): @classmethod def poll(cls, context): - poll = bool(IfcStore.get_file()) + poll = bool(tool.Ifc.get()) if not poll: cls.poll_message_set("Please create or load a project first.") return poll @@ -602,7 +602,7 @@ class AppendLibraryElement(bpy.types.Operator, tool.Ifc.Operator): return {"FINISHED"} def import_material_from_ifc(self, element: ifcopenshell.entity_instance, context: bpy.types.Context) -> None: - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() logger = logging.getLogger("ImportIFC") ifc_import_settings = import_ifc.IfcImportSettings.factory(context, IfcStore.path, logger) ifc_importer = import_ifc.IfcImporter(ifc_import_settings) @@ -620,7 +620,7 @@ class AppendLibraryElement(bpy.types.Operator, tool.Ifc.Operator): ifc_importer.create_style(style) def import_product_from_ifc(self, element: ifcopenshell.entity_instance, context: bpy.types.Context) -> None: - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() logger = logging.getLogger("ImportIFC") ifc_import_settings = import_ifc.IfcImportSettings.factory(context, IfcStore.path, logger) ifc_importer = import_ifc.IfcImporter(ifc_import_settings) @@ -633,7 +633,7 @@ class AppendLibraryElement(bpy.types.Operator, tool.Ifc.Operator): ifc_importer.place_objects_in_collections() def import_type_from_ifc(self, element: ifcopenshell.entity_instance, context: bpy.types.Context) -> None: - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() logger = logging.getLogger("ImportIFC") ifc_import_settings = import_ifc.IfcImportSettings.factory(context, IfcStore.path, logger) @@ -648,7 +648,7 @@ class AppendLibraryElement(bpy.types.Operator, tool.Ifc.Operator): def import_materials(self, element: ifcopenshell.entity_instance, ifc_importer: import_ifc.IfcImporter) -> None: for material in ifcopenshell.util.element.get_materials(element): - if IfcStore.get_element(material.id()): + if tool.Ifc.get_object_by_identifier(material.id()): continue self.import_material_styles(material, ifc_importer) @@ -662,7 +662,7 @@ class AppendLibraryElement(bpy.types.Operator, tool.Ifc.Operator): if not element.is_a("IfcRepresentationItem") or not element.StyledByItem: continue for element2 in self.file.traverse(element.StyledByItem[0]): - if element2.is_a("IfcSurfaceStyle") and not IfcStore.get_element(element2.id()): + if element2.is_a("IfcSurfaceStyle") and not tool.Ifc.get_object_by_identifier(element2.id()): ifc_importer.create_style(element2) def import_material_styles( @@ -673,7 +673,7 @@ class AppendLibraryElement(bpy.types.Operator, tool.Ifc.Operator): if not material.HasRepresentation: return for element in self.file.traverse(material.HasRepresentation[0]): - if element.is_a("IfcSurfaceStyle") and not IfcStore.get_element(element.id()): + if element.is_a("IfcSurfaceStyle") and not tool.Ifc.get_object_by_identifier(element.id()): ifc_importer.create_style(element) @@ -770,14 +770,14 @@ class EnableEditingHeader(bpy.types.Operator): @classmethod def poll(cls, context): - return IfcStore.get_file() + return tool.Ifc.get() def execute(self, context): self.file = tool.Ifc.get() props = tool.Project.get_project_props() props.is_editing = True - mvd = "".join(IfcStore.get_file().wrapped_data.header.file_description.description) + mvd = "".join(tool.Ifc.get().wrapped_data.header.file_description.description) if "[" in mvd: props.mvd = mvd.split("[")[1][0:-1] else: @@ -807,7 +807,7 @@ class EditHeader(bpy.types.Operator): @classmethod def poll(cls, context): - return IfcStore.get_file() + return tool.Ifc.get() def execute(self, context): IfcStore.begin_transaction(self) @@ -832,7 +832,7 @@ class EditHeader(bpy.types.Operator): return {"FINISHED"} def record_state(self): - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() return { "description": self.file.wrapped_data.header.file_description.description, "author": self.file.wrapped_data.header.file_name.author, @@ -841,14 +841,14 @@ class EditHeader(bpy.types.Operator): } def rollback(self, data): - file = IfcStore.get_file() + file = tool.Ifc.get() file.wrapped_data.header.file_description.description = data["old"]["description"] file.wrapped_data.header.file_name.author = data["old"]["author"] file.wrapped_data.header.file_name.organization = data["old"]["organisation"] file.wrapped_data.header.file_name.authorization = data["old"]["authorisation"] def commit(self, data): - file = IfcStore.get_file() + file = tool.Ifc.get() file.wrapped_data.header.file_description.description = data["new"]["description"] file.wrapped_data.header.file_name.author = data["new"]["author"] file.wrapped_data.header.file_name.organization = data["new"]["organisation"] diff --git a/src/bonsai/bonsai/bim/module/project/prop.py b/src/bonsai/bonsai/bim/module/project/prop.py index e56826be57..3d6f0460bc 100644 --- a/src/bonsai/bonsai/bim/module/project/prop.py +++ b/src/bonsai/bonsai/bim/module/project/prop.py @@ -121,7 +121,7 @@ def update_filter_mode(self: "BIMProjectProperties", context: bpy.types.Context) self.filter_categories.clear() if self.filter_mode == "NONE": return - file = IfcStore.get_file() + file = tool.Ifc.get() if self.filter_mode == "DECOMPOSITION": if file.schema == "IFC2X3": elements = file.by_type("IfcSpatialStructureElement") diff --git a/src/bonsai/bonsai/bim/module/project/ui.py b/src/bonsai/bonsai/bim/module/project/ui.py index cd0c69512f..b0950b2f15 100644 --- a/src/bonsai/bonsai/bim/module/project/ui.py +++ b/src/bonsai/bonsai/bim/module/project/ui.py @@ -153,7 +153,7 @@ class BIM_PT_project(Panel): self.layout.use_property_split = True props = context.scene.BIMProperties pprops = self.props = tool.Project.get_project_props() - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() if pprops.is_loading: self.draw_advanced_loading_ui(context) elif self.file or props.ifc_file: @@ -247,7 +247,7 @@ class BIM_PT_project(Panel): def draw_editing_buttons(self, context, row): pprops = self.props - if IfcStore.get_file(): + if tool.Ifc.get(): if pprops.is_editing: row.operator("bim.edit_header", icon="CHECKMARK", text="") row.operator("bim.disable_editing_header", icon="CANCEL", text="") @@ -257,10 +257,10 @@ class BIM_PT_project(Panel): def draw_editable_file_info(self, context): pprops = self.props - if IfcStore.get_file(): + if tool.Ifc.get(): row = self.layout.row(align=True) row.label(text="IFC Schema", icon="FILE_CACHE") - row.label(text=IfcStore.get_file().schema) + row.label(text=tool.Ifc.get().schema) if pprops.is_editing: row = self.layout.row(align=True) @@ -281,7 +281,7 @@ class BIM_PT_project(Panel): else: row = self.layout.row(align=True) row.label(text="IFC MVD", icon="FILE_HIDDEN") - mvd = "".join(IfcStore.get_file().wrapped_data.header.file_description.description) + mvd = "".join(tool.Ifc.get().wrapped_data.header.file_description.description) if "[" in mvd: mvd = mvd.split("[")[1][0:-1] row.label(text=mvd) diff --git a/src/bonsai/bonsai/bim/module/pset/operator.py b/src/bonsai/bonsai/bim/module/pset/operator.py index 4165951a53..691d2e6930 100644 --- a/src/bonsai/bonsai/bim/module/pset/operator.py +++ b/src/bonsai/bonsai/bim/module/pset/operator.py @@ -94,7 +94,7 @@ class EditPset(bpy.types.Operator, tool.Ifc.Operator): properties: bpy.props.StringProperty() def _execute(self, context): - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() props = tool.Pset.get_pset_props(self.obj, self.obj_type) ifc_definition_id = tool.Blender.get_obj_ifc_definition_id(self.obj, self.obj_type, context) element = tool.Ifc.get().by_id(ifc_definition_id) @@ -226,7 +226,7 @@ class AddQto(bpy.types.Operator, tool.Ifc.Operator): obj_type: bpy.props.StringProperty() def _execute(self, context): - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() qto_name = tool.Pset.get_pset_name(self.obj, self.obj_type, pset_type="QTO") bpy.ops.bim.enable_pset_editing( pset_id=0, pset_name=qto_name, pset_type="QTO", obj=self.obj, obj_type=self.obj_type @@ -314,7 +314,7 @@ class BIM_OT_rename_parameters(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): props_to_map = context.scene.RenameProperties - ifc_file = IfcStore.get_file() + ifc_file = tool.Ifc.get() all_ifc_elements = ifc_file.by_type("IfcElement") for ifc_element in all_ifc_elements: @@ -347,7 +347,7 @@ class BIM_OT_add_edit_custom_property(bpy.types.Operator, tool.Ifc.Operator): index: bpy.props.IntProperty() def _execute(self, context): - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() props = context.scene.AddEditProperties for obj in tool.Blender.get_selected_objects(): @@ -402,7 +402,7 @@ class BIM_OT_bulk_remove_psets(bpy.types.Operator, tool.Ifc.Operator): index: bpy.props.IntProperty() def _execute(self, context): - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() props = context.scene.DeletePsets for obj in tool.Blender.get_selected_objects(): diff --git a/src/bonsai/bonsai/bim/module/pset/prop.py b/src/bonsai/bonsai/bim/module/pset/prop.py index 86a3363557..6a1b68841f 100644 --- a/src/bonsai/bonsai/bim/module/pset/prop.py +++ b/src/bonsai/bonsai/bim/module/pset/prop.py @@ -26,7 +26,6 @@ import bonsai.tool as tool from bonsai.bim.prop import Attribute, StrProperty from bonsai.bim.module.pset.data import AddEditCustomPropertiesData, ObjectPsetsData, MaterialPsetsData from bonsai.bim.module.material.data import ObjectMaterialData -from bonsai.bim.ifc import IfcStore from bpy.types import PropertyGroup from bpy.props import ( PointerProperty, @@ -135,7 +134,7 @@ def get_resource_pset_names(self, context): global psetnames rprops = context.scene.BIMResourceProperties rtprops = context.scene.BIMResourceTreeProperties - ifc_class = IfcStore.get_file().by_id(rtprops.resources[rprops.active_resource_index].ifc_definition_id).is_a() + ifc_class = tool.Ifc.get().by_id(rtprops.resources[rprops.active_resource_index].ifc_definition_id).is_a() if ifc_class not in psetnames: psets = bonsai.bim.schema.ifc.psetqto.get_applicable(ifc_class, pset_only=True, schema=tool.Ifc.get_schema()) psetnames[ifc_class] = blender_formatted_enum_from_psets(psets) @@ -146,7 +145,7 @@ def get_resource_qto_names(self, context): global qtonames rprops = context.scene.BIMResourceProperties rtprops = context.scene.BIMResourceTreeProperties - ifc_class = IfcStore.get_file().by_id(rtprops.resources[rprops.active_resource_index].ifc_definition_id).is_a() + ifc_class = tool.Ifc.get().by_id(rtprops.resources[rprops.active_resource_index].ifc_definition_id).is_a() if ifc_class not in qtonames: psets = bonsai.bim.schema.ifc.psetqto.get_applicable(ifc_class, qto_only=True, schema=tool.Ifc.get_schema()) qtonames[ifc_class] = blender_formatted_enum_from_psets(psets) @@ -174,7 +173,7 @@ def get_group_qto_names(self, context): def get_profile_pset_names(self, context): global psetnames pprops = tool.Profile.get_profile_props() - ifc_class = IfcStore.get_file().by_id(pprops.profiles[pprops.active_profile_index].ifc_definition_id).is_a() + ifc_class = tool.Ifc.get().by_id(pprops.profiles[pprops.active_profile_index].ifc_definition_id).is_a() if ifc_class not in psetnames: psets = bonsai.bim.schema.ifc.psetqto.get_applicable(ifc_class, pset_only=True, schema=tool.Ifc.get_schema()) psetnames[ifc_class] = blender_formatted_enum_from_psets(psets) @@ -290,7 +289,8 @@ class AddEditProperties(PropertyGroup): enum_values: CollectionProperty(name="Enum Values", type=Attribute) def get_value_name(self) -> Union[Literal["string_value", "bool_value", "int_value", "float_value"], None]: - ifc_data_type = IfcStore.get_schema().declaration_by_name(self.primary_measure_type) + schema = tool.Ifc.schema() + ifc_data_type = schema.declaration_by_name(self.primary_measure_type) data_type = ifcopenshell.util.attribute.get_primitive_type(ifc_data_type) if data_type == "string": return "string_value" diff --git a/src/bonsai/bonsai/bim/module/pset/ui.py b/src/bonsai/bonsai/bim/module/pset/ui.py index 21f3c1b083..4adda725dc 100644 --- a/src/bonsai/bonsai/bim/module/pset/ui.py +++ b/src/bonsai/bonsai/bim/module/pset/ui.py @@ -20,7 +20,6 @@ from __future__ import annotations import bpy import bonsai.tool as tool from bpy.types import Panel -from bonsai.bim.ifc import IfcStore from bonsai.bim.helper import prop_with_search, get_display_value from bonsai.bim.module.pset.data import ( ObjectPsetsData, @@ -247,7 +246,7 @@ class BIM_PT_object_psets(Panel): props = context.active_object.BIMObjectProperties if not props.ifc_definition_id: return False - if not IfcStore.get_element(props.ifc_definition_id): + if not tool.Ifc.get_object_by_identifier(props.ifc_definition_id): return False return True @@ -325,7 +324,7 @@ class BIM_PT_object_qtos(Panel): props = context.active_object.BIMObjectProperties if not props.ifc_definition_id: return False - if not IfcStore.get_element(props.ifc_definition_id): + if not tool.Ifc.get_object_by_identifier(props.ifc_definition_id): return False return True diff --git a/src/bonsai/bonsai/bim/module/pset_template/prop.py b/src/bonsai/bonsai/bim/module/pset_template/prop.py index 66cd7e3fea..122a09128c 100644 --- a/src/bonsai/bonsai/bim/module/pset_template/prop.py +++ b/src/bonsai/bonsai/bim/module/pset_template/prop.py @@ -183,7 +183,8 @@ class PropTemplate(PropertyGroup): def get_value_name(self) -> str: if self.primary_measure_type == "-": return "string_value" - ifc_data_type = IfcStore.get_schema().declaration_by_name(self.primary_measure_type) + schema = tool.Ifc.schema() + ifc_data_type = schema.declaration_by_name(self.primary_measure_type) data_type = ifcopenshell.util.attribute.get_primitive_type(ifc_data_type) if data_type == "string": return "string_value" diff --git a/src/bonsai/bonsai/bim/module/qto/operator.py b/src/bonsai/bonsai/bim/module/qto/operator.py index fe1574d1fa..63d16335a1 100644 --- a/src/bonsai/bonsai/bim/module/qto/operator.py +++ b/src/bonsai/bonsai/bim/module/qto/operator.py @@ -21,7 +21,6 @@ import ifcopenshell import ifcopenshell.api import bonsai.tool as tool import bonsai.core.qto as core -from bonsai.bim.ifc import IfcStore from bonsai.bim.module.qto import helper diff --git a/src/bonsai/bonsai/bim/module/resource/prop.py b/src/bonsai/bonsai/bim/module/resource/prop.py index 8613f44d1a..b5f1360c4e 100644 --- a/src/bonsai/bonsai/bim/module/resource/prop.py +++ b/src/bonsai/bonsai/bim/module/resource/prop.py @@ -19,7 +19,6 @@ import bpy import ifcopenshell.api import ifcopenshell.util.resource -from bonsai.bim.ifc import IfcStore import bonsai.tool as tool import bonsai.bim.module.pset.data import bonsai.bim.module.resource.data diff --git a/src/bonsai/bonsai/bim/module/resource/ui.py b/src/bonsai/bonsai/bim/module/resource/ui.py index 5ffdac8881..898749ff67 100644 --- a/src/bonsai/bonsai/bim/module/resource/ui.py +++ b/src/bonsai/bonsai/bim/module/resource/ui.py @@ -17,9 +17,9 @@ # along with Bonsai. If not, see . import bpy +import bonsai.tool as tool import bonsai.bim.helper from bpy.types import Panel, UIList -from bonsai.bim.ifc import IfcStore from bonsai.bim.module.resource.data import ResourceData from typing import Any @@ -35,7 +35,7 @@ class BIM_PT_resources(Panel): @classmethod def poll(cls, context): - file = IfcStore.get_file() + file = tool.Ifc.get() return file and hasattr(file, "schema") and file.schema != "IFC2X3" def draw(self, context): diff --git a/src/bonsai/bonsai/bim/module/root/operator.py b/src/bonsai/bonsai/bim/module/root/operator.py index 4801d3f999..0d6a7b4d0f 100644 --- a/src/bonsai/bonsai/bim/module/root/operator.py +++ b/src/bonsai/bonsai/bim/module/root/operator.py @@ -57,8 +57,9 @@ class EnableReassignClass(bpy.types.Operator): "IfcAnnotation", "IfcRelSpaceBoundary", ] + schema = tool.Ifc.schema() for ifc_product in ifc_products: - if ifcopenshell.util.schema.is_a(IfcStore.get_schema().declaration_by_name(ifc_class), ifc_product): + if schema.declaration_by_name(ifc_class).is_a(ifc_product): context.scene.BIMRootProperties.ifc_product = ifc_product element = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id) context.scene.BIMRootProperties.ifc_class = element.is_a() diff --git a/src/bonsai/bonsai/bim/module/root/ui.py b/src/bonsai/bonsai/bim/module/root/ui.py index 809230656f..b1a2b52637 100644 --- a/src/bonsai/bonsai/bim/module/root/ui.py +++ b/src/bonsai/bonsai/bim/module/root/ui.py @@ -17,9 +17,9 @@ # along with Bonsai. If not, see . import bpy +import bonsai.tool as tool import bonsai.bim.module.root.prop as root_prop from bpy.types import Panel -from bonsai.bim.ifc import IfcStore from bonsai.bim.helper import prop_with_search from bonsai.bim.module.root.data import IfcClassData from bonsai.bim.module.model.data import AuthoringData @@ -38,7 +38,7 @@ class BIM_PT_class(Panel): def poll(cls, context): if not context.active_object: return False - return IfcStore.get_file() + return tool.Ifc.get() def draw(self, context): if not IfcClassData.is_loaded: diff --git a/src/bonsai/bonsai/bim/module/sequence/operator.py b/src/bonsai/bonsai/bim/module/sequence/operator.py index 6730353b00..5f5854edd2 100644 --- a/src/bonsai/bonsai/bim/module/sequence/operator.py +++ b/src/bonsai/bonsai/bim/module/sequence/operator.py @@ -31,7 +31,6 @@ import ifcopenshell.util.sequence import ifcopenshell.util.selector from datetime import datetime from dateutil import parser, relativedelta -from bonsai.bim.ifc import IfcStore from bpy_extras.io_utils import ImportHelper from typing import get_args, TYPE_CHECKING from typing_extensions import assert_never @@ -700,7 +699,7 @@ class ImportP6(bpy.types.Operator, tool.Ifc.Operator, ImportHelper): def _execute(self, context): from ifc4d.p62ifc import P62Ifc - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() start = time.time() p62ifc = P62Ifc() p62ifc.xml = self.filepath @@ -728,7 +727,7 @@ class ImportP6XER(bpy.types.Operator, tool.Ifc.Operator, ImportHelper): def _execute(self, context): from ifc4d.p6xer2ifc import P6XER2Ifc - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() start = time.time() p6xer2ifc = P6XER2Ifc() p6xer2ifc.xer = self.filepath @@ -756,7 +755,7 @@ class ImportPP(bpy.types.Operator, tool.Ifc.Operator, ImportHelper): def _execute(self, context): from ifc4d.pp2ifc import PP2Ifc - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() start = time.time() pp2ifc = PP2Ifc() pp2ifc.pp = self.filepath @@ -784,7 +783,7 @@ class ImportMSP(bpy.types.Operator, tool.Ifc.Operator, ImportHelper): def _execute(self, context): from ifc4d.msp2ifc import MSP2Ifc - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() start = time.time() msp2ifc = MSP2Ifc() msp2ifc.xml = self.filepath @@ -814,7 +813,7 @@ class ExportMSP(bpy.types.Operator, ImportHelper): def execute(self, context): from ifc4d.ifc2msp import Ifc2Msp - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() start = time.time() ifc2msp = Ifc2Msp() ifc2msp.work_schedule = self.file.by_type("IfcWorkSchedule")[0] @@ -847,7 +846,7 @@ class ExportP6(bpy.types.Operator, ImportHelper): def execute(self, context): from ifc4d.ifc2p6 import Ifc2P6 - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() start = time.time() ifc2p6 = Ifc2P6() ifc2p6.xml = bpy.path.ensure_ext(self.filepath, ".xml") diff --git a/src/bonsai/bonsai/bim/module/sequence/prop.py b/src/bonsai/bonsai/bim/module/sequence/prop.py index d2e550138d..ce0e307076 100644 --- a/src/bonsai/bonsai/bim/module/sequence/prop.py +++ b/src/bonsai/bonsai/bim/module/sequence/prop.py @@ -23,7 +23,6 @@ import ifcopenshell.util.attribute import ifcopenshell.util.date import bonsai.tool as tool import bonsai.core.sequence as core -from bonsai.bim.ifc import IfcStore from bonsai.bim.module.sequence.data import SequenceData, AnimationColorSchemeData, refresh as refresh_sequence_data import bonsai.bim.module.resource.data import bonsai.bim.module.pset.data diff --git a/src/bonsai/bonsai/bim/module/sequence/ui.py b/src/bonsai/bonsai/bim/module/sequence/ui.py index 2320bb80b4..21ed962852 100644 --- a/src/bonsai/bonsai/bim/module/sequence/ui.py +++ b/src/bonsai/bonsai/bim/module/sequence/ui.py @@ -22,7 +22,6 @@ import isodate import bonsai.tool as tool import bonsai.bim.helper from bpy.types import Panel, UIList -from bonsai.bim.ifc import IfcStore from bonsai.bim.helper import draw_attributes from bonsai.bim.module.sequence.data import ( WorkPlansData, @@ -45,7 +44,7 @@ class BIM_PT_status(Panel): @classmethod def poll(cls, context): - return IfcStore.get_file() + return tool.Ifc.get() def draw(self, context): self.props = context.scene.BIMStatusProperties @@ -77,7 +76,7 @@ class BIM_PT_work_plans(Panel): @classmethod def poll(cls, context): - file = IfcStore.get_file() + file = tool.Ifc.get() return file and file.schema != "IFC2X3" def draw(self, context): @@ -147,7 +146,7 @@ class BIM_PT_work_schedules(Panel): @classmethod def poll(cls, context): - file = IfcStore.get_file() + file = tool.Ifc.get() return file and hasattr(file, "schema") and file.schema != "IFC2X3" def draw(self, context): @@ -592,7 +591,7 @@ class BIM_PT_animation_Color_Scheme(Panel): @classmethod def poll(cls, context): - file = IfcStore.get_file() + file = tool.Ifc.get() return file and hasattr(file, "schema") and file.schema != "IFC2X3" def draw(self, context): @@ -980,7 +979,7 @@ class BIM_PT_work_calendars(Panel): @classmethod def poll(cls, context): - file = IfcStore.get_file() + file = tool.Ifc.get() return file and hasattr(file, "schema") and file.schema != "IFC2X3" def draw(self, context): diff --git a/src/bonsai/bonsai/bim/module/structural/load_decoration_data.py b/src/bonsai/bonsai/bim/module/structural/load_decoration_data.py index 8230c55c66..a91a7947c5 100644 --- a/src/bonsai/bonsai/bim/module/structural/load_decoration_data.py +++ b/src/bonsai/bonsai/bim/module/structural/load_decoration_data.py @@ -26,7 +26,6 @@ import ifcopenshell.api import ifcopenshell.util.attribute import ifcopenshell.util.unit as ifcunit import bonsai.tool as tool -from bonsai.bim.ifc import IfcStore from bonsai.bim.module.structural.shader import DecorationShader from typing import Literal, TypedDict, Iterable @@ -307,7 +306,7 @@ class ShaderInfo: props = bpy.context.scene.BIMStructuralProperties group_definition_id = int(props.load_group_to_show) - file = IfcStore.get_file() + file = tool.Ifc.get() groups = [file.by_id(group_definition_id)] recursive_subgroups(groups, 10, props.activity_type) @@ -333,7 +332,7 @@ class ShaderInfo: orientation = np.eye(3) if reference_frame == "LOCAL_COORDS": orientation = rotation - blender_object: bpy.types.Object = IfcStore.get_element(getattr(surf, "GlobalId", None)) + blender_object: bpy.types.Object = tool.Ifc.get_object_by_identifier(getattr(surf, "GlobalId", None)) mat = blender_object.matrix_world mesh: bpy.types.Mesh = blender_object.data @@ -454,7 +453,7 @@ class ShaderInfo: activity_list = value["activities"] if len(activity_list) == 0: continue - blender_object = IfcStore.get_element(getattr(conn, "GlobalId", None)) + blender_object = tool.Ifc.get_object_by_identifier(getattr(conn, "GlobalId", None)) if blender_object.type == "MESH": conn_location = blender_object.matrix_world @ blender_object.data.vertices[0].co rotation = self.get_point_connection_rotation(conn) @@ -580,7 +579,7 @@ class ShaderInfo: if len(activity_list) == 0: continue - blender_object = IfcStore.get_element(getattr(member, "GlobalId", None)) + blender_object = tool.Ifc.get_object_by_identifier(getattr(member, "GlobalId", None)) start_co = blender_object.matrix_world @ blender_object.data.vertices[0].co end_co = blender_object.matrix_world @ blender_object.data.vertices[1].co diff --git a/src/bonsai/bonsai/bim/module/structural/operator.py b/src/bonsai/bonsai/bim/module/structural/operator.py index 646e5ad294..47d74515f8 100644 --- a/src/bonsai/bonsai/bim/module/structural/operator.py +++ b/src/bonsai/bonsai/bim/module/structural/operator.py @@ -20,13 +20,13 @@ import bpy import json import ifcopenshell import ifcopenshell.api +import ifcopenshell.api.structural import ifcopenshell.util.attribute import bonsai.bim.helper import bonsai.core.structural as core import bonsai.tool as tool from math import degrees from mathutils import Vector, Matrix -from bonsai.bim.ifc import IfcStore from bonsai.bim.module.structural.decorator import LoadsDecorator @@ -77,13 +77,12 @@ class AddStructuralMemberConnection(bpy.types.Operator, tool.Ifc.Operator): obj = context.active_object oprops = obj.BIMObjectProperties props = obj.BIMStructuralProperties - file = IfcStore.get_file() + file = tool.Ifc.get() related_structural_connection = file.by_id(oprops.ifc_definition_id) relating_structural_member = file.by_id(props.relating_structural_member.BIMObjectProperties.ifc_definition_id) if not relating_structural_member.is_a("IfcStructuralMember"): return {"FINISHED"} - ifcopenshell.api.run( - "structural.add_structural_member_connection", + ifcopenshell.api.structural.add_structural_member_connection( file, relating_structural_member=relating_structural_member, related_structural_connection=related_structural_connection, @@ -125,7 +124,7 @@ class RemoveStructuralConnectionCondition(bpy.types.Operator, tool.Ifc.Operator) connects_structural_member: bpy.props.IntProperty() def _execute(self, context): - file = IfcStore.get_file() + file = tool.Ifc.get() relation = file.by_id(self.connects_structural_member) connection = relation.RelatedStructuralConnection ifcopenshell.api.run("structural.remove_structural_connection_condition", file, **{"relation": relation}) @@ -139,7 +138,7 @@ class AddStructuralBoundaryCondition(bpy.types.Operator, tool.Ifc.Operator): connection: bpy.props.IntProperty() def _execute(self, context): - file = IfcStore.get_file() + file = tool.Ifc.get() connection = file.by_id(self.connection) ifcopenshell.api.run("structural.add_structural_boundary_condition", file, **{"connection": connection}) return {"FINISHED"} @@ -152,7 +151,7 @@ class RemoveStructuralBoundaryCondition(bpy.types.Operator, tool.Ifc.Operator): connection: bpy.props.IntProperty() def _execute(self, context): - file = IfcStore.get_file() + file = tool.Ifc.get() connection = file.by_id(self.connection) ifcopenshell.api.run("structural.remove_structural_boundary_condition", file, **{"connection": connection}) return {"FINISHED"} @@ -170,8 +169,9 @@ class EnableEditingStructuralBoundaryCondition(bpy.types.Operator): props.boundary_condition_attributes.clear() condition = tool.Ifc.get().by_id(self.boundary_condition) + schema = tool.Ifc.schema() - for attribute in IfcStore.get_schema().declaration_by_name(condition.is_a()).all_attributes(): + for attribute in schema.declaration_by_name(condition.is_a()).all_attributes(): value = getattr(condition, attribute.name(), None) data_type = ifcopenshell.util.attribute.get_primitive_type(attribute) new = props.boundary_condition_attributes.add() @@ -207,7 +207,7 @@ class EditStructuralBoundaryCondition(bpy.types.Operator, tool.Ifc.Operator): obj = context.active_object props = obj.BIMStructuralProperties - file = IfcStore.get_file() + file = tool.Ifc.get() connection = file.by_id(self.connection) condition = connection.AppliedCondition @@ -353,7 +353,7 @@ class EnableEditingStructuralItemAxis(bpy.types.Operator): oprops = obj.BIMObjectProperties props = obj.BIMStructuralProperties - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() item = self.file.by_id(oprops.ifc_definition_id) z_axis = Vector(item.Axis.DirectionRatios).normalized() @ obj.matrix_world if item.Axis else None x_axis = (obj.data.vertices[1].co - obj.data.vertices[0].co).normalized() @@ -407,7 +407,7 @@ class EditStructuralItemAxis(bpy.types.Operator, tool.Ifc.Operator): props = obj.BIMStructuralProperties relative_matrix = props.axis_empty.matrix_world @ obj.matrix_world.inverted() z_axis = relative_matrix.col[2][0:3] - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() ifcopenshell.api.run( "structural.edit_structural_item_axis", self.file, @@ -428,7 +428,7 @@ class EnableEditingStructuralConnectionCS(bpy.types.Operator): oprops = obj.BIMObjectProperties props = obj.BIMStructuralProperties - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() item = self.file.by_id(oprops.ifc_definition_id) location = obj.data.vertices[0].co @@ -496,7 +496,7 @@ class EditStructuralConnectionCS(bpy.types.Operator, tool.Ifc.Operator): relative_matrix = props.ccs_empty.matrix_world @ obj.matrix_world.inverted() x_axis = relative_matrix.col[0][0:3] z_axis = relative_matrix.col[2][0:3] - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() ifcopenshell.api.run( "structural.edit_structural_connection_cs", self.file, @@ -515,7 +515,7 @@ class AssignStructuralLoadCase(bpy.types.Operator, tool.Ifc.Operator): load_case: bpy.props.IntProperty() def _execute(self, context): - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() ifcopenshell.api.run( "aggregate.assign_object", self.file, @@ -534,7 +534,7 @@ class UnassignStructuralLoadCase(bpy.types.Operator, tool.Ifc.Operator): load_case: bpy.props.IntProperty() def _execute(self, context): - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() ifcopenshell.api.run( "aggregate.unassign_object", self.file, @@ -552,7 +552,7 @@ class AddStructuralLoadCase(bpy.types.Operator, tool.Ifc.Operator): bl_options = {"REGISTER", "UNDO"} def _execute(self, context): - ifcopenshell.api.run("structural.add_structural_load_case", IfcStore.get_file()) + ifcopenshell.api.run("structural.add_structural_load_case", tool.Ifc.get()) return {"FINISHED"} @@ -564,7 +564,7 @@ class EditStructuralLoadCase(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): props = context.scene.BIMStructuralProperties attributes = bonsai.bim.helper.export_attributes(props.load_case_attributes) - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() ifcopenshell.api.run( "structural.edit_structural_load_case", self.file, @@ -581,7 +581,7 @@ class RemoveStructuralLoadCase(bpy.types.Operator, tool.Ifc.Operator): load_case: bpy.props.IntProperty() def _execute(self, context): - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() ifcopenshell.api.run( "structural.remove_structural_load_case", self.file, load_case=self.file.by_id(self.load_case) ) @@ -639,7 +639,7 @@ class AddStructuralLoadGroup(bpy.types.Operator, tool.Ifc.Operator): load_case: bpy.props.IntProperty() def _execute(self, context): - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() load_group = ifcopenshell.api.run("structural.add_structural_load_group", self.file) ifcopenshell.api.run( "group.assign_group", self.file, products=[load_group], group=self.file.by_id(self.load_case) @@ -654,7 +654,7 @@ class RemoveStructuralLoadGroup(bpy.types.Operator, tool.Ifc.Operator): load_group: bpy.props.IntProperty() def _execute(self, context): - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() ifcopenshell.api.run( "structural.remove_structural_load_group", self.file, load_group=self.file.by_id(self.load_group) ) @@ -668,7 +668,7 @@ class EnableEditingStructuralLoadGroupActivities(bpy.types.Operator): load_group: bpy.props.IntProperty() def execute(self, context): - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() self.props = context.scene.BIMStructuralProperties self.props.active_load_group_id = self.load_group self.props.load_group_editing_type = "ACTIVITY" @@ -693,7 +693,7 @@ class AddStructuralActivity(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): self.props = context.scene.BIMStructuralProperties - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() for obj in context.selected_objects: if not obj.BIMObjectProperties.ifc_definition_id: continue @@ -741,7 +741,7 @@ class LoadStructuralLoads(bpy.types.Operator): bl_options = {"REGISTER", "UNDO"} def execute(self, context): - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() props = context.scene.BIMStructuralProperties props.structural_loads.clear() loads = tool.Ifc.get().by_type("IfcStructuralLoad") @@ -787,7 +787,7 @@ class AddStructuralLoad(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): result = ifcopenshell.api.run( - "structural.add_structural_load", IfcStore.get_file(), name="New Load", ifc_class=self.ifc_class + "structural.add_structural_load", tool.Ifc.get(), name="New Load", ifc_class=self.ifc_class ) bpy.ops.bim.load_structural_loads() bpy.ops.bim.enable_editing_structural_load(structural_load=result.id()) @@ -828,7 +828,7 @@ class RemoveStructuralLoad(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): props = context.scene.BIMStructuralProperties - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() ifcopenshell.api.run( "structural.remove_structural_load", self.file, @@ -846,7 +846,7 @@ class EditStructuralLoad(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): props = context.scene.BIMStructuralProperties attributes = bonsai.bim.helper.export_attributes(props.structural_load_attributes) - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() ifcopenshell.api.run( "structural.edit_structural_load", self.file, @@ -877,7 +877,7 @@ class LoadBoundaryConditions(bpy.types.Operator): bl_options = {"REGISTER", "UNDO"} def execute(self, context): - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() props = context.scene.BIMStructuralProperties props.boundary_conditions.clear() conditions = tool.Ifc.get().by_type("IfcBoundaryCondition") @@ -936,7 +936,7 @@ class AddBoundaryCondition(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): result = ifcopenshell.api.run( "structural.add_structural_boundary_condition", - IfcStore.get_file(), + tool.Ifc.get(), name="New Load", ifc_class=self.ifc_class, ) @@ -957,7 +957,8 @@ class EnableEditingBoundaryCondition(bpy.types.Operator): boundary_condition = tool.Ifc.get().by_id(self.boundary_condition) # bonsai.bim.helper.import_attributes(data["type"], props.boundary_condition_attributes, data) - for attribute in IfcStore.get_schema().declaration_by_name(boundary_condition.is_a()).all_attributes(): + schema = tool.Ifc.schema() + for attribute in schema.declaration_by_name(boundary_condition.is_a()).all_attributes(): value = getattr(boundary_condition, attribute.name(), None) data_type = ifcopenshell.util.attribute.get_primitive_type(attribute) new = props.boundary_condition_attributes.add() @@ -1000,7 +1001,7 @@ class RemoveBoundaryCondition(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): props = context.scene.BIMStructuralProperties - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() ifcopenshell.api.run( "structural.remove_structural_boundary_condition", self.file, @@ -1017,7 +1018,7 @@ class EditBoundaryCondition(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): props = context.scene.BIMStructuralProperties - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() # attributes = bonsai.bim.helper.export_attributes(props.boundary_condition_attributes) attributes = {} for attribute in props.boundary_condition_attributes: diff --git a/src/bonsai/bonsai/bim/module/structural/prop.py b/src/bonsai/bonsai/bim/module/structural/prop.py index 740c97f1e6..2ecc29834a 100644 --- a/src/bonsai/bonsai/bim/module/structural/prop.py +++ b/src/bonsai/bonsai/bim/module/structural/prop.py @@ -19,7 +19,6 @@ from math import radians import bpy import bonsai.tool as tool -from bonsai.bim.ifc import IfcStore from bonsai.bim.prop import StrProperty, Attribute from bonsai.bim.module.structural.data import ( StructuralLoadCasesData, diff --git a/src/bonsai/bonsai/bim/module/structural/ui.py b/src/bonsai/bonsai/bim/module/structural/ui.py index 767724bdd5..d8f69e232e 100644 --- a/src/bonsai/bonsai/bim/module/structural/ui.py +++ b/src/bonsai/bonsai/bim/module/structural/ui.py @@ -17,9 +17,9 @@ # along with Bonsai. If not, see . import bpy +import bonsai.tool as tool import bonsai.bim.helper from bpy.types import Panel, UIList -from bonsai.bim.ifc import IfcStore from bonsai.bim.helper import draw_attributes, prop_with_search from bonsai.bim.module.structural.data import ( StructuralBoundaryConditionsData, @@ -90,9 +90,9 @@ class BIM_PT_structural_boundary_conditions(Panel): props = context.active_object.BIMObjectProperties if not props.ifc_definition_id: return False - if not IfcStore.get_element(props.ifc_definition_id): + if not tool.Ifc.get_object_by_identifier(props.ifc_definition_id): return False - if not IfcStore.get_file().by_id(props.ifc_definition_id).is_a("IfcStructuralConnection"): + if not tool.Ifc.get().by_id(props.ifc_definition_id).is_a("IfcStructuralConnection"): return False return True @@ -125,9 +125,9 @@ class BIM_PT_connected_structural_members(Panel): props = context.active_object.BIMObjectProperties if not props.ifc_definition_id: return False - if not IfcStore.get_element(props.ifc_definition_id): + if not tool.Ifc.get_object_by_identifier(props.ifc_definition_id): return False - if not IfcStore.get_file().by_id(props.ifc_definition_id).is_a("IfcStructuralConnection"): + if not tool.Ifc.get().by_id(props.ifc_definition_id).is_a("IfcStructuralConnection"): return False return True @@ -178,9 +178,9 @@ class BIM_PT_structural_member(Panel): props = context.active_object.BIMObjectProperties if not props.ifc_definition_id: return False - if not IfcStore.get_element(props.ifc_definition_id): + if not tool.Ifc.get_object_by_identifier(props.ifc_definition_id): return False - if not IfcStore.get_file().by_id(props.ifc_definition_id).is_a("IfcStructuralMember"): + if not tool.Ifc.get().by_id(props.ifc_definition_id).is_a("IfcStructuralMember"): return False return True @@ -221,9 +221,9 @@ class BIM_PT_structural_connection(Panel): props = context.active_object.BIMObjectProperties if not props.ifc_definition_id: return False - if not IfcStore.get_element(props.ifc_definition_id): + if not tool.Ifc.get_object_by_identifier(props.ifc_definition_id): return False - if not IfcStore.get_file().by_id(props.ifc_definition_id).is_a("IfcStructuralConnection"): + if not tool.Ifc.get().by_id(props.ifc_definition_id).is_a("IfcStructuralConnection"): return False return True @@ -274,7 +274,7 @@ class BIM_PT_structural_analysis_models(Panel): @classmethod def poll(cls, context): - file = IfcStore.get_file() + file = tool.Ifc.get() return file and hasattr(file, "schema") and file.schema != "IFC2X3" def draw(self, context): @@ -348,7 +348,7 @@ class BIM_PT_structural_load_cases(Panel): @classmethod def poll(cls, context): - file = IfcStore.get_file() + file = tool.Ifc.get() return file and hasattr(file, "schema") and file.schema != "IFC2X3" def draw(self, context): @@ -443,7 +443,7 @@ class BIM_PT_show_structural_activities(Panel): @classmethod def poll(cls, context): - file = IfcStore.get_file() + file = tool.Ifc.get() return file and hasattr(file, "schema") and file.schema != "IFC2X3" def draw(self, context): @@ -474,7 +474,7 @@ class BIM_PT_structural_loads(Panel): @classmethod def poll(cls, context): - file = IfcStore.get_file() + file = tool.Ifc.get() return file and hasattr(file, "schema") and file.schema != "IFC2X3" def draw(self, context): @@ -543,7 +543,7 @@ class BIM_PT_boundary_conditions(Panel): @classmethod def poll(cls, context): - file = IfcStore.get_file() + file = tool.Ifc.get() return file and hasattr(file, "schema") and file.schema != "IFC2X3" def draw(self, context): diff --git a/src/bonsai/bonsai/bim/module/style/ui.py b/src/bonsai/bonsai/bim/module/style/ui.py index 2486ee91e8..2b7eaad760 100644 --- a/src/bonsai/bonsai/bim/module/style/ui.py +++ b/src/bonsai/bonsai/bim/module/style/ui.py @@ -20,9 +20,7 @@ import bpy import bonsai.bim.helper import bonsai.tool as tool from bpy.types import Panel, UIList -from bonsai.bim.ifc import IfcStore from bonsai.bim.module.style.data import StylesData, BlenderMaterialStyleData -from typing import Union class BIM_PT_styles(Panel): @@ -36,7 +34,7 @@ class BIM_PT_styles(Panel): @classmethod def poll(cls, context): - return IfcStore.get_file() + return tool.Ifc.get() def draw(self, context): if not StylesData.is_loaded: diff --git a/src/bonsai/bonsai/bim/module/system/operator.py b/src/bonsai/bonsai/bim/module/system/operator.py index 4ef3c255f7..5c9750dc23 100644 --- a/src/bonsai/bonsai/bim/module/system/operator.py +++ b/src/bonsai/bonsai/bim/module/system/operator.py @@ -21,9 +21,7 @@ import ifcopenshell.api import bonsai.tool as tool import bonsai.core.system as core import bonsai.bim.helper -from bonsai.bim.ifc import IfcStore from bonsai.bim.module.system.data import PortData -from mathutils import Matrix class LoadSystems(bpy.types.Operator): diff --git a/src/bonsai/bonsai/bim/module/type/operator.py b/src/bonsai/bonsai/bim/module/type/operator.py index 866407be3e..ee370e5ae5 100644 --- a/src/bonsai/bonsai/bim/module/type/operator.py +++ b/src/bonsai/bonsai/bim/module/type/operator.py @@ -29,7 +29,6 @@ import bonsai.tool as tool import bonsai.core.geometry import bonsai.core.type as core import bonsai.core.root -from bonsai.bim.ifc import IfcStore class AssignType(bpy.types.Operator, tool.Ifc.Operator): @@ -66,7 +65,7 @@ class UnassignType(bpy.types.Operator, tool.Ifc.Operator): def exclude_callback(attribute): return attribute.is_a("IfcProfileDef") and attribute.ProfileName - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() objs = [bpy.data.objects.get(self.related_object)] if self.related_object else context.selected_objects for obj in objs: element = tool.Ifc.get_entity(obj) @@ -187,7 +186,7 @@ class SelectSimilarType(bpy.types.Operator): related_object: bpy.props.StringProperty() def execute(self, context): - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() objects = bpy.context.selected_objects # store relating types to avoid selecting same elements multiple times @@ -229,7 +228,7 @@ class SelectTypeObjects(bpy.types.Operator): relating_type: bpy.props.StringProperty() def execute(self, context): - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() relating_type = bpy.data.objects.get(self.relating_type) if self.relating_type else context.active_object at_least_one_selectable_typed_object = False for element in ifcopenshell.util.element.get_types(tool.Ifc.get_entity(relating_type)): diff --git a/src/bonsai/bonsai/bim/module/type/prop.py b/src/bonsai/bonsai/bim/module/type/prop.py index ac7986fe6b..aedb5c1993 100644 --- a/src/bonsai/bonsai/bim/module/type/prop.py +++ b/src/bonsai/bonsai/bim/module/type/prop.py @@ -20,8 +20,6 @@ import bpy import ifcopenshell.util.element import ifcopenshell.util.type from bonsai.bim.module.type.data import TypeData -from bonsai.bim.prop import StrProperty, Attribute -from bonsai.bim.ifc import IfcStore import bonsai.tool as tool from bpy.types import PropertyGroup from bpy.props import ( diff --git a/src/bonsai/bonsai/bim/module/type/ui.py b/src/bonsai/bonsai/bim/module/type/ui.py index 4bfca516e3..405507f168 100644 --- a/src/bonsai/bonsai/bim/module/type/ui.py +++ b/src/bonsai/bonsai/bim/module/type/ui.py @@ -19,7 +19,6 @@ import bonsai.tool as tool import bonsai.bim.module.type.prop as type_prop from bpy.types import Panel -from bonsai.bim.ifc import IfcStore from bonsai.bim.helper import prop_with_search from bonsai.bim.module.type.data import TypeData diff --git a/src/bonsai/bonsai/bim/module/unit/prop.py b/src/bonsai/bonsai/bim/module/unit/prop.py index edd23f2ce4..b01fab4ddf 100644 --- a/src/bonsai/bonsai/bim/module/unit/prop.py +++ b/src/bonsai/bonsai/bim/module/unit/prop.py @@ -17,7 +17,6 @@ # along with Bonsai. If not, see . import bpy -from bonsai.bim.ifc import IfcStore from bonsai.bim.prop import StrProperty, Attribute from bonsai.bim.module.unit.data import UnitsData from bpy.types import PropertyGroup diff --git a/src/bonsai/bonsai/bim/module/unit/ui.py b/src/bonsai/bonsai/bim/module/unit/ui.py index 77e0117699..83637845f7 100644 --- a/src/bonsai/bonsai/bim/module/unit/ui.py +++ b/src/bonsai/bonsai/bim/module/unit/ui.py @@ -17,8 +17,8 @@ # along with Bonsai. If not, see . import bonsai.bim.helper +import bonsai.tool as tool from bpy.types import Panel, UIList -from bonsai.bim.ifc import IfcStore from bonsai.bim.helper import prop_with_search from bonsai.bim.module.unit.data import UnitsData @@ -34,7 +34,7 @@ class BIM_PT_units(Panel): @classmethod def poll(cls, context): - file = IfcStore.get_file() + file = tool.Ifc.get() return file def draw(self, context): diff --git a/src/bonsai/bonsai/bim/module/void/operator.py b/src/bonsai/bonsai/bim/module/void/operator.py index a1493f2711..91537ed528 100644 --- a/src/bonsai/bonsai/bim/module/void/operator.py +++ b/src/bonsai/bonsai/bim/module/void/operator.py @@ -24,7 +24,6 @@ import bonsai.tool as tool import bonsai.core.geometry import bonsai.core.root import bonsai.bim.handler -from bonsai.bim.ifc import IfcStore from bonsai.bim.module.model.opening import FilledOpeningGenerator @@ -98,7 +97,7 @@ class AddOpening(bpy.types.Operator, tool.Ifc.Operator): break element_had_openings = tool.Geometry.has_openings(voided_element) - body_context = ifcopenshell.util.representation.get_context(IfcStore.get_file(), "Model", "Body") + body_context = ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Model", "Body") if not element2: element2 = bonsai.core.root.assign_class( tool.Ifc, @@ -215,7 +214,7 @@ class AddFilling(bpy.types.Operator, tool.Ifc.Operator): opening = context.scene.objects.get(self.opening, context.scene.VoidProperties.desired_opening) if opening is None: return {"FINISHED"} - self.file = IfcStore.get_file() + self.file = tool.Ifc.get() element_id = obj.BIMObjectProperties.ifc_definition_id opening_id = opening.BIMObjectProperties.ifc_definition_id if not element_id or not opening_id or element_id == opening_id: diff --git a/src/bonsai/bonsai/tool/ifc.py b/src/bonsai/bonsai/tool/ifc.py index c82ffa80a5..ce9f856f80 100644 --- a/src/bonsai/bonsai/tool/ifc.py +++ b/src/bonsai/bonsai/tool/ifc.py @@ -129,9 +129,13 @@ class Ifc(bonsai.core.tool.Ifc): return None @classmethod - def get_object(cls, element: ifcopenshell.entity_instance) -> IFC_CONNECTED_TYPE: + def get_object(cls, element: ifcopenshell.entity_instance) -> Union[IFC_CONNECTED_TYPE, None]: return IfcStore.get_element(element.id()) + @classmethod + def get_object_by_identifier(cls, id_or_guid: Union[int, str]) -> Union[IFC_CONNECTED_TYPE, None]: + return IfcStore.get_element(id_or_guid) + @classmethod def rebuild_element_maps(cls) -> None: """Rebuilds the id_map and guid_map diff --git a/src/bonsai/bonsai/tool/structural.py b/src/bonsai/bonsai/tool/structural.py index 7dfa3dbdd0..30cbb00191 100644 --- a/src/bonsai/bonsai/tool/structural.py +++ b/src/bonsai/bonsai/tool/structural.py @@ -23,8 +23,6 @@ import json import bonsai.bim.helper import bonsai.core.tool import bonsai.tool as tool -from bonsai.bim.ifc import IfcStore -from pprint import pprint from typing import Union, Any @@ -129,7 +127,8 @@ class Structural(bonsai.core.tool.Structural): def load_structural_analysis_model_attributes(cls, data: dict[str, Any]) -> None: props = bpy.context.scene.BIMStructuralProperties props.structural_analysis_model_attributes.clear() - for attribute in IfcStore.get_schema().declaration_by_name("IfcStructuralAnalysisModel").all_attributes(): + schema = tool.Ifc.schema() + for attribute in schema.declaration_by_name("IfcStructuralAnalysisModel").all_attributes(): data_type = str(attribute.type_of_attribute) if " 0: @@ -114,8 +113,8 @@ class Patcher: bpy.ops.bim.update_representation( ifc_representation_class="IfcExtrudedAreaSolid/IfcArbitraryProfileDefWithVoids" ) - for context in IfcStore.get_file().by_type("IfcGeometricRepresentationContext", include_subtypes=False): + for context in tool.Ifc.get().by_type("IfcGeometricRepresentationContext", include_subtypes=False): if context.Precision: context.Precision = 10 - self.file = IfcStore.get_file() + self.file = tool.Ifc.get()