mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 02:02:22 +00:00
BlenderBIM: added dropdown in addon preferences to toggle module visibility (#1798)
* added dropdown in addon preferences to toggle module visibility * Update ui.py * updated ui to allow individual toggling of modules * working * code cleanup and update * fix issue where non relevant operators shown * update based on review comments * add contingency for intermodule panel dependancy * removed 'magic' operators :) * clean up some leftover lines * updated to only register/deregister panel classes
This commit is contained in:
@@ -17,58 +17,11 @@
|
||||
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import bpy
|
||||
import importlib
|
||||
from . import handler, ui, prop, operator
|
||||
from . import handler, ui, prop, operator, modules, helper
|
||||
|
||||
modules = {
|
||||
"project": None,
|
||||
"search": None,
|
||||
"bcf": None,
|
||||
"root": None,
|
||||
"unit": None,
|
||||
"model": None,
|
||||
"georeference": None,
|
||||
"context": None,
|
||||
"drawing": None,
|
||||
"misc": None,
|
||||
"attribute": None,
|
||||
"type": None,
|
||||
"spatial": None,
|
||||
"void": None,
|
||||
"aggregate": None,
|
||||
"geometry": None,
|
||||
"cobie": None,
|
||||
"resource": None,
|
||||
"cost": None,
|
||||
"sequence": None,
|
||||
"group": None,
|
||||
"system": None,
|
||||
"structural": None,
|
||||
"boundary": None,
|
||||
"profile": None,
|
||||
"material": None,
|
||||
"style": None,
|
||||
"layer": None,
|
||||
"owner": None,
|
||||
"pset": None,
|
||||
"qto": None,
|
||||
"classification": None,
|
||||
"constraint": None,
|
||||
"document": None,
|
||||
"pset_template": None,
|
||||
"clash": None,
|
||||
"lca": None,
|
||||
"csv": None,
|
||||
"bimtester": None,
|
||||
"diff": None,
|
||||
"patch": None,
|
||||
"covetool": None,
|
||||
"augin": None,
|
||||
"debug": None,
|
||||
}
|
||||
modules = modules.get_modules()
|
||||
module_property_group = helper.create_module_property_group(modules)
|
||||
|
||||
for name in modules.keys():
|
||||
modules[name] = importlib.import_module(f"blenderbim.bim.module.{name}")
|
||||
|
||||
classes = [
|
||||
operator.OpenUri,
|
||||
@@ -81,6 +34,7 @@ classes = [
|
||||
operator.ReloadIfcFile,
|
||||
operator.AddIfcFile,
|
||||
operator.RemoveIfcFile,
|
||||
operator.ConfigureVisibility,
|
||||
prop.StrProperty,
|
||||
prop.Attribute,
|
||||
prop.BIMProperties,
|
||||
@@ -90,6 +44,7 @@ classes = [
|
||||
prop.BIMObjectProperties,
|
||||
prop.BIMMaterialProperties,
|
||||
prop.BIMMeshProperties,
|
||||
module_property_group,
|
||||
ui.BIM_PT_section_plane,
|
||||
ui.BIM_UL_generic,
|
||||
ui.BIM_UL_topics,
|
||||
@@ -125,6 +80,7 @@ def register():
|
||||
bpy.types.Camera.BIMMeshProperties = bpy.props.PointerProperty(type=prop.BIMMeshProperties)
|
||||
bpy.types.PointLight.BIMMeshProperties = bpy.props.PointerProperty(type=prop.BIMMeshProperties)
|
||||
bpy.types.SCENE_PT_unit.append(ui.ifc_units)
|
||||
bpy.types.Scene.module_state = bpy.props.CollectionProperty(type= module_property_group)
|
||||
|
||||
for mod in modules.values():
|
||||
mod.register()
|
||||
@@ -144,6 +100,7 @@ def unregister():
|
||||
del bpy.types.Curve.BIMMeshProperties
|
||||
del bpy.types.Camera.BIMMeshProperties
|
||||
del bpy.types.PointLight.BIMMeshProperties
|
||||
del bpy.types.Scene.module_state
|
||||
bpy.types.SCENE_PT_unit.remove(ui.ifc_units)
|
||||
|
||||
for mod in reversed(list(modules.values())):
|
||||
|
||||
@@ -97,3 +97,29 @@ def export_attributes(props, callback=None):
|
||||
continue # Our job is done
|
||||
attributes[prop.name] = prop.get_value()
|
||||
return attributes
|
||||
|
||||
def create_module_property_group(modules):
|
||||
def change_state(self, context):
|
||||
module_specific_classes = list(filter(lambda cls: issubclass(cls, bpy.types.Panel), modules[self.module_name].classes))
|
||||
try:
|
||||
for cls in reversed(module_specific_classes):
|
||||
bpy.utils.unregister_class(cls)
|
||||
|
||||
except RuntimeError: #class isn't registered
|
||||
#check for edge-case where pset panels inherit from sequence module
|
||||
sequence= list(filter(lambda prop: prop.module_name=="sequence", context.scene.module_state))
|
||||
if self.module_name == "pset" and not sequence[0].state:
|
||||
print("Pset can not be activated while Sequence is disabled")
|
||||
self["state"] = False
|
||||
else:
|
||||
for cls in module_specific_classes:
|
||||
bpy.utils.register_class(cls)
|
||||
|
||||
return type(
|
||||
"ModuleState",
|
||||
(bpy.types.PropertyGroup,),
|
||||
{'__annotations__':{
|
||||
"module_name": bpy.props.StringProperty(),
|
||||
"state": bpy.props.BoolProperty(default=True, update=change_state)
|
||||
}}
|
||||
)
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import importlib
|
||||
|
||||
modules = {
|
||||
"project": None,
|
||||
"search": None,
|
||||
"bcf": None,
|
||||
"root": None,
|
||||
"unit": None,
|
||||
"model": None,
|
||||
"georeference": None,
|
||||
"context": None,
|
||||
"drawing": None,
|
||||
"misc": None,
|
||||
"attribute": None,
|
||||
"type": None,
|
||||
"spatial": None,
|
||||
"void": None,
|
||||
"aggregate": None,
|
||||
"geometry": None,
|
||||
"cobie": None,
|
||||
"resource": None,
|
||||
"cost": None,
|
||||
"sequence": None,
|
||||
"group": None,
|
||||
"system": None,
|
||||
"structural": None,
|
||||
"boundary": None,
|
||||
"profile": None,
|
||||
"material": None,
|
||||
"style": None,
|
||||
"layer": None,
|
||||
"owner": None,
|
||||
"pset": None,
|
||||
"qto": None,
|
||||
"classification": None,
|
||||
"constraint": None,
|
||||
"document": None,
|
||||
"pset_template": None,
|
||||
"clash": None,
|
||||
"lca": None,
|
||||
"csv": None,
|
||||
"bimtester": None,
|
||||
"diff": None,
|
||||
"patch": None,
|
||||
"covetool": None,
|
||||
"augin": None,
|
||||
"debug": None,
|
||||
}
|
||||
|
||||
for name in modules.keys():
|
||||
modules[name] = importlib.import_module(f"blenderbim.bim.module.{name}")
|
||||
|
||||
def get_modules():
|
||||
return modules
|
||||
@@ -22,11 +22,12 @@ import json
|
||||
import webbrowser
|
||||
import ifcopenshell
|
||||
import blenderbim.bim.handler
|
||||
from . import schema
|
||||
from . import schema, modules
|
||||
from blenderbim.bim.ifc import IfcStore
|
||||
from mathutils import Vector, Matrix, Euler
|
||||
from math import radians
|
||||
|
||||
modules = modules.get_modules()
|
||||
|
||||
class OpenUri(bpy.types.Operator):
|
||||
bl_idname = "bim.open_uri"
|
||||
@@ -485,3 +486,33 @@ class CopyAttributeToSelection(bpy.types.Operator):
|
||||
a.name() for a in self.schema.declaration_by_name(ifc_class).all_attributes()
|
||||
]
|
||||
return self.applicable_attributes_cache[ifc_class]
|
||||
|
||||
|
||||
class ConfigureVisibility(bpy.types.Operator):
|
||||
bl_idname = "bim.configure_visibility"
|
||||
bl_label = "Toggle availability of modules in BlenderBIM"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def invoke(self, context, event):
|
||||
wm = context.window_manager
|
||||
if not context.scene.module_state:
|
||||
for module in sorted(modules.keys()):
|
||||
new = bpy.context.scene.module_state.add()
|
||||
new.module_name = module
|
||||
return wm.invoke_props_dialog(self, width=450)
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
grid = layout.column_flow(columns=3)
|
||||
|
||||
for module in bpy.context.scene.module_state:
|
||||
split = grid.split()
|
||||
col = split.column()
|
||||
#col.enabled = False
|
||||
col.label(text=module.module_name.capitalize())
|
||||
|
||||
col = split.column()
|
||||
col.prop(module, "state", text="")
|
||||
|
||||
def execute(self, context):
|
||||
return {'FINISHED'}
|
||||
@@ -110,7 +110,8 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences):
|
||||
row.prop(self, "should_hide_empty_props")
|
||||
row = layout.row()
|
||||
row.prop(self, "should_play_chaching_sound")
|
||||
|
||||
row = layout.row()
|
||||
row.operator("bim.configure_visibility")
|
||||
|
||||
def ifc_units(self, context):
|
||||
scene = context.scene
|
||||
|
||||
Reference in New Issue
Block a user