From fc736f725c081e3cdb634174c7640ff6a9b17652 Mon Sep 17 00:00:00 2001 From: Ryan Schultz Date: Sun, 24 Nov 2024 09:58:44 -0600 Subject: [PATCH] tweaks to 812e3dc6df32e08fbe85051ccf752ac1d1b5f93c --- src/bonsai/bonsai/bim/module/drawing/helper.py | 10 ++++++++++ src/bonsai/bonsai/bim/module/drawing/prop.py | 2 +- src/bonsai/bonsai/bim/module/drawing/svgwriter.py | 3 ++- src/bonsai/bonsai/tool/drawing.py | 7 +++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/drawing/helper.py b/src/bonsai/bonsai/bim/module/drawing/helper.py index a307dc7ce0..123791f683 100644 --- a/src/bonsai/bonsai/bim/module/drawing/helper.py +++ b/src/bonsai/bonsai/bim/module/drawing/helper.py @@ -421,6 +421,14 @@ def add_newline_between_words(text, newline_at): start = 0 while start < len(text): + # Find the next newline character if present + newline_index = text.find("\n", start) + if newline_index != -1 and newline_index < start + newline_at: + # If a newline is found within the current range + result.append(text[start:newline_index]) # Add text up to the newline + start = newline_index + 1 # Move past the newline + continue + # Find the end index considering the limit newline_at end = start + newline_at if end >= len(text): # If we're at the end of the string @@ -441,3 +449,5 @@ def add_newline_between_words(text, newline_at): start = space_index + 1 # Skip the space itself return "\n".join(result) + + diff --git a/src/bonsai/bonsai/bim/module/drawing/prop.py b/src/bonsai/bonsai/bim/module/drawing/prop.py index 556aa6948d..84f7670949 100644 --- a/src/bonsai/bonsai/bim/module/drawing/prop.py +++ b/src/bonsai/bonsai/bim/module/drawing/prop.py @@ -509,7 +509,7 @@ class Literal(PropertyGroup): return self.get("box_alignment", DEFAULT_BOX_ALIGNMENT) attributes: CollectionProperty(name="Attributes", type=Attribute) - # Current text value with evaluated experessions stored in `value`. + # Current text value with evaluated expressions stored in `value`. # The original (Literal) value stored in `attributes['Literal']` # and can be accessed with `get_text()` value: StringProperty(name="Value", default="TEXT") diff --git a/src/bonsai/bonsai/bim/module/drawing/svgwriter.py b/src/bonsai/bonsai/bim/module/drawing/svgwriter.py index da1c7f074d..de7d2a39bf 100644 --- a/src/bonsai/bonsai/bim/module/drawing/svgwriter.py +++ b/src/bonsai/bonsai/bim/module/drawing/svgwriter.py @@ -807,6 +807,7 @@ class SvgWriter: fill_bg = "fill-bg" in classes symbol = tool.Drawing.get_annotation_symbol(element) + newline_at = tool.Drawing.get_newline_at(element) template_text_fields = [] if symbol: symbol_transform = self.get_symbol_transform(text_position_svg_str, angle, text_obj) @@ -841,7 +842,7 @@ class SvgWriter: self.draw_symbol(symbol, symbol_transform) line_number = 0 - newline_at = text_obj.BIMTextProperties.newline_at + for text_literal in text_literals: text = tool.Drawing.replace_text_literal_variables(text_literal.Literal, product or element) text_tags = self.create_text_tag( diff --git a/src/bonsai/bonsai/tool/drawing.py b/src/bonsai/bonsai/tool/drawing.py index 68d96c2179..213d885572 100644 --- a/src/bonsai/bonsai/tool/drawing.py +++ b/src/bonsai/bonsai/tool/drawing.py @@ -910,6 +910,7 @@ class Drawing(bonsai.core.tool.Drawing): text_data = DecoratorData.get_ifc_text_data(obj) props.font_size = str(text_data["FontSize"]) + props.newline_at = text_data['Newline_At'] @classmethod def import_assigned_product(cls, obj: bpy.types.Object) -> None: @@ -1692,6 +1693,12 @@ class Drawing(bonsai.core.tool.Drawing): symbol = ifcopenshell.util.element.get_pset(element, "EPset_AnnotationSurveyArea", "PointType") return symbol + @classmethod + def get_newline_at(cls, element: ifcopenshell.entity_instance) -> Union[int, 0]: + newline_at = ifcopenshell.util.element.get_pset(element, "EPset_Annotation", "Newline_At") + return newline_at + + @classmethod def has_linework(cls, drawing: ifcopenshell.entity_instance) -> bool: return ifcopenshell.util.element.get_psets(drawing).get("EPset_Drawing", {}).get("HasLinework", False)