From 2dac81ee8d73dd1af88b40181cb9a3586a4ffdde Mon Sep 17 00:00:00 2001 From: Gorgious56 Date: Sun, 19 Sep 2021 10:02:34 +0200 Subject: [PATCH] Parametric object gizmo scale follows scene unit (#1715) * Add missing units in si-conversions * Fix error when using Miles or Thou-inch units * Parametric gizmo scales with scene units * use "thou" instead of "thousandth of an inch" --- .../blenderbim/bim/module/drawing/gizmos.py | 31 ++++++++++++++++--- .../ifcopenshell/api/unit/assign_unit.py | 4 +++ .../ifcopenshell/util/unit.py | 4 +++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/drawing/gizmos.py b/src/blenderbim/blenderbim/bim/module/drawing/gizmos.py index 3bc7124fe1..e939713dae 100644 --- a/src/blenderbim/blenderbim/bim/module/drawing/gizmos.py +++ b/src/blenderbim/blenderbim/bim/module/drawing/gizmos.py @@ -25,6 +25,7 @@ from mathutils import Vector, Matrix from mathutils import geometry from bpy_extras import view3d_utils from blenderbim.bim.module.drawing.shaders import DotsGizmoShader, ExtrusionGuidesShader, BaseLinesShader +from ifcopenshell.util.unit import si_conversions """Gizmos under the hood @@ -469,8 +470,6 @@ class ExtrusionWidget(types.GizmoGroup): bl_region_type = "WINDOW" bl_options = {"3D", "PERSISTENT", "SHOW_MODAL_ALL"} - # FIXME: use proper scale from ifc value to blender units - @classmethod def poll(cls, ctx): obj = ctx.object @@ -486,6 +485,7 @@ class ExtrusionWidget(types.GizmoGroup): basis = target.matrix_world.normalized() theme = ctx.preferences.themes[0].user_interface + scale_value = self.get_scale_value(ctx.scene.unit_settings.system, ctx.scene.unit_settings.length_unit) gz = self.handle = self.gizmos.new("BIM_GT_uglydot_3d") gz.matrix_basis = basis @@ -495,7 +495,7 @@ class ExtrusionWidget(types.GizmoGroup): gz.alpha_highlight = 1.0 gz.use_draw_modal = True gz.target_set_prop("offset", prop, "value") - gz.scale_value = 1000 + gz.scale_value = scale_value gz = self.guides = self.gizmos.new("BIM_GT_extrusion_guides") gz.matrix_basis = basis @@ -503,7 +503,7 @@ class ExtrusionWidget(types.GizmoGroup): gz.alpha = gz.alpha_highlight = 0.5 gz.use_draw_modal = True gz.target_set_prop("depth", prop, "value") - gz.scale_value = 1000 + gz.scale_value = scale_value # gz = self.label = self.gizmos.new('GIZMO_GT_dimension_label') # gz.matrix_basis = basis @@ -526,3 +526,26 @@ class ExtrusionWidget(types.GizmoGroup): prop = target.data.BIMMeshProperties.ifc_parameters.get("IfcExtrudedAreaSolid/Depth") self.handle.target_set_prop("offset", prop, "value") self.guides.target_set_prop("depth", prop, "value") + + @staticmethod + def get_scale_value(system, length_unit): + scale_value = 1 + if system == "METRIC": + if length_unit == "KILOMETERS": + scale_value /= 1000 + elif length_unit == "CENTIMETERS": + scale_value *= 100 + elif length_unit == "MILLIMETERS": + scale_value *= 1000 + elif length_unit == "MICROMETERS": + scale_value *= 1000000 + elif system == "IMPERIAL": + if length_unit == "MILES": + scale_value /= si_conversions["mile"] + elif length_unit == "FEET": + scale_value /= si_conversions["foot"] + elif length_unit == "INCHES": + scale_value /= si_conversions["inch"] + elif length_unit == "THOU": + scale_value /= si_conversions["thou"] + return scale_value diff --git a/src/ifcopenshell-python/ifcopenshell/api/unit/assign_unit.py b/src/ifcopenshell-python/ifcopenshell/api/unit/assign_unit.py index 8ae42c7f53..5d0ad513ba 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/unit/assign_unit.py +++ b/src/ifcopenshell-python/ifcopenshell/api/unit/assign_unit.py @@ -83,6 +83,10 @@ class Usecase: name = "{}inch".format(name_prefix + " " if name_prefix else "") elif data["raw"] == "FEET": name = "{}foot".format(name_prefix + " " if name_prefix else "") + elif data["raw"] == "MILES": + name = "{}mile".format(name_prefix + " " if name_prefix else "") + elif data["raw"] == "THOU": + name = "{}thou".format(name_prefix + " " if name_prefix else "") value_component = self.file.create_entity( "IfcReal", **{"wrappedValue": ifcopenshell.util.unit.si_conversions[name]} ) diff --git a/src/ifcopenshell-python/ifcopenshell/util/unit.py b/src/ifcopenshell-python/ifcopenshell/util/unit.py index 440b4ac805..1229c8db89 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/unit.py +++ b/src/ifcopenshell-python/ifcopenshell/util/unit.py @@ -154,18 +154,22 @@ named_dimensions = { } si_conversions = { + "thou": 0.0000254, "inch": 0.0254, "foot": 0.3048, "yard": 0.914, "mile": 1609, + "square thou": 6.4516e-10, "square inch": 0.0006452, "square foot": 0.09290304, "square yard": 0.83612736, "acre": 4046.86, "square mile": 2588881, + "cubic thou": 1.6387064e-14, "cubic inch": 0.00001639, "cubic foot": 0.02831684671168849, "cubic yard": 0.7636, + "cubic mile": 4165509529, "litre": 0.001, "fluid ounce UK": 0.0000284130625, "fluid ounce US": 0.00002957353,