From 7233840434ce70518062e2089e40ad5160f98be2 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 4 Apr 2023 11:08:04 +0500 Subject: [PATCH] Fixed ifc validation errors for generated openings #2925 Now ELEVATION_VIEW 3d curves converted to 2d to be extruded later on to create opening representation. --- .../blenderbim/bim/module/model/opening.py | 21 ++++++++++++++----- .../blenderbim/bim/module/model/window.py | 6 ++++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/model/opening.py b/src/blenderbim/blenderbim/bim/module/model/opening.py index 0d0115177f..a51cf4f2bf 100644 --- a/src/blenderbim/blenderbim/bim/module/model/opening.py +++ b/src/blenderbim/blenderbim/bim/module/model/opening.py @@ -215,8 +215,9 @@ class FilledOpeningGenerator: def generate_opening_from_filling(self, filling, filling_obj, voided_obj): thickness = voided_obj.dimensions[1] + 0.1 + 0.1 - unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get()) - shape_builder = ifcopenshell.util.shape_builder.ShapeBuilder(tool.Ifc.get()) + ifc_file = tool.Ifc.get() + unit_scale = ifcopenshell.util.unit.calculate_unit_scale(ifc_file) + shape_builder = ifcopenshell.util.shape_builder.ShapeBuilder(ifc_file) profile = None filling_type = ifcopenshell.util.element.get_type(filling) @@ -225,14 +226,24 @@ class FilledOpeningGenerator: filling_type, "Model", "Profile", "ELEVATION_VIEW" ) filling_obj = tool.Ifc.get_object(filling_type) - context = ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Model", "Body", "MODEL_VIEW") + context = ifcopenshell.util.representation.get_context(ifc_file, "Model", "Body", "MODEL_VIEW") if profile: + curve_3d = ifcopenshell.util.representation.resolve_representation(profile).Items[0] + + def get_curve_2d_from_3d(curve_3d): + ifc_segments = [shape_builder.deep_copy(s) for s in curve_3d.Segments] + ifc_points = ifc_file.createIfcCartesianPointList2D([Vector(p).xz for p in curve_3d.Points.CoordList]) + ifc_curve = ifc_file.createIfcIndexedPolyCurve(Points=ifc_points, Segments=ifc_segments) + return ifc_curve + extrusion = shape_builder.extrude( - ifcopenshell.util.representation.resolve_representation(profile).Items[0], + get_curve_2d_from_3d(curve_3d), magnitude=thickness / unit_scale, position=Vector([0.0, -0.1 / unit_scale, 0.0]), - extrusion_vector=Vector([0.0, 1.0, 0.0]), + position_x_axis=Vector((1, 0, 0)), + position_z_axis=Vector((0, -1, 0)), + extrusion_vector=Vector((0, 0, -1)), ) return shape_builder.get_representation(context, [extrusion]) diff --git a/src/blenderbim/blenderbim/bim/module/model/window.py b/src/blenderbim/blenderbim/bim/module/model/window.py index 8dee9b3629..1ee9bc848a 100644 --- a/src/blenderbim/blenderbim/bim/module/model/window.py +++ b/src/blenderbim/blenderbim/bim/module/model/window.py @@ -69,10 +69,12 @@ def update_simple_openings(element, opening_width, opening_height): 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])), + 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]), - extrusion_vector=Vector([0.0, 1.0, 0.0]), + position_x_axis=V(1, 0, 0), + position_z_axis=V(0, -1, 0), + extrusion_vector=V(0, 0, -1), ) new_representation = shape_builder.get_representation(context, extrusion)