mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
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"
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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]}
|
||||
)
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user