WIP fix IFC2X3 errors in classification refactor

This commit is contained in:
Dion Moult
2021-01-22 16:55:38 +11:00
parent c67a99fb5d
commit 3bbdc3f277
5 changed files with 35 additions and 17 deletions
@@ -1,5 +1,6 @@
import ifcopenshell
import ifcopenshell.util.schema
import ifcopenshell.util.date
class Usecase:
def __init__(self, file, settings=None):
@@ -11,8 +12,20 @@ class Usecase:
self.settings[key] = value
def execute(self):
edition_date = None
if self.settings["classification"].EditionDate:
edition_date = ifcopenshell.util.date.ifc2datetime(self.settings["classification"].EditionDate)
self.settings["classification"].EditionDate = None
migrator = ifcopenshell.util.schema.Migrator()
result = migrator.migrate(self.settings["classification"], self.file)
# TODO: should auto date migration be part of the migrator?
if self.file.schema == "IFC2X3" and edition_date:
result.EditionDate = ifcopenshell.util.date.datetime2ifc(edition_date, "IfcCalendarDate")
else:
result.EditionDate = ifcopenshell.util.date.datetime2ifc(edition_date, "IfcDate")
self.file.create_entity("IfcRelAssociatesClassification", **{
"GlobalId": ifcopenshell.guid.new(),
"RelatedObjects": [self.file.by_type("IfcProject")[0]],
@@ -1,6 +1,7 @@
import ifcopenshell
import ifcopenshell.util.schema
class Usecase:
def __init__(self, file, settings=None):
self.file = file
@@ -14,13 +15,19 @@ class Usecase:
def execute(self):
relating_classification = None
if hasattr(self.settings["reference"], "ItemReference"):
identification = self.settings["reference"].ItemReference # IFC2X3
else:
identification = self.settings["reference"].Identification
for reference in self.file.by_type("IfcClassificationReference"):
if self.file.schema == "IFC2X3":
if reference.ItemReference == self.settings["reference"].ItemReference:
if reference.ItemReference == identification:
relating_classification = reference
break
else:
if reference.Identification == self.settings["reference"].Identification:
if reference.Identification == identification:
relating_classification = reference
break
@@ -38,16 +45,19 @@ class Usecase:
relating_classification = migrator.migrate(self.settings["reference"], self.file)
relating_classification.ReferencedSource = self.settings["classification"]
self.settings["reference"].ReferencedSource = old_referenced_source
self.file.create_entity("IfcRelAssociatesClassification", **{
"GlobalId": ifcopenshell.guid.new(),
"RelatedObjects": [self.settings["product"]],
"RelatingClassification": relating_classification
})
self.file.create_entity(
"IfcRelAssociatesClassification",
**{
"GlobalId": ifcopenshell.guid.new(),
"RelatedObjects": [self.settings["product"]],
"RelatingClassification": relating_classification,
}
)
def get_association(self, reference):
if self.file.schema == "IFC2X3":
for association in self.file.by_type("IfcRelAssociatesClassification"):
if relating_classification == reference:
if association.RelatingClassification == reference:
return association
elif reference.ClassificationRefForObjects:
return reference.ClassificationRefForObjects[0]
@@ -1,6 +1,6 @@
import ifcopenshell
import ifcopenshell.util.date
from blenderbim.bim.ifc import IfcStore
from datetime import datetime
class Data:
@@ -39,11 +39,7 @@ class Data:
for classification in cls._file.by_type("IfcClassification"):
data = classification.get_info()
if cls._file.schema == "IFC2X3" and data["EditionDate"]:
data["EditionDate"] = datetime(
classification.EditionDate.YearComponent,
classification.EditionDate.MonthComponent,
classification.EditionDate.DayComponent,
).isoformat()
data["EditionDate"] = ifcopenshell.util.date(data.EditionDate).isoformat()
cls.classifications[classification.id()] = data
@classmethod
@@ -1,6 +1,3 @@
import ifcopenshell.util.schema
class Usecase:
def __init__(self, file, settings=None):
self.file = file
@@ -35,6 +35,8 @@ def ifc2datetime(element):
def datetime2ifc(dt, ifc_type):
if isinstance(dt, str):
dt = datetime.fromisoformat(dt)
if ifc_type == "IfcTimeStamp":
return int(dt.timestamp())
elif ifc_type == "IfcDateTime":