diff --git a/src/ifcblenderexport/blenderbim/bim/handler.py b/src/ifcblenderexport/blenderbim/bim/handler.py index ad9e940872..1937c37e31 100644 --- a/src/ifcblenderexport/blenderbim/bim/handler.py +++ b/src/ifcblenderexport/blenderbim/bim/handler.py @@ -1,6 +1,8 @@ import bpy import json +import addon_utils import blenderbim.bim.decoration as decoration +import ifcopenshell.api.owner.settings from bpy.app.handlers import persistent from blenderbim.bim.ifc import IfcStore from ifcopenshell.api.attribute.data import Data as AttributeData @@ -46,14 +48,13 @@ def subscribe_to(object, data_path, callback): }, ) + def purge_module_data(): from blenderbim.bim import modules - for module in modules.values(): - if not module: - continue + for name in modules.keys(): try: - getattr(getattr(module, "data"), "Data").purge() + getattr(getattr(getattr(ifcopenshell.api, name), "data"), "Data").purge() except AttributeError: pass @@ -101,6 +102,28 @@ def storeIdMap(scene): @persistent def setDefaultProperties(scene): + ifcopenshell.api.owner.settings.get_person = ( + lambda: IfcStore.get_file().by_id(int(bpy.context.scene.BIMOwnerProperties.user_person)) + if bpy.context.scene.BIMOwnerProperties.user_person + else None + ) + ifcopenshell.api.owner.settings.get_organisation = ( + lambda: IfcStore.get_file().by_id(int(bpy.context.scene.BIMOwnerProperties.user_organisation)) + if bpy.context.scene.BIMOwnerProperties.user_organisation + else None + ) + ifcopenshell.api.owner.settings.settings["ApplicationIdentifier"] = "BlenderBIM" + ifcopenshell.api.owner.settings.settings["ApplicationFullName"] = "BlenderBIM Add-on" + ifcopenshell.api.owner.settings.settings["Version"] = ".".join( + [ + str(x) + for x in [ + addon.bl_info.get("version", (-1, -1, -1)) + for addon in addon_utils.modules() + if addon.bl_info["name"] == "BlenderBIM" + ][0] + ] + ) if len(bpy.context.scene.DocProperties.drawing_styles) == 0: drawing_style = bpy.context.scene.DocProperties.drawing_styles.add() drawing_style.name = "Technical" diff --git a/src/ifcblenderexport/blenderbim/bim/module/owner/prop.py b/src/ifcblenderexport/blenderbim/bim/module/owner/prop.py index 63333bb551..a92a6488fe 100644 --- a/src/ifcblenderexport/blenderbim/bim/module/owner/prop.py +++ b/src/ifcblenderexport/blenderbim/bim/module/owner/prop.py @@ -1,5 +1,6 @@ import bpy from blenderbim.bim.prop import StrProperty, Attribute +from blenderbim.bim.ifc import IfcStore from ifcopenshell.api.owner.data import Data from bpy.types import PropertyGroup from bpy.props import ( diff --git a/src/ifcblenderexport/blenderbim/bim/prop.py b/src/ifcblenderexport/blenderbim/bim/prop.py index 4fd5c35797..4c5b493919 100644 --- a/src/ifcblenderexport/blenderbim/bim/prop.py +++ b/src/ifcblenderexport/blenderbim/bim/prop.py @@ -9,6 +9,7 @@ from . import ifc from . import annotation from . import decoration import bpy +from blenderbim.bim.handler import purge_module_data from blenderbim.bim.ifc import IfcStore from bpy.types import PropertyGroup from bpy.props import ( @@ -38,16 +39,7 @@ def updateIfcFile(self, context): if context.scene.BIMProperties.ifc_file: IfcStore.file = None IfcStore.schema = None - # Purge data cache - from blenderbim.bim import modules - - for module in modules.values(): - if not module: - continue - try: - getattr(getattr(module, "data"), "Data").purge() - except AttributeError: - pass + purge_module_data() def getDiagramScales(self, context): diff --git a/src/ifcopenshell-python/ifcopenshell/api/owner/create_owner_history.py b/src/ifcopenshell-python/ifcopenshell/api/owner/create_owner_history.py index bd1c7585b2..eff35c5e87 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/owner/create_owner_history.py +++ b/src/ifcopenshell-python/ifcopenshell/api/owner/create_owner_history.py @@ -11,6 +11,8 @@ class Usecase: self.settings[key] = value def execute(self): + self.settings["person"] = ifcopenshell.api.owner.settings.get_person() + self.settings["organisation"] = ifcopenshell.api.owner.settings.get_organisation() if self.file.schema != "IFC2X3": if not self.settings["person"] or not self.settings["organisation"]: return @@ -22,7 +24,7 @@ class Usecase: "OwningUser": user, "OwningApplication": application, "State": "READWRITE", - "ChangeAction": self.settings["ChangeAction"] or "ADDED", + "ChangeAction": "ADDED", "LastModifiedDate": int(time.time()), "LastModifyingUser": user, "LastModifyingApplication": application, diff --git a/src/ifcopenshell-python/ifcopenshell/api/owner/settings.py b/src/ifcopenshell-python/ifcopenshell/api/owner/settings.py index 20c310efbf..d83e9ee372 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/owner/settings.py +++ b/src/ifcopenshell-python/ifcopenshell/api/owner/settings.py @@ -1,33 +1,13 @@ -# import bpy -# import addon_utils +def get_person(): + pass + + +def get_organisation(): + pass + settings = { - "person": None, - "organisation": None, "ApplicationIdentifier": "", "ApplicationFullName": "", "Version": "", - "ChangeAction": "NOTDEFINED", } - - -# settings = { -# "person": file.by_id(int(bpy.context.scene.BIMOwnerProperties.user_person)), -# "organisation": file.by_id(int(bpy.context.scene.BIMOwnerProperties.user_organisation)), -# "ApplicationIdentifier": "BlenderBIM", -# "ApplicationFullName": "BlenderBIM Add-on", -# "Version": get_application_version(), -# } -# -# -# def get_application_version(): -# return ".".join( -# [ -# str(x) -# for x in [ -# addon.bl_info.get("version", (-1, -1, -1)) -# for addon in addon_utils.modules() -# if addon.bl_info["name"] == "BlenderBIM" -# ][0] -# ] -# ) diff --git a/src/ifcopenshell-python/ifcopenshell/api/owner/update_owner_history.py b/src/ifcopenshell-python/ifcopenshell/api/owner/update_owner_history.py index 603014aa45..9e15a4ab50 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/owner/update_owner_history.py +++ b/src/ifcopenshell-python/ifcopenshell/api/owner/update_owner_history.py @@ -11,9 +11,11 @@ class Usecase: self.settings[key] = value def execute(self): + self.settings["person"] = ifcopenshell.api.owner.settings.get_person() + self.settings["organisation"] = ifcopenshell.api.owner.settings.get_organisation() if not self.settings["element"].OwnerHistory: self.settings["element"].OwnerHistory = create_owner_history.Usecase(self.file, self.settings).execute() - return + return self.settings["element"].OwnerHistory if len(self.file.get_inverse(self.settings["element"].OwnerHistory)) > 1: old_history = self.settings["element"].OwnerHistory self.settings["element"].OwnerHistory = self.file.create_entity("IfcOwnerHistory") @@ -21,11 +23,11 @@ class Usecase: self.settings["element"].OwnerHistory[i] = attribute user = self.get_user() application = self.get_application() - self.settings["element"].OwnerHistory.ChangeAction = self.settings["ChangeAction"] + self.settings["element"].OwnerHistory.ChangeAction = "MODIFIED" self.settings["element"].OwnerHistory.LastModifiedDate = int(time.time()) self.settings["element"].OwnerHistory.LastModifyingUser = user self.settings["element"].OwnerHistory.LastModifyingApplication = application - return self.settings["OwnerHistory"] + return self.settings["element"].OwnerHistory def get_user(self): for element in self.file.by_type("IfcPersonAndOrganization"):