Make IFC export more granular to only export contexts that are specified

This allows us to build up highly specific IFC exports instead of monolithic files.
This commit is contained in:
Dion Moult
2020-05-05 15:25:48 +10:00
parent fa8b12497c
commit 01e82620aa
2 changed files with 16 additions and 19 deletions
@@ -1111,7 +1111,9 @@ class IfcExporter():
self.create_units()
self.create_people()
self.create_organisations()
self.set_common_definitions()
self.create_origin()
self.create_owner_history()
self.set_header()
self.create_rep_context()
self.create_project()
self.create_library_information()
@@ -1156,11 +1158,11 @@ class IfcExporter():
self.relate_objects_to_groups()
self.write_ifc_file()
def set_common_definitions(self):
# Owner history doesn't actually work like this, but for now, it does :)
self.origin = self.file.by_type('IfcAxis2Placement3D')[0]
self.create_owner_history()
self.set_header()
def create_origin(self):
self.origin = self.file.createIfcAxis2Placement3D(
self.file.createIfcCartesianPoint((0., 0., 0.)),
self.file.createIfcDirection((0., 0., 1.)),
self.file.createIfcDirection((1., 0., 0.)))
def set_header(self):
# TODO: add all metadata, pending bug #747
@@ -1449,14 +1451,15 @@ class IfcExporter():
def create_rep_context(self):
self.ifc_rep_context = {}
self.ifc_rep_context['Model'] = {
'ifc': self.file.createIfcGeometricRepresentationContext(
None, 'Model', 3, 1.0E-05, self.origin)}
if 'Plan' in self.ifc_export_settings.contexts:
self.ifc_rep_context['Plan'] = {
'ifc': self.file.createIfcGeometricRepresentationContext(
None, 'Plan', 2, 1.0E-05, self.origin)}
for context in self.ifc_export_settings.context_tree:
if context['name'] == 'Model':
self.ifc_rep_context['Model'] = {
'ifc': self.file.createIfcGeometricRepresentationContext(
None, 'Model', 3, 1.0E-05, self.origin)}
elif context['name'] == 'Plan':
self.ifc_rep_context['Plan'] = {
'ifc': self.file.createIfcGeometricRepresentationContext(
None, 'Plan', 2, 1.0E-05, self.origin)}
for subcontext in context['subcontexts']:
self.ifc_rep_context[context['name']][subcontext['name']] = {}
for target_view in subcontext['target_views']:
@@ -5,11 +5,5 @@ FILE_NAME('$filename','2019-05-12T12:33:45',('$owner','$email'),('$company'),'If
FILE_SCHEMA(('IFC4'));
ENDSEC;
DATA;
#1=IFCDIRECTION((1.,0.,0.));
#2=IFCDIRECTION((0.,0.,1.));
#3=IFCCARTESIANPOINT((0.,0.,0.));
#4=IFCAXIS2PLACEMENT3D(#3,#2,#1);
#5=IFCDIRECTION((0.,1.,0.));
#6=IFCDIMENSIONALEXPONENTS(0,0,0,0,0,0,0);
ENDSEC;
END-ISO-10303-21;