From f518521ea179334e538f69017e4928c9b10fe59a Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Thu, 11 May 2023 17:38:20 +0500 Subject: [PATCH] Option to add prefix and suffix to dimension annotation #3005 Example - https://imgur.com/a/0NkStWm --- .../blenderbim/bim/data/pset/Psets_BBIM_Annotation.ifc | 4 +++- src/blenderbim/blenderbim/bim/module/drawing/data.py | 4 ++++ .../blenderbim/bim/module/drawing/decoration.py | 3 +++ .../blenderbim/bim/module/drawing/svgwriter.py | 9 ++++++++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/data/pset/Psets_BBIM_Annotation.ifc b/src/blenderbim/blenderbim/bim/data/pset/Psets_BBIM_Annotation.ifc index a18f776740..3f0f40c504 100644 --- a/src/blenderbim/blenderbim/bim/data/pset/Psets_BBIM_Annotation.ifc +++ b/src/blenderbim/blenderbim/bim/data/pset/Psets_BBIM_Annotation.ifc @@ -27,8 +27,10 @@ DATA; #20=IFCSIMPLEPROPERTYTEMPLATE('23tejOrxj859R_eCRp1AFP',$,'MarkersPath','Default markers SVG',.P_SINGLEVALUE.,'IfcLabel',$,$,$,$,$,.READWRITE.); #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=IFCPROPERTYSETTEMPLATE('0I9merLinF5Ap$aZwaclgm',$,'BBIM_Dimension','',.PSET_OCCURRENCEDRIVEN.,'IfcAnnotation,IfcTypeProduct',(#24,#25)); +#23=IFCPROPERTYSETTEMPLATE('0I9merLinF5Ap$aZwaclgm',$,'BBIM_Dimension','',.PSET_OCCURRENCEDRIVEN.,'IfcAnnotation,IfcTypeProduct',(#24,#25,#26,#27)); #24=IFCSIMPLEPROPERTYTEMPLATE('1rL2AbQsXD8RbpoWH5pYOV',$,'ShowDescriptionOnly','Hide the measurement values and show only annotation description',.P_SINGLEVALUE.,'IfcBoolean',$,$,$,$,$,.READWRITE.); #25=IFCSIMPLEPROPERTYTEMPLATE('0SVyOfB0rC2xNfdRYf3XvY',$,'SuppressZeroInches','Suppress 0 inch values in dimension annotation text (for example: 12'' - 0" -> 12'')',.P_SINGLEVALUE.,'IfcBoolean',$,$,$,$,$,.READWRITE.); +#26=IFCSIMPLEPROPERTYTEMPLATE('2bUmj458PBqPAtUoI3MXsb',$,'TextPrefix','Text to add before annotation measurement value',.P_SINGLEVALUE.,'IfcLabel',$,$,$,$,$,.READWRITE.); +#27=IFCSIMPLEPROPERTYTEMPLATE('0bnzttUb9BPuN597uNTXOE',$,'TextSuffix','Text to add after annotation measurement value',.P_SINGLEVALUE.,'IfcLabel',$,$,$,$,$,.READWRITE.); ENDSEC; END-ISO-10303-21; diff --git a/src/blenderbim/blenderbim/bim/module/drawing/data.py b/src/blenderbim/blenderbim/bim/module/drawing/data.py index f9d1ab7d59..cc9928e17f 100644 --- a/src/blenderbim/blenderbim/bim/module/drawing/data.py +++ b/src/blenderbim/blenderbim/bim/module/drawing/data.py @@ -286,11 +286,15 @@ class DecoratorData: pset_data = ifcopenshell.util.element.get_pset(element, "BBIM_Dimension") or {} show_description_only = pset_data.get("ShowDescriptionOnly", False) suppress_zero_inches = pset_data.get("SuppressZeroInches", False) + text_prefix = pset_data.get("TextPrefix", "") + text_suffix = pset_data.get("TextSuffix", "") dimension_data = { "dimension_style": dimension_style, "show_description_only": show_description_only, "suppress_zero_inches": suppress_zero_inches, + "text_prefix": text_prefix, + "text_suffix": text_suffix, } cls.data[obj.name] = dimension_data return dimension_data diff --git a/src/blenderbim/blenderbim/bim/module/drawing/decoration.py b/src/blenderbim/blenderbim/bim/module/drawing/decoration.py index ab12fd9c8b..cac6757536 100644 --- a/src/blenderbim/blenderbim/bim/module/drawing/decoration.py +++ b/src/blenderbim/blenderbim/bim/module/drawing/decoration.py @@ -622,6 +622,8 @@ class DimensionDecorator(BaseDecorator): description = element.Description dimension_data = DecoratorData.get_dimension_data(obj) show_description_only = dimension_data["show_description_only"] + text_prefix = dimension_data["text_prefix"] + text_suffix = dimension_data["text_suffix"] for i0, i1 in indices: v0 = Vector(vertices[i0]) @@ -637,6 +639,7 @@ class DimensionDecorator(BaseDecorator): # TODO: same distance format function as in svg? # requires storing drawing precision and decimal_places from pset to data.py text = self.format_value(context, length) + text = text_prefix + text + text_suffix self.draw_label(context, text, p0 + text_dir * 0.5, text_dir, box_alignment="bottom-middle") if description: diff --git a/src/blenderbim/blenderbim/bim/module/drawing/svgwriter.py b/src/blenderbim/blenderbim/bim/module/drawing/svgwriter.py index f7c5f814f2..31ce948602 100644 --- a/src/blenderbim/blenderbim/bim/module/drawing/svgwriter.py +++ b/src/blenderbim/blenderbim/bim/module/drawing/svgwriter.py @@ -1079,6 +1079,8 @@ class SvgWriter: text_format=lambda x: "D" + x, show_description_only=dimension_data["show_description_only"], suppress_zero_inches=dimension_data["suppress_zero_inches"], + text_prefix=dimension_data["text_prefix"], + text_suffix=dimension_data["text_suffix"], ) def draw_dimension_annotations(self, obj): @@ -1100,6 +1102,8 @@ class SvgWriter: dimension_text=dimension_text, show_description_only=dimension_data["show_description_only"], suppress_zero_inches=dimension_data["suppress_zero_inches"], + text_prefix=dimension_data["text_prefix"], + text_suffix=dimension_data["text_suffix"], ) def draw_measureit_arch_dimension_annotations(self): @@ -1123,6 +1127,8 @@ class SvgWriter: text_format=lambda x: x, show_description_only=False, suppress_zero_inches=False, + text_prefix="", + text_suffix="", ): offset = Vector([self.raw_width, self.raw_height]) / 2 v0 = self.project_point_onto_camera(v0_global) @@ -1158,7 +1164,8 @@ class SvgWriter: ) if not show_description_only: - self.svg.add(create_text_tag(str(dimension), text_position + perpendicular, "bottom-middle")) + text = f"{text_prefix}{str(dimension)}{text_suffix}" + self.svg.add(create_text_tag(text, text_position + perpendicular, "bottom-middle")) if dimension_text: self.svg.add(create_text_tag(dimension_text, text_position - perpendicular, "top-middle"))