Small fix

This commit is contained in:
Massimo Fabbro
2023-04-15 14:54:06 +02:00
committed by Dion Moult
parent 4fbf4e7d42
commit 8850d78e5a
4 changed files with 19 additions and 20 deletions
@@ -22,6 +22,6 @@ DATA;
#15=IFCSIMPLEPROPERTYTEMPLATE('2sHDBuW7P4TROy$hL2w7ct',$,'Patterns','',.P_SINGLEVALUE.,'IfcURIReference',$,$,$,$,$,.READWRITE.); #15=IFCSIMPLEPROPERTYTEMPLATE('2sHDBuW7P4TROy$hL2w7ct',$,'Patterns','',.P_SINGLEVALUE.,'IfcURIReference',$,$,$,$,$,.READWRITE.);
#16=IFCSIMPLEPROPERTYTEMPLATE('1$xfo9EVb26QLqmPll2_RK',$,'MetricPrecision','',.P_SINGLEVALUE.,'IfcReal',$,$,$,$,$,.READWRITE.); #16=IFCSIMPLEPROPERTYTEMPLATE('1$xfo9EVb26QLqmPll2_RK',$,'MetricPrecision','',.P_SINGLEVALUE.,'IfcReal',$,$,$,$,$,.READWRITE.);
#17=IFCSIMPLEPROPERTYTEMPLATE('38uAtrp9nD_901NO42zd$7',$,'ImperialPrecision','',.P_SINGLEVALUE.,'IfcLabel',$,$,$,$,$,.READWRITE.); #17=IFCSIMPLEPROPERTYTEMPLATE('38uAtrp9nD_901NO42zd$7',$,'ImperialPrecision','',.P_SINGLEVALUE.,'IfcLabel',$,$,$,$,$,.READWRITE.);
#18=IFCSIMPLEPROPERTYTEMPLATE('1MX0uffTL6TOvtvEJpxFmk',$,'DecimalsNumber','',.P_SINGLEVALUE.,'IfcInteger',$,$,$,$,$,.READWRITE.); #18=IFCSIMPLEPROPERTYTEMPLATE('1MX0uffTL6TOvtvEJpxFmk',$,'DecimalPlaces','',.P_SINGLEVALUE.,'IfcInteger',$,$,$,$,$,.READWRITE.);
ENDSEC; ENDSEC;
END-ISO-10303-21; END-ISO-10303-21;
@@ -120,7 +120,7 @@ class BoundingBox:
# This function stolen from https://github.com/kevancress/MeasureIt_ARCH/blob/dcf607ce0896aa2284463c6b4ae9cd023fc54cbe/measureit_arch_baseclass.py # This function stolen from https://github.com/kevancress/MeasureIt_ARCH/blob/dcf607ce0896aa2284463c6b4ae9cd023fc54cbe/measureit_arch_baseclass.py
# MeasureIt-ARCH is GPL-v3 # MeasureIt-ARCH is GPL-v3
def format_distance(value, isArea=False, hide_units=True, precision=None, decimals_number=None): def format_distance(value, isArea=False, hide_units=True, precision=None, decimal_places=None):
s_code = "\u00b2" # Superscript two THIS IS LEGACY (but being kept for when Area Measurements are re-implimented) s_code = "\u00b2" # Superscript two THIS IS LEGACY (but being kept for when Area Measurements are re-implimented)
# Get Scene Unit Settings # Get Scene Unit Settings
@@ -204,20 +204,19 @@ def format_distance(value, isArea=False, hide_units=True, precision=None, decima
if precision: if precision:
value = precision * round(float(value) / precision) value = precision * round(float(value) / precision)
if decimals_number: if decimal_places:
fmt = "%1." + str(decimals_number) + "f" fmt = "%1." + str(decimal_places) + "f"
#fmt = decimals_number
# Meters # Meters
if unit_length == "METERS": if unit_length == "METERS":
if not decimals_number: if not decimal_places:
fmt = "%1.3f" fmt = "%1.3f"
if hide_units is False: if hide_units is False:
fmt += " m" fmt += " m"
tx_dist = fmt % value tx_dist = fmt % value
# Centimeters # Centimeters
elif unit_length == "CENTIMETERS": elif unit_length == "CENTIMETERS":
if not decimals_number: if not decimal_places:
fmt = "%1.1f" fmt = "%1.1f"
if hide_units is False: if hide_units is False:
fmt += " cm" fmt += " cm"
@@ -225,7 +224,7 @@ def format_distance(value, isArea=False, hide_units=True, precision=None, decima
tx_dist = fmt % d_cm tx_dist = fmt % d_cm
# Millimeters # Millimeters
elif unit_length == "MILLIMETERS": elif unit_length == "MILLIMETERS":
if not decimals_number: if not decimal_places:
fmt = "%1.0f" fmt = "%1.0f"
if hide_units is False: if hide_units is False:
fmt += " mm" fmt += " mm"
@@ -234,20 +233,20 @@ def format_distance(value, isArea=False, hide_units=True, precision=None, decima
# Otherwise Use Adaptive Units # Otherwise Use Adaptive Units
else: else:
if round(value, 2) >= 1.0 and not decimals_number: if round(value, 2) >= 1.0 and not decimal_places:
fmt = "%1.3f" fmt = "%1.3f"
if hide_units is False: if hide_units is False:
fmt += " m" fmt += " m"
tx_dist = fmt % value tx_dist = fmt % value
else: else:
if round(value, 2) >= 0.01 and not decimals_number: if round(value, 2) >= 0.01 and not decimal_places:
fmt = "%1.1f" fmt = "%1.1f"
if hide_units is False: if hide_units is False:
fmt += " cm" fmt += " cm"
d_cm = value * (100) d_cm = value * (100)
tx_dist = fmt % d_cm tx_dist = fmt % d_cm
else: else:
if not decimals_number: if not decimal_places:
fmt = "%1.0f" fmt = "%1.0f"
if hide_units is False: if hide_units is False:
fmt += " mm" fmt += " mm"
@@ -622,9 +622,9 @@ class CreateDrawing(bpy.types.Operator):
if not precision: if not precision:
precision = ifcopenshell.util.element.get_pset(self.camera_element, "EPset_Drawing", "ImperialPrecision") precision = ifcopenshell.util.element.get_pset(self.camera_element, "EPset_Drawing", "ImperialPrecision")
decimals_number = ifcopenshell.util.element.get_pset(self.camera_element, "EPset_Drawing", "DecimalsNumber") decimal_places = ifcopenshell.util.element.get_pset(self.camera_element, "EPset_Drawing", "DecimalPlaces")
self.svg_writer.metadata = self.metadata self.svg_writer.metadata = self.metadata
self.svg_writer.create_blank_svg(svg_path).draw_annotations(annotations, precision, decimals_number).save() self.svg_writer.create_blank_svg(svg_path).draw_annotations(annotations, precision, decimal_places).save()
return svg_path return svg_path
@@ -155,9 +155,9 @@ class SvgWriter:
for child in root: for child in root:
self.svg.defs.add(External(child)) self.svg.defs.add(External(child))
def draw_annotations(self, annotations, precision, decimals_number): def draw_annotations(self, annotations, precision, decimal_places):
self.precision = precision self.precision = precision
self.decimals_number = decimals_number self.decimal_places = decimal_places
for element in annotations: for element in annotations:
obj = tool.Ifc.get_object(element) obj = tool.Ifc.get_object(element)
if not obj or element.ObjectType == "DRAWING": if not obj or element.ObjectType == "DRAWING":
@@ -227,7 +227,7 @@ class SvgWriter:
# TODO: allow metric to be configurable # TODO: allow metric to be configurable
rl = (matrix_world @ points[0].co.xyz).z rl = (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, decimals_number=self.decimals_number) rl = helper.format_distance(rl, 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 /= unit_scale
@@ -783,7 +783,7 @@ class SvgWriter:
# TODO: allow metric to be configurable # TODO: allow metric to be configurable
rl = (matrix_world @ points[0].co).z rl = (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, decimals_number=self.decimals_number) rl = helper.format_distance(rl, 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 /= unit_scale
@@ -977,7 +977,7 @@ class SvgWriter:
text_style = self.get_box_alignment_parameters("center") text_style = self.get_box_alignment_parameters("center")
radius = (points[-1].co - points[-2].co).length radius = (points[-1].co - points[-2].co).length
radius = helper.format_distance(radius, precision=self.precision, decimals_number=self.decimals_number) radius = helper.format_distance(radius, precision=self.precision, decimal_places=self.decimal_places)
tag = element.Description or f"R{radius}" tag = element.Description or f"R{radius}"
self.svg.add(self.svg.text(tag, insert=tuple(text_position), class_="RADIUS", **text_style)) self.svg.add(self.svg.text(tag, insert=tuple(text_position), class_="RADIUS", **text_style))
@@ -1033,7 +1033,7 @@ class SvgWriter:
elif element.ObjectType == "SLOPE_FRACTION": elif element.ObjectType == "SLOPE_FRACTION":
if angle == 90: if angle == 90:
return "-" return "-"
return f"{helper.format_distance(rise, precision=self.precision, decimals_number=self.decimals_number)} / {helper.format_distance(run, precision=self.precision, decimals_number=self.decimals_number)}" return f"{helper.format_distance(rise, precision=self.precision, decimal_places=self.decimal_places)} / {helper.format_distance(run, precision=self.precision, decimal_places=self.decimal_places)}"
elif element.ObjectType == "SLOPE_PERCENT": elif element.ObjectType == "SLOPE_PERCENT":
if angle == 90: if angle == 90:
return "-" return "-"
@@ -1116,7 +1116,7 @@ class SvgWriter:
vector = end - start vector = end - start
perpendicular = Vector((vector.y, -vector.x)).normalized() perpendicular = Vector((vector.y, -vector.x)).normalized()
dimension = (v1_global - v0_global).length dimension = (v1_global - v0_global).length
dimension = helper.format_distance(dimension, precision=self.precision, decimals_number=self.decimals_number) dimension = helper.format_distance(dimension, precision=self.precision, decimal_places=self.decimal_places)
sheet_dimension = (end - start).length sheet_dimension = (end - start).length
# if annotation can't fit offset text to the right of marker # if annotation can't fit offset text to the right of marker