mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 14:41:25 +00:00
fixed neg values in format_distance & section/plan level #3175
This commit is contained in:
@@ -154,13 +154,14 @@ def format_distance(
|
|||||||
# Separate ft and inches
|
# Separate ft and inches
|
||||||
# Unless Inches are the specified Length Unit
|
# Unless Inches are the specified Length Unit
|
||||||
if unit_length != "INCHES":
|
if unit_length != "INCHES":
|
||||||
feet = math.floor(decInches / inPerFoot)
|
feet = int(decInches / inPerFoot) # remove decimal
|
||||||
decInches -= feet * inPerFoot
|
decInches -= feet * inPerFoot
|
||||||
else:
|
else:
|
||||||
feet = 0
|
feet = 0
|
||||||
|
|
||||||
# Separate Fractional Inches
|
# Separate Fractional Inches
|
||||||
inches = math.floor(decInches)
|
decInches = abs(decInches) # ignore the sign for inches
|
||||||
|
inches = math.floor(decInches) # remove decimal
|
||||||
if inches != 0:
|
if inches != 0:
|
||||||
frac = round(base * (decInches - inches))
|
frac = round(base * (decInches - inches))
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -225,17 +225,24 @@ class SvgWriter:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
# TODO: allow metric to be configurable
|
# TODO: allow metric to be configurable
|
||||||
rl = (matrix_world @ points[0].co.xyz).z
|
rl_value = (matrix_world @ points[0].co.xyz).z
|
||||||
if bpy.context.scene.unit_settings.system == "IMPERIAL":
|
if bpy.context.scene.unit_settings.system == "IMPERIAL":
|
||||||
rl = helper.format_distance(rl, precision=self.precision, decimal_places=self.decimal_places)
|
rl = helper.format_distance(rl_value, precision=self.precision, decimal_places=self.decimal_places)
|
||||||
else:
|
else:
|
||||||
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
|
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
|
||||||
rl /= unit_scale
|
rl = rl_value / unit_scale
|
||||||
rl = ifcopenshell.util.geolocation.auto_z2e(tool.Ifc.get(), rl)
|
rl = ifcopenshell.util.geolocation.auto_z2e(tool.Ifc.get(), rl)
|
||||||
rl *= unit_scale
|
rl *= unit_scale
|
||||||
rl = "{:.3f}m".format(rl)
|
rl = "{:.3f}m".format(rl)
|
||||||
text_style = SvgWriter.get_box_alignment_parameters("bottom-left")
|
text_style = SvgWriter.get_box_alignment_parameters("bottom-left")
|
||||||
self.svg.add(self.svg.text(f"RL +{rl}", insert=tuple(text_position), class_="SECTIONLEVEL", **text_style))
|
self.svg.add(
|
||||||
|
self.svg.text(
|
||||||
|
"RL {}{}".format("" if rl_value < 0 else "+", rl),
|
||||||
|
insert=tuple(text_position),
|
||||||
|
class_="SECTIONLEVEL",
|
||||||
|
**text_style,
|
||||||
|
)
|
||||||
|
)
|
||||||
if tag:
|
if tag:
|
||||||
self.svg.add(self.svg.text(tag, insert=(text_position[0], text_position[1] - 5), **text_style))
|
self.svg.add(self.svg.text(tag, insert=(text_position[0], text_position[1] - 5), **text_style))
|
||||||
|
|
||||||
@@ -787,12 +794,12 @@ class SvgWriter:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
# TODO: allow metric to be configurable
|
# TODO: allow metric to be configurable
|
||||||
rl = (matrix_world @ points[0].co).z
|
rl_value = (matrix_world @ points[0].co).z
|
||||||
if bpy.context.scene.unit_settings.system == "IMPERIAL":
|
if bpy.context.scene.unit_settings.system == "IMPERIAL":
|
||||||
rl = helper.format_distance(rl, precision=self.precision, decimal_places=self.decimal_places)
|
rl = helper.format_distance(rl_value, precision=self.precision, decimal_places=self.decimal_places)
|
||||||
else:
|
else:
|
||||||
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
|
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
|
||||||
rl /= unit_scale
|
rl = rl_value / unit_scale
|
||||||
rl = ifcopenshell.util.geolocation.auto_z2e(tool.Ifc.get(), rl)
|
rl = ifcopenshell.util.geolocation.auto_z2e(tool.Ifc.get(), rl)
|
||||||
rl *= unit_scale
|
rl *= unit_scale
|
||||||
rl = "{:.3f}m".format(rl)
|
rl = "{:.3f}m".format(rl)
|
||||||
@@ -801,7 +808,7 @@ class SvgWriter:
|
|||||||
text_style = SvgWriter.get_box_alignment_parameters(box_alignment)
|
text_style = SvgWriter.get_box_alignment_parameters(box_alignment)
|
||||||
self.svg.add(
|
self.svg.add(
|
||||||
self.svg.text(
|
self.svg.text(
|
||||||
"{}".format(rl),
|
"RL {}{}".format("" if rl_value < 0 else "+", rl),
|
||||||
insert=tuple(text_position),
|
insert=tuple(text_position),
|
||||||
class_="PLANLEVEL",
|
class_="PLANLEVEL",
|
||||||
**text_style,
|
**text_style,
|
||||||
|
|||||||
Reference in New Issue
Block a user