mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 06:39:13 +00:00
WIP fix IFC2X3 errors in classification refactor
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import ifcopenshell.util.schema
|
import ifcopenshell.util.schema
|
||||||
|
import ifcopenshell.util.date
|
||||||
|
|
||||||
class Usecase:
|
class Usecase:
|
||||||
def __init__(self, file, settings=None):
|
def __init__(self, file, settings=None):
|
||||||
@@ -11,8 +12,20 @@ class Usecase:
|
|||||||
self.settings[key] = value
|
self.settings[key] = value
|
||||||
|
|
||||||
def execute(self):
|
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()
|
migrator = ifcopenshell.util.schema.Migrator()
|
||||||
result = migrator.migrate(self.settings["classification"], self.file)
|
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", **{
|
self.file.create_entity("IfcRelAssociatesClassification", **{
|
||||||
"GlobalId": ifcopenshell.guid.new(),
|
"GlobalId": ifcopenshell.guid.new(),
|
||||||
"RelatedObjects": [self.file.by_type("IfcProject")[0]],
|
"RelatedObjects": [self.file.by_type("IfcProject")[0]],
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import ifcopenshell.util.schema
|
import ifcopenshell.util.schema
|
||||||
|
|
||||||
|
|
||||||
class Usecase:
|
class Usecase:
|
||||||
def __init__(self, file, settings=None):
|
def __init__(self, file, settings=None):
|
||||||
self.file = file
|
self.file = file
|
||||||
@@ -14,13 +15,19 @@ class Usecase:
|
|||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
relating_classification = None
|
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"):
|
for reference in self.file.by_type("IfcClassificationReference"):
|
||||||
if self.file.schema == "IFC2X3":
|
if self.file.schema == "IFC2X3":
|
||||||
if reference.ItemReference == self.settings["reference"].ItemReference:
|
if reference.ItemReference == identification:
|
||||||
relating_classification = reference
|
relating_classification = reference
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
if reference.Identification == self.settings["reference"].Identification:
|
if reference.Identification == identification:
|
||||||
relating_classification = reference
|
relating_classification = reference
|
||||||
break
|
break
|
||||||
|
|
||||||
@@ -38,16 +45,19 @@ class Usecase:
|
|||||||
relating_classification = migrator.migrate(self.settings["reference"], self.file)
|
relating_classification = migrator.migrate(self.settings["reference"], self.file)
|
||||||
relating_classification.ReferencedSource = self.settings["classification"]
|
relating_classification.ReferencedSource = self.settings["classification"]
|
||||||
self.settings["reference"].ReferencedSource = old_referenced_source
|
self.settings["reference"].ReferencedSource = old_referenced_source
|
||||||
self.file.create_entity("IfcRelAssociatesClassification", **{
|
self.file.create_entity(
|
||||||
"GlobalId": ifcopenshell.guid.new(),
|
"IfcRelAssociatesClassification",
|
||||||
"RelatedObjects": [self.settings["product"]],
|
**{
|
||||||
"RelatingClassification": relating_classification
|
"GlobalId": ifcopenshell.guid.new(),
|
||||||
})
|
"RelatedObjects": [self.settings["product"]],
|
||||||
|
"RelatingClassification": relating_classification,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
def get_association(self, reference):
|
def get_association(self, reference):
|
||||||
if self.file.schema == "IFC2X3":
|
if self.file.schema == "IFC2X3":
|
||||||
for association in self.file.by_type("IfcRelAssociatesClassification"):
|
for association in self.file.by_type("IfcRelAssociatesClassification"):
|
||||||
if relating_classification == reference:
|
if association.RelatingClassification == reference:
|
||||||
return association
|
return association
|
||||||
elif reference.ClassificationRefForObjects:
|
elif reference.ClassificationRefForObjects:
|
||||||
return reference.ClassificationRefForObjects[0]
|
return reference.ClassificationRefForObjects[0]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
|
import ifcopenshell.util.date
|
||||||
from blenderbim.bim.ifc import IfcStore
|
from blenderbim.bim.ifc import IfcStore
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
|
|
||||||
class Data:
|
class Data:
|
||||||
@@ -39,11 +39,7 @@ class Data:
|
|||||||
for classification in cls._file.by_type("IfcClassification"):
|
for classification in cls._file.by_type("IfcClassification"):
|
||||||
data = classification.get_info()
|
data = classification.get_info()
|
||||||
if cls._file.schema == "IFC2X3" and data["EditionDate"]:
|
if cls._file.schema == "IFC2X3" and data["EditionDate"]:
|
||||||
data["EditionDate"] = datetime(
|
data["EditionDate"] = ifcopenshell.util.date(data.EditionDate).isoformat()
|
||||||
classification.EditionDate.YearComponent,
|
|
||||||
classification.EditionDate.MonthComponent,
|
|
||||||
classification.EditionDate.DayComponent,
|
|
||||||
).isoformat()
|
|
||||||
cls.classifications[classification.id()] = data
|
cls.classifications[classification.id()] = data
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
import ifcopenshell.util.schema
|
|
||||||
|
|
||||||
|
|
||||||
class Usecase:
|
class Usecase:
|
||||||
def __init__(self, file, settings=None):
|
def __init__(self, file, settings=None):
|
||||||
self.file = file
|
self.file = file
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ def ifc2datetime(element):
|
|||||||
|
|
||||||
|
|
||||||
def datetime2ifc(dt, ifc_type):
|
def datetime2ifc(dt, ifc_type):
|
||||||
|
if isinstance(dt, str):
|
||||||
|
dt = datetime.fromisoformat(dt)
|
||||||
if ifc_type == "IfcTimeStamp":
|
if ifc_type == "IfcTimeStamp":
|
||||||
return int(dt.timestamp())
|
return int(dt.timestamp())
|
||||||
elif ifc_type == "IfcDateTime":
|
elif ifc_type == "IfcDateTime":
|
||||||
|
|||||||
Reference in New Issue
Block a user