From 2cb8eebf835693ad767d37fc42f0d401f62797ca Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Wed, 5 Oct 2022 21:52:07 +1100 Subject: [PATCH] Profiles now retain manual booleans alongside autogenerated clipping planes --- .../blenderbim/bim/module/model/profile.py | 44 +++++++++++++++---- .../blenderbim/bim/module/model/wall.py | 27 ++---------- src/blenderbim/blenderbim/tool/model.py | 29 ++++++++++++ .../geometry/add_profile_representation.py | 37 +++++++++------- 4 files changed, 88 insertions(+), 49 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/model/profile.py b/src/blenderbim/blenderbim/bim/module/model/profile.py index 9688b689de..9603f30177 100644 --- a/src/blenderbim/blenderbim/bim/module/model/profile.py +++ b/src/blenderbim/blenderbim/bim/module/model/profile.py @@ -428,9 +428,14 @@ class DumbProfileJoiner: ) new_matrix = copy.deepcopy(obj.matrix_world) - new_matrix.col[3] = self.body[0].to_4d() + new_matrix.col[3] = self.body[0].to_4d().copy() new_matrix.invert() - self.clippings = [new_matrix @ c for c in self.clippings] + + for clipping in self.clippings: + if clipping["operand_type"] == "IfcHalfSpaceSolid": + clipping["matrix"] = new_matrix @ clipping["matrix"] + + self.clippings.extend(tool.Model.get_manual_booleans(element)) depth = (self.body[1] - self.body[0]).length @@ -486,7 +491,7 @@ class DumbProfileJoiner: ) is_z_offset_increased = True if percent < 0 else False - change_in_z = (self.body[0] - previous_origin).length + change_in_z = (self.body[0] - previous_origin).length / self.unit_scale coordinates = list(opening.ObjectPlacement.RelativePlacement.Location.Coordinates) if is_z_offset_increased: coordinates[2] += change_in_z @@ -613,7 +618,13 @@ class DumbProfileJoiner: y_axis = direction2 x_axis = (clip2 - clip1).normalized().to_3d() z_axis = x_axis.cross(y_axis) - self.clippings.append(self.create_matrix(clip1, x_axis, y_axis, z_axis)) + self.clippings.append( + { + "type": "IfcBooleanClippingResult", + "operand_type": "IfcHalfSpaceSolid", + "matrix": self.create_matrix(clip1, x_axis, y_axis, z_axis), + } + ) elif connection1 == "ATSTART": if tool.Cad.is_x(abs(xy_angle), (0, 90, 180), tolerance=0.001) and is_orthogonal: plane = self.get_profile_plane(profile2, furthest_plane) @@ -657,8 +668,13 @@ class DumbProfileJoiner: y_axis = direction2 x_axis = (clip2 - clip1).normalized().to_3d() z_axis = x_axis.cross(y_axis) - self.clippings.append(self.create_matrix(clip1, x_axis, y_axis, z_axis)) - + self.clippings.append( + { + "type": "IfcBooleanClippingResult", + "operand_type": "IfcHalfSpaceSolid", + "matrix": self.create_matrix(clip1, x_axis, y_axis, z_axis), + } + ) else: # This is the standard L and T joints described by IFC if connection1 == "ATEND": @@ -679,7 +695,13 @@ class DumbProfileJoiner: ) max_dim = self.get_max_bound_box_dimension(profile1) self.body[1] = intersect + profile1.matrix_world.to_quaternion() @ Vector((0, 0, max_dim)) - self.clippings.append(plane) + self.clippings.append( + { + "type": "IfcBooleanClippingResult", + "operand_type": "IfcHalfSpaceSolid", + "matrix": plane, + } + ) elif connection1 == "ATSTART": if tool.Cad.is_x(abs(xy_angle), (0, 90, 180), tolerance=0.001) and is_orthogonal: plane = self.get_profile_plane(profile2, furthest_plane if is_relating else closest_plane) @@ -698,7 +720,13 @@ class DumbProfileJoiner: ) max_dim = self.get_max_bound_box_dimension(profile1) self.body[0] = intersect - profile1.matrix_world.to_quaternion() @ Vector((0, 0, max_dim)) - self.clippings.append(plane) + self.clippings.append( + { + "type": "IfcBooleanClippingResult", + "operand_type": "IfcHalfSpaceSolid", + "matrix": plane, + } + ) def get_max_bound_box_dimension(self, obj): x = [v[0] for v in obj.bound_box] diff --git a/src/blenderbim/blenderbim/bim/module/model/wall.py b/src/blenderbim/blenderbim/bim/module/model/wall.py index 31919b66a1..f9093893ca 100644 --- a/src/blenderbim/blenderbim/bim/module/model/wall.py +++ b/src/blenderbim/blenderbim/bim/module/model/wall.py @@ -869,6 +869,7 @@ class DumbWallJoiner: body = copy.deepcopy(axis1["reference"]) axis[1 if connection == "ATEND" else 0] = intersect body[1 if connection == "ATEND" else 0] = intersect + self.recreate_wall(element1, wall1, axis, body) def set_length(self, wall1, length): @@ -970,7 +971,7 @@ class DumbWallJoiner: if clipping["operand_type"] == "IfcHalfSpaceSolid": clipping["matrix"] = new_matrix @ clipping["matrix"] - self.get_manual_clippings(element, new_matrix) + self.clippings.extend(tool.Model.get_manual_booleans(element)) length = (self.body[1] - self.body[0]).length @@ -1027,7 +1028,7 @@ class DumbWallJoiner: ) is_x_offset_increased = True if percent < 0 else False - change_in_x = (self.body[0] - previous_origin.to_2d()).length + change_in_x = (self.body[0] - previous_origin.to_2d()).length / self.unit_scale coordinates = list(opening.ObjectPlacement.RelativePlacement.Location.Coordinates) if is_x_offset_increased: coordinates[0] += change_in_x @@ -1046,28 +1047,6 @@ class DumbWallJoiner: ) tool.Geometry.record_object_materials(obj) - def get_manual_clippings(self, element, new_matrix): - body = ifcopenshell.util.representation.get_representation(element, "Model", "Body", "MODEL_VIEW") - if not body: - return - clippings = [] - items = list(body.Items) - while items: - item = items.pop() - if item.is_a() == "IfcBooleanResult": - clippings.append(item.SecondOperand) - items.append(item.FirstOperand) - elif item.is_a("IfcBooleanClippingResult"): - items.append(item.FirstOperand) - for clipping in clippings: - if clipping.is_a("IfcHalfSpaceSolid") and clipping.BaseSurface.is_a("IfcPlane"): - placement = Matrix(ifcopenshell.util.placement.get_local_placement(element.ObjectPlacement).tolist()) - position = clipping.BaseSurface.Position - position = Matrix(ifcopenshell.util.placement.get_axis2placement(position).tolist()) - self.clippings.append( - {"type": "IfcBooleanResult", "operand_type": "IfcHalfSpaceSolid", "matrix": position} - ) - def create_matrix(self, p, x, y, z): return Matrix( ( diff --git a/src/blenderbim/blenderbim/tool/model.py b/src/blenderbim/blenderbim/tool/model.py index 4083b957dd..4132d52d8f 100644 --- a/src/blenderbim/blenderbim/tool/model.py +++ b/src/blenderbim/blenderbim/tool/model.py @@ -17,8 +17,12 @@ # along with BlenderBIM Add-on. If not, see . import bpy +import ifcopenshell +import ifcopenshell.util.placement +import ifcopenshell.util.representation import blenderbim.core.tool import blenderbim.tool as tool +from mathutils import Matrix from blenderbim.bim import import_ifc @@ -81,3 +85,28 @@ class Model(blenderbim.core.tool.Model): if not opening.obj: props.openings.remove(i) has_deleted_opening = True + + @classmethod + def get_manual_booleans(cls, element): + results = [] + body = ifcopenshell.util.representation.get_representation(element, "Model", "Body", "MODEL_VIEW") + if not body: + return [] + clippings = [] + items = list(body.Items) + while items: + item = items.pop() + if item.is_a() == "IfcBooleanResult": + clippings.append(item.SecondOperand) + items.append(item.FirstOperand) + elif item.is_a("IfcBooleanClippingResult"): + items.append(item.FirstOperand) + for clipping in clippings: + if clipping.is_a("IfcHalfSpaceSolid") and clipping.BaseSurface.is_a("IfcPlane"): + placement = Matrix(ifcopenshell.util.placement.get_local_placement(element.ObjectPlacement).tolist()) + position = clipping.BaseSurface.Position + position = Matrix(ifcopenshell.util.placement.get_axis2placement(position).tolist()) + results.append( + {"type": "IfcBooleanResult", "operand_type": "IfcHalfSpaceSolid", "matrix": position} + ) + return results diff --git a/src/ifcopenshell-python/ifcopenshell/api/geometry/add_profile_representation.py b/src/ifcopenshell-python/ifcopenshell/api/geometry/add_profile_representation.py index ac107c2d2e..d2eddcdeb0 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/geometry/add_profile_representation.py +++ b/src/ifcopenshell-python/ifcopenshell/api/geometry/add_profile_representation.py @@ -29,6 +29,7 @@ class Usecase: "depth": 1.0, "cardinal_point": 5, # Planes are defined as a matrix. The XY plane is the clipping boundary and +Z is removed. + # [{"type": "IfcBooleanClippingResult", "operand_type": "IfcHalfSpaceSolid", "matrix": [...]}, {...}] "clippings": [], # A list of planes that define clipping half space solids } for key, value in settings.items(): @@ -62,23 +63,25 @@ class Usecase: def apply_clippings(self, first_operand): while self.settings["clippings"]: clipping = self.settings["clippings"].pop() - second_operand = self.file.createIfcHalfSpaceSolid( - self.file.createIfcPlane( - self.file.createIfcAxis2Placement3D( - self.file.createIfcCartesianPoint( - ( - self.convert_si_to_unit(clipping[0][3]), - self.convert_si_to_unit(clipping[1][3]), - self.convert_si_to_unit(clipping[2][3]), - ) - ), - self.file.createIfcDirection((clipping[0][2], clipping[1][2], clipping[2][2])), - self.file.createIfcDirection((clipping[0][0], clipping[1][0], clipping[2][0])), - ) - ), - False, - ) - first_operand = self.file.createIfcBooleanClippingResult("DIFFERENCE", first_operand, second_operand) + if clipping["operand_type"] == "IfcHalfSpaceSolid": + matrix = clipping["matrix"] + second_operand = self.file.createIfcHalfSpaceSolid( + self.file.createIfcPlane( + self.file.createIfcAxis2Placement3D( + self.file.createIfcCartesianPoint( + ( + self.convert_si_to_unit(matrix[0][3]), + self.convert_si_to_unit(matrix[1][3]), + self.convert_si_to_unit(matrix[2][3]), + ) + ), + self.file.createIfcDirection((matrix[0][2], matrix[1][2], matrix[2][2])), + self.file.createIfcDirection((matrix[0][0], matrix[1][0], matrix[2][0])), + ) + ), + False, + ) + first_operand = self.file.create_entity(clipping["type"], "DIFFERENCE", first_operand, second_operand) return first_operand def convert_si_to_unit(self, co):