Small refactor + allowing to preview text in viewport while editing

This commit is contained in:
Andrej730
2023-03-16 15:19:58 +05:00
parent 0d473fa9ac
commit ff2cda7d18
5 changed files with 16 additions and 3 deletions
@@ -2073,7 +2073,10 @@ class TextDecorator(BaseDecorator):
dir = Vector((1, 0))
pos = location_3d_to_region_2d(region, region3d, obj.matrix_world.translation)
font_size = DecoratorData.get_ifc_text_font_size(obj)
for line_i, line in enumerate(obj.BIMTextProperties.value.split("\\n")):
props = obj.BIMTextProperties
text = props.get_text() if props.is_editing else props.value
for line_i, line in enumerate(text.split("\\n")):
self.draw_label(
context, line, pos, dir, gap=0, center=False, vcenter=False, font_size=font_size, line_no=line_i
)
@@ -423,6 +423,9 @@ class BIMTextProperties(PropertyGroup):
is_editing: BoolProperty(name="Is Editing", default=False)
attributes: CollectionProperty(name="Attributes", type=Attribute)
test_prop: StringProperty(name="test_prop", default="TEXT")
# Current text value with evaluated experessions stored in `value`.
# The original (Literal) value stored in `attributes['Literal']`
# and can be accessed with `get_text()`
value: StringProperty(name="Value", default="TEXT")
font_size: EnumProperty(
items=[
@@ -440,6 +443,10 @@ class BIMTextProperties(PropertyGroup):
name="Box alignment", size=9, set=set_box_alignment, get=get_box_alignment, default=DEFAULT_BOX_ALIGNMENT
)
def get_text(self):
text_attribute = self.attributes.get('Literal', None)
return text_attribute.string_value if text_attribute else self.text
class BIMAssignedProductProperties(PropertyGroup):
is_editing_product: BoolProperty(name="Is Editing Product", default=False)
@@ -380,6 +380,11 @@ class BIM_PT_text(Panel):
row.label(text=attribute["name"])
row.label(text=attribute["value"])
row = self.layout.row(align=True)
row.label(text="Current value:")
row.label(text=props.value)
class BIM_PT_annotation_utilities(Panel):
bl_idname = "BIM_PT_annotation_utilities"
@@ -481,7 +481,6 @@ class Hotkey(bpy.types.Operator, tool.Ifc.Operator):
return self.execute(context)
def draw(self, context):
props = context.scene.BIMModelProperties
if self.hotkey == "S_O":
row = self.layout.row()
row.prop(self, "x")
@@ -538,7 +538,6 @@ class Drawing(blenderbim.core.tool.Drawing):
value = ifc_literal.Literal
product = cls.get_assigned_product(tool.Ifc.get_entity(obj))
if product:
variables = {}
for variable in re.findall("{{.*?}}", value):
value = value.replace(
variable, str(ifcopenshell.util.selector.get_element_value(product, variable[2:-2]) or "")