From 2b1a59a4f891ca9cce719aeb0408c5c44efb5563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Perdig=C3=A3o?= Date: Sat, 25 Jan 2025 16:05:04 -0300 Subject: [PATCH] Refactor how offset and direction sense interact for wall and slabs. --- src/bonsai/bonsai/bim/module/model/polyline.py | 9 +++++---- src/bonsai/bonsai/bim/module/model/slab.py | 1 - src/bonsai/bonsai/bim/module/model/wall.py | 4 +++- src/bonsai/bonsai/tool/model.py | 8 +++----- .../ifcopenshell/api/geometry/add_wall_representation.py | 4 ++++ 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/model/polyline.py b/src/bonsai/bonsai/bim/module/model/polyline.py index e2397c0852..19f0d5adbe 100644 --- a/src/bonsai/bonsai/bim/module/model/polyline.py +++ b/src/bonsai/bonsai/bim/module/model/polyline.py @@ -78,7 +78,6 @@ def get_wall_preview_data(context, relating_type): offset_type = model_props.offset_type_vertical unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get()) offset = model_props.offset * unit_scale - offset *= direction height = float(model_props.extrusion_depth) rl = float(model_props.rl1) @@ -206,7 +205,6 @@ def get_slab_preview_data(context, relating_type): offset_type = model_props.offset_type_horizontal unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get()) offset = model_props.offset * unit_scale - offset *= direction data = {} data["verts"] = [] @@ -915,10 +913,13 @@ class PolylineOperator: def set_offset(self, context: bpy.types.Context, relating_type: ifcopenshell.entity_instance) -> None: props = bpy.context.scene.BIMModelProperties + direction_sense = props.direction_sense if tool.Model.get_usage_type(relating_type) == "LAYER2": offset_type = "offset_type_vertical" + direction = 1 if direction_sense == "POSITIVE" else -1 elif tool.Model.get_usage_type(relating_type) == "LAYER3": offset_type = "offset_type_horizontal" + direction = 1 else: return @@ -926,9 +927,9 @@ class PolylineOperator: thickness = layers["thickness"] self.offset = 0 if getattr(props, offset_type) == "CENTER": - self.offset = -thickness / 2 + self.offset = (-thickness / 2) * direction elif getattr(props, offset_type) in {"INTERIOR", "TOP"}: - self.offset = -thickness + self.offset = -thickness * direction props.offset = self.offset / self.unit_scale tool.Blender.update_viewport() diff --git a/src/bonsai/bonsai/bim/module/model/slab.py b/src/bonsai/bonsai/bim/module/model/slab.py index 4e226bf433..6e5079da61 100644 --- a/src/bonsai/bonsai/bim/module/model/slab.py +++ b/src/bonsai/bonsai/bim/module/model/slab.py @@ -306,7 +306,6 @@ class DumbSlabPlaner: elif layer_params["direction_sense"] == "NEGATIVE": y = -abs(y) if existing_x_angle > 0 else abs(y) z = -abs(z) - offset_vector = -offset_vector extrusion.ExtrudedDirection.DirectionRatios = (x, y, z) extrusion.Depth = thickness diff --git a/src/bonsai/bonsai/bim/module/model/wall.py b/src/bonsai/bonsai/bim/module/model/wall.py index 85c9f4876a..b848a23f5d 100644 --- a/src/bonsai/bonsai/bim/module/model/wall.py +++ b/src/bonsai/bonsai/bim/module/model/wall.py @@ -263,7 +263,6 @@ class ChangeExtrusionXAngle(bpy.types.Operator, tool.Ifc.Operator): if layer_params["direction_sense"] == "NEGATIVE": y = -abs(y) if x_angle > 0 else abs(y) z = -abs(z) - offset_vector = -offset_vector extrusion.ExtrudedDirection.DirectionRatios = (x, y, z) if offset != 0.0 and not extrusion.Position: @@ -418,6 +417,7 @@ class DrawPolylineWall(bpy.types.Operator, PolylineOperator): context.scene.BIMModelProperties.direction_sense = ( "NEGATIVE" if direction_sense == "POSITIVE" else "POSITIVE" ) + self.set_offset(context, self.relating_type) props = bpy.context.scene.BIMModelProperties if event.value == "RELEASE" and event.type == "O": @@ -828,6 +828,7 @@ class DumbWallGenerator: tool.Ifc.get(), context=self.body_context, thickness=self.layers["thickness"], + direction_sense=self.layers["direction_sense"], offset=self.layers["offset"], length=self.length, height=self.height, @@ -1391,6 +1392,7 @@ class DumbWallJoiner: length=length, height=height, x_angle=x_angle, + direction_sense=layers["direction_sense"], offset=layers["offset"], thickness=layers["thickness"], clippings=self.clippings, diff --git a/src/bonsai/bonsai/tool/model.py b/src/bonsai/bonsai/tool/model.py index aa89285ff2..ad45b0139a 100644 --- a/src/bonsai/bonsai/tool/model.py +++ b/src/bonsai/bonsai/tool/model.py @@ -536,9 +536,6 @@ class Model(bonsai.core.tool.Model): material = material.ForLayerSet if material.is_a("IfcMaterialLayerSet"): thickness = sum([l.LayerThickness for l in material.MaterialLayers]) * unit_scale - if direction_sense == "NEGATIVE": - thickness *= -1 - offset *= -1 return { "layer_set_direction": layer_set_direction, "thickness": thickness, @@ -672,14 +669,15 @@ class Model(bonsai.core.tool.Model): max_x = max(x_values) axes = {} if layers: + direction = 1 if layers["direction_sense"] == "POSITIVE" else -1 axes = { "base": [ (obj.matrix_world @ Vector((min_x, layers["offset"], 0.0))).to_2d(), (obj.matrix_world @ Vector((max_x, layers["offset"], 0.0))).to_2d(), ], "side": [ - (obj.matrix_world @ Vector((min_x, layers["offset"] + layers["thickness"], 0.0))).to_2d(), - (obj.matrix_world @ Vector((max_x, layers["offset"] + layers["thickness"], 0.0))).to_2d(), + (obj.matrix_world @ Vector((min_x, layers["offset"] + (layers["thickness"] * direction), 0.0))).to_2d(), + (obj.matrix_world @ Vector((max_x, layers["offset"] + (layers["thickness"] * direction), 0.0))).to_2d(), ], } axes["reference"] = [ diff --git a/src/ifcopenshell-python/ifcopenshell/api/geometry/add_wall_representation.py b/src/ifcopenshell-python/ifcopenshell/api/geometry/add_wall_representation.py index 2e8af69100..36691a044b 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/geometry/add_wall_representation.py +++ b/src/ifcopenshell-python/ifcopenshell/api/geometry/add_wall_representation.py @@ -28,6 +28,7 @@ def add_wall_representation( context: ifcopenshell.entity_instance, length: float = 1.0, height: float = 3.0, + direction_sense: str = "POSITIVE", offset: float = 0.0, thickness: float = 0.2, x_angle: float = 0.0, @@ -55,6 +56,7 @@ def add_wall_representation( "context": context, "length": length, "height": height, + "direction_sense": direction_sense, "offset": offset, "thickness": thickness, "x_angle": x_angle, @@ -83,6 +85,8 @@ class Usecase: length = self.convert_si_to_unit(self.settings["length"]) thickness = self.convert_si_to_unit(self.settings["thickness"]) thickness *= 1 / cos(self.settings["x_angle"]) + if self.settings["direction_sense"] == "NEGATIVE": + thickness *= -1 points = ( (0.0, 0.0), (0.0, thickness),