2021-01-26 13:56:38 +11:00
|
|
|
import time
|
|
|
|
|
import ifcopenshell
|
2021-03-25 11:42:12 +11:00
|
|
|
import ifcopenshell.api.owner.settings
|
2021-01-26 13:56:38 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class Usecase:
|
2021-03-27 19:14:32 +11:00
|
|
|
def __init__(self, file, **settings):
|
2021-01-26 13:56:38 +11:00
|
|
|
self.file = file
|
2021-03-29 16:53:11 +11:00
|
|
|
self.settings = {}
|
2021-01-26 13:56:38 +11:00
|
|
|
for key, value in settings.items():
|
|
|
|
|
self.settings[key] = value
|
|
|
|
|
|
|
|
|
|
def execute(self):
|
2021-03-29 16:53:11 +11:00
|
|
|
self.settings["person"] = ifcopenshell.api.owner.settings.get_person(self.file)
|
|
|
|
|
self.settings["organisation"] = ifcopenshell.api.owner.settings.get_organisation(self.file)
|
2021-03-25 11:42:12 +11:00
|
|
|
if self.file.schema != "IFC2X3":
|
|
|
|
|
if not self.settings["person"] or not self.settings["organisation"]:
|
|
|
|
|
return
|
2021-01-26 13:56:38 +11:00
|
|
|
user = self.get_user()
|
2021-03-29 16:53:11 +11:00
|
|
|
application = ifcopenshell.api.owner.settings.get_application(self.file)
|
2021-01-26 13:56:38 +11:00
|
|
|
return self.file.create_entity(
|
|
|
|
|
"IfcOwnerHistory",
|
|
|
|
|
**{
|
|
|
|
|
"OwningUser": user,
|
|
|
|
|
"OwningApplication": application,
|
|
|
|
|
"State": "READWRITE",
|
2021-03-25 16:32:43 +11:00
|
|
|
"ChangeAction": "ADDED",
|
2021-01-26 13:56:38 +11:00
|
|
|
"LastModifiedDate": int(time.time()),
|
|
|
|
|
"LastModifyingUser": user,
|
|
|
|
|
"LastModifyingApplication": application,
|
|
|
|
|
"CreationDate": int(time.time()),
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def get_user(self):
|
|
|
|
|
for element in self.file.by_type("IfcPersonAndOrganization"):
|
|
|
|
|
if (
|
|
|
|
|
element.ThePerson == self.settings["person"]
|
|
|
|
|
and element.TheOrganization == self.settings["organisation"]
|
|
|
|
|
):
|
|
|
|
|
return element
|
|
|
|
|
return self.file.create_entity(
|
|
|
|
|
"IfcPersonAndOrganization",
|
|
|
|
|
**{"ThePerson": self.settings["person"], "TheOrganization": self.settings["organisation"]},
|
|
|
|
|
)
|