Fix #2955. Drawings can now set a precision.

This commit is contained in:
Dion Moult
2023-04-13 22:20:18 +10:00
parent 33bd6099ee
commit 03d9efb790
6 changed files with 17 additions and 36 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));
#1=IFCPROPERTYSETTEMPLATE('2JhNIvqZrFnAgxfhK0XVQX',$,'EPset_Drawing','',.PSET_OCCURRENCEDRIVEN.,'IfcAnnotation',(#2,#3,#4,#5,#6,#7,#8,#9,#10,#11,#12,#13,#14,#15,#16,#17));
#2=IFCSIMPLEPROPERTYTEMPLATE('23JavTMk98ZxXhrUEnjAcf',$,'TargetView','',.P_SINGLEVALUE.,'IfcLabel',$,$,$,$,$,.READWRITE.);
#3=IFCSIMPLEPROPERTYTEMPLATE('1yVWUt5H9DAOuu0OaMMLpe',$,'Scale','',.P_SINGLEVALUE.,'IfcLabel',$,$,$,$,$,.READWRITE.);
#4=IFCSIMPLEPROPERTYTEMPLATE('3gsuPBtU93b8f0gg1pjkq6',$,'HumanScale','',.P_SINGLEVALUE.,'IfcLabel',$,$,$,$,$,.READWRITE.);
@@ -20,5 +20,7 @@ DATA;
#13=IFCSIMPLEPROPERTYTEMPLATE('3mRF52q81FQB$h4oTh7M45',$,'Markers','',.P_SINGLEVALUE.,'IfcURIReference',$,$,$,$,$,.READWRITE.);
#14=IFCSIMPLEPROPERTYTEMPLATE('1rhr_0N3LDtuORcEJP0KXM',$,'Symbols','',.P_SINGLEVALUE.,'IfcURIReference',$,$,$,$,$,.READWRITE.);
#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.);
ENDSEC;
END-ISO-10303-21;
@@ -120,9 +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
# In the future I will need to rewrite this to allow the user to have custom
# settings for each annotation object, not read from Blender.
def format_distance(value, isArea=False, hide_units=True):
def format_distance(value, isArea=False, hide_units=True, precision=None):
s_code = "\u00b2" # Superscript two THIS IS LEGACY (but being kept for when Area Measurements are re-implimented)
# Get Scene Unit Settings
@@ -141,8 +139,7 @@ def format_distance(value, isArea=False, hide_units=True):
# Imperial Formatting
if unit_system == "IMPERIAL":
precision = bpy.context.scene.BIMProperties.imperial_precision
if precision == "NONE":
if not precision:
precision = 256
elif precision == "1":
precision = 1
@@ -204,8 +201,7 @@ def format_distance(value, isArea=False, hide_units=True):
# METRIC FORMATTING
elif unit_system == "METRIC":
precision = bpy.context.scene.BIMProperties.metric_precision
if precision != 0:
if precision:
value = precision * round(float(value) / precision)
# Meters
@@ -610,8 +610,11 @@ class CreateDrawing(bpy.types.Operator):
annotations = sorted(elements, key=lambda a: tool.Drawing.get_annotation_z_index(a))
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")
self.svg_writer.metadata = tool.Drawing.get_drawing_metadata(self.camera_element)
self.svg_writer.create_blank_svg(svg_path).draw_annotations(annotations).save()
self.svg_writer.create_blank_svg(svg_path).draw_annotations(annotations, precision).save()
return svg_path
@@ -155,7 +155,8 @@ class SvgWriter:
for child in root:
self.svg.defs.add(External(child))
def draw_annotations(self, annotations):
def draw_annotations(self, annotations, precision):
self.precision = precision
for element in annotations:
obj = tool.Ifc.get_object(element)
if not obj or element.ObjectType == "DRAWING":
@@ -225,7 +226,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)
rl = helper.format_distance(rl, precision=self.precision)
else:
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
rl /= unit_scale
@@ -796,7 +797,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)
rl = helper.format_distance(rl, precision=self.precision)
else:
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
rl /= unit_scale
@@ -1005,7 +1006,7 @@ class SvgWriter:
}
radius = (points[-1].co - points[-2].co).length
radius = helper.format_distance(radius)
radius = helper.format_distance(radius, precision=self.precision)
tag = element.Description or f"R{radius}"
self.svg.add(self.svg.text(tag, insert=tuple(text_position), class_="RADIUS", **text_style))
@@ -1061,7 +1062,7 @@ class SvgWriter:
elif element.ObjectType == "SLOPE_FRACTION":
if angle == 90:
return "-"
return f"{helper.format_distance(rise)} / {helper.format_distance(run)}"
return f"{helper.format_distance(rise, precision=self.precision)} / {helper.format_distance(run, precision=self.precision)}"
elif element.ObjectType == "SLOPE_PERCENT":
if angle == 90:
return "-"
@@ -1137,7 +1138,7 @@ class SvgWriter:
vector = end - start
perpendicular = Vector((vector.y, -vector.x)).normalized()
dimension = (v1_global - v0_global).length
dimension = helper.format_distance(dimension)
dimension = helper.format_distance(dimension, precision=self.precision)
sheet_dimension = ((end * self.svg_scale) - (start * self.svg_scale)).length
if sheet_dimension < 5: # annotation can't fit
# offset text to right of marker
-16
View File
@@ -372,22 +372,6 @@ class BIMProperties(PropertyGroup):
],
name="IFC Volume Unit",
)
metric_precision: FloatProperty(default=0, name="Drawing Metric Precision")
imperial_precision: EnumProperty(
items=[
("NONE", "No rounding", ""),
("1", 'Nearest 1"', ""),
("1/2", 'Nearest 1/2"', ""),
("1/4", 'Nearest 1/4"', ""),
("1/8", 'Nearest 1/8"', ""),
("1/16", 'Nearest 1/16"', ""),
("1/32", 'Nearest 1/32"', ""),
("1/64", 'Nearest 1/64"', ""),
("1/128", 'Nearest 1/128"', ""),
("1/256", 'Nearest 1/256"', ""),
],
name="Drawing Imperial Precision",
)
class IfcParameter(PropertyGroup):
-5
View File
@@ -213,11 +213,6 @@ def ifc_units(self, context):
row.prop(props, "area_unit")
row = layout.row()
row.prop(props, "volume_unit")
row = layout.row()
if scene.unit_settings.system == "IMPERIAL":
row.prop(props, "imperial_precision")
else:
row.prop(props, "metric_precision")
# Scene panel groups