Now it's possible to specify the digits number in a drawing. Fix #2993

This commit is contained in:
Massimo Fabbro
2023-04-15 14:35:24 +02:00
committed by Dion Moult
parent d6e1a670b9
commit 4fbf4e7d42
4 changed files with 28 additions and 15 deletions
@@ -5,7 +5,7 @@ FILE_NAME('EPset_Drawing.ifc','2020-01-01T00:00:00',(),(),'EPset_Drawing','EPset
FILE_SCHEMA(('IFC4'));
ENDSEC;
DATA;
#1=IFCPROPERTYSETTEMPLATE('2JhNIvqZrFnAgxfhK0XVQX',$,'EPset_Drawing','',.PSET_OCCURRENCEDRIVEN.,'IfcAnnotation',(#2,#3,#4,#5,#6,#7,#8,#9,#10,#11,#12,#13,#14,#15,#16,#17));
#1=IFCPROPERTYSETTEMPLATE('2JhNIvqZrFnAgxfhK0XVQX',$,'EPset_Drawing','',.PSET_OCCURRENCEDRIVEN.,'IfcAnnotation',(#2,#3,#4,#5,#6,#7,#8,#9,#10,#11,#12,#13,#14,#15,#16,#17,#18));
#2=IFCSIMPLEPROPERTYTEMPLATE('23JavTMk98ZxXhrUEnjAcf',$,'TargetView','',.P_SINGLEVALUE.,'IfcLabel',$,$,$,$,$,.READWRITE.);
#3=IFCSIMPLEPROPERTYTEMPLATE('1yVWUt5H9DAOuu0OaMMLpe',$,'Scale','',.P_SINGLEVALUE.,'IfcLabel',$,$,$,$,$,.READWRITE.);
#4=IFCSIMPLEPROPERTYTEMPLATE('3gsuPBtU93b8f0gg1pjkq6',$,'HumanScale','',.P_SINGLEVALUE.,'IfcLabel',$,$,$,$,$,.READWRITE.);
@@ -22,5 +22,6 @@ DATA;
#15=IFCSIMPLEPROPERTYTEMPLATE('2sHDBuW7P4TROy$hL2w7ct',$,'Patterns','',.P_SINGLEVALUE.,'IfcURIReference',$,$,$,$,$,.READWRITE.);
#16=IFCSIMPLEPROPERTYTEMPLATE('1$xfo9EVb26QLqmPll2_RK',$,'MetricPrecision','',.P_SINGLEVALUE.,'IfcReal',$,$,$,$,$,.READWRITE.);
#17=IFCSIMPLEPROPERTYTEMPLATE('38uAtrp9nD_901NO42zd$7',$,'ImperialPrecision','',.P_SINGLEVALUE.,'IfcLabel',$,$,$,$,$,.READWRITE.);
#18=IFCSIMPLEPROPERTYTEMPLATE('1MX0uffTL6TOvtvEJpxFmk',$,'DecimalsNumber','',.P_SINGLEVALUE.,'IfcInteger',$,$,$,$,$,.READWRITE.);
ENDSEC;
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
# MeasureIt-ARCH is GPL-v3
def format_distance(value, isArea=False, hide_units=True, precision=None):
def format_distance(value, isArea=False, hide_units=True, precision=None, decimals_number=None):
s_code = "\u00b2" # Superscript two THIS IS LEGACY (but being kept for when Area Measurements are re-implimented)
# Get Scene Unit Settings
@@ -204,22 +204,29 @@ def format_distance(value, isArea=False, hide_units=True, precision=None):
if precision:
value = precision * round(float(value) / precision)
if decimals_number:
fmt = "%1." + str(decimals_number) + "f"
#fmt = decimals_number
# Meters
if unit_length == "METERS":
fmt = "%1.3f"
if not decimals_number:
fmt = "%1.3f"
if hide_units is False:
fmt += " m"
tx_dist = fmt % value
# Centimeters
elif unit_length == "CENTIMETERS":
fmt = "%1.1f"
if not decimals_number:
fmt = "%1.1f"
if hide_units is False:
fmt += " cm"
d_cm = value * (100)
tx_dist = fmt % d_cm
# Millimeters
elif unit_length == "MILLIMETERS":
fmt = "%1.0f"
if not decimals_number:
fmt = "%1.0f"
if hide_units is False:
fmt += " mm"
d_mm = value * (1000)
@@ -227,20 +234,21 @@ def format_distance(value, isArea=False, hide_units=True, precision=None):
# Otherwise Use Adaptive Units
else:
if round(value, 2) >= 1.0:
if round(value, 2) >= 1.0 and not decimals_number:
fmt = "%1.3f"
if hide_units is False:
fmt += " m"
tx_dist = fmt % value
else:
if round(value, 2) >= 0.01:
if round(value, 2) >= 0.01 and not decimals_number:
fmt = "%1.1f"
if hide_units is False:
fmt += " cm"
d_cm = value * (100)
tx_dist = fmt % d_cm
else:
fmt = "%1.0f"
if not decimals_number:
fmt = "%1.0f"
if hide_units is False:
fmt += " mm"
d_mm = value * (1000)
@@ -621,8 +621,11 @@ class CreateDrawing(bpy.types.Operator):
precision = ifcopenshell.util.element.get_pset(self.camera_element, "EPset_Drawing", "MetricPrecision")
if not precision:
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")
self.svg_writer.metadata = self.metadata
self.svg_writer.create_blank_svg(svg_path).draw_annotations(annotations, precision).save()
self.svg_writer.create_blank_svg(svg_path).draw_annotations(annotations, precision, decimals_number).save()
return svg_path
@@ -155,8 +155,9 @@ class SvgWriter:
for child in root:
self.svg.defs.add(External(child))
def draw_annotations(self, annotations, precision):
def draw_annotations(self, annotations, precision, decimals_number):
self.precision = precision
self.decimals_number = decimals_number
for element in annotations:
obj = tool.Ifc.get_object(element)
if not obj or element.ObjectType == "DRAWING":
@@ -226,7 +227,7 @@ class SvgWriter:
# TODO: allow metric to be configurable
rl = (matrix_world @ points[0].co.xyz).z
if bpy.context.scene.unit_settings.system == "IMPERIAL":
rl = helper.format_distance(rl, precision=self.precision)
rl = helper.format_distance(rl, precision=self.precision, decimals_number=self.decimals_number)
else:
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
rl /= unit_scale
@@ -782,7 +783,7 @@ class SvgWriter:
# TODO: allow metric to be configurable
rl = (matrix_world @ points[0].co).z
if bpy.context.scene.unit_settings.system == "IMPERIAL":
rl = helper.format_distance(rl, precision=self.precision)
rl = helper.format_distance(rl, precision=self.precision, decimals_number=self.decimals_number)
else:
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
rl /= unit_scale
@@ -976,7 +977,7 @@ class SvgWriter:
text_style = self.get_box_alignment_parameters("center")
radius = (points[-1].co - points[-2].co).length
radius = helper.format_distance(radius, precision=self.precision)
radius = helper.format_distance(radius, precision=self.precision, decimals_number=self.decimals_number)
tag = element.Description or f"R{radius}"
self.svg.add(self.svg.text(tag, insert=tuple(text_position), class_="RADIUS", **text_style))
@@ -1032,7 +1033,7 @@ class SvgWriter:
elif element.ObjectType == "SLOPE_FRACTION":
if angle == 90:
return "-"
return f"{helper.format_distance(rise, precision=self.precision)} / {helper.format_distance(run, precision=self.precision)}"
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)}"
elif element.ObjectType == "SLOPE_PERCENT":
if angle == 90:
return "-"
@@ -1115,7 +1116,7 @@ class SvgWriter:
vector = end - start
perpendicular = Vector((vector.y, -vector.x)).normalized()
dimension = (v1_global - v0_global).length
dimension = helper.format_distance(dimension, precision=self.precision)
dimension = helper.format_distance(dimension, precision=self.precision, decimals_number=self.decimals_number)
sheet_dimension = (end - start).length
# if annotation can't fit offset text to the right of marker