From 9753ed07a0687142c2f666a557555d2318f445c4 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 30 Sep 2021 12:08:07 +1000 Subject: [PATCH] Fix bug where you could accidentally add a context other than what you selected in the UI --- src/blenderbim/blenderbim/bim/handler.py | 6 +-- .../blenderbim/bim/module/context/__init__.py | 7 +-- .../blenderbim/bim/module/context/data.py | 34 +++++++++++++ .../blenderbim/bim/module/context/operator.py | 34 +++++-------- .../blenderbim/bim/module/context/prop.py | 48 ++++++++++++++++++ .../blenderbim/bim/module/context/ui.py | 43 ++++++++-------- .../blenderbim/bim/module/owner/__init__.py | 40 +++++++-------- .../blenderbim/bim/module/owner/data.py | 24 +++++++-- .../blenderbim/bim/module/owner/operator.py | 37 +++++++------- .../blenderbim/bim/module/owner/prop.py | 49 +++++-------------- .../blenderbim/bim/module/owner/ui.py | 35 ++++++------- src/blenderbim/blenderbim/bim/prop.py | 47 ------------------ .../test/bim/feature/context.feature | 6 +-- 13 files changed, 214 insertions(+), 196 deletions(-) create mode 100644 src/blenderbim/blenderbim/bim/module/context/data.py create mode 100644 src/blenderbim/blenderbim/bim/module/context/prop.py diff --git a/src/blenderbim/blenderbim/bim/handler.py b/src/blenderbim/blenderbim/bim/handler.py index cc249506fd..7fa721521d 100644 --- a/src/blenderbim/blenderbim/bim/handler.py +++ b/src/blenderbim/blenderbim/bim/handler.py @@ -23,7 +23,7 @@ import ifcopenshell.api.owner.settings from blenderbim.bim.module.drawing.prop import RasterStyleProperty from bpy.app.handlers import persistent from blenderbim.bim.ifc import IfcStore -from blenderbim.bim.module.owner.prop import getPersons, getOrganisations +from blenderbim.bim.module.owner.prop import get_user_person, get_user_organisation from ifcopenshell.api.attribute.data import Data as AttributeData from ifcopenshell.api.material.data import Data as MaterialData from ifcopenshell.api.style.data import Data as StyleData @@ -230,12 +230,12 @@ def setDefaultProperties(scene): ) ifcopenshell.api.owner.settings.get_person = ( lambda ifc: ifc.by_id(int(bpy.context.scene.BIMOwnerProperties.user_person)) - if getPersons(None, None) and bpy.context.scene.BIMOwnerProperties.user_person + if get_user_person(None, None) and bpy.context.scene.BIMOwnerProperties.user_person else None ) ifcopenshell.api.owner.settings.get_organisation = ( lambda ifc: ifc.by_id(int(bpy.context.scene.BIMOwnerProperties.user_organisation)) - if getOrganisations(None, None) and bpy.context.scene.BIMOwnerProperties.user_organisation + if get_user_organisation(None, None) and bpy.context.scene.BIMOwnerProperties.user_organisation else None ) ifcopenshell.api.owner.settings.get_application = get_application diff --git a/src/blenderbim/blenderbim/bim/module/context/__init__.py b/src/blenderbim/blenderbim/bim/module/context/__init__.py index 7577e1d78d..5021ee0da6 100644 --- a/src/blenderbim/blenderbim/bim/module/context/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/context/__init__.py @@ -17,18 +17,19 @@ # along with BlenderBIM Add-on. If not, see . import bpy -from . import ui, operator +from . import ui, prop, operator classes = ( operator.AddSubcontext, operator.RemoveSubcontext, + prop.BIMContextProperties, ui.BIM_PT_context, ) def register(): - pass + bpy.types.Scene.BIMContextProperties = bpy.props.PointerProperty(type=prop.BIMContextProperties) def unregister(): - pass + del bpy.types.Scene.BIMContextProperties diff --git a/src/blenderbim/blenderbim/bim/module/context/data.py b/src/blenderbim/blenderbim/bim/module/context/data.py new file mode 100644 index 0000000000..111da3dae7 --- /dev/null +++ b/src/blenderbim/blenderbim/bim/module/context/data.py @@ -0,0 +1,34 @@ +import blenderbim.tool as tool + + +class ContextData: + data = {} + is_loaded = False + + @classmethod + def load(cls): + cls.data = {"contexts": cls.get_contexts()} + cls.is_loaded = True + + @classmethod + def get_contexts(cls): + results = [] + for context in tool.Ifc.get().by_type("IfcGeometricRepresentationContext", include_subtypes=False): + results.append( + {"id": context.id(), "context_type": context.ContextType, "subcontexts": cls.get_subcontexts(context)} + ) + return results + + @classmethod + def get_subcontexts(cls, context): + results = [] + for subcontext in context.HasSubContexts: + results.append( + { + "id": subcontext.id(), + "context_type": subcontext.ContextType, + "context_identifier": subcontext.ContextIdentifier, + "target_view": subcontext.TargetView, + } + ) + return results diff --git a/src/blenderbim/blenderbim/bim/module/context/operator.py b/src/blenderbim/blenderbim/bim/module/context/operator.py index 72d8afbbea..fb084d03f5 100644 --- a/src/blenderbim/blenderbim/bim/module/context/operator.py +++ b/src/blenderbim/blenderbim/bim/module/context/operator.py @@ -19,11 +19,19 @@ import bpy import blenderbim.tool as tool import blenderbim.core.context as core +import blenderbim.bim.module.context.data from blenderbim.bim.ifc import IfcStore from ifcopenshell.api.context.data import Data -class AddSubcontext(bpy.types.Operator): +class Operator: + def execute(self, context): + IfcStore.execute_ifc_operator(self, context) + blenderbim.bim.module.context.data.ContextData.is_loaded = False + return {"FINISHED"} + + +class AddSubcontext(bpy.types.Operator, Operator): bl_idname = "bim.add_subcontext" bl_label = "Add Subcontext" bl_options = {"REGISTER", "UNDO"} @@ -31,31 +39,15 @@ class AddSubcontext(bpy.types.Operator): subcontext: bpy.props.StringProperty() target_view: bpy.props.StringProperty() - def execute(self, context): - return IfcStore.execute_ifc_operator(self, context) - def _execute(self, context): - core.add_context( - tool.Ifc(), - context=self.context or context.scene.BIMProperties.available_contexts, - subcontext=self.subcontext or context.scene.BIMProperties.available_subcontexts, - target_view=self.target_view or context.scene.BIMProperties.available_target_views, - ) - Data.load(IfcStore.get_file()) - return {"FINISHED"} + core.add_context(tool.Ifc, context=self.context, subcontext=self.subcontext, target_view=self.target_view) -class RemoveSubcontext(bpy.types.Operator): +class RemoveSubcontext(bpy.types.Operator, Operator): bl_idname = "bim.remove_subcontext" bl_label = "Remove Context" bl_options = {"REGISTER", "UNDO"} - ifc_definition_id: bpy.props.IntProperty() - - def execute(self, context): - return IfcStore.execute_ifc_operator(self, context) + context: bpy.props.IntProperty() def _execute(self, context): - self.file = IfcStore.get_file() - core.remove_context(tool.Ifc(), context=self.file.by_id(self.ifc_definition_id)) - Data.load(self.file) - return {"FINISHED"} + core.remove_context(tool.Ifc, context=tool.Ifc.get().by_id(self.context)) diff --git a/src/blenderbim/blenderbim/bim/module/context/prop.py b/src/blenderbim/blenderbim/bim/module/context/prop.py new file mode 100644 index 0000000000..e22cf7cd41 --- /dev/null +++ b/src/blenderbim/blenderbim/bim/module/context/prop.py @@ -0,0 +1,48 @@ +import bpy +from blenderbim.bim.prop import StrProperty, Attribute +from blenderbim.bim.module.context.data import ContextData +from bpy.types import PropertyGroup +from bpy.props import ( + PointerProperty, + StringProperty, + EnumProperty, + BoolProperty, + IntProperty, + FloatProperty, + FloatVectorProperty, + CollectionProperty, +) + + +class BIMContextProperties(PropertyGroup): + contexts: EnumProperty(items=[("Model", "Model", ""), ("Plan", "Plan", "")], name="Contexts") + subcontexts: EnumProperty( + items=[ + ("Annotation", "Annotation", ""), + ("Axis", "Axis", ""), + ("Box", "Box", ""), + ("FootPrint", "FootPrint", ""), + ("Reference", "Reference", ""), + ("Body", "Body", ""), + ("Clearance", "Clearance", ""), + ("CoG", "CoG", ""), + ("Profile", "Profile", ""), + ("SurveyPoints", "SurveyPoints", ""), + ("Lighting", "Lighting", ""), + ], + name="Subcontexts", + ) + target_views: EnumProperty( + items=[ + ("GRAPH_VIEW", "GRAPH_VIEW", ""), + ("SKETCH_VIEW", "SKETCH_VIEW", ""), + ("MODEL_VIEW", "MODEL_VIEW", ""), + ("PLAN_VIEW", "PLAN_VIEW", ""), + ("REFLECTED_PLAN_VIEW", "REFLECTED_PLAN_VIEW", ""), + ("SECTION_VIEW", "SECTION_VIEW", ""), + ("ELEVATION_VIEW", "ELEVATION_VIEW", ""), + ("USERDEFINED", "USERDEFINED", ""), + ("NOTDEFINED", "NOTDEFINED", ""), + ], + name="Target Views", + ) diff --git a/src/blenderbim/blenderbim/bim/module/context/ui.py b/src/blenderbim/blenderbim/bim/module/context/ui.py index 3cdc87be29..9a72a2697a 100644 --- a/src/blenderbim/blenderbim/bim/module/context/ui.py +++ b/src/blenderbim/blenderbim/bim/module/context/ui.py @@ -16,12 +16,12 @@ # You should have received a copy of the GNU General Public License # along with BlenderBIM Add-on. If not, see . -from bpy.types import Panel -from ifcopenshell.api.context.data import Data -from blenderbim.bim.ifc import IfcStore +import bpy +import blenderbim.tool as tool +from blenderbim.bim.module.context.data import ContextData -class BIM_PT_context(Panel): +class BIM_PT_context(bpy.types.Panel): bl_label = "IFC Geometric Representation Contexts" bl_idname = "BIM_PT_context" bl_options = {"DEFAULT_CLOSED"} @@ -31,28 +31,31 @@ class BIM_PT_context(Panel): @classmethod def poll(cls, context): - return IfcStore.get_file() + return tool.Ifc.get() def draw(self, context): - if not Data.is_loaded: - Data.load(IfcStore.get_file()) + if not ContextData.is_loaded: + ContextData.load() - props = context.scene.BIMProperties + props = context.scene.BIMContextProperties row = self.layout.row(align=True) - row.prop(props, "available_contexts", text="") - row.prop(props, "available_subcontexts", text="") - row.prop(props, "available_target_views", text="") - row.operator("bim.add_subcontext", icon="ADD", text="") + row.prop(props, "contexts", text="") + row.prop(props, "subcontexts", text="") + row.prop(props, "target_views", text="") + op = row.operator("bim.add_subcontext", icon="ADD", text="") + op.context = props.contexts + op.subcontext = props.subcontexts + op.target_view = props.target_views - for ifc_definition_id, context in Data.contexts.items(): + for context in ContextData.data["contexts"]: box = self.layout.box() row = box.row(align=True) - row.label(text=context["ContextType"]) - row.operator("bim.remove_subcontext", icon="X", text="").ifc_definition_id = ifc_definition_id - for ifc_definition_id2, subcontext in context["HasSubContexts"].items(): + row.label(text=context["context_type"]) + row.operator("bim.remove_subcontext", icon="X", text="").context = context["id"] + for subcontext in context["subcontexts"]: row = box.row(align=True) - row.label(text=subcontext["ContextType"]) - row.label(text=subcontext["ContextIdentifier"]) - row.label(text=subcontext["TargetView"]) - row.operator("bim.remove_subcontext", icon="X", text="").ifc_definition_id = ifc_definition_id2 + row.label(text=subcontext["context_type"]) + row.label(text=subcontext["context_identifier"]) + row.label(text=subcontext["target_view"]) + row.operator("bim.remove_subcontext", icon="X", text="").context = subcontext["id"] diff --git a/src/blenderbim/blenderbim/bim/module/owner/__init__.py b/src/blenderbim/blenderbim/bim/module/owner/__init__.py index 1cb236e8f9..aff8435c80 100644 --- a/src/blenderbim/blenderbim/bim/module/owner/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/owner/__init__.py @@ -20,30 +20,30 @@ import bpy from . import ui, prop, operator classes = ( - operator.EnableEditingPerson, - operator.DisableEditingPerson, - operator.AddPerson, - operator.EditPerson, - operator.RemovePerson, - operator.AddPersonAttribute, - operator.RemovePersonAttribute, - operator.EnableEditingOrganisation, - operator.DisableEditingOrganisation, - operator.AddOrganisation, - operator.EditOrganisation, - operator.RemoveOrganisation, - operator.EnableEditingRole, - operator.DisableEditingRole, - operator.AddRole, - operator.EditRole, - operator.RemoveRole, - operator.EnableEditingAddress, - operator.DisableEditingAddress, operator.AddAddress, operator.AddAddressAttribute, - operator.RemoveAddressAttribute, + operator.AddOrganisation, + operator.AddPerson, + operator.AddPersonAttribute, + operator.AddRole, + operator.DisableEditingAddress, + operator.DisableEditingOrganisation, + operator.DisableEditingPerson, + operator.DisableEditingRole, operator.EditAddress, + operator.EditOrganisation, + operator.EditPerson, + operator.EditRole, + operator.EnableEditingAddress, + operator.EnableEditingOrganisation, + operator.EnableEditingPerson, + operator.EnableEditingRole, operator.RemoveAddress, + operator.RemoveAddressAttribute, + operator.RemoveOrganisation, + operator.RemovePerson, + operator.RemovePersonAttribute, + operator.RemoveRole, prop.BIMOwnerProperties, ui.BIM_PT_people, ui.BIM_PT_organisations, diff --git a/src/blenderbim/blenderbim/bim/module/owner/data.py b/src/blenderbim/blenderbim/bim/module/owner/data.py index c4bd2562f9..5719716da0 100644 --- a/src/blenderbim/blenderbim/bim/module/owner/data.py +++ b/src/blenderbim/blenderbim/bim/module/owner/data.py @@ -85,7 +85,7 @@ class PeopleData(RolesAddressesData): @classmethod def get_people(cls): people = [] - for person in tool.Ifc().get().by_type("IfcPerson"): + for person in tool.Ifc.get().by_type("IfcPerson"): people.append( { "id": person.id(), @@ -102,7 +102,7 @@ class PeopleData(RolesAddressesData): @classmethod def get_person_name(cls, person): - if tool.Ifc().get_schema() == "IFC2X3": + if tool.Ifc.get_schema() == "IFC2X3": name = person.Id else: name = person.Identification @@ -143,7 +143,7 @@ class OrganisationsData(RolesAddressesData): @classmethod def get_organisations(cls): organisations = [] - for organisation in tool.Ifc().get().by_type("IfcOrganization"): + for organisation in tool.Ifc.get().by_type("IfcOrganization"): organisations.append( { "id": organisation.id(), @@ -156,3 +156,21 @@ class OrganisationsData(RolesAddressesData): } ) return organisations + + +class OwnerData: + data = {} + is_loaded = False + + @classmethod + def load(cls): + cls.data = {"user_person": cls.get_user_person(), "user_organisation": cls.get_user_organisation()} + cls.is_loaded = True + + @classmethod + def get_user_person(cls): + return [(str(p.id()), p[0] or "Unnamed", "") for p in tool.Ifc.get().by_type("IfcPerson")] + + @classmethod + def get_user_organisation(cls): + return [(str(p.id()), p[0] or "Unnamed", "") for p in tool.Ifc.get().by_type("IfcOrganization")] diff --git a/src/blenderbim/blenderbim/bim/module/owner/operator.py b/src/blenderbim/blenderbim/bim/module/owner/operator.py index d14fbf070b..c180c0ea02 100644 --- a/src/blenderbim/blenderbim/bim/module/owner/operator.py +++ b/src/blenderbim/blenderbim/bim/module/owner/operator.py @@ -22,15 +22,14 @@ import blenderbim.tool as tool import blenderbim.core.owner as core import blenderbim.bim.module.owner.data from blenderbim.bim.ifc import IfcStore -from ifcopenshell.api.owner.data import Data -# TODO: Just testing class Operator: def execute(self, context): IfcStore.execute_ifc_operator(self, context) blenderbim.bim.module.owner.data.PeopleData.is_loaded = False blenderbim.bim.module.owner.data.OrganisationsData.is_loaded = False + blenderbim.bim.module.owner.data.OwnerData.is_loaded = False return {"FINISHED"} @@ -41,7 +40,7 @@ class EnableEditingPerson(bpy.types.Operator, Operator): person: bpy.props.IntProperty() def _execute(self, context): - core.enable_editing_person(tool.PersonEditor(), person=tool.Ifc().get().by_id(self.person)) + core.enable_editing_person(tool.PersonEditor, person=tool.Ifc.get().by_id(self.person)) class DisableEditingPerson(bpy.types.Operator, Operator): @@ -50,7 +49,7 @@ class DisableEditingPerson(bpy.types.Operator, Operator): bl_options = {"REGISTER", "UNDO"} def _execute(self, context): - core.disable_editing_person(tool.PersonEditor()) + core.disable_editing_person(tool.PersonEditor) class AddPerson(bpy.types.Operator, Operator): @@ -59,7 +58,7 @@ class AddPerson(bpy.types.Operator, Operator): bl_options = {"REGISTER", "UNDO"} def _execute(self, context): - core.add_person(tool.Ifc()) + core.add_person(tool.Ifc) class EditPerson(bpy.types.Operator, Operator): @@ -68,7 +67,7 @@ class EditPerson(bpy.types.Operator, Operator): bl_options = {"REGISTER", "UNDO"} def _execute(self, context): - core.edit_person(tool.Ifc(), tool.PersonEditor()) + core.edit_person(tool.Ifc, tool.PersonEditor) class RemovePerson(bpy.types.Operator, Operator): @@ -78,7 +77,7 @@ class RemovePerson(bpy.types.Operator, Operator): person: bpy.props.IntProperty() def _execute(self, context): - core.remove_person(tool.Ifc(), person=tool.Ifc().get().by_id(self.person)) + core.remove_person(tool.Ifc, person=tool.Ifc.get().by_id(self.person)) class AddPersonAttribute(bpy.types.Operator, Operator): @@ -88,7 +87,7 @@ class AddPersonAttribute(bpy.types.Operator, Operator): name: bpy.props.StringProperty() def _execute(self, context): - core.add_person_attribute(tool.PersonEditor(), name=self.name) + core.add_person_attribute(tool.PersonEditor, name=self.name) class RemovePersonAttribute(bpy.types.Operator, Operator): @@ -99,7 +98,7 @@ class RemovePersonAttribute(bpy.types.Operator, Operator): id: bpy.props.IntProperty() def _execute(self, context): - core.remove_person_attribute(tool.PersonEditor(), name=self.name, id=self.id) + core.remove_person_attribute(tool.PersonEditor, name=self.name, id=self.id) class EnableEditingRole(bpy.types.Operator, Operator): @@ -109,7 +108,7 @@ class EnableEditingRole(bpy.types.Operator, Operator): role: bpy.props.IntProperty() def _execute(self, context): - core.enable_editing_role(tool.RoleEditor(), role=tool.Ifc().get().by_id(self.role)) + core.enable_editing_role(tool.RoleEditor, role=tool.Ifc.get().by_id(self.role)) class DisableEditingRole(bpy.types.Operator, Operator): @@ -118,7 +117,7 @@ class DisableEditingRole(bpy.types.Operator, Operator): bl_options = {"REGISTER", "UNDO"} def _execute(self, context): - core.disable_editing_role(tool.RoleEditor()) + core.disable_editing_role(tool.RoleEditor) class AddRole(bpy.types.Operator, Operator): @@ -128,7 +127,7 @@ class AddRole(bpy.types.Operator, Operator): parent: bpy.props.IntProperty() def _execute(self, context): - core.add_role(tool.Ifc(), parent=tool.Ifc().get().by_id(self.parent)) + core.add_role(tool.Ifc, parent=tool.Ifc.get().by_id(self.parent)) class EditRole(bpy.types.Operator, Operator): @@ -137,7 +136,7 @@ class EditRole(bpy.types.Operator, Operator): bl_options = {"REGISTER", "UNDO"} def _execute(self, context): - core.edit_role(tool.Ifc(), tool.RoleEditor()) + core.edit_role(tool.Ifc, tool.RoleEditor) class RemoveRole(bpy.types.Operator, Operator): @@ -147,7 +146,7 @@ class RemoveRole(bpy.types.Operator, Operator): role: bpy.props.IntProperty() def _execute(self, context): - core.remove_role(tool.Ifc(), role=tool.Ifc().get().by_id(self.role)) + core.remove_role(tool.Ifc, role=tool.Ifc.get().by_id(self.role)) class AddAddress(bpy.types.Operator, Operator): @@ -158,7 +157,7 @@ class AddAddress(bpy.types.Operator, Operator): ifc_class: bpy.props.StringProperty() def _execute(self, context): - core.add_address(tool.Ifc(), parent=tool.Ifc().get().by_id(self.parent), ifc_class=self.ifc_class) + core.add_address(tool.Ifc, parent=tool.Ifc.get().by_id(self.parent), ifc_class=self.ifc_class) class AddAddressAttribute(bpy.types.Operator, Operator): @@ -189,7 +188,7 @@ class EnableEditingAddress(bpy.types.Operator, Operator): address: bpy.props.IntProperty() def _execute(self, context): - core.enable_editing_address(tool.AddressEditor(), address=tool.Ifc().get().by_id(self.address)) + core.enable_editing_address(tool.AddressEditor, address=tool.Ifc.get().by_id(self.address)) class DisableEditingAddress(bpy.types.Operator, Operator): @@ -198,7 +197,7 @@ class DisableEditingAddress(bpy.types.Operator, Operator): bl_options = {"REGISTER", "UNDO"} def _execute(self, context): - core.disable_editing_address(tool.AddressEditor()) + core.disable_editing_address(tool.AddressEditor) class EditAddress(bpy.types.Operator, Operator): @@ -217,7 +216,7 @@ class RemoveAddress(bpy.types.Operator, Operator): address: bpy.props.IntProperty() def _execute(self, context): - core.remove_address(tool.Ifc(), address=tool.Ifc().get().by_id(self.address)) + core.remove_address(tool.Ifc, address=tool.Ifc.get().by_id(self.address)) class EnableEditingOrganisation(bpy.types.Operator, Operator): @@ -228,7 +227,7 @@ class EnableEditingOrganisation(bpy.types.Operator, Operator): def _execute(self, context): core.enable_editing_organisation( - tool.OrganisationEditor, organisation=tool.Ifc().get().by_id(self.organisation) + tool.OrganisationEditor, organisation=tool.Ifc.get().by_id(self.organisation) ) diff --git a/src/blenderbim/blenderbim/bim/module/owner/prop.py b/src/blenderbim/blenderbim/bim/module/owner/prop.py index 4d8bbdc485..1cbd3c466c 100644 --- a/src/blenderbim/blenderbim/bim/module/owner/prop.py +++ b/src/blenderbim/blenderbim/bim/module/owner/prop.py @@ -18,8 +18,7 @@ import bpy from blenderbim.bim.prop import StrProperty, Attribute -from blenderbim.bim.ifc import IfcStore -from ifcopenshell.api.owner.data import Data +from blenderbim.bim.module.owner.data import OwnerData from bpy.types import PropertyGroup from bpy.props import ( PointerProperty, @@ -32,47 +31,25 @@ from bpy.props import ( CollectionProperty, ) -_persons_enum = [] -_organisations_enum = [] + +def get_user_person(self, context): + if not OwnerData.is_loaded: + OwnerData.load() + return OwnerData.data["user_person"] -def purge(): - global _persons_enum - global _organisations_enum - _persons_enum.clear() - _organisations_enum.clear() - - -def getPersons(self, context): - global _persons_enum - if not Data.is_loaded: - Data.load(IfcStore.get_file()) - _persons_enum.clear() - for ifc_id, person in Data.people.items(): - if "Id" in person: - identifier = person["Id"] or "" - else: - identifier = person["Identification"] or "" - _persons_enum.append((str(ifc_id), identifier, "")) - return _persons_enum - - -def getOrganisations(self, context): - global _organisations_enum - if not Data.is_loaded: - Data.load(IfcStore.get_file()) - _organisations_enum.clear() - for ifc_id, organisation in Data.organisations.items(): - _organisations_enum.append((str(ifc_id), organisation["Name"], "")) - return _organisations_enum +def get_user_organisation(self, context): + if not OwnerData.is_loaded: + OwnerData.load() + return OwnerData.data["user_organisation"] class BIMOwnerProperties(PropertyGroup): + active_person_id: IntProperty(name="Active Person Id") person_attributes: CollectionProperty(name="Person Attributes", type=Attribute) middle_names: CollectionProperty(type=StrProperty, name="Middle Names") prefix_titles: CollectionProperty(type=StrProperty, name="Prefixes") suffix_titles: CollectionProperty(type=StrProperty, name="Suffixes") - active_person_id: IntProperty(name="Active Person Id") active_organisation_id: IntProperty(name="Active Organisation Id") organisation_attributes: CollectionProperty(name="Organisation Attributes", type=Attribute) active_role_id: IntProperty(name="Active Role Id") @@ -84,5 +61,5 @@ class BIMOwnerProperties(PropertyGroup): facsimile_numbers: CollectionProperty(type=StrProperty, name="Facsimile Numbers") electronic_mail_addresses: CollectionProperty(type=StrProperty, name="Emails") messaging_ids: CollectionProperty(type=StrProperty, name="IMs") - user_person: EnumProperty(items=getPersons, name="Person") - user_organisation: EnumProperty(items=getOrganisations, name="Organisation") + user_person: EnumProperty(items=get_user_person, name="Person") + user_organisation: EnumProperty(items=get_user_organisation, name="Organisation") diff --git a/src/blenderbim/blenderbim/bim/module/owner/ui.py b/src/blenderbim/blenderbim/bim/module/owner/ui.py index bd067ef4bf..7f5d472dfb 100644 --- a/src/blenderbim/blenderbim/bim/module/owner/ui.py +++ b/src/blenderbim/blenderbim/bim/module/owner/ui.py @@ -19,16 +19,7 @@ import bpy import blenderbim.bim.helper import blenderbim.tool as tool -from blenderbim.bim.module.owner.data import PeopleData, OrganisationsData -from bpy.types import Panel -from ifcopenshell.api.owner.data import Data -from blenderbim.bim.ifc import IfcStore - - -def draw_prop_on_new_row(layout, owner, attribute, align=False, **kwargs): - row = layout.row(align=align) - row.prop(owner, attribute, **kwargs) - return row +from blenderbim.bim.module.owner.data import PeopleData, OrganisationsData, OwnerData def draw_roles(box, parent): @@ -95,7 +86,7 @@ class BIM_PT_people(bpy.types.Panel): @classmethod def poll(cls, context): - return tool.Ifc().get() + return tool.Ifc.get() def draw(self, context): if not PeopleData.is_loaded: @@ -141,7 +132,7 @@ class BIM_PT_people(bpy.types.Panel): row.operator("bim.remove_person", icon="X", text="").person = person["id"] -class BIM_PT_organisations(Panel): +class BIM_PT_organisations(bpy.types.Panel): bl_label = "IFC Organisations" bl_idname = "BIM_PT_organisations" bl_options = {"DEFAULT_CLOSED"} @@ -151,7 +142,7 @@ class BIM_PT_organisations(Panel): @classmethod def poll(cls, context): - return IfcStore.get_file() + return tool.Ifc.get() def draw(self, context): if not OrganisationsData.is_loaded: @@ -185,7 +176,7 @@ class BIM_PT_organisations(Panel): row.operator("bim.remove_organisation", icon="X", text="").organisation = organisation["id"] -class BIM_PT_owner(Panel): +class BIM_PT_owner(bpy.types.Panel): bl_label = "IFC Owner History" bl_idname = "BIM_PT_owner" bl_options = {"DEFAULT_CLOSED"} @@ -195,22 +186,24 @@ class BIM_PT_owner(Panel): @classmethod def poll(cls, context): - return IfcStore.get_file() + return tool.Ifc.get() def draw(self, context): - if not Data.is_loaded: - Data.load(IfcStore.get_file()) + if not OwnerData.is_loaded: + OwnerData.load() self.layout.use_property_split = True self.layout.use_property_decorate = False props = context.scene.BIMOwnerProperties - if not Data.people: + if not OwnerData.data["user_person"]: self.layout.label(text="No people found.") else: - draw_prop_on_new_row(self.layout, props, "user_person") + row = self.layout.row() + row.prop(props, "user_person") - if not Data.organisations: + if not OwnerData.data["user_organisation"]: self.layout.label(text="No organisations found.") else: - draw_prop_on_new_row(self.layout, props, "user_organisation") + row = self.layout.row() + row.prop(props, "user_organisation") diff --git a/src/blenderbim/blenderbim/bim/prop.py b/src/blenderbim/blenderbim/bim/prop.py index 5c90d32e93..fd6ee6ec99 100644 --- a/src/blenderbim/blenderbim/bim/prop.py +++ b/src/blenderbim/blenderbim/bim/prop.py @@ -39,9 +39,6 @@ from bpy.props import ( cwd = os.path.dirname(os.path.realpath(__file__)) materialpsetnames_enum = [] -contexts_enum = [] -subcontexts_enum = [] -target_views_enum = [] def getAttributeEnumValues(self, context): @@ -99,47 +96,6 @@ def getContexts(self, context): return results -def getSubcontexts(self, context): - global subcontexts_enum - subcontexts_enum.clear() - # TODO: allow override of generated subcontexts? - subcontexts = [ - "Annotation", - "Axis", - "Box", - "FootPrint", - "Reference", - "Body", - "Clearance", - "CoG", - "Profile", - "SurveyPoints", - "Lighting", - ] - for subcontext in subcontexts: - subcontexts_enum.append((subcontext, subcontext, "")) - return subcontexts_enum - - -def getTargetViews(self, context): - global target_views_enum - target_views_enum.clear() - target_views = [ - "GRAPH_VIEW", - "SKETCH_VIEW", - "MODEL_VIEW", - "PLAN_VIEW", - "REFLECTED_PLAN_VIEW", - "SECTION_VIEW", - "ELEVATION_VIEW", - "USERDEFINED", - "NOTDEFINED", - ] - for target_view in target_views: - target_views_enum.append((target_view, target_view, "")) - return target_views_enum - - class StrProperty(PropertyGroup): pass @@ -225,9 +181,6 @@ class BIMProperties(PropertyGroup): export_schema: EnumProperty(items=[("IFC4", "IFC4", ""), ("IFC2X3", "IFC2X3", "")], name="IFC Schema") last_transaction: StringProperty(name="Last Transaction") contexts: EnumProperty(items=getContexts, name="Contexts") - available_contexts: EnumProperty(items=[("Model", "Model", ""), ("Plan", "Plan", "")], name="Available Contexts") - available_subcontexts: EnumProperty(items=getSubcontexts, name="Available Subcontexts") - available_target_views: EnumProperty(items=getTargetViews, name="Available Target Views") should_section_selected_objects: BoolProperty(name="Section Selected Objects", default=False) section_plane_colour: FloatVectorProperty( name="Temporary Section Cutaway Colour", subtype="COLOR", default=(1, 0, 0), min=0.0, max=1.0 diff --git a/src/blenderbim/test/bim/feature/context.feature b/src/blenderbim/test/bim/feature/context.feature index c76fe80891..2a4596f1e9 100644 --- a/src/blenderbim/test/bim/feature/context.feature +++ b/src/blenderbim/test/bim/feature/context.feature @@ -4,11 +4,11 @@ Feature: Context Scenario: Add subcontext Given an empty IFC project - When I press "bim.add_subcontext(context='Model')" + When I press "bim.add_subcontext(context='Model', subcontext='Body', target_view='MODEL_VIEW')" Then nothing happens Scenario: Remove subcontext Given an empty IFC project - When the variable "context_id" is "IfcStore.get_file().by_type('IfcGeometricRepresentationContext')[0].id()" - And I press "bim.remove_subcontext(ifc_definition_id={context_id})" + When the variable "context" is "IfcStore.get_file().by_type('IfcGeometricRepresentationContext')[0].id()" + And I press "bim.remove_subcontext(context={context})" Then nothing happens