mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-21 10:23:41 +00:00
Add new import workaround for 12D files with absolute coordinates.
This commit is contained in:
@@ -164,6 +164,8 @@ class IfcImporter():
|
|||||||
self.ifc_import_settings.should_ignore_site_coordinates = True
|
self.ifc_import_settings.should_ignore_site_coordinates = True
|
||||||
if self.is_ifc_class_far_away('IfcBuilding'):
|
if self.is_ifc_class_far_away('IfcBuilding'):
|
||||||
self.ifc_import_settings.should_ignore_building_coordinates = True
|
self.ifc_import_settings.should_ignore_building_coordinates = True
|
||||||
|
elif applications[0].ApplicationFullName == '12D Model':
|
||||||
|
self.ifc_import_settings.should_reset_absolute_coordinates = True
|
||||||
|
|
||||||
def is_ifc_class_far_away(self, ifc_class):
|
def is_ifc_class_far_away(self, ifc_class):
|
||||||
for site in self.file.by_type(ifc_class):
|
for site in self.file.by_type(ifc_class):
|
||||||
@@ -171,13 +173,15 @@ class IfcImporter():
|
|||||||
or not site.ObjectPlacement.RelativePlacement \
|
or not site.ObjectPlacement.RelativePlacement \
|
||||||
or not site.ObjectPlacement.RelativePlacement.Location:
|
or not site.ObjectPlacement.RelativePlacement.Location:
|
||||||
continue
|
continue
|
||||||
coordinates = site.ObjectPlacement.RelativePlacement.Location.Coordinates
|
if self.is_point_far_away(site.ObjectPlacement.RelativePlacement.Location):
|
||||||
# Arbitrary threshold based on experience
|
|
||||||
if abs(coordinates[0]) > 1000000 \
|
|
||||||
or abs(coordinates[1]) > 1000000 \
|
|
||||||
or abs(coordinates[2]) > 1000000:
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def is_point_far_away(self, point):
|
||||||
|
# Arbitrary threshold based on experience
|
||||||
|
return abs(point.Coordinates[0]) > 1000000 \
|
||||||
|
or abs(point.Coordinates[1]) > 1000000 \
|
||||||
|
or abs(point.Coordinates[2]) > 1000000
|
||||||
|
|
||||||
def patch_ifc(self):
|
def patch_ifc(self):
|
||||||
project = self.file.by_type('IfcProject')[0]
|
project = self.file.by_type('IfcProject')[0]
|
||||||
if self.ifc_import_settings.should_ignore_site_coordinates:
|
if self.ifc_import_settings.should_ignore_site_coordinates:
|
||||||
@@ -188,6 +192,24 @@ class IfcImporter():
|
|||||||
buildings = self.find_decomposed_ifc_class(project, 'IfcBuilding')
|
buildings = self.find_decomposed_ifc_class(project, 'IfcBuilding')
|
||||||
for building in buildings:
|
for building in buildings:
|
||||||
self.patch_placement_to_origin(building)
|
self.patch_placement_to_origin(building)
|
||||||
|
if self.ifc_import_settings.should_reset_absolute_coordinates:
|
||||||
|
self.reset_absolute_coordinates()
|
||||||
|
|
||||||
|
def reset_absolute_coordinates(self):
|
||||||
|
# 12D can have some funky coordinates out of any sensible range. This
|
||||||
|
# method will not work all the time, but will catch most issues.
|
||||||
|
offset_point = None
|
||||||
|
for point in self.file.by_type('IfcCartesianPoint'):
|
||||||
|
if len(point.Coordinates) == 2 or not self.is_point_far_away(point):
|
||||||
|
continue
|
||||||
|
if not offset_point:
|
||||||
|
offset_point = (point.Coordinates[0], point.Coordinates[1], point.Coordinates[2])
|
||||||
|
self.ifc_import_settings.logger.info(f'Resetting absolute coordinates by {point}')
|
||||||
|
point.Coordinates = (
|
||||||
|
point.Coordinates[0] - offset_point[0],
|
||||||
|
point.Coordinates[1] - offset_point[1],
|
||||||
|
point.Coordinates[2] - offset_point[2]
|
||||||
|
)
|
||||||
|
|
||||||
def find_decomposed_ifc_class(self, element, ifc_class):
|
def find_decomposed_ifc_class(self, element, ifc_class):
|
||||||
results = []
|
results = []
|
||||||
@@ -545,6 +567,7 @@ class IfcImportSettings:
|
|||||||
self.should_auto_set_workarounds = True
|
self.should_auto_set_workarounds = True
|
||||||
self.should_ignore_site_coordinates = False
|
self.should_ignore_site_coordinates = False
|
||||||
self.should_ignore_building_coordinates = False
|
self.should_ignore_building_coordinates = False
|
||||||
|
self.should_reset_absolute_coordinates = False
|
||||||
self.should_import_curves = False
|
self.should_import_curves = False
|
||||||
self.should_treat_styled_item_as_material = False
|
self.should_treat_styled_item_as_material = False
|
||||||
self.should_use_cpu_multiprocessing = False
|
self.should_use_cpu_multiprocessing = False
|
||||||
|
|||||||
@@ -331,6 +331,7 @@ class BIMProperties(PropertyGroup):
|
|||||||
export_should_use_presentation_style_assignment: BoolProperty(name="Export with Presentation Style Assignment", default=False)
|
export_should_use_presentation_style_assignment: BoolProperty(name="Export with Presentation Style Assignment", default=False)
|
||||||
import_should_ignore_site_coordinates: BoolProperty(name="Import Ignoring Site Coordinates", default=False)
|
import_should_ignore_site_coordinates: BoolProperty(name="Import Ignoring Site Coordinates", default=False)
|
||||||
import_should_ignore_building_coordinates: BoolProperty(name="Import Ignoring Building Coordinates", default=False)
|
import_should_ignore_building_coordinates: BoolProperty(name="Import Ignoring Building Coordinates", default=False)
|
||||||
|
import_should_reset_absolute_coordinates: BoolProperty(name="Import Resetting Absolute Coordinates", default=False)
|
||||||
import_should_import_curves: BoolProperty(name="Import Curves", default=False)
|
import_should_import_curves: BoolProperty(name="Import Curves", default=False)
|
||||||
import_should_auto_set_workarounds: BoolProperty(name="Automatically Set Vendor Workarounds", default=True)
|
import_should_auto_set_workarounds: BoolProperty(name="Automatically Set Vendor Workarounds", default=True)
|
||||||
import_should_treat_styled_item_as_material: BoolProperty(name="Import Treating Styled Item as Material", default=False)
|
import_should_treat_styled_item_as_material: BoolProperty(name="Import Treating Styled Item as Material", default=False)
|
||||||
|
|||||||
@@ -574,31 +574,39 @@ class BIM_PT_mvd(Panel):
|
|||||||
scene = context.scene
|
scene = context.scene
|
||||||
bim_properties = scene.BIMProperties
|
bim_properties = scene.BIMProperties
|
||||||
|
|
||||||
layout.label(text="Custom MVD:")
|
layout.label(text='Custom MVD:')
|
||||||
|
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.prop(bim_properties, "export_has_representations")
|
row.prop(bim_properties, 'export_has_representations')
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.prop(bim_properties, "import_should_import_curves")
|
row.prop(bim_properties, 'import_should_import_curves')
|
||||||
|
|
||||||
layout.label(text="Experimental Modes:")
|
layout.label(text='Experimental Modes:')
|
||||||
|
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.prop(bim_properties, "import_should_use_legacy")
|
row.prop(bim_properties, 'import_should_use_legacy')
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.prop(bim_properties, "import_should_use_cpu_multiprocessing")
|
row.prop(bim_properties, 'import_should_use_cpu_multiprocessing')
|
||||||
|
|
||||||
layout.label(text="Revit Workarounds:")
|
layout.label(text='Vendor Workarounds:')
|
||||||
|
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.prop(bim_properties, "import_should_auto_set_workarounds")
|
row.prop(bim_properties, 'import_should_auto_set_workarounds')
|
||||||
|
|
||||||
|
layout.label(text='12D Workarounds:')
|
||||||
|
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.prop(bim_properties, "export_should_export_all_materials_as_styled_items")
|
row.prop(bim_properties, 'import_should_reset_absolute_coordinates')
|
||||||
|
|
||||||
|
layout.label(text='Revit Workarounds:')
|
||||||
|
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.prop(bim_properties, "export_should_use_presentation_style_assignment")
|
row.prop(bim_properties, 'export_should_export_all_materials_as_styled_items')
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.prop(bim_properties, "import_should_ignore_site_coordinates")
|
row.prop(bim_properties, 'export_should_use_presentation_style_assignment')
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.prop(bim_properties, "import_should_ignore_building_coordinates")
|
row.prop(bim_properties, 'import_should_ignore_site_coordinates')
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.prop(bim_properties, "import_should_treat_styled_item_as_material")
|
row.prop(bim_properties, 'import_should_ignore_building_coordinates')
|
||||||
|
row = layout.row()
|
||||||
|
row.prop(bim_properties, 'import_should_treat_styled_item_as_material')
|
||||||
|
|||||||
Reference in New Issue
Block a user