Skip to content
This repository was archived by the owner on Nov 24, 2024. It is now read-only.

Commit 9c367d1

Browse files
committed
fixed neg values in format_distance & section/plan level IfcOpenShell#3175
1 parent db18a81 commit 9c367d1

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

src/blenderbim/blenderbim/bim/module/drawing/helper.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,14 @@ def format_distance(
154154
# Separate ft and inches
155155
# Unless Inches are the specified Length Unit
156156
if unit_length != "INCHES":
157-
feet = math.floor(decInches / inPerFoot)
157+
feet = int(decInches / inPerFoot) # remove decimal
158158
decInches -= feet * inPerFoot
159159
else:
160160
feet = 0
161161

162162
# Separate Fractional Inches
163-
inches = math.floor(decInches)
163+
decInches = abs(decInches) # ignore the sign for inches
164+
inches = math.floor(decInches) # remove decimal
164165
if inches != 0:
165166
frac = round(base * (decInches - inches))
166167
else:

src/blenderbim/blenderbim/bim/module/drawing/svgwriter.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,17 +225,24 @@ def draw_section_level_annotation(self, obj):
225225
)
226226
)
227227
# TODO: allow metric to be configurable
228-
rl = (matrix_world @ points[0].co.xyz).z
228+
rl_value = (matrix_world @ points[0].co.xyz).z
229229
if bpy.context.scene.unit_settings.system == "IMPERIAL":
230-
rl = helper.format_distance(rl, precision=self.precision, decimal_places=self.decimal_places)
230+
rl = helper.format_distance(rl_value, precision=self.precision, decimal_places=self.decimal_places)
231231
else:
232232
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
233-
rl /= unit_scale
233+
rl = rl_value / unit_scale
234234
rl = ifcopenshell.util.geolocation.auto_z2e(tool.Ifc.get(), rl)
235235
rl *= unit_scale
236236
rl = "{:.3f}m".format(rl)
237237
text_style = SvgWriter.get_box_alignment_parameters("bottom-left")
238-
self.svg.add(self.svg.text(f"RL +{rl}", insert=tuple(text_position), class_="SECTIONLEVEL", **text_style))
238+
self.svg.add(
239+
self.svg.text(
240+
"RL {}{}".format("" if rl_value < 0 else "+", rl),
241+
insert=tuple(text_position),
242+
class_="SECTIONLEVEL",
243+
**text_style,
244+
)
245+
)
239246
if tag:
240247
self.svg.add(self.svg.text(tag, insert=(text_position[0], text_position[1] - 5), **text_style))
241248

@@ -787,12 +794,12 @@ def draw_plan_level_annotation(self, obj):
787794
)
788795
)
789796
# TODO: allow metric to be configurable
790-
rl = (matrix_world @ points[0].co).z
797+
rl_value = (matrix_world @ points[0].co).z
791798
if bpy.context.scene.unit_settings.system == "IMPERIAL":
792-
rl = helper.format_distance(rl, precision=self.precision, decimal_places=self.decimal_places)
799+
rl = helper.format_distance(rl_value, precision=self.precision, decimal_places=self.decimal_places)
793800
else:
794801
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
795-
rl /= unit_scale
802+
rl = rl_value / unit_scale
796803
rl = ifcopenshell.util.geolocation.auto_z2e(tool.Ifc.get(), rl)
797804
rl *= unit_scale
798805
rl = "{:.3f}m".format(rl)
@@ -801,7 +808,7 @@ def draw_plan_level_annotation(self, obj):
801808
text_style = SvgWriter.get_box_alignment_parameters(box_alignment)
802809
self.svg.add(
803810
self.svg.text(
804-
"RL +{}".format(rl),
811+
"RL {}{}".format("" if rl_value < 0 else "+", rl),
805812
insert=tuple(text_position),
806813
class_="PLANLEVEL",
807814
**text_style,

0 commit comments

Comments
 (0)