BIMTabProperties fixes

1) Fixed non-existent tool.Blender.get_screen
2) ui.py - remove try/except for the case when tabs are not loaded yet as it's covered by BIMTabProperties
3) removed previous_tab, alt_tab props never used in ui
4) general method for getting area properties that includes BIMTabProperties automatically
This commit is contained in:
Andrej730
2024-11-06 14:17:09 +05:00
parent e3de9c3ea4
commit 41fc0cf8c1
3 changed files with 51 additions and 59 deletions
+2 -3
View File
@@ -60,7 +60,7 @@ def update_tab(self: "BIMAreaProperties", context: bpy.types.Context) -> None:
def update_global_tab(self: "BIMTabProperties", context: bpy.types.Context) -> None:
tool.Blender.setup_tabs()
screen = tool.Blender.get_screen(context)
screen = context.id_data
aprops = screen.BIMAreaProperties[screen.areas[:].index(context.area)]
aprops.tab = self.tab
@@ -400,10 +400,9 @@ class BIMAreaProperties(PropertyGroup):
# BIMAreaProperties exists per area and is setup on load post. However, for new
# or temporary screens, they may not be setup yet, so this global tab
# properties is used as a fallback.
# Need it basically only for UI - to display those props and allow changing tab from the dropdown.
class BIMTabProperties(PropertyGroup):
tab: EnumProperty(default=0, items=get_tab, name="Tab", update=update_global_tab)
previous_tab: StringProperty(default="PROJECT", name="Previous Tab")
alt_tab: StringProperty(default="OBJECT", name="Alt Tab")
active_tab: BoolProperty(default=True, name="Active Tab")
inactive_tab: BoolProperty(default=False, name="Inactive Tab")
+43 -49
View File
@@ -392,58 +392,52 @@ class BIM_PT_tabs(Panel):
bl_options = {"HIDE_HEADER"}
def draw(self, context):
try:
is_ifc_project = bool(tool.Ifc.get())
aprops = tool.Blender.get_area_props(context)
if not aprops:
# Fallback in case areas aren't setup yet.
aprops = context.screen.BIMTabProperties
is_ifc_project = bool(tool.Ifc.get())
aprops = tool.Blender.get_area_props(context)
row = self.layout.row()
row.alignment = "CENTER"
row.operator(
"bim.set_tab",
text="",
emboss=aprops.tab == "PROJECT",
depress=True,
icon_value=bonsai.bim.icons["IFC"].icon_id,
).tab = "PROJECT"
self.draw_tab_entry(row, "FILE_3D", "OBJECT", is_ifc_project, aprops.tab == "OBJECT")
self.draw_tab_entry(row, "MATERIAL", "GEOMETRY", is_ifc_project, aprops.tab == "GEOMETRY")
self.draw_tab_entry(row, "DOCUMENTS", "DRAWINGS", is_ifc_project, aprops.tab == "DRAWINGS")
self.draw_tab_entry(row, "NETWORK_DRIVE", "SERVICES", is_ifc_project, aprops.tab == "SERVICES")
self.draw_tab_entry(row, "EDITMODE_HLT", "STRUCTURE", is_ifc_project, aprops.tab == "STRUCTURE")
self.draw_tab_entry(row, "NLA", "SCHEDULING", is_ifc_project, aprops.tab == "SCHEDULING")
self.draw_tab_entry(row, "PACKAGE", "FM", True, aprops.tab == "FM")
self.draw_tab_entry(row, "COMMUNITY", "QUALITY", True, aprops.tab == "QUALITY")
row.operator("bim.switch_tab", text="", emboss=False, icon="UV_SYNC_SELECT")
row = self.layout.row()
row.alignment = "CENTER"
row.operator(
"bim.set_tab",
text="",
emboss=aprops.tab == "PROJECT",
depress=True,
icon_value=bonsai.bim.icons["IFC"].icon_id,
).tab = "PROJECT"
self.draw_tab_entry(row, "FILE_3D", "OBJECT", is_ifc_project, aprops.tab == "OBJECT")
self.draw_tab_entry(row, "MATERIAL", "GEOMETRY", is_ifc_project, aprops.tab == "GEOMETRY")
self.draw_tab_entry(row, "DOCUMENTS", "DRAWINGS", is_ifc_project, aprops.tab == "DRAWINGS")
self.draw_tab_entry(row, "NETWORK_DRIVE", "SERVICES", is_ifc_project, aprops.tab == "SERVICES")
self.draw_tab_entry(row, "EDITMODE_HLT", "STRUCTURE", is_ifc_project, aprops.tab == "STRUCTURE")
self.draw_tab_entry(row, "NLA", "SCHEDULING", is_ifc_project, aprops.tab == "SCHEDULING")
self.draw_tab_entry(row, "PACKAGE", "FM", True, aprops.tab == "FM")
self.draw_tab_entry(row, "COMMUNITY", "QUALITY", True, aprops.tab == "QUALITY")
row.operator("bim.switch_tab", text="", emboss=False, icon="UV_SYNC_SELECT")
# Yes, that's right.
row = self.layout.row()
row.alignment = "CENTER"
row.scale_y = 0.2
for tab in [
"PROJECT",
"OBJECT",
"GEOMETRY",
"DRAWINGS",
"SERVICES",
"STRUCTURE",
"SCHEDULING",
"FM",
"QUALITY",
"SWITCH",
]:
# Draw a little underscore below the active tab icon.
if aprops.tab == tab:
row.prop(aprops, "active_tab", text="", icon="BLANK1")
else:
row.prop(aprops, "inactive_tab", text="", icon="BLANK1", emboss=False)
# Yes, that's right.
row = self.layout.row()
row.alignment = "CENTER"
row.scale_y = 0.2
for tab in [
"PROJECT",
"OBJECT",
"GEOMETRY",
"DRAWINGS",
"SERVICES",
"STRUCTURE",
"SCHEDULING",
"FM",
"QUALITY",
"SWITCH",
]:
# Draw a little underscore below the active tab icon.
if aprops.tab == tab:
row.prop(aprops, "active_tab", text="", icon="BLANK1")
else:
row.prop(aprops, "inactive_tab", text="", icon="BLANK1", emboss=False)
row = self.layout.row(align=True)
row.prop(aprops, "tab", text="")
except:
pass # Prior to load_post, we may not have any area properties setup
row = self.layout.row(align=True)
row.prop(aprops, "tab", text="")
if bonsai.REINSTALLED_BBIM_VERSION:
box = self.layout.box()
+6 -7
View File
@@ -86,16 +86,17 @@ class Blender(bonsai.core.tool.Blender):
area.spaces[0].region_3d.view_perspective = "CAMERA"
@classmethod
def get_area_props(cls, context: bpy.types.Context) -> Any:
def get_area_props(cls, context: bpy.types.Context) -> bpy.types.PropertyGroup:
try:
if context.screen.name.endswith("-nonnormal"): # Ctrl-space temporary fullscreen
screen = bpy.data.screens[context.screen.name[0 : -len("-nonnormal")]]
screen = bpy.data.screens[context.screen.name.removesuffix("-nonnormal")]
# The original area object has its type changed to "EMPTY" apparently
index = [a.type for a in screen.areas].index("EMPTY")
return screen.BIMAreaProperties[index]
return context.screen.BIMAreaProperties[context.screen.areas[:].index(context.area)]
except:
return
except IndexError:
# Fallback in case areas aren't setup yet.
return context.screen.BIMTabProperties
@classmethod
def set_active_object(cls, obj: bpy.types.Object) -> None:
@@ -119,9 +120,7 @@ class Blender(bonsai.core.tool.Blender):
@classmethod
def is_tab(cls, context: bpy.types.Context, tab: str) -> bool:
aprops = cls.get_area_props(context)
if not aprops:
return context.screen.BIMTabProperties.tab == tab
if context.area.spaces.active.search_filter:
if aprops.path_from_id() == "BIMAreaProperties" and context.area.spaces.active.search_filter:
return True
return aprops.tab == tab