owner.ui - check props explicitly instead of relying on ifc data update

This commit is contained in:
Andrej730
2025-06-17 17:05:18 +05:00
parent 2e3c733c0d
commit f26f2780e9
2 changed files with 17 additions and 29 deletions
@@ -35,30 +35,24 @@ def refresh():
class RolesAddressesData: class RolesAddressesData:
@classmethod @classmethod
def get_roles(cls, parent: ifcopenshell.entity_instance) -> list[dict[str, Any]]: def get_roles(cls, parent: ifcopenshell.entity_instance) -> list[dict[str, Any]]:
props = tool.Owner.get_owner_props()
results: list[dict[str, Any]] = [] results: list[dict[str, Any]] = []
for role in parent.Roles or []: for role in parent.Roles or []:
results.append( results.append(
{ {
"id": role.id(), "id": role.id(),
"is_editing": props.active_role_id == role.id(),
"label": role.UserDefinedRole or role.Role, "label": role.UserDefinedRole or role.Role,
"props": props.role_attributes,
} }
) )
return results return results
@classmethod @classmethod
def get_addresses(cls, parent: ifcopenshell.entity_instance) -> list[dict[str, Any]]: def get_addresses(cls, parent: ifcopenshell.entity_instance) -> list[dict[str, Any]]:
props = tool.Owner.get_owner_props()
results: list[dict[str, Any]] = [] results: list[dict[str, Any]] = []
for address in parent.Addresses or []: for address in parent.Addresses or []:
results.append( results.append(
{ {
"id": address.id(), "id": address.id(),
"is_editing": props.active_address_id == address.id(),
"label": address.is_a(), "label": address.is_a(),
"props": props.address_attributes,
"list_attributes": cls.get_address_list_attributes(address), "list_attributes": cls.get_address_list_attributes(address),
} }
) )
@@ -102,17 +96,14 @@ class PeopleData(RolesAddressesData):
@classmethod @classmethod
def get_people(cls) -> list[dict[str, Any]]: def get_people(cls) -> list[dict[str, Any]]:
props = tool.Owner.get_owner_props()
people: list[dict[str, Any]] = [] people: list[dict[str, Any]] = []
for person in tool.Ifc.get().by_type("IfcPerson"): for person in tool.Ifc.get().by_type("IfcPerson"):
roles = cls.get_roles(person) roles = cls.get_roles(person)
people.append( people.append(
{ {
"id": person.id(), "id": person.id(),
"props": props.person_attributes,
"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_editing": cls.get_person_is_editing(person),
"is_engaged": bool(person.EngagedIn), "is_engaged": bool(person.EngagedIn),
"list_attributes": cls.get_person_list_attributes(person), "list_attributes": cls.get_person_list_attributes(person),
"roles": roles, "roles": roles,
@@ -133,11 +124,6 @@ class PeopleData(RolesAddressesData):
name += f" ({full_name})" name += f" ({full_name})"
return name return name
@classmethod
def get_person_is_editing(cls, person: ifcopenshell.entity_instance) -> bool:
props = tool.Owner.get_owner_props()
return props.active_person_id == person.id()
@classmethod @classmethod
def get_person_list_attributes(cls, person: ifcopenshell.entity_instance) -> list[dict[str, Any]]: def get_person_list_attributes(cls, person: ifcopenshell.entity_instance) -> list[dict[str, Any]]:
results: list[dict[str, Any]] = [] results: list[dict[str, Any]] = []
@@ -167,17 +153,14 @@ class OrganisationsData(RolesAddressesData):
@classmethod @classmethod
def get_organisations(cls) -> list[dict[str, Any]]: def get_organisations(cls) -> list[dict[str, Any]]:
props = tool.Owner.get_owner_props()
organisations: list[dict[str, Any]] = [] organisations: list[dict[str, Any]] = []
for organisation in tool.Ifc.get().by_type("IfcOrganization"): for organisation in tool.Ifc.get().by_type("IfcOrganization"):
roles = cls.get_roles(organisation) roles = cls.get_roles(organisation)
organisations.append( organisations.append(
{ {
"id": organisation.id(), "id": organisation.id(),
"props": props.organisation_attributes,
"name": organisation.Name, "name": organisation.Name,
"roles_label": ", ".join([r["label"] for r in roles]), "roles_label": ", ".join([r["label"] for r in roles]),
"is_editing": props.active_organisation_id == organisation.id(),
"is_engaged": bool(organisation.Engages), "is_engaged": bool(organisation.Engages),
"roles": roles, "roles": roles,
"addresses": cls.get_addresses(organisation), "addresses": cls.get_addresses(organisation),
@@ -251,7 +234,6 @@ class ActorData:
actors: list[dict[str, Any]] = [] actors: list[dict[str, Any]] = []
props = tool.Owner.get_owner_props() props = tool.Owner.get_owner_props()
for actor in tool.Ifc.get().by_type(props.actor_class, include_subtypes=False): for actor in tool.Ifc.get().by_type(props.actor_class, include_subtypes=False):
is_editing = props.active_actor_id == actor.id()
the_actor: ifcopenshell.entity_instance = actor.TheActor the_actor: ifcopenshell.entity_instance = actor.TheActor
if the_actor.is_a("IfcPerson"): if the_actor.is_a("IfcPerson"):
the_actor_ = the_actor.Identification or "N/A" the_actor_ = the_actor.Identification or "N/A"
@@ -267,7 +249,6 @@ class ActorData:
"id": actor.id(), "id": actor.id(),
"name": actor.Name or "Unnamed", "name": actor.Name or "Unnamed",
"the_actor": the_actor_, "the_actor": the_actor_,
"is_editing": is_editing,
} }
) )
return actors return actors
+17 -10
View File
@@ -31,17 +31,18 @@ from bonsai.bim.module.owner.data import (
def draw_roles(box: bpy.types.UILayout, parent: dict[str, Any]) -> None: def draw_roles(box: bpy.types.UILayout, parent: dict[str, Any]) -> None:
props = tool.Owner.get_owner_props()
row = box.row(align=True) row = box.row(align=True)
row.label(text="Roles") row.label(text="Roles")
op = row.operator("bim.add_role", icon="ADD", text="") op = row.operator("bim.add_role", icon="ADD", text="")
op.parent = parent["id"] op.parent = parent["id"]
for role in parent["roles"]: for role in parent["roles"]:
if role["is_editing"]: if props.active_role_id == role["id"]:
row = box.row(align=True) row = box.row(align=True)
row.operator("bim.edit_role", icon="CHECKMARK") row.operator("bim.edit_role", icon="CHECKMARK")
row.operator("bim.disable_editing_role", icon="CANCEL", text="") row.operator("bim.disable_editing_role", icon="CANCEL", text="")
bonsai.bim.helper.draw_attributes(role["props"], box) bonsai.bim.helper.draw_attributes(props.role_attributes, box)
else: else:
row = box.row(align=True) row = box.row(align=True)
row.label(text=role["label"]) row.label(text=role["label"])
@@ -50,6 +51,7 @@ def draw_roles(box: bpy.types.UILayout, parent: dict[str, Any]) -> None:
def draw_addresses(box: bpy.types.UILayout, parent: dict[str, Any]) -> None: def draw_addresses(box: bpy.types.UILayout, parent: dict[str, Any]) -> None:
props = tool.Owner.get_owner_props()
row = box.row(align=True) row = box.row(align=True)
row.label(text="Addresses") row.label(text="Addresses")
op = row.operator("bim.add_address", icon="LINK_BLEND", text="") op = row.operator("bim.add_address", icon="LINK_BLEND", text="")
@@ -60,11 +62,11 @@ def draw_addresses(box: bpy.types.UILayout, parent: dict[str, Any]) -> None:
op.ifc_class = "IfcPostalAddress" op.ifc_class = "IfcPostalAddress"
for address in parent["addresses"]: for address in parent["addresses"]:
if address["is_editing"]: if props.active_address_id == address["id"]:
row = box.row(align=True) row = box.row(align=True)
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(address["props"], box) bonsai.bim.helper.draw_attributes(props.address_attributes, box)
for attribute in address["list_attributes"]: for attribute in address["list_attributes"]:
row = box.row(align=True) row = box.row(align=True)
row.label(text=attribute["name"]) row.label(text=attribute["name"])
@@ -113,12 +115,14 @@ class BIM_PT_people(bpy.types.Panel):
def draw_person(self, person: dict[str, Any]) -> None: def draw_person(self, person: dict[str, Any]) -> None:
assert self.layout assert self.layout
if person["is_editing"]: props = tool.Owner.get_owner_props()
if props.active_person_id == person["id"]:
box = self.layout.box() box = self.layout.box()
row = box.row(align=True) row = box.row(align=True)
row.operator("bim.edit_person", icon="CHECKMARK") row.operator("bim.edit_person", icon="CHECKMARK")
row.operator("bim.disable_editing_person", icon="CANCEL", text="") row.operator("bim.disable_editing_person", icon="CANCEL", text="")
bonsai.bim.helper.draw_attributes(person["props"], box) bonsai.bim.helper.draw_attributes(props.person_attributes, box)
for attribute in person["list_attributes"]: for attribute in person["list_attributes"]:
row = box.row(align=True) row = box.row(align=True)
@@ -174,12 +178,13 @@ class BIM_PT_organisations(bpy.types.Panel):
def draw_organisation(self, organisation: dict[str, Any]) -> None: def draw_organisation(self, organisation: dict[str, Any]) -> None:
assert self.layout assert self.layout
if organisation["is_editing"]: props = tool.Owner.get_owner_props()
if props.active_organisation_id == organisation["id"]:
box = self.layout.box() box = self.layout.box()
row = box.row(align=True) row = box.row(align=True)
row.operator("bim.edit_organisation", icon="CHECKMARK") row.operator("bim.edit_organisation", icon="CHECKMARK")
row.operator("bim.disable_editing_organisation", icon="CANCEL", text="") row.operator("bim.disable_editing_organisation", icon="CANCEL", text="")
bonsai.bim.helper.draw_attributes(organisation["props"], box) bonsai.bim.helper.draw_attributes(props.organisation_attributes, box)
draw_roles(box, organisation) draw_roles(box, organisation)
draw_addresses(box, organisation) draw_addresses(box, organisation)
@@ -284,12 +289,14 @@ class BIM_PT_actor(bpy.types.Panel):
def draw_actor(self, actor: dict[str, Any]) -> None: def draw_actor(self, actor: dict[str, Any]) -> None:
assert self.layout assert self.layout
if actor["is_editing"]: props = tool.Owner.get_owner_props()
if props.active_actor_id == actor["id"]:
box = self.layout.box() box = self.layout.box()
row = box.row(align=True) row = box.row(align=True)
row.operator("bim.edit_actor", icon="CHECKMARK") row.operator("bim.edit_actor", icon="CHECKMARK")
row.operator("bim.disable_editing_actor", icon="CANCEL", text="") row.operator("bim.disable_editing_actor", icon="CANCEL", text="")
bonsai.bim.helper.draw_attributes(self.props.actor_attributes, box) bonsai.bim.helper.draw_attributes(props.actor_attributes, box)
else: else:
row = self.layout.row(align=True) row = self.layout.row(align=True)
row.label(text=actor["name"], icon="USER") row.label(text=actor["name"], icon="USER")