mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-27 10:51:13 +00:00
same openings generator for non-/parametric doors/windows #4710
This commit is contained in:
@@ -159,7 +159,7 @@ def update_door_modifier_representation(context, obj):
|
|||||||
occurrence.OverallWidth = props.overall_width / si_conversion
|
occurrence.OverallWidth = props.overall_width / si_conversion
|
||||||
occurrence.OverallHeight = props.overall_height / si_conversion
|
occurrence.OverallHeight = props.overall_height / si_conversion
|
||||||
|
|
||||||
update_simple_openings(element, props.overall_width / si_conversion, props.overall_height / si_conversion)
|
update_simple_openings(element)
|
||||||
|
|
||||||
|
|
||||||
# TODO: move it out to tools
|
# TODO: move it out to tools
|
||||||
|
|||||||
@@ -29,12 +29,13 @@ from ifcopenshell.api.geometry.add_window_representation import DEFAULT_PANEL_SC
|
|||||||
from ifcopenshell.util.shape_builder import V
|
from ifcopenshell.util.shape_builder import V
|
||||||
from bmesh.types import BMVert
|
from bmesh.types import BMVert
|
||||||
from mathutils import Vector
|
from mathutils import Vector
|
||||||
|
from blenderbim.bim.module.model.opening import FilledOpeningGenerator
|
||||||
|
|
||||||
|
|
||||||
# TODO: move to some utils helpers/tool module
|
# TODO: move to some utils helpers/tool module
|
||||||
def update_simple_openings(element, opening_width, opening_height):
|
def update_simple_openings(element: ifcopenshell.entity_instance) -> None:
|
||||||
ifc_file = tool.Ifc.get()
|
ifc_file = tool.Ifc.get()
|
||||||
fillings = tool.Ifc.get_all_element_occurrences(element)
|
fillings = {e: tool.Ifc.get_object(e) for e in tool.Ifc.get_all_element_occurrences(element)}
|
||||||
|
|
||||||
voided_objs = set()
|
voided_objs = set()
|
||||||
has_replaced_opening_representation = False
|
has_replaced_opening_representation = False
|
||||||
@@ -46,10 +47,10 @@ def update_simple_openings(element, opening_width, opening_height):
|
|||||||
voided_obj = tool.Ifc.get_object(opening.VoidsElements[0].RelatingBuildingElement)
|
voided_obj = tool.Ifc.get_object(opening.VoidsElements[0].RelatingBuildingElement)
|
||||||
voided_objs.add(voided_obj)
|
voided_objs.add(voided_obj)
|
||||||
|
|
||||||
# we assume that the same element type (e.g. window)
|
# We assume all occurrences of the same element type (e.g. a window)
|
||||||
# will be used only for voiding objects of the same thickness (by y-dimension)
|
# will use openings of the same thickness.
|
||||||
# (e.g. all walls window's attached to will share the same thickness)
|
# Generator we use by default will create a really thick opening representation
|
||||||
# If that's not the case it will some linings will be too thick or too thin
|
# to make sure it will fit for walls with different thickness.
|
||||||
if has_replaced_opening_representation:
|
if has_replaced_opening_representation:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -59,20 +60,10 @@ def update_simple_openings(element, opening_width, opening_height):
|
|||||||
"geometry.unassign_representation", ifc_file, product=opening, representation=old_representation
|
"geometry.unassign_representation", ifc_file, product=opening, representation=old_representation
|
||||||
)
|
)
|
||||||
|
|
||||||
thickness = voided_obj.dimensions[1] + 0.1 + 0.1
|
new_representation = FilledOpeningGenerator().generate_opening_from_filling(
|
||||||
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(ifc_file)
|
filling, fillings[filling], voided_obj.dimensions[1]
|
||||||
shape_builder = ifcopenshell.util.shape_builder.ShapeBuilder(ifc_file)
|
|
||||||
context = ifcopenshell.util.representation.get_context(ifc_file, "Model", "Body", "MODEL_VIEW")
|
|
||||||
|
|
||||||
extrusion = shape_builder.extrude(
|
|
||||||
shape_builder.rectangle(size=Vector([opening_width, 0.0, opening_height]).xz),
|
|
||||||
magnitude=thickness / unit_scale,
|
|
||||||
position=Vector([0.0, -0.1 / unit_scale, 0.0]),
|
|
||||||
**shape_builder.extrude_kwargs("Y")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
new_representation = shape_builder.get_representation(context, extrusion)
|
|
||||||
|
|
||||||
for inverse in ifc_file.get_inverse(old_representation):
|
for inverse in ifc_file.get_inverse(old_representation):
|
||||||
ifcopenshell.util.element.replace_attribute(inverse, old_representation, new_representation)
|
ifcopenshell.util.element.replace_attribute(inverse, old_representation, new_representation)
|
||||||
|
|
||||||
@@ -82,7 +73,7 @@ def update_simple_openings(element, opening_width, opening_height):
|
|||||||
|
|
||||||
tool.Model.reload_body_representation(voided_objs)
|
tool.Model.reload_body_representation(voided_objs)
|
||||||
if fillings:
|
if fillings:
|
||||||
with bpy.context.temp_override(selected_objects=[tool.Ifc.get_object(f) for f in fillings]):
|
with bpy.context.temp_override(selected_objects=list(fillings.values())):
|
||||||
bpy.ops.bim.recalculate_fill()
|
bpy.ops.bim.recalculate_fill()
|
||||||
|
|
||||||
|
|
||||||
@@ -175,7 +166,7 @@ def update_window_modifier_representation(context, obj):
|
|||||||
occurrence.OverallWidth = props.overall_width / si_conversion
|
occurrence.OverallWidth = props.overall_width / si_conversion
|
||||||
occurrence.OverallHeight = props.overall_height / si_conversion
|
occurrence.OverallHeight = props.overall_height / si_conversion
|
||||||
|
|
||||||
update_simple_openings(element, props.overall_width / si_conversion, props.overall_height / si_conversion)
|
update_simple_openings(element)
|
||||||
|
|
||||||
|
|
||||||
def create_bm_window_frame(bm, size: Vector, thickness: list, position: Vector = V(0, 0, 0).freeze()):
|
def create_bm_window_frame(bm, size: Vector, thickness: list, position: Vector = V(0, 0, 0).freeze()):
|
||||||
|
|||||||
Reference in New Issue
Block a user