Skip to content

Commit 3bbdc3f

Browse files
committed
WIP fix IFC2X3 errors in classification refactor
1 parent c67a99f commit 3bbdc3f

File tree

5 files changed

+35
-17
lines changed

5 files changed

+35
-17
lines changed

src/ifcblenderexport/blenderbim/bim/module/classification/add_classification.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import ifcopenshell
22
import ifcopenshell.util.schema
3+
import ifcopenshell.util.date
34

45
class Usecase:
56
def __init__(self, file, settings=None):
@@ -11,8 +12,20 @@ def __init__(self, file, settings=None):
1112
self.settings[key] = value
1213

1314
def execute(self):
15+
edition_date = None
16+
if self.settings["classification"].EditionDate:
17+
edition_date = ifcopenshell.util.date.ifc2datetime(self.settings["classification"].EditionDate)
18+
self.settings["classification"].EditionDate = None
19+
1420
migrator = ifcopenshell.util.schema.Migrator()
1521
result = migrator.migrate(self.settings["classification"], self.file)
22+
23+
# TODO: should auto date migration be part of the migrator?
24+
if self.file.schema == "IFC2X3" and edition_date:
25+
result.EditionDate = ifcopenshell.util.date.datetime2ifc(edition_date, "IfcCalendarDate")
26+
else:
27+
result.EditionDate = ifcopenshell.util.date.datetime2ifc(edition_date, "IfcDate")
28+
1629
self.file.create_entity("IfcRelAssociatesClassification", **{
1730
"GlobalId": ifcopenshell.guid.new(),
1831
"RelatedObjects": [self.file.by_type("IfcProject")[0]],

src/ifcblenderexport/blenderbim/bim/module/classification/add_reference.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import ifcopenshell
22
import ifcopenshell.util.schema
33

4+
45
class Usecase:
56
def __init__(self, file, settings=None):
67
self.file = file
@@ -14,13 +15,19 @@ def __init__(self, file, settings=None):
1415

1516
def execute(self):
1617
relating_classification = None
18+
19+
if hasattr(self.settings["reference"], "ItemReference"):
20+
identification = self.settings["reference"].ItemReference # IFC2X3
21+
else:
22+
identification = self.settings["reference"].Identification
23+
1724
for reference in self.file.by_type("IfcClassificationReference"):
1825
if self.file.schema == "IFC2X3":
19-
if reference.ItemReference == self.settings["reference"].ItemReference:
26+
if reference.ItemReference == identification:
2027
relating_classification = reference
2128
break
2229
else:
23-
if reference.Identification == self.settings["reference"].Identification:
30+
if reference.Identification == identification:
2431
relating_classification = reference
2532
break
2633

@@ -38,16 +45,19 @@ def execute(self):
3845
relating_classification = migrator.migrate(self.settings["reference"], self.file)
3946
relating_classification.ReferencedSource = self.settings["classification"]
4047
self.settings["reference"].ReferencedSource = old_referenced_source
41-
self.file.create_entity("IfcRelAssociatesClassification", **{
42-
"GlobalId": ifcopenshell.guid.new(),
43-
"RelatedObjects": [self.settings["product"]],
44-
"RelatingClassification": relating_classification
45-
})
48+
self.file.create_entity(
49+
"IfcRelAssociatesClassification",
50+
**{
51+
"GlobalId": ifcopenshell.guid.new(),
52+
"RelatedObjects": [self.settings["product"]],
53+
"RelatingClassification": relating_classification,
54+
}
55+
)
4656

4757
def get_association(self, reference):
4858
if self.file.schema == "IFC2X3":
4959
for association in self.file.by_type("IfcRelAssociatesClassification"):
50-
if relating_classification == reference:
60+
if association.RelatingClassification == reference:
5161
return association
5262
elif reference.ClassificationRefForObjects:
5363
return reference.ClassificationRefForObjects[0]

src/ifcblenderexport/blenderbim/bim/module/classification/data.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import ifcopenshell
2+
import ifcopenshell.util.date
23
from blenderbim.bim.ifc import IfcStore
3-
from datetime import datetime
44

55

66
class Data:
@@ -39,11 +39,7 @@ def load_classifications(cls):
3939
for classification in cls._file.by_type("IfcClassification"):
4040
data = classification.get_info()
4141
if cls._file.schema == "IFC2X3" and data["EditionDate"]:
42-
data["EditionDate"] = datetime(
43-
classification.EditionDate.YearComponent,
44-
classification.EditionDate.MonthComponent,
45-
classification.EditionDate.DayComponent,
46-
).isoformat()
42+
data["EditionDate"] = ifcopenshell.util.date(data.EditionDate).isoformat()
4743
cls.classifications[classification.id()] = data
4844

4945
@classmethod

src/ifcblenderexport/blenderbim/bim/module/classification/remove_classification.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import ifcopenshell.util.schema
2-
3-
41
class Usecase:
52
def __init__(self, file, settings=None):
63
self.file = file

src/ifcopenshell-python/ifcopenshell/util/date.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ def ifc2datetime(element):
3535

3636

3737
def datetime2ifc(dt, ifc_type):
38+
if isinstance(dt, str):
39+
dt = datetime.fromisoformat(dt)
3840
if ifc_type == "IfcTimeStamp":
3941
return int(dt.timestamp())
4042
elif ifc_type == "IfcDateTime":

0 commit comments

Comments
 (0)