Compare commits

...

1 Commits

Author SHA1 Message Date
Ryan Schultz 394559ff11 snapshot 2025-01-01 23:42:25 -06:00
5 changed files with 113 additions and 15 deletions
@@ -28,11 +28,13 @@ DATA;
#21=IFCSIMPLEPROPERTYTEMPLATE('1UDakJ5_f7kBhggNSW4$h5',$,'SymbolsPath','Default symbols SVG',.P_SINGLEVALUE.,'IfcLabel',$,$,$,$,$,.READWRITE.);
#22=IFCSIMPLEPROPERTYTEMPLATE('0d53LEtgLDQxnv__NfgH7i',$,'PatternsPath','Default patterns SVG',.P_SINGLEVALUE.,'IfcLabel',$,$,$,$,$,.READWRITE.);
#23=IFCSIMPLEPROPERTYTEMPLATE('26qFNMv7nCHgU6Jd7Anga5',$,'ShadingStylesPath','Default shading styles',.P_SINGLEVALUE.,'IfcLabel',$,$,$,$,$,.READWRITE.);
#24=IFCPROPERTYSETTEMPLATE('0I9merLinF5Ap$aZwaclgm',$,'BBIM_Dimension','',.PSET_TYPEDRIVENOVERRIDE.,'IfcAnnotation/DIMENSION,IfcTypeProduct',(#25,#26,#27,#28));
#24=IFCPROPERTYSETTEMPLATE('0I9merLinF5Ap$aZwaclgm',$,'BBIM_Dimension','',.PSET_TYPEDRIVENOVERRIDE.,'IfcAnnotation/DIMENSION,IfcTypeProduct',(#25,#26,#27,#28,#30));
#25=IFCSIMPLEPROPERTYTEMPLATE('1rL2AbQsXD8RbpoWH5pYOV',$,'ShowDescriptionOnly','Hide the measurement values and show only annotation description',.P_SINGLEVALUE.,'IfcBoolean',$,$,$,$,$,.READWRITE.);
#26=IFCSIMPLEPROPERTYTEMPLATE('0SVyOfB0rC2xNfdRYf3XvY',$,'SuppressZeroInches','Suppress 0 inch values in dimension annotation text (for example: 12'' - 0" -> 12'')',.P_SINGLEVALUE.,'IfcBoolean',$,$,$,$,$,.READWRITE.);
#27=IFCSIMPLEPROPERTYTEMPLATE('2bUmj458PBqPAtUoI3MXsb',$,'TextPrefix','Text to add before annotation measurement value',.P_SINGLEVALUE.,'IfcLabel',$,$,$,$,$,.READWRITE.);
#28=IFCSIMPLEPROPERTYTEMPLATE('0bnzttUb9BPuN597uNTXOE',$,'TextSuffix','Text to add after annotation measurement value',.P_SINGLEVALUE.,'IfcLabel',$,$,$,$,$,.READWRITE.);
#29=IFCSIMPLEPROPERTYTEMPLATE('2pJmUDpB50VBdCOib1zcJJ',$,'Newline_At','',.P_SINGLEVALUE.,'IfcInteger',$,$,$,$,$,.READWRITE.);
#30=IFCSIMPLEPROPERTYTEMPLATE('2TJn72t_v2cvBUG916Dpev',$,'Unit_Primary','Dimension''s primary unit',.P_ENUMERATEDVALUE.,'IfcText',$,#31,$,$,$,.READWRITE.);
#31=IFCPROPERTYENUMERATION('Unit_Primary',(IFCTEXT('Feet and Inches - Fractional'),IFCTEXT('Feet - Decimal'),IFCTEXT('Inches - Fractional'),IFCTEXT('Inches - Decimal'),IFCTEXT('Meters'),IFCTEXT('Decimeters'),IFCTEXT('Centimeters'),IFCTEXT('Millimeters')),$);
ENDSEC;
END-ISO-10303-21;
@@ -376,6 +376,11 @@ class DecoratorData:
fill_bg = True
pset_data = ifcopenshell.util.element.get_pset(element, "BBIM_Dimension") or {}
unit_primary = pset_data.get("Unit_Primary", "")
if not unit_primary:
unit_primary = ''
else:
unit_primary = pset_data.get("Unit_Primary", "")[0]
show_description_only = pset_data.get("ShowDescriptionOnly", False)
suppress_zero_inches = pset_data.get("SuppressZeroInches", False)
text_prefix = pset_data.get("TextPrefix", None) or ""
@@ -383,6 +388,7 @@ class DecoratorData:
dimension_data = {
"dimension_style": dimension_style,
"unit_primary": unit_primary,
"show_description_only": show_description_only,
"suppress_zero_inches": suppress_zero_inches,
"text_prefix": text_prefix,
@@ -475,6 +475,7 @@ class BaseDecorator:
blf.disable(font_id, blf.SHADOW)
def draw_dimension_text(self, context, get_text, description, dimension_data, **draw_label_kwargs):
unit_primary = dimension_data["unit_primary"]
prefix = dimension_data["text_prefix"]
suffix = dimension_data["text_suffix"]
show_description_only = dimension_data["show_description_only"]
@@ -493,14 +494,37 @@ class BaseDecorator:
self.draw_label(context, text=text, line_no=line_number_start, multiline=True, **draw_label_kwargs)
@lru_cache(maxsize=None)
def format_value(self, context, value):
def format_value(self, context, value, unit_primary):
drawing_pset_data = DrawingsData.data["active_drawing_pset_data"]
precision = drawing_pset_data.get("MetricPrecision", None)
if not precision:
unit_system = bpy.context.scene.unit_settings.system
imperial_units = {
"Inches - Decimal",
"Feet - Decimal",
"Feet and Inches - Fractional",
"Inches - Fractional",
}
metric_units = {
"Meters",
"Decimeters",
"Centimeters",
"Millimeters"
}
if (
unit_system == "IMPERIAL"
and unit_primary in imperial_units
and unit_primary not in metric_units
):
precision = drawing_pset_data.get("ImperialPrecision", None)
else:
precision = drawing_pset_data.get("MetricPrecision", None)
decimal_places = drawing_pset_data.get("DecimalPlaces", None)
return format_distance(value, precision=precision, decimal_places=decimal_places)
return format_distance(value, precision=precision, decimal_places=decimal_places, unit_primary=unit_primary)
def draw_asterisk(self, context: bpy.types.Context, pos: Vector, rotation: float = 0.0, scale: float = 1.0) -> None:
"""`pos` is a world space position\n
@@ -709,6 +733,7 @@ class DimensionDecorator(BaseDecorator):
element = tool.Ifc.get_entity(obj)
description = element.Description
dimension_data = DecoratorData.get_dimension_data(obj)
unit_primary = dimension_data["unit_primary"]
show_description_only = dimension_data["show_description_only"]
text_prefix = dimension_data["text_prefix"]
text_suffix = dimension_data["text_suffix"]
@@ -735,7 +760,7 @@ class DimensionDecorator(BaseDecorator):
if not show_description_only:
length = (v1 - v0).length
text = self.format_value(context, length)
text = self.format_value(context, length, unit_primary)
if isinstance(self, DiameterDecorator):
text = "D" + text
text = text_prefix + text + text_suffix
@@ -937,6 +962,7 @@ class RadiusDecorator(BaseDecorator):
element = tool.Ifc.get_entity(obj)
description = element.Description
dimension_data = DecoratorData.get_dimension_data(obj)
unit_primary = dimension_data["unit_primary"]
viewportDrawingScale = self.get_viewport_drawing_scale(context)
text_offset = 20 * viewportDrawingScale
@@ -944,7 +970,7 @@ class RadiusDecorator(BaseDecorator):
def get_text():
length = (spline_points[-1] - spline_points[-2]).length
return "R" + self.format_value(context, length)
return "R" + self.format_value(context, length, unit_primary)
self.draw_dimension_text(
context, get_text, description, dimension_data, pos=pos, text_dir=Vector((1, 0)), box_alignment="center"
+69 -8
View File
@@ -124,6 +124,7 @@ def format_distance(
value,
isArea=False,
hide_units=True,
unit_primary = None,
precision=None,
decimal_places=None,
suppress_zero_inches=False,
@@ -139,7 +140,24 @@ def format_distance(
value *= scaleFactor
# Imperial Formatting
if unit_system == "IMPERIAL":
imperial_units = {
"Inches - Decimal",
"Feet - Decimal",
"Feet and Inches - Fractional",
"Inches - Fractional",
}
metric_units = {
"Meters",
"Decimeters",
"Centimeters",
"Millimeters"
}
if (
(unit_system == "IMPERIAL" or unit_primary in imperial_units)
and unit_primary not in metric_units
):
if in_unit_length:
if unit_length == "INCHES":
toInches = 1
@@ -164,12 +182,19 @@ def format_distance(
# Separate ft and inches
# Unless Inches are the specified Length Unit
if unit_length != "INCHES":
if (
unit_length != "INCHES"
and unit_primary != "Feet - Decimal"
and unit_system != "METRIC"
or unit_primary == "Feet and Inches - Fractional"
):
feet = int(decInches / inPerFoot) # remove decimal
decInches -= feet * inPerFoot
else:
feet = 0
# Separate Fractional Inches
decInches = abs(decInches) # ignore the sign for inches
inches = math.floor(decInches) # remove decimal
@@ -224,12 +249,33 @@ def format_distance(
tx_dist += str(frac) + "/" + str(base)
if add_inches or frac:
tx_dist += '"'
if unit_primary == "Inches - Decimal":
value = decInches
if decimal_places:
value = round(value, decimal_places)
tx_dist = f"{str(value)}\""
if unit_primary == "Feet - Decimal":
value = decInches/12
if decimal_places:
value = round(value, decimal_places)
tx_dist = f"{str(value)}\'"
else:
tx_dist = str("%1.3f" % (value * toInches / inPerFoot)) + " sq. ft."
# METRIC FORMATTING
elif unit_system == "METRIC":
if in_unit_length:
elif (
unit_system == "METRIC"
or unit_primary == "Meters"
or unit_primary == "Decimeters"
or unit_primary == "Centimeters"
or unit_primary == "Millimeters"
):
if(
in_unit_length
):
if unit_length == "CENTIMETERS":
value = value / 100
if unit_length == "MILLIMETERS":
@@ -242,14 +288,27 @@ def format_distance(
fmt = "%1." + str(decimal_places) + "f"
# Meters
if unit_length == "METERS":
if (
(unit_length == "METERS" or unit_primary == "Meters")
and unit_primary != "Decimeters"
and unit_primary != "Centimeters"
and unit_primary != "Millimeters"
):
if decimal_places is None:
fmt = "%1.3f"
if hide_units is False:
fmt += " m"
tx_dist = fmt % value
# Centimeters
elif unit_length == "CENTIMETERS":
# Decimeters
elif unit_length == "DECIMETERS" or unit_primary == "Decimeters":
if decimal_places is None:
fmt = "%1.1f"
if hide_units is False:
fmt += " cm"
d_cm = value * (10)
tx_dist = fmt % d_cm
# Centimeters
elif unit_length == "CENTIMETERS" or unit_primary == "Centimeters":
if decimal_places is None:
fmt = "%1.1f"
if hide_units is False:
@@ -257,7 +316,7 @@ def format_distance(
d_cm = value * (100)
tx_dist = fmt % d_cm
# Millimeters
elif unit_length == "MILLIMETERS":
elif unit_length == "MILLIMETERS" or unit_primary == "Millimeters":
if decimal_places is None:
fmt = "%1.0f"
if hide_units is False:
@@ -291,6 +350,8 @@ def format_distance(
else:
tx_dist = fmt % value
return tx_dist
@@ -1273,6 +1273,7 @@ class SvgWriter:
v1_global,
classes,
dimension_text=dimension_text,
unit_primary = dimension_data["unit_primary"],
show_description_only=dimension_data["show_description_only"],
suppress_zero_inches=dimension_data["suppress_zero_inches"],
text_prefix=dimension_data["text_prefix"],
@@ -1299,6 +1300,7 @@ class SvgWriter:
classes,
dimension_text=None,
text_format=lambda x: x,
unit_primary = None,
show_description_only=False,
suppress_zero_inches=False,
text_prefix="",
@@ -1334,6 +1336,7 @@ class SvgWriter:
dimension = (v1_global - v0_global).length
dimension = helper.format_distance(
dimension,
unit_primary = unit_primary,
precision=self.precision,
decimal_places=self.decimal_places,
suppress_zero_inches=suppress_zero_inches,