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:
Vukas Pajic
2021-10-23 09:16:11 +02:00
committed by GitHub
parent e779a57a09
commit 56ff0e7472
5 changed files with 121 additions and 52 deletions
+7 -50
View File
@@ -17,58 +17,11 @@
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>. # along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import bpy import bpy
import importlib from . import handler, ui, prop, operator, modules, helper
from . import handler, ui, prop, operator
modules = { modules = modules.get_modules()
"project": None, module_property_group = helper.create_module_property_group(modules)
"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}")
classes = [ classes = [
operator.OpenUri, operator.OpenUri,
@@ -81,6 +34,7 @@ classes = [
operator.ReloadIfcFile, operator.ReloadIfcFile,
operator.AddIfcFile, operator.AddIfcFile,
operator.RemoveIfcFile, operator.RemoveIfcFile,
operator.ConfigureVisibility,
prop.StrProperty, prop.StrProperty,
prop.Attribute, prop.Attribute,
prop.BIMProperties, prop.BIMProperties,
@@ -90,6 +44,7 @@ classes = [
prop.BIMObjectProperties, prop.BIMObjectProperties,
prop.BIMMaterialProperties, prop.BIMMaterialProperties,
prop.BIMMeshProperties, prop.BIMMeshProperties,
module_property_group,
ui.BIM_PT_section_plane, ui.BIM_PT_section_plane,
ui.BIM_UL_generic, ui.BIM_UL_generic,
ui.BIM_UL_topics, ui.BIM_UL_topics,
@@ -125,6 +80,7 @@ def register():
bpy.types.Camera.BIMMeshProperties = bpy.props.PointerProperty(type=prop.BIMMeshProperties) bpy.types.Camera.BIMMeshProperties = bpy.props.PointerProperty(type=prop.BIMMeshProperties)
bpy.types.PointLight.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_PT_unit.append(ui.ifc_units)
bpy.types.Scene.module_state = bpy.props.CollectionProperty(type= module_property_group)
for mod in modules.values(): for mod in modules.values():
mod.register() mod.register()
@@ -144,6 +100,7 @@ def unregister():
del bpy.types.Curve.BIMMeshProperties del bpy.types.Curve.BIMMeshProperties
del bpy.types.Camera.BIMMeshProperties del bpy.types.Camera.BIMMeshProperties
del bpy.types.PointLight.BIMMeshProperties del bpy.types.PointLight.BIMMeshProperties
del bpy.types.Scene.module_state
bpy.types.SCENE_PT_unit.remove(ui.ifc_units) bpy.types.SCENE_PT_unit.remove(ui.ifc_units)
for mod in reversed(list(modules.values())): for mod in reversed(list(modules.values())):
+26
View File
@@ -97,3 +97,29 @@ def export_attributes(props, callback=None):
continue # Our job is done continue # Our job is done
attributes[prop.name] = prop.get_value() attributes[prop.name] = prop.get_value()
return attributes 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)
}}
)
+54
View File
@@ -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
+32 -1
View File
@@ -22,11 +22,12 @@ import json
import webbrowser import webbrowser
import ifcopenshell import ifcopenshell
import blenderbim.bim.handler import blenderbim.bim.handler
from . import schema from . import schema, modules
from blenderbim.bim.ifc import IfcStore from blenderbim.bim.ifc import IfcStore
from mathutils import Vector, Matrix, Euler from mathutils import Vector, Matrix, Euler
from math import radians from math import radians
modules = modules.get_modules()
class OpenUri(bpy.types.Operator): class OpenUri(bpy.types.Operator):
bl_idname = "bim.open_uri" 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() a.name() for a in self.schema.declaration_by_name(ifc_class).all_attributes()
] ]
return self.applicable_attributes_cache[ifc_class] 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'}
+2 -1
View File
@@ -110,7 +110,8 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences):
row.prop(self, "should_hide_empty_props") row.prop(self, "should_hide_empty_props")
row = layout.row() row = layout.row()
row.prop(self, "should_play_chaching_sound") row.prop(self, "should_play_chaching_sound")
row = layout.row()
row.operator("bim.configure_visibility")
def ifc_units(self, context): def ifc_units(self, context):
scene = context.scene scene = context.scene