mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 14:41:25 +00:00
Still cleaning up related to ownership histories. See #1399.
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
import bpy
|
import bpy
|
||||||
import json
|
import json
|
||||||
|
import addon_utils
|
||||||
import blenderbim.bim.decoration as decoration
|
import blenderbim.bim.decoration as decoration
|
||||||
|
import ifcopenshell.api.owner.settings
|
||||||
from bpy.app.handlers import persistent
|
from bpy.app.handlers import persistent
|
||||||
from blenderbim.bim.ifc import IfcStore
|
from blenderbim.bim.ifc import IfcStore
|
||||||
from ifcopenshell.api.attribute.data import Data as AttributeData
|
from ifcopenshell.api.attribute.data import Data as AttributeData
|
||||||
@@ -46,14 +48,13 @@ def subscribe_to(object, data_path, callback):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def purge_module_data():
|
def purge_module_data():
|
||||||
from blenderbim.bim import modules
|
from blenderbim.bim import modules
|
||||||
|
|
||||||
for module in modules.values():
|
for name in modules.keys():
|
||||||
if not module:
|
|
||||||
continue
|
|
||||||
try:
|
try:
|
||||||
getattr(getattr(module, "data"), "Data").purge()
|
getattr(getattr(getattr(ifcopenshell.api, name), "data"), "Data").purge()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -101,6 +102,28 @@ def storeIdMap(scene):
|
|||||||
|
|
||||||
@persistent
|
@persistent
|
||||||
def setDefaultProperties(scene):
|
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:
|
if len(bpy.context.scene.DocProperties.drawing_styles) == 0:
|
||||||
drawing_style = bpy.context.scene.DocProperties.drawing_styles.add()
|
drawing_style = bpy.context.scene.DocProperties.drawing_styles.add()
|
||||||
drawing_style.name = "Technical"
|
drawing_style.name = "Technical"
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import bpy
|
import bpy
|
||||||
from blenderbim.bim.prop import StrProperty, Attribute
|
from blenderbim.bim.prop import StrProperty, Attribute
|
||||||
|
from blenderbim.bim.ifc import IfcStore
|
||||||
from ifcopenshell.api.owner.data import Data
|
from ifcopenshell.api.owner.data import Data
|
||||||
from bpy.types import PropertyGroup
|
from bpy.types import PropertyGroup
|
||||||
from bpy.props import (
|
from bpy.props import (
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from . import ifc
|
|||||||
from . import annotation
|
from . import annotation
|
||||||
from . import decoration
|
from . import decoration
|
||||||
import bpy
|
import bpy
|
||||||
|
from blenderbim.bim.handler import purge_module_data
|
||||||
from blenderbim.bim.ifc import IfcStore
|
from blenderbim.bim.ifc import IfcStore
|
||||||
from bpy.types import PropertyGroup
|
from bpy.types import PropertyGroup
|
||||||
from bpy.props import (
|
from bpy.props import (
|
||||||
@@ -38,16 +39,7 @@ def updateIfcFile(self, context):
|
|||||||
if context.scene.BIMProperties.ifc_file:
|
if context.scene.BIMProperties.ifc_file:
|
||||||
IfcStore.file = None
|
IfcStore.file = None
|
||||||
IfcStore.schema = None
|
IfcStore.schema = None
|
||||||
# Purge data cache
|
purge_module_data()
|
||||||
from blenderbim.bim import modules
|
|
||||||
|
|
||||||
for module in modules.values():
|
|
||||||
if not module:
|
|
||||||
continue
|
|
||||||
try:
|
|
||||||
getattr(getattr(module, "data"), "Data").purge()
|
|
||||||
except AttributeError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def getDiagramScales(self, context):
|
def getDiagramScales(self, context):
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ class Usecase:
|
|||||||
self.settings[key] = value
|
self.settings[key] = value
|
||||||
|
|
||||||
def execute(self):
|
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 self.file.schema != "IFC2X3":
|
||||||
if not self.settings["person"] or not self.settings["organisation"]:
|
if not self.settings["person"] or not self.settings["organisation"]:
|
||||||
return
|
return
|
||||||
@@ -22,7 +24,7 @@ class Usecase:
|
|||||||
"OwningUser": user,
|
"OwningUser": user,
|
||||||
"OwningApplication": application,
|
"OwningApplication": application,
|
||||||
"State": "READWRITE",
|
"State": "READWRITE",
|
||||||
"ChangeAction": self.settings["ChangeAction"] or "ADDED",
|
"ChangeAction": "ADDED",
|
||||||
"LastModifiedDate": int(time.time()),
|
"LastModifiedDate": int(time.time()),
|
||||||
"LastModifyingUser": user,
|
"LastModifyingUser": user,
|
||||||
"LastModifyingApplication": application,
|
"LastModifyingApplication": application,
|
||||||
|
|||||||
@@ -1,33 +1,13 @@
|
|||||||
# import bpy
|
def get_person():
|
||||||
# import addon_utils
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def get_organisation():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
settings = {
|
settings = {
|
||||||
"person": None,
|
|
||||||
"organisation": None,
|
|
||||||
"ApplicationIdentifier": "",
|
"ApplicationIdentifier": "",
|
||||||
"ApplicationFullName": "",
|
"ApplicationFullName": "",
|
||||||
"Version": "",
|
"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]
|
|
||||||
# ]
|
|
||||||
# )
|
|
||||||
|
|||||||
@@ -11,9 +11,11 @@ class Usecase:
|
|||||||
self.settings[key] = value
|
self.settings[key] = value
|
||||||
|
|
||||||
def execute(self):
|
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:
|
if not self.settings["element"].OwnerHistory:
|
||||||
self.settings["element"].OwnerHistory = create_owner_history.Usecase(self.file, self.settings).execute()
|
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:
|
if len(self.file.get_inverse(self.settings["element"].OwnerHistory)) > 1:
|
||||||
old_history = self.settings["element"].OwnerHistory
|
old_history = self.settings["element"].OwnerHistory
|
||||||
self.settings["element"].OwnerHistory = self.file.create_entity("IfcOwnerHistory")
|
self.settings["element"].OwnerHistory = self.file.create_entity("IfcOwnerHistory")
|
||||||
@@ -21,11 +23,11 @@ class Usecase:
|
|||||||
self.settings["element"].OwnerHistory[i] = attribute
|
self.settings["element"].OwnerHistory[i] = attribute
|
||||||
user = self.get_user()
|
user = self.get_user()
|
||||||
application = self.get_application()
|
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.LastModifiedDate = int(time.time())
|
||||||
self.settings["element"].OwnerHistory.LastModifyingUser = user
|
self.settings["element"].OwnerHistory.LastModifyingUser = user
|
||||||
self.settings["element"].OwnerHistory.LastModifyingApplication = application
|
self.settings["element"].OwnerHistory.LastModifyingApplication = application
|
||||||
return self.settings["OwnerHistory"]
|
return self.settings["element"].OwnerHistory
|
||||||
|
|
||||||
def get_user(self):
|
def get_user(self):
|
||||||
for element in self.file.by_type("IfcPersonAndOrganization"):
|
for element in self.file.by_type("IfcPersonAndOrganization"):
|
||||||
|
|||||||
Reference in New Issue
Block a user