mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-18 14:31:39 +00:00
Replace hard-coded unit scale with ifcopenshell.util.unit.calculate_unit_scale
This commit is contained in:
@@ -78,18 +78,11 @@ def get_wall_preview_data(context, relating_type):
|
|||||||
elif offset_type == "INTERIOR":
|
elif offset_type == "INTERIOR":
|
||||||
offset = -thickness
|
offset = -thickness
|
||||||
|
|
||||||
unit_system = tool.Drawing.get_unit_system()
|
|
||||||
factor = 1
|
|
||||||
if unit_system == "IMPERIAL":
|
|
||||||
factor = 3.28084
|
|
||||||
if unit_system == "METRIC":
|
|
||||||
unit_length = context.scene.unit_settings.length_unit
|
|
||||||
if unit_length == "MILLIMETERS":
|
|
||||||
factor = 1000
|
|
||||||
|
|
||||||
# For the model properties, the offset value should just be converted
|
# For the model properties, the offset value should just be converted
|
||||||
# However, for the wall preview logic that follows, offset and thickness must change direction
|
# However, for the wall preview logic that follows, offset and thickness must change direction
|
||||||
model_props.offset = offset * factor
|
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
|
||||||
|
model_props.offset = offset / unit_scale
|
||||||
thickness *= direction
|
thickness *= direction
|
||||||
offset *= direction
|
offset *= direction
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
import bpy
|
import bpy
|
||||||
import bmesh
|
import bmesh
|
||||||
import math
|
import math
|
||||||
|
import ifcopenshell
|
||||||
import bonsai.core.tool
|
import bonsai.core.tool
|
||||||
import bonsai.tool as tool
|
import bonsai.tool as tool
|
||||||
from bonsai.bim.module.drawing.helper import format_distance
|
from bonsai.bim.module.drawing.helper import format_distance
|
||||||
@@ -416,23 +417,20 @@ class Polyline(bonsai.core.tool.Polyline):
|
|||||||
dimension = args[i]
|
dimension = args[i]
|
||||||
if len(args) > i + 1:
|
if len(args) > i + 1:
|
||||||
expression = args[i + 1]
|
expression = args[i + 1]
|
||||||
return expression(dimension) * factor
|
return expression(dimension) * unit_scale
|
||||||
else:
|
else:
|
||||||
return dimension * factor
|
return dimension * unit_scale
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
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":
|
||||||
parser = Lark(grammar_imperial)
|
parser = Lark(grammar_imperial)
|
||||||
factor = 0.3048
|
|
||||||
else:
|
else:
|
||||||
parser = Lark(grammar_metric)
|
parser = Lark(grammar_metric)
|
||||||
factor = 1
|
|
||||||
if bpy.context.scene.unit_settings.length_unit == "MILLIMETERS":
|
|
||||||
factor = 0.001
|
|
||||||
|
|
||||||
if input_type == "A":
|
if input_type == "A":
|
||||||
parser = Lark(grammar_metric)
|
parser = Lark(grammar_metric)
|
||||||
factor = 1
|
unit_scale = 1
|
||||||
|
|
||||||
parse_tree = parser.parse(input_number)
|
parse_tree = parser.parse(input_number)
|
||||||
|
|
||||||
@@ -445,18 +443,14 @@ class Polyline(bonsai.core.tool.Polyline):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def format_input_ui_units(cls, value: float, is_area: bool = False) -> str:
|
def format_input_ui_units(cls, value: float, is_area: bool = False) -> str:
|
||||||
unit_system = tool.Drawing.get_unit_system()
|
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
|
||||||
if unit_system == "IMPERIAL":
|
if bpy.context.scene.unit_settings.system == "IMPERIAL":
|
||||||
precision = bpy.context.scene.DocProperties.imperial_precision
|
precision = bpy.context.scene.DocProperties.imperial_precision
|
||||||
factor = 3.28084
|
|
||||||
else:
|
else:
|
||||||
precision = None
|
precision = None
|
||||||
factor = 1
|
|
||||||
if bpy.context.scene.unit_settings.length_unit == "MILLIMETERS":
|
|
||||||
factor = 1000
|
|
||||||
|
|
||||||
return format_distance(
|
return format_distance(
|
||||||
value * factor,
|
value / unit_scale,
|
||||||
precision=precision,
|
precision=precision,
|
||||||
hide_units=False,
|
hide_units=False,
|
||||||
isArea=is_area,
|
isArea=is_area,
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
|
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
|
import ifcopenshell
|
||||||
import bonsai.core.tool
|
import bonsai.core.tool
|
||||||
import bonsai.tool as tool
|
import bonsai.tool as tool
|
||||||
from bonsai.bim.module.model.decorator import PolylineDecorator
|
from bonsai.bim.module.model.decorator import PolylineDecorator
|
||||||
@@ -51,8 +52,9 @@ class Snap(bonsai.core.tool.Snap):
|
|||||||
distances = [3, 5, 15, 30]
|
distances = [3, 5, 15, 30]
|
||||||
|
|
||||||
unit_system = tool.Drawing.get_unit_system()
|
unit_system = tool.Drawing.get_unit_system()
|
||||||
|
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
|
||||||
if unit_system == "IMPERIAL":
|
if unit_system == "IMPERIAL":
|
||||||
factor = 3.28084
|
factor = unit_scale
|
||||||
fractions = [24, 12, 6, 2]
|
fractions = [24, 12, 6, 2]
|
||||||
ortho_threshold = [-10.0, -4.75, -2.2, -0.75]
|
ortho_threshold = [-10.0, -4.75, -2.2, -0.75]
|
||||||
distances = [3, 6, 10, 20]
|
distances = [3, 6, 10, 20]
|
||||||
@@ -60,29 +62,29 @@ class Snap(bonsai.core.tool.Snap):
|
|||||||
increment = None
|
increment = None
|
||||||
if rv3d.view_perspective == "PERSP":
|
if rv3d.view_perspective == "PERSP":
|
||||||
if rv3d.view_distance < distances[0]:
|
if rv3d.view_distance < distances[0]:
|
||||||
increment = (1 / fractions[0]) / factor
|
increment = (1 / fractions[0]) * factor
|
||||||
elif distances[0] < rv3d.view_distance < distances[1]:
|
elif distances[0] < rv3d.view_distance < distances[1]:
|
||||||
increment = (1 / fractions[1]) / factor
|
increment = (1 / fractions[1]) * factor
|
||||||
elif distances[1] < rv3d.view_distance < distances[2]:
|
elif distances[1] < rv3d.view_distance < distances[2]:
|
||||||
increment = (1 / fractions[2]) / factor
|
increment = (1 / fractions[2]) * factor
|
||||||
elif distances[2] < rv3d.view_distance < distances[3]:
|
elif distances[2] < rv3d.view_distance < distances[3]:
|
||||||
increment = (1 / fractions[3]) / factor
|
increment = (1 / fractions[3]) * factor
|
||||||
else:
|
else:
|
||||||
increment = 1 / factor
|
increment = 1 * factor
|
||||||
if rv3d.view_perspective == "ORTHO" or (
|
if rv3d.view_perspective == "ORTHO" or (
|
||||||
rv3d.view_perspective == "CAMERA" and context.scene.camera.data.type == "ORTHO"
|
rv3d.view_perspective == "CAMERA" and context.scene.camera.data.type == "ORTHO"
|
||||||
):
|
):
|
||||||
window_scale = rv3d.window_matrix.to_scale()
|
window_scale = rv3d.window_matrix.to_scale()
|
||||||
if window_scale[1] < ortho_threshold[0]:
|
if window_scale[1] < ortho_threshold[0]:
|
||||||
increment = (1 / fractions[0]) / factor
|
increment = (1 / fractions[0]) * factor
|
||||||
elif ortho_threshold[0] < window_scale[1] < ortho_threshold[1]:
|
elif ortho_threshold[0] < window_scale[1] < ortho_threshold[1]:
|
||||||
increment = (1 / fractions[1]) / factor
|
increment = (1 / fractions[1]) * factor
|
||||||
elif ortho_threshold[1] < window_scale[1] < ortho_threshold[2]:
|
elif ortho_threshold[1] < window_scale[1] < ortho_threshold[2]:
|
||||||
increment = (1 / fractions[2]) / factor
|
increment = (1 / fractions[2]) * factor
|
||||||
elif ortho_threshold[2] < window_scale[1] < ortho_threshold[3]:
|
elif ortho_threshold[2] < window_scale[1] < ortho_threshold[3]:
|
||||||
increment = (1 / fractions[3]) / factor
|
increment = (1 / fractions[3]) * factor
|
||||||
else:
|
else:
|
||||||
increment = 1 / factor
|
increment = 1 * factor
|
||||||
|
|
||||||
return increment
|
return increment
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user