diff --git a/src/blenderbim/blenderbim/bim/__init__.py b/src/blenderbim/blenderbim/bim/__init__.py index 0cb84dc766..dbbb189e63 100644 --- a/src/blenderbim/blenderbim/bim/__init__.py +++ b/src/blenderbim/blenderbim/bim/__init__.py @@ -17,10 +17,59 @@ # along with BlenderBIM Add-on. If not, see . import bpy -from . import handler, ui, prop, operator, modules, helper +import importlib +from . import handler, ui, prop, operator, helper -modules = modules.get_modules() -module_property_group = helper.create_module_property_group(modules) +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}") classes = [ @@ -37,6 +86,7 @@ classes = [ operator.ConfigureVisibility, prop.StrProperty, prop.Attribute, + prop.ModuleVisibility, prop.BIMProperties, prop.IfcParameter, prop.PsetQto, @@ -44,7 +94,6 @@ classes = [ prop.BIMObjectProperties, prop.BIMMaterialProperties, prop.BIMMeshProperties, - module_property_group, ui.BIM_PT_section_plane, ui.BIM_UL_generic, ui.BIM_UL_topics, @@ -80,7 +129,6 @@ 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() @@ -100,7 +148,6 @@ 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())): diff --git a/src/blenderbim/blenderbim/bim/helper.py b/src/blenderbim/blenderbim/bim/helper.py index 713525a67e..04d07e0386 100644 --- a/src/blenderbim/blenderbim/bim/helper.py +++ b/src/blenderbim/blenderbim/bim/helper.py @@ -97,29 +97,3 @@ 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) - }} - ) diff --git a/src/blenderbim/blenderbim/bim/modules.py b/src/blenderbim/blenderbim/bim/modules.py deleted file mode 100644 index d13c11a62a..0000000000 --- a/src/blenderbim/blenderbim/bim/modules.py +++ /dev/null @@ -1,54 +0,0 @@ -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 \ No newline at end of file diff --git a/src/blenderbim/blenderbim/bim/operator.py b/src/blenderbim/blenderbim/bim/operator.py index 632074ec8e..f2ea820184 100644 --- a/src/blenderbim/blenderbim/bim/operator.py +++ b/src/blenderbim/blenderbim/bim/operator.py @@ -22,12 +22,11 @@ import json import webbrowser import ifcopenshell import blenderbim.bim.handler -from . import schema, modules +from . import schema 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" @@ -490,29 +489,30 @@ class CopyAttributeToSelection(bpy.types.Operator): class ConfigureVisibility(bpy.types.Operator): bl_idname = "bim.configure_visibility" - bl_label = "Toggle availability of modules in BlenderBIM" + bl_label = "Configure module UI visibility in BlenderBIM" bl_options = {"REGISTER", "UNDO"} def invoke(self, context, event): + from blenderbim.bim import modules + wm = context.window_manager - if not context.scene.module_state: + if not len(context.scene.BIMProperties.module_visibility): for module in sorted(modules.keys()): - new = bpy.context.scene.module_state.add() - new.module_name = module + new = context.scene.BIMProperties.module_visibility.add() + new.name = module return wm.invoke_props_dialog(self, width=450) def draw(self, context): - layout = self.layout + layout = self.layout grid = layout.column_flow(columns=3) - for module in bpy.context.scene.module_state: + for module in context.scene.BIMProperties.module_visibility: split = grid.split() col = split.column() - #col.enabled = False - col.label(text=module.module_name.capitalize()) + col.label(text=module.name.capitalize()) col = split.column() - col.prop(module, "state", text="") - + col.prop(module, "is_visible", text="") + def execute(self, context): - return {'FINISHED'} \ No newline at end of file + return {"FINISHED"} diff --git a/src/blenderbim/blenderbim/bim/prop.py b/src/blenderbim/blenderbim/bim/prop.py index d7cb01cbb3..dbea59fcba 100644 --- a/src/blenderbim/blenderbim/bim/prop.py +++ b/src/blenderbim/blenderbim/bim/prop.py @@ -41,6 +41,29 @@ cwd = os.path.dirname(os.path.realpath(__file__)) materialpsetnames_enum = [] +def update_is_visible(self, context): + from blenderbim.bim import modules + + # TODO: Pset depends on sequence module as an edge case. + if self.name == "sequence" and not self.is_visible: + context.scene.BIMProperties.module_visibility["pset"].is_visible = False + + for cls in modules[self.name].classes: + if not issubclass(cls, bpy.types.Panel): + continue + + if self.is_visible: + try: + bpy.utils.register_class(cls) + except: + pass + else: + try: + bpy.utils.unregister_class(cls) + except: + pass + + def getAttributeEnumValues(self, context): # Support weird buildingSMART dictionary mappings which behave like enums data = json.loads(self.enum_items) @@ -49,13 +72,13 @@ def getAttributeEnumValues(self, context): return [(e, e, "") for e in data] -def updateSchemaDir(self, context): +def update_schema_dir(self, context): import blenderbim.bim.schema blenderbim.bim.schema.ifc.schema_dir = context.scene.BIMProperties.schema_dir -def updateDataDir(self, context): +def update_data_dir(self, context): import blenderbim.bim.schema blenderbim.bim.schema.ifc.data_dir = context.scene.BIMProperties.data_dir @@ -170,12 +193,19 @@ class Attribute(PropertyGroup): setattr(self, self.get_value_name(), value) +class ModuleVisibility(PropertyGroup): + name: StringProperty(name="Name") + is_visible: BoolProperty(name="Value", default=True, update=update_is_visible) + # is_visible: BoolProperty(name="Value", update=update_is_visible) + + class BIMProperties(PropertyGroup): + module_visibility: CollectionProperty(name="Module Visibility", type=ModuleVisibility) schema_dir: StringProperty( - default=os.path.join(cwd, "schema") + os.path.sep, name="Schema Directory", update=updateSchemaDir + default=os.path.join(cwd, "schema") + os.path.sep, name="Schema Directory", update=update_schema_dir ) data_dir: StringProperty( - default=os.path.join(cwd, "data") + os.path.sep, name="Data Directory", update=updateDataDir + default=os.path.join(cwd, "data") + os.path.sep, name="Data Directory", update=update_data_dir ) ifc_file: StringProperty(name="IFC File", update=update_ifc_file) export_schema: EnumProperty(items=[("IFC4", "IFC4", ""), ("IFC2X3", "IFC2X3", "")], name="IFC Schema") diff --git a/src/blenderbim/blenderbim/bim/ui.py b/src/blenderbim/blenderbim/bim/ui.py index 19aa221c92..4667dc92c1 100644 --- a/src/blenderbim/blenderbim/bim/ui.py +++ b/src/blenderbim/blenderbim/bim/ui.py @@ -113,6 +113,7 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences): row = layout.row() row.operator("bim.configure_visibility") + def ifc_units(self, context): scene = context.scene props = scene.BIMProperties