mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
First attempt at ripping out agnostic code into ifcopenshell.api namespace. See #1399.
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import ifcopenshell
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file, settings={}):
|
||||
self.file = file
|
||||
self.settings = {}
|
||||
for key, value in settings.items():
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
id_attribute = "DocumentId" if self.file.schema == "IFC2X3" else "Identification"
|
||||
return self.file.create_entity("IfcDocumentInformation", **{
|
||||
id_attribute: ifcopenshell.guid.new(),
|
||||
"Name": "Unnamed"
|
||||
})
|
||||
@@ -0,0 +1,14 @@
|
||||
import ifcopenshell
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file, settings={}):
|
||||
self.file = file
|
||||
self.settings = {}
|
||||
for key, value in settings.items():
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
id_attribute = "ItemReference" if self.file.schema == "IFC2X3" else "Identification"
|
||||
return self.file.create_entity("IfcDocumentReference", **{
|
||||
id_attribute: ifcopenshell.guid.new()
|
||||
})
|
||||
@@ -0,0 +1,41 @@
|
||||
import ifcopenshell
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file, settings=None):
|
||||
self.file = file
|
||||
self.settings = {
|
||||
"product": None,
|
||||
"document": None,
|
||||
}
|
||||
for key, value in settings.items():
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
rel = self.get_document_rel()
|
||||
related_objects = set(rel.RelatedObjects) if rel.RelatedObjects else set()
|
||||
related_objects.add(self.settings["product"])
|
||||
rel.RelatedObjects = list(related_objects)
|
||||
|
||||
def get_document_rel(self):
|
||||
if self.file.schema == "IFC2X3":
|
||||
for rel in self.file.by_type("IfcRelAssociatesDocument"):
|
||||
if rel.RelatingDocument == self.settings["document"]:
|
||||
return rel
|
||||
else:
|
||||
if (
|
||||
hasattr(self.settings["document"], "DocumentRefForObjects")
|
||||
and self.settings["document"].DocumentRefForObjects
|
||||
):
|
||||
return self.settings["document"].DocumentRefForObjects[0]
|
||||
elif (
|
||||
hasattr(self.settings["document"], "DocumentInfoForObjects")
|
||||
and self.settings["document"].DocumentInfoForObjects
|
||||
):
|
||||
return self.settings["document"].DocumentInfoForObjects[0]
|
||||
|
||||
return self.file.create_entity("IfcRelAssociatesDocument", **{
|
||||
"GlobalId": ifcopenshell.guid.new(),
|
||||
# TODO: owner history
|
||||
"RelatingDocument": self.settings["document"]
|
||||
})
|
||||
@@ -0,0 +1,65 @@
|
||||
import ifcopenshell
|
||||
import ifcopenshell.util.date
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
class Data:
|
||||
is_loaded = False
|
||||
products = {}
|
||||
references = {}
|
||||
information = {}
|
||||
|
||||
@classmethod
|
||||
def purge(cls):
|
||||
cls.is_loaded = False
|
||||
cls.products = {}
|
||||
cls.references = {}
|
||||
cls.information = {}
|
||||
|
||||
@classmethod
|
||||
def load(cls, file, product_id=None):
|
||||
cls._file = file
|
||||
if not cls._file:
|
||||
return
|
||||
if product_id:
|
||||
return cls.load_product(product_id)
|
||||
cls.load_references()
|
||||
cls.load_information()
|
||||
cls.is_loaded = True
|
||||
|
||||
@classmethod
|
||||
def load_product(cls, product_id):
|
||||
product = cls._file.by_id(product_id)
|
||||
cls.products[product_id] = []
|
||||
if not product.HasAssociations:
|
||||
return
|
||||
for association in product.HasAssociations:
|
||||
if association.is_a("IfcRelAssociatesDocument"):
|
||||
cls.products[product_id].append(association.RelatingDocument.id())
|
||||
|
||||
@classmethod
|
||||
def load_information(cls):
|
||||
cls.information = {}
|
||||
for information in cls._file.by_type("IfcDocumentInformation"):
|
||||
data = information.get_info()
|
||||
if cls._file.schema == "IFC2X3":
|
||||
for attribute in ["CreationTime", "LastRevisionTime", "ValidFrom", "ValidUntil"]:
|
||||
if data[attribute]:
|
||||
data[attribute] = ifcopenshell.util.date.ifc2datetime(data[attribute]).isoformat()
|
||||
if data["ElectronicFormat"]:
|
||||
data["ElectronicFormat"] = "{}/{}".format(
|
||||
information.ElectronicFormat.MimeContentType, information.ElectronicFormat.MimeSubtype
|
||||
)
|
||||
cls.information[information.id()] = data
|
||||
|
||||
@classmethod
|
||||
def load_references(cls):
|
||||
cls.references = {}
|
||||
for reference in cls._file.by_type("IfcDocumentReference"):
|
||||
data = reference.get_info()
|
||||
if cls._file.schema == "IFC2X3":
|
||||
if reference.ReferenceToDocument:
|
||||
data["ReferencedDocument"] = reference.ReferenceToDocument[0].id()
|
||||
elif reference.ReferencedDocument:
|
||||
data["ReferencedDocument"] = reference.ReferencedDocument.id()
|
||||
cls.references[reference.id()] = data
|
||||
@@ -0,0 +1,13 @@
|
||||
class Usecase:
|
||||
def __init__(self, file, settings=None):
|
||||
self.file = file
|
||||
self.settings = {
|
||||
"information": None,
|
||||
"attributes": {}
|
||||
}
|
||||
for key, value in settings.items():
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
for name, value in self.settings["attributes"].items():
|
||||
setattr(self.settings["information"], name, value)
|
||||
@@ -0,0 +1,13 @@
|
||||
class Usecase:
|
||||
def __init__(self, file, settings=None):
|
||||
self.file = file
|
||||
self.settings = {
|
||||
"reference": None,
|
||||
"attributes": {}
|
||||
}
|
||||
for key, value in settings.items():
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
for name, value in self.settings["attributes"].items():
|
||||
setattr(self.settings["reference"], name, value)
|
||||
@@ -0,0 +1,12 @@
|
||||
class Usecase:
|
||||
def __init__(self, file, settings=None):
|
||||
self.file = file
|
||||
self.settings = {"document": None}
|
||||
for key, value in settings.items():
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
self.file.remove(self.settings["document"])
|
||||
for rel in self.file.by_type("IfcRelAssociatesDocument"):
|
||||
if not rel.RelatingDocument:
|
||||
self.file.remove(rel)
|
||||
@@ -0,0 +1,17 @@
|
||||
import ifcopenshell
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file, settings=None):
|
||||
self.file = file
|
||||
self.settings = {
|
||||
"product": None,
|
||||
"document": None,
|
||||
}
|
||||
for key, value in settings.items():
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
for rel in self.settings["product"].HasAssociations:
|
||||
if rel.is_a("IfcRelAssociatesDocument") and rel.RelatingDocument == self.settings["document"]:
|
||||
self.file.remove(rel)
|
||||
Reference in New Issue
Block a user