mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 06:58:56 +00:00
Fix #1287. Back to IfcOpenShell for booleans. Optional conversion to Blender if the user decides to do so.
This commit is contained in:
@@ -278,7 +278,6 @@ class IfcImporter:
|
|||||||
self.diff = None
|
self.diff = None
|
||||||
self.file = None
|
self.file = None
|
||||||
self.settings = ifcopenshell.geom.settings()
|
self.settings = ifcopenshell.geom.settings()
|
||||||
self.settings.set(self.settings.DISABLE_OPENING_SUBTRACTIONS, True)
|
|
||||||
self.settings.set_deflection_tolerance(self.ifc_import_settings.deflection_tolerance)
|
self.settings.set_deflection_tolerance(self.ifc_import_settings.deflection_tolerance)
|
||||||
self.settings.set_angular_tolerance(self.ifc_import_settings.angular_tolerance)
|
self.settings.set_angular_tolerance(self.ifc_import_settings.angular_tolerance)
|
||||||
if self.ifc_import_settings.should_import_curves:
|
if self.ifc_import_settings.should_import_curves:
|
||||||
@@ -347,17 +346,15 @@ class IfcImporter:
|
|||||||
self.process_element_filter()
|
self.process_element_filter()
|
||||||
self.profile_code("Process element filter")
|
self.profile_code("Process element filter")
|
||||||
# TODO: Deprecate
|
# TODO: Deprecate
|
||||||
#self.parse_native_elements()
|
# self.parse_native_elements()
|
||||||
#self.profile_code("Parsing native elements")
|
# self.profile_code("Parsing native elements")
|
||||||
self.create_grids()
|
self.create_grids()
|
||||||
self.profile_code("Creating grids")
|
self.profile_code("Creating grids")
|
||||||
# TODO: Deprecate
|
# TODO: Deprecate
|
||||||
#self.create_native_products()
|
# self.create_native_products()
|
||||||
#self.profile_code("Creating native products")
|
# self.profile_code("Creating native products")
|
||||||
self.create_products()
|
self.create_products()
|
||||||
self.profile_code("Creating meshified products")
|
self.profile_code("Creating meshified products")
|
||||||
self.relate_openings()
|
|
||||||
self.profile_code("Relating openings")
|
|
||||||
self.place_objects_in_spatial_tree()
|
self.place_objects_in_spatial_tree()
|
||||||
self.profile_code("Placing objects in spatial tree")
|
self.profile_code("Placing objects in spatial tree")
|
||||||
if self.ifc_import_settings.should_merge_by_class:
|
if self.ifc_import_settings.should_merge_by_class:
|
||||||
@@ -1231,16 +1228,6 @@ class IfcImporter:
|
|||||||
objects_to_purge.append(obj)
|
objects_to_purge.append(obj)
|
||||||
bpy.ops.object.delete({"selected_objects": objects_to_purge})
|
bpy.ops.object.delete({"selected_objects": objects_to_purge})
|
||||||
|
|
||||||
def relate_openings(self):
|
|
||||||
for global_id, opening in self.openings.items():
|
|
||||||
building_element_global_id = self.file.by_guid(global_id).VoidsElements[0].RelatingBuildingElement.GlobalId
|
|
||||||
if building_element_global_id not in self.added_data:
|
|
||||||
continue
|
|
||||||
building_element = self.added_data[building_element_global_id]
|
|
||||||
modifier = building_element.modifiers.new("IfcOpeningElement", "BOOLEAN")
|
|
||||||
modifier.operation = "DIFFERENCE"
|
|
||||||
modifier.object = opening
|
|
||||||
|
|
||||||
def place_objects_in_spatial_tree(self):
|
def place_objects_in_spatial_tree(self):
|
||||||
for ifc_definition_id, obj in IfcStore.id_map.items():
|
for ifc_definition_id, obj in IfcStore.id_map.items():
|
||||||
self.place_object_in_spatial_tree(self.file.by_id(ifc_definition_id), obj)
|
self.place_object_in_spatial_tree(self.file.by_id(ifc_definition_id), obj)
|
||||||
@@ -1380,9 +1367,7 @@ class IfcImporter:
|
|||||||
representation_id = int(re.sub(r"\D", "", representation_id))
|
representation_id = int(re.sub(r"\D", "", representation_id))
|
||||||
representation = self.file.by_id(representation_id)
|
representation = self.file.by_id(representation_id)
|
||||||
context_id = representation.ContextOfItems.id() if hasattr(representation, "ContextOfItems") else 0
|
context_id = representation.ContextOfItems.id() if hasattr(representation, "ContextOfItems") else 0
|
||||||
mesh = bpy.data.meshes.new(
|
mesh = bpy.data.meshes.new("{}/{}".format(context_id, representation_id))
|
||||||
"{}/{}".format(context_id, geometry.id)
|
|
||||||
)
|
|
||||||
|
|
||||||
props = bpy.context.scene.BIMGeoreferenceProperties
|
props = bpy.context.scene.BIMGeoreferenceProperties
|
||||||
if props.has_blender_offset and props.blender_offset_type == "CARTESIAN_POINT":
|
if props.has_blender_offset and props.blender_offset_type == "CARTESIAN_POINT":
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ from blenderbim.bim.ifc import IfcStore
|
|||||||
from blenderbim.bim import import_ifc
|
from blenderbim.bim import import_ifc
|
||||||
from blenderbim.bim.module.geometry.data import Data
|
from blenderbim.bim.module.geometry.data import Data
|
||||||
from blenderbim.bim.module.context.data import Data as ContextData
|
from blenderbim.bim.module.context.data import Data as ContextData
|
||||||
|
from blenderbim.bim.module.void.data import Data as VoidData
|
||||||
|
|
||||||
|
|
||||||
def get_box_context_id():
|
def get_box_context_id():
|
||||||
@@ -142,13 +143,14 @@ class SwitchRepresentation(bpy.types.Operator):
|
|||||||
bl_idname = "bim.switch_representation"
|
bl_idname = "bim.switch_representation"
|
||||||
bl_label = "Switch Representation"
|
bl_label = "Switch Representation"
|
||||||
ifc_definition_id: bpy.props.IntProperty()
|
ifc_definition_id: bpy.props.IntProperty()
|
||||||
|
disable_opening_subtractions: bpy.props.BoolProperty()
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
self.obj = bpy.context.active_object
|
self.obj = bpy.context.active_object
|
||||||
|
|
||||||
self.file = IfcStore.get_file()
|
self.file = IfcStore.get_file()
|
||||||
context_of_items = self.file.by_id(self.ifc_definition_id).ContextOfItems
|
self.context_of_items = self.file.by_id(self.ifc_definition_id).ContextOfItems
|
||||||
self.mesh_name = "{}/{}".format(context_of_items.id(), self.ifc_definition_id)
|
self.mesh_name = "{}/{}".format(self.context_of_items.id(), self.ifc_definition_id)
|
||||||
|
|
||||||
mesh = bpy.data.meshes.get(self.mesh_name)
|
mesh = bpy.data.meshes.get(self.mesh_name)
|
||||||
if mesh:
|
if mesh:
|
||||||
@@ -162,8 +164,18 @@ class SwitchRepresentation(bpy.types.Operator):
|
|||||||
ifc_import_settings = import_ifc.IfcImportSettings.factory(bpy.context, IfcStore.path, logger)
|
ifc_import_settings = import_ifc.IfcImportSettings.factory(bpy.context, IfcStore.path, logger)
|
||||||
element = self.file.by_id(self.obj.BIMObjectProperties.ifc_definition_id)
|
element = self.file.by_id(self.obj.BIMObjectProperties.ifc_definition_id)
|
||||||
settings = ifcopenshell.geom.settings()
|
settings = ifcopenshell.geom.settings()
|
||||||
settings.set(settings.INCLUDE_CURVES, True)
|
|
||||||
shape = ifcopenshell.geom.create_shape(settings, self.file.by_id(self.ifc_definition_id))
|
if self.context_of_items.ContextIdentifier != "Body":
|
||||||
|
settings.set(settings.INCLUDE_CURVES, True)
|
||||||
|
|
||||||
|
if self.disable_opening_subtractions and self.context_of_items.ContextIdentifier == "Body":
|
||||||
|
settings.set(settings.DISABLE_OPENING_SUBTRACTIONS, True)
|
||||||
|
shape = ifcopenshell.geom.create_shape(settings, self.file.by_id(self.ifc_definition_id))
|
||||||
|
else:
|
||||||
|
shape = ifcopenshell.geom.create_shape(
|
||||||
|
settings, self.file.by_id(self.obj.BIMObjectProperties.ifc_definition_id)
|
||||||
|
)
|
||||||
|
|
||||||
ifc_importer = import_ifc.IfcImporter(ifc_import_settings)
|
ifc_importer = import_ifc.IfcImporter(ifc_import_settings)
|
||||||
ifc_importer.file = self.file
|
ifc_importer.file = self.file
|
||||||
mesh = ifc_importer.create_mesh(element, shape)
|
mesh = ifc_importer.create_mesh(element, shape)
|
||||||
@@ -173,6 +185,20 @@ class SwitchRepresentation(bpy.types.Operator):
|
|||||||
material_creator = import_ifc.MaterialCreator(ifc_import_settings, ifc_importer)
|
material_creator = import_ifc.MaterialCreator(ifc_import_settings, ifc_importer)
|
||||||
material_creator.create(element, self.obj, mesh)
|
material_creator.create(element, self.obj, mesh)
|
||||||
|
|
||||||
|
if self.disable_opening_subtractions and self.context_of_items.ContextIdentifier == "Body":
|
||||||
|
if self.obj.BIMObjectProperties.ifc_definition_id not in VoidData.products:
|
||||||
|
VoidData.load(self.obj.BIMObjectProperties.ifc_definition_id)
|
||||||
|
for opening_id in VoidData.products[self.obj.BIMObjectProperties.ifc_definition_id]:
|
||||||
|
if opening_id in IfcStore.id_map:
|
||||||
|
opening = IfcStore.id_map[opening_id]
|
||||||
|
modifier = self.obj.modifiers.new("IfcOpeningElement", "BOOLEAN")
|
||||||
|
modifier.operation = "DIFFERENCE"
|
||||||
|
modifier.object = opening
|
||||||
|
else:
|
||||||
|
for modifier in self.obj.modifiers:
|
||||||
|
if modifier.type == "BOOLEAN" and "IfcOpeningElement" in modifier.name:
|
||||||
|
self.obj.modifiers.remove(modifier)
|
||||||
|
|
||||||
|
|
||||||
class RemoveRepresentation(bpy.types.Operator):
|
class RemoveRepresentation(bpy.types.Operator):
|
||||||
bl_idname = "bim.remove_representation"
|
bl_idname = "bim.remove_representation"
|
||||||
|
|||||||
@@ -38,7 +38,9 @@ class BIM_PT_representations(Panel):
|
|||||||
row.label(text=representation["ContextOfItems"]["ContextIdentifier"])
|
row.label(text=representation["ContextOfItems"]["ContextIdentifier"])
|
||||||
row.label(text=representation["ContextOfItems"]["TargetView"])
|
row.label(text=representation["ContextOfItems"]["TargetView"])
|
||||||
row.label(text=representation["RepresentationType"])
|
row.label(text=representation["RepresentationType"])
|
||||||
row.operator("bim.switch_representation", icon="OUTLINER_DATA_MESH", text="").ifc_definition_id = ifc_definition_id
|
op = row.operator("bim.switch_representation", icon="OUTLINER_DATA_MESH", text="")
|
||||||
|
op.ifc_definition_id = ifc_definition_id
|
||||||
|
op.disable_opening_subtractions = False
|
||||||
row.operator("bim.remove_representation", icon="X", text="").ifc_definition_id = ifc_definition_id
|
row.operator("bim.remove_representation", icon="X", text="").ifc_definition_id = ifc_definition_id
|
||||||
|
|
||||||
|
|
||||||
@@ -65,11 +67,20 @@ class BIM_PT_mesh(Panel):
|
|||||||
props = context.active_object.data.BIMMeshProperties
|
props = context.active_object.data.BIMMeshProperties
|
||||||
|
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.operator("bim.get_representation_ifc_parameters")
|
row.operator("bim.map_representation")
|
||||||
|
|
||||||
|
row = layout.row(align=True)
|
||||||
|
op = row.operator("bim.switch_representation", text="Bake Voids", icon="SELECT_SUBTRACT")
|
||||||
|
op.ifc_definition_id = props.ifc_definition_id
|
||||||
|
op.disable_opening_subtractions = False
|
||||||
|
op = row.operator("bim.switch_representation", text="Dynamic Voids", icon="SELECT_INTERSECT")
|
||||||
|
op.ifc_definition_id = props.ifc_definition_id
|
||||||
|
op.disable_opening_subtractions = True
|
||||||
|
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.operator("bim.update_mesh_representation")
|
row.operator("bim.update_mesh_representation")
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.operator("bim.map_representation")
|
row.operator("bim.get_representation_ifc_parameters")
|
||||||
for index, ifc_parameter in enumerate(props.ifc_parameters):
|
for index, ifc_parameter in enumerate(props.ifc_parameters):
|
||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
row.prop(ifc_parameter, "name", text="")
|
row.prop(ifc_parameter, "name", text="")
|
||||||
|
|||||||
Reference in New Issue
Block a user