Finish decoupling ownership history code from Blender

This commit is contained in:
Dion Moult
2021-03-29 16:53:11 +11:00
parent f1ffb81c86
commit 44df1f676d
4 changed files with 84 additions and 139 deletions
+72 -14
View File
@@ -100,21 +100,24 @@ def storeIdMap(scene):
bpy.context.scene.BIMProperties.guid_map = json.dumps({k: v.name for k, v in IfcStore.guid_map.items()})
@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
def get_application(ifc):
version = get_application_version()
for element in ifc.by_type("IfcApplication"):
if element.ApplicationIdentifier == "BlenderBIM" and element.Version == version:
return element
return ifc.create_entity(
"IfcApplication",
**{
"ApplicationDeveloper": create_application_organisation(ifc),
"Version": get_application_version(),
"ApplicationFullName": "BlenderBIM Add-on",
"ApplicationIdentifier": "BlenderBIM",
},
)
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(
def get_application_version():
return ".".join(
[
str(x)
for x in [
@@ -124,6 +127,61 @@ def setDefaultProperties(scene):
][0]
]
)
def create_application_organisation(ifc):
return ifc.create_entity(
"IfcOrganization",
**{
"Name": "IfcOpenShell",
"Description": "IfcOpenShell is an open source (LGPL) software library that helps users and software developers to work with the IFC file format.",
"Roles": [ifc.create_entity("IfcActorRole", **{"Role": "USERDEFINED", "UserDefinedRole": "CONTRIBUTOR"})],
"Addresses": [
ifc.create_entity(
"IfcTelecomAddress",
**{
"Purpose": "USERDEFINED",
"UserDefinedPurpose": "WEBPAGE",
"Description": "The main webpage of the software collection.",
"WWWHomePageURL": "https://ifcopenshell.org",
},
),
ifc.create_entity(
"IfcTelecomAddress",
**{
"Purpose": "USERDEFINED",
"UserDefinedPurpose": "WEBPAGE",
"Description": "The BlenderBIM Add-on webpage of the software collection.",
"WWWHomePageURL": "https://blenderbim.org",
},
),
ifc.create_entity(
"IfcTelecomAddress",
**{
"Purpose": "USERDEFINED",
"UserDefinedPurpose": "REPOSITORY",
"Description": "The source code repository of the software collection.",
"WWWHomePageURL": "https://github.com/IfcOpenShell/IfcOpenShell.git",
},
),
],
},
)
@persistent
def setDefaultProperties(scene):
ifcopenshell.api.owner.settings.get_person = (
lambda ifc : ifc.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 ifc : ifc.by_id(int(bpy.context.scene.BIMOwnerProperties.user_organisation))
if bpy.context.scene.BIMOwnerProperties.user_organisation
else None
)
ifcopenshell.api.owner.settings.get_application = get_application
if len(bpy.context.scene.DocProperties.drawing_styles) == 0:
drawing_style = bpy.context.scene.DocProperties.drawing_styles.add()
drawing_style.name = "Technical"
@@ -6,18 +6,18 @@ import ifcopenshell.api.owner.settings
class Usecase:
def __init__(self, file, **settings):
self.file = file
self.settings = ifcopenshell.api.owner.settings.settings
self.settings = {}
for key, value in settings.items():
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()
self.settings["person"] = ifcopenshell.api.owner.settings.get_person(self.file)
self.settings["organisation"] = ifcopenshell.api.owner.settings.get_organisation(self.file)
if self.file.schema != "IFC2X3":
if not self.settings["person"] or not self.settings["organisation"]:
return
user = self.get_user()
application = self.get_application()
application = ifcopenshell.api.owner.settings.get_application(self.file)
return self.file.create_entity(
"IfcOwnerHistory",
**{
@@ -43,58 +43,3 @@ class Usecase:
"IfcPersonAndOrganization",
**{"ThePerson": self.settings["person"], "TheOrganization": self.settings["organisation"]},
)
def get_application(self):
for element in self.file.by_type("IfcApplication"):
if element.ApplicationIdentifier == self.settings["ApplicationIdentifier"]:
return element
return self.file.create_entity(
"IfcApplication",
**{
"ApplicationDeveloper": self.get_application_organisation(),
"Version": self.settings["Version"],
"ApplicationFullName": self.settings["ApplicationFullName"],
"ApplicationIdentifier": self.settings["ApplicationIdentifier"],
},
)
def get_application_organisation(self):
return self.file.create_entity(
"IfcOrganization",
**{
"Name": "IfcOpenShell",
"Description": "IfcOpenShell is an open source (LGPL) software library that helps users and software developers to work with the IFC file format.",
"Roles": [
self.file.create_entity("IfcActorRole", **{"Role": "USERDEFINED", "UserDefinedRole": "CONTRIBUTOR"})
],
"Addresses": [
self.file.create_entity(
"IfcTelecomAddress",
**{
"Purpose": "USERDEFINED",
"UserDefinedPurpose": "WEBPAGE",
"Description": "The main webpage of the software collection.",
"WWWHomePageURL": "https://ifcopenshell.org",
},
),
self.file.create_entity(
"IfcTelecomAddress",
**{
"Purpose": "USERDEFINED",
"UserDefinedPurpose": "WEBPAGE",
"Description": "The BlenderBIM Add-on webpage of the software collection.",
"WWWHomePageURL": "https://blenderbim.org",
},
),
self.file.create_entity(
"IfcTelecomAddress",
**{
"Purpose": "USERDEFINED",
"UserDefinedPurpose": "REPOSITORY",
"Description": "The source code repository of the software collection.",
"WWWHomePageURL": "https://github.com/IfcOpenShell/IfcOpenShell.git",
},
),
],
},
)
@@ -1,13 +1,10 @@
def get_person():
def get_person(ifc):
pass
def get_organisation():
def get_organisation(ifc):
pass
settings = {
"ApplicationIdentifier": "",
"ApplicationFullName": "",
"Version": "",
}
def get_application(ifc):
pass
@@ -6,13 +6,13 @@ import ifcopenshell.api
class Usecase:
def __init__(self, file, **settings):
self.file = file
self.settings = ifcopenshell.api.owner.settings.settings
self.settings = {}
for key, value in settings.items():
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()
self.settings["person"] = ifcopenshell.api.owner.settings.get_person(self.file)
self.settings["organisation"] = ifcopenshell.api.owner.settings.get_organisation(self.file)
if not self.settings["element"].OwnerHistory:
self.settings["element"].OwnerHistory = ifcopenshell.api.run(
"owner.create_owner_history", self.file, **self.settings
@@ -24,7 +24,7 @@ class Usecase:
for i, attribute in enumerate(old_history):
self.settings["element"].OwnerHistory[i] = attribute
user = self.get_user()
application = self.get_application()
application = ifcopenshell.api.owner.settings.get_application(self.file)
self.settings["element"].OwnerHistory.ChangeAction = "MODIFIED"
self.settings["element"].OwnerHistory.LastModifiedDate = int(time.time())
self.settings["element"].OwnerHistory.LastModifyingUser = user
@@ -42,58 +42,3 @@ class Usecase:
"IfcPersonAndOrganization",
**{"ThePerson": self.settings["person"], "TheOrganization": self.settings["organisation"]},
)
def get_application(self):
for element in self.file.by_type("IfcApplication"):
if element.ApplicationIdentifier == self.settings["ApplicationIdentifier"]:
return element
return self.file.create_entity(
"IfcApplication",
**{
"ApplicationDeveloper": self.get_application_organisation(),
"Version": self.settings["Version"],
"ApplicationFullName": self.settings["ApplicationFullName"],
"ApplicationIdentifier": self.settings["ApplicationIdentifier"],
},
)
def get_application_organisation(self):
return self.file.create_entity(
"IfcOrganization",
**{
"Name": "IfcOpenShell",
"Description": "IfcOpenShell is an open source (LGPL) software library that helps users and software developers to work with the IFC file format.",
"Roles": [
self.file.create_entity("IfcActorRole", **{"Role": "USERDEFINED", "UserDefinedRole": "CONTRIBUTOR"})
],
"Addresses": [
self.file.create_entity(
"IfcTelecomAddress",
**{
"Purpose": "USERDEFINED",
"UserDefinedPurpose": "WEBPAGE",
"Description": "The main webpage of the software collection.",
"WWWHomePageURL": "https://ifcopenshell.org",
},
),
self.file.create_entity(
"IfcTelecomAddress",
**{
"Purpose": "USERDEFINED",
"UserDefinedPurpose": "WEBPAGE",
"Description": "The BlenderBIM Add-on webpage of the software collection.",
"WWWHomePageURL": "https://blenderbim.org",
},
),
self.file.create_entity(
"IfcTelecomAddress",
**{
"Purpose": "USERDEFINED",
"UserDefinedPurpose": "REPOSITORY",
"Description": "The source code repository of the software collection.",
"WWWHomePageURL": "https://github.com/IfcOpenShell/IfcOpenShell.git",
},
),
],
},
)