From f95466ee0c0ec45bd4af6f84d257190f417baa8f Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Tue, 16 Aug 2022 11:51:16 +1000 Subject: [PATCH] IfcTester now integrated into BlenderBIM Add-on UI --- src/blenderbim/Makefile | 10 +- src/blenderbim/blenderbim/bim/__init__.py | 1 + .../blenderbim/bim/module/tester/__init__.py | 36 +++++++ .../blenderbim/bim/module/tester/operator.py | 97 +++++++++++++++++++ .../blenderbim/bim/module/tester/prop.py | 40 ++++++++ .../blenderbim/bim/module/tester/ui.py | 51 ++++++++++ 6 files changed, 231 insertions(+), 4 deletions(-) create mode 100644 src/blenderbim/blenderbim/bim/module/tester/__init__.py create mode 100644 src/blenderbim/blenderbim/bim/module/tester/operator.py create mode 100644 src/blenderbim/blenderbim/bim/module/tester/prop.py create mode 100644 src/blenderbim/blenderbim/bim/module/tester/ui.py diff --git a/src/blenderbim/Makefile b/src/blenderbim/Makefile index 608f9e54fa..4db2c4d89c 100644 --- a/src/blenderbim/Makefile +++ b/src/blenderbim/Makefile @@ -143,6 +143,8 @@ endif cd dist/working && . env/bin/activate && pip install babel cd dist/working && . env/bin/activate && ./env/bin/pybabel compile -d ./IfcOpenShell-0.7.0/src/ifcbimtester/bimtester/locale/ 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 IFCCOBie functionality cp -r dist/working/IfcOpenShell-0.7.0/src/ifccobie/* dist/blenderbim/libs/site/packages/ # Provides IFCDiff functionality @@ -238,16 +240,16 @@ endif # Required by bcf mkdir dist/working - cd dist/working && wget https://files.pythonhosted.org/packages/bb/41/ad9ce53bb978b68af8ae415293cafc89b165b8ad55a593725299dca76729/xmlschema-1.1.1.tar.gz + cd dist/working && wget https://files.pythonhosted.org/packages/5b/ef/f97c3e1a7efa00e989a793fe15297214fc95ad7d9e3810586bd08ce9f0f3/xmlschema-2.0.2.tar.gz cd dist/working && tar -xzvf xmlschema* - cp -r dist/working/xmlschema-1.1.1/xmlschema dist/blenderbim/libs/site/packages/ + cp -r dist/working/xmlschema-2.0.2/xmlschema dist/blenderbim/libs/site/packages/ rm -rf dist/working # Required by bcf mkdir dist/working - cd dist/working && wget https://files.pythonhosted.org/packages/12/f9/f9960222d5274944b01391749e55e4dcdf28d8f0c108b64ac931ceff6fdb/elementpath-1.4.3.tar.gz + cd dist/working && wget https://files.pythonhosted.org/packages/11/bc/5afb61dd5d863e5cf77cd952445c50c17e65953405986f19e97e4389692a/elementpath-3.0.2.tar.gz cd dist/working && tar -xzvf elementpath* - cp -r dist/working/elementpath-1.4.3/elementpath dist/blenderbim/libs/site/packages/ + cp -r dist/working/elementpath-3.0.2/elementpath dist/blenderbim/libs/site/packages/ rm -rf dist/working # Required by bcf diff --git a/src/blenderbim/blenderbim/bim/__init__.py b/src/blenderbim/blenderbim/bim/__init__.py index ff52cf6ed9..ca9b679eca 100644 --- a/src/blenderbim/blenderbim/bim/__init__.py +++ b/src/blenderbim/blenderbim/bim/__init__.py @@ -62,6 +62,7 @@ modules = { "clash": None, "lca": None, "csv": None, + "tester": None, "bimtester": None, "diff": None, "patch": None, diff --git a/src/blenderbim/blenderbim/bim/module/tester/__init__.py b/src/blenderbim/blenderbim/bim/module/tester/__init__.py new file mode 100644 index 0000000000..aae027b711 --- /dev/null +++ b/src/blenderbim/blenderbim/bim/module/tester/__init__.py @@ -0,0 +1,36 @@ +# BlenderBIM Add-on - OpenBIM Blender Add-on +# Copyright (C) 2022 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.ExecuteIfcTester, + operator.SelectSpecs, + operator.SelectIfcTesterIfcFile, + prop.IfcTesterProperties, + ui.BIM_PT_tester, +) + + +def register(): + bpy.types.Scene.IfcTesterProperties = bpy.props.PointerProperty(type=prop.IfcTesterProperties) + + +def unregister(): + del bpy.types.Scene.IfcTesterProperties diff --git a/src/blenderbim/blenderbim/bim/module/tester/operator.py b/src/blenderbim/blenderbim/bim/module/tester/operator.py new file mode 100644 index 0000000000..591567a338 --- /dev/null +++ b/src/blenderbim/blenderbim/bim/module/tester/operator.py @@ -0,0 +1,97 @@ +# BlenderBIM Add-on - OpenBIM Blender Add-on +# Copyright (C) 2020, 2021 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 time +import tempfile +import webbrowser +import ifctester +import ifctester.ids +import ifctester.reporter +import ifcopenshell +import blenderbim.tool as tool + + +class ExecuteIfcTester(bpy.types.Operator): + bl_idname = "bim.execute_ifc_tester" + bl_label = "Execute IfcTester" + + @classmethod + def poll(cls, context): + props = context.scene.IfcTesterProperties + return (props.ifc_file or props.should_load_from_memory) and props.specs + + def execute(self, context): + props = context.scene.IfcTesterProperties + + with tempfile.TemporaryDirectory() as dirpath: + start = time.time() + output = os.path.join(dirpath, "{}.html".format(props.specs)) + + if props.should_load_from_memory and tool.Ifc.get(): + ifc = tool.Ifc.get() + else: + ifc = ifcopenshell.open(props.ifc_file) + + specs = ifctester.ids.open(props.specs) + print("Finished loading:", time.time() - start) + start = time.time() + specs.validate(ifc) + print("Finished validating:", time.time() - start) + start = time.time() + + engine = ifctester.reporter.Html(specs) + engine.report() + engine.to_file(output) + webbrowser.open("file://" + output) + return {"FINISHED"} + + +class SelectSpecs(bpy.types.Operator): + bl_idname = "bim.select_specs" + bl_label = "Select IDS" + bl_options = {"REGISTER", "UNDO"} + filename_ext = ".ids" + filter_glob: bpy.props.StringProperty(default="*.ids;*.xml", options={"HIDDEN"}) + filepath: bpy.props.StringProperty(subtype="FILE_PATH") + + def execute(self, context): + context.scene.IfcTesterProperties.specs = self.filepath + return {"FINISHED"} + + def invoke(self, context, event): + context.window_manager.fileselect_add(self) + return {"RUNNING_MODAL"} + + +class SelectIfcTesterIfcFile(bpy.types.Operator): + bl_idname = "bim.select_ifctester_ifc_file" + bl_label = "Select IfcTester 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.IfcTesterProperties.ifc_file = self.filepath + return {"FINISHED"} + + def invoke(self, context, event): + context.window_manager.fileselect_add(self) + return {"RUNNING_MODAL"} diff --git a/src/blenderbim/blenderbim/bim/module/tester/prop.py b/src/blenderbim/blenderbim/bim/module/tester/prop.py new file mode 100644 index 0000000000..09866feed1 --- /dev/null +++ b/src/blenderbim/blenderbim/bim/module/tester/prop.py @@ -0,0 +1,40 @@ +# BlenderBIM Add-on - OpenBIM Blender Add-on +# Copyright (C) 2022 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 . + +from blenderbim.bim.prop import StrProperty +from bpy.types import PropertyGroup +from bpy.props import ( + PointerProperty, + StringProperty, + EnumProperty, + BoolProperty, + IntProperty, + FloatProperty, + FloatVectorProperty, + CollectionProperty, +) + + +def purge(): + pass + + +class IfcTesterProperties(PropertyGroup): + specs: StringProperty(default="", name="IDS File") + ifc_file: StringProperty(default="", name="IFC File") + should_load_from_memory: BoolProperty(default=False, name="Load from Memory") diff --git a/src/blenderbim/blenderbim/bim/module/tester/ui.py b/src/blenderbim/blenderbim/bim/module/tester/ui.py new file mode 100644 index 0000000000..59a0d12281 --- /dev/null +++ b/src/blenderbim/blenderbim/bim/module/tester/ui.py @@ -0,0 +1,51 @@ +# BlenderBIM Add-on - OpenBIM Blender Add-on +# Copyright (C) 2022 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 + + +class BIM_PT_tester(Panel): + bl_label = "IFC Tester" + bl_idname = "BIM_PT_tester" + bl_options = {"DEFAULT_CLOSED"} + bl_space_type = "PROPERTIES" + bl_region_type = "WINDOW" + bl_context = "scene" + bl_parent_id = "BIM_PT_quality_control" + + def draw(self, context): + self.layout.use_property_split = True + + props = context.scene.IfcTesterProperties + + if tool.Ifc.get(): + row = self.layout.row() + row.prop(props, "should_load_from_memory") + + if not tool.Ifc.get() or not props.should_load_from_memory: + row = self.layout.row(align=True) + row.prop(props, "ifc_file") + row.operator("bim.select_ifctester_ifc_file", icon="FILE_FOLDER", text="") + + row = self.layout.row(align=True) + row.prop(props, "specs") + row.operator("bim.select_specs", icon="FILE_FOLDER", text="") + + row = self.layout.row() + row.operator("bim.execute_ifc_tester")