mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 18:21:59 +00:00
IfcText - box alignment interface instead of manually typing text position
realigning box widget
This commit is contained in:
@@ -38,6 +38,7 @@ from bpy.props import (
|
|||||||
FloatProperty,
|
FloatProperty,
|
||||||
FloatVectorProperty,
|
FloatVectorProperty,
|
||||||
CollectionProperty,
|
CollectionProperty,
|
||||||
|
BoolVectorProperty
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -381,9 +382,36 @@ class BIMCameraProperties(PropertyGroup):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
DEFAULT_BOX_ALIGNMENT = [False]*6 + [True] + [False]*2
|
||||||
|
BOX_ALIGNMENT_POSITIONS = [ "top-left", "top-middle", "top-right", "middle-left", "center", "middle-right", "bottom-left", "bottom-middle", "bottom-right"]
|
||||||
|
|
||||||
class BIMTextProperties(PropertyGroup):
|
class BIMTextProperties(PropertyGroup):
|
||||||
|
def set_box_alignment(self, new_value):
|
||||||
|
markers = new_value.count(True)
|
||||||
|
if not markers:
|
||||||
|
return
|
||||||
|
|
||||||
|
if markers > 1:
|
||||||
|
prev_value = self.get("box_alignment", DEFAULT_BOX_ALIGNMENT)
|
||||||
|
# looking for the first value changed to positive
|
||||||
|
first_changed_value = next( (i for i in range(9) if new_value[i] and new_value[i] != prev_value[i]), None )
|
||||||
|
|
||||||
|
# if nothing have changed we just keep the previous value
|
||||||
|
if first_changed_value is None:
|
||||||
|
return
|
||||||
|
new_value = [False] * 9
|
||||||
|
new_value[first_changed_value] = True
|
||||||
|
|
||||||
|
self["box_alignment"] = new_value
|
||||||
|
position_string = BOX_ALIGNMENT_POSITIONS[ next(i for i in range(9) if new_value[i]) ]
|
||||||
|
self.attributes['BoxAlignment'].set_value( position_string )
|
||||||
|
|
||||||
|
def get_box_alignment(self):
|
||||||
|
return self.get("box_alignment", DEFAULT_BOX_ALIGNMENT)
|
||||||
|
|
||||||
is_editing: BoolProperty(name="Is Editing", default=False)
|
is_editing: BoolProperty(name="Is Editing", default=False)
|
||||||
attributes: CollectionProperty(name="Attributes", type=Attribute)
|
attributes: CollectionProperty(name="Attributes", type=Attribute)
|
||||||
|
test_prop: StringProperty(name="test_prop", default="TEXT")
|
||||||
value: StringProperty(name="Value", default="TEXT")
|
value: StringProperty(name="Value", default="TEXT")
|
||||||
font_size: EnumProperty(
|
font_size: EnumProperty(
|
||||||
items=[
|
items=[
|
||||||
@@ -397,6 +425,10 @@ class BIMTextProperties(PropertyGroup):
|
|||||||
update=refreshFontSize,
|
update=refreshFontSize,
|
||||||
name="Font Size",
|
name="Font Size",
|
||||||
)
|
)
|
||||||
|
box_alignment: BoolVectorProperty(name="Box alignment", size=9,
|
||||||
|
set=set_box_alignment,
|
||||||
|
get=get_box_alignment,
|
||||||
|
default=DEFAULT_BOX_ALIGNMENT)
|
||||||
|
|
||||||
|
|
||||||
class BIMAssignedProductProperties(PropertyGroup):
|
class BIMAssignedProductProperties(PropertyGroup):
|
||||||
|
|||||||
@@ -349,7 +349,25 @@ class BIM_PT_text(Panel):
|
|||||||
row = self.layout.row(align=True)
|
row = self.layout.row(align=True)
|
||||||
row.operator("bim.edit_text", icon="CHECKMARK")
|
row.operator("bim.edit_text", icon="CHECKMARK")
|
||||||
row.operator("bim.disable_editing_text", icon="CANCEL", text="")
|
row.operator("bim.disable_editing_text", icon="CANCEL", text="")
|
||||||
blenderbim.bim.helper.draw_attributes(props.attributes, self.layout)
|
# skip BoxAlignment since we're going to format it ourselves
|
||||||
|
attributes = [a for a in props.attributes if a.name != 'BoxAlignment']
|
||||||
|
blenderbim.bim.helper.draw_attributes(attributes, self.layout)
|
||||||
|
row = self.layout.row(align=True)
|
||||||
|
row.prop(props, 'font_size')
|
||||||
|
|
||||||
|
# a bit hacky way to align box alignment widget
|
||||||
|
rows = [self.layout.row(align=True) for i in range(3)]
|
||||||
|
for i in range(9):
|
||||||
|
if i % 3 == 0:
|
||||||
|
split = rows[i//3].split(factor=0.1, align=True)
|
||||||
|
split.column()
|
||||||
|
split.prop(props, "box_alignment", text="", index=i)
|
||||||
|
|
||||||
|
text_lines = ["Text box alignment:", props.attributes['BoxAlignment'].string_value, '' ]
|
||||||
|
for i in range(3):
|
||||||
|
split = rows[i].split(factor=0.1, align=False)
|
||||||
|
split.column()
|
||||||
|
split.label(text=text_lines[i])
|
||||||
else:
|
else:
|
||||||
row = self.layout.row()
|
row = self.layout.row()
|
||||||
row.operator("bim.enable_editing_text", icon="GREASEPENCIL")
|
row.operator("bim.enable_editing_text", icon="GREASEPENCIL")
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import blenderbim.bim.module.drawing.sheeter as sheeter
|
|||||||
import blenderbim.bim.module.drawing.scheduler as scheduler
|
import blenderbim.bim.module.drawing.scheduler as scheduler
|
||||||
import blenderbim.bim.module.drawing.annotation as annotation
|
import blenderbim.bim.module.drawing.annotation as annotation
|
||||||
import blenderbim.bim.module.drawing.helper as helper
|
import blenderbim.bim.module.drawing.helper as helper
|
||||||
from blenderbim.bim.module.drawing.prop import get_diagram_scales
|
from blenderbim.bim.module.drawing.prop import get_diagram_scales, BOX_ALIGNMENT_POSITIONS
|
||||||
|
|
||||||
|
|
||||||
class Drawing(blenderbim.core.tool.Drawing):
|
class Drawing(blenderbim.core.tool.Drawing):
|
||||||
@@ -457,6 +457,11 @@ class Drawing(blenderbim.core.tool.Drawing):
|
|||||||
props.attributes.clear()
|
props.attributes.clear()
|
||||||
text = cls.get_text_literal(obj)
|
text = cls.get_text_literal(obj)
|
||||||
blenderbim.bim.helper.import_attributes2(text, props.attributes)
|
blenderbim.bim.helper.import_attributes2(text, props.attributes)
|
||||||
|
|
||||||
|
box_alignment_mask = [False] * 9
|
||||||
|
position_string = props.attributes['BoxAlignment'].string_value
|
||||||
|
box_alignment_mask[BOX_ALIGNMENT_POSITIONS.index(position_string)] = True
|
||||||
|
props.box_alignment = box_alignment_mask
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def import_assigned_product(cls, obj):
|
def import_assigned_product(cls, obj):
|
||||||
|
|||||||
Reference in New Issue
Block a user