From 18361360495f7fe927baf596de50b3632b566e6e Mon Sep 17 00:00:00 2001 From: QwiglyDee Date: Tue, 12 Jan 2021 09:32:04 +0700 Subject: [PATCH] adding section annotations --- .../blenderbim/bim/__init__.py | 1 + .../blenderbim/bim/operator.py | 51 +++++++++++++++++++ src/ifcblenderexport/blenderbim/bim/ui.py | 2 + 3 files changed, 54 insertions(+) diff --git a/src/ifcblenderexport/blenderbim/bim/__init__.py b/src/ifcblenderexport/blenderbim/bim/__init__.py index 525cf58ccf..4d0efb5ab2 100644 --- a/src/ifcblenderexport/blenderbim/bim/__init__.py +++ b/src/ifcblenderexport/blenderbim/bim/__init__.py @@ -195,6 +195,7 @@ if bpy is not None: operator.LinkIfc, operator.SnapSpacesTogether, operator.CopyGrid, + operator.AddSectionsAnnotations, prop.StrProperty, prop.Attribute, prop.MaterialLayer, diff --git a/src/ifcblenderexport/blenderbim/bim/operator.py b/src/ifcblenderexport/blenderbim/bim/operator.py index f64f010ebf..e684639e3f 100644 --- a/src/ifcblenderexport/blenderbim/bim/operator.py +++ b/src/ifcblenderexport/blenderbim/bim/operator.py @@ -3830,3 +3830,54 @@ class CopyGrid(bpy.types.Operator): view_coll.objects.link(assemble(obj, mesh)) return {"FINISHED"} + + +class AddSectionsAnnotations(bpy.types.Operator): + bl_idname = "bim.add_sections_annotations" + bl_label = "Add Sections" + bl_options = {"UNDO"} + + def execute(self, context): + scene = context.scene + view_coll, camera = helper.get_active_drawing(scene) + is_ortho = camera.data.type == "ORTHO" + if not is_ortho: + return {'CANCELLED'} + bounds = helper.ortho_view_frame(camera.data) if is_ortho else None + + drawings = [d + for d in scene.DocProperties.drawings + if (d.camera is not camera and + d.camera.data.type == "ORTHO" and + d.camera.data.BIMCameraProperties.target_view == 'SECTION_VIEW')] + + def sideview(cam): + # leftmost and righmost points of camera view area, local coords + xmin, xmax, _, _, _, _ = helper.ortho_view_frame(cam.data, margin=0) + proj = camera.matrix_world.inverted() @ cam.matrix_world + p_l = proj @ Vector((xmin, 0, 0)) + p_r = proj @ Vector((xmax, 0, 0)) + return helper.clip_segment(bounds, (p_l, p_r)) + + def annotation(drawing, points): + # object with path geometry + name = drawing.name + curve = bpy.data.curves.new(f"Section/{name}", 'CURVE') + spline = curve.splines.new('POLY') # has 1 initial point + spline.points.add(1) + p1, p2 = points + z = bounds[4] - 1e-5 # zmin + spline.points[0].co = (p1.x, p1.y, z, 1) + spline.points[1].co = (p2.x, p2.y, z, 1) + obj = bpy.data.objects.new(f"IfcAnnotation/Section/{name}", curve) + obj.matrix_world = camera.matrix_world + return obj + + for d in drawings: + points = sideview(d.camera) + if points is None: + continue + obj = annotation(d, points) + view_coll.objects.link(obj) + + return {'FINISHED'} diff --git a/src/ifcblenderexport/blenderbim/bim/ui.py b/src/ifcblenderexport/blenderbim/bim/ui.py index 96321153b5..d4e843a38e 100644 --- a/src/ifcblenderexport/blenderbim/bim/ui.py +++ b/src/ifcblenderexport/blenderbim/bim/ui.py @@ -1683,6 +1683,8 @@ class BIM_PT_annotation_utilities(Panel): row.operator("bim.link_ifc") row = layout.row(align=True) row.operator("bim.add_grid") + row = layout.row(align=True) + row.operator("bim.add_sections_annotations") row = layout.row(align=True) op = row.operator("bim.add_annotation", text="Dim", icon="ARROW_LEFTRIGHT")