mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
Fix names lists are not updated immediately
Similar to addresses problem in #6869
This commit is contained in:
@@ -91,7 +91,6 @@ class PeopleData(RolesAddressesData):
|
||||
"name": cls.get_person_name(person),
|
||||
"roles_label": ", ".join([r["label"] for r in roles]),
|
||||
"is_engaged": bool(person.EngagedIn),
|
||||
"list_attributes": cls.get_person_list_attributes(person),
|
||||
"roles": roles,
|
||||
"addresses": cls.get_addresses(person),
|
||||
}
|
||||
@@ -110,23 +109,6 @@ class PeopleData(RolesAddressesData):
|
||||
name += f" ({full_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):
|
||||
data = {}
|
||||
|
||||
@@ -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.disable_editing_address", icon="CANCEL", text="")
|
||||
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.label(text=attribute["name"])
|
||||
row.label(text=attribute_name)
|
||||
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):
|
||||
row = box.row(align=True)
|
||||
row.prop(item, "name", text="")
|
||||
op = row.operator("bim.remove_address_attribute", icon="REMOVE", text="")
|
||||
op.name = attribute["name"]
|
||||
op.name = attribute_name
|
||||
op.id = i
|
||||
else:
|
||||
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="")
|
||||
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.label(text=attribute["name"])
|
||||
row.label(text=attribute_name)
|
||||
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.prop(item["prop"], "name", text="")
|
||||
row.prop(item, "name", text="")
|
||||
op = row.operator("bim.remove_person_attribute", icon="REMOVE", text="")
|
||||
op.name = attribute["name"]
|
||||
op.id = item["id"]
|
||||
op.name = attribute_name
|
||||
op.id = i
|
||||
|
||||
draw_roles(box, person)
|
||||
draw_addresses(box, person)
|
||||
|
||||
@@ -177,6 +177,23 @@ class Owner(bonsai.core.tool.Owner):
|
||||
props = cls.get_owner_props()
|
||||
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
|
||||
def import_person_attributes(cls) -> None:
|
||||
props = cls.get_owner_props()
|
||||
@@ -187,15 +204,10 @@ class Owner(bonsai.core.tool.Owner):
|
||||
props.suffix_titles.clear()
|
||||
|
||||
def callback(name: str, prop, data: dict[str, Any]) -> None:
|
||||
if name == "MiddleNames":
|
||||
for name in data["MiddleNames"] or []:
|
||||
props.middle_names.add().name = name or ""
|
||||
if name == "PrefixTitles":
|
||||
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 ""
|
||||
if name in cls.PERSON_ATTRIBUTE_TYPES:
|
||||
collection = cls.get_names_collection(name)
|
||||
for name_ in data[name] or []:
|
||||
collection.add().name = name_ or ""
|
||||
|
||||
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)
|
||||
|
||||
PersonAttributeType = Literal["MiddleNames", "PrefixTitles", "SuffixTitles"]
|
||||
PERSON_ATTRIBUTE_TYPES = ("MiddleNames", "PrefixTitles", "SuffixTitles")
|
||||
|
||||
@classmethod
|
||||
def add_person_attribute(cls, name: PersonAttributeType) -> None:
|
||||
props = cls.get_owner_props()
|
||||
if name == "MiddleNames":
|
||||
props.middle_names.add()
|
||||
elif name == "PrefixTitles":
|
||||
props.prefix_titles.add()
|
||||
elif name == "SuffixTitles":
|
||||
props.suffix_titles.add()
|
||||
else:
|
||||
assert_never(name)
|
||||
collection = cls.get_names_collection(name)
|
||||
collection.add()
|
||||
|
||||
@classmethod
|
||||
def remove_person_attribute(cls, name: PersonAttributeType, id: int) -> None:
|
||||
props = cls.get_owner_props()
|
||||
if name == "MiddleNames":
|
||||
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)
|
||||
collection = cls.get_names_collection(name)
|
||||
collection.remove(id)
|
||||
|
||||
@classmethod
|
||||
def set_role(cls, role: ifcopenshell.entity_instance) -> None:
|
||||
|
||||
Reference in New Issue
Block a user