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()}) bpy.context.scene.BIMProperties.guid_map = json.dumps({k: v.name for k, v in IfcStore.guid_map.items()})
@persistent def get_application(ifc):
def setDefaultProperties(scene): version = get_application_version()
ifcopenshell.api.owner.settings.get_person = ( for element in ifc.by_type("IfcApplication"):
lambda: IfcStore.get_file().by_id(int(bpy.context.scene.BIMOwnerProperties.user_person)) if element.ApplicationIdentifier == "BlenderBIM" and element.Version == version:
if bpy.context.scene.BIMOwnerProperties.user_person return element
else None 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 def get_application_version():
else None return ".".join(
)
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) str(x)
for x in [ for x in [
@@ -124,6 +127,61 @@ def setDefaultProperties(scene):
][0] ][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: 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"
@@ -6,18 +6,18 @@ import ifcopenshell.api.owner.settings
class Usecase: class Usecase:
def __init__(self, file, **settings): def __init__(self, file, **settings):
self.file = file self.file = file
self.settings = ifcopenshell.api.owner.settings.settings self.settings = {}
for key, value in settings.items(): for key, value in settings.items():
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["person"] = ifcopenshell.api.owner.settings.get_person(self.file)
self.settings["organisation"] = ifcopenshell.api.owner.settings.get_organisation() self.settings["organisation"] = ifcopenshell.api.owner.settings.get_organisation(self.file)
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
user = self.get_user() user = self.get_user()
application = self.get_application() application = ifcopenshell.api.owner.settings.get_application(self.file)
return self.file.create_entity( return self.file.create_entity(
"IfcOwnerHistory", "IfcOwnerHistory",
**{ **{
@@ -43,58 +43,3 @@ class Usecase:
"IfcPersonAndOrganization", "IfcPersonAndOrganization",
**{"ThePerson": self.settings["person"], "TheOrganization": self.settings["organisation"]}, **{"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 pass
def get_organisation(): def get_organisation(ifc):
pass pass
settings = { def get_application(ifc):
"ApplicationIdentifier": "", pass
"ApplicationFullName": "",
"Version": "",
}
@@ -6,13 +6,13 @@ import ifcopenshell.api
class Usecase: class Usecase:
def __init__(self, file, **settings): def __init__(self, file, **settings):
self.file = file self.file = file
self.settings = ifcopenshell.api.owner.settings.settings self.settings = {}
for key, value in settings.items(): for key, value in settings.items():
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["person"] = ifcopenshell.api.owner.settings.get_person(self.file)
self.settings["organisation"] = ifcopenshell.api.owner.settings.get_organisation() self.settings["organisation"] = ifcopenshell.api.owner.settings.get_organisation(self.file)
if not self.settings["element"].OwnerHistory: if not self.settings["element"].OwnerHistory:
self.settings["element"].OwnerHistory = ifcopenshell.api.run( self.settings["element"].OwnerHistory = ifcopenshell.api.run(
"owner.create_owner_history", self.file, **self.settings "owner.create_owner_history", self.file, **self.settings
@@ -24,7 +24,7 @@ class Usecase:
for i, attribute in enumerate(old_history): for i, attribute in enumerate(old_history):
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 = ifcopenshell.api.owner.settings.get_application(self.file)
self.settings["element"].OwnerHistory.ChangeAction = "MODIFIED" 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
@@ -42,58 +42,3 @@ class Usecase:
"IfcPersonAndOrganization", "IfcPersonAndOrganization",
**{"ThePerson": self.settings["person"], "TheOrganization": self.settings["organisation"]}, **{"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",
},
),
],
},
)