mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 18:16:40 +00:00
Merge branch 'light/newUI' of https://github.com/IfcOpenShell/IfcOpenShell into light/newUI
This commit is contained in:
@@ -45,9 +45,7 @@ classes = (
|
||||
material.RADIANCE_OT_export_material_mappings,
|
||||
material.RADIANCE_OT_import_material_mappings,
|
||||
material.RADIANCE_OT_open_spectraldb,
|
||||
operator.EnumPropertySearch,
|
||||
prepare.PrepareRadianceScene,
|
||||
operator.SetEnumProperty,
|
||||
ies.AddIESLight,
|
||||
ies.RemoveIESLight,
|
||||
export.CleanupRadianceFiles,
|
||||
|
||||
@@ -30,14 +30,10 @@ All operator classes are defined in their respective submodules:
|
||||
RADIANCE_OT_open_spectraldb
|
||||
- ies.py: AddIESLight, RemoveIESLight
|
||||
|
||||
Small operators (EnumPropertySearch, SetEnumProperty) remain defined here.
|
||||
EnumPropertySearch and SetEnumProperty are provided by the global
|
||||
bonsai.bim.operator module (bl_idname "bim.enum_property_search").
|
||||
"""
|
||||
|
||||
import bpy
|
||||
|
||||
import bonsai.tool as tool
|
||||
from bonsai.bim.module.light.ui import get_enum_items
|
||||
|
||||
# Re-export from submodules
|
||||
from bonsai.bim.module.light.export import CleanupRadianceFiles, ExportOBJ # noqa: F401
|
||||
from bonsai.bim.module.light.ies import AddIESLight, RemoveIESLight # noqa: F401
|
||||
@@ -58,54 +54,3 @@ from bonsai.bim.module.light.solar import ( # noqa: F401
|
||||
MoveSunPathTo3DCursor,
|
||||
ViewFromSun,
|
||||
)
|
||||
|
||||
|
||||
class EnumPropertySearch(bpy.types.Operator):
|
||||
bl_idname = "bim.enum_property_search"
|
||||
bl_label = "Search Enum Property"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
prop_name: bpy.props.StringProperty()
|
||||
search_term: bpy.props.StringProperty()
|
||||
|
||||
def execute(self, context):
|
||||
try:
|
||||
data = context.space_data.context_pointer_get("data")
|
||||
except Exception:
|
||||
self.report({"ERROR"}, "Could not access context data for enum search.")
|
||||
return {"CANCELLED"}
|
||||
if data is None:
|
||||
self.report({"ERROR"}, "No context data available for enum search.")
|
||||
return {"CANCELLED"}
|
||||
enum_items = get_enum_items(data, self.prop_name)
|
||||
filtered_items = [item for item in enum_items if self.search_term.lower() in item[1].lower()]
|
||||
|
||||
def draw_menu(self, context):
|
||||
layout = self.layout
|
||||
for item in filtered_items:
|
||||
props = layout.operator("bim.set_enum_property", text=item[1])
|
||||
props.prop_name = self.prop_name
|
||||
props.enum_value = item[0]
|
||||
|
||||
bpy.context.window_manager.popup_menu(draw_menu, title="Search Results", icon="VIEWZOOM")
|
||||
return {"FINISHED"}
|
||||
|
||||
def invoke(self, context, event):
|
||||
return context.window_manager.invoke_props_dialog(self)
|
||||
|
||||
def draw(self, context):
|
||||
self.layout.prop(self, "search_term", text="Search")
|
||||
|
||||
|
||||
class SetEnumProperty(bpy.types.Operator):
|
||||
bl_idname = "bim.set_enum_property"
|
||||
bl_label = "Set Enum Property"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
prop_name: bpy.props.StringProperty()
|
||||
enum_value: bpy.props.StringProperty()
|
||||
|
||||
def execute(self, context):
|
||||
data = context.space_data.context_pointer_get("data")
|
||||
setattr(data, self.prop_name, self.enum_value)
|
||||
return {"FINISHED"}
|
||||
|
||||
@@ -22,31 +22,10 @@ from typing import TYPE_CHECKING
|
||||
import bpy
|
||||
|
||||
import bonsai.tool as tool
|
||||
from bonsai.bim.helper import prop_with_search
|
||||
from bonsai.bim.module.light.data import SolarData
|
||||
|
||||
|
||||
def get_enum_items(data, prop_name, context=None):
|
||||
prop = data.__annotations__[prop_name]
|
||||
items = prop.keywords.get("items")
|
||||
if items is None:
|
||||
return
|
||||
if not isinstance(items, (list, tuple)):
|
||||
items = items(data, context or bpy.context)
|
||||
return items
|
||||
|
||||
|
||||
def prop_with_search(layout, data, prop_name, **kwargs):
|
||||
row = layout.row(align=True)
|
||||
row.prop(data, prop_name, **kwargs)
|
||||
try:
|
||||
if len(get_enum_items(data, prop_name)) > 10:
|
||||
row.context_pointer_set(name="data", data=data)
|
||||
op = row.operator("bim.enum_property_search", text="", icon="VIEWZOOM")
|
||||
op.prop_name = prop_name
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Root panel (replaces the old "Radiance Exporter" nested panel)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user