From 611e83ff1e4e4371e2e089eb5707177571f76485 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Fri, 27 Jun 2025 18:03:11 +0500 Subject: [PATCH] Remove unused code for additional ifc files in the drawings Code isn't used for over 3 years now and it's quite simple, so it's easy to restore if we'll need it again. Noticed when started to investigate what was the use for `include_query` and `exclude_query` and turned out they basically had no effect for all this time. --- src/bonsai/bonsai/bim/__init__.py | 2 - .../bonsai/bim/module/drawing/__init__.py | 1 - .../bonsai/bim/module/drawing/operator.py | 58 +------------------ src/bonsai/bonsai/bim/module/drawing/prop.py | 6 -- src/bonsai/bonsai/bim/module/drawing/ui.py | 14 ----- .../bonsai/bim/module/project/operator.py | 4 -- src/bonsai/bonsai/bim/operator.py | 23 -------- 7 files changed, 1 insertion(+), 107 deletions(-) diff --git a/src/bonsai/bonsai/bim/__init__.py b/src/bonsai/bonsai/bim/__init__.py index f004d3024b..50be50b3bf 100644 --- a/src/bonsai/bonsai/bim/__init__.py +++ b/src/bonsai/bonsai/bim/__init__.py @@ -97,7 +97,6 @@ for name in modules.keys(): classes = [ - operator.AddIfcFile, operator.BIM_OT_add_section_plane, operator.BIM_OT_delete_object, operator.BIM_OT_remove_section_plane, @@ -117,7 +116,6 @@ classes = [ operator.OpenUpstream, operator.OpenUri, operator.ReloadIfcFile, - operator.RemoveIfcFile, operator.RevertClippingPlaneCut, operator.SelectDir, operator.SelectIfcFile, diff --git a/src/bonsai/bonsai/bim/module/drawing/__init__.py b/src/bonsai/bonsai/bim/module/drawing/__init__.py index 7e3be31e36..c010e644eb 100644 --- a/src/bonsai/bonsai/bim/module/drawing/__init__.py +++ b/src/bonsai/bonsai/bim/module/drawing/__init__.py @@ -88,7 +88,6 @@ classes = ( operator.SelectAllDrawings, operator.SelectAllSheets, operator.SelectAssignedProduct, - operator.SelectDocIfcFile, operator.OpenDocumentationWebUi, prop.Variable, prop.Drawing, diff --git a/src/bonsai/bonsai/bim/module/drawing/operator.py b/src/bonsai/bonsai/bim/module/drawing/operator.py index d5a9a07097..2bc27a7a1c 100644 --- a/src/bonsai/bonsai/bim/module/drawing/operator.py +++ b/src/bonsai/bonsai/bim/module/drawing/operator.py @@ -2264,22 +2264,6 @@ class ActivateDrawingFromSheet(bpy.types.Operator, ActivateDrawingBase): return True -# TODO: not exposed to the UI. -class SelectDocIfcFile(bpy.types.Operator, ImportHelper): - bl_idname = "bim.select_doc_ifc_file" - bl_label = "Select Documentation IFC File" - bl_description = "Selection .ifc file for documentation." - bl_options = {"REGISTER", "UNDO"} - filter_glob: bpy.props.StringProperty(default="*.ifc;*.ifczip;*.ifcxml", options={"HIDDEN"}) - filename_ext = ".ifc" - index: bpy.props.IntProperty() - - def execute(self, context): - props = tool.Drawing.get_document_props() - props.ifc_files[self.index].name = self.filepath - return {"FINISHED"} - - class RemoveDrawing(bpy.types.Operator, tool.Ifc.Operator): bl_idname = "bim.remove_drawing" bl_label = "Remove Drawing" @@ -2483,6 +2467,7 @@ class SaveDrawingStyle(bpy.types.Operator, tool.Ifc.Operator): return {"FINISHED"} +# TODO: operator is not exposed to UI, move it to tool. class SaveDrawingStylesData(bpy.types.Operator, tool.Ifc.Operator): bl_idname = "bim.save_drawing_styles_data" bl_label = "Save Drawing Styles Data" @@ -2556,7 +2541,6 @@ class ActivateDrawingStyle(bpy.types.Operator, tool.Ifc.Operator): self.drawing_style = drawing_style self.set_raster_style(context) - self.set_query(context) props = tool.Drawing.get_document_props() assert (drawing := props.get_active_drawing()) @@ -2650,46 +2634,6 @@ class ActivateDrawingStyle(bpy.types.Operator, tool.Ifc.Operator): if "PYTEST_VERSION" in os.environ: raise - def set_query(self, context: bpy.types.Context) -> None: - self.include_global_ids = [] - self.exclude_global_ids = [] - props = tool.Drawing.get_document_props() - for ifc_file in props.ifc_files: - try: - ifc = ifcopenshell.open(ifc_file.name) - except: - continue - if self.drawing_style.include_query: - results = ifcopenshell.util.selector.filter_elements(ifc, self.drawing_style.include_query) - self.include_global_ids.extend([e.GlobalId for e in results]) - if self.drawing_style.exclude_query: - results = ifcopenshell.util.selector.filter_elements(ifc, self.drawing_style.exclude_query) - self.exclude_global_ids.extend([e.GlobalId for e in results]) - if self.drawing_style.include_query: - self.parse_filter_query("INCLUDE", context) - if self.drawing_style.exclude_query: - self.parse_filter_query("EXCLUDE", context) - - def parse_filter_query(self, mode: Literal["INCLUDE", "EXCLUDE"], context: bpy.types.Context) -> None: - if mode == "INCLUDE": - assert context.scene - objects = context.scene.objects - elif mode == "EXCLUDE": - objects = context.visible_objects - for obj in objects: - if mode == "INCLUDE": - obj.hide_viewport = False # Note: this breaks alt-H - global_id = obj.BIMObjectProperties.attributes.get("GlobalId") - if not global_id: - continue - global_id = global_id.string_value - if mode == "INCLUDE": - if global_id not in self.include_global_ids: - obj.hide_viewport = True # Note: this breaks alt-H - elif mode == "EXCLUDE": - if global_id in self.exclude_global_ids: - obj.hide_viewport = True # Note: this breaks alt-H - class RemoveSheet(bpy.types.Operator, tool.Ifc.Operator): bl_idname = "bim.remove_sheet" diff --git a/src/bonsai/bonsai/bim/module/drawing/prop.py b/src/bonsai/bonsai/bim/module/drawing/prop.py index c4e9d37067..b88b60c3a0 100644 --- a/src/bonsai/bonsai/bim/module/drawing/prop.py +++ b/src/bonsai/bonsai/bim/module/drawing/prop.py @@ -368,15 +368,11 @@ class DrawingStyle(PropertyGroup): name="Render Type", default="VIEWPORT", ) - include_query: StringProperty(name="Include Query") - exclude_query: StringProperty(name="Exclude Query") if TYPE_CHECKING: name: str raster_style: str render_type: RenderType - include_query: str - exclude_query: str class RasterStyleProperty(enum.Enum): @@ -425,7 +421,6 @@ class DocProperties(PropertyGroup): is_editing_sheets: BoolProperty(name="Is Editing Sheets", default=False) sheets: CollectionProperty(name="Sheets", type=Sheet) active_sheet_index: IntProperty(name="Active Sheet Index") - ifc_files: CollectionProperty(name="IFCs", type=StrProperty) drawing_styles: CollectionProperty(name="Drawing Styles", type=DrawingStyle) should_draw_decorations: BoolProperty(name="Should Draw Decorations", update=update_should_draw_decorations) sheets_dir: StringProperty(default=os.path.join("sheets") + os.path.sep, name="Default Sheets Directory") @@ -483,7 +478,6 @@ class DocProperties(PropertyGroup): is_editing_sheets: bool sheets: bpy.types.bpy_prop_collection_idprop[Sheet] active_sheet_index: int - ifc_files: bpy.types.bpy_prop_collection_idprop[StrProperty] drawing_styles: bpy.types.bpy_prop_collection_idprop[DrawingStyle] should_draw_decorations: bool sheets_dir: str diff --git a/src/bonsai/bonsai/bim/module/drawing/ui.py b/src/bonsai/bonsai/bim/module/drawing/ui.py index 3cb313a005..33d728ac1e 100644 --- a/src/bonsai/bonsai/bim/module/drawing/ui.py +++ b/src/bonsai/bonsai/bim/module/drawing/ui.py @@ -234,10 +234,6 @@ class BIM_PT_drawing_underlay(Panel): row = layout.row() row.prop(drawing_style, "render_type") - row = layout.row(align=True) - row.prop(drawing_style, "include_query") - row = layout.row(align=True) - row.prop(drawing_style, "exclude_query") row = layout.row(align=True) row.operator("bim.save_drawing_style") @@ -303,16 +299,6 @@ class BIM_PT_drawings(Panel): "BIM_UL_drawinglist", "", self.props, "drawings", self.props, "active_drawing_index" ) - # Commented out until federated drawing generation is rebuilt - # row = self.layout.row() - # row.operator("bim.add_ifc_file") - - # for index, ifc_file in enumerate(self.props.ifc_files): - # row = self.layout.row(align=True) - # row.prop(ifc_file, "name", text="IFC #{}".format(index + 1)) - # row.operator("bim.select_doc_ifc_file", icon="FILE_FOLDER", text="").index = index - # row.operator("bim.remove_ifc_file", icon="X", text="").index = index - class BIM_PT_schedules(Panel): bl_label = "Schedules" diff --git a/src/bonsai/bonsai/bim/module/project/operator.py b/src/bonsai/bonsai/bim/module/project/operator.py index e1a120dafe..5542ff24d4 100644 --- a/src/bonsai/bonsai/bim/module/project/operator.py +++ b/src/bonsai/bonsai/bim/module/project/operator.py @@ -1640,10 +1640,6 @@ class ExportIFC(bpy.types.Operator, ExportHelper): print("Export finished in {:.2f} seconds".format(time.time() - start)) # New project created in Bonsai should be in recent projects too. tool.Project.add_recent_ifc_project(Path(output_file)) - props = tool.Drawing.get_document_props() - if not props.ifc_files: - new = props.ifc_files.add() - new.name = output_file props = tool.Project.get_project_props() if props.use_relative_project_path and bpy.data.is_saved: output_file = os.path.relpath(output_file, bpy.path.abspath("//")) diff --git a/src/bonsai/bonsai/bim/operator.py b/src/bonsai/bonsai/bim/operator.py index 9b55b0c0f0..5be88d306f 100644 --- a/src/bonsai/bonsai/bim/operator.py +++ b/src/bonsai/bonsai/bim/operator.py @@ -887,29 +887,6 @@ class ReloadIfcFile(bpy.types.Operator, tool.Ifc.Operator, ImportHelper): return {"FINISHED"} -class AddIfcFile(bpy.types.Operator): - bl_idname = "bim.add_ifc_file" - bl_label = "Add IFC File" - bl_options = {"REGISTER", "UNDO"} - - def execute(self, context): - props = tool.Drawing.get_document_props() - props.ifc_files.add() - return {"FINISHED"} - - -class RemoveIfcFile(bpy.types.Operator): - bl_idname = "bim.remove_ifc_file" - bl_label = "Remove IFC File" - index: bpy.props.IntProperty() - bl_options = {"REGISTER", "UNDO"} - - def execute(self, context): - props = tool.Drawing.get_document_props() - props.ifc_files.remove(self.index) - return {"FINISHED"} - - class FetchObjectPassport(bpy.types.Operator): bl_idname = "bim.fetch_object_passport" bl_label = "Fetch Object Passport"