Fix names lists are not updated immediately

Similar to addresses problem in #6869
This commit is contained in:
Andrej730
2025-07-07 13:12:57 +05:00
parent 40dcd393c6
commit 416ebde333
3 changed files with 40 additions and 57 deletions
@@ -91,7 +91,6 @@ class PeopleData(RolesAddressesData):
"name": cls.get_person_name(person), "name": cls.get_person_name(person),
"roles_label": ", ".join([r["label"] for r in roles]), "roles_label": ", ".join([r["label"] for r in roles]),
"is_engaged": bool(person.EngagedIn), "is_engaged": bool(person.EngagedIn),
"list_attributes": cls.get_person_list_attributes(person),
"roles": roles, "roles": roles,
"addresses": cls.get_addresses(person), "addresses": cls.get_addresses(person),
} }
@@ -110,23 +109,6 @@ class PeopleData(RolesAddressesData):
name += f" ({full_name})" name += f" ({full_name})"
return name return name
@classmethod
def get_person_list_attributes(cls, person: ifcopenshell.entity_instance) -> list[dict[str, Any]]:
results: list[dict[str, Any]] = []
props = tool.Owner.get_owner_props()
name: tool.Owner.PersonAttributeType
for name in ("MiddleNames", "PrefixTitles", "SuffixTitles"):
if name == "MiddleNames":
items = [{"id": id, "prop": prop} for id, prop in enumerate(props.middle_names)]
elif name == "PrefixTitles":
items = [{"id": id, "prop": prop} for id, prop in enumerate(props.prefix_titles)]
elif name == "SuffixTitles":
items = [{"id": id, "prop": prop} for id, prop in enumerate(props.suffix_titles)]
else:
assert False, name
results.append({"name": name, "items": items})
return results
class OrganisationsData(RolesAddressesData): class OrganisationsData(RolesAddressesData):
data = {} data = {}
+14 -12
View File
@@ -66,18 +66,19 @@ def draw_addresses(box: bpy.types.UILayout, parent: dict[str, Any]) -> None:
row.operator("bim.edit_address", icon="CHECKMARK") row.operator("bim.edit_address", icon="CHECKMARK")
row.operator("bim.disable_editing_address", icon="CANCEL", text="") row.operator("bim.disable_editing_address", icon="CANCEL", text="")
bonsai.bim.helper.draw_attributes(props.address_attributes, box) bonsai.bim.helper.draw_attributes(props.address_attributes, box)
for attribute in address["list_attributes"]: attributes: list[str] = address["list_attributes"]
for attribute_name in attributes:
row = box.row(align=True) row = box.row(align=True)
row.label(text=attribute["name"]) row.label(text=attribute_name)
op = row.operator("bim.add_address_attribute", icon="ADD", text="") op = row.operator("bim.add_address_attribute", icon="ADD", text="")
op.name = attribute["name"] op.name = attribute_name
collection = tool.Owner.get_address_collection(attribute["name"]) collection = tool.Owner.get_address_collection(attribute_name)
for i, item in enumerate(collection): for i, item in enumerate(collection):
row = box.row(align=True) row = box.row(align=True)
row.prop(item, "name", text="") row.prop(item, "name", text="")
op = row.operator("bim.remove_address_attribute", icon="REMOVE", text="") op = row.operator("bim.remove_address_attribute", icon="REMOVE", text="")
op.name = attribute["name"] op.name = attribute_name
op.id = i op.id = i
else: else:
row = box.row(align=True) row = box.row(align=True)
@@ -124,18 +125,19 @@ class BIM_PT_people(bpy.types.Panel):
row.operator("bim.disable_editing_person", icon="CANCEL", text="") row.operator("bim.disable_editing_person", icon="CANCEL", text="")
bonsai.bim.helper.draw_attributes(props.person_attributes, box) bonsai.bim.helper.draw_attributes(props.person_attributes, box)
for attribute in person["list_attributes"]: for attribute_name in tool.Owner.PERSON_ATTRIBUTE_TYPES:
row = box.row(align=True) row = box.row(align=True)
row.label(text=attribute["name"]) row.label(text=attribute_name)
op = row.operator("bim.add_person_attribute", icon="ADD", text="") op = row.operator("bim.add_person_attribute", icon="ADD", text="")
op.name = attribute["name"] op.name = attribute_name
for item in attribute["items"]: collection = tool.Owner.get_names_collection(attribute_name)
for i, item in enumerate(collection):
row = box.row(align=True) row = box.row(align=True)
row.prop(item["prop"], "name", text="") row.prop(item, "name", text="")
op = row.operator("bim.remove_person_attribute", icon="REMOVE", text="") op = row.operator("bim.remove_person_attribute", icon="REMOVE", text="")
op.name = attribute["name"] op.name = attribute_name
op.id = item["id"] op.id = i
draw_roles(box, person) draw_roles(box, person)
draw_addresses(box, person) draw_addresses(box, person)
+26 -27
View File
@@ -177,6 +177,23 @@ class Owner(bonsai.core.tool.Owner):
props = cls.get_owner_props() props = cls.get_owner_props()
props.active_person_id = person.id() props.active_person_id = person.id()
@classmethod
def get_names_collection_name(cls, attribute_name: PersonAttributeType) -> str:
blender_names = {
"MiddleNames": "middle_names",
"PrefixTitles": "prefix_titles",
"SuffixTitles": "suffix_titles",
}
return blender_names[attribute_name]
@classmethod
def get_names_collection(
cls, attribute_name: PersonAttributeType
) -> bpy.types.bpy_prop_collection_idprop[StrProperty]:
props = cls.get_owner_props()
blender_name = cls.get_names_collection_name(attribute_name)
return getattr(props, blender_name)
@classmethod @classmethod
def import_person_attributes(cls) -> None: def import_person_attributes(cls) -> None:
props = cls.get_owner_props() props = cls.get_owner_props()
@@ -187,15 +204,10 @@ class Owner(bonsai.core.tool.Owner):
props.suffix_titles.clear() props.suffix_titles.clear()
def callback(name: str, prop, data: dict[str, Any]) -> None: def callback(name: str, prop, data: dict[str, Any]) -> None:
if name == "MiddleNames": if name in cls.PERSON_ATTRIBUTE_TYPES:
for name in data["MiddleNames"] or []: collection = cls.get_names_collection(name)
props.middle_names.add().name = name or "" for name_ in data[name] or []:
if name == "PrefixTitles": collection.add().name = name_ or ""
for name in data["PrefixTitles"] or []:
props.prefix_titles.add().name = name or ""
if name == "SuffixTitles":
for name in data["SuffixTitles"] or []:
props.suffix_titles.add().name = name or ""
bonsai.bim.helper.import_attributes("IfcPerson", props.person_attributes, person.get_info(), callback) bonsai.bim.helper.import_attributes("IfcPerson", props.person_attributes, person.get_info(), callback)
@@ -219,30 +231,17 @@ class Owner(bonsai.core.tool.Owner):
return tool.Ifc().get().by_id(props.active_person_id) return tool.Ifc().get().by_id(props.active_person_id)
PersonAttributeType = Literal["MiddleNames", "PrefixTitles", "SuffixTitles"] PersonAttributeType = Literal["MiddleNames", "PrefixTitles", "SuffixTitles"]
PERSON_ATTRIBUTE_TYPES = ("MiddleNames", "PrefixTitles", "SuffixTitles")
@classmethod @classmethod
def add_person_attribute(cls, name: PersonAttributeType) -> None: def add_person_attribute(cls, name: PersonAttributeType) -> None:
props = cls.get_owner_props() collection = cls.get_names_collection(name)
if name == "MiddleNames": collection.add()
props.middle_names.add()
elif name == "PrefixTitles":
props.prefix_titles.add()
elif name == "SuffixTitles":
props.suffix_titles.add()
else:
assert_never(name)
@classmethod @classmethod
def remove_person_attribute(cls, name: PersonAttributeType, id: int) -> None: def remove_person_attribute(cls, name: PersonAttributeType, id: int) -> None:
props = cls.get_owner_props() collection = cls.get_names_collection(name)
if name == "MiddleNames": collection.remove(id)
props.middle_names.remove(id)
elif name == "PrefixTitles":
props.prefix_titles.remove(id)
elif name == "SuffixTitles":
props.suffix_titles.remove(id)
else:
assert_never(name)
@classmethod @classmethod
def set_role(cls, role: ifcopenshell.entity_instance) -> None: def set_role(cls, role: ifcopenshell.entity_instance) -> None: