mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-23 12:32:39 +00:00
See #6121. Area measurement tool now uses IFC area unit.
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
import bpy
|
import bpy
|
||||||
import math
|
import math
|
||||||
import mathutils.geometry
|
import mathutils.geometry
|
||||||
|
import ifcopenshell
|
||||||
import bonsai.tool as tool
|
import bonsai.tool as tool
|
||||||
from mathutils import Vector
|
from mathutils import Vector
|
||||||
|
|
||||||
@@ -135,6 +136,7 @@ def format_distance(
|
|||||||
scaleFactor = bpy.context.scene.unit_settings.scale_length
|
scaleFactor = bpy.context.scene.unit_settings.scale_length
|
||||||
unit_system = bpy.context.scene.unit_settings.system
|
unit_system = bpy.context.scene.unit_settings.system
|
||||||
unit_length = bpy.context.scene.unit_settings.length_unit
|
unit_length = bpy.context.scene.unit_settings.length_unit
|
||||||
|
area_unit_symbol = " " + ifcopenshell.util.unit.get_unit_symbol(ifcopenshell.util.unit.get_project_unit(tool.Ifc.get(), "AREAUNIT"))
|
||||||
|
|
||||||
value *= scaleFactor
|
value *= scaleFactor
|
||||||
|
|
||||||
@@ -225,7 +227,24 @@ def format_distance(
|
|||||||
if add_inches or frac:
|
if add_inches or frac:
|
||||||
tx_dist += '"'
|
tx_dist += '"'
|
||||||
else:
|
else:
|
||||||
tx_dist = str("%1.3f" % (value * toInches / inPerFoot)) + " sq. ft."
|
fmt = "%1.3f"
|
||||||
|
sq_feet = round(value * toInches / inPerFoot, 4)
|
||||||
|
tx_dist = ""
|
||||||
|
if area_unit_symbol == " ft2":
|
||||||
|
fmt += area_unit_symbol
|
||||||
|
tx_dist = fmt % sq_feet
|
||||||
|
if area_unit_symbol == " in2":
|
||||||
|
sq_inch = sq_feet * 144
|
||||||
|
fmt += area_unit_symbol
|
||||||
|
tx_dist = fmt % sq_inch
|
||||||
|
if area_unit_symbol == " yd2":
|
||||||
|
sq_yard = sq_feet / 9
|
||||||
|
fmt += area_unit_symbol
|
||||||
|
tx_dist = fmt % sq_yard
|
||||||
|
if area_unit_symbol == " mi2":
|
||||||
|
sq_mile = sq_feet / 27878400
|
||||||
|
fmt += area_unit_symbol
|
||||||
|
tx_dist = fmt % sq_mile
|
||||||
|
|
||||||
# METRIC FORMATTING
|
# METRIC FORMATTING
|
||||||
elif unit_system == "METRIC":
|
elif unit_system == "METRIC":
|
||||||
@@ -287,7 +306,27 @@ def format_distance(
|
|||||||
d_mm = value * (1000)
|
d_mm = value * (1000)
|
||||||
tx_dist = fmt % d_mm
|
tx_dist = fmt % d_mm
|
||||||
if isArea:
|
if isArea:
|
||||||
tx_dist += s_code
|
if area_unit_symbol == " m2":
|
||||||
|
if decimal_places is None:
|
||||||
|
fmt = "%1.3f"
|
||||||
|
if hide_units is False:
|
||||||
|
fmt += area_unit_symbol
|
||||||
|
tx_dist = fmt % value
|
||||||
|
if area_unit_symbol == " cm2":
|
||||||
|
if decimal_places is None:
|
||||||
|
fmt = "%1.1f"
|
||||||
|
if hide_units is False:
|
||||||
|
fmt += area_unit_symbol
|
||||||
|
d_cm = value * (10000)
|
||||||
|
tx_dist = fmt % d_cm
|
||||||
|
if area_unit_symbol == " mm2":
|
||||||
|
if decimal_places is None:
|
||||||
|
fmt = "%1.0f"
|
||||||
|
if hide_units is False:
|
||||||
|
fmt += area_unit_symbol
|
||||||
|
d_cm = value * (1000000)
|
||||||
|
tx_dist = fmt % d_cm
|
||||||
|
|
||||||
else:
|
else:
|
||||||
tx_dist = fmt % value
|
tx_dist = fmt % value
|
||||||
|
|
||||||
|
|||||||
@@ -453,12 +453,14 @@ class Polyline(bonsai.core.tool.Polyline):
|
|||||||
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
|
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
|
||||||
if bpy.context.scene.unit_settings.system == "IMPERIAL":
|
if bpy.context.scene.unit_settings.system == "IMPERIAL":
|
||||||
precision = bpy.context.scene.DocProperties.imperial_precision
|
precision = bpy.context.scene.DocProperties.imperial_precision
|
||||||
|
if is_area:
|
||||||
|
area_unit = bpy.context.scene.BIMProperties.area_unit
|
||||||
|
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get(), unit_type=area_unit)
|
||||||
else:
|
else:
|
||||||
precision = None
|
precision = None
|
||||||
|
|
||||||
value = value if is_area else value / unit_scale
|
|
||||||
return format_distance(
|
return format_distance(
|
||||||
value,
|
value / unit_scale,
|
||||||
precision=precision,
|
precision=precision,
|
||||||
hide_units=False,
|
hide_units=False,
|
||||||
isArea=is_area,
|
isArea=is_area,
|
||||||
|
|||||||
Reference in New Issue
Block a user