From 1d8a568a0ba9d1e4b76ee0b80f724abbc3d654e3 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Wed, 20 Jan 2021 10:44:43 +1100 Subject: [PATCH] WIP finish refactoring owner module props. See #1222. --- .../blenderbim/bim/module/owner/__init__.py | 11 +- .../blenderbim/bim/module/owner/data.py | 3 + .../blenderbim/bim/module/owner/operator.py | 24 ++-- .../blenderbim/bim/module/owner/prop.py | 129 ++++++++++++++++++ .../blenderbim/bim/module/owner/ui.py | 10 +- src/ifcblenderexport/blenderbim/bim/prop.py | 28 ---- 6 files changed, 157 insertions(+), 48 deletions(-) create mode 100644 src/ifcblenderexport/blenderbim/bim/module/owner/prop.py diff --git a/src/ifcblenderexport/blenderbim/bim/module/owner/__init__.py b/src/ifcblenderexport/blenderbim/bim/module/owner/__init__.py index a83187dbf1..a097f0fb07 100644 --- a/src/ifcblenderexport/blenderbim/bim/module/owner/__init__.py +++ b/src/ifcblenderexport/blenderbim/bim/module/owner/__init__.py @@ -1,5 +1,5 @@ import bpy -from . import ui, operator +from . import ui, prop, operator classes = ( operator.EnableEditingPerson, @@ -22,6 +22,11 @@ classes = ( operator.AddAddress, operator.EditAddress, operator.RemoveAddress, + prop.Role, + prop.Address, + prop.Person, + prop.Organisation, + prop.BIMOwnerProperties, ui.BIM_PT_people, ui.BIM_PT_organisations, ui.BIM_PT_owner, @@ -29,8 +34,8 @@ classes = ( def register(): - pass + bpy.types.Scene.BIMOwnerProperties = bpy.props.PointerProperty(type=prop.BIMOwnerProperties) def unregister(): - pass + del bpy.types.Scene.BIMOwnerProperties diff --git a/src/ifcblenderexport/blenderbim/bim/module/owner/data.py b/src/ifcblenderexport/blenderbim/bim/module/owner/data.py index c134474f6a..8b1eba8c92 100644 --- a/src/ifcblenderexport/blenderbim/bim/module/owner/data.py +++ b/src/ifcblenderexport/blenderbim/bim/module/owner/data.py @@ -14,6 +14,9 @@ class Data: if not file: return cls.people = {} + cls.organisations = {} + cls.addresses = {} + cls.roles = {} for person in file.by_type("IfcPerson"): data = person.get_info() data["is_engaged"] = bool(person.EngagedIn) diff --git a/src/ifcblenderexport/blenderbim/bim/module/owner/operator.py b/src/ifcblenderexport/blenderbim/bim/module/owner/operator.py index 42fcc78d8c..9fed15eb7c 100644 --- a/src/ifcblenderexport/blenderbim/bim/module/owner/operator.py +++ b/src/ifcblenderexport/blenderbim/bim/module/owner/operator.py @@ -23,7 +23,7 @@ class EnableEditingPerson(bpy.types.Operator): def execute(self, context): self.file = IfcStore.get_file() - props = context.scene.BIMProperties + props = context.scene.BIMOwnerProperties props.active_person_id = self.person_id data = Data.people[self.person_id] name = data["Id"] if self.file.schema == "IFC2X3" else data["Identification"] @@ -41,7 +41,7 @@ class DisableEditingPerson(bpy.types.Operator): bl_label = "Disable Editing Person" def execute(self, context): - context.scene.BIMProperties.active_person_id = 0 + context.scene.BIMOwnerProperties.active_person_id = 0 return {"FINISHED"} @@ -61,7 +61,7 @@ class EditPerson(bpy.types.Operator): def execute(self, context): self.file = IfcStore.get_file() - props = context.scene.BIMProperties + props = context.scene.BIMOwnerProperties attributes = { "Identification": props.person.name or None, "FamilyName": props.person.family_name or None, @@ -100,7 +100,7 @@ class EnableEditingRole(bpy.types.Operator): def execute(self, context): self.file = IfcStore.get_file() - props = context.scene.BIMProperties + props = context.scene.BIMOwnerProperties props.active_role_id = self.role_id data = Data.roles[self.role_id] props.role.name = data["Role"] @@ -114,7 +114,7 @@ class DisableEditingRole(bpy.types.Operator): bl_label = "Disable Editing Role" def execute(self, context): - context.scene.BIMProperties.active_role_id = 0 + context.scene.BIMOwnerProperties.active_role_id = 0 return {"FINISHED"} @@ -136,7 +136,7 @@ class EditRole(bpy.types.Operator): def execute(self, context): self.file = IfcStore.get_file() - props = context.scene.BIMProperties + props = context.scene.BIMOwnerProperties attributes = { "Role": props.role.name, "UserDefinedRole": props.role.user_defined_role if props.role.name == "USERDEFINED" else None, @@ -184,7 +184,7 @@ class EnableEditingAddress(bpy.types.Operator): def execute(self, context): self.file = IfcStore.get_file() - props = context.scene.BIMProperties + props = context.scene.BIMOwnerProperties props.active_address_id = self.address_id data = Data.addresses[self.address_id] props.address.name = data["type"] @@ -218,7 +218,7 @@ class DisableEditingAddress(bpy.types.Operator): bl_label = "Disable Editing Address" def execute(self, context): - context.scene.BIMProperties.active_address_id = 0 + context.scene.BIMOwnerProperties.active_address_id = 0 return {"FINISHED"} @@ -228,7 +228,7 @@ class EditAddress(bpy.types.Operator): def execute(self, context): self.file = IfcStore.get_file() - props = context.scene.BIMProperties + props = context.scene.BIMOwnerProperties attributes = { "Purpose": props.address.purpose, "UserDefinedPurpose": props.address.user_defined_purpose @@ -291,7 +291,7 @@ class EnableEditingOrganisation(bpy.types.Operator): def execute(self, context): self.file = IfcStore.get_file() - props = context.scene.BIMProperties + props = context.scene.BIMOwnerProperties props.active_organisation_id = self.organisation_id data = Data.organisations[self.organisation_id] identification = data["Id"] if self.file.schema == "IFC2X3" else data["Identification"] @@ -306,7 +306,7 @@ class DisableEditingOrganisation(bpy.types.Operator): bl_label = "Disable Editing Organisation" def execute(self, context): - context.scene.BIMProperties.active_organisation_id = 0 + context.scene.BIMOwnerProperties.active_organisation_id = 0 return {"FINISHED"} @@ -326,7 +326,7 @@ class EditOrganisation(bpy.types.Operator): def execute(self, context): self.file = IfcStore.get_file() - props = context.scene.BIMProperties + props = context.scene.BIMOwnerProperties attributes = { "Identification": props.organisation.identification or None, "Name": props.organisation.name, diff --git a/src/ifcblenderexport/blenderbim/bim/module/owner/prop.py b/src/ifcblenderexport/blenderbim/bim/module/owner/prop.py new file mode 100644 index 0000000000..5140f1f4ce --- /dev/null +++ b/src/ifcblenderexport/blenderbim/bim/module/owner/prop.py @@ -0,0 +1,129 @@ +import bpy +from blenderbim.bim.prop import StrProperty, Attribute +from blenderbim.bim.module.owner.data import Data +from bpy.types import PropertyGroup +from bpy.props import ( + PointerProperty, + StringProperty, + EnumProperty, + BoolProperty, + IntProperty, + FloatProperty, + FloatVectorProperty, + CollectionProperty, +) + + +def getPersons(self, context): + if not Data.is_loaded: + Data.load() + results = [] + for ifc_id, person in Data.people.items(): + if "Id" in person: + identifier = person["Id"] or "" + else: + identifier = person["Identifier"] or "" + results.append((str(ifc_id), identifier, "")) + return results + + +def getOrganisations(self, context): + if not Data.is_loaded: + Data.load() + results = [] + for ifc_id, organisation in Data.organisations.items(): + results.append((str(ifc_id), organisation["Name"], "")) + return results + + +class Address(PropertyGroup): + name: StringProperty(name="Name", default="IfcPostalAddress") # Stores IfcPostalAddress or IfcTelecomAddress + purpose: EnumProperty( + items=[ + ("None", "None", ""), + ("OFFICE", "OFFICE", "An office address."), + ("SITE", "SITE", "A site address."), + ("HOME", "HOME", "A home address."), + ("DISTRIBUTIONPOINT", "DISTRIBUTIONPOINT", "A postal distribution point address."), + ("USERDEFINED", "USERDEFINED", "A user defined address type to be provided."), + ], + name="Purpose", + ) + description: StringProperty(name="Description") + user_defined_purpose: StringProperty(name="Custom Purpose") + + internal_location: StringProperty(name="Internal Location") + address_lines: StringProperty(name="Address") + postal_box: StringProperty(name="Postal Box") + town: StringProperty(name="Town") + region: StringProperty(name="Region") + postal_code: StringProperty(name="Postal Code") + country: StringProperty(name="Country") + + telephone_numbers: StringProperty(name="Telephone Numbers") + facsimile_numbers: StringProperty(name="Facsimile Numbers") + pager_number: StringProperty(name="Pager Number") + electronic_mail_addresses: StringProperty(name="Emails") + www_home_page_url: StringProperty(name="Websites") + messaging_ids: StringProperty(name="IMs") + + +class Role(PropertyGroup): + name: EnumProperty( + items=[ + ("SUPPLIER", "SUPPLIER", ""), + ("MANUFACTURER", "MANUFACTURER", ""), + ("CONTRACTOR", "CONTRACTOR", ""), + ("SUBCONTRACTOR", "SUBCONTRACTOR", ""), + ("ARCHITECT", "ARCHITECT", ""), + ("STRUCTURALENGINEER", "STRUCTURALENGINEER", ""), + ("COSTENGINEER", "COSTENGINEER", ""), + ("CLIENT", "CLIENT", ""), + ("BUILDINGOWNER", "BUILDINGOWNER", ""), + ("BUILDINGOPERATOR", "BUILDINGOPERATOR", ""), + ("MECHANICALENGINEER", "MECHANICALENGINEER", ""), + ("ELECTRICALENGINEER", "ELECTRICALENGINEER", ""), + ("PROJECTMANAGER", "PROJECTMANAGER", ""), + ("FACILITIESMANAGER", "FACILITIESMANAGER", ""), + ("CIVILENGINEER", "CIVILENGINEER", ""), + ("COMMISSIONINGENGINEER", "COMMISSIONINGENGINEER", ""), + ("ENGINEER", "ENGINEER", ""), + ("OWNER", "OWNER", ""), + ("CONSULTANT", "CONSULTANT", ""), + ("CONSTRUCTIONMANAGER", "CONSTRUCTIONMANAGER", ""), + ("FIELDCONSTRUCTIONMANAGER", "FIELDCONSTRUCTIONMANAGER", ""), + ("RESELLER", "RESELLER", ""), + ("USERDEFINED", "USERDEFINED", ""), + ], + name="Name", + ) + user_defined_role: StringProperty(name="Custom Role") + description: StringProperty(name="Description") + + +class Organisation(PropertyGroup): + identification: StringProperty(name="Identification") + name: StringProperty(name="Name") + description: StringProperty(name="Description") + + +class Person(PropertyGroup): + name: StringProperty(name="Identification") + family_name: StringProperty(name="Family Name") + given_name: StringProperty(name="Given Name") + middle_names: StringProperty(name="Middle Names") + prefix_titles: StringProperty(name="Prefixes") + suffix_titles: StringProperty(name="Suffixes") + + +class BIMOwnerProperties(PropertyGroup): + person: PointerProperty(type=Person) + active_person_id: IntProperty(name="Active Person Id") + organisation: PointerProperty(type=Organisation) + active_organisation_id: IntProperty(name="Active Organisation Id") + role: PointerProperty(type=Role) + active_role_id: IntProperty(name="Active Role Id") + address: PointerProperty(type=Address) + active_address_id: IntProperty(name="Active Address Id") + user_person: EnumProperty(items=getPersons, name="Person") + user_organisation: EnumProperty(items=getOrganisations, name="Organisation") diff --git a/src/ifcblenderexport/blenderbim/bim/module/owner/ui.py b/src/ifcblenderexport/blenderbim/bim/module/owner/ui.py index c192326223..cae55b06cc 100644 --- a/src/ifcblenderexport/blenderbim/bim/module/owner/ui.py +++ b/src/ifcblenderexport/blenderbim/bim/module/owner/ui.py @@ -5,7 +5,7 @@ from blenderbim.bim.ifc import IfcStore def draw_roles_ui(box, assigned_object_id, roles): - props = bpy.context.scene.BIMProperties + props = bpy.context.scene.BIMOwnerProperties row = box.row(align=True) row.label(text="Roles") row.operator("bim.add_role", icon="ADD", text="").assigned_object_id = assigned_object_id @@ -31,7 +31,7 @@ def draw_roles_ui(box, assigned_object_id, roles): def draw_addresses_ui(box, assigned_object_id, addresses, file): - props = bpy.context.scene.BIMProperties + props = bpy.context.scene.BIMOwnerProperties row = box.row(align=True) row.label(text="Addresses") op = row.operator("bim.add_address", icon="LINK_BLEND", text="") @@ -110,7 +110,7 @@ class BIM_PT_people(Panel): self.file = IfcStore.get_file() self.layout.use_property_split = True - props = context.scene.BIMProperties + props = context.scene.BIMOwnerProperties row = self.layout.row() row.operator("bim.add_person", icon="ADD") @@ -169,7 +169,7 @@ class BIM_PT_organisations(Panel): self.file = IfcStore.get_file() self.layout.use_property_split = True - props = context.scene.BIMProperties + props = context.scene.BIMOwnerProperties row = self.layout.row() row.operator("bim.add_organisation", icon="ADD") @@ -216,7 +216,7 @@ class BIM_PT_owner(Panel): Data.load() self.layout.use_property_split = True - props = context.scene.BIMProperties + props = context.scene.BIMOwnerProperties if not Data.people: self.layout.label(text="No people found.") diff --git a/src/ifcblenderexport/blenderbim/bim/prop.py b/src/ifcblenderexport/blenderbim/bim/prop.py index 2d1862b0b2..780745cac4 100644 --- a/src/ifcblenderexport/blenderbim/bim/prop.py +++ b/src/ifcblenderexport/blenderbim/bim/prop.py @@ -284,30 +284,6 @@ def getAttributeEnumValues(self, context): return [(e, e, "") for e in json.loads(self.enum_items)] -def getPersons(self, context): - from blenderbim.bim.module.owner.data import Data - if not Data.is_loaded: - Data.load() - results = [] - for ifc_id, person in Data.people.items(): - if "Id" in person: - identifier = person["Id"] or "" - else: - identifier = person["Identifier"] or "" - results.append((str(ifc_id), identifier, "")) - return results - - -def getOrganisations(self, context): - from blenderbim.bim.module.owner.data import Data - if not Data.is_loaded: - Data.load() - results = [] - for ifc_id, organisation in Data.organisations.items(): - results.append((str(ifc_id), organisation["Name"], "")) - return results - - def getIfcPatchRecipes(self, context): global ifcpatchrecipes_enum if len(ifcpatchrecipes_enum) < 1: @@ -1057,10 +1033,6 @@ class BIMProperties(PropertyGroup): import_should_offset_model: BoolProperty(name="Import and Offset Model", default=False) import_model_offset_coordinates: StringProperty(name="Model Offset Coordinates", default="0,0,0") - # TODO: move into owner module - user_person: EnumProperty(items=getPersons, name="Person") - user_organisation: EnumProperty(items=getOrganisations, name="Organisation") - has_georeferencing: BoolProperty(name="Has Georeferencing", default=False) has_library: BoolProperty(name="Has Project Library", default=False) search_regex: BoolProperty(name="Search With Regex", default=False)