From 205c6a9263c512dcad112b205cff004d884b1c2d Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Fri, 6 Oct 2023 10:45:54 +1100 Subject: [PATCH] New drawing width / height / depth / raster DPI controls --- .../blenderbim/bim/module/drawing/handler.py | 27 ++++++++-- .../blenderbim/bim/module/drawing/prop.py | 4 +- .../blenderbim/bim/module/drawing/ui.py | 49 ++++++++++--------- src/blenderbim/blenderbim/tool/drawing.py | 16 ++---- 4 files changed, 57 insertions(+), 39 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/drawing/handler.py b/src/blenderbim/blenderbim/bim/module/drawing/handler.py index 1553e2cc98..d553fcb113 100644 --- a/src/blenderbim/blenderbim/bim/module/drawing/handler.py +++ b/src/blenderbim/blenderbim/bim/module/drawing/handler.py @@ -18,6 +18,7 @@ import bpy import blenderbim.bim.module.drawing.decoration as decoration +import blenderbim.tool as tool from bpy.app.handlers import persistent @@ -37,10 +38,28 @@ def depsgraph_update_pre_handler(scene): def set_active_camera_resolution(scene): if not scene.camera or "/" not in scene.camera.name or not scene.DocProperties.drawings: return + props = scene.camera.data.BIMCameraProperties + ortho_scale = max((props.width, props.height)) + aspect_ratio = props.width / props.height if ( - scene.render.resolution_x != scene.camera.data.BIMCameraProperties.raster_x - or scene.render.resolution_y != scene.camera.data.BIMCameraProperties.raster_y + (scene.camera.data.ortho_scale != ortho_scale) + or (scene.render.resolution_x / scene.render.resolution_y != aspect_ratio) ): - scene.render.resolution_x = scene.camera.data.BIMCameraProperties.raster_x - scene.render.resolution_y = scene.camera.data.BIMCameraProperties.raster_y + scene.camera.data.ortho_scale = ortho_scale + + diagram_scale = tool.Drawing.get_diagram_scale(scene.camera) + scale_ratio = tool.Drawing.get_scale_ratio(diagram_scale["Scale"]) + + if props.width > props.height: + aspect_ratio = props.height / props.width + raster_x = ortho_scale * scale_ratio * props.dpi / 0.0254 + raster_y = ortho_scale * aspect_ratio * scale_ratio * props.dpi / 0.0254 + else: + aspect_ratio = props.width / props.height + raster_x = ortho_scale * aspect_ratio * scale_ratio * props.dpi / 0.0254 + raster_y = ortho_scale * scale_ratio * props.dpi / 0.0254 + + scene.render.resolution_x = scene.camera.data.BIMCameraProperties.raster_x = int(raster_x) + scene.render.resolution_y = scene.camera.data.BIMCameraProperties.raster_y = int(raster_y) + current_drawing = scene.DocProperties.drawings[scene.DocProperties.current_drawing_index] diff --git a/src/blenderbim/blenderbim/bim/module/drawing/prop.py b/src/blenderbim/blenderbim/bim/module/drawing/prop.py index 0578ff8105..3374b9e97a 100644 --- a/src/blenderbim/blenderbim/bim/module/drawing/prop.py +++ b/src/blenderbim/blenderbim/bim/module/drawing/prop.py @@ -312,7 +312,6 @@ class DocProperties(PropertyGroup): should_use_underlay_cache: BoolProperty(name="Use Underlay Cache", default=False) should_use_linework_cache: BoolProperty(name="Use Linework Cache", default=False) should_use_annotation_cache: BoolProperty(name="Use Annotation Cache", default=False) - should_extract: BoolProperty(name="Should Extract", default=True) is_editing_drawings: BoolProperty(name="Is Editing Drawings", default=False) is_editing_schedules: BoolProperty(name="Is Editing Schedules", default=False) is_editing_references: BoolProperty(name="Is Editing References", default=False) @@ -375,6 +374,9 @@ class BIMCameraProperties(PropertyGroup): custom_scale_denominator: bpy.props.StringProperty(default="100", update=update_diagram_scale) raster_x: IntProperty(name="Raster X", default=1000) raster_y: IntProperty(name="Raster Y", default=1000) + dpi: IntProperty(name="DPI", default=75) + width: FloatProperty(name="Width", default=50, subtype="DISTANCE") + height: FloatProperty(name="Height", default=50, subtype="DISTANCE") is_nts: BoolProperty(name="Is NTS", update=update_is_nts) active_drawing_style_index: IntProperty(name="Active Drawing Style Index") diff --git a/src/blenderbim/blenderbim/bim/module/drawing/ui.py b/src/blenderbim/blenderbim/bim/module/drawing/ui.py index 4784b48354..e051207dbc 100644 --- a/src/blenderbim/blenderbim/bim/module/drawing/ui.py +++ b/src/blenderbim/blenderbim/bim/module/drawing/ui.py @@ -39,21 +39,20 @@ class BIM_PT_camera(Panel): bl_parent_id = "BIM_PT_tab_drawings" def draw(self, context): - if not (context.scene.camera and hasattr(context.active_object.data, "BIMCameraProperties")): + if not (context.scene.camera and hasattr(context.scene.camera.data, "BIMCameraProperties")): row = self.layout.row() row.label(text="No Active Drawing", icon="ERROR") - - layout = self.layout - - if "/" not in context.active_object.name: - layout.label(text="This is not a BIM camera.") return - layout.use_property_split = True - dprops = context.scene.DocProperties - props = context.active_object.data.BIMCameraProperties + if "/" not in context.scene.camera.name: + self.layout.label(text="This is not a BIM camera.") + return - col = layout.column(align=True) + self.layout.use_property_split = True + dprops = context.scene.DocProperties + props = context.scene.camera.data.BIMCameraProperties + + col = self.layout.column(align=True) row = col.row(align=True) row.prop(props, "has_underlay", icon="OUTLINER_OB_IMAGE") row.prop(dprops, "should_use_underlay_cache", text="", icon="FILE_REFRESH") @@ -64,32 +63,36 @@ class BIM_PT_camera(Panel): row.prop(props, "has_annotation", icon="MOD_EDGESPLIT") row.prop(dprops, "should_use_annotation_cache", text="", icon="FILE_REFRESH") - row = layout.row() + row = self.layout.row() row.prop(props, "calculate_shapely_surfaces") - row = layout.row() + row = self.layout.row() row.prop(props, "calculate_svgfill_surfaces") - row = layout.row() - row.prop(dprops, "should_extract") + row = self.layout.row() + row.prop(props, "width") + row = self.layout.row() + row.prop(props, "height") - row = layout.row() - row.prop(props, "raster_x") - row = layout.row() - row.prop(props, "raster_y") + row = self.layout.row() + row.prop(context.scene.camera.data, "clip_end", text="Depth") - row = layout.row(align=True) - row.prop(props, "diagram_scale") + row = self.layout.row(align=True) + row.prop(props, "diagram_scale", text="Scale") row.prop(props, "is_nts", text="", icon="MOD_EDGESPLIT") if props.diagram_scale == "CUSTOM": - row = layout.row(align=True) + row = self.layout.row(align=True) row.prop(props, "custom_scale_numerator", text="Custom Scale") row.prop(props, "custom_scale_denominator", text="") - row = layout.row(align=True) + if props.has_underlay: + row = self.layout.row() + row.prop(props, "dpi") + + row = self.layout.row(align=True) row.operator("bim.create_drawing", text="Create Drawing", icon="OUTPUT") op = row.operator("bim.open_drawing", icon="URL", text="") - op.view = context.active_object.name.split("/")[1] + op.view = context.scene.camera.name.split("/")[1] class BIM_PT_drawing_underlay(Panel): diff --git a/src/blenderbim/blenderbim/tool/drawing.py b/src/blenderbim/blenderbim/tool/drawing.py index 7a88fe2c86..7083cbf131 100644 --- a/src/blenderbim/blenderbim/tool/drawing.py +++ b/src/blenderbim/blenderbim/tool/drawing.py @@ -633,16 +633,11 @@ class Drawing(blenderbim.core.tool.Drawing): camera.show_limits = True if camera_type == "ORTHO": - camera.ortho_scale = width if width > height else height camera.clip_start = 0.002 # Technically 0, but Blender doesn't allow this, so 2mm it is! camera.clip_end = depth - if width > height: - camera.BIMCameraProperties.raster_x = 1000 - camera.BIMCameraProperties.raster_y = round(1000 * (height / width)) - else: - camera.BIMCameraProperties.raster_x = round(1000 * (width / height)) - camera.BIMCameraProperties.raster_y = 1000 + camera.BIMCameraProperties.width = width + camera.BIMCameraProperties.height = height elif camera_type == "PERSP": abs_min_z = abs(min(z)) abs_max_z = abs(max(z)) @@ -650,14 +645,13 @@ class Drawing(blenderbim.core.tool.Drawing): camera.clip_end = abs_min_z max_res = 1000 + camera.BIMCameraProperties.width = width + camera.BIMCameraProperties.height = height + if width > height: fov = 2 * math.atan(width / (2 * abs_min_z)) - camera.BIMCameraProperties.raster_x = max_res - camera.BIMCameraProperties.raster_y = int(max_res / (width / height)) else: fov = 2 * math.atan(height / (2 * abs_min_z)) - camera.BIMCameraProperties.raster_y = max_res - camera.BIMCameraProperties.raster_x = int(max_res * (width / height)) camera.angle = fov