From e04b69717b5ce65ed9f47ca45703d77f5275f88c Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Wed, 13 Sep 2023 17:06:42 +1000 Subject: [PATCH] New FM module in BlenderBIM Add-on for interacting with IfcFM. --- src/blenderbim/Makefile | 2 + src/blenderbim/blenderbim/bim/__init__.py | 1 + .../blenderbim/bim/module/fm/__init__.py | 35 ++++++++ .../blenderbim/bim/module/fm/operator.py | 83 +++++++++++++++++++ .../blenderbim/bim/module/fm/prop.py | 54 ++++++++++++ src/blenderbim/blenderbim/bim/module/fm/ui.py | 54 ++++++++++++ 6 files changed, 229 insertions(+) create mode 100644 src/blenderbim/blenderbim/bim/module/fm/__init__.py create mode 100644 src/blenderbim/blenderbim/bim/module/fm/operator.py create mode 100644 src/blenderbim/blenderbim/bim/module/fm/prop.py create mode 100644 src/blenderbim/blenderbim/bim/module/fm/ui.py diff --git a/src/blenderbim/Makefile b/src/blenderbim/Makefile index 736a2277a1..5d3ceeeee3 100644 --- a/src/blenderbim/Makefile +++ b/src/blenderbim/Makefile @@ -199,6 +199,8 @@ endif cp -r dist/working/IfcOpenShell-0.7.0/src/ifcbimtester/bimtester dist/blenderbim/libs/site/packages/ # Provides IFCTester functionality cp -r dist/working/IfcOpenShell-0.7.0/src/ifctester/ifctester dist/blenderbim/libs/site/packages/ + # Provides IFCFM functionality + cp -r dist/working/IfcOpenShell-0.7.0/src/ifcfm/ifcfm dist/blenderbim/libs/site/packages/ # Provides IFCCOBie functionality cp -r dist/working/IfcOpenShell-0.7.0/src/ifccobie/* dist/blenderbim/libs/site/packages/ # Provides IFCDiff functionality diff --git a/src/blenderbim/blenderbim/bim/__init__.py b/src/blenderbim/blenderbim/bim/__init__.py index b048d888d9..2bfccf20e8 100644 --- a/src/blenderbim/blenderbim/bim/__init__.py +++ b/src/blenderbim/blenderbim/bim/__init__.py @@ -44,6 +44,7 @@ modules = { "void": None, "aggregate": None, "geometry": None, + "fm": None, "cobie": None, "resource": None, "cost": None, diff --git a/src/blenderbim/blenderbim/bim/module/fm/__init__.py b/src/blenderbim/blenderbim/bim/module/fm/__init__.py new file mode 100644 index 0000000000..de3f0f9448 --- /dev/null +++ b/src/blenderbim/blenderbim/bim/module/fm/__init__.py @@ -0,0 +1,35 @@ +# BlenderBIM Add-on - OpenBIM Blender Add-on +# Copyright (C) 2023 Dion Moult +# +# This file is part of BlenderBIM Add-on. +# +# BlenderBIM Add-on is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# BlenderBIM Add-on is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with BlenderBIM Add-on. If not, see . + +import bpy +from . import ui, prop, operator + +classes = ( + operator.SelectFMIfcFile, + operator.ExecuteIfcFM, + prop.BIMFMProperties, + ui.BIM_PT_fm, +) + + +def register(): + bpy.types.Scene.BIMFMProperties = bpy.props.PointerProperty(type=prop.BIMFMProperties) + + +def unregister(): + del bpy.types.Scene.BIMFMProperties diff --git a/src/blenderbim/blenderbim/bim/module/fm/operator.py b/src/blenderbim/blenderbim/bim/module/fm/operator.py new file mode 100644 index 0000000000..a53c92dc0c --- /dev/null +++ b/src/blenderbim/blenderbim/bim/module/fm/operator.py @@ -0,0 +1,83 @@ +# BlenderBIM Add-on - OpenBIM Blender Add-on +# Copyright (C) 2023 Dion Moult +# +# This file is part of BlenderBIM Add-on. +# +# BlenderBIM Add-on is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# BlenderBIM Add-on is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with BlenderBIM Add-on. If not, see . + +import os +import bpy +import json +import logging +import tempfile +import webbrowser +import ifcopenshell +import blenderbim.tool as tool + + +class SelectFMIfcFile(bpy.types.Operator): + bl_idname = "bim.select_fm_ifc_file" + bl_label = "Select FM IFC File" + bl_options = {"REGISTER", "UNDO"} + filename_ext = ".ifc" + filter_glob: bpy.props.StringProperty(default="*.ifc;*.ifczip;*.ifcxml", options={"HIDDEN"}) + filepath: bpy.props.StringProperty(subtype="FILE_PATH") + + def execute(self, context): + context.scene.BIMFMProperties.ifc_file = self.filepath + return {"FINISHED"} + + def invoke(self, context, event): + context.window_manager.fileselect_add(self) + return {"RUNNING_MODAL"} + + +class ExecuteIfcFM(bpy.types.Operator): + bl_idname = "bim.execute_ifcfm" + bl_label = "Execute IfcFM" + file_format: bpy.props.StringProperty() + filter_glob: bpy.props.StringProperty(default="*.csv;*.ods;*.xlsx", options={"HIDDEN"}) + filepath: bpy.props.StringProperty(subtype="FILE_PATH") + + @classmethod + def poll(cls, context): + props = context.scene.BIMFMProperties + return props.should_load_from_memory or props.ifc_file + + def invoke(self, context, event): + props = context.scene.BIMFMProperties + self.filepath = bpy.path.ensure_ext(bpy.data.filepath, f".{props.format}") + WindowManager = context.window_manager + WindowManager.fileselect_add(self) + return {"RUNNING_MODAL"} + + def execute(self, context): + import ifcfm + + props = context.scene.BIMFMProperties + ifc_file = tool.Ifc.get() + if not (ifc_file and props.should_load_from_memory): + ifc_file = ifcopenshell.open(props.ifc_file) + + parser = ifcfm.Parser(preset=props.engine) + parser.parse(ifc_file) + writer = ifcfm.Writer(parser) + writer.write() + if props.format == "csv": + writer.write_csv('tmp/') + elif props.format == "ods": + writer.write_ods(self.filepath) + elif props.format == "xlsx": + writer.write_xlsx(self.filepath) + return {"FINISHED"} diff --git a/src/blenderbim/blenderbim/bim/module/fm/prop.py b/src/blenderbim/blenderbim/bim/module/fm/prop.py new file mode 100644 index 0000000000..120de1a747 --- /dev/null +++ b/src/blenderbim/blenderbim/bim/module/fm/prop.py @@ -0,0 +1,54 @@ +# BlenderBIM Add-on - OpenBIM Blender Add-on +# Copyright (C) 2023 Dion Moult +# +# This file is part of BlenderBIM Add-on. +# +# BlenderBIM Add-on is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# BlenderBIM Add-on is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with BlenderBIM Add-on. If not, see . + +import bpy +from bpy.types import PropertyGroup +from bpy.props import ( + PointerProperty, + StringProperty, + EnumProperty, + BoolProperty, + IntProperty, + FloatProperty, + FloatVectorProperty, + CollectionProperty, +) + + +class BIMFMProperties(PropertyGroup): + ifc_file: StringProperty(default="", name="IFC File") + should_load_from_memory: BoolProperty(default=False, name="Load from Memory") + engine: EnumProperty( + items=[ + ("aohbsem", "AOH-BSEM", ""), + ("basic", "Basic", ""), + ("cobie", "COBie 2.4", ""), + ("cobie3", "COBie 3", ""), + ], + name="Engine", + default="cobie", + ) + format: EnumProperty( + items=[ + ("csv", "csv", ""), + ("xlsx", "xlsx", ""), + ("ods", "ods", ""), + ], + name="Format", + default="ods", + ) diff --git a/src/blenderbim/blenderbim/bim/module/fm/ui.py b/src/blenderbim/blenderbim/bim/module/fm/ui.py new file mode 100644 index 0000000000..8ef8a4dd43 --- /dev/null +++ b/src/blenderbim/blenderbim/bim/module/fm/ui.py @@ -0,0 +1,54 @@ +# BlenderBIM Add-on - OpenBIM Blender Add-on +# Copyright (C) 2023 Dion Moult +# +# This file is part of BlenderBIM Add-on. +# +# BlenderBIM Add-on is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# BlenderBIM Add-on is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with BlenderBIM Add-on. If not, see . + +import blenderbim.tool as tool +from bpy.types import Panel +from blenderbim.bim.ifc import IfcStore + + +class BIM_PT_fm(Panel): + bl_label = "Facility Management" + bl_idname = "BIM_PT_fm" + bl_space_type = "PROPERTIES" + bl_region_type = "WINDOW" + bl_context = "scene" + bl_parent_id = "BIM_PT_tab_handover" + + def draw(self, context): + layout = self.layout + layout.use_property_split = True + + scene = context.scene + props = scene.BIMFMProperties + + if IfcStore.get_file(): + row = layout.row() + row.prop(props, "should_load_from_memory") + + if not IfcStore.get_file() or not props.should_load_from_memory: + row = layout.row(align=True) + row.prop(props, "ifc_file") + row.operator("bim.select_fm_ifc_file", icon="FILE_FOLDER", text="") + + row = layout.row() + row.prop(props, "engine") + row = layout.row() + row.prop(props, "format") + + row = layout.row() + op = row.operator("bim.execute_ifcfm", text="Convert To Spreadsheet")